Filter
Since 4.3.0
uncanny-automator-pro
upgrader_package_options
Filter the package options before running an update. See also {@see 'upgrader_process_complete'}. Filters the package options array before a WordPress update process begins, allowing modification of update parameters.
add_filter( 'upgrader_package_options', $callback, 10, 1 );
Description
Filters the options array before an update package is processed. This allows developers to modify package details, destination, clearing behavior, and abort conditions for plugins, themes, or core updates, including multi-update scenarios and language pack updates.
Usage
add_filter( 'upgrader_package_options', 'your_function_name', 10, 1 );
Parameters
-
$options(array) - { Options used by the upgrader. Extra hook arguments. or 'core'.
Return Value
The filtered value.
Examples
// Prevent automatic updates for a specific plugin, e.g., "my-custom-plugin/my-custom-plugin.php"
add_filter( 'upgrader_package_options', 'my_prevent_specific_plugin_update', 10, 1 );
function my_prevent_specific_plugin_update( $options ) {
// Check if the update is for a plugin and if it's the one we want to block.
// The 'plugin' key in $options['hook_extra'] contains the plugin slug.
if ( isset( $options['hook_extra']['type'] ) && 'plugin' === $options['hook_extra']['type'] &&
isset( $options['hook_extra']['plugin'] ) && 'my-custom-plugin/my-custom-plugin.php' === $options['hook_extra']['plugin'] ) {
// If it's the target plugin, abort the update by returning an error.
// This will display an error message to the user instead of proceeding with the update.
return new WP_Error( 'my_plugin_update_blocked', __( 'Automatic updates for My Custom Plugin are disabled.', 'text-domain' ) );
}
// For all other updates, return the original options array to allow the update to proceed.
return $options;
}
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
uncanny-automator-pro/src/core/admin/installer/includes/class-upgrader.php:107
* or 'core'.
* @type object $language_update The language pack update offer.
* }
* }
* @since 4.3.0
*
*/
$options = apply_filters( 'upgrader_package_options', $options );
if ( ! $options['is_multi'] ) {
// call $this->header separately if running multiple times.
$this->skin->header();
}
// Connect to the Filesystem first.