WPLib_Posts::make_new_item PHP Method

make_new_item() static public method

Create new Instance of a Post MVI
static public make_new_item ( WP_Post | integer $_post, array $args = [] ) : mixed
$_post WP_Post | integer
$args array { @type string $instance_class @type string $list_owner }
return mixed
    static function make_new_item($_post, $args = array())
    {
        $args = wp_parse_args($args, array('instance_class' => false, 'list_owner' => 'WPLib_Posts'));
        if (is_numeric($_post)) {
            $_post = WP_Post::get_instance($_post);
        }
        if (!$args['instance_class']) {
            $args['instance_class'] = WPLib::get_constant('INSTANCE_CLASS', $args['list_owner']);
        }
        if (!$args['instance_class']) {
            $args['instance_class'] = self::get_post_type_class($_post->post_type);
        }
        $instance_class = $args['instance_class'];
        return $instance_class ? new $instance_class($_post) : null;
    }

Usage Example

Example #1
0
 /**
  * @return WPLib_Post_Base
  *
  * @todo Make work for non-posts?
  */
 function item()
 {
     return $this->has_posts() ? WPLib_Posts::make_new_item($this->post()) : new WPLib_Post_Default(null);
 }
All Usage Examples Of WPLib_Posts::make_new_item