/**
  * Insert post 
  *
  * @param array $args argument of post
  * @return mixed $validate_data of $args
  * @author Jack Bui
  */
 public function insert($args = array())
 {
     global $current_user, $user_ID;
     foreach ($args as $key => $value) {
         if ((in_array($key, $this->meta) || in_array($key, $this->convert)) && is_string($args[$key]) && $key != 'post_content') {
             $args[$key] = strip_tags($args[$key]);
         }
     }
     $validated_data = $this->prepare_data($args, $this->create_rules);
     if (is_wp_error($validated_data)) {
         return $validated_data;
     }
     $args = $validated_data;
     // pre filter filter post args
     $args = apply_filters('jb_pre_insert_' . $this->post_type, $args);
     if (is_wp_error($args)) {
         return $args;
     }
     $args = wp_parse_args($args, array('post_type' => $this->post_type));
     //set post status to pending
     $pending = jb_get_option('use_pending_' . $this->post_type, false);
     if ($pending) {
         $args['post_status'] = 'pendding';
     }
     if (!isset($args['post_status'])) {
         $args['post_status'] = 'draft';
     }
     // could not create with an ID
     if (isset($args['ID'])) {
         return new WP_Error('invalid_data', __("The ID already existed!", JB_DOMAIN));
     }
     if (!isset($args['post_author']) || empty($args['post_author'])) {
         $args['post_author'] = $current_user->ID;
     }
     if (empty($args['post_author'])) {
         return new WP_Error('missing_author', __('You must login to submit listing.', JB_DOMAIN));
     }
     // filter tax_input
     $args = $this->_filter_tax_input($args);
     // filter post content strip invalid tag
     if (isset($args['post_content'])) {
         $args['post_content'] = $this->filter_content($args['post_content']);
     }
     /**
      * insert post by wordpress function
      */
     $result = wp_insert_post($args, true);
     /**
      * update custom field and tax
      */
     if ($result != false && !is_wp_error($result)) {
         $this->update_custom_field($result, $args);
         $args['ID'] = $result;
         $args['id'] = $result;
         /**
          * do action jb_insert_{$this->post_type}
          * @param Int $result Inserted post ID
          * @param Array $args The array of post data
          */
         do_action('jb_insert_' . $this->post_type, $result, $args);
         $result = (object) $args;
         /**
          * do action jb_insert_post
          * @param object $args The object of post data
          */
         do_action('jb_insert_post', $result);
         // localize text for js
         if (!empty($this->localize)) {
             foreach ($this->localize as $key => $localize) {
                 $a = array();
                 foreach ($localize['data'] as $loc) {
                     array_push($a, $result->{$loc});
                 }
                 $result->{$key} = vsprintf($localize['text'], $a);
             }
         }
         $result->permalink = get_permalink($result->ID);
         if (current_user_can('manage_options') || $result->post_author == $user_ID) {
             /**
              * featured image not null and should be in carousels array data
              */
             if (isset($args['featured_image']) && $args['featured_image'] != '') {
                 set_post_thumbnail($result->ID, $args['featured_image']);
             }
         }
     }
     return $result;
 }
 /**
  * Register taxonomies for this post type
  *
  * @param void
  * @return void
  * @since 1.0
  * @package JBTHEME
  * @category void
  * @author JACK BUI
  */
 public function register_taxonomy()
 {
     $labels = $this->jb_generate_tax_label('work category');
     $args = array('labels' => $labels, 'public' => true, 'show_in_nav_menus' => true, 'show_admin_column' => true, 'hierarchical' => true, 'show_tagcloud' => true, 'show_ui' => true, 'query_var' => true, 'rewrite' => array('slug' => jb_get_option('work_category_slug', 'work_category'), 'hierarchical' => jb_get_option('work_category_hierarchical', false)), 'capabilities' => array('manage_terms', 'edit_terms', 'delete_terms', 'assign_terms'));
     register_taxonomy('work_category', array('jb_work'), $args);
 }