コード例 #1
0
 /**
  * Getter
  *
  * @param string $key Key to get.
  * @return mixed
  */
 public function __get($key)
 {
     if ('page_template' == $key && $this->__isset($key)) {
         return get_post_meta($this->ID, '_wp_page_template', true);
     }
     if ('post_category' == $key) {
         return array();
     }
     if ('tags_input' == $key) {
         return array();
     }
     if ('ancestors' == $key) {
         return array();
     }
     if ('post_title' == $key) {
         return $this->name;
     }
     if ('post_parent' == $key) {
         return $this->event;
     }
     $value = get_post_meta($this->ID, $key, true);
     if ($this->filter) {
         $value = btb_sanitize_time_field($key, $value, $this->ID, $this->filter);
     }
     return $value;
 }
コード例 #2
0
/**
* Sanitize every time field.
*
* If the context is 'raw', then the time object or array will get minimal
* sanitization of the integer fields.
*
* @since 1.0.0
*
* @see btb_sanitize_time_field($field, $value, $booking_id, $context = 'display')
*
* @param object|BTB_Time|array	$time		The time object or array.
* @param string				$context	Optional. How to sanitize the time fields.
											Accepts 'raw', 'edit', 'db', 'attribute', 'js' or 'display'.
											Default 'display'.
* @return object|BTB_Time|array The now sanitized BTB_Time object or array.
*/
function btb_sanitize_time($time, $context = 'display')
{
    if (is_object($time)) {
        // Check if time already filtered for this context.
        if (isset($time->filter) && $context == $time->filter) {
            return $time;
        }
        if (!isset($time->ID)) {
            $time->ID = 0;
        }
        foreach (array_keys(get_object_vars($time)) as $field) {
            $time->{$field} = btb_sanitize_time_field($field, $time->{$field}, $time->ID, $context);
        }
        $time->filter = $context;
    } elseif (is_array($time)) {
        // Check if time already filtered for this context.
        if (isset($time['filter']) && $context == $time['filter']) {
            return $time;
        }
        if (!isset($time['ID'])) {
            $time['ID'] = 0;
        }
        foreach (array_keys($time) as $field) {
            $time[$field] = btb_sanitize_time_field($field, $time[$field], $time['ID'], $context);
        }
        $time['filter'] = $context;
    }
    return $time;
}