wp/wp-includes/theme.php
changeset 22 8c2e4d02f4ef
parent 21 48c4eec2b7e6
equal deleted inserted replaced
21:48c4eec2b7e6 22:8c2e4d02f4ef
    12  * Despite advances over get_themes(), this function is quite expensive, and grows
    12  * Despite advances over get_themes(), this function is quite expensive, and grows
    13  * linearly with additional themes. Stick to wp_get_theme() if possible.
    13  * linearly with additional themes. Stick to wp_get_theme() if possible.
    14  *
    14  *
    15  * @since 3.4.0
    15  * @since 3.4.0
    16  *
    16  *
    17  * @global array $wp_theme_directories
    17  * @global string[] $wp_theme_directories
    18  *
    18  *
    19  * @param array $args {
    19  * @param array $args {
    20  *     Optional. The search arguments.
    20  *     Optional. The search arguments.
    21  *
    21  *
    22  *     @type mixed $errors  True to return themes with errors, false to return
    22  *     @type mixed $errors  True to return themes with errors, false to return
   103 /**
   103 /**
   104  * Gets a WP_Theme object for a theme.
   104  * Gets a WP_Theme object for a theme.
   105  *
   105  *
   106  * @since 3.4.0
   106  * @since 3.4.0
   107  *
   107  *
   108  * @global array $wp_theme_directories
   108  * @global string[] $wp_theme_directories
   109  *
   109  *
   110  * @param string $stylesheet Optional. Directory name for the theme. Defaults to active theme.
   110  * @param string $stylesheet Optional. Directory name for the theme. Defaults to active theme.
   111  * @param string $theme_root Optional. Absolute path of the theme root to look in.
   111  * @param string $theme_root Optional. Absolute path of the theme root to look in.
   112  *                           If not specified, get_raw_theme_root() is used to calculate
   112  *                           If not specified, get_raw_theme_root() is used to calculate
   113  *                           the theme root for the $stylesheet provided (or active theme).
   113  *                           the theme root for the $stylesheet provided (or active theme).
   378 /**
   378 /**
   379  * Retrieves theme roots.
   379  * Retrieves theme roots.
   380  *
   380  *
   381  * @since 2.9.0
   381  * @since 2.9.0
   382  *
   382  *
   383  * @global array $wp_theme_directories
   383  * @global string[] $wp_theme_directories
   384  *
   384  *
   385  * @return array|string An array of theme roots keyed by template/stylesheet
   385  * @return array|string An array of theme roots keyed by template/stylesheet
   386  *                      or a single theme root if all themes have the same root.
   386  *                      or a single theme root if all themes have the same root.
   387  */
   387  */
   388 function get_theme_roots() {
   388 function get_theme_roots() {
   403 /**
   403 /**
   404  * Registers a directory that contains themes.
   404  * Registers a directory that contains themes.
   405  *
   405  *
   406  * @since 2.9.0
   406  * @since 2.9.0
   407  *
   407  *
   408  * @global array $wp_theme_directories
   408  * @global string[] $wp_theme_directories
   409  *
   409  *
   410  * @param string $directory Either the full filesystem path to a theme folder
   410  * @param string $directory Either the full filesystem path to a theme folder
   411  *                          or a folder within WP_CONTENT_DIR.
   411  *                          or a folder within WP_CONTENT_DIR.
   412  * @return bool True if successfully registered a directory that contains themes,
   412  * @return bool True if successfully registered a directory that contains themes,
   413  *              false if the directory does not exist.
   413  *              false if the directory does not exist.
   439 /**
   439 /**
   440  * Searches all registered theme directories for complete and valid themes.
   440  * Searches all registered theme directories for complete and valid themes.
   441  *
   441  *
   442  * @since 2.9.0
   442  * @since 2.9.0
   443  *
   443  *
   444  * @global array $wp_theme_directories
   444  * @global string[] $wp_theme_directories
   445  *
   445  *
   446  * @param bool $force Optional. Whether to force a new directory scan. Default false.
   446  * @param bool $force Optional. Whether to force a new directory scan. Default false.
   447  * @return array|false Valid themes found on success, false on failure.
   447  * @return array|false Valid themes found on success, false on failure.
   448  */
   448  */
   449 function search_theme_directories( $force = false ) {
   449 function search_theme_directories( $force = false ) {
   589  *
   589  *
   590  * Does not have trailing slash.
   590  * Does not have trailing slash.
   591  *
   591  *
   592  * @since 1.5.0
   592  * @since 1.5.0
   593  *
   593  *
   594  * @global array $wp_theme_directories
   594  * @global string[] $wp_theme_directories
   595  *
   595  *
   596  * @param string $stylesheet_or_template Optional. The stylesheet or template name of the theme.
   596  * @param string $stylesheet_or_template Optional. The stylesheet or template name of the theme.
   597  *                                       Default is to leverage the main theme root.
   597  *                                       Default is to leverage the main theme root.
   598  * @return string Themes directory path.
   598  * @return string Themes directory path.
   599  */
   599  */
   634  *
   634  *
   635  * Does not have trailing slash.
   635  * Does not have trailing slash.
   636  *
   636  *
   637  * @since 1.5.0
   637  * @since 1.5.0
   638  *
   638  *
   639  * @global array $wp_theme_directories
   639  * @global string[] $wp_theme_directories
   640  *
   640  *
   641  * @param string $stylesheet_or_template Optional. The stylesheet or template name of the theme.
   641  * @param string $stylesheet_or_template Optional. The stylesheet or template name of the theme.
   642  *                                       Default is to leverage the main theme root.
   642  *                                       Default is to leverage the main theme root.
   643  * @param string $theme_root             Optional. The theme root for which calculations will be based,
   643  * @param string $theme_root             Optional. The theme root for which calculations will be based,
   644  *                                       preventing the need for a get_raw_theme_root() call. Default empty.
   644  *                                       preventing the need for a get_raw_theme_root() call. Default empty.
   685 /**
   685 /**
   686  * Gets the raw theme root relative to the content directory with no filters applied.
   686  * Gets the raw theme root relative to the content directory with no filters applied.
   687  *
   687  *
   688  * @since 3.1.0
   688  * @since 3.1.0
   689  *
   689  *
   690  * @global array $wp_theme_directories
   690  * @global string[] $wp_theme_directories
   691  *
   691  *
   692  * @param string $stylesheet_or_template The stylesheet or template name of the theme.
   692  * @param string $stylesheet_or_template The stylesheet or template name of the theme.
   693  * @param bool   $skip_cache             Optional. Whether to skip the cache.
   693  * @param bool   $skip_cache             Optional. Whether to skip the cache.
   694  *                                       Defaults to false, meaning the cache is used.
   694  *                                       Defaults to false, meaning the cache is used.
   695  * @return string Theme root.
   695  * @return string Theme root.
   748  * Accepts one argument: $stylesheet of the theme. It also accepts an additional function signature
   748  * Accepts one argument: $stylesheet of the theme. It also accepts an additional function signature
   749  * of two arguments: $template then $stylesheet. This is for backward compatibility.
   749  * of two arguments: $template then $stylesheet. This is for backward compatibility.
   750  *
   750  *
   751  * @since 2.5.0
   751  * @since 2.5.0
   752  *
   752  *
   753  * @global array                $wp_theme_directories
   753  * @global string[]             $wp_theme_directories
   754  * @global WP_Customize_Manager $wp_customize
   754  * @global WP_Customize_Manager $wp_customize
   755  * @global array                $sidebars_widgets
   755  * @global array                $sidebars_widgets
   756  * @global array                $wp_registered_sidebars
   756  * @global array                $wp_registered_sidebars
   757  *
   757  *
   758  * @param string $stylesheet Stylesheet name.
   758  * @param string $stylesheet Stylesheet name.
   784 			)
   784 			)
   785 		);
   785 		);
   786 	}
   786 	}
   787 
   787 
   788 	$nav_menu_locations = get_theme_mod( 'nav_menu_locations' );
   788 	$nav_menu_locations = get_theme_mod( 'nav_menu_locations' );
   789 	update_option( 'theme_switch_menu_locations', $nav_menu_locations );
   789 	update_option( 'theme_switch_menu_locations', $nav_menu_locations, true );
   790 
   790 
   791 	if ( func_num_args() > 1 ) {
   791 	if ( func_num_args() > 1 ) {
   792 		$stylesheet = func_get_arg( 1 );
   792 		$stylesheet = func_get_arg( 1 );
   793 	}
   793 	}
   794 
   794 
  1891 			printf( '<style%s id="custom-background-css"></style>', $type_attr );
  1891 			printf( '<style%s id="custom-background-css"></style>', $type_attr );
  1892 		}
  1892 		}
  1893 		return;
  1893 		return;
  1894 	}
  1894 	}
  1895 
  1895 
  1896 	$style = $color ? "background-color: #$color;" : '';
  1896 	$style = $color ? 'background-color: ' . maybe_hash_hex_color( $color ) . ';' : '';
  1897 
  1897 
  1898 	if ( $background ) {
  1898 	if ( $background ) {
  1899 		$image = ' background-image: url("' . sanitize_url( $background ) . '");';
  1899 		$image = ' background-image: url("' . sanitize_url( $background ) . '");';
  1900 
  1900 
  1901 		// Background Position.
  1901 		// Background Position.
  2999 		?>
  2999 		?>
  3000 		<!-- Custom Logo: hide header text -->
  3000 		<!-- Custom Logo: hide header text -->
  3001 		<style id="custom-logo-css"<?php echo $type_attr; ?>>
  3001 		<style id="custom-logo-css"<?php echo $type_attr; ?>>
  3002 			<?php echo $classes; ?> {
  3002 			<?php echo $classes; ?> {
  3003 				position: absolute;
  3003 				position: absolute;
  3004 				clip: rect(1px, 1px, 1px, 1px);
  3004 				clip-path: inset(50%);
  3005 			}
  3005 			}
  3006 		</style>
  3006 		</style>
  3007 		<?php
  3007 		<?php
  3008 	}
  3008 	}
  3009 }
  3009 }
  4350  * @since 5.9.0
  4350  * @since 5.9.0
  4351  *
  4351  *
  4352  * @return bool Whether the active theme is a block-based theme or not.
  4352  * @return bool Whether the active theme is a block-based theme or not.
  4353  */
  4353  */
  4354 function wp_is_block_theme() {
  4354 function wp_is_block_theme() {
       
  4355 	if ( empty( $GLOBALS['wp_theme_directories'] ) ) {
       
  4356 		_doing_it_wrong( __FUNCTION__, __( 'This function should not be called before the theme directory is registered.' ), '6.8.0' );
       
  4357 		return false;
       
  4358 	}
       
  4359 
  4355 	return wp_get_theme()->is_block_theme();
  4360 	return wp_get_theme()->is_block_theme();
  4356 }
  4361 }
  4357 
  4362 
  4358 /**
  4363 /**
  4359  * Given an element name, returns a class name.
  4364  * Given an element name, returns a class name.
  4393 	 */
  4398 	 */
  4394 	add_theme_support( 'html5', array( 'comment-form', 'comment-list', 'search-form', 'gallery', 'caption', 'style', 'script' ) );
  4399 	add_theme_support( 'html5', array( 'comment-form', 'comment-list', 'search-form', 'gallery', 'caption', 'style', 'script' ) );
  4395 	add_theme_support( 'automatic-feed-links' );
  4400 	add_theme_support( 'automatic-feed-links' );
  4396 
  4401 
  4397 	add_filter( 'should_load_separate_core_block_assets', '__return_true' );
  4402 	add_filter( 'should_load_separate_core_block_assets', '__return_true' );
       
  4403 	add_filter( 'should_load_block_assets_on_demand', '__return_true' );
  4398 
  4404 
  4399 	/*
  4405 	/*
  4400 	 * Remove the Customizer's Menus panel when block theme is active.
  4406 	 * Remove the Customizer's Menus panel when block theme is active.
  4401 	 */
  4407 	 */
  4402 	add_filter(
  4408 	add_filter(