WordPress.org

Make WordPress Core

Ticket #34010: 34010b.post.php.patch

File 34010b.post.php.patch, 1.4 KB (added by wpsmith, 6 years ago)

get_post_types_by_supports()

  • wp-includes/post.php

     
    11981198}
    11991199
    12001200/**
     1201 * Get a list of post type names that support a specific feature.
     1202 *
     1203 * @since 4.4.0
     1204 *
     1205 * @uses get_post_types_by_support Get a list of post type names that support a specific feature.
     1206 *
     1207 * @param array  $features Array of a support features.
     1208 * @param string $operator Operator for retrieving post types by multiple features.
     1209 *                         Default: 'and' ('or' is only other option)
     1210 *
     1211 * @return array $post_types Array of post type names that support a feature.
     1212 */
     1213function get_post_types_by_supports( $features, $operator = 'and' ) {
     1214        $features = ! is_array( $features ) ? (array) $features : $features;
     1215        $supports = array();
     1216
     1217        if ( 'and' === strtolower( $operator ) ) {
     1218                foreach ( $features as $feature ) {
     1219                        $supports[ $feature ] = true;
     1220                }
     1221
     1222                return get_post_types_by_support( $supports );
     1223        } else {
     1224                $post_types = array();
     1225                foreach ( $features as $feature ) {
     1226                        $post_types = array_merge( $post_types, get_post_types_by_support( $feature ) );
     1227                }
     1228
     1229                return array_unique( $post_types );
     1230        }
     1231
     1232}
     1233
     1234/**
    12011235 * Register a post type. Do not use before init.
    12021236 *
    12031237 * A function for creating or modifying a post type based on the