/** * Returns built configuration array * * @return array */ public function getFullConfig() { $config = $this->config->getAll(); $config['labels'] = $this->getLabels(); $config['capabilities'] = $this->getCapabilities(); $config['rewrite'] = $this->getRewrite(); return $config; }
/** * Runs existing hooks * * @return void */ protected function runHooks() { foreach ($this->hooks->getAll() as $hook => $configs) { foreach ($configs as $config) { $this->processConfig($hook, $config); } } }
/** * Returns a single context container by ID * * @param string $id ID of the target context container * @return Ponticlaro\Bebop\Common\ContextContainer Target context container */ private function __getContextById($id) { $target_context = null; foreach ($this->contexts->getAll() as $context) { if ($context->getId() == $id) { $target_context = $context; break; } } return $target_context; }
/** * Renders tab content * * @return void */ public function render() { $this->__setData(); // Execute callable if ($function = $this->getFunction()) { call_user_func_array($function, array($this->data, $this)); } // Render sections $sections = $this->getAllSections(); if ($sections) { foreach ($sections as $section) { $section->render($this->data->getAll()); } } }
/** * Registers Shortcode and its function * * @param array $attrs Attributes from user input * @param string $content Content on shortcodes with opening and closing tags * @param string $tag Shortcode tag * @return void */ public function __registerShortcode($attrs, $content = null, $tag) { // Clear attributes $this->attributes->clear(); // Set default attributes $this->attributes->setList($this->default_attributes->getAll()); // Remove quotes from attributes if ($attrs) { if (is_array($attrs)) { foreach ($attrs as $key => $attr) { $attrs[$key] = static::__cleanAttrValue($attr); } } elseif (is_string($attrs)) { $attrs = static::__cleanAttrValue($attrs); } $this->attributes->setList($attrs); } ob_start(); // Execute shortcode function call_user_func_array($this->function, array($this->attributes, $content, $tag)); $html = ob_get_contents(); ob_end_clean(); return $html; }
/** * Returns query metadata * * @return array */ protected function __getQueryMeta() { $args = $this->clean_args->getAll(); $meta = array(); $meta['items_total'] = (int) $this->query->found_posts; $meta['items_returned'] = (int) $this->query->post_count; $meta['total_pages'] = (int) $this->query->max_num_pages; $meta['current_page'] = $this->query->max_num_pages === 0 ? 0 : (int) max(1, $this->query->query_vars['paged']); $meta['has_more'] = $meta['current_page'] == $meta['total_pages'] || $meta['total_pages'] == 0 ? false : true; // Remove post_type parameter when not querying the /posts resource if (isset($resource_name) && $resource_name != 'posts' && isset($args['post_type'])) { unset($args['post_type']); } $meta['previous_page'] = in_array($meta['current_page'], [0, 1]) ? null : $this->__buildPreviousPageUrl($this->raw_args->getAll()); $meta['next_page'] = $meta['current_page'] == $meta['total_pages'] || $meta['total_pages'] == 0 ? null : $this->__buildNextPageUrl($this->raw_args->getAll()); return $meta; }
/** * Renders single page UI * * @return void */ protected function renderSinglePage() { echo '<div style="padding-top:30px;">'; settings_fields($this->getId()); $this->__setData(); // Execute callable if ($function = $this->getFunction()) { call_user_func_array($function, array($this->data, $this)); } // Render sections $sections = $this->getAllSections(); if ($sections) { foreach ($sections as $section) { $section->render($this->data->getAll()); } } echo '</div>'; }
/** * Saves meta data * * @param int $post_id ID of the post currently being edited * @return void */ public function __saveMeta($post_id) { // Return if this is a quick edition if (isset($_POST['_inline_edit']) && wp_verify_nonce($_POST['_inline_edit'], 'inlineeditnonce')) { return; } $id = $this->getId(); $nonce_name = 'metabox_' . $id . '_nonce'; $nonce = isset($_POST[$nonce_name]) ? $_POST[$nonce_name] : ''; // Check if $_POST is not empty and nonce is there if (!empty($_POST) && wp_verify_nonce($nonce, 'metabox_' . $id . '_saving_meta')) { $post = get_post($post_id); if (isset($_POST['post_type']) && $_POST['post_type'] == $post->post_type) { // Get out if current post is in the middle of an auto-save if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return $post_id; } // Get out if current user cannot edit this post if (!current_user_can('edit_post', $post_id)) { return $post_id; } // Get fields from callback function $this->__setMetaFields(); foreach ($this->meta_fields->getAll() as $field) { $value = isset($_POST[$field]) ? $_POST[$field] : ''; // Empty values if ($value === '') { delete_post_meta($post_id, $field); } elseif (is_array($value)) { // Delete all entries delete_post_meta($post_id, $field); foreach ($value as $v) { // Add single entry with same meta_key add_post_meta($post_id, $field, $v); } } else { update_post_meta($post_id, $field, $value); } } } } }
/** * Renders this view * * @param string $template Template relative path, without file extension * @param array $vars List of vars for rendering * @param boolean $merge True if these vars should merge with existing ones, false otherwise * @return void */ public function render($template = null, array $vars = array(), $merge = true) { // Throw error if we neither already have a template // or one is not provided in this method if (is_null($this->template) && (!$template || !is_string($template))) { throw new \Exception('You must defined a template to be rendered'); } elseif ($this->template && is_array($template)) { $vars = $template; $merge = is_bool($vars) ? $vars : true; } // Set template and variables $this->setTemplate($template); $this->setVars($vars, $merge); // Expose variables to template foreach ($this->vars->getAll() as $key => $value) { ${$key} = $value; } // Include template include $this->__getTemplatePath($this->getTemplate()); }
/** * Starts router * * @return void */ public function run() { // Remove WordPress Content-Type header & Set Slim response content-type header header_remove('Content-Type'); $this->slim->response()->header('Content-Type', 'application/json'); $this->handleErrors()->preFlightCheck()->handleNotFound()->handleResponse(); $rewrite_tag = $this->getRewriteTag(); $base_url = $this->getBaseUrl(); // Loop through all defined routes foreach ($this->routes->getAll() as $route) { $this->slim->{$route->getMethod()}('/' . $base_url . trim($route->getPath(), '/'), function () use($route, $rewrite_tag) { // Get data from route function $data = call_user_func_array($route->getFunction(), func_get_args()); // Enable developers to modify global response $data = apply_filters($rewrite_tag . ':response', $data); // Send response $this->slim->applyHook('handle_response', $data); }); } $this->slim->run(); }
/** * Returns all routes * * @return array Routes list */ public function getAll() { return $this->routes->getAll(); }
/** * Returns all data * * @return array */ public function getAll() { return $this->data->getAll(); }