/** * Output hidden input field that cointains which property is used. */ protected function render_hidden_html() { $slug = $this->get_option('slug'); if (substr($slug, -1) === ']') { $slug = substr($slug, 0, -1); $slug = papi_get_property_type_key($slug); $slug .= ']'; } else { $slug = papi_get_property_type_key($slug); } $slug = papify($slug); $options = $this->get_options(); $property_json = base64_encode(papi_maybe_json_encode($options)); papi_render_html_tag('input', ['data-property' => strtolower($this->get_option('type')), 'name' => $slug, 'type' => 'hidden', 'value' => $property_json]); }
/** * Prepare properties data for saving. * * @param array $data * @param int $post_id * * @return array */ protected function prepare_properties_data(array $data = [], $post_id = 0) { // Since we are storing witch property it is in the $data array // we need to remove that and set the property type to the property // and make a array of the property type and the value. foreach ($data as $key => $value) { $property_type_key = papi_get_property_type_key(); if (strpos($key, $property_type_key) === false) { continue; } $property_key = str_replace($property_type_key, '', $key); // Check if value exists. if (isset($data[$property_key])) { $data[$property_key] = ['type' => $value, 'value' => $data[$property_key]]; } unset($data[$key]); } foreach ($data as $key => $item) { $property = papi_get_property_type($item['type']); unset($data[$key]); if (papi_is_property($property)) { // Run `update_value` method on the property class. $data[$key] = $property->update_value($item['value'], papi_remove_papi($key), $post_id); // Apply `update_value` filter so this can be changed from the theme for specified property type. $data[$key] = papi_filter_update_value($item['type']->type, $data[$key], papi_remove_papi($key), $post_id); if ($item['type']->overwrite) { $slug = papi_remove_papi($key); $this->overwrite[$slug] = $data[$key]; } } } return $data; }
/** * Get the right key for a property type with a underscore as the first character. * * @param string $str * * @return string */ function papi_get_property_type_key_f($str) { return papi_f(papi_get_property_type_key($str)); }
/** * Prepare properties data for saving. * * @param array $data * @param int $post_id * * @return array */ protected function prepare_properties_data(array $data = [], $post_id = 0) { // Since we are storing witch property it is in the `$data` array // we need to remove that and set the property type to the property // and make a array of the property type and the value. foreach ($data as $key => $value) { if (papi_is_property_type_key($key)) { continue; } $property_type_key = papify(papi_get_property_type_key($key)); // Check if value exists. if (!isset($data[$key]) && !isset($data[$property_type_key])) { continue; } // Pair property value with property type object. $data[$key] = ['type' => $data[$property_type_key], 'value' => $value]; // Remove property type object since it's not needed anymore. unset($data[$property_type_key]); } foreach ($data as $key => $item) { if (papi_is_property_type_key($key)) { continue; } $property = papi_get_property_type($item['type']); unset($data[$key]); if (papi_is_property($property)) { // Run `update_value` method on the property class. $data[$key] = $property->update_value($item['value'], unpapify($key), $post_id); // Apply `update_value` filter so this can be changed from // the theme for specified property type. $data[$key] = papi_filter_update_value($item['type']->type, $data[$key], unpapify($key), $post_id, papi_get_meta_type()); if ($item['type']->overwrite) { $slug = unpapify($key); $this->overwrite[$slug] = $data[$key]; unset($data[$key]); } } } return $data; }