: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
update_post_cache( $children );
foreach ( $children as $key => $child ) {
$kids[ $child->ID ] = $children[ $key ];
if ( OBJECT === $output ) {
} elseif ( ARRAY_A === $output ) {
foreach ( (array) $kids as $kid ) {
$weeuns[ $kid->ID ] = get_object_vars( $kids[ $kid->ID ] );
} elseif ( ARRAY_N === $output ) {
foreach ( (array) $kids as $kid ) {
$babes[ $kid->ID ] = array_values( get_object_vars( $kids[ $kid->ID ] ) );
* Gets extended entry info (<!--more-->).
* There should not be any space after the second dash and before the word
* 'more'. There can be text or space(s) after the word 'more', but won't be
* The returned array has 'main', 'extended', and 'more_text' keys. Main has the text before
* the `<!--more-->`. The 'extended' key has the content after the
* `<!--more-->` comment. The 'more_text' key has the custom "Read More" text.
* @param string $post Post content.
* @type string $main Content before the more tag.
* @type string $extended Content after the more tag.
* @type string $more_text Custom read more text, or empty string.
function get_extended( $post ) {
// Match the new style more links.
if ( preg_match( '/<!--more(.*?)?-->/', $post, $matches ) ) {
list($main, $extended) = explode( $matches[0], $post, 2 );
$more_text = $matches[1];
// Leading and trailing whitespace.
$main = preg_replace( '/^[\s]*(.*)[\s]*$/', '\\1', $main );
$extended = preg_replace( '/^[\s]*(.*)[\s]*$/', '\\1', $extended );
$more_text = preg_replace( '/^[\s]*(.*)[\s]*$/', '\\1', $more_text );
'more_text' => $more_text,
* Retrieves post data given a post ID or post object.
* See sanitize_post() for optional $filter values. Also, the parameter
* `$post`, must be given as a variable, since it is passed by reference.
* @global WP_Post $post Global post object.
* @param int|WP_Post|null $post Optional. Post ID or post object. `null`, `false`, `0` and other PHP falsey values
* return the current global post inside the loop. A numerically valid post ID that
* points to a non-existent post returns `null`. Defaults to global $post.
* @param string $output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which
* correspond to a WP_Post object, an associative array, or a numeric array,
* respectively. Default OBJECT.
* @param string $filter Optional. Type of filter to apply. Accepts 'raw', 'edit', 'db',
* or 'display'. Default 'raw'.
* @return WP_Post|array|null Type corresponding to $output on success or null on failure.
* When $output is OBJECT, a `WP_Post` instance is returned.
function get_post( $post = null, $output = OBJECT, $filter = 'raw' ) {
if ( empty( $post ) && isset( $GLOBALS['post'] ) ) {
$post = $GLOBALS['post'];
if ( $post instanceof WP_Post ) {
} elseif ( is_object( $post ) ) {
if ( empty( $post->filter ) ) {
$_post = sanitize_post( $post, 'raw' );
$_post = new WP_Post( $_post );
} elseif ( 'raw' === $post->filter ) {
$_post = new WP_Post( $post );
$_post = WP_Post::get_instance( $post->ID );
$_post = WP_Post::get_instance( $post );
$_post = $_post->filter( $filter );
if ( ARRAY_A === $output ) {
return $_post->to_array();
} elseif ( ARRAY_N === $output ) {
return array_values( $_post->to_array() );
* Retrieves the IDs of the ancestors of a post.
* @param int|WP_Post $post Post ID or post object.
* @return int[] Array of ancestor IDs or empty array if there are none.
function get_post_ancestors( $post ) {
$post = get_post( $post );
if ( ! $post || empty( $post->post_parent ) || $post->post_parent == $post->ID ) {
$id = $post->post_parent;
while ( $ancestor = get_post( $id ) ) {
// Loop detection: If the ancestor has been seen before, break.
if ( empty( $ancestor->post_parent ) || ( $ancestor->post_parent == $post->ID ) || in_array( $ancestor->post_parent, $ancestors, true ) ) {
$id = $ancestor->post_parent;
* Retrieves data from a post field based on Post ID.
* Examples of the post field will be, 'post_type', 'post_status', 'post_content',
* etc and based off of the post object property or key names.
* The context values are based off of the taxonomy filter functions and
* supported values are found within those functions.
* @since 4.5.0 The `$post` parameter was made optional.
* @see sanitize_post_field()
* @param string $field Post field name.
* @param int|WP_Post $post Optional. Post ID or post object. Defaults to global $post.
* @param string $context Optional. How to filter the field. Accepts 'raw', 'edit', 'db',
* or 'display'. Default 'display'.
* @return string The value of the post field on success, empty string on failure.
function get_post_field( $field, $post = null, $context = 'display' ) {
$post = get_post( $post );
if ( ! isset( $post->$field ) ) {
return sanitize_post_field( $field, $post->$field, $post->ID, $context );
* Retrieves the mime type of an attachment based on the ID.
* This function can be used with any post type, but it makes more sense with
* @param int|WP_Post $post Optional. Post ID or post object. Defaults to global $post.
* @return string|false The mime type on success, false on failure.
function get_post_mime_type( $post = null ) {
$post = get_post( $post );
if ( is_object( $post ) ) {
return $post->post_mime_type;
* Retrieves the post status based on the post ID.
* If the post ID is of an attachment, then the parent post status will be given
* @param int|WP_Post $post Optional. Post ID or post object. Defaults to global $post.
* @return string|false Post status on success, false on failure.
function get_post_status( $post = null ) {
// Normalize the post object if necessary, skip normalization if called from get_sample_permalink().
if ( ! $post instanceof WP_Post || ! isset( $post->filter ) || 'sample' !== $post->filter ) {
$post = get_post( $post );
if ( ! is_object( $post ) ) {
$post_status = $post->post_status;
'attachment' === $post->post_type &&
'inherit' === $post_status
0 === $post->post_parent ||
! get_post( $post->post_parent ) ||
$post->ID === $post->post_parent
// Unattached attachments with inherit status are assumed to be published.
$post_status = 'publish';
} elseif ( 'trash' === get_post_status( $post->post_parent ) ) {
// Get parent status prior to trashing.
$post_status = get_post_meta( $post->post_parent, '_wp_trash_meta_status', true );
// Assume publish as above.
$post_status = 'publish';
$post_status = get_post_status( $post->post_parent );
'attachment' === $post->post_type &&
! in_array( $post_status, array( 'private', 'trash', 'auto-draft' ), true )
* Ensure uninherited attachments have a permitted status either 'private', 'trash', 'auto-draft'.
* This is to match the logic in wp_insert_post().
* Note: 'inherit' is excluded from this check as it is resolved to the parent post's
* status in the logic block above.
$post_status = 'publish';
* Filters the post status.
* @since 5.7.0 The attachment post type is now passed through this filter.
* @param string $post_status The post status.
* @param WP_Post $post The post object.
return apply_filters( 'get_post_status', $post_status, $post );
* Retrieves all of the WordPress supported post statuses.
* Posts have a limited set of valid status values, this provides the
* post_status values and descriptions.
* @return string[] Array of post status labels keyed by their status.
function get_post_statuses() {
'draft' => __( 'Draft' ),
'pending' => __( 'Pending Review' ),
'private' => __( 'Private' ),
'publish' => __( 'Published' ),
* Retrieves all of the WordPress support page statuses.
* Pages have a limited set of valid status values, this provides the
* post_status values and descriptions.
* @return string[] Array of page status labels keyed by their status.
function get_page_statuses() {
'draft' => __( 'Draft' ),
'private' => __( 'Private' ),
'publish' => __( 'Published' ),
* Returns statuses for privacy requests.
* @return string[] Array of privacy request status labels keyed by their status.
function _wp_privacy_statuses() {
'request-pending' => _x( 'Pending', 'request status' ), // Pending confirmation from user.
'request-confirmed' => _x( 'Confirmed', 'request status' ), // User has confirmed the action.
'request-failed' => _x( 'Failed', 'request status' ), // User failed to confirm the action.
'request-completed' => _x( 'Completed', 'request status' ), // Admin has handled the request.
* Registers a post status. Do not use before init.
* A simple function for creating or modifying a post status based on the
* parameters given. The function will accept an array (second optional
* parameter), along with a string for the post status name.
* Arguments prefixed with an _underscore shouldn't be used by plugins and themes.
* @global stdClass[] $wp_post_statuses Inserts new post status object into the list
* @param string $post_status Name of the post status.
* @param array|string $args {
* Optional. Array or string of post status arguments.
* @type bool|string $label A descriptive name for the post status marked
* for translation. Defaults to value of $post_status.
* @type array|false $label_count Nooped plural text from _n_noop() to provide the singular
* and plural forms of the label for counts. Default false
* which means the `$label` argument will be used for both
* the singular and plural forms of this label.
* @type bool $exclude_from_search Whether to exclude posts with this post status
* from search results. Default is value of $internal.
* @type bool $_builtin Whether the status is built-in. Core-use only.
* @type bool $public Whether posts of this status should be shown
* in the front end of the site. Default false.
* @type bool $internal Whether the status is for internal use only.
* @type bool $protected Whether posts with this status should be protected.
* @type bool $private Whether posts with this status should be private.
* @type bool $publicly_queryable Whether posts with this status should be publicly-
* queryable. Default is value of $public.
* @type bool $show_in_admin_all_list Whether to include posts in the edit listing for
* their post type. Default is the opposite value
* @type bool $show_in_admin_status_list Show in the list of statuses with post counts at
* the top of the edit listings,
* e.g. All (12) | Published (9) | My Custom Status (2)
* Default is the opposite value of $internal.
* @type bool $date_floating Whether the post has a floating creation date.
function register_post_status( $post_status, $args = array() ) {
global $wp_post_statuses;
if ( ! is_array( $wp_post_statuses ) ) {
$wp_post_statuses = array();
// Args prefixed with an underscore are reserved for internal use.
'exclude_from_search' => null,
'publicly_queryable' => null,
'show_in_admin_status_list' => null,
'show_in_admin_all_list' => null,
$args = wp_parse_args( $args, $defaults );
$post_status = sanitize_key( $post_status );
$args->name = $post_status;
if ( null === $args->public && null === $args->internal && null === $args->protected && null === $args->private ) {
if ( null === $args->public ) {
if ( null === $args->private ) {
if ( null === $args->protected ) {
$args->protected = false;
if ( null === $args->internal ) {
if ( null === $args->publicly_queryable ) {
$args->publicly_queryable = $args->public;
if ( null === $args->exclude_from_search ) {
$args->exclude_from_search = $args->internal;
if ( null === $args->show_in_admin_all_list ) {
$args->show_in_admin_all_list = ! $args->internal;
if ( null === $args->show_in_admin_status_list ) {
$args->show_in_admin_status_list = ! $args->internal;
if ( null === $args->date_floating ) {
$args->date_floating = false;
if ( false === $args->label ) {
$args->label = $post_status;
if ( false === $args->label_count ) {
// phpcs:ignore WordPress.WP.I18n.NonSingularStringLiteralSingular,WordPress.WP.I18n.NonSingularStringLiteralPlural
$args->label_count = _n_noop( $args->label, $args->label );
$wp_post_statuses[ $post_status ] = $args;
* Retrieves a post status object by name.
* @global stdClass[] $wp_post_statuses List of post statuses.
* @see register_post_status()
* @param string $post_status The name of a registered post status.
* @return stdClass|null A post status object.
function get_post_status_object( $post_status ) {
global $wp_post_statuses;
if ( empty( $wp_post_statuses[ $post_status ] ) ) {
return $wp_post_statuses[ $post_status ];
* Gets a list of post statuses.