diff --git src/wp-admin/includes/file.php src/wp-admin/includes/file.php
index efc846b..b348c11 100644
|
|
$wp_file_descriptions = array( |
36 | 36 | 'single.php' => __( 'Single Post' ), |
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' ), |
41 | 42 | 'image.php' => __( 'Image Attachment Template' ), |
diff --git src/wp-includes/class-wp-query.php src/wp-includes/class-wp-query.php
index 02f2406..f778402 100644
|
|
class WP_Query { |
326 | 326 | public $is_home = false; |
327 | 327 | |
328 | 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; |
| 335 | |
| 336 | /** |
329 | 337 | * Signifies whether the current query couldn't find anything. |
330 | 338 | * |
331 | 339 | * @since 1.5.0 |
… |
… |
class WP_Query { |
463 | 471 | $this->is_comment_feed = false; |
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; |
468 | 477 | $this->is_admin = false; |
… |
… |
class WP_Query { |
998 | 1007 | $this->is_home = true; |
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 | |
1003 | 1016 | if ( $qv['page_id'] ) { |
… |
… |
class WP_Query { |
1006 | 1019 | $this->is_home = true; |
1007 | 1020 | $this->is_posts_page = true; |
1008 | 1021 | } |
| 1022 | |
| 1023 | if ( $qv['page_id'] == get_option( 'wp_page_for_privacy_policy' ) ) { |
| 1024 | $this->is_privacy_policy = true; |
| 1025 | } |
1009 | 1026 | } |
1010 | 1027 | |
1011 | 1028 | if ( ! empty( $qv['post_type'] ) ) { |
… |
… |
class WP_Query { |
3878 | 3895 | } |
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 | * @see WP_Query::is_front_page() |
| 3907 | * |
| 3908 | * @since 5.2.0 |
| 3909 | * |
| 3910 | * @return bool True, if Privacy Policy page. |
| 3911 | */ |
| 3912 | public function is_privacy_policy() { |
| 3913 | if ( get_option( 'wp_page_for_privacy_policy' ) && $this->is_page( get_option( 'wp_page_for_privacy_policy' ) ) ) { |
| 3914 | return true; |
| 3915 | } else { |
| 3916 | return false; |
| 3917 | } |
| 3918 | } |
| 3919 | |
| 3920 | /** |
3881 | 3921 | * Is the query for an existing month archive? |
3882 | 3922 | * |
3883 | 3923 | * @since 3.1.0 |
diff --git src/wp-includes/post-template.php src/wp-includes/post-template.php
index 3cf0c7c..7738fcb 100644
|
|
function get_body_class( $class = '' ) { |
603 | 603 | if ( is_home() ) { |
604 | 604 | $classes[] = 'blog'; |
605 | 605 | } |
| 606 | if ( is_privacy_policy() ) { |
| 607 | $classes[] = 'privacy-policy'; |
| 608 | } |
606 | 609 | if ( is_archive() ) { |
607 | 610 | $classes[] = 'archive'; |
608 | 611 | } |
diff --git src/wp-includes/query.php src/wp-includes/query.php
index 9d2db74..9d668f0 100644
|
|
function is_home() { |
490 | 490 | } |
491 | 491 | |
492 | 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(); |
| 520 | } |
| 521 | |
| 522 | /** |
493 | 523 | * Determines whether the query is for an existing month archive. |
494 | 524 | * |
495 | 525 | * For more information on this and similar theme functions, check out |
diff --git src/wp-includes/template-loader.php src/wp-includes/template-loader.php
index 0879798..7e627c5 100644
|
|
if ( wp_using_themes() ) : |
51 | 51 | elseif ( is_search() && $template = get_search_template() ) : |
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() ) : |
56 | 57 | elseif ( is_attachment() && $template = get_attachment_template() ) : |
diff --git src/wp-includes/template.php src/wp-includes/template.php
index 862b2cc..67db6dd 100644
|
|
function get_query_template( $type, $templates = array() ) { |
33 | 33 | * The last element in the array should always be the fallback template for this query type. |
34 | 34 | * |
35 | 35 | * Possible values for `$type` include: 'index', '404', 'archive', 'author', 'category', 'tag', 'taxonomy', 'date', |
36 | | * 'embed', 'home', 'frontpage', 'page', '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 |
39 | 39 | * |
… |
… |
function get_query_template( $type, $templates = array() ) { |
51 | 51 | * This hook also applies to various types of files loaded as part of the Template Hierarchy. |
52 | 52 | * |
53 | 53 | * Possible values for `$type` include: 'index', '404', 'archive', 'author', 'category', 'tag', 'taxonomy', 'date', |
54 | | * 'embed', 'home', 'frontpage', 'page', '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 |
57 | 57 | * @since 4.8.0 The `$type` and `$templates` parameters were added. |
… |
… |
function get_front_page_template() { |
377 | 377 | } |
378 | 378 | |
379 | 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 ); |
| 395 | } |
| 396 | |
| 397 | /** |
380 | 398 | * Retrieve path of page template in current or parent template. |
381 | 399 | * |
382 | 400 | * The hierarchy for this template looks like: |
diff --git tests/phpunit/includes/abstract-testcase.php tests/phpunit/includes/abstract-testcase.php
index 7858862..e064fe3 100644
|
|
abstract class WP_UnitTestCase_Base extends PHPUnit_Framework_TestCase { |
836 | 836 | 'is_time', |
837 | 837 | 'is_trackback', |
838 | 838 | 'is_year', |
| 839 | 'is_privacy_policy', |
839 | 840 | ); |
840 | 841 | $true = func_get_args(); |
841 | 842 | |
diff --git tests/phpunit/tests/post/getBodyClass.php tests/phpunit/tests/post/getBodyClass.php
index 5b0ade1..9c8ce67 100644
|
|
class Tests_Post_GetBodyClass extends WP_UnitTestCase { |
202 | 202 | $this->assertContains( "attachmentid-{$attachment_id}", $class ); |
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 | } |
diff --git tests/phpunit/tests/query/conditionals.php tests/phpunit/tests/query/conditionals.php
index 6be39be..5b296d5 100644
|
|
class Tests_Query_Conditionals extends WP_UnitTestCase { |
1590 | 1590 | $this->assertTrue( is_single( $p2 ) ); |
1591 | 1591 | $this->assertFalse( is_single( $p1 ) ); |
1592 | 1592 | } |
| 1593 | /** |
| 1594 | * @ticket 44005 |
| 1595 | * @group privacy |
| 1596 | */ |
| 1597 | public function test_is_privacy_policy() { |
| 1598 | $page_id = self::factory()->post->create( |
| 1599 | array( |
| 1600 | 'post_type' => 'page', |
| 1601 | 'post_title' => 'Privacy Policy', |
| 1602 | ) |
| 1603 | ); |
| 1604 | |
| 1605 | update_option( 'wp_page_for_privacy_policy', $page_id ); |
| 1606 | |
| 1607 | $this->go_to( get_permalink( $page_id ) ); |
| 1608 | |
| 1609 | $this->assertQueryTrue( 'is_page', 'is_singular', 'is_privacy_policy' ); |
| 1610 | } |
| 1611 | |
1593 | 1612 | } |
diff --git tests/phpunit/tests/template.php tests/phpunit/tests/template.php
index 3a0b66b..ba79ab4 100644
|
|
class Tests_Template extends WP_UnitTestCase { |
13 | 13 | protected static $page; |
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( |
18 | 27 | array( |
… |
… |
class Tests_Template extends WP_UnitTestCase { |
45 | 54 | ); |
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 | |
50 | 66 | public function setUp() { |
… |
… |
class Tests_Template extends WP_UnitTestCase { |
273 | 289 | } |
274 | 290 | |
275 | 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 | 'page-privacy-policy.php', |
| 302 | 'page-' . self::$page_for_privacy_policy->ID . '.php', |
| 303 | 'page.php', |
| 304 | 'singular.php', |
| 305 | ) |
| 306 | ); |
| 307 | } |
| 308 | |
| 309 | /** |
276 | 310 | * @ticket 18375 |
277 | 311 | */ |
278 | 312 | public function test_single_template_hierarchy_for_post() { |
diff --git tests/phpunit/tests/url/getPrivacyPolicyUrl.php tests/phpunit/tests/url/getPrivacyPolicyUrl.php
index b6d6a23..6938470 100644
|
|
class Tests_Url_GetPrivacyPolicyUrl extends WP_UnitTestCase { |
45 | 45 | 'post_title' => WP_TESTS_DOMAIN . ' Privacy Policy', |
46 | 46 | ) |
47 | 47 | ); |
48 | | |
49 | | self::$privacy_policy_url = get_permalink( self::$privacy_policy_page_id ); |
50 | 48 | } |
51 | 49 | |
52 | 50 | /** |
… |
… |
class Tests_Url_GetPrivacyPolicyUrl extends WP_UnitTestCase { |
60 | 58 | * The function should return the privacy policy URL when `wp_page_for_privacy_policy` is set. |
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 | |
68 | 67 | /** |