[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/ -> class-wp-theme.php (summary)

WP_Theme Class

File Size: 2156 lines (65 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 52 functions

  __construct()
  __toString()
  __isset()
  __get()
  offsetSet()
  offsetUnset()
  offsetExists()
  offsetGet()
  errors()
  exists()
  parent()
  __wakeup()
  cache_add()
  cache_get()
  cache_delete()
  get()
  display()
  sanitize_header()
  markup_header()
  translate_header()
  get_stylesheet()
  get_template()
  get_stylesheet_directory()
  get_template_directory()
  get_stylesheet_directory_uri()
  get_template_directory_uri()
  get_theme_root()
  get_theme_root_uri()
  get_screenshot()
  get_files()
  get_post_templates()
  get_page_templates()
  scandir()
  load_textdomain()
  is_allowed()
  is_block_theme()
  get_file_path()
  get_core_default_theme()
  get_allowed()
  get_allowed_on_network()
  get_allowed_on_site()
  get_block_template_folders()
  get_block_patterns()
  get_pattern_cache()
  set_pattern_cache()
  delete_pattern_cache()
  network_enable_theme()
  network_disable_theme()
  sort_by_name()
  _name_sort()
  _name_sort_i18n()
  _check_headers_property_has_correct_type()

Functions
Functions that are not part of a class:

__construct( $theme_dir, $theme_root, $_child = null )   X-Ref
Constructor for WP_Theme.

param: string        $theme_dir  Directory of the theme within the theme_root.
param: string        $theme_root Theme root.
param: WP_Theme|null $_child If this theme is a parent theme, the child may be passed for validation purposes.

__toString()   X-Ref
When converting the object to a string, the theme name is returned.

return: string Theme name, ready for display (translated)

__isset( $offset )   X-Ref
__isset() magic method for properties formerly returned by current_theme_info()

return: bool Whether the given property is set.
param: string $offset Property to check if set.

__get( $offset )   X-Ref
__get() magic method for properties formerly returned by current_theme_info()

return: mixed Property value.
param: string $offset Property to get.

offsetSet( $offset, $value )   X-Ref
Method to implement ArrayAccess for keys formerly returned by get_themes()

param: mixed $offset
param: mixed $value

offsetUnset( $offset )   X-Ref
Method to implement ArrayAccess for keys formerly returned by get_themes()

param: mixed $offset

offsetExists( $offset )   X-Ref
Method to implement ArrayAccess for keys formerly returned by get_themes()

return: bool
param: mixed $offset

offsetGet( $offset )   X-Ref
Method to implement ArrayAccess for keys formerly returned by get_themes().

Author, Author Name, Author URI, and Description did not previously return
translated data. We are doing so now as it is safe to do. However, as
Name and Title could have been used as the key for get_themes(), both remain
untranslated for back compatibility. This means that ['Name'] is not ideal,
and care should be taken to use `$theme::display( 'Name' )` to get a properly
translated header.

return: mixed
param: mixed $offset

errors()   X-Ref
Returns errors property.

return: WP_Error|false WP_Error if there are errors, or false.

exists()   X-Ref
Determines whether the theme exists.

A theme with errors exists. A theme with the error of 'theme_not_found',
meaning that the theme's directory was not found, does not exist.

return: bool Whether the theme exists.

parent()   X-Ref
Returns reference to the parent theme.

return: WP_Theme|false Parent theme, or false if the active theme is not a child theme.

__wakeup()   X-Ref
Perform reinitialization tasks.

Prevents a callback from being injected during unserialization of an object.

cache_add( $key, $data )   X-Ref
Adds theme data to cache.

Cache entries keyed by the theme and the type of data.

return: bool Return value from wp_cache_add()
param: string       $key  Type of data to store (theme, screenshot, headers, post_templates)
param: array|string $data Data to store

cache_get( $key )   X-Ref
Gets theme data from cache.

Cache entries are keyed by the theme and the type of data.

return: mixed Retrieved data
param: string $key Type of data to retrieve (theme, screenshot, headers, post_templates)

cache_delete()   X-Ref
Clears the cache for the theme.


get( $header )   X-Ref
Gets a raw, unformatted theme header.

The header is sanitized, but is not translated, and is not marked up for display.
To get a theme header for display, use the display() method.

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.

return: string|array|false String or array (for Tags header) on success, false on failure.
param: string $header Theme header. Name, Description, Author, Version, ThemeURI, AuthorURI, Status, Tags.

display( $header, $markup = true, $translate = true )   X-Ref
Gets a theme header, formatted and translated for display.

return: string|array|false Processed header. An array for Tags if `$markup` is false, string otherwise.
param: string $header    Theme header. Name, Description, Author, Version, ThemeURI, AuthorURI, Status, Tags.
param: bool   $markup    Optional. Whether to mark up the header. Defaults to true.
param: bool   $translate Optional. Whether to translate the header. Defaults to true.

sanitize_header( $header, $value )   X-Ref
Sanitizes a theme header.

return: string|array An array for Tags header, string otherwise.
param: string $header Theme header. Accepts 'Name', 'Description', 'Author', 'Version',
param: string $value  Value to sanitize.

markup_header( $header, $value, $translate )   X-Ref
Marks up a theme header.

return: string Value, marked up.
param: string       $header    Theme header. Name, Description, Author, Version, ThemeURI, AuthorURI, Status, Tags.
param: string|array $value     Value to mark up. An array for Tags header, string otherwise.
param: string       $translate Whether the header has been translated.

translate_header( $header, $value )   X-Ref
Translates a theme header.

return: string|array Translated value. An array for Tags header, string otherwise.
param: string       $header Theme header. Name, Description, Author, Version, ThemeURI, AuthorURI, Status, Tags.
param: string|array $value  Value to translate. An array for Tags header, string otherwise.

get_stylesheet()   X-Ref
Returns the directory name of the theme's "stylesheet" files, inside the theme root.

In the case of a child theme, this is directory name of the child theme.
Otherwise, get_stylesheet() is the same as get_template().

return: string Stylesheet

get_template()   X-Ref
Returns the directory name of the theme's "template" files, inside the theme root.

In the case of a child theme, this is the directory name of the parent theme.
Otherwise, the get_template() is the same as get_stylesheet().

return: string Template

get_stylesheet_directory()   X-Ref
Returns the absolute path to the directory of a theme's "stylesheet" files.

In the case of a child theme, this is the absolute path to the directory
of the child theme's files.

return: string Absolute path of the stylesheet directory.

get_template_directory()   X-Ref
Returns the absolute path to the directory of a theme's "template" files.

In the case of a child theme, this is the absolute path to the directory
of the parent theme's files.

return: string Absolute path of the template directory.

get_stylesheet_directory_uri()   X-Ref
Returns the URL to the directory of a theme's "stylesheet" files.

In the case of a child theme, this is the URL to the directory of the
child theme's files.

return: string URL to the stylesheet directory.

get_template_directory_uri()   X-Ref
Returns the URL to the directory of a theme's "template" files.

In the case of a child theme, this is the URL to the directory of the
parent theme's files.

return: string URL to the template directory.

get_theme_root()   X-Ref
Returns the absolute path to the directory of the theme root.

This is typically the absolute path to wp-content/themes.

return: string Theme root.

get_theme_root_uri()   X-Ref
Returns the URL to the directory of the theme root.

This is typically the absolute URL to wp-content/themes. This forms the basis
for all other URLs returned by WP_Theme, so we pass it to the public function
get_theme_root_uri() and allow it to run the {@see 'theme_root_uri'} filter.

return: string Theme root URI.

get_screenshot( $uri = 'uri' )   X-Ref
Returns the main screenshot file for the theme.

The main screenshot is called screenshot.png. gif and jpg extensions are also allowed.

Screenshots for a theme must be in the stylesheet directory. (In the case of child
themes, parent theme screenshots are not inherited.)

return: string|false Screenshot file. False if the theme does not have a screenshot.
param: string $uri Type of URL to return, either 'relative' or an absolute URI. Defaults to absolute URI.

get_files( $type = null, $depth = 0, $search_parent = false )   X-Ref
Returns files in the theme's directory.

return: string[] Array of files, keyed by the path to the file relative to the theme's directory, with the values
param: string[]|string $type          Optional. Array of extensions to find, string of a single extension,
param: int             $depth         Optional. How deep to search for files. Defaults to a flat scan (0 depth).
param: bool            $search_parent Optional. Whether to return parent files. Default false.

get_post_templates()   X-Ref
Returns the theme's post templates.

return: array[] Array of page template arrays, keyed by post type and filename,

get_page_templates( $post = null, $post_type = 'page' )   X-Ref
Returns the theme's post templates for a given post type.

return: string[] Array of template header names keyed by the template file name.
param: WP_Post|null $post      Optional. The post being edited, provided for context.
param: string       $post_type Optional. Post type to get the templates for. Default 'page'.

scandir( $path, $extensions = null, $depth = 0, $relative_path = '' )   X-Ref
Scans a directory for files of a certain extension.

return: string[]|false Array of files, keyed by the path to the file relative to the `$path` directory prepended
param: string            $path          Absolute path to search.
param: array|string|null $extensions    Optional. Array of extensions to find, string of a single extension,
param: int               $depth         Optional. How many levels deep to search for files. Accepts 0, 1+, or
param: string            $relative_path Optional. The basename of the absolute path. Used to control the

load_textdomain()   X-Ref
Loads the theme's textdomain.

Translation files are not inherited from the parent theme. TODO: If this fails for the
child theme, it should probably try to load the parent theme's translations.

return: bool True if the textdomain was successfully loaded or has already been loaded.

is_allowed( $check = 'both', $blog_id = null )   X-Ref
Determines whether the theme is allowed (multisite only).

return: bool Whether the theme is allowed for the network. Returns true in single-site.
param: string $check   Optional. Whether to check only the 'network'-wide settings, the 'site'
param: int    $blog_id Optional. Ignored if only network-wide settings are checked. Defaults to current site.

is_block_theme()   X-Ref
Returns whether this theme is a block-based theme or not.

return: bool

get_file_path( $file = '' )   X-Ref
Retrieves the path of a file in the theme.

Searches in the stylesheet directory before the template directory so themes
which inherit from a parent theme can just override one file.

return: string The path of the file.
param: string $file Optional. File to search for in the stylesheet directory.

get_core_default_theme()   X-Ref
Determines the latest WordPress default theme that is installed.

This hits the filesystem.

return: WP_Theme|false Object, or false if no theme is installed, which would be bad.

get_allowed( $blog_id = null )   X-Ref
Returns array of stylesheet names of themes allowed on the site or network.

return: string[] Array of stylesheet names.
param: int $blog_id Optional. ID of the site. Defaults to the current site.

get_allowed_on_network()   X-Ref
Returns array of stylesheet names of themes allowed on the network.

return: string[] Array of stylesheet names.

get_allowed_on_site( $blog_id = null )   X-Ref
Returns array of stylesheet names of themes allowed on the site.

return: string[] Array of stylesheet names.
param: int $blog_id Optional. ID of the site. Defaults to the current site.

get_block_template_folders()   X-Ref
Returns the folder names of the block template directories.

return: string[] {

get_block_patterns()   X-Ref
Gets block pattern data for a specified theme.
Each pattern is defined as a PHP file and defines
its metadata using plugin-style headers. The minimum required definition is:

/**
* Title: My Pattern
* Slug: my-theme/my-pattern
*

The output of the PHP source corresponds to the content of the pattern, e.g.:

<main><p><?php echo "Hello"; ?></p></main>

If applicable, this will collect from both parent and child theme.

Other settable fields include:

- Description
- Viewport Width
- Inserter         (yes/no)
- Categories       (comma-separated values)
- Keywords         (comma-separated values)
- Block Types      (comma-separated values)
- Post Types       (comma-separated values)
- Template Types   (comma-separated values)

return: array Block pattern data.

get_pattern_cache()   X-Ref
Gets block pattern cache.

return: array|false Returns an array of patterns if cache is found, otherwise false.

set_pattern_cache( array $patterns )   X-Ref
Sets block pattern cache.

param: array $patterns Block patterns data to set in cache.

delete_pattern_cache()   X-Ref
Clears block pattern cache.


network_enable_theme( $stylesheets )   X-Ref
Enables a theme for all sites on the current network.

param: string|string[] $stylesheets Stylesheet name or array of stylesheet names.

network_disable_theme( $stylesheets )   X-Ref
Disables a theme for all sites on the current network.

param: string|string[] $stylesheets Stylesheet name or array of stylesheet names.

sort_by_name( &$themes )   X-Ref
Sorts themes by name.

param: WP_Theme[] $themes Array of theme objects to sort (passed by reference).

_name_sort( $a, $b )   X-Ref
Callback function for usort() to naturally sort themes by name.

Accesses the Name header directly from the class for maximum speed.
Would choke on HTML but we don't care enough to slow it down with strip_tags().

return: int Negative if `$a` falls lower in the natural order than `$b`. Zero if they fall equally.
param: WP_Theme $a First theme.
param: WP_Theme $b Second theme.

_name_sort_i18n( $a, $b )   X-Ref
Callback function for usort() to naturally sort themes by translated name.

return: int Negative if `$a` falls lower in the natural order than `$b`. Zero if they fall equally.
param: WP_Theme $a First theme.
param: WP_Theme $b Second theme.

_check_headers_property_has_correct_type( $headers )   X-Ref
No description



Generated : Sat Dec 21 08:20:01 2024 Cross-referenced by PHPXref