WP_REST_Posts_Controller::__construct PHP Method

__construct() public method

Constructor.
Since: 4.7.0
public __construct ( string $post_type )
$post_type string Post type.
    public function __construct($post_type)
    {
        $this->post_type = $post_type;
        $this->namespace = 'wp/v2';
        $obj = get_post_type_object($post_type);
        $this->rest_base = !empty($obj->rest_base) ? $obj->rest_base : $obj->name;
        $this->meta = new WP_REST_Post_Meta_Fields($this->post_type);
    }

Usage Example

 /**
  * Snapshot_REST_API_Controller constructor.
  *
  * @throws Exception If the post type was not registered properly.
  * @param string $post_type Post type.
  */
 public function __construct($post_type)
 {
     $post_type_obj = get_post_type_object($post_type);
     if (empty($post_type_obj) || empty($post_type_obj->customize_snapshot_post_type_obj)) {
         throw new Exception('Missing customize_snapshot post type obj or arg for customize_snapshot_post_type_obj');
     }
     $this->snapshot_post_type = $post_type_obj->customize_snapshot_post_type_obj;
     parent::__construct($post_type);
 }
All Usage Examples Of WP_REST_Posts_Controller::__construct