/** * Displays the input control for the field. * * @since 0.5.0 * @param string $val the current value of the field * @param bool $echo whether to echo the output (default is true) * @return string the HTML output of the field control */ public function display($val, $echo = true) { $args = $this->args; $args['value'] = $this->parse($val, true); $args = array_merge($args, $this->data_atts); $output = '<input type="text"' . FieldManager::make_html_attributes($args, false, false) . ' />'; if ($echo) { echo $output; } return $output; }
/** * Displays the input control for the field. * * @since 0.5.0 * @param string $val the current value of the field * @param bool $echo whether to echo the output (default is true) * @return string the HTML output of the field control */ public function display($val, $echo = true) { $args = $this->args; $args = array_merge($args, $this->data_atts); $output = '<textarea' . FieldManager::make_html_attributes($args, false, false) . '>'; $output .= esc_textarea($val); $output .= '</textarea>'; if ($echo) { echo $output; } return $output; }
/** * Displays the input control for the field. * * @since 0.5.0 * @param integer|float $val the current value of the field * @param bool $echo whether to echo the output (default is true) * @return string the HTML output of the field control */ public function display($val, $echo = true) { $args = $this->args; $args['value'] = $val; $args = array_merge($args, $this->data_atts); $text_args = array('id' => $args['id'] . '-' . $this->type . '-viewer', 'class' => 'wpdlib-input-' . $this->type . '-viewer', 'value' => $args['value'], 'min' => $args['min'], 'max' => $args['max'], 'step' => $args['step']); $output = '<input type="number"' . FieldManager::make_html_attributes($text_args, false, false) . ' />'; $output .= '<input type="' . $this->type . '"' . FieldManager::make_html_attributes($args, false, false) . ' />'; if ($echo) { echo $output; } return $output; }
/** * Displays the input control for the field. * * @since 0.6.0 * @param string $val the current value of the field * @param bool $echo whether to echo the output (default is true) * @return string the HTML output of the field control */ public function display($val, $echo = true) { global $wp_locale; $args = $this->args; $args['value'] = $val; if ('coords' === $args['store']) { $args['value'] = $this->parse($val, true); } $args = array_merge($args, $this->data_atts); $args['data-store'] = $args['store']; $args['data-decimal_separator'] = $wp_locale->number_format['decimal_point']; unset($args['store']); $output = '<input type="text"' . FieldManager::make_html_attributes($args, false, false) . ' />'; if ($echo) { echo $output; } return $output; }
/** * Displays the input control for the field. * * @since 0.5.0 * @param integer|string $val the current value of the field * @param bool $echo whether to echo the output (default is true) * @return string the HTML output of the field control */ public function display($val, $echo = true) { $args = $this->args; unset($args['placeholder']); $args['value'] = $val; $args = array_merge($args, $this->data_atts); $args['data-store'] = $args['store']; $mime_types = $this->verify_mime_types($args['mime_types']); if ($mime_types) { $args['data-query'] = json_encode(array('post_mime_type' => $mime_types)); } unset($args['store']); unset($args['mime_types']); $output = '<input type="text"' . FieldManager::make_html_attributes($args, false, false) . ' />'; if ($echo) { echo $output; } return $output; }
/** * Displays the input control for the field. * * @since 0.5.0 * @param bool $val the current value of the field * @param bool $echo whether to echo the output (default is true) * @return string the HTML output of the field control */ public function display($val, $echo = true) { $args = $this->args; $label = $args['label']; unset($args['label']); unset($args['placeholder']); if ($val) { $args['checked'] = true; } $args = array_merge($args, $this->data_atts); $output = '<label>'; $output .= '<input type="' . $this->type . '"' . FieldManager::make_html_attributes($args, false, false) . ' />'; $output .= esc_html($label); $output .= '</label>'; if ($echo) { echo $output; } return $output; }
/** * Renders the sections of this tab. * * If the tab is set to be draggable, the function will run its metabox action. * Otherwise it will just manually output the sections. * * @since 0.5.0 */ protected function render_sections() { $form_atts = array('id' => $this->slug, 'action' => admin_url('options.php'), 'method' => 'post', 'novalidate' => true); /** * This filter can be used to adjust the form attributes. * * @since 0.5.0 * @param array the associative array of form attributes * @param WPOD\Components\Tab current tab instance */ $form_atts = apply_filters('wpod_form_atts', $form_atts, $this); echo '<form' . FieldManager::make_html_attributes($form_atts, false, false) . '>'; if ('draggable' == $this->args['mode']) { wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); echo '<div class="metabox-holder">'; echo '<div class="postbox-container">'; do_meta_boxes($this->slug, 'normal', null); echo '</div>'; echo '</div>'; } else { foreach ($this->get_children() as $section) { $section->render(false); } } settings_fields($this->slug); submit_button(); echo '</form>'; }
/** * Displays a single item in the select. * * @since 0.5.0 * @param string $value the value of the item * @param string|array $label the label of the item * @param string $id the overall field's ID attribute * @param string $name the overall field's name attribute * @param string|array $current the current value of the field * @param bool $echo whether to echo the output (default is true) * @return string the HTML output of the item */ protected function display_item($value, $label, $single_type, $id, $name, $current = '', $echo = true) { $option_atts = array('value' => $value, 'selected' => $this->is_value_checked_or_selected($current, $value)); if (is_array($label)) { if (isset($label['image'])) { $option_atts['data-image'] = esc_url($label['image']); } elseif (isset($label['color'])) { $option_atts['data-color'] = ltrim($label['color'], '#'); } if (isset($label['label'])) { $label = $label['label']; } else { $label = ''; } } $output = '<option' . FieldManager::make_html_attributes($option_atts, false, false) . '>' . esc_html($label) . '</option>'; if ($echo) { echo $output; } return $output; }
/** * Displays the input control for the field. * * @since 0.5.0 * @param string $val the current value of the field * @param bool $echo whether to echo the output (default is true) * @return string the HTML output of the field control */ public function display($val, $echo = true) { $args = $this->args; $args['value'] = $val; if (isset($args['rows'])) { unset($args['rows']); } $args = array_merge($args, $this->data_atts); $output = '<input type="' . $this->type . '"' . FieldManager::make_html_attributes($args, false, false) . ' />'; if ($echo) { echo $output; } return $output; }
/** * Displays a single group of fields. * * The function is also used to generate a dynamic template which is used in Javascript when appending new groups. * * @since 0.5.0 * @param integer $key the index of the group * @param array $values the values of the group as `$field_slug => $value` * @param bool $echo whether to echo the output (default is true) * @return string the HTML output of the group */ protected function display_item($key, $values = array(), $echo = true) { $output = '<tr class="wpdlib-repeatable-row">'; $output .= '<td class="wpdlib-repeatable-number">'; if ('{{' . 'KEY' . '}}' === $key) { $output .= '<span>' . sprintf(__('%s.', 'wpdlib'), '{{' . 'KEY_PLUSONE' . '}}') . '</span>'; } else { $key = absint($key); $output .= '<span>' . sprintf(__('%s.', 'wpdlib'), $key + 1) . '</span>'; } $output .= '</td>'; foreach ($this->args['repeatable']['fields'] as $slug => $args) { if (!isset($this->fields[$slug])) { continue; } $val = isset($values[$slug]) ? $values[$slug] : $this->fields[$slug]->validate(); $this->fields[$slug]->id = $this->args['id'] . '-' . $key . '-' . $slug; $this->fields[$slug]->name = $this->args['name'] . '[' . $key . '][' . $slug . ']'; $output .= '<td class="wpdlib-repeatable-col wpdlib-repeatable-' . $this->args['id'] . '-' . $slug . '">'; $output .= $this->fields[$slug]->display($val, false); $output .= '</td>'; } $button_args = array('class' => 'wpdlib-remove-repeatable-button', 'href' => '#', 'data-number' => $key); $output .= '<td class="wpdlib-repeatable-remove">'; $output .= '<a' . FieldManager::make_html_attributes($button_args, false, false) . '>' . __('Remove', 'wpdlib') . '</a>'; $output .= '</td>'; $output .= '</tr>'; if ($echo) { echo $output; } return $output; }
/** * Displays a single item in the group. * * @since 0.5.0 * @param string $value the value of the item * @param string|array $label the label of the item * @param string $id the overall field's ID attribute * @param string $name the overall field's name attribute * @param string|array $current the current value of the field * @param bool $echo whether to echo the output (default is true) * @return string the HTML output of the item */ protected function display_item($value, $label, $single_type, $id, $name, $current = '', $echo = true) { $option_atts = array('id' => $id . '-' . $value, 'name' => $name, 'value' => $value, 'checked' => $this->is_value_checked_or_selected($current, $value), 'readonly' => $this->args['readonly'], 'disabled' => $this->args['disabled']); $option_atts = array_merge($option_atts, $this->data_atts); $additional_output = $additional_class = ''; if (is_array($label)) { list($additional_output, $additional_class, $label) = $this->maybe_generate_additional_item_output($option_atts['id'], $label, $option_atts['checked']); } $output = '<div class="wpdlib-' . $single_type . $additional_class . '">'; $output .= '<input type="' . $single_type . '"' . FieldManager::make_html_attributes($option_atts, false, false) . ' />'; $output .= $additional_output; if (!empty($label)) { $output .= ' <label for="' . $option_atts['id'] . '">' . esc_html($label) . '</label>'; } $output .= '</div>'; if ($echo) { echo $output; } return $output; }
/** * Renders the section. * * It displays the title and description (if available) for the section. * Then it shows the fields of this section or, if no fields are available, calls the callback function. * * @since 0.5.0 * @param boolean $metabox if this function is called inside a metabox, this parameter needs to be true, otherwise it has to be explicitly false */ public function render($metabox = true) { // only display the title if the section is not displayed as a metabox if (null !== $metabox || false === $metabox) { echo '<h3>' . $this->args['title'] . '</h3>'; } $parent_tab = $this->get_parent(); /** * This action can be used to display additional content on top of this section. * * @since 0.5.0 * @param string the slug of the current section * @param array the arguments array for the current section * @param string the slug of the current tab */ do_action('wpod_section_before', $this->slug, $this->args, $parent_tab->slug); if (!empty($this->args['description'])) { echo '<p class="description">' . $this->args['description'] . '</p>'; } if (count($this->get_children()) > 0) { $table_atts = array('class' => 'form-table wpdlib-form-table'); /** * This filter can be used to adjust the form table attributes. * * @since 0.5.0 * @param array the associative array of form table attributes * @param WPOD\Components\Section current section instance */ $table_atts = apply_filters('wpod_table_atts', $table_atts, $this); echo '<table' . FieldManager::make_html_attributes($table_atts, false, false) . '>'; do_settings_fields($parent_tab->slug, $this->slug); echo '</table>'; } elseif ($this->args['callback'] && is_callable($this->args['callback'])) { call_user_func($this->args['callback']); } else { App::doing_it_wrong(__METHOD__, sprintf(__('There are no fields to display for section %s. Either add some or provide a valid callback function instead.', 'options-definitely'), $this->slug), '0.5.0'); } /** * This action can be used to display additional content at the bottom of this section. * * @since 0.5.0 * @param string the slug of the current section * @param array the arguments array for the current section * @param string the slug of the current tab */ do_action('wpod_section_after', $this->slug, $this->args, $parent_tab->slug); }
/** * Renders the term metabox. * * It displays the title and description (if available) for the metabox. * Then it shows the fields of this metabox or, if no fields are available, calls the callback function. * * @since 0.6.0 * @param WP_Term $term the term currently being shown */ public function render($term) { $parent_taxonomy = $this->get_parent(); if ('side' == $this->args['context']) { echo '<div class="wpdlib-narrow">'; } /** * This action can be used to display additional content on top of this term metabox. * * @since 0.6.0 * @param string the slug of the current metabox * @param array the arguments array for the current metabox * @param string the slug of the current taxonomy */ do_action('wpptd_term_metabox_before', $this->slug, $this->args, $parent_taxonomy->slug); if (!empty($this->args['description'])) { echo '<p class="description">' . $this->args['description'] . '</p>'; } if (count($this->get_children()) > 0) { $table_atts = array('class' => 'form-table wpdlib-form-table'); /** * This filter can be used to adjust the term editing form table attributes. * * @since 0.6.0 * @param array the associative array of form table attributes * @param WPPTD\Components\TermMetabox current metabox instance */ $table_atts = apply_filters('wpptd_term_table_atts', $table_atts, $this); echo '<table' . FieldManager::make_html_attributes($table_atts, false, false) . '>'; foreach ($this->get_children() as $field) { $field->render($term); } echo '</table>'; } elseif ($this->args['callback'] && is_callable($this->args['callback'])) { call_user_func($this->args['callback'], $term); } else { App::doing_it_wrong(__METHOD__, sprintf(__('There are no fields to display for metabox %s. Either add some or provide a valid callback function instead.', 'post-types-definitely'), $this->slug), '0.5.0'); } /** * This action can be used to display additional content at the bottom of this term metabox. * * @since 0.6.0 * @param string the slug of the current metabox * @param array the arguments array for the current metabox * @param string the slug of the current taxonomy */ do_action('wpptd_term_metabox_after', $this->slug, $this->args, $parent_taxonomy->slug); if ('side' == $this->args['context']) { echo '</div>'; } }