/** * Convert property value with the property type converter. * * @param string $slug * @param mixed $value * * @return mixed */ protected function convert($slug, $value) { $property = $this->get_property($slug); // If no property type is found, just return null. if (!papi_is_property($property)) { return; } if (papi_is_empty($value)) { if (!papi_is_empty($property->get_option('value'))) { return $property->get_option('value'); } return; } // A property need to know about the page. $property->set_page($this); // Run load value method right after the value has been loaded from the database. $value = $property->load_value($value, $slug, $this->id); $value = papi_filter_load_value($property->type, $value, $slug, $this->id); // Format the value from the property class. $value = $property->format_value($value, $slug, $this->id); // Only fired when not in admin. if (!is_admin()) { $value = papi_filter_format_value($property->type, $value, $slug, $this->id); } if (is_array($value)) { $value = array_filter($value); } return $value; }
/** * Format the value of the property before it's returned * to WordPress admin or the site. * * @param mixed $values * @param string $repeater_slug * @param int $post_id * * @return array */ public function format_value($values, $repeater_slug, $post_id) { if (!is_array($values)) { return []; } foreach ($values as $index => $layout) { foreach ($layout as $slug => $value) { if (is_string($value) && preg_match($this->layout_value_regex, $value)) { if (isset($values[$index][$this->layout_key])) { unset($values[$index][$slug]); continue; } $values[$index][$this->layout_key] = $value; unset($values[$index][$slug]); continue; } if (papi_is_property_type_key($slug)) { continue; } $property_type_slug = papi_get_property_type_key_f($slug); if (!isset($values[$index][$property_type_slug])) { continue; } $property_type_value = $values[$index][$property_type_slug]; $property_type = papi_get_property_type($property_type_value); if (!is_object($property_type)) { continue; } // Get property child slug. $child_slug = $this->get_child_slug($repeater_slug, $slug); // Create cache key. $cache_key = sprintf('%s_%d_%s', $repeater_slug, $index, $slug); // Get raw value from cache if enabled. if ($this->cache) { $raw_value = papi_cache_get($cache_key, $post_id, $this->get_meta_type()); } else { $raw_value = false; } // Load the value. if ($raw_value === null || $raw_value === false) { $values[$index][$slug] = $property_type->load_value($value, $child_slug, $post_id); $values[$index][$slug] = papi_filter_load_value($property_type->type, $values[$index][$slug], $child_slug, $post_id, papi_get_meta_type()); if (!papi_is_empty($values[$index][$slug]) && $this->cache) { papi_cache_set($cache_key, $post_id, $values[$index][$slug], $this->get_meta_type()); } } else { $values[$index][$slug] = $raw_value; } if (strtolower($property_type->type) === 'repeater') { $property_type->cache = false; } // Format the value from the property class. $values[$index][$slug] = $property_type->format_value($values[$index][$slug], $child_slug, $post_id); if (!is_admin()) { $values[$index][$slug] = papi_filter_format_value($property_type->type, $values[$index][$slug], $child_slug, $post_id, papi_get_meta_type()); } $values[$index][$property_type_slug] = $property_type_value; } } if (!is_admin()) { foreach ($values as $index => $row) { foreach ($row as $slug => $value) { if (is_string($value) && preg_match($this->layout_value_regex, $value)) { unset($values[$index][$slug]); $values[$index]['_layout'] = preg_replace($this->layout_value_regex, '', $value); } if (papi_is_property_type_key($slug)) { unset($values[$index][$slug]); } if (papi_is_empty($value)) { unset($values[$index][$slug]); } } } } return $values; }
/** * Format the value of the property before it's returned * to WordPress admin or the site. * * @param mixed $values * @param string $repeater_slug * @param int $post_id * * @return array */ public function format_value($values, $repeater_slug, $post_id) { if (!is_array($values)) { return []; } $values = papi_to_property_array_slugs($values, $repeater_slug); foreach ($values as $slug => $value) { if (papi_is_property_type_key($slug)) { continue; } $property_type_slug = papi_get_property_type_key_f($slug); if (!isset($values[$property_type_slug])) { continue; } // Get property type $property_type_value = $values[$property_type_slug]; $property_type = papi_get_property_type($property_type_value); if (!is_object($property_type)) { continue; } // Get property child slug. $child_slug = $this->get_child_slug($repeater_slug, $slug); // Get raw value from cache if enabled. if ($this->cache) { $raw_value = papi_cache_get($slug, $post_id, $this->get_meta_type()); } else { $raw_value = false; } // Load the value. if ($raw_value === null || $raw_value === false) { $values[$slug] = $property_type->load_value($value, $child_slug, $post_id); $values[$slug] = papi_filter_load_value($property_type->type, $values[$slug], $child_slug, $post_id, papi_get_meta_type()); if (!papi_is_empty($values[$slug]) && $this->cache) { papi_cache_set($slug, $post_id, $values[$slug], $this->get_meta_type()); } } else { $values[$slug] = $raw_value; } // Format the value from the property class. $values[$slug] = $property_type->format_value($values[$slug], $child_slug, $post_id); if (!is_admin()) { $values[$slug] = papi_filter_format_value($property_type->type, $values[$slug], $child_slug, $post_id, papi_get_meta_type()); } $values[$property_type_slug] = $property_type_value; } if (!is_admin()) { foreach ($values as $slug => $value) { if (papi_is_property_type_key($slug)) { unset($values[$slug]); } } } return papi_from_property_array_slugs($values, $repeater_slug); }
/** * Format the value of the property before it's returned * to WordPress admin or the site. * * @param mixed $values * @param string $repeater_slug * @param int $post_id * * @return array */ public function format_value($values, $repeater_slug, $post_id) { if (!is_array($values)) { return []; } foreach ($values as $index => $layout) { foreach ($layout as $slug => $value) { if (is_string($value) && preg_match($this->layout_prefix_regex, $value)) { if (isset($values[$index][$this->layout_key])) { unset($values[$index][$slug]); continue; } $values[$index][$this->layout_key] = $value; unset($values[$index][$slug]); continue; } if (papi_is_property_type_key($slug)) { continue; } $property_type_slug = papi_get_property_type_key_f($slug); if (!isset($values[$index][$property_type_slug])) { continue; } $property_type_value = $values[$index][$property_type_slug]; $property_type = papi_get_property_type($property_type_value); if (!is_object($property_type)) { continue; } // Get property child slug. $child_slug = $this->get_child_slug($repeater_slug, $slug); // Load the value. $values[$index][$slug] = $property_type->load_value($value, $child_slug, $post_id); $values[$index][$slug] = papi_filter_load_value($property_type->type, $values[$index][$slug], $child_slug, $post_id); // Format the value from the property class. $values[$index][$slug] = $property_type->format_value($values[$index][$slug], $child_slug, $post_id); if (!is_admin()) { $values[$index][$slug] = papi_filter_format_value($property_type->type, $values[$index][$slug], $child_slug, $post_id); } $values[$index][$property_type_slug] = $property_type_value; } } if (!is_admin()) { foreach ($values as $index => $row) { foreach ($row as $slug => $value) { if (is_string($value) && preg_match($this->layout_prefix_regex, $value)) { $values[$index][$slug] = preg_replace($this->layout_prefix_regex, '', $value); } if (papi_is_property_type_key($slug)) { unset($values[$index][$slug]); } } } } return $values; }
/** * Format the value of the property before it's returned * to WordPress admin or the site. * * @param mixed $values * @param string $repeater_slug * @param int $post_id * * @return array */ public function format_value($values, $repeater_slug, $post_id) { if (!is_array($values)) { return []; } $values = papi_to_property_array_slugs($values, $repeater_slug); foreach ($values as $slug => $value) { if (papi_is_property_type_key($slug)) { continue; } $property_type_slug = papi_get_property_type_key_f($slug); if (!isset($values[$property_type_slug])) { continue; } // Get property type $property_type_value = $values[$property_type_slug]; $property_type = papi_get_property_type($property_type_value); if (!is_object($property_type)) { continue; } // Get property child slug. $child_slug = $this->get_child_slug($repeater_slug, $slug); // Load the value. $values[$slug] = $property_type->load_value($value, $child_slug, $post_id); $values[$slug] = papi_filter_load_value($property_type->type, $values[$slug], $child_slug, $post_id); // Format the value from the property class. $values[$slug] = $property_type->format_value($values[$slug], $child_slug, $post_id); if (!is_admin()) { $values[$slug] = papi_filter_format_value($property_type->type, $values[$slug], $child_slug, $post_id); } $values[$property_type_slug] = $property_type_value; } if (!is_admin()) { foreach ($values as $slug => $value) { if (papi_is_property_type_key($slug)) { unset($values[$slug]); } } } return papi_from_property_array_slugs($values, $repeater_slug); }
/** * Load property value from the property. * * @param string $slug * * @return mixed */ public function load_value($slug) { $slug = unpapify($slug); $property = $this->property($slug); // If no property type is found, just return null. if (!papi_is_property($property)) { return; } // Get raw property meta value. $value = papi_get_property_meta_value($this->id, $slug, $this->get_type()); // Prepare load value, when you have `overwrite => true` // this value will not exist in the database and that's // why we need to prepare (change) the value. $value = $this->prepare_load_value($property, $value); // Bail if value is empty and option value is empty. if (papi_is_empty($value)) { if (!papi_is_empty($property->get_option('value'))) { return $property->get_option('value'); } return; } // A property need to know about the store. $this->property($slug)->set_store($this); // Run load value method right after the value has been loaded from the database. $value = $property->load_value($value, $slug, $this->id); $value = papi_filter_load_value($property->type, $value, $slug, $this->id, papi_get_meta_type()); // Remove empty values from arrays. if (is_array($value)) { $value = array_filter($value); } return $value; }