26 Commits

Author SHA1 Message Date
Nathan Rice f83f625c84 Merge from develop. 2017-04-13 13:12:29 -04:00
Nathan Rice 42315b2944 Indicate replacement for ss_do_one_sidebar(). see #22. 2017-03-10 17:18:33 -05:00
Nathan Rice 6f8b1a2069 Modify deprecated functions for backward compatibility. see #22. 2017-03-10 14:27:11 -05:00
Nathan Rice 7b439c95a7 Use more reliable method for switching sidebars. should eliminate issues moving sidebars in #22. 2017-03-08 22:42:02 -05:00
Nathan Rice 775ece1a8b Forgot to change version after copy/paste. 2017-03-07 15:21:21 -05:00
Nathan Rice a3dc69479a Load textdomain first thing. 2017-03-07 15:18:28 -05:00
Nathan Rice f2280a3fae Change minimum requirement message. 2017-03-06 15:41:58 -05:00
Nathan Rice 991b354175 Fix typo. 2017-03-06 13:32:33 -05:00
Nathan Rice 491a2b74fc Better wording for admin notice. 2017-03-06 12:32:21 -05:00
Nathan Rice e5afd4f9ef Better wording for admin notice. 2017-03-06 12:29:22 -05:00
Nathan Rice 7d10d3c408 Fix translations issues. see #20. 2017-03-06 11:36:53 -05:00
Nathan Rice 1509276708 Change activation hook to admin notice. see #19. 2017-03-06 11:01:36 -05:00
Nathan Rice e5c3b527f1 Account for net result empty sidebar ID. 2017-03-03 13:09:34 -05:00
Nathan Rice 6afb3213f7 Account for numeric sidebars. 2017-03-03 10:50:52 -05:00
Nathan Rice dffb99c57b Remove debugging code. 2017-03-03 10:44:09 -05:00
Nathan Rice 49d5cfce79 Include deprecated.php, update readme.txt. 2017-03-01 20:01:43 -05:00
Nathan Rice febb5ede11 Rewrite based on new plugin boilerplate. 2017-03-01 19:51:34 -05:00
Nathan Rice c7fdc4387e Bump version. 2016-06-17 17:04:30 -04:00
Tiago Hillebrandt eff4992b6c ping gitbot 2016-06-13 14:20:36 -05:00
Nathan Rice 97fac5c57b Fix errors associated with variables not being set. see #8, #17. 2016-04-21 11:36:53 -04:00
Nathan Rice 36553a6557 Bump version, update Readme.txt. 2016-02-24 14:54:21 -05:00
Nathan Rice 4d09f1c1ac Update POT. 2016-02-24 14:51:29 -05:00
Nathan Rice 93a304aa06 Update for new term meta handling. 2016-02-24 14:48:19 -05:00
Lauren Mancke 4106eb6c68 Add StudioPress 2016-01-25 14:11:33 -05:00
Nathan Rice be896fd123 Update grunt dependencies. 2015-10-12 16:04:42 -04:00
Nathan Rice e63975e620 Update grunt tasks. 2015-09-29 17:34:15 -04:00
8 changed files with 117 additions and 113 deletions
+12 -9
View File
@@ -74,25 +74,28 @@ class Genesis_Simple_Sidebars {
*/
public function init() {
register_activation_hook( __FILE__, array( $this, 'activation' ) );
$this->load_plugin_textdomain();
add_action( 'admin_notices', array( $this, 'requirements_notice' ) );
$this->includes();
$this->instantiate();
}
/**
* Plugin activation hook. Runs when plugin is activated.
* Show admin notice if minimum requirements aren't met.
*
* @since 2.1.0
*/
public function activation() {
public function requirements_notice() {
if ( ! defined( 'PARENT_THEME_VERSION' ) || ! version_compare( PARENT_THEME_VERSION, $this->min_genesis_version, '>=' ) ) {
deactivate_plugins( plugin_basename( __FILE__ ) );
wp_die( sprintf( __( 'Sorry, you cannot run Genesis Simple Sidebars without WordPress %s and <a href="%s">Genesis %s</a>, or greater.', 'genesis-simple-sidebars' ), $this->min_wp_version, 'http://my.studiopress.com/?download_id=91046d629e74d525b3f2978e404e7ffa', $this->min_genesis_version ) );
$action = defined( 'PARENT_THEME_VERSION' ) ? __( 'upgrade to', 'genesis-simple-sidebars' ) : __( 'install and activate', 'genesis-simple-sidebars' );
$message = sprintf( __( 'Genesis Simple Sidebars requires WordPress %s and Genesis %s, or greater. Please %s the latest version of <a href="%s" target="_blank">Genesis</a> to use this plugin.', 'genesis-simple-sidebars' ), $this->min_wp_version, $this->min_genesis_version, $action, 'http://my.studiopress.com/?download_id=91046d629e74d525b3f2978e404e7ffa' );
echo '<div class="notice notice-warning"><p>' . $message . '</p></div>';
}
@@ -104,7 +107,7 @@ class Genesis_Simple_Sidebars {
* @since 2.1.0
*/
public function load_plugin_textdomain() {
load_plugin_textdomain( $this->plugin_textdomain, false, $this->plugin_dir_path . 'languages/' );
load_plugin_textdomain( $this->plugin_textdomain, false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
}
/**
@@ -114,8 +117,8 @@ class Genesis_Simple_Sidebars {
*/
public function includes() {
//require_once( $this->plugin_dir_path . 'includes/functions.php' );
//require_once( $this->plugin_dir_path . 'includes/deprecated.php' );
require_once( $this->plugin_dir_path . 'includes/functions.php' );
require_once( $this->plugin_dir_path . 'includes/deprecated.php' );
}
@@ -223,6 +223,8 @@ class Genesis_Simple_Sidebars_Admin extends Genesis_Admin_Basic {
// nonce verification
check_admin_referer( 'simple-sidebars-action_create-sidebar' );
$db = (array) get_option( $this->settings_field );
// Change empty or numeric IDs to the name, lowercased and separated by dashes.
if ( empty( $args['id'] ) || is_numeric( $args['id'] ) ) {
$args['id'] = $args['name'];
@@ -231,7 +233,16 @@ class Genesis_Simple_Sidebars_Admin extends Genesis_Admin_Basic {
// Strip all but alphanumeric, sanitize with dashes.
$id = preg_replace( "/[^a-zA-Z0-9 -]+/", "", sanitize_title_with_dashes( $args['id'] ) );
$db = (array) get_option( $this->settings_field );
// Preface numeric IDs with 'sidebar-'.
$id = is_numeric( $id ) ? 'gss-sidebar-' . $id : $id;
// If empty after all the sanitizing ...
if ( ! $id || is_registered_sidebar( $id ) ) {
$n = count( $db ) + 1;
do {
$id = 'gss-sidebar-' . $n++;
} while ( is_registered_sidebar( $id ) );
}
$new = array(
$id => array(
+55 -79
View File
@@ -22,8 +22,18 @@ class Genesis_Simple_Sidebars_Core {
*/
public function init() {
add_action( 'after_setup_theme', array( $this, 'backward_compatibility' ) );
add_action( 'widgets_init', array( $this, 'register_sidebars' ) );
add_action( 'get_header', array( $this, 'swap_sidebars' ) );
add_filter( 'sidebars_widgets', array( $this, 'sidebars_widgets_filter' ) );
}
public function backward_compatibility() {
remove_action( 'genesis_sidebar', 'genesis_do_sidebar' );
add_action( 'genesis_sidebar', 'ss_do_sidebar' );
remove_action( 'genesis_sidebar_alt', 'genesis_do_sidebar_alt' );
add_action( 'genesis_sidebar_alt', 'ss_do_sidebar_alt' );
}
@@ -34,7 +44,7 @@ class Genesis_Simple_Sidebars_Core {
*/
public function register_sidebars() {
$sidebars = Genesis_Simple_Sidebars()->core->get_sidebars();
$sidebars = $this->get_sidebars();
if ( ! $sidebars ) {
return;
@@ -59,98 +69,64 @@ class Genesis_Simple_Sidebars_Core {
}
/**
* Remove default sidebars and inject custom sidebars.
* Filter the widgets in each widget area.
*
* @since 2.1.0
*/
public function swap_sidebars() {
public function sidebars_widgets_filter( $widgets ) {
// Header
if ( is_registered_sidebar( 'header-right' ) ) {
global $wp_registered_sidebars;
$wp_registered_sidebars['ss-header-right-temp'] = $wp_registered_sidebars['header-right'];
unset( $wp_registered_sidebars['header-right'] );
add_action( 'genesis_header_right', array( $this, 'do_header_right' ) );
}
$sidebars = array();
// Sidebars
remove_action( 'genesis_sidebar', 'genesis_do_sidebar' );
remove_action( 'genesis_sidebar_alt', 'genesis_do_sidebar_alt' );
add_action( 'genesis_sidebar', array( $this, 'do_primary_sidebar' ) );
add_action( 'genesis_sidebar_alt', array( $this, 'do_secondary_sidebar' ) );
if ( is_singular() ) {
}
/**
* Output custom header widget area, if one is set. Otherwise output default.
*
* @since 2.1.0
*/
public function do_header_right() {
global $wp_registered_sidebars;
if ( ! $this->do_sidebar( '_ss_header' ) ) {
$wp_registered_sidebars['header-right'] = $wp_registered_sidebars['ss-header-right-temp'];
}
unset( $wp_registered_sidebars['ss-header-right-temp'] );
}
/**
* Output custom primary sidebar, if one is set. Otherwise output default.
*
* @since 2.1.0
*/
public function do_primary_sidebar() {
if ( ! $this->do_sidebar( '_ss_sidebar' ) ) {
genesis_do_sidebar();
}
}
/**
* Output custom secondary sidebar, if one is set. Otherwise output default.
*
* @since 2.1.0
*/
public function do_secondary_sidebar() {
if ( ! $this->do_sidebar( '_ss_sidebar_alt' ) ) {
genesis_do_sidebar_alt();
}
}
/**
* Show widgets in a particular sidebar.
*
* @param string $key sidebar id you wish to output.
*
* @since 2.1.0
*/
public function do_sidebar( $key ) {
if ( is_singular() && $key = genesis_get_custom_field( $key ) ) {
if ( dynamic_sidebar( $key ) ) {
return true;
}
$sidebars = array(
'sidebar' => genesis_get_custom_field( '_ss_sidebar' ),
'sidebar-alt' => genesis_get_custom_field( '_ss_sidebar_alt' ),
'header-right' => genesis_get_custom_field( '_ss_header' ),
);
}
if ( is_tax() || is_category() || is_tag() ) {
if ( $key = get_term_meta( get_queried_object()->term_id, $key, true ) ) {
dynamic_sidebar( $key );
return true;
$sidebars = array(
'sidebar' => get_term_meta( get_queried_object()->term_id, '_ss_sidebar', true ),
'sidebar-alt' => get_term_meta( get_queried_object()->term_id, '_ss_sidebar_alt', true ),
'header-right' => get_term_meta( get_queried_object()->term_id, '_ss_header', true ),
);
}
$widgets = $this->swap_widgets( $widgets, $sidebars );
return $widgets;
}
/**
* Take the $widgets array and swap the contents of each widget area with a custom widget area, if specified.
*
* @since 2.1.0
*/
public function swap_widgets( $widgets, $sidebars ) {
if ( is_admin() ) {
return $widgets;
}
foreach ( (array) $sidebars as $old_sidebar => $new_sidebar ) {
if ( ! is_registered_sidebar( $old_sidebar ) ) {
continue;
}
if ( $new_sidebar && ! empty( $widgets[ $new_sidebar ] ) ) {
$widgets[ $old_sidebar ] = $widgets[ $new_sidebar ];
}
}
return false;
return $widgets;
}
@@ -35,8 +35,6 @@ class Genesis_Simple_Sidebars_Entry {
require_once( Genesis_Simple_Sidebars()->plugin_dir_path . 'includes/views/entry-metabox-content.php' );
print_r( get_post_meta( get_the_ID() ) );
}
/**
+12 -20
View File
@@ -56,28 +56,20 @@ function ss_sidebars_init() {
* @since 0.9.0
* @deprecated 2.1.0
*/
function ss_do_sidebar() {
_deprecated_function( __FUNCTION__, '2.1.0' );
}
function ss_do_one_sidebar( $sidebar_key = '' ) {
/**
* Deprecated.
*
* @since 0.9.0
* @deprecated 2.1.0
*/
function ss_do_sidebar_alt() {
_deprecated_function( __FUNCTION__, '2.1.0' );
}
_deprecated_function( __FUNCTION__, '2.1.0', __( 'dynamic_sidebar() with sidebars_widget filter', 'genesis-simple-sidebars' ) );
if ( '_ss_sidebar' == $sidebar_key ) {
genesis_do_sidebar();
return true;
}
if ( '_ss_sidebar_alt' == $sidebar_key ) {
genesis_do_sidebar_alt();
return true;
}
/**
* Deprecated.
*
* @since 0.9.0
* @deprecated 2.1.0
*/
function ss_do_one_sidebar() {
_deprecated_function( __FUNCTION__, '2.1.0' );
}
/**
+19
View File
@@ -0,0 +1,19 @@
<?php
/**
* Dummy function for backward compatibility. Outputs the primary sidebar.
*
* @since 0.9.0
*/
function ss_do_sidebar() {
genesis_do_sidebar();
}
/**
* Dummy function for backward compatibility. Outputs the secondary sidebar.
*
* @since 0.9.0
*/
function ss_do_sidebar_alt() {
genesis_do_sidebar_alt();
}
+2 -2
View File
@@ -5,8 +5,8 @@ Plugin URI: http://www.studiopress.com/plugins/simple-sidebars
Description: Genesis Simple Sidebars allows you to easily create and use new sidebar widget areas.
Author: Nathan Rice
Author URI: http://www.nathanrice.net/
Author: StudioPress
Author URI: http://www.studiopress.com/
Version: 2.1.0
+5
View File
@@ -39,6 +39,11 @@ Not in the way you're probably thinking. The markup surrounding the widget area
= 2.1.0 =
* Rewrite based on new plugin boilerplate.
* Make ID field readonly, rather than disabled.
* Add header widget area support.
* Allow for empty ID (auto-generate ID from name).
* Allow for only alphanumeric characters in ID.
* Use WordPress native term meta functions.
= 2.0.3 =
* Fix warnings and notices.