Ejemplo n.º 1
0
 /**
  * @since	1.0
  */
 function can_output()
 {
     $post_id = WPAlchemy_MetaBox::_get_post_id();
     if (!empty($this->exclude_template) or !empty($this->include_template)) {
         $template_file = get_post_meta($post_id, '_wp_page_template', TRUE);
     }
     if (!empty($this->exclude_category) or !empty($this->exclude_category_id) or !empty($this->include_category) or !empty($this->include_category_id)) {
         $categories = wp_get_post_categories($post_id, 'fields=all');
     }
     if (!empty($this->exclude_tag) or !empty($this->exclude_tag_id) or !empty($this->include_tag) or !empty($this->include_tag_id)) {
         $tags = wp_get_post_tags($post_id);
     }
     // processing order: "exclude" then "include"
     // processing order: "template" then "category" then "post"
     $can_output = TRUE;
     // include all
     if (!empty($this->exclude_template) or !empty($this->exclude_category_id) or !empty($this->exclude_category) or !empty($this->exclude_tag_id) or !empty($this->exclude_tag) or !empty($this->exclude_post_id) or !empty($this->include_template) or !empty($this->include_category_id) or !empty($this->include_category) or !empty($this->include_tag_id) or !empty($this->include_tag) or !empty($this->include_post_id)) {
         if (!empty($this->exclude_template)) {
             if (in_array($template_file, $this->exclude_template)) {
                 $can_output = FALSE;
             }
         }
         if (!empty($this->exclude_category_id)) {
             foreach ($categories as $cat) {
                 if (in_array($cat->term_id, $this->exclude_category_id)) {
                     $can_output = FALSE;
                     break;
                 }
             }
         }
         if (!empty($this->exclude_category)) {
             foreach ($categories as $cat) {
                 if (in_array($cat->slug, $this->exclude_category) or in_array($cat->name, $this->exclude_category)) {
                     $can_output = FALSE;
                     break;
                 }
             }
         }
         if (!empty($this->exclude_tag_id)) {
             foreach ($tags as $tag) {
                 if (in_array($tag->term_id, $this->exclude_tag_id)) {
                     $can_output = FALSE;
                     break;
                 }
             }
         }
         if (!empty($this->exclude_tag)) {
             foreach ($tags as $tag) {
                 if (in_array($tag->slug, $this->exclude_tag) or in_array($tag->name, $this->exclude_tag)) {
                     $can_output = FALSE;
                     break;
                 }
             }
         }
         if (!empty($this->exclude_post_id)) {
             if (in_array($post_id, $this->exclude_post_id)) {
                 $can_output = FALSE;
             }
         }
         // excludes are not set use "include only" mode
         if (empty($this->exclude_template) and empty($this->exclude_category_id) and empty($this->exclude_category) and empty($this->exclude_tag_id) and empty($this->exclude_tag) and empty($this->exclude_post_id)) {
             $can_output = FALSE;
         }
         if (!empty($this->include_template)) {
             if (in_array($template_file, $this->include_template)) {
                 $can_output = TRUE;
             }
         }
         if (!empty($this->include_category_id)) {
             foreach ($categories as $cat) {
                 if (in_array($cat->term_id, $this->include_category_id)) {
                     $can_output = TRUE;
                     break;
                 }
             }
         }
         if (!empty($this->include_category)) {
             foreach ($categories as $cat) {
                 if (in_array($cat->slug, $this->include_category) or in_array($cat->name, $this->include_category)) {
                     $can_output = TRUE;
                     break;
                 }
             }
         }
         if (!empty($this->include_tag_id)) {
             foreach ($tags as $tag) {
                 if (in_array($tag->term_id, $this->include_tag_id)) {
                     $can_output = TRUE;
                     break;
                 }
             }
         }
         if (!empty($this->include_tag)) {
             foreach ($tags as $tag) {
                 if (in_array($tag->slug, $this->include_tag) or in_array($tag->name, $this->include_tag)) {
                     $can_output = TRUE;
                     break;
                 }
             }
         }
         if (!empty($this->include_post_id)) {
             if (in_array($post_id, $this->include_post_id)) {
                 $can_output = TRUE;
             }
         }
     }
     $post_type = WPAlchemy_MetaBox::_get_current_post_type();
     if (isset($post_type) and !in_array($post_type, $this->types)) {
         $can_output = FALSE;
     }
     // filter: output (can_output)
     if ($this->has_filter('output')) {
         $can_output = $this->apply_filters('output', $post_id);
     }
     return $can_output;
 }
Ejemplo n.º 2
0
 /**
  * Used to check if creating or editing a post or page
  *
  * @static
  * @since	1.3.8
  * @access	private
  * @return	string "post" or "page"
  * @see		_is_post(), _is_page()
  */
 static function _is_post_or_page()
 {
     $post_type = WPAlchemy_MetaBox::_get_current_post_type();
     if (isset($post_type)) {
         if ('page' == $post_type) {
             return 'page';
         } else {
             return 'post';
         }
     }
     return NULL;
 }