Filter Since 4.3.0 uncanny-continuing-education-credits

upgrader_package_options

Filter the package options before running an update. See also {@see 'upgrader_process_complete'}. Filters the package options array before an update process begins, allowing modification of update details.

add_filter( 'upgrader_package_options', $callback, 10, 1 );

Description

Filters the options array used for package updates before the update process begins. Developers can modify package, destination, and other update-related settings, including handling specific actions like plugin, theme, or core updates, 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

<?php
/**
 * Modify package options for a plugin update to always clear the destination.
 *
 * This filter allows us to intercept the options passed to the upgrader
 * before it downloads and installs a package. In this example, we're
 * ensuring that the destination directory is always cleared before
 * the new version is installed, which can help prevent issues caused by
 * leftover files from previous versions.
 *
 * @param array $options The current package options for the upgrader.
 * @return array The modified package options.
 */
function my_force_clear_destination_on_plugin_update( $options ) {
    // Check if this is a plugin update and if clear_destination is not already true.
    // The 'hook_extra' array contains details about the update type.
    if ( isset( $options['hook_extra']['type'] ) && 'plugin' === $options['hook_extra']['type'] ) {
        // Force clear_destination to true if it's a plugin update.
        $options['clear_destination'] = true;
    }

    // Always return the options array, even if no modifications were made.
    return $options;
}
add_filter( 'upgrader_package_options', 'my_force_clear_destination_on_plugin_update', 10, 1 );

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

src/install-automator/vendor/uncanny-one-click-installer/includes/PluginSilentUpgrader.php:108

*                                            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.

Scroll to Top