WPML minor compatibility issue

Hello Themeco,
Thanks for the 2.5 update, it’s really great!

We have a slight issue that seems to be known (by WPML) regarding recent posts.
We found the issue documented by WPML here: https://wpml.org/errata/x-theme-all-post-links-in-the-recent-posts-widget-links-to-the-same-page/

Is there a more permanent option to fix the problem? Upon updating the theme, it overwrote the modification.

Can we add that class-wpml.php file be edited through the child theme? Or that won’t work?

Thank you!

Hey @magikweb,

Please try adding this code in functions.php.

add_action('after_setup_theme', 'fix_wpml_permalink_conflict', 999);

function fix_wpml_permalink_conflict() {
  remove_filter( 'the_permalink', array( $this, 'filter_permalink' ) );
}

If that does not work, please follow the advice in the WPML thread.

Thanks.

1 Like

Thank you @christian_y,
We gave it a shot, but had to remove it because some sites (WPMU) do not have WPML and it was causing a fatal error (500).

How would you wrap it to check if WPML exists first to avoid this issue?

Hello @magikweb,

You can update the code with this instead to check if WPML is active:

 add_action('after_setup_theme', 'fix_wpml_permalink_conflict', 999);

function fix_wpml_permalink_conflict() {
  if ( function_exists('icl_object_id') ) {
    remove_filter( 'the_permalink', array( $this, 'filter_permalink' ) );
  }
}

We would loved to know if this has work for you. Thank you.

I think it’s close to it!
We are now getting the following error:

Fatal error: Uncaught Error: Using $this when not in object context in /home/magikwe1/public_html/wp-content/themes/pro-child/functions.php:89 Stack trace: #0 /home/magikwe1/public_html/wp-includes/class-wp-hook.php(286): fix_wpml_permalink_conflict('') #1 /home/magikwe1/public_html/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters(NULL, Array) #2 /home/magikwe1/public_html/wp-includes/plugin.php(465): WP_Hook->do_action(Array) #3 /home/magikwe1/public_html/wp-settings.php(489): do_action('after_setup_the...') #4 /home/magikwe1/public_html/wp-config.php(115): require_once('/home/magikwe1/...') #5 /home/magikwe1/public_html/wp-load.php(37): require_once('/home/magikwe1/...') #6 /home/magikwe1/public_html/wp-admin/admin.php(34): require_once('/home/magikwe1/...') #7 /home/magikwe1/public_html/wp-admin/plugins.php(10): require_once('/home/magikwe1/...') #8 {main} thrown in /home/magikwe1/public_html/wp-content/themes/pro-child/functions.php on line 89

Hello @magikweb,

Could you please post the entire contents of your child theme’s functions.php file?
We’d like to find out which is the line causing the error above.

Thank you in advance.

Hello RueNel,
This should do it I think, the error is related to the $this and its context.

Please try removing $this, as Ruenel suggested. If that doesn’t still work. Please comment out the line in cornerstone/includes/classes/components/class-wpml.php as suggested in the WPML thread.

I’m sorry I forgot to say that this was a known bug that does yet have a permanent fix and it really should be fixed in the mentioned PHP file rather than removing filter or other methods. The suggestions we gave was just an attempt. We can’t continue on fixing the bug immediately as part of product support.

Thanks.

1 Like

I confirm that it works without the $this and its array. If anyone else encounters the issue, here is the fix:

// Fix WPML compatibility for the recent posts' issue
add_action('after_setup_theme', 'fix_wpml_permalink_conflict', 999);

function fix_wpml_permalink_conflict() {
  if ( function_exists('icl_object_id') ) {
    remove_filter( 'the_permalink', 'filter_permalink' );
  }
}

Glad to hear it’s working now.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.