Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions includes/class-cherry-include-sidebars.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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();
Expand Down