delete_theme example

wp_die(
                '<h1>' . __( 'Something went wrong.' ) . '</h1>' .
                '<p>' . __( 'The requested theme does not exist.' ) . '</p>',
                403
            );
        }

        $active = wp_get_theme();
        if ( $active->get( 'Template' ) === $_GET['stylesheet'] ) {
            wp_redirect( admin_url( 'themes.php?delete-active-child=true' ) );
        } else {
            delete_theme( $_GET['stylesheet'] );
            wp_redirect( admin_url( 'themes.php?deleted=true' ) );
        }
        exit;
    } elseif ( 'enable-auto-update' === $_GET['action'] ) {
        if ( ! ( current_user_can( 'update_themes' ) && wp_is_auto_update_enabled_for_type( 'theme' ) ) ) {
            wp_die( __( 'Sorry, you are not allowed to enable themes automatic updates.' ) );
        }

        check_admin_referer( 'updates' );

        $all_items    = wp_get_themes();
        
// 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 );
    }

    require_once ABSPATH . 'wp-admin/includes/theme.php';

    $result = delete_theme( $stylesheet );

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

    wp_send_json_success( $status );
}

<form method="post" action="<?php echo $referer ? esc_url( $referer ) : ''; ?>" style="display:inline;"> <?php submit_button( __( 'No, return me to the theme list' ), '', 'submit', false ); ?> </form> </div> <?php
                require_once ABSPATH . 'wp-admin/admin-footer.php';
                exit;
            } // End if verify-delete.
            foreach ( $themes as $theme ) {
                $delete_result = delete_theme(
                    $theme,
                    esc_url(
                        add_query_arg(
                            array(
                                'verify-delete' => 1,
                                'action'        => 'delete-selected',
                                'checked'       => $_REQUEST['checked'],
                                '_wpnonce'      => $_REQUEST['_wpnonce'],
                            ),
                            network_admin_url( 'themes.php' )
                        )
                    )
Home | Imprint | This part of the site doesn't use cookies.