Using WordPress ‘install_plugin_overwrite_actions’ PHP filter

The install_plugin_overwrite_actions WordPress PHP Filter allows you to modify the list of action links shown after a single plugin installation fails, when overwriting is allowed.

Usage

add_filter('install_plugin_overwrite_actions', 'your_custom_function', 10, 3);

function your_custom_function($install_actions, $api, $new_plugin_data) {
    // your custom code here
    return $install_actions;
}

Parameters

  • $install_actions (string[]): Array of plugin action links.
  • $api (object): Object containing WordPress.org API plugin data.
  • $new_plugin_data (array): Array with uploaded plugin data.

More information

See WordPress Developer Resources: install_plugin_overwrite_actions

Examples

Add a custom action link to the list of plugin action links after a failed installation.

add_filter('install_plugin_overwrite_actions', 'add_custom_action_link', 10, 3);

function add_custom_action_link($install_actions, $api, $new_plugin_data) {
    $install_actions['custom'] = '<a href="https://example.com">Custom Action</a>';
    return $install_actions;
}

Remove a specific action link from the list of plugin action links.

add_filter('install_plugin_overwrite_actions', 'remove_specific_action_link', 10, 3);

function remove_specific_action_link($install_actions, $api, $new_plugin_data) {
    unset($install_actions['activate']);
    return $install_actions;
}

Change the order of the plugin action links.

add_filter('install_plugin_overwrite_actions', 'change_order_of_action_links', 10, 3);

function change_order_of_action_links($install_actions, $api, $new_plugin_data) {
    // Move the "activate" link to the end
    $activate = $install_actions['activate'];
    unset($install_actions['activate']);
    $install_actions['activate'] = $activate;

    return $install_actions;
}

Add an action link conditionally, based on plugin information.

add_filter('install_plugin_overwrite_actions', 'add_conditional_action_link', 10, 3);

function add_conditional_action_link($install_actions, $api, $new_plugin_data) {
    if ($api->slug == 'your-plugin-slug') {
        $install_actions['custom'] = '<a href="https://example.com">Custom Action</a>';
    }
    return $install_actions;
}

Modify the attributes of an existing action link.

add_filter('install_plugin_overwrite_actions', 'modify_action_link_attributes', 10, 3);

function modify_action_link_attributes($install_actions, $api, $new_plugin_data) {
    $install_actions['activate'] = str_replace('class="', 'class="custom-class ', $install_actions['activate']);
    return $install_actions;
}