wppaste
WordPress

Plugin_Installer_Skin::do_overwrite(): bool

Since
5.5.0
Source
wp-admin/includes/class-plugin-installer-skin.php:192
Checks if the plugin can be overwritten and outputs the HTML for overwriting a plugin on upload.

Compatibility

WordPress
since 5.5.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Return value

bool
Whether the plugin can be overwritten and HTML was outputted.

Performance profile

How much work a call to Plugin_Installer_Skin::do_overwrite() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Moderate

Only touches the object cache, via wp_cache_get().

Scaling
Scales with input

The body loops, so the work grows with how much data it finds.

Instructions
4–257

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 330.

Plugin surface
2 hooks

Third-party callbacks on 'install_plugin_overwrite_comparison', 'install_plugin_overwrite_actions' run inside this call, and their cost is not bounded by anything here.

Called by
1

1 place in core call this, so the cost is paid more often than your own code shows.

What it touches

  • hookthird-party callbacksapply_filters()called directly
  • cacheobject cachewp_cache_get()one call below Plugin_Installer_Skin::do_overwrite()

Further down the call graph this can also reach option, serialize, query and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 20 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost Plugin_Installer_Skin::do_overwrite() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
always4none
!is_wp_error()10is_wp_error()
is_wp_error()15is_wp_error(), ->get_error_code()
is_wp_error()37–39is_wp_error(), ->get_error_code(), ->get_error_data(), ltrim(), get_plugins()
is_wp_error() && is_php_version_compatible() && is_wp_version_compatible() && empty($install_actions)160–164is_wp_error(), ->get_error_code(), ->get_error_data(), ltrim(), get_plugins(), esc_html__(), version_compare(), __(), __(), __(), __(), __(), esc_html_x(), esc_html_x(), apply_filters(), esc_html__(), is_php_version_compatible(), is_wp_version_compatible(), add_query_arg(), wp_nonce_url(), __(), apply_filters()
is_wp_error() && is_php_version_compatible() && is_wp_version_compatible() && !empty($install_actions)172–176is_wp_error(), ->get_error_code(), ->get_error_data(), ltrim(), get_plugins(), esc_html__(), version_compare(), __(), __(), __(), __(), __(), esc_html_x(), esc_html_x(), apply_filters(), esc_html__(), is_php_version_compatible(), is_wp_version_compatible(), add_query_arg(), wp_nonce_url(), __(), apply_filters(), __(), printf()
is_wp_error() && !is_php_version_compatible() && is_wp_version_compatible() && empty($install_actions)176–180is_wp_error(), ->get_error_code(), ->get_error_data(), ltrim(), get_plugins(), esc_html__(), version_compare(), __(), __(), __(), __(), __(), esc_html_x(), esc_html_x(), apply_filters(), esc_html__(), is_php_version_compatible(), __(), sprintf(), esc_html(), is_wp_version_compatible(), add_query_arg(), wp_nonce_url(), __(), apply_filters()
is_wp_error() && is_php_version_compatible() && !is_wp_version_compatible() && empty($install_actions)181–185is_wp_error(), ->get_error_code(), ->get_error_data(), ltrim(), get_plugins(), esc_html__(), version_compare(), __(), __(), __(), __(), __(), esc_html_x(), esc_html_x(), apply_filters(), esc_html__(), is_php_version_compatible(), is_wp_version_compatible(), __(), wp_get_wp_version(), esc_html(), sprintf(), esc_html(), add_query_arg(), wp_nonce_url(), __(), apply_filters()
is_wp_error() && !is_php_version_compatible() && is_wp_version_compatible() && !empty($install_actions)188–192is_wp_error(), ->get_error_code(), ->get_error_data(), ltrim(), get_plugins(), esc_html__(), version_compare(), __(), __(), __(), __(), __(), esc_html_x(), esc_html_x(), apply_filters(), esc_html__(), is_php_version_compatible(), __(), sprintf(), esc_html(), is_wp_version_compatible(), add_query_arg(), wp_nonce_url(), __(), apply_filters(), __(), printf()
is_wp_error() && is_php_version_compatible() && !is_wp_version_compatible() && !empty($install_actions)193–197is_wp_error(), ->get_error_code(), ->get_error_data(), ltrim(), get_plugins(), esc_html__(), version_compare(), __(), __(), __(), __(), __(), esc_html_x(), esc_html_x(), apply_filters(), esc_html__(), is_php_version_compatible(), is_wp_version_compatible(), __(), wp_get_wp_version(), esc_html(), sprintf(), esc_html(), add_query_arg(), wp_nonce_url(), __(), apply_filters(), __(), printf()
is_wp_error() && !is_php_version_compatible() && !is_wp_version_compatible() && empty($install_actions)197–201is_wp_error(), ->get_error_code(), ->get_error_data(), ltrim(), get_plugins(), esc_html__(), version_compare(), __(), __(), __(), __(), __(), esc_html_x(), esc_html_x(), apply_filters(), esc_html__(), is_php_version_compatible(), __(), sprintf(), esc_html(), is_wp_version_compatible(), __(), wp_get_wp_version(), esc_html(), sprintf(), esc_html(), add_query_arg(), wp_nonce_url(), __(), apply_filters()
is_wp_error() && is_php_version_compatible() && is_wp_version_compatible() && empty($install_actions)202–208is_wp_error(), ->get_error_code(), ->get_error_data(), ltrim(), get_plugins(), esc_html__(), version_compare(), __(), __(), __(), __(), __(), esc_html_x(), esc_html_x(), apply_filters(), esc_html__(), is_php_version_compatible(), is_wp_version_compatible(), __(), __(), sprintf(), add_query_arg(), wp_nonce_url(), _x(), add_query_arg(), wp_nonce_url(), __(), apply_filters()
8 further outcomes, up to 257 instructions
is_wp_error() && !is_php_version_compatible() && !is_wp_version_compatible() && !empty($install_actions)209–213is_wp_error(), ->get_error_code(), ->get_error_data(), ltrim(), get_plugins(), esc_html__(), version_compare(), __(), __(), __(), __(), __(), esc_html_x(), esc_html_x(), apply_filters(), esc_html__(), is_php_version_compatible(), __(), sprintf(), esc_html(), is_wp_version_compatible(), __(), wp_get_wp_version(), esc_html(), sprintf(), esc_html(), add_query_arg(), wp_nonce_url(), __(), apply_filters(), __(), printf()
is_wp_error() && is_php_version_compatible() && is_wp_version_compatible() && !empty($install_actions)214–220is_wp_error(), ->get_error_code(), ->get_error_data(), ltrim(), get_plugins(), esc_html__(), version_compare(), __(), __(), __(), __(), __(), esc_html_x(), esc_html_x(), apply_filters(), esc_html__(), is_php_version_compatible(), is_wp_version_compatible(), __(), __(), sprintf(), add_query_arg(), wp_nonce_url(), _x(), add_query_arg(), wp_nonce_url(), __(), apply_filters(), __(), printf()
is_wp_error() && !is_php_version_compatible() && is_wp_version_compatible() && empty($install_actions)218–224is_wp_error(), ->get_error_code(), ->get_error_data(), ltrim(), get_plugins(), esc_html__(), version_compare(), __(), __(), __(), __(), __(), esc_html_x(), esc_html_x(), apply_filters(), esc_html__(), is_php_version_compatible(), __(), sprintf(), esc_html(), is_wp_version_compatible(), __(), __(), sprintf(), add_query_arg(), wp_nonce_url(), _x(), add_query_arg(), wp_nonce_url(), __(), apply_filters()
is_wp_error() && is_php_version_compatible() && !is_wp_version_compatible() && empty($install_actions)223–229is_wp_error(), ->get_error_code(), ->get_error_data(), ltrim(), get_plugins(), esc_html__(), version_compare(), __(), __(), __(), __(), __(), esc_html_x(), esc_html_x(), apply_filters(), esc_html__(), is_php_version_compatible(), is_wp_version_compatible(), __(), wp_get_wp_version(), esc_html(), sprintf(), esc_html(), __(), __(), sprintf(), add_query_arg(), wp_nonce_url(), _x(), add_query_arg(), wp_nonce_url(), __(), apply_filters()
is_wp_error() && !is_php_version_compatible() && is_wp_version_compatible() && !empty($install_actions)230–236is_wp_error(), ->get_error_code(), ->get_error_data(), ltrim(), get_plugins(), esc_html__(), version_compare(), __(), __(), __(), __(), __(), esc_html_x(), esc_html_x(), apply_filters(), esc_html__(), is_php_version_compatible(), __(), sprintf(), esc_html(), is_wp_version_compatible(), __(), __(), sprintf(), add_query_arg(), wp_nonce_url(), _x(), add_query_arg(), wp_nonce_url(), __(), apply_filters(), __(), printf()
is_wp_error() && is_php_version_compatible() && !is_wp_version_compatible() && !empty($install_actions)235–241is_wp_error(), ->get_error_code(), ->get_error_data(), ltrim(), get_plugins(), esc_html__(), version_compare(), __(), __(), __(), __(), __(), esc_html_x(), esc_html_x(), apply_filters(), esc_html__(), is_php_version_compatible(), is_wp_version_compatible(), __(), wp_get_wp_version(), esc_html(), sprintf(), esc_html(), __(), __(), sprintf(), add_query_arg(), wp_nonce_url(), _x(), add_query_arg(), wp_nonce_url(), __(), apply_filters(), __(), printf()
is_wp_error() && !is_php_version_compatible() && !is_wp_version_compatible() && empty($install_actions)239–245is_wp_error(), ->get_error_code(), ->get_error_data(), ltrim(), get_plugins(), esc_html__(), version_compare(), __(), __(), __(), __(), __(), esc_html_x(), esc_html_x(), apply_filters(), esc_html__(), is_php_version_compatible(), __(), sprintf(), esc_html(), is_wp_version_compatible(), __(), wp_get_wp_version(), esc_html(), sprintf(), esc_html(), __(), __(), sprintf(), add_query_arg(), wp_nonce_url(), _x(), add_query_arg(), wp_nonce_url(), __(), apply_filters()
is_wp_error() && !is_php_version_compatible() && !is_wp_version_compatible() && !empty($install_actions)251–257is_wp_error(), ->get_error_code(), ->get_error_data(), ltrim(), get_plugins(), esc_html__(), version_compare(), __(), __(), __(), __(), __(), esc_html_x(), esc_html_x(), apply_filters(), esc_html__(), is_php_version_compatible(), __(), sprintf(), esc_html(), is_wp_version_compatible(), __(), wp_get_wp_version(), esc_html(), sprintf(), esc_html(), __(), __(), sprintf(), add_query_arg(), wp_nonce_url(), _x(), add_query_arg(), wp_nonce_url(), __(), apply_filters(), __(), printf()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev3304–25725
8.53304–25725
8.43304–257256 fewer instructions than PHP 8.3
8.33364–26325
8.23364–26325
8.13364–263254 fewer instructions than PHP 7.4
7.43404–26525

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Hooks and filters fired · 2

2 hooks fire while Plugin_Installer_Skin::do_overwrite() runs, in this order:

  1. apply_filters( install_plugin_overwrite_comparison )filterline 260 (+68 into the body)

    Filters the compare table output for overwriting a plugin package on upload.

  2. apply_filters( install_plugin_overwrite_actions )filterline 343 (+151 into the body)

    Filters the list of action links available following a single plugin installation failure when overwriting is allowed.

Uses · 14

Show all 14
  • add_query_arg()Retrieves a modified URL query string.
  • _x()Retrieves translated string with gettext context.

Used by · 1

Source code

	private function do_overwrite() {		if ( 'upload' !== $this->type || ! is_wp_error( $this->result ) || 'folder_exists' !== $this->result->get_error_code() ) {			return false;		} 		$folder = $this->result->get_error_data( 'folder_exists' );		$folder = ltrim( substr( $folder, strlen( WP_PLUGIN_DIR ) ), '/' ); 		$current_plugin_data = false;		$all_plugins         = get_plugins(); 		foreach ( $all_plugins as $plugin => $plugin_data ) {			if ( strrpos( $plugin, $folder ) !== 0 ) {				continue;			} 			$current_plugin_data = $plugin_data;		} 		$new_plugin_data = $this->upgrader->new_plugin_data; 		if ( ! $current_plugin_data || ! $new_plugin_data ) {			return false;		} 		echo '<h2 class="update-from-upload-heading">' . esc_html__( 'This plugin is already installed.' ) . '</h2>'; 		$this->is_downgrading = version_compare( $current_plugin_data['Version'], $new_plugin_data['Version'], '>' ); 		$rows = array(			'Name'        => __( 'Plugin name' ),			'Version'     => __( 'Version' ),			'Author'      => __( 'Author' ),			'RequiresWP'  => __( 'Required WordPress version' ),			'RequiresPHP' => __( 'Required PHP version' ),		); 		$table  = '<table class="update-from-upload-comparison"><tbody>';		$table .= '<tr><th></th><th>' . esc_html_x( 'Current', 'plugin' ) . '</th>';		$table .= '<th>' . esc_html_x( 'Uploaded', 'plugin' ) . '</th></tr>'; 		$is_same_plugin = true; // Let's consider only these rows. 		foreach ( $rows as $field => $label ) {			$old_value = ! empty( $current_plugin_data[ $field ] ) ? (string) $current_plugin_data[ $field ] : '-';			$new_value = ! empty( $new_plugin_data[ $field ] ) ? (string) $new_plugin_data[ $field ] : '-'; 			$is_same_plugin = $is_same_plugin && ( $old_value === $new_value ); 			$diff_field   = ( 'Version' !== $field && $new_value !== $old_value );			$diff_version = ( 'Version' === $field && $this->is_downgrading ); 			$table .= '<tr><td class="name-label">' . $label . '</td><td>' . wp_strip_all_tags( $old_value ) . '</td>';			$table .= ( $diff_field || $diff_version ) ? '<td class="warning">' : '<td>';			$table .= wp_strip_all_tags( $new_value ) . '</td></tr>';		} 		$table .= '</tbody></table>'; 		/**		 * Filters the compare table output for overwriting a plugin package on upload.		 *		 * @since 5.5.0		 *		 * @param string $table               The output table with Name, Version, Author, RequiresWP, and RequiresPHP info.		 * @param array  $current_plugin_data Array with current plugin data.		 * @param array  $new_plugin_data     Array with uploaded plugin data.		 */		echo apply_filters( 'install_plugin_overwrite_comparison', $table, $current_plugin_data, $new_plugin_data ); 		$install_actions = array();		$can_update      = true; 		$blocked_message  = '<p>' . esc_html__( 'The plugin cannot be updated due to the following:' ) . '</p>';		$blocked_message .= '<ul class="ul-disc">'; 		$requires_php = isset( $new_plugin_data['RequiresPHP'] ) ? $new_plugin_data['RequiresPHP'] : null;		$requires_wp  = isset( $new_plugin_data['RequiresWP'] ) ? $new_plugin_data['RequiresWP'] : null; 		if ( ! is_php_version_compatible( $requires_php ) ) {

Changelog

Introduced in 5.5.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 6.7.7 tag, from src/wp-admin/includes/class-plugin-installer-skin.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.