diff --git a/wp-admin/includes/file.php b/wp-admin/includes/file.php index 0cb55806c3..11e5f9231f 100644 --- a/wp-admin/includes/file.php +++ b/wp-admin/includes/file.php @@ -36,6 +36,7 @@ $wp_file_descriptions = array( 'single.php' => __( 'Single Post' ), 'page.php' => __( 'Single Page' ), 'front-page.php' => __( 'Homepage' ), + 'privacy-policy.php' => __( 'Privacy Policy Page' ), // Attachments 'attachment.php' => __( 'Attachment Template' ), 'image.php' => __( 'Image Attachment Template' ), diff --git a/wp-includes/class-wp-query.php b/wp-includes/class-wp-query.php index cd938061db..953f917d27 100644 --- a/wp-includes/class-wp-query.php +++ b/wp-includes/class-wp-query.php @@ -325,6 +325,14 @@ class WP_Query { */ public $is_home = false; + /** + * Signifies whether the current query is for the Privacy Policy page. + * + * @since 5.2.0 + * @var bool + */ + public $is_privacy_policy = false; + /** * Signifies whether the current query couldn't find anything. * @@ -463,6 +471,7 @@ class WP_Query { $this->is_comment_feed = false; $this->is_trackback = false; $this->is_home = false; + $this->is_privacy_policy = false; $this->is_404 = false; $this->is_paged = false; $this->is_admin = false; @@ -998,6 +1007,10 @@ class WP_Query { $this->is_home = true; $this->is_posts_page = true; } + + if ( isset( $this->queried_object_id ) && $this->queried_object_id == get_option( 'wp_page_for_privacy_policy' ) ) { + $this->is_privacy_policy = true; + } } if ( $qv['page_id'] ) { @@ -1006,6 +1019,10 @@ class WP_Query { $this->is_home = true; $this->is_posts_page = true; } + + if ( $qv['page_id'] == get_option( 'wp_page_for_privacy_policy' ) ) { + $this->is_privacy_policy = true; + } } if ( ! empty( $qv['post_type'] ) ) { @@ -3877,6 +3894,27 @@ class WP_Query { return (bool) $this->is_home; } + /** + * Is the query for the Privacy Policy page? + * + * This is the page which shows the Privacy Policy content of your site. + * + * Depends on the site's "Change your Privacy Policy page" Privacy Settings 'wp_page_for_privacy_policy'. + * + * This function will return true only on the page you set as the "Privacy Policy page". + * + * @since 5.2.0 + * + * @return bool True, if Privacy Policy page. + */ + public function is_privacy_policy() { + if ( get_option( 'wp_page_for_privacy_policy' ) && $this->is_page( get_option( 'wp_page_for_privacy_policy' ) ) ) { + return true; + } else { + return false; + } + } + /** * Is the query for an existing month archive? * diff --git a/wp-includes/nav-menu-template.php b/wp-includes/nav-menu-template.php index 2c8a64ade7..45d9e47de4 100644 --- a/wp-includes/nav-menu-template.php +++ b/wp-includes/nav-menu-template.php @@ -361,8 +361,9 @@ function _wp_menu_item_classes_by_context( &$menu_items ) { $possible_object_parents = array_filter( $possible_object_parents ); - $front_page_url = home_url(); - $front_page_id = (int) get_option( 'page_on_front' ); + $front_page_url = home_url(); + $front_page_id = (int) get_option( 'page_on_front' ); + $privacy_policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' ); foreach ( (array) $menu_items as $key => $menu_item ) { @@ -378,6 +379,11 @@ function _wp_menu_item_classes_by_context( &$menu_items ) { $classes[] = 'menu-item-home'; } + // This menu item is set as the 'Privacy Policy Page'. + if ( 'post_type' === $menu_item->type && $privacy_policy_page_id === (int) $menu_item->object_id ) { + $classes[] = 'menu-item-privacy-policy'; + } + // if the menu item corresponds to a taxonomy term for the currently-queried non-hierarchical post object if ( $wp_query->is_singular && 'taxonomy' == $menu_item->type && in_array( $menu_item->object_id, $possible_object_parents ) ) { $active_parent_object_ids[] = (int) $menu_item->object_id; diff --git a/wp-includes/post-template.php b/wp-includes/post-template.php index 2aad0a03e0..b817edec4f 100644 --- a/wp-includes/post-template.php +++ b/wp-includes/post-template.php @@ -621,6 +621,9 @@ function get_body_class( $class = '' ) { if ( is_home() ) { $classes[] = 'blog'; } + if ( is_privacy_policy() ) { + $classes[] = 'privacy-policy'; + } if ( is_archive() ) { $classes[] = 'archive'; } diff --git a/wp-includes/query.php b/wp-includes/query.php index 98f1934b19..a2c7d19684 100644 --- a/wp-includes/query.php +++ b/wp-includes/query.php @@ -489,6 +489,36 @@ function is_home() { return $wp_query->is_home(); } +/** + * Determines whether the query is for the Privacy Policy page. + * + * The Privacy Policy page is the page that shows the Privacy Policy content of the site. + * + * is_privacy_policy() is dependent on the site's "Change your Privacy Policy page" Privacy Settings 'wp_page_for_privacy_policy'. + * + * This function will return true only on the page you set as the "Privacy Policy page". + * + * For more information on this and similar theme functions, check out + * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ + * Conditional Tags} article in the Theme Developer Handbook. + * + * @since 5.2.0 + * + * @global WP_Query $wp_query Global WP_Query instance. + * + * @return bool + */ +function is_privacy_policy() { + global $wp_query; + + if ( ! isset( $wp_query ) ) { + _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' ); + return false; + } + + return $wp_query->is_privacy_policy(); +} + /** * Determines whether the query is for an existing month archive. * diff --git a/wp-includes/template-loader.php b/wp-includes/template-loader.php index 0879798f55..7e627c508b 100644 --- a/wp-includes/template-loader.php +++ b/wp-includes/template-loader.php @@ -51,6 +51,7 @@ if ( wp_using_themes() ) : elseif ( is_search() && $template = get_search_template() ) : elseif ( is_front_page() && $template = get_front_page_template() ) : elseif ( is_home() && $template = get_home_template() ) : + elseif ( is_privacy_policy() && $template = get_privacy_policy_template() ) : elseif ( is_post_type_archive() && $template = get_post_type_archive_template() ) : elseif ( is_tax() && $template = get_taxonomy_template() ) : elseif ( is_attachment() && $template = get_attachment_template() ) : diff --git a/wp-includes/template.php b/wp-includes/template.php index 862b2ccbdf..67db6dd610 100644 --- a/wp-includes/template.php +++ b/wp-includes/template.php @@ -33,7 +33,7 @@ function get_query_template( $type, $templates = array() ) { * The last element in the array should always be the fallback template for this query type. * * Possible values for `$type` include: 'index', '404', 'archive', 'author', 'category', 'tag', 'taxonomy', 'date', - * 'embed', 'home', 'frontpage', 'page', 'paged', 'search', 'single', 'singular', and 'attachment'. + * 'embed', 'home', 'frontpage', 'privacypolicy', 'page', 'paged', 'search', 'single', 'singular', and 'attachment'. * * @since 4.7.0 * @@ -51,7 +51,7 @@ function get_query_template( $type, $templates = array() ) { * This hook also applies to various types of files loaded as part of the Template Hierarchy. * * Possible values for `$type` include: 'index', '404', 'archive', 'author', 'category', 'tag', 'taxonomy', 'date', - * 'embed', 'home', 'frontpage', 'page', 'paged', 'search', 'single', 'singular', and 'attachment'. + * 'embed', 'home', 'frontpage', 'privacypolicy', 'page', 'paged', 'search', 'single', 'singular', and 'attachment'. * * @since 1.5.0 * @since 4.8.0 The `$type` and `$templates` parameters were added. @@ -376,6 +376,24 @@ function get_front_page_template() { return get_query_template( 'front_page', $templates ); } +/** + * Retrieve path of Privacy Policy page template in current or parent template. + * + * The template hierarchy and template path are filterable via the {@see '$type_template_hierarchy'} + * and {@see '$type_template'} dynamic hooks, where `$type` is 'privacypolicy'. + * + * @since 5.2.0 + * + * @see get_query_template() + * + * @return string Full path to front page template file. + */ +function get_privacy_policy_template() { + $templates = array( 'privacy-policy.php' ); + + return get_query_template( 'privacy_policy', $templates ); +} + /** * Retrieve path of page template in current or parent template. * diff --git a/wp-includes/version.php b/wp-includes/version.php index 9f6e12dcd6..fa861b66b8 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.2-alpha-44965'; +$wp_version = '5.2-alpha-44966'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.