Using WordPress ‘install_plugin_overwrite_comparison’ PHP filter

The install_plugin_overwrite_comparison WordPress PHP Filter allows you to customize the comparison table output when overwriting a plugin package during an upload.

Usage

add_filter('install_plugin_overwrite_comparison', 'my_custom_comparison', 10, 3);

function my_custom_comparison($table, $current_plugin_data, $new_plugin_data) {
    // your custom code here
    return $table;
}

Parameters

  • $table (string): The output table with Name, Version, Author, RequiresWP, and RequiresPHP info.
  • $current_plugin_data (array): Array with current plugin data.
  • $new_plugin_data (array): Array with uploaded plugin data.

More information

See WordPress Developer Resources: install_plugin_overwrite_comparison

Examples

Add custom data to the comparison table

This example adds a custom “Tested up to” field to the comparison table.

add_filter('install_plugin_overwrite_comparison', 'add_tested_up_to_field', 10, 3);

function add_tested_up_to_field($table, $current_plugin_data, $new_plugin_data) {
    $tested_field = "<tr><td>Tested up to:</td><td>{$current_plugin_data['Tested']}</td><td>{$new_plugin_data['Tested']}</td></tr>";
    return $table . $tested_field;
}

Change table style

This example changes the table style by adding custom CSS classes.

add_filter('install_plugin_overwrite_comparison', 'change_table_style', 10, 3);

function change_table_style($table, $current_plugin_data, $new_plugin_data) {
    $table = str_replace('<table>', '<table class="my-custom-table">', $table);
    return $table;
}

Highlight updated information

This example highlights updated information in the table by comparing the current and new plugin data.

add_filter('install_plugin_overwrite_comparison', 'highlight_updated_info', 10, 3);

function highlight_updated_info($table, $current_plugin_data, $new_plugin_data) {
    if ($current_plugin_data['Version'] != $new_plugin_data['Version']) {
        $table = str_replace($new_plugin_data['Version'], "<strong>{$new_plugin_data['Version']}</strong>", $table);
    }
    return $table;
}

Remove author information from the table

This example removes the author information from the comparison table.

add_filter('install_plugin_overwrite_comparison', 'remove_author_info', 10, 3);

function remove_author_info($table, $current_plugin_data, $new_plugin_data) {
    $pattern = '/<tr><td>Author:<\/td><td>.*<\/td><td>.*<\/td><\/tr>/';
    return preg_replace($pattern, '', $table);
}

Add a custom message based on version difference

This example adds a custom message based on the version difference between the current and new plugin.

add_filter('install_plugin_overwrite_comparison', 'add_custom_message', 10, 3);
function add_custom_message($table, $current_plugin_data, $new_plugin_data) {
    $current_version = $current_plugin_data['Version'];
    $new_version = $new_plugin_data['Version'];
    if (version_compare($new_version, $current_version, '>')) {
        $message = "<p>Great! You're updating to a newer version.</p>";
    } else if (version_compare($new_version, $current_version, '<')) {
        $message = "<p>Warning! You're downgrading to an older version.</p>";
    } else {
        $message = "<p>You're uploading the same version.</p>";
    }
    return $table . $message;
}

Add a custom message based on the RequiresWP field

This example adds a custom message based on whether the uploaded plugin supports the current WordPress version.

add_filter('install_plugin_overwrite_comparison', 'check_wp_compatibility', 10, 3);

function check_wp_compatibility($table, $current_plugin_data, $new_plugin_data) {
    $current_wp_version = get_bloginfo('version');
    $requires_wp = $new_plugin_data['RequiresWP'];
    if (version_compare($current_wp_version, $requires_wp, '>=')) {
        $message = "<p>Great! The uploaded plugin is compatible with your WordPress version.</p>";
    } else {
        $message = "<p>Warning! The uploaded plugin may not be compatible with your WordPress version.</p>";
    }
    return $table . $message;
}