wp/wp-includes/query.php
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 16 a86126ab1dd4
--- a/wp/wp-includes/query.php	Mon Oct 14 18:06:33 2019 +0200
+++ b/wp/wp-includes/query.php	Mon Oct 14 18:28:13 2019 +0200
@@ -93,9 +93,9 @@
  * @param array|string $query Array or string of WP_Query arguments.
  * @return array List of post objects.
  */
-function query_posts($query) {
+function query_posts( $query ) {
 	$GLOBALS['wp_query'] = new WP_Query();
-	return $GLOBALS['wp_query']->query($query);
+	return $GLOBALS['wp_query']->query( $query );
 }
 
 /**
@@ -136,10 +136,14 @@
  */
 
 /**
- * Is the query for an existing archive page?
+ * Determines whether the query is for an existing archive page.
  *
  * Month, Year, Category, Author, Post Type archive...
  *
+ * 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 1.5.0
  *
  * @global WP_Query $wp_query Global WP_Query instance.
@@ -158,7 +162,11 @@
 }
 
 /**
- * Is the query for an existing post type archive page?
+ * Determines whether the query is for an existing post type archive 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 3.1.0
  *
@@ -179,7 +187,11 @@
 }
 
 /**
- * Is the query for an existing attachment page?
+ * Determines whether the query is for an existing attachment 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 2.0.0
  *
@@ -200,11 +212,15 @@
 }
 
 /**
- * Is the query for an existing author archive page?
+ * Determines whether the query is for an existing author archive page.
  *
  * If the $author parameter is specified, this function will additionally
  * check if the query is for one of the authors specified.
  *
+ * 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 1.5.0
  *
  * @global WP_Query $wp_query Global WP_Query instance.
@@ -224,11 +240,15 @@
 }
 
 /**
- * Is the query for an existing category archive page?
+ * Determines whether the query is for an existing category archive page.
  *
  * If the $category parameter is specified, this function will additionally
  * check if the query is for one of the categories specified.
  *
+ * 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 1.5.0
  *
  * @global WP_Query $wp_query Global WP_Query instance.
@@ -248,11 +268,15 @@
 }
 
 /**
- * Is the query for an existing tag archive page?
+ * Determines whether the query is for an existing tag archive page.
  *
  * If the $tag parameter is specified, this function will additionally
  * check if the query is for one of the tags specified.
  *
+ * 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 2.3.0
  *
  * @global WP_Query $wp_query Global WP_Query instance.
@@ -272,7 +296,7 @@
 }
 
 /**
- * Is the query for an existing custom taxonomy archive page?
+ * Determines whether the query is for an existing custom taxonomy archive page.
  *
  * If the $taxonomy parameter is specified, this function will additionally
  * check if the query is for that specific $taxonomy.
@@ -281,6 +305,10 @@
  * this function will additionally check if the query is for one of the terms
  * specified.
  *
+ * 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 2.5.0
  *
  * @global WP_Query $wp_query Global WP_Query instance.
@@ -301,7 +329,11 @@
 }
 
 /**
- * Is the query for an existing date archive?
+ * Determines whether the query is for an existing date archive.
+ *
+ * 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 1.5.0
  *
@@ -321,7 +353,13 @@
 }
 
 /**
- * Is the query for an existing day archive?
+ * Determines whether the query is for an existing day archive.
+ *
+ * A conditional check to test whether the page is a date-based archive page displaying posts for the current day.
+ *
+ * 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 1.5.0
  *
@@ -341,7 +379,11 @@
 }
 
 /**
- * Is the query for a feed?
+ * Determines whether the query is for a feed.
+ *
+ * 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 1.5.0
  *
@@ -382,7 +424,7 @@
 }
 
 /**
- * Is the query for the front page of the site?
+ * Determines whether the query is for the front page of the site.
  *
  * This is for what is displayed at your site's main URL.
  *
@@ -393,6 +435,10 @@
  *
  * Otherwise the same as @see is_home()
  *
+ * 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 2.5.0
  *
  * @global WP_Query $wp_query Global WP_Query instance.
@@ -411,7 +457,7 @@
 }
 
 /**
- * Determines if the query is for the blog homepage.
+ * Determines whether the query is for the blog homepage.
  *
  * The blog homepage is the page that shows the time-based blog content of the site.
  *
@@ -421,6 +467,10 @@
  * If a static page is set for the front page of the site, this function will return true only
  * on the page you set as the "Posts 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 1.5.0
  *
  * @see is_front_page()
@@ -440,7 +490,41 @@
 }
 
 /**
- * Is the query for an existing month archive?
+ * 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.
+ *
+ * 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 1.5.0
  *
@@ -460,11 +544,15 @@
 }
 
 /**
- * Is the query for an existing single page?
+ * Determines whether the query is for an existing single page.
  *
  * If the $page parameter is specified, this function will additionally
  * check if the query is for one of the pages specified.
  *
+ * 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.
+ *
  * @see is_single()
  * @see is_singular()
  *
@@ -487,7 +575,11 @@
 }
 
 /**
- * Is the query for paged result and not for the first page?
+ * Determines whether the query is for paged results and not for the first 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 1.5.0
  *
@@ -507,7 +599,11 @@
 }
 
 /**
- * Is the query for a post or page preview?
+ * Determines whether the query is for a post or page preview.
+ *
+ * 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 2.0.0
  *
@@ -547,7 +643,11 @@
 }
 
 /**
- * Is the query for a search?
+ * Determines whether the query is for a search.
+ *
+ * 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 1.5.0
  *
@@ -567,13 +667,17 @@
 }
 
 /**
- * Is the query for an existing single post?
+ * Determines whether the query is for an existing single post.
  *
  * Works for any post type, except attachments and pages
  *
  * If the $post parameter is specified, this function will additionally
  * check if the query is for one of the Posts specified.
  *
+ * 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.
+ *
  * @see is_page()
  * @see is_singular()
  *
@@ -596,12 +700,16 @@
 }
 
 /**
- * Is the query for an existing single post of any post type (post, attachment, page,
- * custom post types)?
+ * Determines whether the query is for an existing single post of any post type
+ * (post, attachment, page, custom post types).
  *
  * If the $post_types parameter is specified, this function will additionally
  * check if the query is for one of the Posts Types specified.
  *
+ * 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.
+ *
  * @see is_page()
  * @see is_single()
  *
@@ -624,7 +732,11 @@
 }
 
 /**
- * Is the query for a specific time?
+ * Determines whether the query is for a specific time.
+ *
+ * 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 1.5.0
  *
@@ -644,7 +756,11 @@
 }
 
 /**
- * Is the query for a trackback endpoint call?
+ * Determines whether the query is for a trackback endpoint call.
+ *
+ * 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 1.5.0
  *
@@ -664,7 +780,11 @@
 }
 
 /**
- * Is the query for an existing year archive?
+ * Determines whether the query is for an existing year archive.
+ *
+ * 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 1.5.0
  *
@@ -684,7 +804,11 @@
 }
 
 /**
- * Is the query a 404 (returns no results)?
+ * Determines whether the query has resulted in a 404 (returns no results).
+ *
+ * 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 1.5.0
  *
@@ -724,7 +848,11 @@
 }
 
 /**
- * Is the query the main query?
+ * Determines whether the query is the main query.
+ *
+ * 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 3.3.0
  *
@@ -768,7 +896,11 @@
 }
 
 /**
- * Whether the caller is in the Loop.
+ * Determines whether the caller is in the Loop.
+ *
+ * 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 2.0.0
  *
@@ -892,7 +1024,7 @@
 
 		if ( get_query_var( 'paged' ) > 1 ) {
 			$link = user_trailingslashit( trailingslashit( $link ) . 'page/' . get_query_var( 'paged' ) );
-		} elseif( is_embed() ) {
+		} elseif ( is_embed() ) {
 			$link = user_trailingslashit( trailingslashit( $link ) . 'embed' );
 		}
 
@@ -935,13 +1067,13 @@
 	// if year, monthnum, or day have been specified, make our query more precise
 	// just in case there are multiple identical _wp_old_slug values
 	if ( get_query_var( 'year' ) ) {
-		$query .= $wpdb->prepare( " AND YEAR(post_date) = %d", get_query_var( 'year' ) );
+		$query .= $wpdb->prepare( ' AND YEAR(post_date) = %d', get_query_var( 'year' ) );
 	}
 	if ( get_query_var( 'monthnum' ) ) {
-		$query .= $wpdb->prepare( " AND MONTH(post_date) = %d", get_query_var( 'monthnum' ) );
+		$query .= $wpdb->prepare( ' AND MONTH(post_date) = %d', get_query_var( 'monthnum' ) );
 	}
 	if ( get_query_var( 'day' ) ) {
-		$query .= $wpdb->prepare( " AND DAYOFMONTH(post_date) = %d", get_query_var( 'day' ) );
+		$query .= $wpdb->prepare( ' AND DAYOFMONTH(post_date) = %d', get_query_var( 'day' ) );
 	}
 
 	$id = (int) $wpdb->get_var( $query );
@@ -967,13 +1099,13 @@
 
 	$date_query = '';
 	if ( get_query_var( 'year' ) ) {
-		$date_query .= $wpdb->prepare( " AND YEAR(pm_date.meta_value) = %d", get_query_var( 'year' ) );
+		$date_query .= $wpdb->prepare( ' AND YEAR(pm_date.meta_value) = %d', get_query_var( 'year' ) );
 	}
 	if ( get_query_var( 'monthnum' ) ) {
-		$date_query .= $wpdb->prepare( " AND MONTH(pm_date.meta_value) = %d", get_query_var( 'monthnum' ) );
+		$date_query .= $wpdb->prepare( ' AND MONTH(pm_date.meta_value) = %d', get_query_var( 'monthnum' ) );
 	}
 	if ( get_query_var( 'day' ) ) {
-		$date_query .= $wpdb->prepare( " AND DAYOFMONTH(pm_date.meta_value) = %d", get_query_var( 'day' ) );
+		$date_query .= $wpdb->prepare( ' AND DAYOFMONTH(pm_date.meta_value) = %d', get_query_var( 'day' ) );
 	}
 
 	$id = 0;
@@ -1009,3 +1141,23 @@
 
 	return false;
 }
+
+/**
+ * Generates post data.
+ *
+ * @since 5.2.0
+ *
+ * @global WP_Query $wp_query Global WP_Query instance.
+ *
+ * @param WP_Post|object|int $post WP_Post instance or Post ID/object.
+ * @return array|bool Elements of post, or false on failure.
+ */
+function generate_postdata( $post ) {
+	global $wp_query;
+
+	if ( ! empty( $wp_query ) && $wp_query instanceof WP_Query ) {
+		return $wp_query->generate_postdata( $post );
+	}
+
+	return false;
+}