Changeset 1295313
- Timestamp:
- 11/26/2015 11:01:12 PM (10 years ago)
- Location:
- simple-frontend-template-display
- Files:
-
- 3 added
- 2 edited
-
tags/0.4.0 (added)
-
tags/0.4.0/readme.txt (added)
-
tags/0.4.0/simple-frontend-template-display.php (added)
-
trunk/readme.txt (modified) (3 diffs)
-
trunk/simple-frontend-template-display.php (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
simple-frontend-template-display/trunk/readme.txt
r1157017 r1295313 4 4 Tags: template name, admin bar, front end display, page template, development, view, page, toolbar 5 5 Requires at least: 3.4 6 Tested up to: 4. 2.27 Stable tag: 0. 3.16 Tested up to: 4.4 7 Stable tag: 0.4.0 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 15 15 Simple 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. 16 16 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. 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. 18 18 19 19 == Installation == 20 20 21 21 1. Upload `Simple Frontend Template Display` folder to the `/wp-content/plugins/` directory 22 2. Activate the plugin through the 'Plugins'menu in WordPress22 2. Activate the plugin through the `Plugins` menu in WordPress 23 23 3. Magic! On your pages, the name of the template will show on the toolbar on the fronted 24 24 … … 32 32 33 33 == Upgrade Notice == 34 35 = 0.4.0 = 36 Cleaned up to better adhere to WP code standards 37 Added documentation 38 Tested up to 4.3 34 39 35 40 = 0.3.1 = -
simple-frontend-template-display/trunk/simple-frontend-template-display.php
r994057 r1295313 1 1 <?php 2 2 defined( 'ABSPATH' ) OR exit; 3 3 4 /* 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 11 13 */ 12 14 … … 25 27 class PageTemplateDisplay{ 26 28 27 const VERSION = '0. 3.1';28 29 /** 30 * Constructor function.31 * 32 * @ access public33 * @since 0.1.029 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 * 34 36 * @return void 35 37 */ 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 42 45 43 46 /** 44 47 * Displays the template name on the admin menu bar 45 48 * 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. 48 53 */ 49 54 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() ){ 53 58 return; 59 } 54 60 55 61 // 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 item59 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() ) { 60 66 61 67 $wp_admin_bar->add_node( 62 68 array( 63 69 'id' => 'page_template', 64 'title' => __( 'Template: ' .$this->get_current_template_name(), 'page_template' ),70 'title' => __( 'Template: ' . $this->_get_current_template_name(), 'page-template-display' ), 65 71 'parent' => false, 66 72 'href' => false … … 68 74 ); 69 75 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 72 79 $wp_admin_bar->add_node( 73 80 array( 74 81 'id' => 'page_template_slug', 75 'title' => __( $this-> get_current_page_slug(), 'page_template' ),82 'title' => __( $this->_get_current_page_slug(), 'page-template-display' ), 76 83 'parent' => 'page_template', 77 84 'href' => false 78 85 ) 79 86 ); 80 } 87 88 } // end if _get_current_page_slug returns 81 89 82 90 } // end if template name is returned … … 86 94 } // end page_template_display() 87 95 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; 96 108 97 109 // get all templates 98 110 $all_templates = wp_get_theme()->get_page_templates(); 99 $returned = false; 111 112 // Loop through templates and match file w/ith a name 100 113 foreach ( $all_templates as $filename => $name ) { 101 114 102 115 // 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 ){ 104 117 return $name; 105 $returned = true;106 118 }; 107 119 108 120 } // end foreach 109 121 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(){ 125 139 global $wp_query; 126 140 127 141 $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. 137 155 */ 138 156 public function get_similar_pages( $wp_admin_bar ){ 139 157 global $wp_query; 140 158 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() ){ 142 161 return; 162 } 143 163 144 164 // if you're not in the admin backend & it's a page 145 if ( ( !is_admin() ) && ( is_page()) ){165 if ( !is_admin() && is_page() ){ 146 166 147 167 // define the variables 148 $template = $this-> get_current_page_slug();168 $template = $this->_get_current_page_slug(); 149 169 $post_id = $wp_query->post->ID; 150 170 $i = 1; … … 166 186 array( 167 187 'id' => 'similar_pages', 168 'title' => "<strong>" .__( 'Similar Pages:', 'page_template' )."</strong>",188 'title' => "<strong>" . __( 'Similar Pages:', 'page-template-display' )."</strong>", 169 189 'parent' => 'page_template', 170 190 'href' => false … … 180 200 $wp_admin_bar->add_node( 181 201 array( 182 'id' => 'similar_page_' .$i,202 'id' => 'similar_page_' . $i, 183 203 'title' => $page->post_title, 184 204 'parent' => 'page_template', 185 'href' => get_permalink( $page->ID)205 'href' => get_permalink( $page->ID ) 186 206 ) 187 207 ); … … 199 219 } // end get_similar_pages() 200 220 201 } // end PageTemplateDisplay 202 221 } // end Class 222 223 // Register class & call hooks 203 224 $display_template = new PageTemplateDisplay; 225 $display_template->_hooks(); 204 226 205 227 ?>
Note: See TracChangeset
for help on using the changeset viewer.