Changeset 54563 for branches/5.2/src/wp-includes/post.php
- Timestamp:
- 10/17/2022 06:08:00 PM (2 years ago)
- Location:
- branches/5.2
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/5.2
- Property svn:mergeinfo changed
/trunk merged: 54521-54530,54541
- Property svn:mergeinfo changed
-
branches/5.2/src/wp-includes/post.php
r52471 r54563 1884 1884 * @since 4.5.0 Added the ability to pass a post type name in addition to object. 1885 1885 * @since 4.6.0 Converted the `$post_type` parameter to accept a `WP_Post_Type` object. 1886 * @since 5.9.0 Added `is_post_type_viewable` hook to filter the result. 1886 1887 * 1887 1888 * @param string|WP_Post_Type $post_type Post type name or object. … … 1891 1892 if ( is_scalar( $post_type ) ) { 1892 1893 $post_type = get_post_type_object( $post_type ); 1894 1893 1895 if ( ! $post_type ) { 1894 1896 return false; … … 1896 1898 } 1897 1899 1898 return $post_type->publicly_queryable || ( $post_type->_builtin && $post_type->public ); 1900 if ( ! is_object( $post_type ) ) { 1901 return false; 1902 } 1903 1904 $is_viewable = $post_type->publicly_queryable || ( $post_type->_builtin && $post_type->public ); 1905 1906 /** 1907 * Filters whether a post type is considered "viewable". 1908 * 1909 * The returned filtered value must be a boolean type to ensure 1910 * `is_post_type_viewable()` only returns a boolean. This strictness 1911 * is by design to maintain backwards-compatibility and guard against 1912 * potential type errors in PHP 8.1+. Non-boolean values (even falsey 1913 * and truthy values) will result in the function returning false. 1914 * 1915 * @since 5.9.0 1916 * 1917 * @param bool $is_viewable Whether the post type is "viewable" (strict type). 1918 * @param WP_Post_Type $post_type Post type object. 1919 */ 1920 return true === apply_filters( 'is_post_type_viewable', $is_viewable, $post_type ); 1921 } 1922 1923 /** 1924 * Determines whether a post status is considered "viewable". 1925 * 1926 * For built-in post statuses such as publish and private, the 'public' value will be evaluated. 1927 * For all others, the 'publicly_queryable' value will be used. 1928 * 1929 * @since 5.7.0 1930 * @since 5.9.0 Added `is_post_status_viewable` hook to filter the result. 1931 * 1932 * @param string|stdClass $post_status Post status name or object. 1933 * @return bool Whether the post status should be considered viewable. 1934 */ 1935 function is_post_status_viewable( $post_status ) { 1936 if ( is_scalar( $post_status ) ) { 1937 $post_status = get_post_status_object( $post_status ); 1938 1939 if ( ! $post_status ) { 1940 return false; 1941 } 1942 } 1943 1944 if ( 1945 ! is_object( $post_status ) || 1946 $post_status->internal || 1947 $post_status->protected 1948 ) { 1949 return false; 1950 } 1951 1952 $is_viewable = $post_status->publicly_queryable || ( $post_status->_builtin && $post_status->public ); 1953 1954 /** 1955 * Filters whether a post status is considered "viewable". 1956 * 1957 * The returned filtered value must be a boolean type to ensure 1958 * `is_post_status_viewable()` only returns a boolean. This strictness 1959 * is by design to maintain backwards-compatibility and guard against 1960 * potential type errors in PHP 8.1+. Non-boolean values (even falsey 1961 * and truthy values) will result in the function returning false. 1962 * 1963 * @since 5.9.0 1964 * 1965 * @param bool $is_viewable Whether the post status is "viewable" (strict type). 1966 * @param stdClass $post_status Post status object. 1967 */ 1968 return true === apply_filters( 'is_post_status_viewable', $is_viewable, $post_status ); 1969 } 1970 1971 /** 1972 * Determines whether a post is publicly viewable. 1973 * 1974 * Posts are considered publicly viewable if both the post status and post type 1975 * are viewable. 1976 * 1977 * @since 5.7.0 1978 * 1979 * @param int|WP_Post|null $post Optional. Post ID or post object. Defaults to global $post. 1980 * @return bool Whether the post is publicly viewable. 1981 */ 1982 function is_post_publicly_viewable( $post = null ) { 1983 $post = get_post( $post ); 1984 1985 if ( ! $post ) { 1986 return false; 1987 } 1988 1989 $post_type = get_post_type( $post ); 1990 $post_status = get_post_status( $post ); 1991 1992 return is_post_type_viewable( $post_type ) && is_post_status_viewable( $post_status ); 1899 1993 } 1900 1994 … … 6864 6958 6865 6959 /** 6866 * Filter the SQL clauses of an attachment query to include filenames.6867 *6868 * @since 4.7.06869 * @access private6870 *6871 * @global wpdb $wpdb WordPress database abstraction object.6872 *6873 * @param array $clauses An array including WHERE, GROUP BY, JOIN, ORDER BY,6874 * DISTINCT, fields (SELECT), and LIMITS clauses.6875 * @return array The modified clauses.6876 */6877 function _filter_query_attachment_filenames( $clauses ) {6878 global $wpdb;6879 remove_filter( 'posts_clauses', __FUNCTION__ );6880 6881 // Add a LEFT JOIN of the postmeta table so we don't trample existing JOINs.6882 $clauses['join'] .= " LEFT JOIN {$wpdb->postmeta} AS sq1 ON ( {$wpdb->posts}.ID = sq1.post_id AND sq1.meta_key = '_wp_attached_file' )";6883 6884 $clauses['groupby'] = "{$wpdb->posts}.ID";6885 6886 $clauses['where'] = preg_replace(6887 "/\({$wpdb->posts}.post_content (NOT LIKE|LIKE) (\'[^']+\')\)/",6888 '$0 OR ( sq1.meta_value $1 $2 )',6889 $clauses['where']6890 );6891 6892 return $clauses;6893 }6894 6895 /**6896 6960 * Sets the last changed time for the 'posts' cache group. 6897 6961 *
Note: See TracChangeset
for help on using the changeset viewer.