Changeset 57685
- Timestamp:
- 02/21/2024 07:24:12 PM (10 months ago)
- Location:
- trunk
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/theme.php
r57644 r57685 1161 1161 * @since 5.2.0 1162 1162 * 1163 * @global string $wp_stylesheet_path Path to current theme's stylesheet directory. 1164 * @global string $wp_template_path Path to current theme's template directory. 1165 * 1163 1166 * @param string $theme Single theme to resume. 1164 1167 * @param string $redirect Optional. URL to redirect to. Default empty string. … … 1167 1170 */ 1168 1171 function resume_theme( $theme, $redirect = '' ) { 1172 global $wp_stylesheet_path, $wp_template_path; 1173 1169 1174 list( $extension ) = explode( '/', $theme ); 1170 1175 … … 1174 1179 */ 1175 1180 if ( ! empty( $redirect ) ) { 1176 $stylesheet_path = get_stylesheet_directory();1177 $template_path = get_template_directory();1178 1179 1181 $functions_path = ''; 1180 if ( str_contains( $ stylesheet_path, $extension ) ) {1181 $functions_path = $ stylesheet_path . '/functions.php';1182 } elseif ( str_contains( $ template_path, $extension ) ) {1183 $functions_path = $ template_path . '/functions.php';1182 if ( str_contains( $wp_stylesheet_path, $extension ) ) { 1183 $functions_path = $wp_stylesheet_path . '/functions.php'; 1184 } elseif ( str_contains( $wp_template_path, $extension ) ) { 1185 $functions_path = $wp_template_path . '/functions.php'; 1184 1186 } 1185 1187 -
trunk/src/wp-includes/comment-template.php
r57648 r57685 1391 1391 * @since 1.5.0 1392 1392 * 1393 * @global WP_Query $wp_query WordPress Query object.1394 * @global WP_Post $post Global post object.1395 * @global wpdb $wpdb WordPress database abstraction object.1393 * @global WP_Query $wp_query WordPress Query object. 1394 * @global WP_Post $post Global post object. 1395 * @global wpdb $wpdb WordPress database abstraction object. 1396 1396 * @global int $id 1397 * @global WP_Comment $comment Global comment object.1397 * @global WP_Comment $comment Global comment object. 1398 1398 * @global string $user_login 1399 1399 * @global string $user_identity 1400 1400 * @global bool $overridden_cpage 1401 1401 * @global bool $withcomments 1402 * @global string $wp_stylesheet_path Path to current theme's stylesheet directory. 1403 * @global string $wp_template_path Path to current theme's template directory. 1402 1404 * 1403 1405 * @param string $file Optional. The file to load. Default '/comments.php'. … … 1406 1408 */ 1407 1409 function comments_template( $file = '/comments.php', $separate_comments = false ) { 1408 global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_identity, $overridden_cpage ;1410 global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_identity, $overridden_cpage, $wp_stylesheet_path, $wp_template_path; 1409 1411 1410 1412 if ( ! ( is_single() || is_page() || $withcomments ) || empty( $post ) ) { … … 1601 1603 } 1602 1604 1603 $stylesheet_path = get_stylesheet_directory(); 1604 $template_path = get_template_directory(); 1605 1606 $theme_template = $stylesheet_path . $file; 1605 $theme_template = trailingslashit( $wp_stylesheet_path ) . $file; 1607 1606 1608 1607 /** … … 1617 1616 if ( file_exists( $include ) ) { 1618 1617 require $include; 1619 } elseif ( file_exists( $template_path. $file ) ) {1620 require $template_path. $file;1618 } elseif ( file_exists( trailingslashit( $wp_template_path ) . $file ) ) { 1619 require trailingslashit( $wp_template_path ) . $file; 1621 1620 } else { // Backward compat code will be removed in a future release. 1622 1621 require ABSPATH . WPINC . '/theme-compat/comments.php'; -
trunk/src/wp-includes/load.php
r57608 r57685 1047 1047 * @access private 1048 1048 * 1049 * @global string $pagenow The filename of the current screen. 1049 * @global string $pagenow The filename of the current screen. 1050 * @global string $wp_stylesheet_path Path to current theme's stylesheet directory. 1051 * @global string $wp_template_path Path to current theme's template directory. 1050 1052 * 1051 1053 * @return string[] Array of absolute paths to theme directories. 1052 1054 */ 1053 1055 function wp_get_active_and_valid_themes() { 1054 global $pagenow ;1056 global $pagenow, $wp_stylesheet_path, $wp_template_path; 1055 1057 1056 1058 $themes = array(); … … 1060 1062 } 1061 1063 1062 $stylesheet_path = get_stylesheet_directory(); 1063 $template_path = get_template_directory(); 1064 1065 if ( $template_path !== $stylesheet_path ) { 1066 $themes[] = $stylesheet_path; 1067 } 1068 1069 $themes[] = $template_path; 1064 if ( is_child_theme() ) { 1065 $themes[] = $wp_stylesheet_path; 1066 } 1067 1068 $themes[] = $wp_template_path; 1070 1069 1071 1070 /* -
trunk/src/wp-includes/template.php
r57223 r57685 681 681 682 682 /** 683 * Set up the globals used for template loading. 684 * 685 * @since 6.5.0 686 * 687 * @global string $wp_stylesheet_path Path to current theme's stylesheet directory. 688 * @global string $wp_template_path Path to current theme's template directory. 689 */ 690 function wp_set_template_globals() { 691 global $wp_stylesheet_path, $wp_template_path; 692 693 $wp_stylesheet_path = get_stylesheet_directory(); 694 $wp_template_path = get_template_directory(); 695 } 696 697 /** 683 698 * Retrieves the name of the highest priority template file that exists. 684 699 * … … 689 704 * @since 2.7.0 690 705 * @since 5.5.0 The `$args` parameter was added. 706 * 707 * @global string $wp_stylesheet_path Path to current theme's stylesheet directory. 708 * @global string $wp_template_path Path to current theme's template directory. 691 709 * 692 710 * @param string|array $template_names Template file(s) to search for, in order. … … 699 717 */ 700 718 function locate_template( $template_names, $load = false, $load_once = true, $args = array() ) { 701 $stylesheet_path = get_stylesheet_directory(); 702 $template_path = get_template_directory(); 703 $is_child_theme = $stylesheet_path !== $template_path; 719 global $wp_stylesheet_path, $wp_template_path; 720 721 if ( ! isset( $wp_stylesheet_path ) || ! isset( $wp_template_path ) ) { 722 wp_set_template_globals(); 723 } 724 725 $is_child_theme = is_child_theme(); 704 726 705 727 $located = ''; … … 708 730 continue; 709 731 } 710 if ( file_exists( $ stylesheet_path . '/' . $template_name ) ) {711 $located = $ stylesheet_path . '/' . $template_name;732 if ( file_exists( $wp_stylesheet_path . '/' . $template_name ) ) { 733 $located = $wp_stylesheet_path . '/' . $template_name; 712 734 break; 713 } elseif ( $is_child_theme && file_exists( $ template_path . '/' . $template_name ) ) {714 $located = $ template_path . '/' . $template_name;735 } elseif ( $is_child_theme && file_exists( $wp_template_path . '/' . $template_name ) ) { 736 $located = $wp_template_path . '/' . $template_name; 715 737 break; 716 738 } elseif ( file_exists( ABSPATH . WPINC . '/theme-compat/' . $template_name ) ) { -
trunk/src/wp-includes/theme.php
r57608 r57685 154 154 * 155 155 * @since 3.0.0 156 * @since 6.5.0 Makes use of global template variables. 157 * 158 * @global string $wp_stylesheet_path Path to current theme's stylesheet directory. 159 * @global string $wp_template_path Path to current theme's template directory. 156 160 * 157 161 * @return bool True if a child theme is in use, false otherwise. 158 162 */ 159 163 function is_child_theme() { 160 return get_template_directory() !== get_stylesheet_directory(); 164 global $wp_stylesheet_path, $wp_template_path; 165 166 return $wp_stylesheet_path !== $wp_template_path; 161 167 } 162 168 … … 836 842 837 843 update_option( 'theme_switched', $old_theme->get_stylesheet() ); 844 845 /* 846 * Reset template globals when switching themes outside of a switched blog 847 * context to ensure templates will be loaded from the new theme. 848 */ 849 if ( ! is_multisite() || ! ms_is_switched() ) { 850 wp_set_template_globals(); 851 } 838 852 839 853 // Clear pattern caches. -
trunk/src/wp-settings.php
r57661 r57685 609 609 do_action( 'setup_theme' ); 610 610 611 // Define the template related constants .611 // Define the template related constants and globals. 612 612 wp_templating_constants(); 613 wp_set_template_globals(); 613 614 614 615 // Load the default text localization domain. -
trunk/tests/phpunit/includes/abstract-testcase.php
r57608 r57685 190 190 */ 191 191 $GLOBALS['wp_sitemaps'] = null; 192 193 // Reset template globals. 194 $GLOBALS['wp_stylesheet_path'] = null; 195 $GLOBALS['wp_template_path'] = null; 192 196 193 197 $this->unregister_all_meta_keys(); -
trunk/tests/phpunit/tests/comment/metaCache.php
r56549 r57685 6 6 protected $i = 0; 7 7 protected $queries = 0; 8 9 /** 10 * Performs setup tasks for every test. 11 */ 12 public function set_up() { 13 parent::set_up(); 14 switch_theme( 'default' ); 15 } 8 16 9 17 /** -
trunk/tests/phpunit/tests/theme.php
r57244 r57685 1306 1306 $this->assertSame( $new_root . '/test-parent', $path2, 'The new template path is not correct' ); 1307 1307 } 1308 1309 /** 1310 * Tests that switch_to_blog() uses the original template path. 1311 * 1312 * @ticket 60290 1313 * 1314 * @group ms-required 1315 * 1316 * @covers ::locate_template 1317 */ 1318 public function test_switch_to_blog_uses_original_template_path() { 1319 $old_theme = wp_get_theme(); 1320 $template_path = locate_template( 'index.php' ); 1321 1322 $blog_id = self::factory()->blog->create(); 1323 switch_to_blog( $blog_id ); 1324 1325 switch_theme( 'block-theme' ); 1326 $new_template_path = locate_template( 'index.php' ); 1327 1328 // Cleanup. 1329 restore_current_blog(); 1330 switch_theme( $old_theme->get_stylesheet() ); 1331 1332 $this->assertSame( $template_path, $new_template_path, 'Switching blogs switches the template path' ); 1333 } 1308 1334 }
Note: See TracChangeset
for help on using the changeset viewer.