コード例 #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_status' == $key) {
         return $this->booking_status;
     }
     if ('post_title' == $key) {
         return $this->code;
     }
     if ('post_type' == $key) {
         return 'btb_booking';
     }
     if ('post_parent' == $key) {
         return $this->booked_time;
     }
     $value = get_post_meta($this->ID, $key, true);
     if ($this->filter) {
         $value = btb_sanitize_booking_field($key, $value, $this->ID, $this->filter);
     }
     return $value;
 }
コード例 #2
0
/**
* Sanitize every booking field.
*
* If the context is 'raw', then the booking object or array will get minimal
* sanitization of the integer fields.
*
* @since 1.0.0
*
* @see BTB_Booking::sanitize_post_field()
*
* @param object|BTB_Booking|array	$booking	The booking object or array.
* @param string					$context	Optional. How to sanitize the booking fields.
												Accepts 'raw', 'edit', 'db', 'attribute', 'js' or 'display'.
												Default 'display'.
* @return object|BTB_Booking|array	The now snitized BTB_Booking object or array.
*/
function btb_sanitize_booking($booking, $context = 'display')
{
    if (is_object($booking)) {
        // Check if booking already filtered for this context.
        if (isset($booking->filter) && $context == $booking->filter) {
            return $booking;
        }
        if (!isset($booking->ID)) {
            $booking->ID = 0;
        }
        foreach (array_keys(get_object_vars($booking)) as $field) {
            $booking->{$field} = btb_sanitize_booking_field($field, $booking->{$field}, $booking->ID, $context);
        }
        $booking->filter = $context;
    } elseif (is_array($booking)) {
        // Check if booking already filtered for this context.
        if (isset($booking['filter']) && $context == $booking['filter']) {
            return $booking;
        }
        if (!isset($booking['ID'])) {
            $booking['ID'] = 0;
        }
        foreach (array_keys($booking) as $field) {
            $booking[$field] = btb_sanitize_booking_field($field, $booking[$field], $booking['ID'], $context);
        }
        $booking['filter'] = $context;
    }
    return $booking;
}