Modify deprecated functions for backward compatibility. see #22.

This commit is contained in:
Nathan Rice
2017-03-10 14:27:11 -05:00
parent 7b439c95a7
commit 6f8b1a2069
5 changed files with 66 additions and 57 deletions
+1 -1
View File
@@ -117,7 +117,7 @@ class Genesis_Simple_Sidebars {
*/ */
public function includes() { public function includes() {
//require_once( $this->plugin_dir_path . 'includes/functions.php' ); 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/deprecated.php' );
} }
+29 -31
View File
@@ -22,11 +22,21 @@ class Genesis_Simple_Sidebars_Core {
*/ */
public function init() { public function init() {
add_action( 'after_setup_theme', array( $this, 'backward_compatibility' ) );
add_action( 'widgets_init', array( $this, 'register_sidebars' ) ); add_action( 'widgets_init', array( $this, 'register_sidebars' ) );
add_filter( 'sidebars_widgets', array( $this, 'sidebars_widgets_filter' ) ); 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' );
}
/** /**
* Take created sidebars and register them with WordPress. * Take created sidebars and register them with WordPress.
* *
@@ -65,23 +75,27 @@ class Genesis_Simple_Sidebars_Core {
*/ */
public function sidebars_widgets_filter( $widgets ) { public function sidebars_widgets_filter( $widgets ) {
$sidebars = array();
if ( is_singular() ) {
$sidebars = array( $sidebars = array(
'sidebar' => '_ss_sidebar', 'sidebar' => genesis_get_custom_field( '_ss_sidebar' ),
'sidebar-alt' => '_ss_sidebar_alt', 'sidebar-alt' => genesis_get_custom_field( '_ss_sidebar_alt' ),
'header-right' => '_ss_header', 'header-right' => genesis_get_custom_field( '_ss_header' ),
); );
/** }
* Swappable widget areas.
* if ( is_tax() || is_category() || is_tag() ) {
* An array of original widget area => GSS key for new sidebar. Can be used to add or remove widget areas from being
* swappable in the Genesis Simple Sidebars admin. $sidebars = array(
* 'sidebar' => get_term_meta( get_queried_object()->term_id, '_ss_sidebar', true ),
* @since 2.1.0 '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 ),
* @param array $sidebars Array of widget areas that can be swapped, with the keys used to find the ID of the new widget area to swap in. );
*/
$sidebars = apply_filters( 'genesis_simple_sidebars_widget_areas', $sidebars ); }
$widgets = $this->swap_widgets( $widgets, $sidebars ); $widgets = $this->swap_widgets( $widgets, $sidebars );
@@ -100,34 +114,18 @@ class Genesis_Simple_Sidebars_Core {
return $widgets; return $widgets;
} }
foreach ( (array) $sidebars as $old_sidebar => $new_sidebar_key ) { foreach ( (array) $sidebars as $old_sidebar => $new_sidebar ) {
if ( ! is_registered_sidebar( $old_sidebar ) ) { if ( ! is_registered_sidebar( $old_sidebar ) ) {
continue; continue;
} }
if ( is_singular() ) {
$new_sidebar = genesis_get_custom_field( $new_sidebar_key );
if ( $new_sidebar && ! empty( $widgets[ $new_sidebar ] ) ) { if ( $new_sidebar && ! empty( $widgets[ $new_sidebar ] ) ) {
$widgets[ $old_sidebar ] = $widgets[ $new_sidebar ]; $widgets[ $old_sidebar ] = $widgets[ $new_sidebar ];
} }
} }
if ( is_tax() || is_category() || is_tag() ) {
$new_sidebar = get_term_meta( get_queried_object()->term_id, $new_sidebar_key, true );
if ( $new_sidebar && ! empty( $widgets[ $new_sidebar ] ) ) {
$widgets[ $old_sidebar ] = $widgets[ $new_sidebar ];
}
}
}
return $widgets; return $widgets;
} }
+11 -19
View File
@@ -56,28 +56,20 @@ function ss_sidebars_init() {
* @since 0.9.0 * @since 0.9.0
* @deprecated 2.1.0 * @deprecated 2.1.0
*/ */
function ss_do_sidebar() { function ss_do_one_sidebar( $sidebar_key = '' ) {
_deprecated_function( __FUNCTION__, '2.1.0' );
}
/**
* 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' );
}
/** if ( '_ss_sidebar' == $sidebar_key ) {
* Deprecated. genesis_do_sidebar();
* return true;
* @since 0.9.0 }
* @deprecated 2.1.0
*/ if ( '_ss_sidebar_alt' == $sidebar_key ) {
function ss_do_one_sidebar() { genesis_do_sidebar_alt();
_deprecated_function( __FUNCTION__, '2.1.0' ); return true;
}
} }
/** /**
+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. Description: Genesis Simple Sidebars allows you to easily create and use new sidebar widget areas.
Author: Nathan Rice Author: StudioPress
Author URI: http://www.nathanrice.net/ Author URI: http://www.studiopress.com/
Version: 2.1.0 Version: 2.1.0