Example #1
0
 /**
  * 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']);
     }
 }
Example #2
0
 /**
  * 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));
     }
 }