Ticket #12588: is_post_of_type.diff

File is_post_of_type.diff, 1.2 KB (added by scribu, 3 years ago)

introduce is_post_of_type()

Line 
1Index: wp-includes/post.php
2===================================================================
3--- wp-includes/post.php        (revision 14499)
4+++ wp-includes/post.php        (working copy)
5@@ -681,23 +681,30 @@
6 }
7 
8 /**
9- * Checks if a post type is registered. Can also check if the current or specified post is of a post type.
10+ * Check if a post type is registered.
11  *
12  * @since 3.0.0
13+ * @uses get_post_type_object()
14+ *
15+ * @param string $types Type to check.
16+ * @return bool
17+ */
18+function is_post_type( $type ) {
19+       return (bool) get_post_type_object($type);
20+}
21+
22+/**
23+ * Check if the current or specified post is of a given post type.
24+ *
25+ * @since 3.0.0
26  * @uses get_post_type()
27  *
28- * @param string|array $types Type or types to check. Defaults to all post types.
29+ * @param string|array $types Type or types to check.
30  * @param int $id Post ID. Defaults to current ID.
31  * @return bool
32  */
33-function is_post_type( $types = false, $id = false ) {
34-       if ( $id ) {
35-               $types = ( $types === false ) ? get_post_types() : (array) $types;
36-
37-               return in_array( get_post_type( $id ), $types );
38-       }
39-
40-       return (bool) get_post_type_object($types);
41+function is_post_of_type( $types, $id = false ) {
42+       return in_array( get_post_type( $id ), (array) $types );
43 }
44 
45 /**