delete_plugins example

$status['errorCode']    = 'unable_to_connect_to_filesystem';
        $status['errorMessage'] = __( 'Unable to connect to the filesystem. Please confirm your credentials.' );

        // Pass through the error from WP_Filesystem if one was raised.         if ( $wp_filesystem instanceof WP_Filesystem_Base && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors() ) {
            $status['errorMessage'] = esc_html( $wp_filesystem->errors->get_error_message() );
        }

        wp_send_json_error( $status );
    }

    $result = delete_plugins( array( $plugin ) );

    if ( is_wp_error( $result ) ) {
        $status['errorMessage'] = $result->get_error_message();
        wp_send_json_error( $status );
    } elseif ( false === $result ) {
        $status['errorMessage'] = __( 'Plugin could not be deleted.' );
        wp_send_json_error( $status );
    }

    wp_send_json_success( $status );
}

<?php submit_button( __( 'No, return me to the plugin list' ), '', 'submit', false ); ?> </form> </div> <?php
                require_once ABSPATH . 'wp-admin/admin-footer.php';
                exit;
            } else {
                $plugins_to_delete = count( $plugins );
            } // End if verify-delete.
            $delete_result = delete_plugins( $plugins );

            // Store the result in a cache rather than a URL param due to object type & length.             set_transient( 'plugins_delete_result_' . $user_ID$delete_result );
            wp_redirect( self_admin_url( "plugins.php?deleted=$plugins_to_delete&plugin_status=$status&paged=$page&s=$s) );
            exit;
        case 'clear-recent-list':
            if ( ! is_network_admin() ) {
                update_option( 'recently_activated', array() );
            } else {
                update_site_option( 'recently_activated', array() );
            }

            
__( 'Cannot delete an active plugin. Please deactivate it first.' ),
                array( 'status' => 400 )
            );
        }

        $filesystem_available = $this->is_filesystem_available();
        if ( is_wp_error( $filesystem_available ) ) {
            return $filesystem_available;
        }

        $prepared = $this->prepare_item_for_response( $data$request );
        $deleted  = delete_plugins( array( $request['plugin'] ) );

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

            return $deleted;
        }

        return new WP_REST_Response(
            array(
                'deleted'  => true,
                'previous' => $prepared->get_data(),
            )
Home | Imprint | This part of the site doesn't use cookies.