Support » Fixing WordPress » [WP 6.0.1]upgrader_post_install hook not called

  • Resolved trustring

    (@trustring)


    I’d examined on WP 5.9.7 and WP 6.0.1.

    At first, write like below in a class of some WP plugin’s main PHP file.

    function __construct() {
    	add_filter( 'upgrader_post_install', [ $this, 'check_update' ], 10, 3 );
    }
    
    public function check_update( $response, $hook_extra, $result ) {
    	error_log( 'called' );
    }

    After zipping the plugin including this PHP file, upload and install it to a WP (or updating existing plugin).
    Then a log “called” is output in WP 5.9.7.
    But in WP 6.0.1, the log is not shown.

    I guess this may a bug.
    Could I get your opinon? Thank you.

Viewing 6 replies - 1 through 6 (of 6 total)
  • I can’t reproduce this on my end. I always get an entry in the debug.log or error.log.

    The question is, how is the class initiated? I have used the following minimal example with and without activated debugging:

    class mytest {
        function __construct() {
            add_filter( 'upgrader_post_install', [ $this, 'check_update' ], 10, 3 );
        }
    
        public function check_update( $response, $hook_extra, $result ) {
            error_log( 'called' );
        }
    }
    new mytest();
    Thread Starter trustring

    (@trustring)

    @threadi Oh, really. Sorry for that.
    I’ll investigate the condition for reproducing and write again.
    Thank you!

    Thread Starter trustring

    (@trustring)

    After testing some cases, I have a question.
    “upgrader_post_install” and “upgrader_process_complete” hook is fired on update only in case that the older version plugin has them?

    When a plugin is to be updated and it needs some new options, I think the author will want to add a hook that will be fired on update to the newer version file.
    In those cases, “upgrader_post_install” and “upgrader_process_complete” hook seems not active.

    Is this interpretation right?
    If so, what should we do in such cases?

    If it’s appropriate to talk this in an other topic, I would do so.
    Thanks.

    Both hooks you mention are executed after the upgrade, so by the updated plugin and not by the previous old plugin. See:
    https://developer.wordpress.org/reference/hooks/upgrader_post_install/
    https://developer.wordpress.org/reference/hooks/upgrader_process_complete/

    Thread Starter trustring

    (@trustring)

    Then in my situation, somehow what should work is simply not working.
    In actual, both hooks behaved similar for several times as I wrote in the previous comment…
    For this time, I managed to find a next best way to fill my necessity.

    If I notice the reason I’ll write again.
    Thank you very much!

    Thread Starter trustring

    (@trustring)

    I’ll close this topic since the title thing is understood as not be able to be reproduced.
    Thanks!

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.