/** * Create a new set of options. * * @param string $key Option name. * @param array $defaults (optional) An associative array of default values. * * @param bool $pluginFile */ public function __construct($key, $defaults = array(), $pluginFile = false) { $this->key = $key; $this->defaults = $defaults; if (!$pluginFile) { add_action("after_switch_theme", array($this, '_activation')); add_action('switch_theme', array($this, 'delete')); } else { Util::add_activation_hook($pluginFile, array($this, '_activation')); Util::add_uninstall_hook($pluginFile, array($this, 'delete')); } add_action('ae_get_option', array($this, 'get'), 10, 2); add_action('ae_set_option', array($this, 'set'), 10, 2); add_action('set_default_option', array($this, 'set_default'), 10, 2); }
/** * Generate the corresponding HTML for a field. * * @param array $args * * @return string */ protected function _render_specific($args) { $args = wp_parse_args($args, array('text' => false, 'extra' => array())); $options = array(); if (false !== $args['text']) { $options[] = array('value' => '', 'selected' => $args['selected'] === array('foo'), 'title' => $args['text']); } foreach ($args['choices'] as $value => $title) { $value = (string) $value; $options[] = array('value' => $value, 'selected' => $value == $args['selected'], 'title' => $title); } $opts = ''; foreach ($options as $option) { $opts .= Util::html('option', array('value' => $option['value'], 'selected' => $option['selected']), $option['title']); } $args['extra']['name'] = $args['name']; $input = Util::html('select', $args['extra'], $opts); return FormField::add_label($input, $args['desc'], $args['desc_pos']); }
function AE_POST($var) { return \AEngine\Util::POST($var); }
/** * Wraps a content in a table row. * * @param string $title * @param string $content * * @return string */ public static function row_wrap($title, $content) { return Util::html('tr', Util::html("th scope='row'", $title), Util::html('td', $content)); }
/** * Wraps a form field in a label, and position field description. * * @param string $input * @param string $desc * @param string $desc_pos * * @return string */ protected static function add_label($input, $desc, $desc_pos) { return Util::html('label', self::add_desc($input, $desc, $desc_pos)) . "\n"; }
/** * Displays notices. * * @param array|string $notices * @param string $class (optional) * * @return void */ public function display_notices($notices, $class = 'updated') { // add inline class so the notices stays in metabox $class .= ' inline'; foreach ((array) $notices as $notice) { echo Util::admin_notice($notice, $class); } }
/** * Adds an action link. * * @param array $links * * @return array */ public function _action_link($links) { $url = add_query_arg('page', $this->args['page_slug'], admin_url($this->args['parent'])); $links[] = Util::html_link($url, $this->args['action_link']); return $links; }