/** * 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]); }
/** * 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>'; }
/** * 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 empty. if (!papi_is_empty($value)) { $settings->selected = $value; } $settings->selected = papi_to_array($settings->selected); 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_html_tag('input', ['checked' => in_array($value, $settings->selected) ? 'checked' : null, 'id' => $this->html_id($key), 'name' => $this->html_name() . '[]', 'type' => 'checkbox', 'value' => $value]), papi_convert_to_string($key)]); papi_render_html_tag('br'); } }
/** * 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]); }
/** * Render property html. */ public function html() { $settings = $this->get_settings(); $value = $this->get_value(); papi_render_html_tag('div', ['class' => 'papi-property-color-picker', papi_html_tag('input', ['data-palettes' => $settings->palettes, 'id' => $this->html_id(), 'name' => $this->html_name(), 'type' => $settings->show_input === true ? 'text' : 'hidden', 'value' => $value])]); }
/** * Render html tag from tag name and array of attributes. * * @param string $tag * @param array $attr * * @return string */ function papi_render_html_tag($tag, $attr = []) { echo papi_html_tag($tag, $attr); }
/** * Render repeater html. * * @param object $options */ protected function render_repeater($options) { $layouts = $this->get_settings_layouts(); ?> <div class="papi-property-flexible papi-property-repeater-top" data-limit="<?php echo esc_attr($this->get_setting('limit')); ?> "> <table class="papi-table"> <tbody class="repeater-tbody flexible-tbody"> <?php $this->render_repeater_row(); ?> </tbody> </table> <div class="bottom"> <div class="flexible-layouts-btn-wrap"> <div class="flexible-layouts papi-hide"> <div class="flexible-layouts-arrow"></div> <ul> <?php foreach ($layouts as $layout) { papi_render_html_tag('li', [papi_html_tag('a', ['data-layout' => esc_html($layout['slug']), 'data-papi-json' => sprintf('%s_repeater_json', $options->slug), 'href' => '#', 'role' => 'button', 'tabindex' => 0, esc_html($layout['title'])])]); } ?> </ul> </div> <?php papi_render_html_tag('button', ['class' => 'button button-primary', 'type' => 'button', esc_html($this->get_setting('add_new_label'))]); ?> </div> </div> <?php /* Default repeater value */ ?> <input type="hidden" data-papi-rule="<?php echo esc_attr($options->slug); ?> " name="<?php echo esc_attr($this->get_slug()); ?> []" /> </div> <?php }