/** * Render property html. */ public function html() { $settings = $this->get_settings(); $value = papi_cast_string_value($this->get_value()); $options_html = []; // Override selected setting with // database value if not empty. if (!papi_is_empty($value)) { $settings->selected = $value; } $classes = 'papi-fullwidth'; if ($settings->select2) { $classes .= ' papi-component-select2'; } if (!empty($settings->placeholder)) { $options_html[] = papi_html_tag('option', ['value' => '', $settings->placeholder]); } // Create option html tags for all items. foreach ($this->get_items() as $key => $value) { $key = is_numeric($key) ? $value : $key; if (papi_is_empty($key)) { continue; } $options_html[] = papi_html_tag('option', ['selected' => $value === $settings->selected ? 'selected' : null, 'value' => $value, papi_convert_to_string($key)]); } papi_render_html_tag('select', ['class' => $classes, 'data-allow-clear' => true, 'data-placeholder' => $settings->placeholder, 'data-width' => '100%', 'id' => $this->html_id(), 'name' => $this->html_name(), $options_html]); }
/** * Echo the value for property on a option page. * * @param string $slug * @param mixed $default */ function the_papi_option($slug = null, $default = null) { $value = papi_get_option($slug, $default); if (is_array($value)) { $value = implode(', ', $value); } if (is_object($value)) { $value = papi_convert_to_string($value); } echo esc_html($value); }
/** * Get Papi cache key. * * @param string $key * @param mixed $suffix * * @return string */ function papi_cache_key($key, $suffix) { if (!is_string($key)) { return ''; } $key = papify($key); $suffix = papi_convert_to_string($suffix); $suffix = papi_html_name($suffix); $suffix = papi_remove_papi($suffix); return sprintf('%s_%s', $key, $suffix); }
/** * Get Papi cache key. * * @param string $key * @param mixed $suffix * @param string $type * * @return string */ function papi_cache_key($key, $suffix, $type = 'post') { if (!is_string($key)) { return ''; } $type = empty($type) ? 'post' : $type; $type = $type === 'page' ? 'post' : $type; $key = unpapify($key); $key = papify($type . '_' . $key); $suffix = papi_convert_to_string($suffix); $suffix = papi_html_name($suffix); $suffix = unpapify($suffix); return sprintf('%s_%s', $key, $suffix); }
/** * Render property html. */ public function html() { $settings = $this->get_settings(); $value = papi_cast_string_value($this->get_value()); // Override selected setting with // database value if not null. if (!papi_is_empty($value)) { $settings->selected = $value; } foreach ($settings->items as $key => $value) { $key = is_numeric($key) ? $value : $key; papi_render_html_tag('label', ['class' => 'light', 'for' => $this->html_id($key), papi_render_html_tag('input', ['id' => $this->html_id($key), 'name' => $this->html_name(), 'type' => 'radio', 'checked' => $value === $settings->selected ? 'checked' : null, 'value' => $value]), papi_convert_to_string($key)]); papi_render_html_tag('br'); } }
/** * Render property html. */ public function html() { $settings = $this->get_settings(); $value = papi_cast_string_value($this->get_value()); // Override selected setting with // database value if not null. if (!papi_is_empty($value)) { $settings->selected = $value; } echo '<div class="papi-property-radio">'; foreach ($settings->items as $key => $value) { $key = is_numeric($key) ? $value : $key; papi_render_html_tag('p', [papi_html_tag('label', ['class' => 'light', 'for' => esc_attr($this->html_id($key)), papi_html_tag('input', ['id' => esc_attr($this->html_id($key)), 'name' => esc_attr($this->html_name()), 'type' => 'radio', 'checked' => $value === $settings->selected, 'value' => $value]), esc_html(papi_convert_to_string($key))])]); } echo '</div>'; }
/** * Get value. * * @return mixed */ public function get_value() { $value = $this->get_option('value'); if (papi_is_empty($value)) { $type = papi_get_meta_type(); $slug = $this->get_slug(true); $value = papi_get_field($slug, null, $type); $post_status = get_post_status($this->get_post_id()); if (papi_is_empty($value) && ($post_status === false || $post_status === 'auto-draft')) { $value = $this->get_option('default'); } } if (papi_is_empty($value)) { return $this->default_value; } if ($this->convert_type === 'string') { $value = papi_convert_to_string($value); } return papi_santize_data($value); }
/** * Build table from array data. * * @param array $arr * @param bool $child * * @return stringe */ protected function build_table(array $arr, $child = false) { $html = '<div class="papi-property-table"><table class="papi-table">'; if ($child) { $html .= '<thead>'; foreach ($arr[0] as $key => $value) { $html .= sprintf('<th>%s</th>', $key); } $html .= '</thead>'; } foreach ($arr as $key => $value) { $html .= '<tr>'; foreach ($value as $key2 => $value2) { if (is_array($value2)) { $value2 = $this->build_table($value2, true); } $html .= sprintf('<td>%s</td>', papi_convert_to_string($value2)); } $html .= '</tr>'; } return $html . '</table></div>'; }
/** * Render property html. */ public function html() { // Setup variables needed. $settings = $this->get_settings(); $value = $this->get_value(); $options_html = []; // Properties that extends dropdown property // maybe don't have this setting. if (!isset($settings->multiple)) { $settings->multiple = false; } // Override selected setting with // database value if not empty. if (!papi_is_empty($value)) { $settings->selected = $value; } $classes = 'papi-fullwidth'; if ($settings->select2) { $classes .= ' papi-component-select2'; } // Add placeholder if any. if (!empty($settings->placeholder)) { $options_html[] = papi_html_tag('option', ['value' => '', $settings->placeholder]); } // Create option html tags for all items. foreach ($this->get_items() as $key => $value) { $key = is_numeric($key) ? $value : $key; if (papi_is_empty($key)) { continue; } // When a multiple we need to check with // `in_array` since the value is a array. if ($settings->multiple) { $selected = in_array($value, $settings->selected, true); } else { $selected = $value === $settings->selected; } $options_html[] = papi_html_tag('option', ['data-edit-url' => get_edit_post_link($value), 'selected' => $selected ? 'selected' : null, 'value' => $value, esc_html(papi_convert_to_string($key))]); } // When selectize is empty this will be used. papi_render_html_tag('input', ['name' => $this->html_name() . ($settings->multiple ? '[]' : ''), 'type' => 'hidden']); papi_render_html_tag('select', ['class' => $classes, 'data-allow-clear' => !empty($settings->placeholder), 'data-placeholder' => $settings->placeholder, 'data-width' => '100%', 'id' => $this->html_id() . ($settings->multiple ? '[]' : ''), 'multiple' => $settings->multiple ? 'multiple' : null, 'name' => $this->html_name() . ($settings->multiple ? '[]' : ''), $options_html]); }
/** * Prepare property value. * * @param mixed $value * * @return mixed */ protected function prepare_value($value) { if (papi_is_empty($value)) { return $this->default_value; } if ($this->convert_type === 'string') { $value = papi_convert_to_string($value); } return papi_santize_data($value); }
/** * Like conditional rule. * * @param Papi_Core_Conditional_Rule $rule * * @return bool */ public function rule_like(Papi_Core_Conditional_Rule $rule) { $value = $this->get_value($rule); if (!is_string($value)) { $value = papi_convert_to_string($value); } if (papi_is_empty($value)) { return false; } return strpos(strtolower($value), strtolower($rule->value)) !== false; }