I'm trying to fire the auto_update_plugins filter to see if I can figure out how to make auto-updates occur more often. I'm using the code below as reference.
NOTE: The below functionality modifies core, while normally this is a bad idea on a production site, this is a test site.
Down The Rabbithole
The Call Stack:
wp_maybe_auto_update()WP_Automatic_Updater::run()WP_Automatic_Updater::update()WP_Automatic_Updater::should_update()auto_update_{$type}
Now, the function wp_maybe_auto_update() ( View on Trac ) can technically be called anywhere by anyone, I'm preferring to run it at the top of my MU-Plugins Folder which starts our journey. This function creates a new WP_Automatic_Updater Object and calls WP_Automatic_Updater::run() ( View on Trac )
Here I had to comment out a couple things to make it so I could run wp_maybe_auto_update() multiple times, otherwise WordPress puts a lock on the database to prevent update collisions.
// Try to lock
// $lock_result = $wpdb->query( $wpdb->prepare( "INSERT IGNORE INTO `$wpdb->options` ( `option_name`, `option_value`, `autoload` ) VALUES (%s, %s, 'no') /* LOCK */", $lock_name, time() ) );
$lock_result = true;
if ( ! $lock_result ) {
$lock_result = get_option( $lock_name );
// If we couldn't create a lock, and there isn't a lock, bail
if ( ! $lock_result )
return;
// Check to see if the lock is still valid
if ( $lock_result > ( time() - HOUR_IN_SECONDS ) )
return;
}
// Update the lock, as by this point we've definitely got a lock, just need to fire the actions
// update_option( $lock_name, time() );
The key notes above is to stop the update lock being written to the database: commenting out the $wpdb->query, turning $lock_result to true so that it doesn't return, and finally commenting out the update_option() at the bottom.
On WP_Automatic_Updater::run() Line:2726 WP checks for plugin updates. I've changed some arbitrary plugin version to fool WordPress into thinking it needs updated which I know works a little later on.
Then, WP_Automatic_Updater::run() Line:2730 calls WP_Automatic_Updater::update() ( View on Trac )
Finally on WP_Automatic_Updater::update() Line:2617 calls WP_Automatic_Updater::should_update() which is where all the update filters run and return either TRUE|FALSE depending. Specifically, WP_Automatic_Updater::should_update() Line:2516
The Problem
From this point, I'm trying to determine why $update is false whenever trying to update plugins. Directly underneath the filter line I have:
if( 'plugin' == $type ) {
print_r( $item );
echo ( $update ) ? 'T R U E' : 'F A L S E';
die();
}
It's almost like it ignores my auto_update_plugins filter so I can only assume I'm in the incorrect place and the filter is also run elsewhere but I haven't found where. With the filter I've tried:
add_filter( 'auto_update_plugin', '__return_true' );
function plugin_update_test() {
return true;
}
add_filter( 'auto_update_plugin', 'plugin_update_test' );
I've even tried to die() inside the filter but nothing. I did a global search through the file structure to see if there were any more instances of that filter but there didn't seem to be. I'm wondering why this filter is returning false even though everything else is pointing to true?
On a sidenote, I tried this on both a custom install and then a Fresh install with the default theme to make sure it wasn't just something unique to my case.
Aucun commentaire:
Enregistrer un commentaire