Changeset 1335361
- Timestamp:
- 01/25/2016 09:02:18 AM (9 years ago)
- Location:
- display-template-name/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
display-template-name/trunk/display-template-name.php
r1195496 r1335361 3 3 Plugin Name: Display Template Name 4 4 Description: Displays the name of the template used by the currently displayed page in the admin bar or inside the pages. Plugins very useful for developing your blog. 5 Version: 1.7 5 Version: 1.7.1 6 6 Author: Aurélien Chappard 7 7 Author URI: http://www.deefuse.fr/ … … 10 10 */ 11 11 if( !class_exists( 'Display_template_name' ) ) { 12 13 14 15 16 17 18 19 20 21 22 23 24 $devOptions = get_option($this->adminOptionsName); 25 26 27 28 29 30 31 32 33 34 12 class Display_template_name { 13 var $adminOptionsName = "DisplayTemplateNameAdminOptions"; 14 15 public function __construct() { 16 load_plugin_textdomain('display-template-name', false, basename(dirname(__FILE__)).'/lang' ); 17 18 } 19 20 21 //Returns an array of admin options 22 function getAdminOptions() { 23 $displayTemplateNameAdminOptions = array('position' => 'TL'); 24 $devOptions = get_option($this->adminOptionsName); 25 if (!empty($devOptions)) { 26 foreach ($devOptions as $key => $option) 27 $displayTemplateNameAdminOptions[$key] = $option; 28 } 29 update_option($this->adminOptionsName, $displayTemplateNameAdminOptions); 30 return $displayTemplateNameAdminOptions; 31 } 32 33 function init() { 34 // add special cap 35 35 $admin_role = get_role("administrator"); 36 36 $admin_role->add_cap( 'view_template_name' ); 37 37 38 38 //get option 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 } 163 164 165 39 $this->getAdminOptions(); 40 } 41 42 43 function displayTplNameenqueue_my_styles() 44 { 45 wp_register_style( 'displayTPLNameStylesheet', plugins_url('stylesheet.css', __FILE__) ); 46 wp_enqueue_style( 'displayTPLNameStylesheet' ); 47 } 48 49 50 //Prints out the admin page 51 function printAdminPage() 52 { 53 $devOptions = $this->getAdminOptions(); 54 if (isset($_POST['update_displayTemplateNamePluginSettings'])) 55 { 56 if (isset($_POST['news_position'])) { 57 $devOptions['position'] = $_POST['news_position']; 58 } 59 60 update_option($this->adminOptionsName, $devOptions); 61 62 ?> 63 <div class="updated"><p><strong><?php _e("The position have been saved.", "display-template-name");?></strong></p></div> 64 <?php 65 } ?> 66 <div class=wrap> 67 <form method="post" action="<?php echo $_SERVER["REQUEST_URI"]; ?>"> 68 <h2>Display Template Name</h2> 69 <?php 70 $themes = wp_get_theme(); 71 72 $urlScreenShot = $themes->get_screenshot(); 73 if( empty($urlScreenShot) ) 74 { 75 $urlScreenShot = plugin_dir_url(__FILE__) . 'images/default.png'; 76 } 77 ?> 78 <p><?php _e("Select the position of the debug box.", "display-template-name") ?></p> 79 <div id="tablePreviewDisplayTplName"> 80 81 <label for="displatTplName_TL"> 82 <div class="macPreviewDebug"> 83 <img src="<?php echo $urlScreenShot;?>" width="201" class="preview" height="150"/> 84 <img src="<?php echo plugin_dir_url(__FILE__) . 'images/masque_tl.png';?>" class="maskDisplayTpl" /> 85 </div> 86 <input type="radio" id="displatTplName_TL" name="news_position" value="TL" <?php if ($devOptions['position'] == "TL") { echo 'checked="checked"'; }?> /> 87 <?php _e("Top left", "display-template-name") ?> 88 </label> 89 90 <label for="displatTplName_TR"> 91 <div class="macPreviewDebug"> 92 <img src="<?php echo $urlScreenShot;?>" width="201" class="preview" height="150"/> 93 <img src="<?php echo plugin_dir_url(__FILE__) . 'images/masque_tr.png';?>" class="maskDisplayTpl" /> 94 </div> 95 <input type="radio" id="displatTplName_TR" name="news_position" value="TR" <?php if ($devOptions['position'] == "TR") {echo 'checked="checked"'; }?>/> 96 <?php _e("Top right", "display-template-name") ?> 97 </label> 98 99 <label for="displatTplName_BL"> 100 <div class="macPreviewDebug"> 101 <img src="<?php echo $urlScreenShot;?>" width="201" class="preview" height="150"/> 102 <img src="<?php echo plugin_dir_url(__FILE__) . 'images/masque_bl.png';?>" class="maskDisplayTpl" /> 103 </div> 104 <input type="radio" id="displatTplName_BL" name="news_position" value="BL" <?php if ($devOptions['position'] == "BL") {echo 'checked="checked"'; }?>/> 105 <?php _e("Bottom left", "display-template-name") ?> 106 </label> 107 108 <label for="displatTplName_BR"> 109 <div class="macPreviewDebug"> 110 <img src="<?php echo $urlScreenShot;?>" width="201" class="preview" height="150"/> 111 <img src="<?php echo plugin_dir_url(__FILE__) . 'images/masque_br.png';?>" class="maskDisplayTpl" /> 112 </div> 113 <input type="radio" id="displatTplName_BR" name="news_position" value="BR" <?php if ($devOptions['position'] == "BR") {echo 'checked="checked"'; }?>/> 114 <?php _e("Bottom right", "display-template-name") ?> 115 </label> 116 </div> 117 <div class="clearBoth"></div> 118 <p><em> 119 <?php _e("If the toolbar is displayed when you visit the site, the template name will be displayed in it and the above parameter will not be considered.", "display-template-name") ?> 120 </em></p> 121 <div class="submit"> 122 <input type="submit" class="button-primary" name="update_displayTemplateNamePluginSettings" value="<?php _e('Update Settings', 'display-template-name') ?>" /> 123 </div> 124 </form> 125 </div> 126 <?php 127 }//End function printAdminPage() 128 129 130 /** 131 * Display the name on the top of the pages 132 */ 133 function displayTheTemplateName() 134 { 135 // Get the actual user 136 $actualUser = wp_get_current_user(); 137 if($actualUser->data != null) 138 { 139 // 140 $devOptions = $this->getAdminOptions(); 141 142 // Css position according to the showing admin bar 143 if( !is_admin_bar_showing() && current_user_can('view_template_name') ) 144 { 145 $top = "0px"; 146 switch ($devOptions['position']) 147 { 148 149 case 'BL' : 150 $stringCss = 'bottom:0px; left:0px;'; 151 break; 152 case 'BR' : 153 $stringCss = 'bottom:0px; right:0px;'; 154 break; 155 case 'TR' : 156 $stringCss = 'top:' . $top . '; right:0px;'; 157 break; 158 case 'TL' : 159 default : 160 $stringCss = 'top:' . $top . '; left:0px;'; 161 break; 162 } 163 ?> 164 <style type="text/css"> 165 #debug-display-template-name{ 166 166 font-size: 14px; 167 167 cursor: default; 168 168 position: fixed; 169 169 <?php echo $stringCss;?> 170 170 background: #333; 171 171 color: #FFF; … … 181 181 border-bottom:1px solid #000; 182 182 } 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 <?php 204 205 206 207 208 209 210 211 183 #debug-display-template-name a, #debug-display-template-name a:visited{ 184 color: #FFF; 185 cursor: default; 186 } 187 #debug-display-template-name p{margin-bottom:10px;} 188 #debug-display-template-name ul{ 189 list-style-type:disc; 190 padding-left:10px; 191 line-height:17px; 192 list-style-position:inside; 193 } 194 #debug-display-template-name ul li{ 195 margin-bottom:10px; 196 } 197 #debug-display-template-name ul li ul{ 198 list-style-type:square; 199 padding-left:15px; 200 } 201 #debug-display-template-name ul li ul li{margin-bottom:inherit;} 202 </style> 203 <?php 204 $templateInfos = $this->get_current_template(); 205 $child_template = $this->get_child_templates($templateInfos); 206 ?> 207 <div id="debug-display-template-name"> 208 <h6><?php _e('Current template:','display-template-name'); ?></h6> 209 <ul> 210 <li> 211 <a href="#" title="<?php echo $templateInfos; ?>" target="_blank"><?php echo basename($templateInfos); ?></a> 212 212 <?php if ( count($child_template > 0) ) : ?> 213 <ul>214 <?php foreach ($child_template as $tpl) : ?>215 <li><a title="<?php echo $tpl; ?>"><?php echo basename($tpl); ?></a></li>216 <?php endforeach ?>217 </ul>213 <ul> 214 <?php foreach ($child_template as $tpl) : ?> 215 <li><a title="<?php echo $tpl; ?>"><?php echo basename($tpl); ?></a></li> 216 <?php endforeach ?> 217 </ul> 218 218 <?php endif; ?> 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 */ 243 244 245 246 247 248 249 250 251 219 </li> 220 </ul> 221 </div> 222 <?php 223 } 224 } 225 } 226 227 228 /** 229 * Retrieve the current template name et save into a global variable current_theme_template 230 */ 231 232 function var_template_include( $t ) 233 { 234 // $GLOBALS['current_theme_template'] = basename($t); 235 $GLOBALS['current_theme_template'] = $t; 236 237 return $t; 238 } 239 240 /** 241 * Grab the global variable et return it 242 */ 243 function get_current_template( $echo = false ) 244 { 245 if( !isset( $GLOBALS['current_theme_template'] ) ) 246 return false; 247 if( $echo ) 248 echo $GLOBALS['current_theme_template']; 249 else 250 return $GLOBALS['current_theme_template']; 251 } 252 252 253 253 /** … … 289 289 } 290 290 291 292 293 $settings_link = '<a href="options-general.php?page=display-template-name.php">' . __('Settings', 'display-template-name') . '</a>'; 294 array_unshift($links, $settings_link); 295 296 291 function dispayTplName_settings_link($links) 292 { 293 $settings_link = '<a href="options-general.php?page=display-template-name.php">' . __('Settings', 'display-template-name') . '</a>'; 294 array_unshift($links, $settings_link); 295 return $links; 296 } 297 297 298 298 function custom_css_admin_bar(){ … … 310 310 } 311 311 312 313 314 315 316 312 function displayTplNameAdminBar() 313 { 314 if(!is_admin() && is_admin_bar_showing() && current_user_can('view_template_name') ){ 315 global $wp_admin_bar; 316 $templateInfos = $this->get_current_template(); 317 317 $child_template = $this->get_child_templates($templateInfos); 318 318 $wp_admin_bar->add_menu( array( 319 319 'parent' => false, // use 'false' for a root menu, or pass the ID of the parent menu 320 320 'id' => 'displayTemplateName', // link ID, defaults to a sanitized title value 321 'title' => '<span class="ab-icon"></span> '.__('Current template:','display-template-name') .' <b>'. basename($templateInfos) .'</b>', // link title321 'title' => '<span class="ab-icon"></span>', // link title 322 322 'meta' => array('title' => $templateInfos) // array of any of the following options: array( 'html' => '', 'class' => '', 'onclick' => '', target => '', title => '' ); 323 323 )); 324 $wp_admin_bar->add_menu( 325 array( 326 'parent' => 'displayTemplateName', // use 'false' for a root menu, or pass the ID of the parent menu 327 'id' => 'displayTemplateName-root', // link ID, defaults to a sanitized title value 328 'title' => basename($templateInfos), 329 'meta' => array('title' => $templateInfos) // array of any of the following options: array( 'html' => '', 'class' => '', 'onclick' => '', target => '', title => '' ); 330 331 ) 332 ); 324 333 if ( count($child_template > 0) ) { 325 334 $i = 0; … … 339 348 340 349 } 341 342 343 350 351 } 352 } 344 353 } 345 354 346 355 347 356 if (class_exists("Display_template_name")) { 348 357 $display_template_name_plugin = new Display_template_name(); 349 358 } 350 359 351 //Actions and Filters 360 //Actions and Filters 352 361 if (isset($display_template_name_plugin)) 353 362 { 354 355 356 357 358 359 363 register_activation_hook( __FILE__, array(&$display_template_name_plugin, 'init') ); 364 365 366 //Actions 367 add_action( 'wp_footer', array(&$display_template_name_plugin, 'displayTheTemplateName') ); 368 add_action('admin_menu', 'DisplaYTemplateName_ap'); 360 369 add_action('wp_head', array(&$display_template_name_plugin, 'custom_css_admin_bar' )); 361 362 363 364 365 366 $plugin = plugin_basename(__FILE__); 367 368 369 370 add_action( 'admin_init', array(&$display_template_name_plugin, 'displayTplNameenqueue_my_styles') ); 371 add_action( 'wp_before_admin_bar_render', array(&$display_template_name_plugin, 'displayTplNameAdminBar') ); 372 // Filter 373 add_filter( 'template_include', array(&$display_template_name_plugin,'var_template_include'), 1000 ); 374 375 $plugin = plugin_basename(__FILE__); 376 add_filter("plugin_action_links_$plugin", array(&$display_template_name_plugin,'dispayTplName_settings_link') ); 377 378 370 379 } 371 380 372 381 //Initialize the admin panel 373 382 if (!function_exists("DisplaYTemplateName_ap")) { 374 375 376 377 378 379 380 381 382 } 383 function DisplaYTemplateName_ap() { 384 global $display_template_name_plugin; 385 if (!isset($display_template_name_plugin)) { 386 return; 387 } 388 if (function_exists('add_options_page')) { 389 add_options_page('Display Template Name', 'Display Template Name', 'activate_plugins', basename(__FILE__), array(&$display_template_name_plugin, 'printAdminPage')); 390 } 391 } 383 392 } -
display-template-name/trunk/readme.txt
r1195524 r1335361 2 2 Tags: developpement, template 3 3 Requires at least: 3.0.0 4 Tested up to: 4. 2.25 Stable tag: 1.7 4 Tested up to: 4.4.1 5 Stable tag: 1.7.1 6 6 7 7 … … 24 24 25 25 == Changelog == 26 27 = 1.7.1 = 28 * Move main template name, in the submenu of admin bar 26 29 27 30 = 1.7 =
Note: See TracChangeset
for help on using the changeset viewer.