Make WordPress Core

Ticket #37667: 37667.diff

File 37667.diff, 10.3 KB (added by flixos90, 7 years ago)
  • src/wp-includes/class-wp-post-type.php

     
    325325        public $rewrite;
    326326
    327327        /**
    328          * The features supported by the post type.
     328         * The features supported by the post type, per post type definition.
    329329         *
    330330         * @since 4.6.0
    331331         * @access public
     
    334334        public $supports;
    335335
    336336        /**
     337         * All features supported by the post type.
     338         *
     339         * @since 4.7.0
     340         * @access private
     341         * @var array $features
     342         */
     343        private $features = array();
     344
     345        /**
    337346         * Constructor.
    338347         *
    339348         * Will populate object properties from the provided arguments and assign other
     
    511520         */
    512521        public function add_supports() {
    513522                if ( ! empty( $this->supports ) ) {
    514                         add_post_type_support( $this->name, $this->supports );
     523                        $this->add_support( $this->supports );
    515524                        unset( $this->supports );
    516525                } elseif ( false !== $this->supports ) {
    517526                        // Add default features.
    518                         add_post_type_support( $this->name, array( 'title', 'editor' ) );
     527                        $this->add_support( array( 'title', 'editor' ) );
    519528                }
    520529        }
    521530
     
    602611        }
    603612
    604613        /**
     614         * Registers support of certain features for the post type.
     615         *
     616         * All core features are directly associated with a functional area of the edit
     617         * screen, such as the editor or a meta box. Features include: 'title', 'editor',
     618         * 'comments', 'revisions', 'trackbacks', 'author', 'excerpt', 'page-attributes',
     619         * 'thumbnail', 'custom-fields', and 'post-formats'.
     620         *
     621         * Additionally, the 'revisions' feature dictates whether the post type will
     622         * store revisions, and the 'comments' feature dictates whether the comments
     623         * count will show on the edit screen.
     624         *
     625         * @since 4.7.0
     626         * @access public
     627         *
     628         * @param string|array $feature The feature being added, accepts an array of
     629         *                              feature strings or a single string.
     630         * @param bool         $value   Optional. The value to give to the feature. Default
     631         *                              true.
     632         * @param string       $subtype Optional. A subtype to add this feature to. An
     633         *                              empty value will add this feature to the overall
     634         *                              post type. Default empty.
     635         */
     636        public function add_support( $feature, $value = true, $subtype = '' ) {
     637                $features = (array) $feature;
     638                foreach ( $features as $feature ) {
     639                        $this->features[ $subtype ][ $feature ] = $value;
     640                }
     641        }
     642
     643        /**
     644         * Removes support for a feature from the post type.
     645         *
     646         * @since 4.7.0
     647         * @access public
     648         *
     649         * @param string $feature The feature being removed.
     650         * @param string $subtype Optional. A subtype to remove this feature from. An
     651         *                        empty value will remove this feature from the overall
     652         *                        post type. Default empty.
     653         */
     654        public function remove_support( $feature, $subtype = '' ) {
     655                unset( $this->features[ $subtype ][ $feature ] );
     656        }
     657
     658        /**
     659         * Gets all the post type features.
     660         *
     661         * @since 4.7.0
     662         * @access public
     663         *
     664         * @param string $subtype Optional. A subtype to get its features. An
     665         *                        empty value will return the overall post type
     666         *                        features. Default empty.
     667         * @return array Post type supports list.
     668         */
     669        public function get_all_supports( $subtype = '' ) {
     670                return $this->features[ $subtype ];
     671        }
     672
     673        /**
     674         * Checks the post type's support for a given feature.
     675         *
     676         * @since 4.7.0
     677         * @access public
     678         *
     679         * @param string $feature The feature being checked.
     680         * @param string $subtype Optional. A subtype to check in its features. An
     681         *                        empty value will check within the overall post type
     682         *                        features. Default empty.
     683         * @return bool Whether the post type supports the given feature.
     684         */
     685        public function supports( $feature, $subtype = '' ) {
     686                return isset( $this->features[ $subtype ][ $feature ] );
     687        }
     688
     689        /**
     690         * Retrieves a list of post type and subtype names that support a specific feature.
     691         *
     692         * If the features are supported by the overall post type, the post type name is
     693         * included in the list. If the features are supported by a specific subtype, a
     694         * string consisting of post type name and subtype name delimited by a colon is
     695         * included in the list.
     696         *
     697         * @since 4.7.0
     698         * @access public
     699         *
     700         * @param array|string $feature  Single feature or an array of features the post type should support.
     701         * @param string       $operator Optional. The logical operation to perform. 'or' means
     702         *                               only one element from the array needs to match; 'and'
     703         *                               means all elements must match; 'not' means no elements may
     704         *                               match. Default 'and'.
     705         * @return array A list of post type and subtype names.
     706         */
     707        public function get_by_support( $feature, $operator = 'and' ) {
     708                $features = array_fill_keys( (array) $feature, true );
     709                $subtypes = array_keys( wp_filter_object_list( $this->features, $features, $operator ) );
     710
     711                $names = array();
     712                foreach ( $subtypes as $subtype ) {
     713                        if ( empty( $subtype ) ) {
     714                                $names[] = $this->name;
     715                        } else {
     716                                $names[] = $this->name . ':' . $subtype;
     717                        }
     718                }
     719
     720                return $names;
     721        }
     722
     723        /**
    605724         * Removes the features support for the post type.
    606725         *
    607726         * @since 4.6.0
    608727         * @access public
    609          *
    610          * @global array $_wp_post_type_features Post type features.
    611728         */
    612729        public function remove_supports() {
    613                 global $_wp_post_type_features;
    614 
    615                 unset( $_wp_post_type_features[ $this->name ] );
     730                $this->features = array();
    616731        }
    617732
    618733        /**
  • src/wp-includes/post.php

     
    13981398 * count will show on the edit screen.
    13991399 *
    14001400 * @since 3.0.0
     1401 * @since 4.7.0 Uses `WP_Post_Type` to handle features.
    14011402 *
    1402  * @global array $_wp_post_type_features
    1403  *
    14041403 * @param string       $post_type The post type for which to add the feature.
    14051404 * @param string|array $feature   The feature being added, accepts an array of
    14061405 *                                feature strings or a single string.
    14071406 */
    14081407function add_post_type_support( $post_type, $feature ) {
    1409         global $_wp_post_type_features;
     1408        $subtype = '';
     1409        if ( strpos( $post_type, ':' ) ) {
     1410                list( $post_type, $subtype ) = explode( ':', $post_type );
     1411        }
    14101412
    1411         $features = (array) $feature;
    1412         foreach ($features as $feature) {
    1413                 if ( func_num_args() == 2 )
    1414                         $_wp_post_type_features[$post_type][$feature] = true;
    1415                 else
    1416                         $_wp_post_type_features[$post_type][$feature] = array_slice( func_get_args(), 2 );
     1413        $ptype_obj = get_post_type_object( $post_type );
     1414        if ( ! $ptype_obj ) {
     1415                return;
    14171416        }
     1417
     1418        if ( func_num_args() == 2 ) {
     1419                $value = true;
     1420        } else {
     1421                $value = array_slice( func_get_args(), 2 );
     1422        }
     1423
     1424        $ptype_obj->add_support( $feature, $value, $subtype );
    14181425}
    14191426
    14201427/**
    14211428 * Remove support for a feature from a post type.
    14221429 *
    14231430 * @since 3.0.0
     1431 * @since 4.7.0 Uses `WP_Post_Type` to handle features.
    14241432 *
    1425  * @global array $_wp_post_type_features
    1426  *
    14271433 * @param string $post_type The post type for which to remove the feature.
    14281434 * @param string $feature   The feature being removed.
    14291435 */
    14301436function remove_post_type_support( $post_type, $feature ) {
    1431         global $_wp_post_type_features;
     1437        $subtype = '';
     1438        if ( strpos( $post_type, ':' ) ) {
     1439                list( $post_type, $subtype ) = explode( ':', $post_type );
     1440        }
    14321441
    1433         unset( $_wp_post_type_features[ $post_type ][ $feature ] );
     1442        $ptype_obj = get_post_type_object( $post_type );
     1443        if ( ! $ptype_obj ) {
     1444                return;
     1445        }
     1446
     1447        $ptype_obj->remove_support( $feature, $subtype );
    14341448}
    14351449
    14361450/**
    14371451 * Get all the post type features
    14381452 *
    14391453 * @since 3.4.0
     1454 * @since 4.7.0 Uses `WP_Post_Type` to handle features.
    14401455 *
    1441  * @global array $_wp_post_type_features
    1442  *
    14431456 * @param string $post_type The post type.
    14441457 * @return array Post type supports list.
    14451458 */
    14461459function get_all_post_type_supports( $post_type ) {
    1447         global $_wp_post_type_features;
     1460        $subtype = '';
     1461        if ( strpos( $post_type, ':' ) ) {
     1462                list( $post_type, $subtype ) = explode( ':', $post_type );
     1463        }
    14481464
    1449         if ( isset( $_wp_post_type_features[$post_type] ) )
    1450                 return $_wp_post_type_features[$post_type];
     1465        $ptype_obj = get_post_type_object( $post_type );
     1466        if ( ! $ptype_obj ) {
     1467                return array();
     1468        }
    14511469
    1452         return array();
     1470        return $ptype_obj->get_all_supports( $subtype );
    14531471}
    14541472
    14551473/**
    14561474 * Check a post type's support for a given feature.
    14571475 *
    14581476 * @since 3.0.0
     1477 * @since 4.7.0 Uses `WP_Post_Type` to handle features.
    14591478 *
    1460  * @global array $_wp_post_type_features
    1461  *
    14621479 * @param string $post_type The post type being checked.
    14631480 * @param string $feature   The feature being checked.
    14641481 * @return bool Whether the post type supports the given feature.
    14651482 */
    14661483function post_type_supports( $post_type, $feature ) {
    1467         global $_wp_post_type_features;
     1484        $subtype = '';
     1485        if ( strpos( $post_type, ':' ) ) {
     1486                list( $post_type, $subtype ) = explode( ':', $post_type );
     1487        }
    14681488
    1469         return ( isset( $_wp_post_type_features[$post_type][$feature] ) );
     1489        $ptype_obj = get_post_type_object( $post_type );
     1490        if ( ! $ptype_obj ) {
     1491                return false;
     1492        }
     1493
     1494        return $ptype_obj->supports( $feature, $subtype );
    14701495}
    14711496
    14721497/**
    14731498 * Retrieves a list of post type names that support a specific feature.
    14741499 *
    14751500 * @since 4.5.0
     1501 * @since 4.7.0 Uses `WP_Post_Type` to handle features.
    14761502 *
    1477  * @global array $_wp_post_type_features Post type features
    1478  *
    14791503 * @param array|string $feature  Single feature or an array of features the post types should support.
    14801504 * @param string       $operator Optional. The logical operation to perform. 'or' means
    14811505 *                               only one element from the array needs to match; 'and'
     
    14841508 * @return array A list of post type names.
    14851509 */
    14861510function get_post_types_by_support( $feature, $operator = 'and' ) {
    1487         global $_wp_post_type_features;
     1511        $names = array();
    14881512
    1489         $features = array_fill_keys( (array) $feature, true );
     1513        $ptype_objects = get_post_types( array(), 'objects' );
     1514        foreach ( $ptype_objects as $ptype_obj ) {
     1515                $names = array_merge( $names, $ptype_obj->get_by_support( $feature, $operator ) );
     1516        }
    14901517
    1491         return array_keys( wp_filter_object_list( $_wp_post_type_features, $features, $operator ) );
     1518        return $names;
    14921519}
    14931520
    14941521/**