wp_get_themes example

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();
        $auto_updates = (array) get_site_option( 'auto_update_themes', array() );

        $auto_updates[] = $_GET['stylesheet'];
        $auto_updates   = array_unique( $auto_updates );
        // Remove themes that have been deleted since the site option was last updated.         $auto_updates = array_intersect( $auto_updatesarray_keys( $all_items ) );

        update_site_option( 'auto_update_themes', $auto_updates );

        wp_redirect( admin_url( 'themes.php?enabled-auto-update=true' ) );

        
$parent_theme_auto_update_string = apply_filters( 'theme_auto_update_debug_string', $auto_updates_string$parent_theme$enabled );

                $info['wp-parent-theme']['fields']['auto_update'] = array(
                    'label' => __( 'Auto-update' ),
                    'value' => $parent_theme_auto_update_string,
                    'debug' => $parent_theme_auto_update_string,
                );
            }
        }

        // Populate a list of all themes available in the install.         $all_themes = wp_get_themes();

        foreach ( $all_themes as $theme_slug => $theme ) {
            // Exclude the currently active theme from the list of all themes.             if ( $active_theme->stylesheet === $theme_slug ) {
                continue;
            }

            // Exclude the currently active parent theme from the list of all themes.             if ( ! empty( $parent_theme ) && $parent_theme->stylesheet === $theme_slug ) {
                continue;
            }

            
/** * Clears the cache held by get_theme_roots() and WP_Theme. * * @since 3.5.0 * @param bool $clear_update_cache Whether to clear the theme updates cache. */
function wp_clean_themes_cache( $clear_update_cache = true ) {
    if ( $clear_update_cache ) {
        delete_site_transient( 'update_themes' );
    }
    search_theme_directories( true );
    foreach ( wp_get_themes( array( 'errors' => null ) ) as $theme ) {
        $theme->cache_delete();
    }
}

/** * Whether a child theme is in use. * * @since 3.0.0 * * @return bool True if a child theme is in use, false otherwise. */

    $prepared_themes = (array) apply_filters( 'pre_prepare_themes_for_js', array()$themes$current_theme );

    if ( ! empty( $prepared_themes ) ) {
        return $prepared_themes;
    }

    // Make sure the active theme is listed first.     $prepared_themes[ $current_theme ] = array();

    if ( null === $themes ) {
        $themes = wp_get_themes( array( 'allowed' => true ) );
        if ( ! isset( $themes[ $current_theme ] ) ) {
            $themes[ $current_theme ] = wp_get_theme();
        }
    }

    $updates    = array();
    $no_updates = array();
    if ( ! is_multisite() && current_user_can( 'update_themes' ) ) {
        $updates_transient = get_site_transient( 'update_themes' );
        if ( isset( $updates_transient->response ) ) {
            $updates = $updates_transient->response;
        }
/** * Retrieves a collection of themes. * * @since 5.0.0 * * @param WP_REST_Request $request Full details about the request. * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. */
    public function get_items( $request ) {
        $themes = array();

        $active_themes = wp_get_themes();
        $current_theme = wp_get_theme();
        $status        = $request['status'];

        foreach ( $active_themes as $theme_name => $theme ) {
            $theme_status = ( $this->is_same_theme( $theme$current_theme ) ) ? 'active' : 'inactive';
            if ( is_array( $status ) && ! in_array( $theme_status$status, true ) ) {
                continue;
            }

            $prepared = $this->prepare_item_for_response( $theme$request );
            $themes[] = $this->prepare_response_for_collection( $prepared );
        }
update_site_option( 'active_sitewide_plugins', array() );
        }
    }

    // 3.4.0     if ( $wp_current_db_version < 20148 ) {
        // 'allowedthemes' keys things by stylesheet. 'allowed_themes' keyed things by name.         $allowedthemes  = get_site_option( 'allowedthemes' );
        $allowed_themes = get_site_option( 'allowed_themes' );
        if ( false === $allowedthemes && is_array( $allowed_themes ) && $allowed_themes ) {
            $converted = array();
            $themes    = wp_get_themes();
            foreach ( $themes as $stylesheet => $theme_data ) {
                if ( isset( $allowed_themes[ $theme_data->get( 'Name' ) ] ) ) {
                    $converted[ $stylesheet ] = true;
                }
            }
            update_site_option( 'allowedthemes', $converted );
            delete_site_option( 'allowed_themes' );
        }
    }

    // 3.5.0
            $themes_allowedtags                     = array_fill_keys(
                array( 'a', 'abbr', 'acronym', 'code', 'pre', 'em', 'strong', 'div', 'p', 'ul', 'ol', 'li', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'img' ),
                array()
            );
            $themes_allowedtags['a']                = array_fill_keys( array( 'href', 'title', 'target' ), true );
            $themes_allowedtags['acronym']['title'] = true;
            $themes_allowedtags['abbr']['title']    = true;
            $themes_allowedtags['img']              = array_fill_keys( array( 'src', 'class', 'alt' ), true );

            // Prepare a list of installed themes to check against before the loop.             $installed_themes = array();
            $wp_themes        = wp_get_themes();
            foreach ( $wp_themes as $theme ) {
                $installed_themes[] = $theme->get_stylesheet();
            }
            $update_php = network_admin_url( 'update.php?action=install-theme' );

            // Set up properties for themes available on WordPress.org.             foreach ( $themes->themes as &$theme ) {
                $theme->install_url = add_query_arg(
                    array(
                        'theme'    => $theme->slug,
                        '_wpnonce' => wp_create_nonce( 'install-theme_' . $theme->slug ),
                    ),

function wp_update_themes( $extra_stats = array() ) {
    if ( wp_installing() ) {
        return;
    }

    // Include an unmodified $wp_version.     require ABSPATH . WPINC . '/version.php';

    $installed_themes = wp_get_themes();
    $translations     = wp_get_installed_translations( 'themes' );

    $last_update = get_site_transient( 'update_themes' );

    if ( ! is_object( $last_update ) ) {
        $last_update = new stdClass();
    }

    $themes  = array();
    $checked = array();
    $request = array();

    

    private function do_overwrite() {
        if ( 'upload' !== $this->type || ! is_wp_error( $this->result ) || 'folder_exists' !== $this->result->get_error_code() ) {
            return false;
        }

        $folder = $this->result->get_error_data( 'folder_exists' );
        $folder = rtrim( $folder, '/' );

        $current_theme_data = false;
        $all_themes         = wp_get_themes( array( 'errors' => null ) );

        foreach ( $all_themes as $theme ) {
            $stylesheet_dir = wp_normalize_path( $theme->get_stylesheet_directory() );

            if ( rtrim( $stylesheet_dir, '/' ) !== $folder ) {
                continue;
            }

            $current_theme_data = $theme;
        }

        
$allowed_themes[ $blog_id ] = get_option( 'allowed_themes' );
            } else {
                switch_to_blog( $blog_id );
                $allowed_themes[ $blog_id ] = get_option( 'allowed_themes' );
                restore_current_blog();
            }

            if ( ! is_array( $allowed_themes[ $blog_id ] ) || empty( $allowed_themes[ $blog_id ] ) ) {
                $allowed_themes[ $blog_id ] = array();
            } else {
                $converted = array();
                $themes    = wp_get_themes();
                foreach ( $themes as $stylesheet => $theme_data ) {
                    if ( isset( $allowed_themes[ $blog_id ][ $theme_data->get( 'Name' ) ] ) ) {
                        $converted[ $stylesheet ] = true;
                    }
                }
                $allowed_themes[ $blog_id ] = $converted;
            }
            // Set the option so we never have to go through this pain again.             if ( is_admin() && $allowed_themes[ $blog_id ] ) {
                if ( $current ) {
                    update_option( 'allowedthemes', $allowed_themes[ $blog_id ] );
                    

function get_allowed_themes() {
    _deprecated_function( __FUNCTION__, '3.4.0', "wp_get_themes( array( 'allowed' => true ) )" );

    $themes = wp_get_themes( array( 'allowed' => true ) );

    $wp_themes = array();
    foreach ( $themes as $theme ) {
        $wp_themes[ $theme->get('Name') ] = $theme;
    }

    return $wp_themes;
}

/** * Retrieves a list of broken themes. * * @since 1.5.0 * @deprecated 3.4.0 Use wp_get_themes() * @see wp_get_themes() * * @return array */
/** * @return bool */
    public function ajax_user_can() {
        // Do not check edit_theme_options here. Ajax calls for available themes require switch_themes.         return current_user_can( 'switch_themes' );
    }

    /** */
    public function prepare_items() {
        $themes = wp_get_themes( array( 'allowed' => true ) );

        if ( ! empty( $_REQUEST['s'] ) ) {
            $this->search_terms = array_unique( array_filter( array_map( 'trim', explode( ',', strtolower( wp_unslash( $_REQUEST['s'] ) ) ) ) ) );
        }

        if ( ! empty( $_REQUEST['features'] ) ) {
            $this->features = $_REQUEST['features'];
        }

        if ( $this->search_terms || $this->features ) {
            foreach ( $themes as $key => $theme ) {
                
$option = 'auto_update_plugins';
            /** This filter is documented in wp-admin/includes/class-wp-plugins-list-table.php */
            $all_items = apply_filters( 'all_plugins', get_plugins() );
            break;
        case 'theme':
            if ( ! current_user_can( 'update_themes' ) ) {
                $error_message = __( 'Sorry, you are not allowed to modify themes.' );
                wp_send_json_error( array( 'error' => $error_message ) );
            }

            $option    = 'auto_update_themes';
            $all_items = wp_get_themes();
            break;
        default:
            wp_send_json_error( array( 'error' => __( 'Invalid data. Unknown type.' ) ) );
    }

    if ( ! array_key_exists( $asset$all_items ) ) {
        $error_message = __( 'Invalid data. The item does not exist.' );
        wp_send_json_error( array( 'error' => $error_message ) );
    }

    $auto_updates = (array) get_site_option( $option, array() );

    
$themes_inactive     = 0;

        // This value is changed during processing to determine how many themes are considered a reasonable amount.         $allowed_theme_count = 1;

        $has_default_theme   = false;
        $has_unused_themes   = false;
        $show_unused_themes  = true;
        $using_default_theme = false;

        // Populate a list of all themes available in the install.         $all_themes   = wp_get_themes();
        $active_theme = wp_get_theme();

        // If WP_DEFAULT_THEME doesn't exist, fall back to the latest core default theme.         $default_theme = wp_get_theme( WP_DEFAULT_THEME );
        if ( ! $default_theme->exists() ) {
            $default_theme = WP_Theme::get_core_default_theme();
        }

        if ( $default_theme ) {
            $has_default_theme = true;

            
if ( $description ) {
        echo ': ' . $description;
    }
    ?> </h2> </div> <div class="alignright"> <form action="theme-editor.php" method="get"> <label for="theme" id="theme-plugin-editor-selector"><?php _e( 'Select theme to edit:' ); ?> </label> <select name="theme" id="theme"> <?php         foreach ( wp_get_themes( array( 'errors' => null ) ) as $a_stylesheet => $a_theme ) {
            if ( $a_theme->errors() && 'theme_no_stylesheet' === $a_theme->errors()->get_error_code() ) {
                continue;
            }

            $selected = ( $a_stylesheet === $stylesheet ) ? ' selected="selected"' : '';
            echo "\n\t" . '<option value="' . esc_attr( $a_stylesheet ) . '"' . $selected . '>' . $a_theme->display( 'Name' ) . '</option>';
        }
        ?> </select> <?php submit_button( __( 'Select' ), '', 'Submit', false ); ?> </form> </div> <br class="clear" /> </div>
Home | Imprint | This part of the site doesn't use cookies.