This plugin requires at least PHP 5.
'; } return; } class PostFormat_Filter { private $formats = array(); private $current = ''; private $supported_types = array(); public function __construct() { add_action( 'admin_init', array( $this, 'pff_admin_init' ), 2000 ); } public function pff_admin_init() { add_action( 'parse_query', array( $this, 'pff_parse_query' ) ); add_action( 'restrict_manage_posts', array( $this, 'pff_restrict_manage_posts' ) ); global $wp_post_types; foreach( $wp_post_types as $type => $type_object ) { if( !post_type_supports( $type, 'post-formats' ) ) continue; $this->supported_types[] = $type; } } public function pff_parse_query( $query ) { if( !$this->is_supported_type_listing() ) return; $this->formats = get_post_format_strings(); array_shift( $this->formats ); $this->formats = apply_filters( 'pff_post_formats', $this->formats ); if( !$this->is_set_format() ) return; $format = $this->get_format(); if( empty( $format ) ) return; $tax_group = array( 'taxonomy' => 'post_format', 'terms' => array( 'post-format-' . $format ), 'field' => 'slug', 'operator' => 'IN', 'include_children' => 1 ); set_query_var( 'tax_query', array( $tax_group ) ); } public function pff_restrict_manage_posts() { if( $this->is_supported_type_listing() ) $this->pff_postformat_dropdown(); } private function get_format() { if( !$this->is_set_format() ) return ''; foreach( $this->formats as $slug => $name ) { if( $slug != $_GET['post_format_filter'] ) continue; if( empty( $this->current ) ) $this->current = $slug; return $this->current; } return ''; } private function is_supported_type_listing() { global $pagenow, $post_type; if( 'edit.php' != $pagenow ) return false; if( !in_array( $post_type, $this->supported_types ) ) return false; return true; } private function is_set_format() { return (bool) ( isset( $_GET['post_format_filter'] ) ); } private function pff_postformat_dropdown() { ?>