Using WordPress ‘install_plugins_upload()’ PHP function

The install_plugins_upload() WordPress PHP function displays a form to upload plugins from zip files.

Usage

To use the install_plugins_upload() function, simply call it within your code:

install_plugins_upload();

Parameters

This function has no parameters.

More information

See WordPress Developer Resources: install_plugins_upload()

Examples

Display plugin upload form within a custom admin page

// In your theme or plugin file, create a custom admin page
function my_custom_plugin_upload_page() {
    add_menu_page(
        'Plugin Upload',
        'Plugin Upload',
        'manage_options',
        'plugin-upload',
        'my_custom_plugin_upload_page_callback'
    );
}
add_action('admin_menu', 'my_custom_plugin_upload_page');

// Callback function to display the plugin upload form
function my_custom_plugin_upload_page_callback() {
    // Check if the user has permission to manage plugins
    if (!current_user_can('upload_plugins')) {
        wp_die(__('Sorry, you are not allowed to install plugins on this site.'));
    }

    // Call the install_plugins_upload() function to display the form
    install_plugins_upload();
}

Display plugin upload form in a custom theme options page

// In your theme's functions.php file, create a custom theme options page
function my_custom_theme_options_page() {
    add_theme_page(
        'Theme Plugin Upload',
        'Theme Plugin Upload',
        'manage_options',
        'theme-plugin-upload',
        'my_custom_theme_options_page_callback'
    );
}
add_action('admin_menu', 'my_custom_theme_options_page');

// Callback function to display the plugin upload form
function my_custom_theme_options_page_callback() {
    // Check if the user has permission to manage plugins
    if (!current_user_can('upload_plugins')) {
        wp_die(__('Sorry, you are not allowed to install plugins on this site.'));
    }

    // Call the install_plugins_upload() function to display the form
    install_plugins_upload();
}

Display plugin upload form within a custom post type admin page

// In your theme or plugin file, create a custom post type
function my_custom_post_type() {
    register_post_type('my_custom_post_type', array(
        'public' => true,
        'label'  => 'My Custom Post Type',
        'show_in_menu' => 'plugin-upload'
    ));
}
add_action('init', 'my_custom_post_type');

// Create a custom admin page for the plugin upload form
function my_custom_plugin_upload_post_type_page() {
    add_submenu_page(
        'edit.php?post_type=my_custom_post_type',
        'Plugin Upload',
        'Plugin Upload',
        'manage_options',
        'plugin-upload',
        'my_custom_plugin_upload_post_type_page_callback'
    );
}
add_action('admin_menu', 'my_custom_plugin_upload_post_type_page');

// Callback function to display the plugin upload form
function my_custom_plugin_upload_post_type_page_callback() {
    // Check if the user has permission to manage plugins
    if (!current_user_can('upload_plugins')) {
        wp_die(__('Sorry, you are not allowed to install plugins on this site.'));
    }

    // Call the install_plugins_upload() function to display the form
    install_plugins_upload();
}