Finding code which governs a crucial part of my site .. Help!

Current Wordpress project is supported by the infamous Mystique template (http://digitalnature.eu/themes/mystique/) and the premium WPML (multilingual) plugin.

The WPML and the template aren’t playing nice together. For those who don’t know: WPML generates ghost pages and posts without actually cluttering your pages with translations. It’s a wonderful tool for running a mulitlingual WP. Each translated post and page gets an individual page_id and as an URL it is ‘put’ in a ghost folder such as /en/ for English, etc.

In Mystique, each widget can be made visible on specific pages which is wonderful. Less wonderful is that it only shows English pages and not the translated pages as options, so I can’t show translated widgets in pages of their own language. The same problem persists with the slider, which is not a widget, but a theme option.

http://www.grayscale.com.hk/images/wpml.png

This list appears underneath each widget area in Wordpress, but I can’t find it back in any of the widget php files.

I’ve been digging through all the PHP files, which for an extensive theme weren’t many. There is this list of files:

http://www.grayscale.com.hk/images/phphelp01.png

I’ve looked through all remotely related files, but none of them refer to the field I’m looking for.

Digging through functions.php gave noreferences to widget visibility. The entire functions.php is here: http://www.grayscale.com.hk/images/functions.txt

One very beefy file, Atom.php, contains references to widget visibility but nothing more than that, and certainly leaving me no ideas where to configure my widgets to also list translated pages.

I’ve copypasted some relevant codes (I think) from Atom.php here:

[php]
/**

  • Get the status of a widgetized area (replaces wp’s is_active_sidebar)
  • This function also verifies if the widgets inside the sidebar are visible to the current user or not (splitters are ignored)
  • Note: If we’re in preview mode areas are always considered to be active, but the returned widget count may be 0 (boolean false).
  • (we use type equivalence checking to avoid confusions)
  • @since 1.0
  • @global $wp_registered_widgets Stored registered widgets.
  • @global $post Current post object
  • @param string $index Area (sidebar) ID
  • @return int|bool false or the visible widget count, based on widget visibility settings and current user status
    */
    public function isAreaActive($index){
    global $wp_registered_widgets, $post;
// always return true if the layout options are not enabled. obviously, the css designer wants to handle this
if(!$this->isOptionEnabled('layout')) return true;

// -- same as getLayoutType() --
if(is_404()){
  $layout = 'c1'; // 404 pages have 1 column layout
}else{
  // the "layout" custom field - highest priority
  if(isset($post->ID)) $layout = get_post_meta($post->ID, 'layout', true);

  // custom page templates - lower priority
  if(empty($layout) && (is_single() || is_page()) && ($page_template = sanitize_html_class(str_replace(array('page-', '.php'), '', get_post_meta($post->ID, '_wp_page_template', true)))))
    if(in_array($page_template, $this->layout_types)) $layout = $page_template;

  // if no template is defined so far, revert to the global layout option from the theme settings - lowest priority
  if(empty($layout)) $layout = $this->options('layout');
}
// -- /same as getLayoutType() --

$index = (is_int($index)) ? "sidebar{$index}" : sanitize_html_class($index);
$sidebars_widgets = wp_get_sidebars_widgets();

$visible_widgets = 0;

// only check widget settings if we have widgets in this sidebar
if(!empty($sidebars_widgets[$index]))
  foreach($sidebars_widgets[$index] as $i => $w)
    if(isset($wp_registered_widgets[$w])){
      $number = $wp_registered_widgets[$w]['params'][0]['number'];


      $callback = AtomWidget::getObject($w);
      if(!$callback) continue;

      $options = get_option($callback->option_name);

      // count only visible widgets that are not "splitters"
      // @important atom_visibility_check() can also return array(), which means that the widget is there but it's settings are missing (like fallback widgets)
      if((strpos($w, 'atom-splitter') === false) && atom_visibility_check($options[$number]) !== false) $visible_widgets++;
    }


// always show active if we're in preview mode (eg. theme setting site preview), regardless of the contents
if(Atom::app()->previewMode()) return $visible_widgets;

// check free column(s) for sidebar(s)
if($index === 'sidebar1' && $layout === 'c1') return false;
if($index === 'sidebar2' && in_array($layout, array('c1', 'c2left', 'c2right'))) return false;

// get sidebar contents
$first_check = false;
if(!isset($this->widget_areas[$index]['output'])){
  ob_start();
  dynamic_sidebar($index);
  $this->widget_areas[$index]['output'] = ob_get_clean();
  $first_check = true;
}

[/php]

And this is the entire Atom.php : http://www.grayscale.com.hk/images/Atom.txt

And that’s pretty much it. Naturally I’ve contacted the theme builder but he’s not responsive. I’ve contacted WPML and they’ll gladly cooperate with the theme builder, who’s not responsive. I’m trapped in the middle with a finished website which I can’t make work if the widgets aren’t translated. This bit of code is really really crucial to me.

I’d much appreciate any constructive suggestion… Thanks in advance for reading!

Hi,

How does Wordpress / WPML know which language to use? Does it use a specific URL, e.g. /en/ or /de/?

Also, how do you load the widgets for Mystique? Do you have to specify which language to use when you load it?

My idea would be to change the loading code so that it gets the correct language from WPML then displays it.

hey, thanks for responding. WPML gives each subsequent language a different URL like you said. When I disable WPML, the pages in different languages become visible - so I think you’re right, but I’m not sure what the next step would be.

I’m not sure how to answer the question about the widgets - they’re simply there through the Atom framework belonging to Mystique.

Do the widgets support multiple languages?

Not inherently, that’s why I’ll need to tweak the code. Hence my quest to the code that lists all the possible pages so I can somehow add all the translated pages as well.

So are you trying to get the widgets to use pages that your language plugin hides?

yeah - the odd thing is that WPML encourages any other plugin or template to cooperate, so I wouldn’t say that WPML hides them. It’s more that WPML renders them unrecognizable as such.

I discovered a temporary solution:

If I disable the WPML plugin, all the translated pages become visible as well. I can then select which widget should appear on which page. If I then enable WPML again, the settings remain and the widgets are properly governed.

It’s a little tricky because it means whenever a new blog post is made, I need to do the WPML shuffle again, so I’m still hopeful for a more permanent solution…

I’m sorry that I couldn’t be of more help but happy that you found a solution - even though temporary one. This is the kind of issue that, without cooperation from both developers, is very hard to solve. Congratulations on finding a solution though!

Sponsor our Newsletter | Privacy Policy | Terms of Service