Changeset 54555 for branches/5.6/src/wp-includes/post.php
- Timestamp:
- 10/17/2022 05:56:34 PM (2 years ago)
- Location:
- branches/5.6
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/5.6
- Property svn:mergeinfo changed
/trunk merged: 54521-54530,54541
- Property svn:mergeinfo changed
-
branches/5.6/src/wp-includes/post.php
r52467 r54555 1988 1988 * @since 4.5.0 Added the ability to pass a post type name in addition to object. 1989 1989 * @since 4.6.0 Converted the `$post_type` parameter to accept a `WP_Post_Type` object. 1990 * @since 5.9.0 Added `is_post_type_viewable` hook to filter the result. 1990 1991 * 1991 1992 * @param string|WP_Post_Type $post_type Post type name or object. … … 1995 1996 if ( is_scalar( $post_type ) ) { 1996 1997 $post_type = get_post_type_object( $post_type ); 1998 1997 1999 if ( ! $post_type ) { 1998 2000 return false; … … 2000 2002 } 2001 2003 2002 return $post_type->publicly_queryable || ( $post_type->_builtin && $post_type->public ); 2004 if ( ! is_object( $post_type ) ) { 2005 return false; 2006 } 2007 2008 $is_viewable = $post_type->publicly_queryable || ( $post_type->_builtin && $post_type->public ); 2009 2010 /** 2011 * Filters whether a post type is considered "viewable". 2012 * 2013 * The returned filtered value must be a boolean type to ensure 2014 * `is_post_type_viewable()` only returns a boolean. This strictness 2015 * is by design to maintain backwards-compatibility and guard against 2016 * potential type errors in PHP 8.1+. Non-boolean values (even falsey 2017 * and truthy values) will result in the function returning false. 2018 * 2019 * @since 5.9.0 2020 * 2021 * @param bool $is_viewable Whether the post type is "viewable" (strict type). 2022 * @param WP_Post_Type $post_type Post type object. 2023 */ 2024 return true === apply_filters( 'is_post_type_viewable', $is_viewable, $post_type ); 2025 } 2026 2027 /** 2028 * Determines whether a post status is considered "viewable". 2029 * 2030 * For built-in post statuses such as publish and private, the 'public' value will be evaluated. 2031 * For all others, the 'publicly_queryable' value will be used. 2032 * 2033 * @since 5.7.0 2034 * @since 5.9.0 Added `is_post_status_viewable` hook to filter the result. 2035 * 2036 * @param string|stdClass $post_status Post status name or object. 2037 * @return bool Whether the post status should be considered viewable. 2038 */ 2039 function is_post_status_viewable( $post_status ) { 2040 if ( is_scalar( $post_status ) ) { 2041 $post_status = get_post_status_object( $post_status ); 2042 2043 if ( ! $post_status ) { 2044 return false; 2045 } 2046 } 2047 2048 if ( 2049 ! is_object( $post_status ) || 2050 $post_status->internal || 2051 $post_status->protected 2052 ) { 2053 return false; 2054 } 2055 2056 $is_viewable = $post_status->publicly_queryable || ( $post_status->_builtin && $post_status->public ); 2057 2058 /** 2059 * Filters whether a post status is considered "viewable". 2060 * 2061 * The returned filtered value must be a boolean type to ensure 2062 * `is_post_status_viewable()` only returns a boolean. This strictness 2063 * is by design to maintain backwards-compatibility and guard against 2064 * potential type errors in PHP 8.1+. Non-boolean values (even falsey 2065 * and truthy values) will result in the function returning false. 2066 * 2067 * @since 5.9.0 2068 * 2069 * @param bool $is_viewable Whether the post status is "viewable" (strict type). 2070 * @param stdClass $post_status Post status object. 2071 */ 2072 return true === apply_filters( 'is_post_status_viewable', $is_viewable, $post_status ); 2073 } 2074 2075 /** 2076 * Determines whether a post is publicly viewable. 2077 * 2078 * Posts are considered publicly viewable if both the post status and post type 2079 * are viewable. 2080 * 2081 * @since 5.7.0 2082 * 2083 * @param int|WP_Post|null $post Optional. Post ID or post object. Defaults to global $post. 2084 * @return bool Whether the post is publicly viewable. 2085 */ 2086 function is_post_publicly_viewable( $post = null ) { 2087 $post = get_post( $post ); 2088 2089 if ( ! $post ) { 2090 return false; 2091 } 2092 2093 $post_type = get_post_type( $post ); 2094 $post_status = get_post_status( $post ); 2095 2096 return is_post_type_viewable( $post_type ) && is_post_status_viewable( $post_status ); 2003 2097 } 2004 2098 … … 7476 7570 7477 7571 /** 7478 * Filters the SQL clauses of an attachment query to include filenames.7479 *7480 * @since 4.7.07481 * @access private7482 *7483 * @global wpdb $wpdb WordPress database abstraction object.7484 *7485 * @param string[] $clauses An array including WHERE, GROUP BY, JOIN, ORDER BY,7486 * DISTINCT, fields (SELECT), and LIMITS clauses.7487 * @return string[] The modified array of clauses.7488 */7489 function _filter_query_attachment_filenames( $clauses ) {7490 global $wpdb;7491 remove_filter( 'posts_clauses', __FUNCTION__ );7492 7493 // Add a LEFT JOIN of the postmeta table so we don't trample existing JOINs.7494 $clauses['join'] .= " LEFT JOIN {$wpdb->postmeta} AS sq1 ON ( {$wpdb->posts}.ID = sq1.post_id AND sq1.meta_key = '_wp_attached_file' )";7495 7496 $clauses['groupby'] = "{$wpdb->posts}.ID";7497 7498 $clauses['where'] = preg_replace(7499 "/\({$wpdb->posts}.post_content (NOT LIKE|LIKE) (\'[^']+\')\)/",7500 '$0 OR ( sq1.meta_value $1 $2 )',7501 $clauses['where']7502 );7503 7504 return $clauses;7505 }7506 7507 /**7508 7572 * Sets the last changed time for the 'posts' cache group. 7509 7573 *
Note: See TracChangeset
for help on using the changeset viewer.