Plugin_Upgrader example

public function update( $type$item ) {
        $skin = new Automatic_Upgrader_Skin();

        switch ( $type ) {
            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;
        }

        

    );

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

    $status['pluginName'] = $api->name;

    $skin     = new WP_Ajax_Upgrader_Skin();
    $upgrader = new Plugin_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 ) ) {
        
if ( is_wp_error( $api ) ) {
            if ( str_contains( $api->get_error_message(), 'Plugin not found.' ) ) {
                $api->add_data( array( 'status' => 404 ) );
            } else {
                $api->add_data( array( 'status' => 500 ) );
            }

            return $api;
        }

        $skin     = new WP_Ajax_Upgrader_Skin();
        $upgrader = new Plugin_Upgrader( $skin );

        $result = $upgrader->install( $api->download_link );

        if ( is_wp_error( $result ) ) {
            $result->add_data( array( 'status' => 500 ) );

            return $result;
        }

        // This should be the same as $result above.         if ( is_wp_error( $skin->result ) ) {
            

function wp_update_plugin($plugin$feedback = '') {
    _deprecated_function( __FUNCTION__, '3.7.0', 'new Plugin_Upgrader();' );

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

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

/** * This was once used to kick-off the Theme Updater. * * Deprecated in favor of instantiating a Theme_Upgrader instance directly, * and calling the 'upgrade' method. * Unused since 2.8.0. * * @since 2.7.0 * @deprecated 3.7.0 Use Theme_Upgrader * @see Theme_Upgrader */
$plugins = array();
        }

        $plugins = array_map( 'urldecode', $plugins );

        $url   = 'update.php?action=update-selected&plugins=' . urlencode( implode( ',', $plugins ) );
        $nonce = 'bulk-update-plugins';

        wp_enqueue_script( 'updates' );
        iframe_header();

        $upgrader = new Plugin_Upgrader( new Bulk_Plugin_Upgrader_Skin( compact( 'nonce', 'url' ) ) );
        $upgrader->bulk_upgrade( $plugins );

        iframe_footer();

    } elseif ( 'upgrade-plugin' === $action ) {
        if ( ! current_user_can( 'update_plugins' ) ) {
            wp_die( __( 'Sorry, you are not allowed to update plugins for this site.' ) );
        }

        check_admin_referer( 'upgrade-plugin_' . $plugin );

        
Home | Imprint | This part of the site doesn't use cookies.