hey guys, I really need you help with this one.

I'm using the subscribe2 Plugin (for email subscriptions). I want to show the signup form as a widget. The plugin author recommends doing it the following way.

$content = apply_filters('the_content', '<!--subscribe2-->');
$content = remove_filter('the_content', 'page_route');
echo $content;

this works fine, except for the fact that I'm additionally using the mingle plugin (kind of a social network plugin).

Whenever I'm on a page of the mingle plugin (like /login, /register, /activity, etc.) the widget with the subscribe form suddenly displays the exact same content as the pages itself? Just weird!

Any idea why that could happen? Or how I could prevent that! I really need a solution for that!

edit: all filters mingle applies...

add_filter('get_avatar', array($this,'override_avatar'), 10, 4);
add_filter('get_comment_author_url', array($this,'override_author_url'));
add_filter('mngl-show-powered-by', array(&$this, 'show_powered_by'));
add_filter('the_content', array( &$this, 'page_route' ), 100);
add_action('wp_enqueue_scripts', array(&$this, 'load_scripts'), 1);
add_action('admin_enqueue_scripts', array(&$this,'load_admin_scripts'));
register_activation_hook(MNGL_PATH."/mingle.php", array( &$this, 'install' ));

// Used to process standalone requests (make sure mingle_init comes before parse_standalone_request)
add_action('init', array(&$this,'mingle_init'));
add_action('init', array(&$this,'parse_standalone_request'));
add_filter('request', array(&$this,'parse_pretty_profile_url'));

add_action('phpmailer_init', array(&$this, 'set_wp_mail_return_path'));
add_action('phpmailer_init', array(&$this, 'set_wp_mailer'));
add_action('admin_init', array(&$this, 'prevent_admin_access'));

add_filter('mngl-activity-types', array( &$this, 'add_activity_types' ));
add_filter('mngl-notification-types', array( &$this, 'add_notification_types' ));

add_filter('mngl-notification-types', array( $this, 'add_notification_types' ));
add_filter('mngl-activity-types', array( &$this, 'add_activity_types' ));
add_action('user_register', array(&$this, 'add_default_friends') );
add_filter('mngl-activity-types', array( &$this, 'add_activity_types' ));
  • Does echo apply_filters( 'do_shortcode', '<!--subscribe2-->'); give you what you want? If that works, it might be easier than trying to remove all of the extra filters from the_content... Mar 24 '11 at 20:32
  • no, sorry that doesn't work. i already tried apply_filters( 'do_shortcode', '<!--subscribe2-->' and do_shortcode('<!--subscribe2-->'). Non of them is working - I guess because it's not really a shortcode is it? A shortcode is more like [shortcode] which can be placed inside of a normal post. <!--subscribe2--> has to be posted as html so that might be the thing. what do you mean with remove all extra filters? There must be a solution for that. Can you explain why the widget does only show the content of the current page when I'm on a mingle()-specific page? why not on all pages? Mar 24 '11 at 20:53
  • Well, it looks like that mingle plugin is adding its own specific filters to the_content that are triggered on certain pages. You can search through the plugin's source to find out what those filters are, call remove_filter for each of them in your widget. Then be sure to add them back after you're done displaying your widget, otherwise the regular page content will not display correctly on those pages if the widget is rendered before the post content. Mar 24 '11 at 21:01
  • thank you for your help. mingle is only adding one filter to the_content! add_filter('the_content', array( &$this, 'page_route' ), 100); it's adding probably another 15 filters, but always to plugin specific stuff. I edited my post and added the remove_filter line. however if i so so, nothing's printed out in my widget? Mar 24 '11 at 21:25

Its extremely difficult to remove a filter that's added as part of an object. You have get the reference to the original object and pass that as part of the function to remove.

Luckily the filter was added at an unusual priority, so you will probably be safe removing all filters at priority 100:

remove_all_filters( 'the_content', 100 );
$content = apply_filters('the_content', '<!--subscribe2-->');
echo $content;

Just make sure that you don't have anything else essential being added at priority 100...

If you have to find only this specific filter to remove, then I'm out of my depth. Anyone else?


I had to figure this one out, since I've actually wondered for a while how to remove a filter that was passed by reference. In this case the class MnglAppController which adds the filter is initiated as a variable:

$mngl_app_controller           = new MnglAppController();

So to remove it, you have to globalize that variable, and pass it as part of the remove_filter call:

global $mngl_app_controller;
remove_filter( 'the_content', array($mngl_app_controller, 'page_route'), 100 );
$content = apply_filters('the_content', '<!--subscribe2-->');
echo $content;
add_filter( 'the_content', array($mngl_app_controller, 'page_route'), 100 );

I think you have a little error in your code that will prevent it from working:

$content = apply_filters('the_content', '<!--subscribe2-->');
$content = remove_filter('the_content', 'page_route');
echo $content;

The second line:

$content = remove_filter('the_content', 'page_route');

will put TRUE or FALSE into $content.

Just replace it with

$result_remove_filter = remove_filter('the_content', 'page_route');

and try again.

  • when I do so, do I still echo $content or echo the $result_remove_filter? If I echo $result_remove_filter nothing is printed. If I echo $content the behaviour doesn't change - the widget shows the same content as the page itself. I updated my question so you can see what filters mingle is applying. i searched the entire plugin folder for "add_filter" and this is all I found. Mar 24 '11 at 22:11
  • Okay I see. If prints nothing with $result_remove_filter, then the removal of the filter failed (!), nothing printed means acutally FALSE, use var_dump($variable) to get more info what's inside a variable. remove_filter()-Reference (Return Values and their Meaning explained).
    – hakre
    Mar 24 '11 at 22:16
  • You can't remove that filter in that way, because it was added as part of an object. You can remove all filters at that priority, though, or look through the global $wp_filters to find the specific one you want. Mar 24 '11 at 22:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.