Plugin Directory

Changeset 2775642


Ignore:
Timestamp:
08/25/2022 04:08:59 PM (4 years ago)
Author:
onetarek
Message:

Adding Version 3.0

Location:
filter-page-by-template/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • filter-page-by-template/trunk/filter-page-by-template.php

    r2696282 r2775642  
    99*/
    1010
    11 define ( 'FPBT_EMBEDER_PLUGIN_DIR', dirname(__FILE__) ); // Plugin Directory
    12 define ( 'FPBT_EMBEDER_PLUGIN_URL', plugin_dir_url(__FILE__) ); // Plugin URL (for http requests)
     11define ( 'FILTER_PAGE_BY_TEMPLATE_PLUGIN_DIR', dirname(__FILE__) ); // Plugin Directory
     12define ( 'FILTER_PAGE_BY_TEMPLATE_PLUGIN_URL', plugin_dir_url(__FILE__) ); // Plugin URL (for http requests)
    1313
    14 class FilterPagesByTemplate {
     14class Filter_Page_By_Template {
    1515   
    16     public function __construct()
    17     {
    18         add_action( 'restrict_manage_posts', array( $this, 'filter_dropdown' ) );
    19         add_filter( 'request', array( $this, 'filter_post_list' ) );
    20        
    21         add_filter('manage_pages_columns', array( $this, 'post_list_columns_head'));
    22         add_action('manage_pages_custom_column', array( $this, 'post_list_columns_content' ), 10, 2);
     16    public function __construct() {
     17        if( $GLOBALS['pagenow'] == 'edit.php' ) {
     18            $post_type = $this->current_post_type();
     19            add_action( 'restrict_manage_posts', array( $this, 'filter_dropdown' ) );
     20            add_filter( 'request', array( $this, 'filter_post_list' ) );
     21            add_filter( "manage_{$post_type}_posts_columns", array( $this, 'post_list_columns_head') );
     22            add_action( "manage_{$post_type}_posts_custom_column", array( $this, 'post_list_columns_content' ), 10, 2 );
     23        }
    2324
    2425        add_action( 'init', array( $this , 'load_textdomain' ) );
    25 
    2626    }
    2727   
    28     public function filter_dropdown()
    29     {
     28    public function current_post_type() {
     29        return isset( $_GET['post_type'] ) ? $_GET['post_type'] : 'post';
     30    }
     31
     32    public function filter_dropdown() {
    3033        if ( $GLOBALS['pagenow'] === 'upload.php' ) {
    3134            return;
    3235        }
    33    
     36
     37        $post_type = $this->current_post_type();
    3438        $template = isset( $_GET['page_template_filter'] ) ? $_GET['page_template_filter'] : "all";
    3539        $default_title = apply_filters( 'default_page_template_title',  __( 'Default Template' ), 'meta-box' );
     
    3943            <option value="all_missing" style="color:red" <?php echo ( $template == 'all_missing' )? ' selected="selected" ' : "";?>><?php _e( 'All Missing Page Templates', 'filter-page-by-template' ) ?></option>
    4044            <option value="default" <?php echo ( $template == 'default' )? ' selected="selected" ' : "";?>><?php echo esc_html( $default_title ); ?></option>
    41             <?php page_template_dropdown($template); ?>
     45            <?php page_template_dropdown( $template, $post_type ); ?>
    4246        </select>
    4347        <?php   
    4448    }//end func
    4549   
    46     public function filter_post_list( $vars ){
     50    public function filter_post_list( $vars ) {
     51        if ( ! isset( $_GET['page_template_filter'] ) ) return $vars;
     52        $template = trim( $_GET['page_template_filter'] );
    4753
    48         if ( ! isset( $_GET['page_template_filter'] ) ) return $vars;
    49         $template = trim($_GET['page_template_filter']);
    50 
    51         $data = get_option("filter_page_by_template_data", array() );
     54        $data = get_option( "filter_page_by_template_data", array() );
    5255        $filter_used = isset( $data['filter_used'] ) ? intval( $data['filter_used'] ) : 0;
    5356        $filter_used ++;
    5457        $data['filter_used'] = $filter_used;
    55         update_option("filter_page_by_template_data", $data );
     58        update_option( "filter_page_by_template_data", $data );
    5659
    5760        if ( $template == "" || $template == 'all' ) return $vars;
    5861       
    59         if( $template == 'all_missing')
    60         {
     62        if( $template == 'all_missing') {
    6163            $templates = wp_get_theme()->get_page_templates( null, 'page' );
    62             $template_files = array_keys($templates);
     64            $template_files = array_keys( $templates );
    6365            $template_files[] = 'default';
    6466            $vars = array_merge(
     
    7476                )
    7577            );
    76         }
    77         else
    78         {
     78        } else {
    7979            $vars = array_merge(
    8080                $vars,
     
    9696
    9797    # Add new column to post list
    98     public function post_list_columns_head( $columns )
    99     {
     98    public function post_list_columns_head( $columns ) {
    10099        $columns['template'] = 'Template';
    101100        return $columns;
     
    103102     
    104103    #post list column content
    105     public function post_list_columns_content( $column_name, $post_id )
    106     {
    107         $post_type = 'page';
     104    public function post_list_columns_content( $column_name, $post_id ) {
     105        $post_type = $this->current_post_type();
    108106
    109         if($column_name == 'template')
    110         {
    111             $template = get_post_meta($post_id, "_wp_page_template" , true );
    112             if($template)
    113             {
    114                 if($template == 'default')
    115                 {
     107        if( $column_name == 'template' ) {
     108            $template = get_post_meta( $post_id, "_wp_page_template" , true );
     109            if( $template ) {
     110                if( $template == 'default' ) {
    116111                    $template_name = apply_filters( 'default_page_template_title',  __( 'Default Template' ), 'meta-box' );
    117112                    echo '<span title="' . esc_attr( __( 'Template file', 'filter-page-by-template' ) ) . ': page.php">'.$template_name.'</span>';
    118                 }
    119                 else
    120                 {
     113                } else {
    121114                    $templates = wp_get_theme()->get_page_templates( null, $post_type );
    122115
    123                     if( isset( $templates[ $template ] ) )
    124                     {
     116                    if( isset( $templates[ $template ] ) ) {
    125117                        echo '<span title="Template file: '.$template.'">'.$templates[ $template ].'</span>';
    126                     }
    127                     else
    128                     {
     118                    } else {
    129119                       
    130120                        echo '<span style="color:red" title="' . esc_attr( __( 'This template file does not exist', 'filter-page-by-template' ) ) . '">'.$template.'</span>';
     
    140130     * @return void
    141131     */
    142     public function load_textdomain(){
     132    public function load_textdomain() {
    143133        load_plugin_textdomain( 'filter-page-by-template', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
    144134    }
     
    147137}//end class
    148138
    149 if( is_admin() )
    150 {
    151    new FilterPagesByTemplate();
    152    include_once(FPBT_EMBEDER_PLUGIN_DIR."/includes/five_star_wp_rate_notice.php");
     139if( is_admin() ) {
     140   new Filter_Page_By_Template();
     141   include_once(FILTER_PAGE_BY_TEMPLATE_PLUGIN_DIR."/includes/five_star_wp_rate_notice.php");
    153142}
  • filter-page-by-template/trunk/includes/five_star_wp_rate_notice.php

    r2696273 r2775642  
    4343    function admin_enqueue_scripts()
    4444    {
    45         wp_enqueue_script('fpbt_rate_notice', FPBT_EMBEDER_PLUGIN_URL.'js/five_star_wp_rate_notice.js', array('jquery') );
     45        wp_enqueue_script('fpbt_rate_notice', FILTER_PAGE_BY_TEMPLATE_PLUGIN_URL.'js/five_star_wp_rate_notice.js', array('jquery') );
    4646    }
    4747
  • filter-page-by-template/trunk/readme.txt

    r2696282 r2775642  
    44Tags: Filter, Page List, Template Filter, Missing templates   
    55Requires at least: 3.8.0
    6 Tested up to: 5.9.2
    7 Stable tag: 2.2
     6Tested up to: 6.0.1
     7Stable tag: 3.0
    88License: GPLv2+
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    1717**Using this plugin you can do :**
    1818
    19  * Filter page list according to page template
    20  * See which page is using which template
    21  * See which page template is being used by which pages
    22  * See which pages are using missing templates
    23  * Know the PHP file name of templates
     19 * Filter page list according to page template.
     20 * See which page is using which template.
     21 * See which page template is being used by which pages.
     22 * See which pages are using missing templates.
     23 * Know the PHP file name of templates.
     24 * You can do the same things above for posts and any custom post type posts.
    2425
    2526== Installation ==
     
    4445
    4546== Changelog ==
     47= 3.0 (August 25, 2022) =
     48* Show appropriate templates dropdown list for posts and custom post types.
     49* Show template column for posts and custom post types.
     50
    4651= 2.2 (March 19, 2022) =
    4752* Fix plugin translation.
     
    7782
    7883== Upgrade Notice ==
     84= 3.0 (August 25, 2022) =
     85* Show appropriate templates dropdown list for posts and custom post types.
     86* Show template column for posts and custom post types.
     87
    7988= 2.2 (March 19, 2022) =
    8089* Fix plugin translation.
Note: See TracChangeset for help on using the changeset viewer.