WordPress.org

Ready to get started?Download WordPress

Forums

Live Blogging
[resolved] [Bug+fix] Unhooking of filters not working for class methods (9 posts)

  1. jrf
    Member
    Posted 1 year ago #

    L.S.,

    I encountered a quite annoying oversight in the offered 'unhooking of filters'-functionality.

    The Live-blogging plugin poses that it provides a way to unhook filters from the_content. However, it only allow for unhooking of global namespace functions, not for the unhooking of class methods - which is the more commonly used/preferred way of building plugins-.

    I've rewritten the relevant code to allow for both functions and class methods.

    You will need to replace the function live_blogging_get_entry() in the
    /wp-content/plugins/live-blogging/live-blogging.php file (line 1068 - line 1110 in v2.2.6) with the code I provide you with here:
    http://pastebin.com/H9q2je9Z

    Once the function has been replaced, the user can add the following to the Live Blogging Settings -> Advanced Settings to make the unhooking work for class method:
    class_object_variable_name, method_name
    where class_object_variable_name is the variable name of the instantiatied object in the global namespace.

    Hope this helps & that you will include this fix in the next version of the plugin.

    Smile,
    Juliette

    http://wordpress.org/extend/plugins/live-blogging/

  2. chrisnorthwood
    Member
    Plugin Author

    Posted 11 months ago #

    Hi jrf,

    If you want to raise this as a pull request (the code has changed significantly since what you've posted above) I can merge this in: https://github.com/cnorthwood/liveblogging

    Thanks

  3. jrf
    Member
    Posted 11 months ago #

    Hi Chris,

    Pull request has been send ;-)

  4. chrisnorthwood
    Member
    Plugin Author

    Posted 11 months ago #

    And merged, thanks!

  5. jrf
    Member
    Posted 11 months ago #

    Excellent! Thanks ;-)

  6. rlg
    Member
    Posted 10 months ago #

    Can I get an example of using:
    class_object_variable_name, method_name

    The add filter line for the Send to Kindle Plugin looks like this:
    add_filter( 'the_content', array( $this, 'attach_to_content' ) );

    I cannot get it to work.

  7. jrf
    Member
    Posted 10 months ago #

    @rlg,

    Looks like my code did get merged with the development code @ Github, but has not been released yet, so it will only work if you download the latest version of the plugin from GitHub.

    Secondly, the Send to Kindle Plugin does not instantiate their class with a variable in the global namespace, so I can see your problem.

    You could make it work, but you'd need to edit the Send to Kindle plugin to do so.

    At the bottom of their send-to-kindle.php file, look for the following code:

    function STK_loader() {
            $kindle_loader = STK_Button::get_instance();
            include_once( dirname( __FILE__ ) . '/jetpack.php' );
    }
    
    add_action( 'init', 'STK_loader' );

    And replace the second line with:

    $GLOBALS['kindle_loader'] = STK_Button::get_instance();

    If you do that *and* use the latest version of the Liveblogging plugin downloaded from GitHub, you could then unhook it by adding the following to the settings:

    kindle_loader, attach_to_content

    Hope this helps!

    Smile,
    Juliette

  8. rlg
    Member
    Posted 10 months ago #

    Hi Juliette,

    I did not download from github, but copied your code from the pastebin link above.

    Anyway, thank you for your kindess and swift response, the mod worked like a charm! I was trying to do something like above, but had the incorrect syntax, thanks for teaching me something new.

  9. jrf
    Member
    Posted 10 months ago #

    You're very welcome, glad to hear it works ;-)

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic