/** * [taken from WPAlchemy Class by Dimas Begunoff] * Used to check for the current post type, works when creating or editing a * new post, page or custom post type. * * @static * @return string [custom_post_type], page or post */ public static function get_current_post_type() { if (!class_exists('WPAlchemy_MetaBox')) { require_once VP_FileSystem::instance()->resolve_path('includes', 'wpalchemy/MetaBox'); } $uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : NULL; if (isset($uri)) { $uri_parts = parse_url($uri); $file = basename($uri_parts['path']); if ($uri and in_array($file, array('post.php', 'post-new.php'))) { $post_id = WPAlchemy_MetaBox::_get_post_id(); $post_type = isset($_GET['post_type']) ? $_GET['post_type'] : NULL; $post_type = $post_id ? get_post_type($post_id) : $post_type; if (isset($post_type)) { return $post_type; } else { // because of the 'post.php' and 'post-new.php' checks above, we can default to 'post' return 'post'; } } } return NULL; }
/** * @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; }
/** * Used to check for the current post type, works when creating or editing a * new post, page or custom post type. * * @static * @since 1.4.6 * @return string [custom_post_type], page or post */ static function _get_current_post_type() { $uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : NULL; if (isset($uri)) { $uri_parts = parse_url($uri); $file = basename($uri_parts['path']); if ($uri and in_array($file, array('post.php', 'post-new.php'))) { $post_id = WPAlchemy_MetaBox::_get_post_id(); $post_type = isset($_GET['post_type']) ? $_GET['post_type'] : NULL; $post_type = $post_id ? get_post_type($post_id) : $post_type; if (isset($post_type)) { return $post_type; } else { // because of the 'post.php' and 'post-new.php' checks above, we can default to 'post' return 'post'; } } } return NULL; }