/** * Render an admin column * @param string $column_name * @param integer $item_id */ public function renderAdminColumn($column_name, $item_id) { $columns = $this->getAdminColumns(); if (!in_array($column_name, $columns)) { return; } $field = $this->getField($column_name); if (is_array($field)) { $class = get_called_class(); $entry = new $class(); $entry->load($item_id); $out = $entry->get($column_name); if (isset($field['type'])) { switch ($field['type']) { case 'checkbox': $checkbox_display = $entry->getCheckboxDisplay($column_name); $out = $entry->get($column_name) ? reset($checkbox_display) : end($checkbox_display); break; case 'image': $out = Html::image($entry->get($column_name), $entry->get($column_name), array('class' => 'thumbnail')); break; case 'select': $out = array_key_exists($entry->get($column_name), $field['options']) ? $field['options'][$entry->get($column_name)] : null; break; } } // Hide the title field if necessary. // But since the title field is the link to the edit page // we are instead going to link the first custom field column. if (method_exists($this, 'getHideTitleFromAdminColumns') && $this->getHideTitleFromAdminColumns() && method_exists($this, 'getEditPermalink') && array_search($column_name, array_values($columns)) === 0) { $out = sprintf('<a href="%s">%s</a>', $this->getEditPermalink(), $out); } echo $out; return; } if (Arr::iterable($this->getTaxonomies())) { $taxonomy_key = $this->getTaxonomyKey($column_name); if ($taxonomy_key) { echo get_the_term_list($item_id, $taxonomy_key, null, ', '); return; } } }
/** * 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; }
/** * Render a meta box * @param object $post * @param array $post_config * @param bool $return Return the output? If false, echoes the output */ public function renderMetaBox($post, $post_config, $return = false) { $config = $this->getMetaBoxConfig($post_config['args']); if (!Arr::iterable($config['fields'])) { return false; } $this->load($post); $out = array(); $out[] = '<table>'; foreach ($config['fields'] as $name => $field) { // Hack to know if we're editing an existing post $is_existing_post = is_array($_SERVER) && array_key_exists('REQUEST_URI', $_SERVER) && preg_match('/post=([\\d]{1,})/', $_SERVER['REQUEST_URI']); $field['type'] = array_key_exists('type', $field) ? $field['type'] : 'text'; if (array_key_exists($name, $this->_info)) { $field['value'] = $this->_info[$name]; } elseif ($is_existing_post && $field['type'] !== 'html') { $field['value'] = null; } $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; if ($field['type'] === 'hidden') { $tr_class .= ' hidden'; } $out[] = sprintf('<tr%s><td>%s</td><td>%s%s%s</td></tr>', Html::attribs(array('class' => $tr_class)), $this->getRenderLabel($name), $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; }