0

I am wondering why I am unable to get error_log() to print this to the debug log. error_log() works everywhere else in this class. It does not work inside this function so I believe this function is not running. Here is how I am calling the function (I am using 'init' as the hook in the constructor):

add_filter( 'auto_update_plugin', array( $this, 'l7wau_auto_update_specific_plugins' ), 10, 2 );            

And here is the function in the same class. The error does not get recorded.

    /**
     * Update specific plugins. Got this from Wordpress codex.
     */
    function l7wau_auto_update_specific_plugins( $update, $item ) {

        /**
         * Get the array of slugs to set to auto-update
         */
        $plugins = $this->l7wau_get_array_plugins_to_update();
        error_log( $item->slug );
        if ( in_array( $item->slug, $plugins ) ) {
            return true; // Always update plugins in this array
        } else {
            return $update; // Else, use the normal API response to decide whether to update or not
        }
    }

Just so you have it all here in the init hook in the constructor.

        // Action hook for the update filters
        add_action( 'init', array( $this, 'l7wau_set_auto_updates' ) );

It is also interesting to note that in the function I have the add_filter(). The error_log() function works just fine. Before and after the add_filter is called. It does not work in the callback function though.

0

I found that the add_filter callback function was called but at a much later time. There was a record of it in the debug.log this morning. This means that this filter is only called when the cron is run for automatic updates. This runs every 12 hours and is hard coded into Wordpress core.

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.