Changeset 44966
- Timestamp:
- 03/21/2019 07:47:29 PM (6 years ago)
- Location:
- trunk
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/file.php
r44954 r44966 37 37 'page.php' => __( 'Single Page' ), 38 38 'front-page.php' => __( 'Homepage' ), 39 'privacy-policy.php' => __( 'Privacy Policy Page' ), 39 40 // Attachments 40 41 'attachment.php' => __( 'Attachment Template' ), -
trunk/src/wp-includes/class-wp-query.php
r44941 r44966 325 325 */ 326 326 public $is_home = false; 327 328 /** 329 * Signifies whether the current query is for the Privacy Policy page. 330 * 331 * @since 5.2.0 332 * @var bool 333 */ 334 public $is_privacy_policy = false; 327 335 328 336 /** … … 464 472 $this->is_trackback = false; 465 473 $this->is_home = false; 474 $this->is_privacy_policy = false; 466 475 $this->is_404 = false; 467 476 $this->is_paged = false; … … 999 1008 $this->is_posts_page = true; 1000 1009 } 1010 1011 if ( isset( $this->queried_object_id ) && $this->queried_object_id == get_option( 'wp_page_for_privacy_policy' ) ) { 1012 $this->is_privacy_policy = true; 1013 } 1001 1014 } 1002 1015 … … 1006 1019 $this->is_home = true; 1007 1020 $this->is_posts_page = true; 1021 } 1022 1023 if ( $qv['page_id'] == get_option( 'wp_page_for_privacy_policy' ) ) { 1024 $this->is_privacy_policy = true; 1008 1025 } 1009 1026 } … … 3879 3896 3880 3897 /** 3898 * Is the query for the Privacy Policy page? 3899 * 3900 * This is the page which shows the Privacy Policy content of your site. 3901 * 3902 * Depends on the site's "Change your Privacy Policy page" Privacy Settings 'wp_page_for_privacy_policy'. 3903 * 3904 * This function will return true only on the page you set as the "Privacy Policy page". 3905 * 3906 * @since 5.2.0 3907 * 3908 * @return bool True, if Privacy Policy page. 3909 */ 3910 public function is_privacy_policy() { 3911 if ( get_option( 'wp_page_for_privacy_policy' ) && $this->is_page( get_option( 'wp_page_for_privacy_policy' ) ) ) { 3912 return true; 3913 } else { 3914 return false; 3915 } 3916 } 3917 3918 /** 3881 3919 * Is the query for an existing month archive? 3882 3920 * -
trunk/src/wp-includes/nav-menu-template.php
r43571 r44966 362 362 $possible_object_parents = array_filter( $possible_object_parents ); 363 363 364 $front_page_url = home_url(); 365 $front_page_id = (int) get_option( 'page_on_front' ); 364 $front_page_url = home_url(); 365 $front_page_id = (int) get_option( 'page_on_front' ); 366 $privacy_policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' ); 366 367 367 368 foreach ( (array) $menu_items as $key => $menu_item ) { … … 377 378 if ( 'post_type' === $menu_item->type && $front_page_id === (int) $menu_item->object_id ) { 378 379 $classes[] = 'menu-item-home'; 380 } 381 382 // This menu item is set as the 'Privacy Policy Page'. 383 if ( 'post_type' === $menu_item->type && $privacy_policy_page_id === (int) $menu_item->object_id ) { 384 $classes[] = 'menu-item-privacy-policy'; 379 385 } 380 386 -
trunk/src/wp-includes/post-template.php
r44941 r44966 621 621 if ( is_home() ) { 622 622 $classes[] = 'blog'; 623 } 624 if ( is_privacy_policy() ) { 625 $classes[] = 'privacy-policy'; 623 626 } 624 627 if ( is_archive() ) { -
trunk/src/wp-includes/query.php
r44941 r44966 488 488 489 489 return $wp_query->is_home(); 490 } 491 492 /** 493 * Determines whether the query is for the Privacy Policy page. 494 * 495 * The Privacy Policy page is the page that shows the Privacy Policy content of the site. 496 * 497 * is_privacy_policy() is dependent on the site's "Change your Privacy Policy page" Privacy Settings 'wp_page_for_privacy_policy'. 498 * 499 * This function will return true only on the page you set as the "Privacy Policy page". 500 * 501 * For more information on this and similar theme functions, check out 502 * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ 503 * Conditional Tags} article in the Theme Developer Handbook. 504 * 505 * @since 5.2.0 506 * 507 * @global WP_Query $wp_query Global WP_Query instance. 508 * 509 * @return bool 510 */ 511 function is_privacy_policy() { 512 global $wp_query; 513 514 if ( ! isset( $wp_query ) ) { 515 _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' ); 516 return false; 517 } 518 519 return $wp_query->is_privacy_policy(); 490 520 } 491 521 -
trunk/src/wp-includes/template-loader.php
r44524 r44966 52 52 elseif ( is_front_page() && $template = get_front_page_template() ) : 53 53 elseif ( is_home() && $template = get_home_template() ) : 54 elseif ( is_privacy_policy() && $template = get_privacy_policy_template() ) : 54 55 elseif ( is_post_type_archive() && $template = get_post_type_archive_template() ) : 55 56 elseif ( is_tax() && $template = get_taxonomy_template() ) : -
trunk/src/wp-includes/template.php
r44569 r44966 34 34 * 35 35 * Possible values for `$type` include: 'index', '404', 'archive', 'author', 'category', 'tag', 'taxonomy', 'date', 36 * 'embed', 'home', 'frontpage', 'p age', 'paged', 'search', 'single', 'singular', and 'attachment'.36 * 'embed', 'home', 'frontpage', 'privacypolicy', 'page', 'paged', 'search', 'single', 'singular', and 'attachment'. 37 37 * 38 38 * @since 4.7.0 … … 52 52 * 53 53 * Possible values for `$type` include: 'index', '404', 'archive', 'author', 'category', 'tag', 'taxonomy', 'date', 54 * 'embed', 'home', 'frontpage', 'p age', 'paged', 'search', 'single', 'singular', and 'attachment'.54 * 'embed', 'home', 'frontpage', 'privacypolicy', 'page', 'paged', 'search', 'single', 'singular', and 'attachment'. 55 55 * 56 56 * @since 1.5.0 … … 375 375 376 376 return get_query_template( 'front_page', $templates ); 377 } 378 379 /** 380 * Retrieve path of Privacy Policy page template in current or parent template. 381 * 382 * The template hierarchy and template path are filterable via the {@see '$type_template_hierarchy'} 383 * and {@see '$type_template'} dynamic hooks, where `$type` is 'privacypolicy'. 384 * 385 * @since 5.2.0 386 * 387 * @see get_query_template() 388 * 389 * @return string Full path to front page template file. 390 */ 391 function get_privacy_policy_template() { 392 $templates = array( 'privacy-policy.php' ); 393 394 return get_query_template( 'privacy_policy', $templates ); 377 395 } 378 396 -
trunk/tests/phpunit/includes/abstract-testcase.php
r44944 r44966 927 927 'is_front_page', 928 928 'is_home', 929 'is_privacy_policy', 929 930 'is_month', 930 931 'is_page', -
trunk/tests/phpunit/tests/post/getBodyClass.php
r43571 r44966 203 203 $this->assertContains( 'attachment-jpeg', $class ); 204 204 } 205 206 /** 207 * @ticket 44005 208 * @group privacy 209 */ 210 public function test_privacy_policy_body_class() { 211 $page_id = self::factory()->post->create( 212 array( 213 'post_type' => 'page', 214 'post_title' => 'Privacy Policy', 215 ) 216 ); 217 update_option( 'wp_page_for_privacy_policy', $page_id ); 218 219 $this->go_to( get_permalink( $page_id ) ); 220 221 $class = get_body_class(); 222 223 $this->assertContains( 'privacy-policy', $class ); 224 $this->assertContains( 'page-template-default', $class ); 225 $this->assertContains( 'page', $class ); 226 $this->assertContains( "page-id-{$page_id}", $class ); 227 } 228 205 229 } -
trunk/tests/phpunit/tests/post/nav-menu.php
r43571 r44966 862 862 } 863 863 864 /** 865 * @ticket 44005 866 * @group privacy 867 */ 868 function test_no_privacy_policy_class_applied() { 869 $page_id = self::factory()->post->create( 870 array( 871 'post_type' => 'page', 872 'post_title' => 'Privacy Policy Page', 873 ) 874 ); 875 876 wp_update_nav_menu_item( 877 $this->menu_id, 878 0, 879 array( 880 'menu-item-type' => 'post_type', 881 'menu-item-object' => 'page', 882 'menu-item-object-id' => $page_id, 883 'menu-item-status' => 'publish', 884 ) 885 ); 886 887 $menu_items = wp_get_nav_menu_items( $this->menu_id ); 888 _wp_menu_item_classes_by_context( $menu_items ); 889 890 $classes = $menu_items[0]->classes; 891 892 $this->assertNotContains( 'menu-item-privacy-policy', $classes ); 893 } 894 895 /** 896 * @ticket 44005 897 * @group privacy 898 */ 899 function test_class_applied_to_privacy_policy_page_item() { 900 $page_id = self::factory()->post->create( 901 array( 902 'post_type' => 'page', 903 'post_title' => 'Privacy Policy Page', 904 ) 905 ); 906 update_option( 'wp_page_for_privacy_policy', $page_id ); 907 908 wp_update_nav_menu_item( 909 $this->menu_id, 910 0, 911 array( 912 'menu-item-type' => 'post_type', 913 'menu-item-object' => 'page', 914 'menu-item-object-id' => $page_id, 915 'menu-item-status' => 'publish', 916 ) 917 ); 918 919 $menu_items = wp_get_nav_menu_items( $this->menu_id ); 920 _wp_menu_item_classes_by_context( $menu_items ); 921 922 $classes = $menu_items[0]->classes; 923 924 delete_option( 'wp_page_for_privacy_policy' ); 925 926 $this->assertContains( 'menu-item-privacy-policy', $classes ); 927 } 928 864 929 } -
trunk/tests/phpunit/tests/query/conditionals.php
r43571 r44966 1591 1591 $this->assertFalse( is_single( $p1 ) ); 1592 1592 } 1593 1594 /** 1595 * @ticket 44005 1596 * @group privacy 1597 */ 1598 public function test_is_privacy_policy() { 1599 $page_id = self::factory()->post->create( 1600 array( 1601 'post_type' => 'page', 1602 'post_title' => 'Privacy Policy', 1603 ) 1604 ); 1605 1606 update_option( 'wp_page_for_privacy_policy', $page_id ); 1607 1608 $this->go_to( get_permalink( $page_id ) ); 1609 1610 $this->assertQueryTrue( 'is_page', 'is_singular', 'is_privacy_policy' ); 1611 } 1612 1593 1613 } -
trunk/tests/phpunit/tests/template.php
r43571 r44966 14 14 protected static $post; 15 15 16 /** 17 * Page For Privacy Policy. 18 * 19 * @since 5.2.0 20 * 21 * @var WP_Post $page_for_privacy_policy 22 */ 23 protected static $page_for_privacy_policy; 24 16 25 public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { 17 26 self::$page_on_front = $factory->post->create_and_get( … … 46 55 set_post_format( self::$post, 'quote' ); 47 56 add_post_meta( self::$post->ID, '_wp_page_template', 'templates/post.php' ); 57 58 self::$page_for_privacy_policy = $factory->post->create_and_get( 59 array( 60 'post_type' => 'page', 61 'post_title' => 'Privacy Policy', 62 ) 63 ); 48 64 } 49 65 … … 267 283 'page-page-name-%f0%9f%98%80.php', 268 284 'page-' . self::$page->ID . '.php', 285 'page.php', 286 'singular.php', 287 ) 288 ); 289 } 290 291 /** 292 * @ticket 44005 293 * @group privacy 294 */ 295 public function test_privacy_template_hierarchy() { 296 update_option( 'wp_page_for_privacy_policy', self::$page_for_privacy_policy->ID ); 297 298 $this->assertTemplateHierarchy( 299 get_permalink( self::$page_for_privacy_policy->ID ), 300 array( 301 'privacy-policy.php', 302 'page-privacy-policy.php', 303 'page-' . self::$page_for_privacy_policy->ID . '.php', 269 304 'page.php', 270 305 'singular.php', … … 437 472 'front_page' => 'is_front_page', 438 473 'home' => 'is_home', 474 'privacy_policy' => 'is_privacy_policy', 439 475 'post_type_archive' => 'is_post_type_archive', 440 476 'taxonomy' => 'is_tax', -
trunk/tests/phpunit/tests/theme.php
r44151 r44966 289 289 $this->assertEquals( get_date_template(), get_query_template( 'date' ) ); 290 290 $this->assertEquals( get_home_template(), get_query_template( 'home', array( 'home.php', 'index.php' ) ) ); 291 $this->assertEquals( get_privacy_policy_template(), get_query_template( 'privacy_policy', array( 'privacy-policy.php' ) ) ); 291 292 $this->assertEquals( get_page_template(), get_query_template( 'page' ) ); 292 293 $this->assertEquals( get_search_template(), get_query_template( 'search' ) ); -
trunk/tests/phpunit/tests/url/getPrivacyPolicyUrl.php
r43002 r44966 46 46 ) 47 47 ); 48 49 self::$privacy_policy_url = get_permalink( self::$privacy_policy_page_id );50 48 } 51 49 … … 61 59 */ 62 60 public function test_get_privacy_policy_url_should_return_valid_url_when_policy_page_set() { 61 $privacy_policy_url = get_permalink( self::$privacy_policy_page_id ); 63 62 update_option( 'wp_page_for_privacy_policy', self::$privacy_policy_page_id ); 64 63 65 $this->assertSame( self::$privacy_policy_url, get_privacy_policy_url() );64 $this->assertSame( $privacy_policy_url, get_privacy_policy_url() ); 66 65 } 67 66
Note: See TracChangeset
for help on using the changeset viewer.