Compatability with Disable Comments Plugin

Hi,
I am using the extremely popular Disable Comments plugin on my site. After installing your theme though, I now see this warning (when debug mode is on):

Notice: Undefined index: WP_Widget_Recent_Comments in /var/www/wp-content/themes/x/framework/functions/setup.php on line 213

This arises because Disable Comments prevents the file that defines WP_Widget_Recent_Comments from being require_onced.

Is there any way you can modify your x_remove_recent_comments_style function to return immediately if !key_exists('WP_Widget_Recent_Comments', $wp_widget_factory->widgets)?

As Disable Comments has over 1 million active users, I would imagine I won’t be the only person to run into this, and it’s an exceedingly simple fix.

Thanks

Hi Louis,

Thanks for reaching out.

Sure, you could do that. The function is pluggable and can be added to child theme’s functions.php with your own customization.

Add this with your own modification,

  function x_remove_recent_comments_style() {
    GLOBAL $wp_widget_factory;
    remove_action( 'wp_head', array( $wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style' ) );
  }
  add_action( 'widgets_init', 'x_remove_recent_comments_style' );

Pluggable functions are the one with function_exists() that prevents the existence of multiple but same function name.

Thanks!

Uhh, I know I can do that. I’m asking you to do that, because your code should work out of the box. I don’t have a child theme at the moment.
It would be nice if you could change the code to:

if ( ! function_exists( 'x_remove_recent_comments_style' ) ) :
  GLOBAL $wp_widget_factory;
  if (!array_key_exists('WP_Widget_Recent_Comments', $wp_widget_factory->widgets)) return;
  function x_remove_recent_comments_style() {
    GLOBAL $wp_widget_factory;
    remove_action( 'wp_head', array( $wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style' ) );
  }
  add_action( 'widgets_init', 'x_remove_recent_comments_style' );
endif;

Hello Louis,

The correct code should be:

if ( ! function_exists( 'x_remove_recent_comments_style' ) ) :
  function x_remove_recent_comments_style() {
    GLOBAL $wp_widget_factory;

  	if (!array_key_exists('WP_Widget_Recent_Comments', $wp_widget_factory->widgets)) {
  		return;
  	}
  	
    remove_action( 'wp_head', array( $wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style' ) );
  }
  add_action( 'widgets_init', 'x_remove_recent_comments_style' );
endif;

Yes, our developers has been informed about this issue to eliminate the PHP notice.

Thank you.

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