Comment on Display Widgets SEO Plus Plugin by SEO Dave.

Display Widgets WordPress SEO Plus PluginFor the record up until a few days ago (early November 2016) I’d not used the WPML language plugin: I can barely understand my native language (English), so don’t have multiple language sites :-) Since I wanted to conserve as many of the Display Widget version 2.05 features I downloaded a nulled version of the WPML language plugin version 3.5.1.1 (current version is 3.5.3.1) for localhost testing.

So consider I’ve not rigorously tested the WPML language plugin features under multiple environments : I develop WordPress Plugins/Themes in the latest version of WordPress (version 4.6.1 currently) in a localhost environment running PHP 7.0.11 (one of the latest PHP versions). Before public release I also do basic localhost testing in PHP versions PHP 5.3, PHP 5.4 and PHP 5.6.

WordPress Development Testing in Multiple PHP Versions

I then test on live servers with real domains: this is where it tends to go wrong if it’s going to go wrong :-) Since I don’t have any domains running the WPML language plugin my testing is going to be on the minimal side: I’ve started the process of setting up a WPML demo site under the WPML Go-Global Program, so should have a WPML language test site soon. If the Widget Display SEO Plus plugin doesn’t work with WPML exactly how it does for me in localhost you know why. If something doesn’t work I’ll need as much detail as possible, I’m not an expert user of WPML, so not sure how users use it in the real world.

In my WPML testing I did notice a few quirks related to the WPML plugin. For example the WPML language categories were not available in the “Categories +/-” section, so they can’t be selected: not ideal, meant widgets couldn’t be filtered via specific language categories! The issue was WPML hooks into the WordPress core get_categories() function and excludes categories not in the default language. There’s a WPML remove_filter for “terms_clauses”, so when the WPML plugin is active, the Display Widgets SEO Plus Plugin has to remove the filter, run the get_categories() function, re-add the filter:

if ( class_exists( 'SitePress' ) ) {
  if ( empty( $this->cats ) ) {
    global $sitepress;
    remove_filter( 'terms_clauses', array( $sitepress, 'terms_clauses' ) );
    $this->cats = get_categories( array(
      'hide_empty' => false,
    ) );
    add_filter( 'terms_clauses', array( $sitepress, 'terms_clauses' ) );
  }
} else {
  if ( empty( $this->cats ) ) {
    $this->cats = get_categories( array(
      'hide_empty' => false,
    ) );
  }
}

During my tests this works most of the time, but occasionally the language categories aren’t available (don’t know why). Also couldn’t get it to work with WordPress transients, transients are a way to temporarily cache the output of “expensive” functions like get_categories() which don’t change very often.

I expect there’s going to be other quirks with WPML, this is to be expected with highly customized uses of WordPress: WordPress wasn’t designed to work the way the WPML plugin organizes categories etc…

David Law