Here are two untested ideas:
想法#1:
如果要在
Plugin_Upgrader
创建类时使用:
$upgrader = new Plugin_Upgrader( ... )
其中,通过以下方式激活升级:
$upgrader->upgrade($plugin); // for a single plugin upgrade
$upgrader->bulk_upgrade( $plugins ); // for bulk plugins upgrades
然后您可以尝试:
/**
* Idea #1 - Prior to plugin (bulk or single) upgrades
*/
add_action( \'admin_action_upgrade-plugin\', function() {
add_action( \'check_admin_referer\', \'wpse_referer\', 10, 2 );
});
add_action( \'admin_action_bulk-update-plugins\', function() {
add_action( \'check_admin_referer\', \'wpse_referer\', 10, 2 );
});
function wpse_referer( $action, $result )
{
remove_action( current_filter(), __FUNCTION__, 10 );
if( $result )
{
if( \'bulk-update-plugins\' === $action )
{
// Do stuff before we run the bulk upgrade
}
elseif( \'upgrade-plugin_\' === substr( $action, 0, 15 ) )
{
// Do stuff before we run the single plugin upgrade
}
}
}
如果你想更深入地了解
Plugin_Upgrader
对象,然后您可以尝试劫持
upgrader_pre_install
针对单个升级案例的筛选器:
/**
* Idea #2 - Prior to a single plugin upgrade
*/
add_action( \'admin_action_upgrade-plugin\', function() {
add_action( \'upgrader_pre_install\', \'wpse_upgrader_pre_install\', 99, 2 );
});
function wpse_upgrader_pre_install( $return, $plugin )
{
if ( ! is_wp_error( $return ) )
{
// Do stuff before we run the single plugin upgrade
}
remove_action( current_filter(), __FUNCTION__, 99 );
return $return;
}
同样,您可以劫持
upgrader_clear_destination
批量升级筛选:
/**
* Idea #2 - Prior to bulk plugins upgrade
*/
add_action( \'admin_action_bulk-update-plugins\', function() {
add_action( \'upgrader_clear_destination\', \'wpse_upgrader_clear_destination\', 99, 4 );
});
function wpse_upgrader_clear_destination( $removed, $local_destination,
$remote_destination, $plugin )
{
if ( ! is_wp_error( $removed ) )
{
// Do stuff before we run the bulk plugins upgrades
}
remove_action( current_filter(), __FUNCTION__, 99 );
return $removed;
}
如果可行,希望您可以根据自己的需要进行调整;-)