Make WordPress Core

Ticket #38323: wp-object-type.diff

File wp-object-type.diff, 4.3 KB (added by flixos90, 6 years ago)
  • src/wp-includes/class-wp-object-type.php

     
     1<?php
     2/**
     3 * Object Type API: WP_Object_Type class
     4 *
     5 * @package WordPress
     6 * @subpackage Object
     7 * @since 4.8.0
     8 */
     9
     10/**
     11 * Core class used for interacting with object types.
     12 *
     13 * @since 4.8.0
     14 */
     15class WP_Object_Type {
     16        /**
     17         * Object type name.
     18         *
     19         * @since 4.8.0
     20         * @access protected
     21         * @var string
     22         */
     23        protected $object_type = '';
     24
     25        /**
     26         * Object type instances.
     27         *
     28         * @since 4.8.0
     29         * @access protected
     30         * @static
     31         * @var array
     32         */
     33        protected static $instances = array();
     34
     35        /**
     36         * Constructor.
     37         *
     38         * @since 4.8.0
     39         * @access public
     40         *
     41         * @param string $object_type Object type name.
     42         */
     43        public function __construct( $object_type ) {
     44                $this->object_type = $object_type;
     45        }
     46
     47        /**
     48         * Returns the object type name.
     49         *
     50         * @since 4.8.0
     51         * @access public
     52         *
     53         * @return string Object type name.
     54         */
     55        public function get_object_type() {
     56                return $this->object_type;
     57        }
     58
     59        /**
     60         * Returns the subtype name.
     61         *
     62         * @since 4.8.0
     63         * @access public
     64         *
     65         * @return string Subtype name, or empty string if no subtype set.
     66         */
     67        public function get_subtype() {
     68                if ( ! isset( $this->name ) ) {
     69                        return '';
     70                }
     71
     72                return $this->name;
     73        }
     74
     75        /**
     76         * Returns an general object type instance.
     77         *
     78         * @since 4.8.0
     79         * @access public
     80         * @static
     81         *
     82         * @param string $object_type Object type name.
     83         * @return WP_Object_Type|null Object type instance, or null if invalid object type.
     84         */
     85        public static function get_instance( $object_type ) {
     86                if ( ! in_array( $object_type, array( 'post', 'term', 'comment', 'user' ), true ) ) {
     87                        return null;
     88                }
     89
     90                if ( ! isset( self::$instances[ $object_type ] ) ) {
     91                        self::$instances[ $object_type ] = new self( $object_type );
     92                }
     93
     94                return self::$instances[ $object_type ];
     95        }
     96}
  • src/wp-includes/class-wp-post-type.php

    Property changes on: src/wp-includes/class-wp-object-type.php
    ___________________________________________________________________
    Added: svn:executable
    ## -0,0 +1 ##
    +*
    \ No newline at end of property
     
    1111 * Core class used for interacting with post types.
    1212 *
    1313 * @since 4.6.0
     14 * @since 4.8.0 Now inherits WP_Object_Type.
    1415 *
    1516 * @see register_post_type()
    1617 */
    17 final class WP_Post_Type {
     18final class WP_Post_Type extends WP_Object_Type {
    1819        /**
    1920         * Post type key.
    2021         *
     
    381382         *                                Default empty array.
    382383         */
    383384        public function __construct( $post_type, $args = array() ) {
     385                parent::__construct( 'post' );
     386
    384387                $this->name = $post_type;
    385388
    386389                $this->set_props( $args );
  • src/wp-includes/class-wp-taxonomy.php

     
    1111 * Core class used for interacting with taxonomies.
    1212 *
    1313 * @since 4.7.0
     14 * @since 4.8.0 Now inherits WP_Object_Type.
    1415 */
    15 final class WP_Taxonomy {
     16final class WP_Taxonomy extends WP_Object_Type {
    1617        /**
    1718         * Taxonomy key.
    1819         *
     
    241242         *                                  Default empty array.
    242243         */
    243244        public function __construct( $taxonomy, $object_type, $args = array() ) {
     245                parent::__construct( 'term' );
     246
    244247                $this->name = $taxonomy;
    245248
    246249                $this->set_props( $object_type, $args );
  • src/wp-settings.php

     
    145145require( ABSPATH . WPINC . '/class-wp-ajax-response.php' );
    146146require( ABSPATH . WPINC . '/formatting.php' );
    147147require( ABSPATH . WPINC . '/capabilities.php' );
     148require( ABSPATH . WPINC . '/class-wp-object-type.php' );
    148149require( ABSPATH . WPINC . '/class-wp-roles.php' );
    149150require( ABSPATH . WPINC . '/class-wp-role.php' );
    150151require( ABSPATH . WPINC . '/class-wp-user.php' );