/** * Get the label text for a field * @param mixed $field_key Alternatively, you can pass in the field array * @return string */ public function getLabelText($field_key) { $field = $this->getField($field_key); if (!is_array($field)) { return null; } return array_key_exists('label', $field) ? $field['label'] : Str::human(str_replace('-', ' ', preg_replace('/_id$/i', '', $field_key))); }
/** * Render a meta box * @param object $taxonomy_key * @param array $term_config * @param bool $return Return the output? If false, echoes the output */ public function renderMetaBox($taxonomy_key, $term_config, $return = false) { $config =& $term_config['args']; if (!Arr::iterable($config['fields'])) { return false; } $extra = get_option($this->getOptionID()); $out = array(); $out[] = '<table class="form-table">'; foreach ($config['fields'] as $name => $field) { // Hack to determine if we're on the category admin page $is_quick_add_page = !preg_match('/tag_ID/', $_SERVER['REQUEST_URI']); if ($is_quick_add_page && is_array($field) && array_key_exists('value', $field)) { $field['value'] = $field['value']; } elseif (is_array($extra) && array_key_exists($name, $extra)) { $field['value'] = $extra[$name]; } else { $field['value'] = null; } // Remove the escaped double quotes that WordPress fails to remove // when it unserializes data stored in the options table. // This bug was identified when links were added to a WYSIWYG field // and the anchor tags were rendered like <a href=\"foo.com\">... $field['value'] = str_replace('\\"', '"', $field['value']); $default = null; if (array_key_exists('default', $field)) { if ($field['type'] === 'select') { $default = $field['options'][$field['default']]; } elseif ($field['type'] === 'image') { $default = '<br>' . Html::image($field['default'], null, array('style' => 'max-width:100px;')); } else { $default = nl2br($field['default']); } } $tr_class = $name . ' form-field'; if ($field['type'] === 'hidden') { $tr_class .= ' hidden'; } $out[] = sprintf('<tr%s><td><label for="%s">%s%s</label></td><td>%s%s</td><td>%s</td></tr>', Html::attribs(array('class' => $tr_class)), array_key_exists('id', $field) ? $field['id'] : $name, array_key_exists('label', $field) ? $field['label'] : Str::human($name), array_key_exists('required', $field) && $field['required'] ? ' <span class="required">*</span>' : '', $this->getRenderMetaBoxField($name, $field), array_key_exists('description', $field) ? Html::p($field['description'], array('class' => 'description')) : null, !is_null($default) ? sprintf('<p class="description">Default: %s</p>', $default) : null); } $out[] = '</table>'; $html = join("\n", $out); if ($return) { return $html; } echo $html; }
/** * Get the excerpt through the_content filter * Accepted values for length_unit: 'char', 'word' * @param array $args * @return string */ public function getTheExcerpt($args = array()) { $default_args = array('length' => 150, 'length_unit' => 'char', 'strip_shortcodes' => true, 'hellip' => '…'); $args = Arr::iterable($args) ? array_merge($default_args, $args) : $default_args; extract($args); $excerpt = $this->get('post_excerpt'); if (!strlen($excerpt)) { $excerpt = strip_tags($this->get('post_content')); if ($length_unit == 'char') { $excerpt = Str::shortenWordsByChar($excerpt, $length, $hellip); } elseif ($length_unit == 'word') { $excerpt = Str::shortenWords($excerpt, $length, $hellip); } } $excerpt = apply_filters('the_excerpt', $excerpt); return $strip_shortcodes ? strip_shortcodes($excerpt) : $excerpt; }