The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

Automating Theme Update (3 posts)

  1. Kolokial
    Posted 3 years 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
    Posted 3 years 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') ) );
    include(ABSPATH . 'wp-admin/admin-footer.php');
  3. Kolokial
    Posted 3 years 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