/** * @param WP_User|object|null $user * @param array $args */ function __construct($user, $args = array()) { /* * Find the user if possible */ $this->_user = WPLib_Users::get_user($user); /* * Let our parent class capture whatever properties where passed in as $args */ parent::__construct($args); }
/** * @param string $method_name * @param array $args * * @return array|mixed|null */ function __call($method_name, $args) { if (!$this->has_post()) { $value = parent::__call($method_name, $args); } else { /** * Capture methods that identify WP_Post field names. * * Strip 'post_' as a prefix and recognize methods as accessing WP_Post properties. * * 'name' is too generic so 'post_name' is accessed via slug(): * * $this->slug() => return $this->_post->post_name * * 'post_type' is too iconic so post_type() is used vs. type(): * * 'post_parent' is accessed by parent_id(): * * $this->parent_id() => return $this->_post->post_parent * * Others are accessed as method name sans 'post_' prefix, i.e. * * $this->ID() => return $this->_post->ID * $this->menu_order() => return $this->_post->menu_order * $this->date() => return $this->_post->post_date * $this->date_gmt() => return $this->_post->post_date_gmt * $this->modified() => return $this->_post->post_modified * $this->modified_gmt() => return $this->_post->post_modified_gmt * $this->password() => return $this->_post->password * $this->comment_count() => return $this->_post->comment_count * $this->pinged() => return $this->_post->pinged * $this->to_ping() => return $this->_post->to_ping * $this->ping_status() => return $this->_post->ping_status * $this->comment_status() => return $this->_post->comment_status * * Lastly 'post_type', 'post_content' and 'post_excerpt' are accessed via more functions, so: * * $this->post_type() !=> return $this->_post->post_type * $this->content() !=> return $this->_post->post_content * $this->excerpt() !=> return $this->_post->post_excerpt * */ switch (preg_replace('#^post_(.+)$#', '$1', $method_name)) { case 'ID': case 'menu_order': case 'comment_count': $data_type = 'int'; $property_name = $method_name; break; case 'date': case 'date_gmt': case 'modified': case 'modified_gmt': $data_type = 'date'; $property_name = "post_{$method_name}"; break; case 'status': case 'password': $data_type = 'string'; $property_name = "post_{$method_name}"; break; case 'comment_status': case 'ping_status': case 'to_ping': case 'pinged': $data_type = 'string'; $property_name = $method_name; break; default: $property_name = false; } if (!$property_name) { $value = parent::__call($method_name, $args); } else { $value = $this->_post->{$property_name}; switch ($data_type) { case 'int': $value = intval($value); break; case 'date': /** * @todo Verify that this is what we want to standardize on. */ $value = mysql2date(DATE_W3C, $value); default: /* * No need to do anything for a string. */ } } } return $value; }
/** * @param object|int|string|null $term * @param array $args * */ function __construct($term, $args = array()) { $this->_term = WPLib::get_term($term, static::item_taxonomy()); parent::__construct($args); }
/** * @param array $args */ function __construct($args = array()) { /** * For both model and view, create the items. */ foreach (array('model', 'view') as $property_name) { if (!isset($args[$property_name])) { /* * If no model or view class was specified then use the default. */ $args[$property_name] = $this->_get_property_class($property_name); } if (is_object($args[$property_name])) { /* * If it was an object, just assign is. */ $this->{$property_name} = $args[$property_name]; } else { if (is_string($args[$property_name])) { /** * It's a class name thus needs no $args */ $class_name = $args[$property_name]; $property_args = array(); } else { if (is_array($args[$property_name])) { /** * It's an array of args, so use the default class name */ $class_name = $this->_get_property_class($property_name); $property_args = $args[$property_name]; } } if (method_exists($class_name, 'make_new')) { /* * If this class has a make_new() method. * A Class::make_new() method is needed when the class constructor has more than 1 parameter of $args. */ $this->{$property_name} = $class_name::make_new($property_args); } else { if (class_exists($class_name)) { /* * If an array or string, instantiate the class. */ $this->{$property_name} = new $class_name($property_args); } else { $this->{$property_name} = null; } } } if (is_object($this->{$property_name}) && property_exists($this->{$property_name}, 'owner')) { /** * Set a reference back to the item for both $view and $model. */ $this->{$property_name}->owner = $this; } /** * Remove processed args to prevent overwriting them later. */ unset($args[$property_name]); } parent::__construct($args); if (count($this->extra_args)) { /** * If there are any leftover args, see if we can assign them to */ $this->model->set_state($this->extra_args); /** * Any extra args will be left in model. */ $this->extra_args = array(); } }
/** * @param object|int|string|null $term * @param array $args * */ function __construct($term, $args = array()) { $this->_term = WPLib::get_term($term, $args); parent::__construct($args); }