diff --git a/includes/class-cherry-include-sidebars.php b/includes/class-cherry-include-sidebars.php index 18935fc..0625a20 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 int + */ + 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();