Plugin Directory

Changeset 1295313


Ignore:
Timestamp:
11/26/2015 11:01:12 PM (10 years ago)
Author:
mikeselander
Message:

Adding version 0.4.0

Location:
simple-frontend-template-display
Files:
3 added
2 edited

Legend:

Unmodified
Added
Removed
  • simple-frontend-template-display/trunk/readme.txt

    r1157017 r1295313  
    44Tags: template name, admin bar, front end display, page template, development, view, page, toolbar
    55Requires at least: 3.4
    6 Tested up to: 4.2.2
    7 Stable tag: 0.3.1
     6Tested up to: 4.4
     7Stable tag: 0.4.0
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    1515Simple Frontend Template Display will show the name of the template that you’re using in the toolbar when you’re in the frontend of your website. You can use this to keep track of the various templates you’re using without having to hop into the edit screen every time you want to check a template.
    1616
    17 All you have to do to get this working is to install the plugin. It will then automatically show up in the toolbar on all pages on your site. 
     17All you have to do to get this working is to install the plugin. It will then automatically show up in the toolbar on all pages on your site.
    1818
    1919== Installation ==
    2020
    21211. Upload `Simple Frontend Template Display` folder to the `/wp-content/plugins/` directory
    22 2. Activate the plugin through the 'Plugins' menu in WordPress
     222. Activate the plugin through the `Plugins` menu in WordPress
    23233. Magic! On your pages, the name of the template will show on the toolbar on the fronted
    2424
     
    3232
    3333== Upgrade Notice ==
     34
     35= 0.4.0 =
     36Cleaned up to better adhere to WP code standards
     37Added documentation
     38Tested up to 4.3
    3439
    3540= 0.3.1 =
  • simple-frontend-template-display/trunk/simple-frontend-template-display.php

    r994057 r1295313  
    11<?php
    22defined( 'ABSPATH' ) OR exit;
     3
    34/*
    4 Plugin Name: Simple Frontend Template Display
    5 Plugin URI: http://www.mikeselander.com/
    6 Description: Displays the current page template in the admin toolbar for quick & easy reference
    7 Version: 0.3.1
    8 Author: Mike Selander
    9 Author URI: http://www.mikeselander.com/
    10 License: GPL2
     5 * Plugin Name: Simple Frontend Template Display
     6 * Plugin URI: http://www.mikeselander.com/
     7 * Description: Displays the current page template in the admin toolbar for quick & easy reference
     8 * Version: 0.4.0
     9 * Author: Mike Selander
     10 * Text Domain: page-template-display
     11 * Author URI: http://www.mikeselander.com/
     12 * License: GPL2
    1113*/
    1214
     
    2527class PageTemplateDisplay{
    2628
    27     const VERSION = '0.3.1';
    28 
    29     /**
    30      * Constructor function.
    31      *
    32      * @access public
    33      * @since 0.1.0
     29    const VERSION = '0.4.0';
     30
     31    /**
     32     * Hook into appropriate actions in WordPress.
     33     *
     34     * @see add_action, $this->page_template_display, $this->get_similar_pages
     35     *
    3436     * @return void
    3537     */
    36     public function __construct(){
    37 
    38         add_action('admin_bar_menu', array( $this, "page_template_display" ), 500 );
    39         add_action('admin_bar_menu', array( $this, "get_similar_pages" ), 501 );
    40 
    41     } // end __construct()
     38    public function _hooks(){
     39
     40        add_action( 'admin_bar_menu', array( $this, "page_template_display" ), 500 );
     41        add_action( 'admin_bar_menu', array( $this, "get_similar_pages" ), 501 );
     42
     43    } // end _hooks()
     44
    4245
    4346    /**
    4447     * Displays the template name on the admin menu bar
    4548     *
    46      * @access public
    47      * @since 0.1.0
     49     * @see WP_Admin_Bar
     50     *
     51     * @param type $wp_admin_bar Object containining the Wp Admin Bar items.
     52     * @return void.
    4853     */
    4954    public function page_template_display( $wp_admin_bar ){
    50         //global $wp_admin_bar;
    51 
    52         if (!is_super_admin() || !is_admin_bar_showing() )
     55
     56        // Check for appropriate priveledges & that admin bar is running
     57        if ( !is_super_admin() || !is_admin_bar_showing() ){
    5358            return;
     59        }
    5460
    5561        // if you're not in the admin backend & it's a page
    56         if ( ( !is_admin() ) && ( is_page() ) ){
    57 
    58             // if get_current_template_name returns - set the menu item
    59             if ( $this->get_current_template_name() ) {
     62        if ( !is_admin() && is_page() ){
     63
     64            // if _get_current_template_name returns - set the menu item
     65            if ( $this->_get_current_template_name() ) {
    6066
    6167                $wp_admin_bar->add_node(
    6268                    array(
    6369                        'id'        => 'page_template',
    64                         'title'     => __( 'Template: '.$this->get_current_template_name(), 'page_template' ),
     70                        'title'     => __( 'Template: ' . $this->_get_current_template_name(), 'page-template-display' ),
    6571                        'parent'    => false,
    6672                        'href'      => false
     
    6874                );
    6975
    70                 // if get_current_page_slug returns - set the next menu item
    71                 if ( $this->get_current_page_slug() ) {
     76                // if _get_current_page_slug returns - set the next menu item
     77                if ( $this->_get_current_page_slug() ) {
     78
    7279                    $wp_admin_bar->add_node(
    7380                        array(
    7481                            'id'        => 'page_template_slug',
    75                             'title'     => __( $this->get_current_page_slug(), 'page_template' ),
     82                            'title'     => __( $this->_get_current_page_slug(), 'page-template-display' ),
    7683                            'parent'    => 'page_template',
    7784                            'href'      => false
    7885                        )
    7986                    );
    80                 }
     87
     88                } // end if _get_current_page_slug returns
    8189
    8290            } // end if template name is returned
     
    8694    } // end page_template_display()
    8795
    88     /**
    89      * Grabs the template name
    90      *
    91      * @access public
    92      * @since 0.1.0
    93      * @return Template name string
    94      */
    95     public function get_current_template_name(){
     96
     97    /**
     98     * Finds and returns the template name from all available page templates.
     99     *
     100     * @access private
     101     *
     102     * @see wp_get_theme()
     103     *
     104     * @return string Give name of template file used, "Default" if none.
     105     */
     106    private function _get_current_template_name(){
     107        $returned = false;
    96108
    97109        // get all templates
    98110        $all_templates = wp_get_theme()->get_page_templates();
    99         $returned = false;
     111
     112        // Loop through templates and match file w/ith a name
    100113        foreach ( $all_templates as $filename => $name ) {
    101114
    102115            // if the template matches one of the filenames, return
    103             if ( $this->get_current_page_slug() == $filename ){
     116            if ( $this->_get_current_page_slug() == $filename ){
    104117                return $name;
    105                 $returned = true;
    106118            };
    107119
    108120        } // end foreach
    109121
    110         // If no slug is returned, then return "Default"
    111         if ( $returned === false ){
    112             return "Default";
    113         }
    114 
    115     } // end get_current_template_name()
    116 
    117     /**
    118      * Grabs the template slug
    119      *
    120      * @access public
    121      * @since 0.2.0
    122      * @return Template slug string
    123      */
    124     public function get_current_page_slug(){
     122        // If no template is matched, then return "Default"
     123        return "Default";
     124
     125    } // end _get_current_template_name()
     126
     127
     128    /**
     129     * Finds the current page template slug used on a page.
     130     *
     131     * @access private
     132     *
     133     * @see get_page_template_slug
     134     * @global object $wp_query Description.
     135     *
     136     * @return string Slug/path of current page template used.
     137     */
     138    private function _get_current_page_slug(){
    125139        global $wp_query;
    126140
    127141        $post_id = $wp_query->post->ID;
    128         return get_page_template_slug($post_id);
    129     } // end get_current_page_slug()
    130 
    131     /**
    132      * Grabs other pages with the same template
    133      *
    134      * @access public
    135      * @since 0.3.0
    136      * @return list of pages with
     142        return get_page_template_slug( $post_id );
     143
     144    } // end _get_current_page_slug()
     145
     146
     147    /**
     148     * Identify and grab other pages using the same template
     149     *
     150     * @see WP_Admin_Bar, WP_Query
     151     * @global object $wp_query
     152     *
     153     * @param type $wp_admin_bar Object containining the Wp Admin Bar items.
     154     * @return void.
    137155     */
    138156    public function get_similar_pages( $wp_admin_bar ){
    139157        global $wp_query;
    140158
    141         if (!is_super_admin() || !is_admin_bar_showing() )
     159        // Check for appropriate priveledges & that admin bar is running
     160        if ( !is_super_admin() || !is_admin_bar_showing() ){
    142161            return;
     162        }
    143163
    144164        // if you're not in the admin backend & it's a page
    145         if ( ( !is_admin() ) && ( is_page() ) ){
     165        if ( !is_admin() && is_page() ){
    146166
    147167            // define the variables
    148             $template = $this->get_current_page_slug();
     168            $template = $this->_get_current_page_slug();
    149169            $post_id = $wp_query->post->ID;
    150170            $i = 1;
     
    166186                    array(
    167187                        'id'        => 'similar_pages',
    168                         'title'     => "<strong>".__( 'Similar Pages:', 'page_template' )."</strong>",
     188                        'title'     => "<strong>" . __( 'Similar Pages:', 'page-template-display' )."</strong>",
    169189                        'parent'    => 'page_template',
    170190                        'href'      => false
     
    180200                        $wp_admin_bar->add_node(
    181201                            array(
    182                                 'id'        => 'similar_page_'.$i,
     202                                'id'        => 'similar_page_' . $i,
    183203                                'title'     => $page->post_title,
    184204                                'parent'    => 'page_template',
    185                                 'href'      => get_permalink($page->ID)
     205                                'href'      => get_permalink( $page->ID )
    186206                            )
    187207                        );
     
    199219    } // end get_similar_pages()
    200220
    201 } // end PageTemplateDisplay
    202 
     221} // end Class
     222
     223// Register class & call hooks
    203224$display_template = new PageTemplateDisplay;
     225$display_template->_hooks();
    204226
    205227?>
Note: See TracChangeset for help on using the changeset viewer.