Support » Plugins » Hacks » Automating Theme Update

  • 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.

Viewing 2 replies - 1 through 2 (of 2 total)
  • 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');

    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 for theme updates. I need to track down this Theme_Upgrader to see how that works!

    Thank you Shaun!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Automating Theme Update’ is closed to new replies.