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
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);
 }
Example #2
0
 /**
  * Returns a WPLib_Item_Base from the queried object, if the queried object is a post.
  *
  * Useful for accessing the post prior to $wp_the_query
  * Similar to single_post_title() in concept
  *
  * @return WPLib_Post_Base
  */
 function single_post_item()
 {
     /**
      * @var WP_Post $_post
      */
     return $_post = $this->single_post() ? WPLib_Posts::make_new_item($_post) : null;
 }
Example #3
0
 /**
  * @param WPLib_Item_Base|WP_Post|WP_Term $item
  * @param array $args
  *
  * @return WPLib_Term_Base|WPLib_Post_Base
  */
 static function make_new_item($item, $args = array())
 {
     $class = get_called_class();
     if (WPLib::get_constant('POST_TYPE', $class)) {
         $item = WPLib_Posts::make_new_item($item, $args);
     } else {
         if (WPLib::get_constant('TAXONOMY', $class)) {
             $item = WPLib_Terms::make_new_item($item, $args);
         } else {
             $err_msg = __('Cannot make new item. Class %s does not have POST_TYPE or TAXONOMY constant.', 'wplib');
             WPLib::trigger_error(sprintf($err_msg, $class));
         }
     }
     return $item;
 }