/** * Register a theme through a theme or plugin * * @param array $args - id, title, dir and url of the theme */ function register($args) { # Check for all required keys $keys = apply_filters('uf_theme_args', array('id', 'title', 'dir', 'url', 'image')); if (count(array_intersect_key($args, array_flip($keys))) < count($keys)) { uf_die('Incorrect keys for uf_register_theme!'); } # Add trailing slashes where needed $args['dir'] = trailingslashit($args['dir']); $args['url'] = trailingslashit($args['url']); # Add the theme to the right place array_unshift($this->available, $args); }
/** * Adds an exception to the pool. * * @param string $message The message of the error * @param string $type The type of the error/notification */ static function add($message, $type = null) { # If there's no type set, we can't know if it should be saved if (!$type) { uf_die($message); } # If the type is not set to be buffered, die if (!isset(self::$catchable[$type])) { uf_die($message); } else { self::$buffer[$type][] = $message; UF_Notices::add($message, true); } }
/** * Add multiple terms at once * * @param int[] $terms IDs of terms * @return UF_Postmeta The instance of the current box */ public function set_terms(array $terms) { foreach ($terms as $taxonomy => $term) { if (is_array($term) && taxonomy_exists($taxonomy)) { foreach ($term as $id) { $this->add_term($taxonomy, $id); } } elseif (is_array($term)) { $this->set_terms($term); } else { uf_die("<strong>UF_Postmeta</strong>: Taxonomy "{$taxonomy}" does not exist!"); } } return $this; }
/** * Adds a fields group. Used internally by this and child classes. * * @access protected * @param mixed[] $atts The settings of the group. * @param UF_Field[] $fields The fields of the group */ protected function add_fields_group($atts, array $fields) { # The key/type is the most important part of the group. It should be valid for attributes $group_key = sanitize_title($atts['group_key']); # Prepare the main settings $field_group = array('title' => $atts['group_title'], 'fields' => array(), 'type' => $group_key, 'title_field' => isset($atts['title_field']) ? $atts['title_field'] : '', 'description' => $atts['group_description'], 'icon' => $atts['group_icon']); # Add min/max width for the layout field if (isset($atts['min_width'])) { $field_group['min_width'] = $atts['min_width']; } if (isset($atts['max_width'])) { $field_group['max_width'] = $atts['max_width']; } # Check all fields and then add them to the group $field_keys = array(); foreach ($fields as $field) { # Skip the field if not existing or null if (!$field) { continue; } $key = $field->get_id(); if (isset($field_keys[$key])) { uf_die(sprintf(__('Error: Trying to register a field with the %s key twice in a repeater group!', 'uf'), $key)); } if ($key == 'type') { uf_die(__('"type" is a reserved key in repeaters and cannot be overwritten!', 'uf')); } if (!is_a($field, 'UF_Field')) { uf_die('<strong>' . get_class($this) . '</strong> only supports fields of type UF_Field!'); } $field_group['fields'][] = $field; # Saves the key to prevent duplicate keys $field_keys[$field->get_id()] = 1; } # Add the prepared group to the containing ones $this->field_groups[$group_key] = $field_group; }
/** * Sets the type of the page, a.k.a. it's parent in the menu. * The available types can be seen in the first array below. * * @param string $type One of the types below * @return UF_Options The instance of the page */ public function set_type($type) { $available = array('settings', 'appearance', 'menu', 'tools'); if (!in_array($type, $available)) { uf_die('<strong>UF_Options</strong>: ' . $type . ' is not a valid Options page type!'); } $this->type = $type; return $this; }