Using WordPress ‘install_themes_upload()’ PHP function

The install_themes_upload() WordPress PHP function displays a form to upload themes from zip files.

Usage

To use the install_themes_upload() function, simply call the function in your PHP code:

install_themes_upload();

Parameters

  • None

More information

See WordPress Developer Resources: install_themes_upload

Examples

Display the theme upload form in a custom page

Create a custom page template to display the theme upload form. Save this code in a file named page-upload-theme.php in your theme folder.

/*
Template Name: Theme Upload Page
*/

get_header();

install_themes_upload();

get_footer();

Add a custom admin page with theme upload form

Create a custom admin page in WordPress admin dashboard and display the theme upload form on it. Add this code to your functions.php file.

// Register a custom admin page
function my_custom_admin_page() {
    add_menu_page('Theme Upload', 'Theme Upload', 'manage_options', 'my-theme-upload', 'my_theme_upload_callback');
}
add_action('admin_menu', 'my_custom_admin_page');

// Display the theme upload form on custom admin page
function my_theme_upload_callback() {
    install_themes_upload();
}

Create a shortcode to display theme upload form

Create a shortcode [theme_upload_form] to display the theme upload form. Add this code to your functions.php file.

// Register the shortcode
function theme_upload_form_shortcode() {
    ob_start();
    install_themes_upload();
    return ob_get_clean();
}
add_shortcode('theme_upload_form', 'theme_upload_form_shortcode');

Display theme upload form on a widget

Create a custom widget to display the theme upload form. Add this code to your functions.php file.

// Register the custom widget
class Theme_Upload_Widget extends WP_Widget {
    public function __construct() {
        parent::__construct('theme_upload_widget', 'Theme Upload Widget');
    }

    public function widget($args, $instance) {
        echo $args['before_widget'];
        install_themes_upload();
        echo $args['after_widget'];
    }
}
add_action('widgets_init', function() {
    register_widget('Theme_Upload_Widget');
});

Display theme upload form conditionally

Display the theme upload form on a specific page, based on a condition. For example, display it only for users with the manage_options capability. Add this code to your template file where you want to display the form.

if (current_user_can('manage_options')) {
    install_themes_upload();
}