From 908ca6617a8cebcd587a2b25493345541f5d7a57 Mon Sep 17 00:00:00 2001 From: mjhead Date: Mon, 21 Nov 2016 13:10:58 +0200 Subject: [PATCH 1/2] UPD: better WPML-compatibility --- includes/class-cherry-include-sidebars.php | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/includes/class-cherry-include-sidebars.php b/includes/class-cherry-include-sidebars.php index 18935fc..9a390a0 100644 --- a/includes/class-cherry-include-sidebars.php +++ b/includes/class-cherry-include-sidebars.php @@ -39,9 +39,37 @@ class Cherry_Include_Sidebars { * @return void */ public function __construct() { + add_filter( 'cherry_sidebar_manager_object_id', array( $this, 'fix_wpml_id' ) ); add_filter( 'sidebars_widgets', array( $this, 'set_custom_sidebar' ), 10, 1 ); } + /** + * If is WPML - try to get original language ID> + * + * @param int $object_id Current object ID. + * @return void + */ + public function fix_wpml_id( $object_id = null ) { + + if ( ! is_singular() ) { + return $object_id; + } + + if ( ! class_exists( 'SitePress' ) ) { + return $object_id; + } + + global $sitepress; + $id = icl_object_id( get_the_id(), get_post_type(), true, $sitepress->get_default_language() ); + + if ( $id ) { + return $id; + } else { + return $object_id; + } + + } + /** * Set custom sidebar in global array $wp_registered_sidebars. * @@ -66,6 +94,10 @@ public function set_custom_sidebar( $widgets ) { $post_sidebars = get_post_meta( apply_filters( 'cherry_sidebar_manager_object_id', $object_id ), 'post_sidebar', true ); + if ( ! empty( $post_sidebars ) && is_string( $post_sidebars ) ) { + $post_sidebars = maybe_unserialize( $post_sidebars ); + } + if ( $post_sidebars && ! empty( $post_sidebars ) ) { $instance = new Cherry_Sidebar_Utils(); From d0e5c79a1f3eb4055ecddc55a08628d846cd3019 Mon Sep 17 00:00:00 2001 From: mjhead Date: Mon, 21 Nov 2016 13:22:40 +0200 Subject: [PATCH 2/2] FIX: Travis CI --- includes/class-cherry-include-sidebars.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/class-cherry-include-sidebars.php b/includes/class-cherry-include-sidebars.php index 9a390a0..0625a20 100644 --- a/includes/class-cherry-include-sidebars.php +++ b/includes/class-cherry-include-sidebars.php @@ -47,7 +47,7 @@ public function __construct() { * If is WPML - try to get original language ID> * * @param int $object_id Current object ID. - * @return void + * @return int */ public function fix_wpml_id( $object_id = null ) {