/** * Build each type content. * * @param array $contents Contains all data * * @since 3.3.0 */ protected function tplFields($contents) { //Admin panel if (!TTO_IS_ADMIN) { return; } //Build special pages $enabled = array($this->identifier); /** * Get special pages. * * @param array $enabled * @param string $identifier * @return array $enabled * * @since 3.2.0 */ $enabled = apply_filters('tto_template_special_pages', $enabled, $this->identifier); //Define if we are in a special page or not $specials = in_array($this->currentPage, $enabled); $template = array(); $ids = array(); //Check contents if (empty($contents)) { return; } //Check sections $contents = isset($contents['sections']) ? $contents['sections'][$this->currentSection] : $contents; //Iteration on all array foreach ($contents as $content) { //Get type and id $type = isset($content['type']) ? $content['type'] : ''; $id = isset($content['id']) ? $content['id'] : ''; //Get field instance $field = Field::getField($type, $id, $specials, $ids); //Check error if (is_array($field) && $field['error']) { $template[] = $field; continue; } //Update ids if (!empty($id)) { $ids[] = $id; } /** * Set current page. * * @param string $current * * @since 3.3.0 */ do_action('tto_field_current_page', $this->currentPage); //Display field content $template[] = $field->prepareField($content); } return $template; }
/** * Hook building custom fields. * * @param string|object $term Contain term used by function * @uses add_meta_box() * * @since 3.3.0 */ public function hookFieldsDisplay($term) { //Get all authorized fields $unauthorized = Field::getUnauthorizedFields(); $contents = array(); $ids = array(); //Get current $isobject = is_object($term); $slug = $isobject ? $term->taxonomy : $term; $termid = $isobject ? $term->term_id : 0; /** * Build term contents. * * @var string $slug * @param array $contents * @return array $contents * * @since 3.3.0 */ $contents = apply_filters('tto_term_' . $slug . '_contents', $contents); //Check contents if (empty($contents)) { return; } //Get contents foreach ($contents as $ctn) { //Check fields if (empty($ctn)) { continue; } //Get type and id $type = isset($ctn['type']) ? $ctn['type'] : ''; $id = isset($ctn['id']) ? $ctn['id'] : ''; //Check if we are authorized to use this field in CPTs if (empty($type) || in_array($type, $unauthorized)) { continue; } //Get field instance $field = Field::getField($type, $id, array(), $ids); //Get template $tpl = $field->prepareField($ctn, array('prefix' => $slug, 'term_id' => $termid, 'structure' => Engine::getPrefix())); //Display it TeaThemeOptions::getRender($tpl['template'], $tpl['vars']); } }
/** * Hook building custom fields for CPTS. * * @uses add_meta_box() * * @since 3.3.3 */ public function hookFieldsDisplay() { //Get all authorized fields $unauthorized = Field::getUnauthorizedFields(); $slug = isset($_GET['post_type']) ? $_GET['post_type'] : ''; $contents = array(); $ids = array(); //Define current post type's contents if (empty($slug)) { $post = isset($_GET['post']) ? $_GET['post'] : 0; $slug = !empty($post) ? get_post_type($post) : ''; //Define pagenow var if (empty($slug)) { global $pagenow; if ('post-new.php' === $pagenow) { $slug = 'post'; } else { if ('media-new.php' === $pagenow) { $slug = 'attachment'; } else { return; } } } } /** * Build post type contents. * * @var string $slug * @param array $contents * @return array $contents * * @since 3.3.0 */ $contents = apply_filters('tto_posttype_' . $slug . '_contents', $contents); //Check contents if (empty($contents)) { return; } //Get contents foreach ($contents as $ctn) { //Check fields if (empty($ctn)) { continue; } //Get type and id $type = isset($ctn['type']) ? $ctn['type'] : ''; $id = isset($ctn['id']) ? $ctn['id'] : ''; //Check if we are authorized to use this field in CPTs if (empty($type) || in_array($type, $unauthorized)) { continue; } //Title $title = isset($ctn['title']) ? $ctn['title'] : TeaThemeOptions::__('Metabox'); //Get field instance $field = Field::getField($type, $id, array(), $ids); //Check error if (is_array($field) && $field['error']) { continue; } //Update ids if (!empty($id)) { $ids[] = $id; } //Add meta box add_meta_box($slug . '-meta-box-' . $id, $title, array(&$field, 'hookFieldBuild'), $slug, 'normal', 'low', array('type' => $type, 'field' => $field, 'contents' => $ctn)); } }