From 6f8b1a2069c242d1c8b0e2702938bd8f66831e5d Mon Sep 17 00:00:00 2001 From: Nathan Rice Date: Fri, 10 Mar 2017 14:27:11 -0500 Subject: [PATCH] Modify deprecated functions for backward compatibility. see #22. --- genesis-simple-sidebars.php | 2 +- .../class-genesis-simple-sidebars-core.php | 68 +++++++++---------- includes/deprecated.php | 30 +++----- includes/functions.php | 19 ++++++ plugin.php | 4 +- 5 files changed, 66 insertions(+), 57 deletions(-) create mode 100644 includes/functions.php diff --git a/genesis-simple-sidebars.php b/genesis-simple-sidebars.php index 8e3f574..962ba45 100644 --- a/genesis-simple-sidebars.php +++ b/genesis-simple-sidebars.php @@ -117,7 +117,7 @@ class Genesis_Simple_Sidebars { */ 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' ); } diff --git a/includes/class-genesis-simple-sidebars-core.php b/includes/class-genesis-simple-sidebars-core.php index 5fda384..72766b9 100644 --- a/includes/class-genesis-simple-sidebars-core.php +++ b/includes/class-genesis-simple-sidebars-core.php @@ -22,11 +22,21 @@ 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_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. * @@ -65,23 +75,27 @@ class Genesis_Simple_Sidebars_Core { */ public function sidebars_widgets_filter( $widgets ) { - $sidebars = array( - 'sidebar' => '_ss_sidebar', - 'sidebar-alt' => '_ss_sidebar_alt', - 'header-right' => '_ss_header', - ); + $sidebars = array(); - /** - * Swappable widget areas. - * - * 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. - * - * @since 2.1.0 - * - * @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 ); + if ( is_singular() ) { + + $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() ) { + + $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 ); @@ -100,30 +114,14 @@ class Genesis_Simple_Sidebars_Core { 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 ) ) { continue; } - if ( is_singular() ) { - - $new_sidebar = genesis_get_custom_field( $new_sidebar_key ); - - if ( $new_sidebar && ! empty( $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 ]; - } - + if ( $new_sidebar && ! empty( $widgets[ $new_sidebar ] ) ) { + $widgets[ $old_sidebar ] = $widgets[ $new_sidebar ]; } } diff --git a/includes/deprecated.php b/includes/deprecated.php index ab4cbf4..805e8c8 100644 --- a/includes/deprecated.php +++ b/includes/deprecated.php @@ -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. - * - * @since 0.9.0 - * @deprecated 2.1.0 - */ -function ss_do_one_sidebar() { - _deprecated_function( __FUNCTION__, '2.1.0' ); + if ( '_ss_sidebar' == $sidebar_key ) { + genesis_do_sidebar(); + return true; + } + + if ( '_ss_sidebar_alt' == $sidebar_key ) { + genesis_do_sidebar_alt(); + return true; + } + } /** diff --git a/includes/functions.php b/includes/functions.php new file mode 100644 index 0000000..8112009 --- /dev/null +++ b/includes/functions.php @@ -0,0 +1,19 @@ +