Theme_Upgrader example


function wp_update_theme($theme$feedback = '') {
    _deprecated_function( __FUNCTION__, '3.7.0', 'new Theme_Upgrader();' );

    if ( !empty($feedback) )
        add_filter('update_feedback', $feedback);

    require ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
    $upgrader = new Theme_Upgrader();
    return $upgrader->upgrade($theme);
}

/** * This was once used to display attachment links. Now it is deprecated and stubbed. * * @since 2.0.0 * @deprecated 3.7.0 * * @param int|bool $id */
case 'core':
                // The Core upgrader doesn't use the Upgrader's skin during the actual main part of the upgrade, instead, firing a filter.                 add_filter( 'update_feedback', array( $skin, 'feedback' ) );
                $upgrader = new Core_Upgrader( $skin );
                $context  = ABSPATH;
                break;
            case 'plugin':
                $upgrader = new Plugin_Upgrader( $skin );
                $context  = WP_PLUGIN_DIR; // We don't support custom Plugin directories, or updates for WPMU_PLUGIN_DIR.                 break;
            case 'theme':
                $upgrader = new Theme_Upgrader( $skin );
                $context  = get_theme_root( $item->theme );
                break;
            case 'translation':
                $upgrader = new Language_Pack_Upgrader( $skin );
                $context  = WP_CONTENT_DIR; // WP_LANG_DIR;                 break;
        }

        // Determine whether we can and should perform this update.         if ( ! $this->should_update( $type$item$context ) ) {
            return false;
        }
// Used in the HTML title tag.         $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=' . urlencode( $theme );

        $upgrader = new Theme_Upgrader( new Theme_Upgrader_Skin( compact( 'title', 'nonce', 'url', 'theme' ) ) );
        $upgrader->upgrade( $theme );

        require_once ABSPATH . 'wp-admin/admin-footer.php';
    } elseif ( 'update-selected-themes' === $action ) {
        if ( ! current_user_can( 'update_themes' ) ) {
            wp_die( __( 'Sorry, you are not allowed to update themes for this site.' ) );
        }

        check_admin_referer( 'bulk-update-themes' );

        if ( isset( $_GET['themes'] ) ) {
            
'slug'   => $slug,
            'fields' => array( 'sections' => false ),
        )
    );

    if ( is_wp_error( $api ) ) {
        $status['errorMessage'] = $api->get_error_message();
        wp_send_json_error( $status );
    }

    $skin     = new WP_Ajax_Upgrader_Skin();
    $upgrader = new Theme_Upgrader( $skin );
    $result   = $upgrader->install( $api->download_link );

    if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
        $status['debug'] = $skin->get_upgrade_messages();
    }

    if ( is_wp_error( $result ) ) {
        $status['errorCode']    = $result->get_error_code();
        $status['errorMessage'] = $result->get_error_message();
        wp_send_json_error( $status );
    } elseif ( is_wp_error( $skin->result ) ) {
        
Home | Imprint | This part of the site doesn't use cookies.