/** * Hook building menus. * * @uses add_filter() * @uses add_menu_page() * @uses add_submenu_page() * * @since 3.0.0 */ public function hookAdminMenu() { //Admin panel if (!TTO_IS_ADMIN) { return; } //Check if no master page is defined if (empty($this->pages)) { TeaThemeOptions::notify('error', TeaThemeOptions::__('Something went wrong in your parameters definition: no master page found. You can simply do that by using the <code>TeaThemeOptions::addMenu</code> public function.')); return; } //Load assets action hook add_filter('admin_body_class', array(&$this, 'hookBodyClass')); //Reserved words $tocheck = array($this->identifier . '-settings'); /** * Update reserved words. * * @param boolean $tocheck * @param string $identifier * @return boolean $tocheck * * @since 3.2.0 */ $tocheck = apply_filters('tto_menu_engine_check', $tocheck, $this->identifier); //Add submenu pages foreach ($this->pages as $page) { //Main page if ($this->identifier == $page['slug']) { //Update slug and capability $slug = $this->identifier; $capability = TTO_WP_CAP; //Add menu page add_menu_page($page['title'], $page['title'], $capability, $slug, array(&$this, 'tplContents'), ME_ICONSMALL, 80); } else { //Build slug and check it $slug = $page['slug']; $capability = in_array($page['slug'], $tocheck) ? TTO_WP_CAP_MAX : TTO_WP_CAP; } //Add subpage add_submenu_page($this->identifier, $page['title'], $page['name'], $capability, $slug, array(&$this, 'tplContents')); } }
/** * Build header layout. * * @since 3.3.0 */ protected function initialize() { //Admin panel if (!TTO_IS_ADMIN) { return; } //Get current infos $currentpage = empty($this->currentPage) ? $this->identifier : $this->currentPage; $currentsection = empty($this->currentSection) ? '' : $this->currentSection; $slug = $this->pages[$currentpage]['id']; $contents = array(); //Check sections if (!empty($this->pages[$currentpage]['sections'])) { $stns = array(); //Get all datas foreach ($this->pages[$currentpage]['sections'] as $k => $section) { $stns[$k] = array(); //Update section if (empty($this->currentSection)) { $this->currentSection = $k; $this->breadcrumb['currentSection'] = $section['title']; } else { if ($this->currentSection === $k) { $this->breadcrumb['currentSection'] = $section['title']; } } /** * Build section page contents. * * @var string $slug * @var string $section * @param array $stns[$section] * @return array $stns[$section] * * @since 3.3.0 */ $stns[$k] = apply_filters('tto_menu_' . $slug . '-' . $k . '_contents', $stns[$k]); } //Update sections' contents $contents['sections'] = $stns; } else { if ($currentpage == $this->identifier) { //Main page special case $contents = $this->pages[$currentpage]['contents']; } else { $contents = array(); /** * Build page contents. * * @var string $slug * @param array $contents * @return array $contents * * @since 3.3.0 */ $contents = apply_filters('tto_menu_' . $slug . '_contents', $contents); } } //Check if contents are not empty if (empty($contents)) { TeaThemeOptions::notify('error', TeaThemeOptions::__('Something went wrong in your parameters definition: your contents are empty. See README.md for more explanations.')); } //Get all template variables to inject in Twig template $tplvars = $this->tplVars(); //Build contents relatively to the type $fields = $this->tplFields($contents); //Merge all $vars = array_merge($tplvars, array('fields' => $fields)); //Display template TeaThemeOptions::getRender('layouts/base.html.twig', $vars); }
/** * Build HTML component. * * @param array $post Contains all data such as Wordpress asks * @param array $args Contains all data such as Wordpress asks * * @return int|null * * @since 3.0.0 */ public function hookFieldBuild($post, $args) { //If autosave... if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return isset($post->ID) ? $post->ID : null; } //Get contents $content = isset($args['args']['contents']) ? $args['args']['contents'] : array(); $field = isset($args['args']['field']) ? $args['args']['field'] : ''; //Check if a type is defined if (empty($content) || empty($field) || !isset($args['args']['type'])) { TeaThemeOptions::notify('error', TeaThemeOptions::__('A field is missing because no type is defined.')); return null; } //Get values //$type = $args['args']['type']; //$id = isset($content['id']) ? $content['id'] : ''; //Display field content $tpl = $field->prepareField($content, array('post' => $post)); TeaThemeOptions::getRender($tpl['template'], $tpl['vars']); //Return post if it is asked return isset($post->ID) ? $post->ID : null; }
/** * Register $_POST and $_FILES into transients. * * @uses wp_handle_upload() * @param array $request Contains all data in $_REQUEST * @param array $files Contains all data in $_FILES * * @since 3.3.0 */ protected function updateSettings($request, $files) { //Admin panel if (!TTO_IS_ADMIN) { return; } //Check request if (empty($request)) { return; } //Set all options foreach ($request as $k => $v) { //Don't register this default value if (in_array($k, array('do', 'from', 'updated', 'submit'))) { continue; } //Check the key for special "NONE" value $v = 'NONE' == $v || empty($v) ? '' : $v; //Check settings if (preg_match('/^tto-configs-/', $k)) { $k = str_replace('tto-configs-', '', $k); TeaThemeOptions::setConfigs($k, $v); } else { /** * Fires for each data saved in DB. * * @param string $k Option's name * @param string $v Option's value * * @since 3.3.0 */ do_action('tto_action_update_settings', $k, $v); //Register option TeaThemeOptions::setOption($k, $v); } } //Check if files are attempting to be uploaded if (!empty($files)) { //Get required files require_once ABSPATH . 'wp-admin/includes/image.php'; require_once ABSPATH . 'wp-admin/includes/file.php'; require_once ABSPATH . 'wp-admin/includes/media.php'; //Set all URL in transient foreach ($files as $k => $v) { //Don't do nothing if no file is defined if (empty($v['tmp_name'])) { continue; } //Do the magic $file = wp_handle_upload($v, array('test_form' => false)); //Register option and transient TeaThemeOptions::setOption($k, $file['url']); } } //Notify TeaThemeOptions::notify('updated', TeaThemeOptions::__('The Tea Theme Options is updated.')); }