wp_get_theme example

$guessurl = wp_guess_url();
    /** * Fires before creating WordPress options and populating their default values. * * @since 2.6.0 */
    do_action( 'populate_options' );

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

    // If we can't find a core default theme, WP_DEFAULT_THEME is the best we can do.     if ( $theme ) {
        $stylesheet = $theme->get_stylesheet();
        $template   = $theme->get_template();
    }

    $timezone_string = '';
    

    public function get_name_for_update( $update ) {
        switch ( $update->type ) {
            case 'core':
                return 'WordPress'; // Not translated.
            case 'theme':
                $theme = wp_get_theme( $update->slug );
                if ( $theme->exists() ) {
                    return $theme->Get( 'Name' );
                }
                break;
            case 'plugin':
                $plugin_data = get_plugins( '/' . $update->slug );
                $plugin_data = reset( $plugin_data );
                if ( $plugin_data ) {
                    return $plugin_data['Name'];
                }
                break;
        }
if ( ! $should_add ) {
            foreach ( get_post_types( array( 'show_in_rest' => true ), 'objects' ) as $post_type ) {
                if ( current_user_can( $post_type->cap->edit_posts ) ) {
                    $should_add = true;
                    break;
                }
            }
        }

        if ( $should_add ) {
            $theme = wp_get_theme();
            $response->add_link( 'https://api.w.org/active-theme', rest_url( 'wp/v2/themes/' . $theme->get_stylesheet() ) );
        }
    }

    /** * Exposes the site logo through the WordPress REST API. * * This is used for fetching this information when user has no rights * to update settings. * * @since 5.8.0 * * @param WP_REST_Response $response REST API response. */
if ( isset( $_REQUEST['customize_theme'] ) ) {
                $args['theme'] = wp_unslash( $_REQUEST['customize_theme'] );
            } elseif ( isset( $_REQUEST['theme'] ) ) { // Deprecated.                 $args['theme'] = wp_unslash( $_REQUEST['theme'] );
            }
        }
        if ( ! isset( $args['messenger_channel'] ) && isset( $_REQUEST['customize_messenger_channel'] ) ) {
            $args['messenger_channel'] = sanitize_key( wp_unslash( $_REQUEST['customize_messenger_channel'] ) );
        }

        $this->original_stylesheet = get_stylesheet();
        $this->theme               = wp_get_theme( 0 === validate_file( $args['theme'] ) ? $args['theme'] : null );
        $this->messenger_channel   = $args['messenger_channel'];
        $this->_changeset_uuid     = $args['changeset_uuid'];

        foreach ( array( 'settings_previewed', 'autosaved', 'branching' ) as $key ) {
            if ( isset( $args[ $key ] ) ) {
                $this->$key = (bool) $args[ $key ];
            }
        }

        require_once ABSPATH . WPINC . '/class-wp-customize-setting.php';
        require_once ABSPATH . WPINC . '/class-wp-customize-panel.php';
        

    public function enqueue_scripts() {
        if ( ! $this->switch_should_render() ) {
            return;
        }
        $url = get_template_directory_uri() . '/assets/css/style-dark-mode.css';
        if ( is_rtl() ) {
            $url = get_template_directory_uri() . '/assets/css/style-dark-mode-rtl.css';
        }
        wp_enqueue_style( 'tt1-dark-mode', $url, array( 'twenty-twenty-one-style' )wp_get_theme()->get( 'Version' ) ); // @phpstan-ignore-line. Version is always a string.     }

    /** * Enqueues scripts for the customizer. * * @since Twenty Twenty-One 1.0 * * @return void */
    public function customize_controls_enqueue_scripts() {
        if ( ! $this->switch_should_render() ) {
            
if ( ! current_user_can( 'switch_themes' ) && ! current_user_can( 'edit_theme_options' ) ) {
    wp_die(
        '<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' .
        '<p>' . __( 'Sorry, you are not allowed to edit theme options on this site.' ) . '</p>',
        403
    );
}

if ( current_user_can( 'switch_themes' ) && isset( $_GET['action'] ) ) {
    if ( 'activate' === $_GET['action'] ) {
        check_admin_referer( 'switch-theme_' . $_GET['stylesheet'] );
        $theme = wp_get_theme( $_GET['stylesheet'] );

        if ( ! $theme->exists() || ! $theme->is_allowed() ) {
            wp_die(
                '<h1>' . __( 'Something went wrong.' ) . '</h1>' .
                '<p>' . __( 'The requested theme does not exist.' ) . '</p>',
                403
            );
        }

        switch_theme( $theme->get_stylesheet() );
        wp_redirect( admin_url( 'themes.php?activated=true' ) );
        
 else {
            $post             = null;
            $current_template = '';
        }

        // Always allow for updating a post to the same template, even if that template is no longer supported.         if ( $template === $current_template ) {
            return true;
        }

        // If this is a create request, get_post() will return null and wp theme will fallback to the passed post type.         $allowed_templates = wp_get_theme()->get_page_templates( $post$this->post_type );

        if ( isset( $allowed_templates[ $template ] ) ) {
            return true;
        }

        return new WP_Error(
            'rest_invalid_param',
            /* translators: 1: Parameter, 2: List of valid values. */
            sprintf( __( '%1$s is not one of %2$s.' ), 'template', implode( ', ', array_keys( $allowed_templates ) ) )
        );
    }

    
'<p>' . __( '<a href="https://wordpress.org/support/forums/">Support forums</a>' ) . '</p>'
);

wp_reset_vars( array( 'action', 'error', 'file', 'theme' ) );

if ( $theme ) {
    $stylesheet = $theme;
} else {
    $stylesheet = get_stylesheet();
}

$theme = wp_get_theme( $stylesheet );

if ( ! $theme->exists() ) {
    wp_die( __( 'The requested theme does not exist.' ) );
}

if ( $theme->errors() && 'theme_no_stylesheet' === $theme->errors()->get_error_code() ) {
    wp_die( __( 'The requested theme does not exist.' ) . ' ' . $theme->errors()->get_error_message() );
}

$allowed_files = array();
$style_files   = array();

'wp-editor',
    sprintf( 'var _wpMetaBoxUrl = %s;', wp_json_encode( $meta_box_url ) ),
    'before'
);

/* * Get all available templates for the post/page attributes meta-box. * The "Default template" array element should only be added if the array is * not empty so we do not trigger the template select element without any options * besides the default value. */
$available_templates = wp_get_theme()->get_page_templates( get_post( $post->ID ) );
$available_templates = ! empty( $available_templates ) ? array_replace(
    array(
        /** This filter is documented in wp-admin/includes/meta-boxes.php */
        '' => apply_filters( 'default_page_template_title', __( 'Default template' ), 'rest-api' ),
    ),
    $available_templates
) : $available_templates;

// Lock settings. $user_id = wp_check_post_lock( $post->ID );
if ( $user_id ) {
    

function get_current_theme() {
    _deprecated_function( __FUNCTION__, '3.4.0', 'wp_get_theme()' );

    if ( $theme = get_option( 'current_theme' ) )
        return $theme;

    return wp_get_theme()->get('Name');
}

/** * Accepts matches array from preg_replace_callback in wpautop() or a string. * * Ensures that the contents of a `<pre>...</pre>` HTML block are not * converted into paragraphs or line breaks. * * @since 1.2.0 * @deprecated 3.4.0 * * @param array|string $matches The array or string * @return string The pre block without paragraph/line break conversion. */

    public function enqueue() {
        parent::enqueue();

        // Enqueue the script.         wp_enqueue_script(
            'twentytwentyone-control-color',
            get_theme_file_uri( 'assets/js/palette-colorpicker.js' ),
            array( 'customize-controls', 'jquery', 'customize-base', 'wp-color-picker' ),
            wp_get_theme()->get( 'Version' ),
            false
        );
    }

    /** * Refresh the parameters passed to the JavaScript via JSON. * * @since Twenty Twenty-One 1.0 * * @uses WP_Customize_Control::to_json() * * @return void */

    public static function get_theme_data( $deprecated = array()$options = array() ) {
        if ( ! empty( $deprecated ) ) {
            _deprecated_argument( __METHOD__, '5.9.0' );
        }

        $options = wp_parse_args( $options, array( 'with_supports' => true ) );

        if ( null === static::$theme || ! static::has_same_registered_blocks( 'theme' ) ) {
            $wp_theme        = wp_get_theme();
            $theme_json_file = $wp_theme->get_file_path( 'theme.json' );
            if ( is_readable( $theme_json_file ) ) {
                $theme_json_data = static::read_json_file( $theme_json_file );
                $theme_json_data = static::translate( $theme_json_data$wp_theme->get( 'TextDomain' ) );
            } else {
                $theme_json_data = array();
            }

            /** * Filters the data provided by the theme for global styles and settings. * * @since 6.1.0 * * @param WP_Theme_JSON_Data $theme_json Class to access and update the underlying data. */

function current_theme_info() {
    _deprecated_function( __FUNCTION__, '3.4.0', 'wp_get_theme()' );

    return wp_get_theme();
}

/** * This was once used to display an 'Insert into Post' button. * * Now it is deprecated and stubbed. * * @deprecated 3.5.0 */
function _insert_into_post_button( $type ) {
    _deprecated_function( __FUNCTION__, '3.5.0' );
}

    public function editor_custom_color_variables() {
        wp_enqueue_style(
            'twenty-twenty-one-custom-color-overrides',
            get_theme_file_uri( 'assets/css/custom-color-overrides.css' ),
            array(),
            wp_get_theme()->get( 'Version' )
        );

        $background_color = get_theme_mod( 'background_color', 'D1E4DD' );
        if ( 'd1e4dd' !== strtolower( $background_color ) ) {
            wp_add_inline_style( 'twenty-twenty-one-custom-color-overrides', $this->generate_custom_color_variables( 'editor' ) );
        }
    }

    /** * Get luminance from a HEX color. * * @static * * @since Twenty Twenty-One 1.0 * * @param string $hex The HEX color. * @return int Returns a number (0-255). */
// 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 (
                
Home | Imprint | This part of the site doesn't use cookies.