[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-includes/ -> class-wp-post-type.php (source)

   1  <?php
   2  /**
   3   * Post API: WP_Post_Type class
   4   *
   5   * @package WordPress
   6   * @subpackage Post
   7   * @since 4.6.0
   8   */
   9  
  10  /**
  11   * Core class used for interacting with post types.
  12   *
  13   * @since 4.6.0
  14   *
  15   * @see register_post_type()
  16   */
  17  final class WP_Post_Type {
  18      /**
  19       * Post type key.
  20       *
  21       * @since 4.6.0
  22       * @var string $name
  23       */
  24      public $name;
  25  
  26      /**
  27       * Name of the post type shown in the menu. Usually plural.
  28       *
  29       * @since 4.6.0
  30       * @var string $label
  31       */
  32      public $label;
  33  
  34      /**
  35       * Labels object for this post type.
  36       *
  37       * If not set, post labels are inherited for non-hierarchical types
  38       * and page labels for hierarchical ones.
  39       *
  40       * @see get_post_type_labels()
  41       *
  42       * @since 4.6.0
  43       * @var object $labels
  44       */
  45      public $labels;
  46  
  47      /**
  48       * A short descriptive summary of what the post type is.
  49       *
  50       * Default empty.
  51       *
  52       * @since 4.6.0
  53       * @var string $description
  54       */
  55      public $description = '';
  56  
  57      /**
  58       * Whether a post type is intended for use publicly either via the admin interface or by front-end users.
  59       *
  60       * While the default settings of $exclude_from_search, $publicly_queryable, $show_ui, and $show_in_nav_menus
  61       * are inherited from public, each does not rely on this relationship and controls a very specific intention.
  62       *
  63       * Default false.
  64       *
  65       * @since 4.6.0
  66       * @var bool $public
  67       */
  68      public $public = false;
  69  
  70      /**
  71       * Whether the post type is hierarchical (e.g. page).
  72       *
  73       * Default false.
  74       *
  75       * @since 4.6.0
  76       * @var bool $hierarchical
  77       */
  78      public $hierarchical = false;
  79  
  80      /**
  81       * Whether to exclude posts with this post type from front end search
  82       * results.
  83       *
  84       * Default is the opposite value of $public.
  85       *
  86       * @since 4.6.0
  87       * @var bool $exclude_from_search
  88       */
  89      public $exclude_from_search = null;
  90  
  91      /**
  92       * Whether queries can be performed on the front end for the post type as part of `parse_request()`.
  93       *
  94       * Endpoints would include:
  95       * - `?post_type={post_type_key}`
  96       * - `?{post_type_key}={single_post_slug}`
  97       * - `?{post_type_query_var}={single_post_slug}`
  98       *
  99       * Default is the value of $public.
 100       *
 101       * @since 4.6.0
 102       * @var bool $publicly_queryable
 103       */
 104      public $publicly_queryable = null;
 105  
 106      /**
 107       * Whether to generate and allow a UI for managing this post type in the admin.
 108       *
 109       * Default is the value of $public.
 110       *
 111       * @since 4.6.0
 112       * @var bool $show_ui
 113       */
 114      public $show_ui = null;
 115  
 116      /**
 117       * Where to show the post type in the admin menu.
 118       *
 119       * To work, $show_ui must be true. If true, the post type is shown in its own top level menu. If false, no menu is
 120       * shown. If a string of an existing top level menu (eg. 'tools.php' or 'edit.php?post_type=page'), the post type
 121       * will be placed as a sub-menu of that.
 122       *
 123       * Default is the value of $show_ui.
 124       *
 125       * @since 4.6.0
 126       * @var bool $show_in_menu
 127       */
 128      public $show_in_menu = null;
 129  
 130      /**
 131       * Makes this post type available for selection in navigation menus.
 132       *
 133       * Default is the value $public.
 134       *
 135       * @since 4.6.0
 136       * @var bool $show_in_nav_menus
 137       */
 138      public $show_in_nav_menus = null;
 139  
 140      /**
 141       * Makes this post type available via the admin bar.
 142       *
 143       * Default is the value of $show_in_menu.
 144       *
 145       * @since 4.6.0
 146       * @var bool $show_in_admin_bar
 147       */
 148      public $show_in_admin_bar = null;
 149  
 150      /**
 151       * The position in the menu order the post type should appear.
 152       *
 153       * To work, $show_in_menu must be true. Default null (at the bottom).
 154       *
 155       * @since 4.6.0
 156       * @var int $menu_position
 157       */
 158      public $menu_position = null;
 159  
 160      /**
 161       * The URL to the icon to be used for this menu.
 162       *
 163       * Pass a base64-encoded SVG using a data URI, which will be colored to match the color scheme.
 164       * This should begin with 'data:image/svg+xml;base64,'. Pass the name of a Dashicons helper class
 165       * to use a font icon, e.g. 'dashicons-chart-pie'. Pass 'none' to leave div.wp-menu-image empty
 166       * so an icon can be added via CSS.
 167       *
 168       * Defaults to use the posts icon.
 169       *
 170       * @since 4.6.0
 171       * @var string $menu_icon
 172       */
 173      public $menu_icon = null;
 174  
 175      /**
 176       * The string to use to build the read, edit, and delete capabilities.
 177       *
 178       * May be passed as an array to allow for alternative plurals when using
 179       * this argument as a base to construct the capabilities, e.g.
 180       * array( 'story', 'stories' ). Default 'post'.
 181       *
 182       * @since 4.6.0
 183       * @var string $capability_type
 184       */
 185      public $capability_type = 'post';
 186  
 187      /**
 188       * Whether to use the internal default meta capability handling.
 189       *
 190       * Default false.
 191       *
 192       * @since 4.6.0
 193       * @var bool $map_meta_cap
 194       */
 195      public $map_meta_cap = false;
 196  
 197      /**
 198       * Provide a callback function that sets up the meta boxes for the edit form.
 199       *
 200       * Do `remove_meta_box()` and `add_meta_box()` calls in the callback. Default null.
 201       *
 202       * @since 4.6.0
 203       * @var callable $register_meta_box_cb
 204       */
 205      public $register_meta_box_cb = null;
 206  
 207      /**
 208       * An array of taxonomy identifiers that will be registered for the post type.
 209       *
 210       * Taxonomies can be registered later with `register_taxonomy()` or `register_taxonomy_for_object_type()`.
 211       *
 212       * Default empty array.
 213       *
 214       * @since 4.6.0
 215       * @var array $taxonomies
 216       */
 217      public $taxonomies = array();
 218  
 219      /**
 220       * Whether there should be post type archives, or if a string, the archive slug to use.
 221       *
 222       * Will generate the proper rewrite rules if $rewrite is enabled. Default false.
 223       *
 224       * @since 4.6.0
 225       * @var bool|string $has_archive
 226       */
 227      public $has_archive = false;
 228  
 229      /**
 230       * Sets the query_var key for this post type.
 231       *
 232       * Defaults to $post_type key. If false, a post type cannot be loaded at `?{query_var}={post_slug}`.
 233       * If specified as a string, the query `?{query_var_string}={post_slug}` will be valid.
 234       *
 235       * @since 4.6.0
 236       * @var string|bool $query_var
 237       */
 238      public $query_var;
 239  
 240      /**
 241       * Whether to allow this post type to be exported.
 242       *
 243       * Default true.
 244       *
 245       * @since 4.6.0
 246       * @var bool $can_export
 247       */
 248      public $can_export = true;
 249  
 250      /**
 251       * Whether to delete posts of this type when deleting a user.
 252       *
 253       * - If true, posts of this type belonging to the user will be moved to Trash when the user is deleted.
 254       * - If false, posts of this type belonging to the user will *not* be trashed or deleted.
 255       * - If not set (the default), posts are trashed if post type supports the 'author' feature.
 256       *   Otherwise posts are not trashed or deleted.
 257       *
 258       * Default null.
 259       *
 260       * @since 4.6.0
 261       * @var bool $delete_with_user
 262       */
 263      public $delete_with_user = null;
 264  
 265      /**
 266       * Array of blocks to use as the default initial state for an editor session.
 267       *
 268       * Each item should be an array containing block name and optional attributes.
 269       *
 270       * Default empty array.
 271       *
 272       * @link https://developer.wordpress.org/block-editor/developers/block-api/block-templates/
 273       *
 274       * @since 5.0.0
 275       * @var array $template
 276       */
 277      public $template = array();
 278  
 279      /**
 280       * Whether the block template should be locked if $template is set.
 281       *
 282       * - If set to 'all', the user is unable to insert new blocks, move existing blocks
 283       *   and delete blocks.
 284       * - If set to 'insert', the user is able to move existing blocks but is unable to insert
 285       *   new blocks and delete blocks.
 286       *
 287       * Default false.
 288       *
 289       * @link https://developer.wordpress.org/block-editor/developers/block-api/block-templates/
 290       *
 291       * @since 5.0.0
 292       * @var string|false $template_lock
 293       */
 294      public $template_lock = false;
 295  
 296      /**
 297       * Whether this post type is a native or "built-in" post_type.
 298       *
 299       * Default false.
 300       *
 301       * @since 4.6.0
 302       * @var bool $_builtin
 303       */
 304      public $_builtin = false;
 305  
 306      /**
 307       * URL segment to use for edit link of this post type.
 308       *
 309       * Default 'post.php?post=%d'.
 310       *
 311       * @since 4.6.0
 312       * @var string $_edit_link
 313       */
 314      public $_edit_link = 'post.php?post=%d';
 315  
 316      /**
 317       * Post type capabilities.
 318       *
 319       * @since 4.6.0
 320       * @var object $cap
 321       */
 322      public $cap;
 323  
 324      /**
 325       * Triggers the handling of rewrites for this post type.
 326       *
 327       * Defaults to true, using $post_type as slug.
 328       *
 329       * @since 4.6.0
 330       * @var array|false $rewrite
 331       */
 332      public $rewrite;
 333  
 334      /**
 335       * The features supported by the post type.
 336       *
 337       * @since 4.6.0
 338       * @var array|bool $supports
 339       */
 340      public $supports;
 341  
 342      /**
 343       * Whether this post type should appear in the REST API.
 344       *
 345       * Default false. If true, standard endpoints will be registered with
 346       * respect to $rest_base and $rest_controller_class.
 347       *
 348       * @since 4.7.4
 349       * @var bool $show_in_rest
 350       */
 351      public $show_in_rest;
 352  
 353      /**
 354       * The base path for this post type's REST API endpoints.
 355       *
 356       * @since 4.7.4
 357       * @var string|bool $rest_base
 358       */
 359      public $rest_base;
 360  
 361      /**
 362       * The controller for this post type's REST API endpoints.
 363       *
 364       * Custom controllers must extend WP_REST_Controller.
 365       *
 366       * @since 4.7.4
 367       * @var string|bool $rest_controller_class
 368       */
 369      public $rest_controller_class;
 370  
 371      /**
 372       * The controller instance for this post type's REST API endpoints.
 373       *
 374       * Lazily computed. Should be accessed using {@see WP_Post_Type::get_rest_controller()}.
 375       *
 376       * @since 5.3.0
 377       * @var WP_REST_Controller $rest_controller
 378       */
 379      public $rest_controller;
 380  
 381      /**
 382       * Constructor.
 383       *
 384       * Will populate object properties from the provided arguments and assign other
 385       * default properties based on that information.
 386       *
 387       * @since 4.6.0
 388       *
 389       * @see register_post_type()
 390       *
 391       * @param string       $post_type Post type key.
 392       * @param array|string $args      Optional. Array or string of arguments for registering a post type.
 393       *                                Default empty array.
 394       */
 395  	public function __construct( $post_type, $args = array() ) {
 396          $this->name = $post_type;
 397  
 398          $this->set_props( $args );
 399      }
 400  
 401      /**
 402       * Sets post type properties.
 403       *
 404       * @since 4.6.0
 405       *
 406       * @param array|string $args Array or string of arguments for registering a post type.
 407       */
 408  	public function set_props( $args ) {
 409          $args = wp_parse_args( $args );
 410  
 411          /**
 412           * Filters the arguments for registering a post type.
 413           *
 414           * @since 4.4.0
 415           *
 416           * @param array  $args      Array of arguments for registering a post type.
 417           * @param string $post_type Post type key.
 418           */
 419          $args = apply_filters( 'register_post_type_args', $args, $this->name );
 420  
 421          $has_edit_link = ! empty( $args['_edit_link'] );
 422  
 423          // Args prefixed with an underscore are reserved for internal use.
 424          $defaults = array(
 425              'labels'                => array(),
 426              'description'           => '',
 427              'public'                => false,
 428              'hierarchical'          => false,
 429              'exclude_from_search'   => null,
 430              'publicly_queryable'    => null,
 431              'show_ui'               => null,
 432              'show_in_menu'          => null,
 433              'show_in_nav_menus'     => null,
 434              'show_in_admin_bar'     => null,
 435              'menu_position'         => null,
 436              'menu_icon'             => null,
 437              'capability_type'       => 'post',
 438              'capabilities'          => array(),
 439              'map_meta_cap'          => null,
 440              'supports'              => array(),
 441              'register_meta_box_cb'  => null,
 442              'taxonomies'            => array(),
 443              'has_archive'           => false,
 444              'rewrite'               => true,
 445              'query_var'             => true,
 446              'can_export'            => true,
 447              'delete_with_user'      => null,
 448              'show_in_rest'          => false,
 449              'rest_base'             => false,
 450              'rest_controller_class' => false,
 451              'template'              => array(),
 452              'template_lock'         => false,
 453              '_builtin'              => false,
 454              '_edit_link'            => 'post.php?post=%d',
 455          );
 456  
 457          $args = array_merge( $defaults, $args );
 458  
 459          $args['name'] = $this->name;
 460  
 461          // If not set, default to the setting for 'public'.
 462          if ( null === $args['publicly_queryable'] ) {
 463              $args['publicly_queryable'] = $args['public'];
 464          }
 465  
 466          // If not set, default to the setting for 'public'.
 467          if ( null === $args['show_ui'] ) {
 468              $args['show_ui'] = $args['public'];
 469          }
 470  
 471          // If not set, default to the setting for 'show_ui'.
 472          if ( null === $args['show_in_menu'] || ! $args['show_ui'] ) {
 473              $args['show_in_menu'] = $args['show_ui'];
 474          }
 475  
 476          // If not set, default to the setting for 'show_in_menu'.
 477          if ( null === $args['show_in_admin_bar'] ) {
 478              $args['show_in_admin_bar'] = (bool) $args['show_in_menu'];
 479          }
 480  
 481          // If not set, default to the setting for 'public'.
 482          if ( null === $args['show_in_nav_menus'] ) {
 483              $args['show_in_nav_menus'] = $args['public'];
 484          }
 485  
 486          // If not set, default to true if not public, false if public.
 487          if ( null === $args['exclude_from_search'] ) {
 488              $args['exclude_from_search'] = ! $args['public'];
 489          }
 490  
 491          // Back compat with quirky handling in version 3.0. #14122.
 492          if ( empty( $args['capabilities'] )
 493              && null === $args['map_meta_cap'] && in_array( $args['capability_type'], array( 'post', 'page' ), true )
 494          ) {
 495              $args['map_meta_cap'] = true;
 496          }
 497  
 498          // If not set, default to false.
 499          if ( null === $args['map_meta_cap'] ) {
 500              $args['map_meta_cap'] = false;
 501          }
 502  
 503          // If there's no specified edit link and no UI, remove the edit link.
 504          if ( ! $args['show_ui'] && ! $has_edit_link ) {
 505              $args['_edit_link'] = '';
 506          }
 507  
 508          $this->cap = get_post_type_capabilities( (object) $args );
 509          unset( $args['capabilities'] );
 510  
 511          if ( is_array( $args['capability_type'] ) ) {
 512              $args['capability_type'] = $args['capability_type'][0];
 513          }
 514  
 515          if ( false !== $args['query_var'] ) {
 516              if ( true === $args['query_var'] ) {
 517                  $args['query_var'] = $this->name;
 518              } else {
 519                  $args['query_var'] = sanitize_title_with_dashes( $args['query_var'] );
 520              }
 521          }
 522  
 523          if ( false !== $args['rewrite'] && ( is_admin() || get_option( 'permalink_structure' ) ) ) {
 524              if ( ! is_array( $args['rewrite'] ) ) {
 525                  $args['rewrite'] = array();
 526              }
 527              if ( empty( $args['rewrite']['slug'] ) ) {
 528                  $args['rewrite']['slug'] = $this->name;
 529              }
 530              if ( ! isset( $args['rewrite']['with_front'] ) ) {
 531                  $args['rewrite']['with_front'] = true;
 532              }
 533              if ( ! isset( $args['rewrite']['pages'] ) ) {
 534                  $args['rewrite']['pages'] = true;
 535              }
 536              if ( ! isset( $args['rewrite']['feeds'] ) || ! $args['has_archive'] ) {
 537                  $args['rewrite']['feeds'] = (bool) $args['has_archive'];
 538              }
 539              if ( ! isset( $args['rewrite']['ep_mask'] ) ) {
 540                  if ( isset( $args['permalink_epmask'] ) ) {
 541                      $args['rewrite']['ep_mask'] = $args['permalink_epmask'];
 542                  } else {
 543                      $args['rewrite']['ep_mask'] = EP_PERMALINK;
 544                  }
 545              }
 546          }
 547  
 548          foreach ( $args as $property_name => $property_value ) {
 549              $this->$property_name = $property_value;
 550          }
 551  
 552          $this->labels = get_post_type_labels( $this );
 553          $this->label  = $this->labels->name;
 554      }
 555  
 556      /**
 557       * Sets the features support for the post type.
 558       *
 559       * @since 4.6.0
 560       */
 561  	public function add_supports() {
 562          if ( ! empty( $this->supports ) ) {
 563              foreach ( $this->supports as $feature => $args ) {
 564                  if ( is_array( $args ) ) {
 565                      add_post_type_support( $this->name, $feature, $args );
 566                  } else {
 567                      add_post_type_support( $this->name, $args );
 568                  }
 569              }
 570              unset( $this->supports );
 571          } elseif ( false !== $this->supports ) {
 572              // Add default features.
 573              add_post_type_support( $this->name, array( 'title', 'editor' ) );
 574          }
 575      }
 576  
 577      /**
 578       * Adds the necessary rewrite rules for the post type.
 579       *
 580       * @since 4.6.0
 581       *
 582       * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
 583       * @global WP         $wp         Current WordPress environment instance.
 584       */
 585  	public function add_rewrite_rules() {
 586          global $wp_rewrite, $wp;
 587  
 588          if ( false !== $this->query_var && $wp && is_post_type_viewable( $this ) ) {
 589              $wp->add_query_var( $this->query_var );
 590          }
 591  
 592          if ( false !== $this->rewrite && ( is_admin() || get_option( 'permalink_structure' ) ) ) {
 593              if ( $this->hierarchical ) {
 594                  add_rewrite_tag( "%$this->name%", '(.+?)', $this->query_var ? "{$this->query_var}=" : "post_type=$this->name&pagename=" );
 595              } else {
 596                  add_rewrite_tag( "%$this->name%", '([^/]+)', $this->query_var ? "{$this->query_var}=" : "post_type=$this->name&name=" );
 597              }
 598  
 599              if ( $this->has_archive ) {
 600                  $archive_slug = true === $this->has_archive ? $this->rewrite['slug'] : $this->has_archive;
 601                  if ( $this->rewrite['with_front'] ) {
 602                      $archive_slug = substr( $wp_rewrite->front, 1 ) . $archive_slug;
 603                  } else {
 604                      $archive_slug = $wp_rewrite->root . $archive_slug;
 605                  }
 606  
 607                  add_rewrite_rule( "{$archive_slug}/?$", "index.php?post_type=$this->name", 'top' );
 608                  if ( $this->rewrite['feeds'] && $wp_rewrite->feeds ) {
 609                      $feeds = '(' . trim( implode( '|', $wp_rewrite->feeds ) ) . ')';
 610                      add_rewrite_rule( "{$archive_slug}/feed/$feeds/?$", "index.php?post_type=$this->name" . '&feed=$matches[1]', 'top' );
 611                      add_rewrite_rule( "{$archive_slug}/$feeds/?$", "index.php?post_type=$this->name" . '&feed=$matches[1]', 'top' );
 612                  }
 613                  if ( $this->rewrite['pages'] ) {
 614                      add_rewrite_rule( "{$archive_slug}/{$wp_rewrite->pagination_base}/([0-9]{1,})/?$", "index.php?post_type=$this->name" . '&paged=$matches[1]', 'top' );
 615                  }
 616              }
 617  
 618              $permastruct_args         = $this->rewrite;
 619              $permastruct_args['feed'] = $permastruct_args['feeds'];
 620              add_permastruct( $this->name, "{$this->rewrite['slug']}/%$this->name%", $permastruct_args );
 621          }
 622      }
 623  
 624      /**
 625       * Registers the post type meta box if a custom callback was specified.
 626       *
 627       * @since 4.6.0
 628       */
 629  	public function register_meta_boxes() {
 630          if ( $this->register_meta_box_cb ) {
 631              add_action( 'add_meta_boxes_' . $this->name, $this->register_meta_box_cb, 10, 1 );
 632          }
 633      }
 634  
 635      /**
 636       * Adds the future post hook action for the post type.
 637       *
 638       * @since 4.6.0
 639       */
 640  	public function add_hooks() {
 641          add_action( 'future_' . $this->name, '_future_post_hook', 5, 2 );
 642      }
 643  
 644      /**
 645       * Registers the taxonomies for the post type.
 646       *
 647       * @since 4.6.0
 648       */
 649  	public function register_taxonomies() {
 650          foreach ( $this->taxonomies as $taxonomy ) {
 651              register_taxonomy_for_object_type( $taxonomy, $this->name );
 652          }
 653      }
 654  
 655      /**
 656       * Removes the features support for the post type.
 657       *
 658       * @since 4.6.0
 659       *
 660       * @global array $_wp_post_type_features Post type features.
 661       */
 662  	public function remove_supports() {
 663          global $_wp_post_type_features;
 664  
 665          unset( $_wp_post_type_features[ $this->name ] );
 666      }
 667  
 668      /**
 669       * Removes any rewrite rules, permastructs, and rules for the post type.
 670       *
 671       * @since 4.6.0
 672       *
 673       * @global WP_Rewrite $wp_rewrite          WordPress rewrite component.
 674       * @global WP         $wp                  Current WordPress environment instance.
 675       * @global array      $post_type_meta_caps Used to remove meta capabilities.
 676       */
 677  	public function remove_rewrite_rules() {
 678          global $wp, $wp_rewrite, $post_type_meta_caps;
 679  
 680          // Remove query var.
 681          if ( false !== $this->query_var ) {
 682              $wp->remove_query_var( $this->query_var );
 683          }
 684  
 685          // Remove any rewrite rules, permastructs, and rules.
 686          if ( false !== $this->rewrite ) {
 687              remove_rewrite_tag( "%$this->name%" );
 688              remove_permastruct( $this->name );
 689              foreach ( $wp_rewrite->extra_rules_top as $regex => $query ) {
 690                  if ( false !== strpos( $query, "index.php?post_type=$this->name" ) ) {
 691                      unset( $wp_rewrite->extra_rules_top[ $regex ] );
 692                  }
 693              }
 694          }
 695  
 696          // Remove registered custom meta capabilities.
 697          foreach ( $this->cap as $cap ) {
 698              unset( $post_type_meta_caps[ $cap ] );
 699          }
 700      }
 701  
 702      /**
 703       * Unregisters the post type meta box if a custom callback was specified.
 704       *
 705       * @since 4.6.0
 706       */
 707  	public function unregister_meta_boxes() {
 708          if ( $this->register_meta_box_cb ) {
 709              remove_action( 'add_meta_boxes_' . $this->name, $this->register_meta_box_cb, 10 );
 710          }
 711      }
 712  
 713      /**
 714       * Removes the post type from all taxonomies.
 715       *
 716       * @since 4.6.0
 717       */
 718  	public function unregister_taxonomies() {
 719          foreach ( get_object_taxonomies( $this->name ) as $taxonomy ) {
 720              unregister_taxonomy_for_object_type( $taxonomy, $this->name );
 721          }
 722      }
 723  
 724      /**
 725       * Removes the future post hook action for the post type.
 726       *
 727       * @since 4.6.0
 728       */
 729  	public function remove_hooks() {
 730          remove_action( 'future_' . $this->name, '_future_post_hook', 5 );
 731      }
 732  
 733      /**
 734       * Gets the REST API controller for this post type.
 735       *
 736       * Will only instantiate the controller class once per request.
 737       *
 738       * @since 5.3.0
 739       *
 740       * @return WP_REST_Controller|null The controller instance, or null if the post type
 741       *                                 is set not to show in rest.
 742       */
 743  	public function get_rest_controller() {
 744          if ( ! $this->show_in_rest ) {
 745              return null;
 746          }
 747  
 748          $class = $this->rest_controller_class ? $this->rest_controller_class : WP_REST_Posts_Controller::class;
 749  
 750          if ( ! class_exists( $class ) ) {
 751              return null;
 752          }
 753  
 754          if ( ! is_subclass_of( $class, WP_REST_Controller::class ) ) {
 755              return null;
 756          }
 757  
 758          if ( ! $this->rest_controller ) {
 759              $this->rest_controller = new $class( $this->name );
 760          }
 761  
 762          if ( ! ( $this->rest_controller instanceof $class ) ) {
 763              return null;
 764          }
 765  
 766          return $this->rest_controller;
 767      }
 768  }


Generated: Tue Dec 1 01:00:04 2020 Cross-referenced by PHPXref 0.7.1