WordPress.org

Ready to get started?Download WordPress

Forums

Automating Theme Update (3 posts)

  1. Kolokial
    Member
    Posted 1 year ago #

    Hi Guys, I've been working on an automated theme updater for some private themes, and would like to know if there is a particular criteria I need to meet before I can overwrite a theme.

    I've searched the WordPress codex for such things, and was wondering if there was a hook or an action I needed to call before it was safe to do so. It seems a little easy that overwriting the theme accomplishes the task.

  2. Shaun Scovil
    Member
    Posted 1 year ago #

    You probably want to look at wp-admin/update.php to see how it's done in core. Particularly lines 150-168:

    if ( ! current_user_can('update_themes') )
        wp_die(__('You do not have sufficient permissions to update themes for this site.'));
    
    check_admin_referer('upgrade-theme_' . $theme);
    
    wp_enqueue_script( 'customize-loader' );
    
    $title = __('Update Theme');
    $parent_file = 'themes.php';
    $submenu_file = 'themes.php';
    require_once(ABSPATH . 'wp-admin/admin-header.php');
    
    $nonce = 'upgrade-theme_' . $theme;
    $url = 'update.php?action=upgrade-theme&theme=' . $theme;
    
    $upgrader = new Theme_Upgrader( new Theme_Upgrader_Skin( compact('title', 'nonce', 'url', 'theme') ) );
    $upgrader->upgrade($theme);
    
    include(ABSPATH . 'wp-admin/admin-footer.php');
  3. Kolokial
    Member
    Posted 1 year ago #

    Awesome! It seems so obvious now that I should be checking admin rights, I've just assumed the admin will be looking!

    I've already got a system in place to set and check nonces, and I can't connect to WordPress.org for theme updates. I need to track down this Theme_Upgrader to see how that works!

    Thank you Shaun!

Topic Closed

This topic has been closed to new replies.

About this Topic