get_template example

if ( empty( $this->upgrader->result['destination_name'] ) ) {
            return;
        }

        $theme_info = $this->upgrader->theme_info();
        if ( empty( $theme_info ) ) {
            return;
        }

        $name       = $theme_info->display( 'Name' );
        $stylesheet = $this->upgrader->result['destination_name'];
        $template   = $theme_info->get_template();

        $activate_link = add_query_arg(
            array(
                'action'     => 'activate',
                'template'   => urlencode( $template ),
                'stylesheet' => urlencode( $stylesheet ),
            ),
            admin_url( 'themes.php' )
        );
        $activate_link = wp_nonce_url( $activate_link, 'switch-theme_' . $stylesheet );

        
        $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 (
                $active_theme->get_stylesheet() === $default_theme->get_stylesheet()
            ||
                is_child_theme() && $active_theme->get_template() === $default_theme->get_template()
            ) {
                $using_default_theme = true;
            }
        }

        foreach ( $all_themes as $theme_slug => $theme ) {
            $themes_total++;

            if ( array_key_exists( $theme_slug$theme_updates ) ) {
                $themes_need_updates++;
            }
        }
<?php _e( 'Theme Files' ); ?></h2> <ul role="tree" aria-labelledby="theme-files-label"> <?php if ( $theme->parent() ) : ?> <li class="howto"> <?php                 printf(
                    /* translators: %s: Link to edit parent theme. */
                    __( 'This child theme inherits templates from a parent theme, %s.' ),
                    sprintf(
                        '<a href="%s">%s</a>',
                        self_admin_url( 'theme-editor.php?theme=' . urlencode( $theme->get_template() ) ),
                        $theme->parent()->display( 'Name' )
                    )
                );
                ?> </li> <?php endif; ?> <li role="treeitem" tabindex="-1" aria-expanded="true" aria-level="1" aria-posinset="1" aria-setsize="1"> <ul role="group"> <?php wp_print_theme_file_tree( wp_make_theme_file_tree( $allowed_files ) ); ?> </ul> </li> </ul> </div>
return apply_filters( 'template', get_option( 'template' ) );
}

/** * Retrieves template directory path for the active theme. * * @since 1.5.0 * * @return string Path to active theme's template directory. */
function get_template_directory() {
    $template     = get_template();
    $theme_root   = get_theme_root( $template );
    $template_dir = "$theme_root/$template";

    /** * Filters the active theme directory path. * * @since 1.5.0 * * @param string $template_dir The path of the active theme directory. * @param string $template Directory name of the active theme. * @param string $theme_root Absolute path to the themes directory. */
break;
            }
        }

        // Compare based on relative paths.         if ( 0 !== validate_file( $filearray_keys( $allowed_files ) ) ) {
            return new WP_Error( 'disallowed_theme_file', __( 'Sorry, that file cannot be edited.' ) );
        }

        $real_file = $theme->get_stylesheet_directory() . '/' . $file;

        $is_active = ( get_stylesheet() === $stylesheet || get_template() === $stylesheet );

    } else {
        return new WP_Error( 'missing_theme_or_plugin' );
    }

    // Ensure file is real.     if ( ! is_file( $real_file ) ) {
        return new WP_Error( 'file_does_not_exist', __( 'File does not exist! Please double check the name and try again.' ) );
    }

    // Ensure file extension is allowed.

function is_theme_paused( $theme ) {
    if ( ! isset( $GLOBALS['_paused_themes'] ) ) {
        return false;
    }

    if ( get_stylesheet() !== $theme && get_template() !== $theme ) {
        return false;
    }

    return array_key_exists( $theme$GLOBALS['_paused_themes'] );
}

/** * Gets the error that was recorded for a paused theme. * * @since 5.2.0 * * @param string $theme Path to the theme directory relative to the themes * directory. * @return array|false Array of error information as it was returned by * `error_get_last()`, or false if none was recorded. */
/** */
    public function display_rows() {
        $themes = $this->items;

        foreach ( $themes as $theme ) :
            ?> <div class="available-theme"> <?php
            $template   = $theme->get_template();
            $stylesheet = $theme->get_stylesheet();
            $title      = $theme->display( 'Name' );
            $version    = $theme->display( 'Version' );
            $author     = $theme->display( 'Author' );

            $activate_link = wp_nonce_url( 'themes.php?action=activate&amp;template=' . urlencode( $template ) . '&amp;stylesheet=' . urlencode( $stylesheet ), 'switch-theme_' . $stylesheet );

            $actions             = array();
            $actions['activate'] = sprintf(
                '<a href="%s" class="activatelink" title="%s">%s</a>',
                $activate_link,
                

    public function after() {
        $this->decrement_update_count( 'theme' );

        $update_actions = array();
        $theme_info     = $this->upgrader->theme_info();
        if ( $theme_info ) {
            $name       = $theme_info->display( 'Name' );
            $stylesheet = $this->upgrader->result['destination_name'];
            $template   = $theme_info->get_template();

            $activate_link = add_query_arg(
                array(
                    'action'     => 'activate',
                    'template'   => urlencode( $template ),
                    'stylesheet' => urlencode( $stylesheet ),
                ),
                admin_url( 'themes.php' )
            );
            $activate_link = wp_nonce_url( $activate_link, 'switch-theme_' . $stylesheet );

            
$this->skin->bulk_header();

        /* * Only start maintenance mode if: * - running Multisite and there are one or more themes specified, OR * - a theme with an update available is currently in use. * @todo For multisite, maintenance mode should only kick in for individual sites if at all possible. */
        $maintenance = ( is_multisite() && ! empty( $themes ) );
        foreach ( $themes as $theme ) {
            $maintenance = $maintenance || get_stylesheet() === $theme || get_template() === $theme;
        }
        if ( $maintenance ) {
            $this->maintenance_mode( true );
        }

        $results = array();

        $this->update_count   = count( $themes );
        $this->update_current = 0;
        foreach ( $themes as $theme ) {
            $this->update_current++;

            

function wp_get_theme_preview_path( $current_stylesheet = null ) {
    if ( ! current_user_can( 'switch_themes' ) ) {
        return $current_stylesheet;
    }

    $preview_stylesheet = ! empty( $_GET['wp_theme_preview'] ) ? sanitize_text_field( wp_unslash( $_GET['wp_theme_preview'] ) ) : null;
    $wp_theme           = wp_get_theme( $preview_stylesheet );
    if ( ! is_wp_error( $wp_theme->errors() ) ) {
        if ( current_filter() === 'template' ) {
            $theme_path = $wp_theme->get_template();
        } else {
            $theme_path = $wp_theme->get_stylesheet();
        }

        return sanitize_text_field( $theme_path );
    }

    return $current_stylesheet;
}

/** * Adds a middleware to `apiFetch` to set the theme for the preview. * This adds a `wp_theme_preview` URL parameter to API requests from the Site Editor, so they also respond as if the theme is set to the value of the parameter. * * @since 6.3.0 */
count( $templates ) &&
            $fallback_template_slug === $templates[0]->slug &&
            'theme' === $templates[0]->source
        ) {
            // Unfortunately, we cannot trust $templates[0]->theme, since it will always             // be set to the active theme's slug by _build_block_template_result_from_file(),             // even if the block template is really coming from the active theme's parent.             // (The reason for this is that we want it to be associated with the active theme             // -- not its parent -- once we edit it and store it to the DB as a wp_template CPT.)             // Instead, we use _get_block_template_file() to locate the block template file.             $template_file = _get_block_template_file( 'wp_template', $fallback_template_slug );
            if ( $template_file && get_template() === $template_file['theme'] ) {
                // The block template is part of the parent theme, so we                 // have to give precedence to the child theme's PHP template.                 array_shift( $templates );
            }
        }
    }

    return count( $templates ) ? $templates[0] : null;
}

/** * Displays title tag with content, regardless of whether theme has title-tag support. * * @access private * @since 5.8.0 * * @see _wp_render_title_tag() */
foreach ( array( 'Name', 'Description', 'Author', 'Author', 'AuthorURI' ) as $field ) {
            // Don't mark up; Do translate.             if ( false !== stripos( $theme->display( $field, false, true )$term ) ) {
                return true;
            }
        }

        if ( false !== stripos( $theme->get_stylesheet()$term ) ) {
            return true;
        }

        if ( false !== stripos( $theme->get_template()$term ) ) {
            return true;
        }

        return false;
    }

    // Not used by any core columns.     /** * @global string $orderby * @global string $order * @param array $theme_a * @param array $theme_b * @return int */

function _get_block_template_file( $template_type$slug ) {
    if ( 'wp_template' !== $template_type && 'wp_template_part' !== $template_type ) {
        return null;
    }

    $themes = array(
        get_stylesheet() => get_stylesheet_directory(),
        get_template()   => get_template_directory(),
    );
    foreach ( $themes as $theme_slug => $theme_dir ) {
        $template_base_paths = get_block_theme_folders( $theme_slug );
        $file_path           = $theme_dir . '/' . $template_base_paths[ $template_type ] . '/' . $slug . '.html';
        if ( file_exists( $file_path ) ) {
            $new_template_item = array(
                'slug'  => $slug,
                'path'  => $file_path,
                'theme' => $theme_slug,
                'type'  => $template_type,
            );

            
// 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 = '';
    $gmt_offset      = 0;
    /* * translators: default GMT offset or timezone string. Must be either a valid offset (-12 to 14) * or a valid timezone string (America/New_York). See https://www.php.net/manual/en/timezones.php * for all timezone strings currently supported by PHP. * * Important: When a previous timezone string, like `Europe/Kiev`, has been superseded by an * updated one, like `Europe/Kyiv`, as a rule of thumb, the **old** timezone name should be used * in the "translation" to allow for the default timezone setting to be PHP cross-version compatible, * as old timezone names will be recognized in new PHP versions, while new timezone names cannot * be recognized in old PHP versions. * * To verify which timezone strings are available in the _oldest_ PHP version supported, you can * use https://3v4l.org/6YQAt#v5.6.20 and replace the "BR" (Brazil) in the code line with the * country code for which you want to look up the supported timezone names. */
if ( rest_is_field_included( 'stylesheet', $fields ) ) {
            $data['stylesheet'] = $theme->get_stylesheet();
        }

        if ( rest_is_field_included( 'template', $fields ) ) {
            /** * Use the get_template() method, not the 'Template' header, for finding the template. * The 'Template' header is only good for what was written in the style.css, while * get_template() takes into account where WordPress actually located the theme and * whether it is actually valid. */
            $data['template'] = $theme->get_template();
        }

        $plain_field_mappings = array(
            'requires_php' => 'RequiresPHP',
            'requires_wp'  => 'RequiresWP',
            'textdomain'   => 'TextDomain',
            'version'      => 'Version',
        );

        foreach ( $plain_field_mappings as $field => $header ) {
            if ( rest_is_field_included( $field$fields ) ) {
                
Home | Imprint | This part of the site doesn't use cookies.