Tribe__Context::is_editing_post( null|array|string|int $post_or_type = null )
Whether we are currently editing a post(s), post type(s) or not.
Contents
Parameters
- $post_or_type
-
(null|array|string|int) (Optional) A post ID, post type, an array of post types or post IDs,
null
to just make sure we are currently editing a post.Default value: null
Return
(bool)
Source
File: src/Tribe/Context.php
public function is_editing_post( $post_or_type = null ) { global $pagenow; $is_new = 'post-new.php' === $pagenow; $is_post = 'post.php' === $pagenow; if ( ! $is_new && ! $is_post ) { return false; } if ( null !== $post_or_type ) { $lookup = array( $_GET, $_POST, $_REQUEST ); $current_post = Tribe__Utils__Array::get_in_any( $lookup, 'post', get_post() ); if ( is_numeric( $post_or_type ) ) { $post = $is_post ? get_post( $post_or_type ) : null; return ! empty( $post ) && $post == $current_post; } $post_types = is_array( $post_or_type ) ? $post_or_type : array( $post_or_type ); $post = $is_post ? $current_post : null; if ( count( array_filter( $post_types, 'is_numeric' ) ) === count( $post_types ) ) { return ! empty( $post ) && in_array( $post->ID, $post_types ); } if ( $is_post && $post instanceof WP_Post ) { $post_type = $post->post_type; } else { $post_type = Tribe__Utils__Array::get_in_any( $lookup, 'post_type', 'post' ); } return (bool) count( array_intersect( $post_types, array( $post_type ) ) ); } return $is_new || $is_post; }
Changelog
Version | Description |
---|---|
4.7.7 | Introduced. |