The install_theme_overwrite_comparison WordPress PHP filter allows you to modify the comparison table output when overwriting an existing theme during a theme upload.
Usage
add_filter('install_theme_overwrite_comparison', 'your_custom_function', 10, 3); function your_custom_function($table, $current_theme_data, $new_theme_data) { // your custom code here return $table; }
Parameters
$table
(string) – The output table with Name, Version, Author, RequiresWP, and RequiresPHP information.$current_theme_data
(WP_Theme) – Active theme data.$new_theme_data
(array) – Array with uploaded theme data.
More information
See WordPress Developer Resources: install_theme_overwrite_comparison
Examples
Add custom column to the table
Add a custom column “Description” to the comparison table.
add_filter('install_theme_overwrite_comparison', 'add_description_column', 10, 3); function add_description_column($table, $current_theme_data, $new_theme_data) { // Add the custom header column $table['header']['description'] = 'Description'; // Add the current theme description $table['current_theme']['description'] = $current_theme_data->get('Description'); // Add the new theme description $table['new_theme']['description'] = $new_theme_data['Description']; return $table; }
Highlight major version updates
Highlight the version column in red if the new theme version is a major update.
add_filter('install_theme_overwrite_comparison', 'highlight_major_version_update', 10, 3); function highlight_major_version_update($table, $current_theme_data, $new_theme_data) { $current_version = $current_theme_data->get('Version'); $new_version = $new_theme_data['Version']; // Compare major versions if (version_compare($current_version, $new_version, '<')) { $table['new_theme']['version'] = '<span style="color: red;">' . $new_version . '</span>'; } return $table; }
Modify Author column
Append the author’s email to the author column.
add_filter('install_theme_overwrite_comparison', 'modify_author_column', 10, 3); function modify_author_column($table, $current_theme_data, $new_theme_data) { $current_author = $current_theme_data->get('Author'); $new_author = $new_theme_data['Author']; // Append the author's email $table['current_theme']['author'] .= ' (' . $current_theme_data->get('AuthorURI') . ')'; $table['new_theme']['author'] .= ' (' . $new_theme_data['AuthorURI'] . ')'; return $table; }
Remove RequiresPHP column
Remove the RequiresPHP column from the comparison table.
add_filter('install_theme_overwrite_comparison', 'remove_requires_php_column', 10, 3); function remove_requires_php_column($table, $current_theme_data, $new_theme_data) { // Remove the RequiresPHP column from the header, current_theme, and new_theme unset($table['header']['requires_php'], $table['current_theme']['requires_php'], $table['new_theme']['requires_php']); return $table; }
Add custom message
Add a custom message below the comparison table to display a warning about creating a backup before updating the theme.
add_filter('install_theme_overwrite_comparison', 'add_custom_message', 10, 3); function add_custom_message($table, $current_theme_data, $new_theme_data) { // Create a custom message $message = '<p style="color: red; font-weight: bold;">Warning: Please create a backup of your current theme before updating.</p>'; // Add the message to the table $table['footer']['message'] = $message; return $table; }