Make WordPress Core


Ignore:
Timestamp:
02/23/2016 10:49:17 PM (8 years ago)
Author:
swissspidy
Message:

Posts: Introduce get_post_types_by_support().

Similar to get_post_types(), this new function returns a list of post type names that support a specific feature.

Props wpsmith, barryceelen, swissspidy.
Fixes #34010.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/post.php

    r36607 r36652  
    16401640
    16411641/**
     1642 * Get a list of post type names that support a specific feature.
     1643 *
     1644 * @since 4.5.0
     1645 *
     1646 * @global array $_wp_post_type_features
     1647 *
     1648 * @param array|string $args     Single feature or an array of features the post types should support.
     1649 * @param string       $operator Optional. The logical operation to perform. 'or' means
     1650 *                               only one element from the array needs to match; 'and'
     1651 *                               means all elements must match; 'not' means no elements may
     1652 *                               match. Default 'and'.
     1653 * @return array A list of post type names.
     1654 */
     1655function get_post_types_by_support( $args, $operator = 'and' ) {
     1656    global $_wp_post_type_features;
     1657
     1658    $features = array_fill_keys( (array) $args, true );
     1659
     1660    return array_keys( wp_filter_object_list( $_wp_post_type_features, $features, $operator ) );
     1661}
     1662
     1663/**
    16421664 * Update the post type for the post ID.
    16431665 *
Note: See TracChangeset for help on using the changeset viewer.