Changeset 2980000
- Timestamp:
- 10/17/2023 10:38:43 AM (17 months ago)
- Location:
- which-template-file
- Files:
-
- 6 edited
- 3 copied
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified which-template-file/tags/4.9/admin/add_menu_page.php ¶
r2273456 r2980000 10 10 * 11 11 * Pour y ajouter des paramètres, les ajouter en param sous forme de array 12 * $url = parent::url( array('foo' => 'bar'));12 * $url = parent::url( array( 'foo' => 'bar' ) ); 13 13 * 14 14 * @author Gilles Dumas <circusmind@gmail.com> … … 20 20 21 21 class wtf_admin_page extends class_page_admin { 22 22 23 /* 24 * Nonce name. 25 * */ 26 private $nonce_name = 'wtf-nonce-2'; 27 28 /* 29 * Nonce value. 30 * */ 31 private $nonce_value; 32 23 33 /** 24 34 * Start up 25 35 */ 26 36 public function __construct() { 27 // die('wtf_admin_page __construct'); 28 29 add_action('admin_menu', array( $this, 'add_plugin_page')); 30 add_action('admin_init', array( $this, 'page_init')); 31 add_action('admin_head', array( $this, 'add_action_admin_head')); 32 parent::__construct(get_class()); 37 add_action( 'init', array( $this, 'init' ) ); 38 add_action( 'admin_init', array( $this, 'admin_init' ) ); 39 add_action( 'admin_head', array( $this, 'admin_head' ) ); 40 add_action( 'admin_menu', array( $this, 'add_plugin_page' ) ); 41 parent::__construct( get_class() ); 33 42 34 43 $this->text = new stdClass; 35 44 36 // Il faut paramétrer tout ceci45 // Il faut paramétrer ceci. 37 46 $this->text->tag_title = 'Which Template File Options'; 38 47 $this->text->menu_title = 'Which Template File'; … … 41 50 42 51 /** 43 * Ajout de la page 52 * Inits. 53 */ 54 public function init() { 55 $this->nonce_value = wp_create_nonce( $this->nonce_name ); 56 } 57 58 /** 59 * Les actions à effectuer au cas où l'utilisateur vienne de cliquer sur un lien avec des paramètres. 60 */ 61 public function admin_init() { 62 if ( isset( $_GET[_WTF_OPTION_1] ) ) { 63 if ( wp_verify_nonce( $_GET[$this->nonce_name], $this->nonce_name ) ) { 64 if ( $_GET[_WTF_OPTION_1] == 'administrator' || $_GET[_WTF_OPTION_1] == 'all' ) { 65 update_option( _WTF_OPTION_1, $_GET[_WTF_OPTION_1] ); 66 $this->notice_msg = 'Setting updated !'; 67 $this->notice_class = 'updated'; 68 } 69 else { 70 $this->notice_msg = 'Bad setting value !'; 71 $this->notice_class = 'error'; 72 } 73 add_action( 'admin_notices', array( $this, 'my_admin_notice' ) ); 74 } 75 else { 76 $this->notice_msg = 'Bad nonce value, try again !'; 77 $this->notice_class = 'error'; 78 add_action( 'admin_notices', array( $this, 'my_admin_notice' ) ); 79 } 80 } 81 } 82 83 /** 84 * Ajout de code dans le <head>. 85 */ 86 public function admin_head() { 87 parent::admin_head( get_class() ); 88 } 89 90 /** 91 * Ajout de la page. 44 92 * @author Gilles Dumas <circusmind@gmail.com> 45 93 * @since 20150918 … … 47 95 */ 48 96 function add_plugin_page() { 49 50 97 $page_title = $this->text->tag_title; 51 98 $menu_title = $this->text->menu_title; 52 99 $capability = 'manage_options'; 53 100 $menu_slug = get_class(); 54 $function = array( $this, 'display_admin_page');101 $function = array( $this, 'display_admin_page' ); 55 102 $icon_url = null; 56 103 $position = '9996'; 57 58 add_menu_page($page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position); 104 add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position ); 59 105 } 60 106 61 107 /** 62 * Options page callback 63 * @author Gilles Dumas <circusmind@gmail.com> 64 * @since 20150918 65 */ 66 function display_admin_page() { 67 $this->display_my_admin_page(); 68 } 69 70 /** 71 * 108 * Options page callback. 72 109 * @author Gilles Dumas <circusmind@gmail.com> 73 110 * @since 20140729 74 111 */ 75 function display_ my_admin_page() {76 112 function display_admin_page() { 113 77 114 $title = $this->text->page_h2; 78 parent::display_box_begin( $title, 'display_admin_page');79 80 $wtf_option_1 = get_option( _WTF_OPTION_1);115 parent::display_box_begin( $title, 'display_admin_page' ); 116 117 $wtf_option_1 = get_option( _WTF_OPTION_1 ); 81 118 ?> 82 119 83 120 <form name="newsletters-filter" id="newsletters-filter" method="get" action="?"> 84 < !-- For plugins, we also need to ensure that the form posts back to our current page -->121 <input type="hidden" name="<?php echo $this->nonce_name; ?>" value="<?php echo $this->nonce_value; ?>" /> 85 122 <input type="hidden" name="page" value="<?php echo $_REQUEST['page']; ?>" /> 86 123 … … 89 126 <?php 90 127 $checked = ''; 91 if ( $wtf_option_1 == 'administrator' || $wtf_option_1 == false) {128 if ( $wtf_option_1 == 'administrator' || $wtf_option_1 == false ) { 92 129 $checked = 'checked'; 93 130 } … … 99 136 <?php 100 137 $checked = ''; 101 if ( $wtf_option_1 == 'all') {138 if ( $wtf_option_1 == 'all' ) { 102 139 $checked = 'checked'; 103 140 } … … 106 143 <input type="radio" name="<?php echo _WTF_OPTION_1; ?>" value="all" <?php echo $checked; ?>> 107 144 </label><br /><br /> 108 109 145 <input type="submit" class="button button-primary" /> 110 111 146 </form> 112 147 <?php 113 148 parent::display_box_stop(); 114 149 } 115 116 117 /** 118 * Les actions à effectuer au cas où l'utilisateur vienne de cliquer sur un lien 119 * avec des paramètres. 120 */ 121 public function page_init() { 122 if (isset($_GET[_WTF_OPTION_1])) { 123 if ($_GET[_WTF_OPTION_1] == 'administrator' || $_GET[_WTF_OPTION_1] == 'all') { 124 update_option(_WTF_OPTION_1, $_GET[_WTF_OPTION_1]); 125 $this->notice_msg = 'Setting updated !'; 126 $this->notice_class = 'updated'; 127 } 128 else { 129 $this->notice_msg = 'Bad setting value !'; 130 $this->notice_class = 'error'; 131 } 132 add_action( 'admin_notices', array( $this, 'my_admin_notice' )); 133 } 134 } 135 136 150 137 151 /** 138 152 * … … 144 158 </div> 145 159 <?php 146 // On ré-initialise ces deux variables147 160 $this->notice_class = $this->notice_msg = ''; 148 161 } 149 150 151 /**152 * Ajout de code dans le <head>153 */154 public function add_action_admin_head() {155 parent::admin_head(get_class());156 }157 158 159 162 160 163 /** … … 162 165 */ 163 166 function set_links_footer() { 164 165 167 $this->links_footer = []; 166 167 // // Lien vers page de tous les paiements168 // $this->links_footer[paiement_page::url()] = 'Les paiements';169 170 // // Lien vers page de tous les newsletters171 // $this->links_footer[newsletter_batch_page::url()] = 'Les newsletters';172 173 168 } 174 169 175 170 } 176 171 177 178 if( is_admin() ) 179 $wtf_admin_page = new wtf_admin_page; 180 181 172 if( is_admin() ) $wtf_admin_page = new wtf_admin_page; -
TabularUnified which-template-file/tags/4.9/admin/class_page_admin.php ¶
r2273456 r2980000 3 3 * @author Gilles Dumas <circusmind@gmail.com> 4 4 * @since 20140713 5 * @version 20 1510285 * @version 20231017 6 6 */ 7 7 … … 9 9 10 10 /** 11 * Le nom de la classe fille qui a étendu celle-là 11 * Le nom de la classe fille qui a étendu celle-là. 12 12 */ 13 13 private $get_called_class; … … 27 27 /** 28 28 * Cette fonction renvoie l'url de cette page d'admin. 29 * Elle peut être appelée de n'importe où, notament de l'extérieur de cette classe.30 * Appelée de cette manière : newsletter_batch_page::url();31 * On peut aussi l'appeler en ajoutant des paramètres en faisant comme ça :32 * newsletter_batch_page::url(array('foo'=>'bar', 'foo2'=>'bar2'));33 29 * @link http://www.php.net/manual/en/function.get-called-class.php 34 30 */ 35 public static function url( $params=null) {36 $url = add_query_arg( array(31 public static function url( $params=null ) { 32 $url = add_query_arg( array( 37 33 'page' => 'wtf_admin_page' 38 ),39 admin_url( 'admin.php')40 );41 if ( !is_null($params)) {42 $url = add_query_arg( $params, $url);34 ), 35 admin_url( 'admin.php' ) 36 ); 37 if ( !is_null( $params ) ) { 38 $url = add_query_arg( $params, $url ); 43 39 } 44 40 return $url; … … 50 46 public function __destruct() { 51 47 } 52 53 48 54 49 /** 55 50 * Le code html au début de toute box. … … 59 54 * @param $str String Le titre de la box 60 55 */ 61 function display_box_begin( $box_title, $id=null) {56 function display_box_begin( $box_title, $id=null ) { 62 57 ?> 63 58 <div class="wrap"> 64 65 59 <div id="icon-users" class="icon32"><br /></div> 66 60 <h2><?php echo $box_title; ?></h2> … … 73 67 <?php 74 68 } 75 76 69 77 70 /** 78 71 * Le code html à la fin de toute box. … … 80 73 * @since 20140923 81 74 */ 82 function display_box_stop( $nb_total_items=0) {75 function display_box_stop( $nb_total_items=0 ) { 83 76 ?></div><!--/.wrap--><?php 84 77 $this->display_links_footer(); 85 78 } 86 87 79 88 80 /** 89 * Affiche les liens de bas de page 81 * Affiche les liens de bas de page. 90 82 */ 91 83 function display_links_footer() { 92 84 $this->set_links_footer(); 93 85 94 $count_links = count( $this->links_footer);95 if ( $count_links) {86 $count_links = count( $this->links_footer ); 87 if ( $count_links ) { 96 88 echo '<div id="links_footer_container" style="padding:10px 3px;margin:12px 3px;">'; 97 89 $count = 0; 98 foreach ( $this->links_footer as $href => $lbl) {90 foreach ( $this->links_footer as $href => $lbl ) { 99 91 echo '<a href="'.$href.'">'.$lbl.'</a>'; 100 92 $count++; 101 if ( $count != $count_links) {93 if ( $count != $count_links ) { 102 94 echo ' | '; 103 95 } … … 108 100 109 101 /** 110 * Ajout de code dans le <head> 102 * Ajout de code dans le <head>. 111 103 */ 112 104 function admin_head() { … … 116 108 /* Pour corriger le 65px que wp met par défaut */ 117 109 padding-bottom:0px; 118 /* parce que ! */119 110 float:none; 120 111 } … … 122 113 <?php 123 114 } 124 125 126 127 115 } 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 -
TabularUnified which-template-file/tags/4.9/readme.txt ¶
r2979822 r2980000 4 4 Requires at least: 3.3.0 5 5 Tested up to: 6.3.2 6 Stable tag: 4. 8.06 Stable tag: 4.9.0 7 7 Requires PHP: 5.6 8 8 License: GPLv2 or later … … 52 52 == Changelog == 53 53 54 = 4.9 = 55 * Fix CSRF issue 56 54 57 = 4.8 = 55 58 * Compatibility with WP 6.3.2 … … 79 82 80 83 = 4.0 = 81 * Compatibility with wp4.4.284 * Compatibility with WP 4.4.2 82 85 * Bug fix for multi-sites 83 86 * Display the name of the template now for all users with admin bar (not just admninistrators) … … 85 88 86 89 = 3.1 = 87 * Compatibility with wp4.190 * Compatibility with WP 4.1 88 91 * Bug fix for child themes 89 92 … … 105 108 The color of the text is different regarding the origin of the template(the theme, a parent theme, or a plugin) 106 109 (icon author :http://www.megaicons.net/iconspack-1096/45043/) 107 108 == Installation ==109 110 Installation process is exactly the same than other WordPress plugins.111 Check this link if you need help : https://www.google.fr/search?q=how+to+install+a+wordpress+plugin&oq=how+to+install+a+wordpress112 113 1. Upload the plugin folder 'which-template-file' to the '/wp-content/plugins/' directory114 2. Activate the plugin through the 'Plugins' menu in WordPress115 3. Smile ;-)116 117 118 == Frequently Asked Questions ==119 120 = Why would I need this plugin ? =121 122 Just usefull if you are a WordPress theme developer.123 124 == Screenshots ==125 126 1. The template used owns to your theme127 1. The template used owns to the parent theme128 1. The template used owns to a plugin129 130 131 == Changelog ==132 133 = 4.6 =134 * Compatibility with WP 5.8135 136 = 4.3.0 =137 * Compatibility with WP 4.8.2138 139 = 4.2.2 =140 * Compatibility with PHP < 5.3141 142 = 4.2.1 =143 * Correction of an error in updating the plugin on v 4.2.0144 145 = 4.2.0 =146 * Adding an option to chose if every logged user can see the template file in the admin-bar, or just the admnistrators of the website.147 (with administrator role)148 By default, just the administrators can.149 150 = 4.1.1 =151 * Admin fix (the template name was added in the admin bar in the back-office too. Sorry for this)152 153 = 4.1 =154 * Notice fix155 156 = 4.0 =157 * Compatibility with wp 4.4.2158 * Bug fix for multi-sites159 * Display the name of the template now for all users with admin bar (not just admninistrators)160 * Different colors for the text regarding the origin of the template(the theme, a parent theme, or a plugin)161 162 = 3.1 =163 * Compatibility with wp 4.1164 * Bug fix for child themes165 166 = 3.0 =167 * Add the "title" attribute to see the whole path to the template file168 169 = 2.1 =170 * Fixing a bug for non admin171 172 = 2.0 =173 * Now the template name is shown in the admin bar just for the admin174 175 = 1.4 =176 * Small css change (adding !important to the color of the text)177 178 = 1.0 =179 * The first version -
TabularUnified which-template-file/tags/4.9/which-template-file.php ¶
r2979822 r2980000 2 2 /* 3 3 Plugin Name: Which Template File 4 Description: Plugin for developers. Display in the admin bar, the name of the template ( PHP file) for this page. Display with different colors if the template owns to the current theme, the theme parent, or a plugin. An option page allows to chose if every logged user car see the template file in the admin-bar, or just the admnistrators of the website. (with "administrator" role)5 Version: 4. 8.04 Description: Plugin for developers. Display in the admin bar, the name of the template ( PHP file ) for this page. Display with different colors if the template owns to the current theme, the theme parent, or a plugin. An option page allows to chose if every logged user car see the template file in the admin-bar, or just the admnistrators of the website. ( with "administrator" role ) 5 Version: 4.9.0 6 6 Author: Gilles Dumas 7 7 Author URI: https://gillesdumas.com 8 8 */ 9 9 10 define( '_WTF_OPTION_1', 'wtf_tpl_name_visibility');10 define( '_WTF_OPTION_1', 'wtf_tpl_name_visibility' ); 11 11 12 12 /** 13 * Display the name of the template used in the admin bar13 * Displays the name of the template used in the admin bar. 14 14 * 15 15 * @author Gilles Dumas <circusmind@gmail.com> … … 19 19 * @return array() 20 20 */ 21 add_action( 'admin_bar_menu', 'gwp_my_admin_bar_menu', 9999);22 function gwp_my_admin_bar_menu( $wp_admin_bar) {21 add_action( 'admin_bar_menu', 'gwp_my_admin_bar_menu', 9999 ); 22 function gwp_my_admin_bar_menu( $wp_admin_bar ) { 23 23 24 if ( is_admin()) {24 if ( is_admin() ) { 25 25 return; 26 26 } … … 28 28 global $user_ID, $template; 29 29 30 if ( $user_ID == 0) {30 if ( $user_ID == 0 ) { 31 31 return $template; 32 32 } 33 33 34 34 global $current_user; 35 if ( is_null($current_user)) {35 if ( is_null( $current_user ) ) { 36 36 return; 37 37 } 38 38 39 $wtf_option_1 = get_option( _WTF_OPTION_1);40 if ( $wtf_option_1 == 'administrator' || $wtf_option_1 == false) {39 $wtf_option_1 = get_option( _WTF_OPTION_1 ); 40 if ( $wtf_option_1 == 'administrator' || $wtf_option_1 == false ) { 41 41 // Alors le user connecté doit être administrator pour que l'on affiche le nom du tpl dans l'admin bar 42 if ( !in_array('administrator', $current_user->roles)) {42 if ( ! in_array( 'administrator', $current_user->roles ) ) { 43 43 return; 44 44 } 45 45 } 46 46 47 if ( strpos($template, '/') !== false) {48 $gwp_my_template_file = ltrim( strrchr($template, '/'), '/');47 if ( strpos( $template, '/' ) !== false ) { 48 $gwp_my_template_file = ltrim( strrchr( $template, '/' ), '/' ); 49 49 } 50 50 else { … … 53 53 54 54 // Check if the template is from the current theme, or from something else 55 // ( a plugin, a parent theme)55 // ( a plugin, a parent theme ) 56 56 57 57 $color = ''; 58 $theme = wp_get_theme();59 58 60 if ( strpos($template, get_stylesheet_directory()) !== false) {61 // The template comes from the current theme 59 if ( strpos( $template, get_stylesheet_directory() ) !== false ) { 60 // The template comes from the current theme. 62 61 $color = 'hotpink'; 63 62 } 64 elseif ( strpos($template, WP_PLUGIN_DIR) !== false) {65 // The template comes from a plugin 63 elseif ( strpos( $template, WP_PLUGIN_DIR ) !== false ) { 64 // The template comes from a plugin. 66 65 $color = '#80ff00'; // green color 67 66 $gwp_my_template_file.= ' ← plugin'; 68 67 } 69 elseif ( 68 elseif ( 70 69 get_stylesheet_directory_uri() != get_template_directory_uri() && 71 strpos( $template, get_stylesheet_directory()) === false70 strpos( $template, get_stylesheet_directory() ) === false 72 71 ) { 73 // The template comes from the parent theme 72 // The template comes from the parent theme. 74 73 $color = '#00bfff'; // blue color 75 74 $gwp_my_template_file.= ' ← parent theme'; 76 75 } 77 76 78 $args = array( 77 $args = array( 79 78 'id' => '_gwp_my_template_file', 80 79 'title' => '<span id="gwp-wtf" style="color:'.$color.' !important;">'.$gwp_my_template_file.'</span>', 81 'meta' => array( 80 'meta' => array( 82 81 'title' => $template, 83 82 'class' => 'class_gwp_my_template_file' 84 83 ) 85 84 ); 86 $wp_admin_bar->add_menu( $args);85 $wp_admin_bar->add_menu( $args ); 87 86 } 88 87 89 88 90 89 /** 91 * Add a link in the plugin option page90 * Adds a link in the plugin option page. 92 91 * 93 92 * @author Gilles Dumas <circusmind@gmail.com> 94 93 * @since 20160518 95 94 */ 96 function wtf_add_action_links ( $links) {97 $mylinks = array( '<a href="' . admin_url( 'admin.php?page=wtf_admin_page' ) . '">Settings</a>');98 return array_merge( $links, $mylinks);95 function wtf_add_action_links ( $links ) { 96 $mylinks = array( '<a href="' . admin_url( 'admin.php?page=wtf_admin_page' ) . '">Settings</a>' ); 97 return array_merge( $links, $mylinks ); 99 98 } 100 add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'wtf_add_action_links'); 101 99 add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'wtf_add_action_links' ); 102 100 103 101 /** 104 102 * Admin page 105 103 */ 106 if ( isset($_GET['page']) && ($_GET['page'] == 'wtf_admin_page')) {107 require( 'admin/class_page_admin.php');108 require( 'admin/add_menu_page.php');104 if ( isset( $_GET['page'] ) && ( $_GET['page'] == 'wtf_admin_page' ) ) { 105 require( 'admin/class_page_admin.php' ); 106 require( 'admin/add_menu_page.php' ); 109 107 } 110 111 108 112 109 /** … … 115 112 * @since 20160229 116 113 */ 117 add_action( 'wp_head', 'which_template_file_style');114 add_action( 'wp_head', 'which_template_file_style' ); 118 115 function which_template_file_style() { 119 116 ?> 120 <style type="text/css">117 <style> 121 118 .class_gwp_my_template_file { 122 119 cursor:help; … … 125 122 <?php 126 123 } 127 128 129 130 131 132 -
TabularUnified which-template-file/trunk/admin/add_menu_page.php ¶
r2273456 r2980000 10 10 * 11 11 * Pour y ajouter des paramètres, les ajouter en param sous forme de array 12 * $url = parent::url( array('foo' => 'bar'));12 * $url = parent::url( array( 'foo' => 'bar' ) ); 13 13 * 14 14 * @author Gilles Dumas <circusmind@gmail.com> … … 20 20 21 21 class wtf_admin_page extends class_page_admin { 22 22 23 /* 24 * Nonce name. 25 * */ 26 private $nonce_name = 'wtf-nonce-2'; 27 28 /* 29 * Nonce value. 30 * */ 31 private $nonce_value; 32 23 33 /** 24 34 * Start up 25 35 */ 26 36 public function __construct() { 27 // die('wtf_admin_page __construct'); 28 29 add_action('admin_menu', array( $this, 'add_plugin_page')); 30 add_action('admin_init', array( $this, 'page_init')); 31 add_action('admin_head', array( $this, 'add_action_admin_head')); 32 parent::__construct(get_class()); 37 add_action( 'init', array( $this, 'init' ) ); 38 add_action( 'admin_init', array( $this, 'admin_init' ) ); 39 add_action( 'admin_head', array( $this, 'admin_head' ) ); 40 add_action( 'admin_menu', array( $this, 'add_plugin_page' ) ); 41 parent::__construct( get_class() ); 33 42 34 43 $this->text = new stdClass; 35 44 36 // Il faut paramétrer tout ceci45 // Il faut paramétrer ceci. 37 46 $this->text->tag_title = 'Which Template File Options'; 38 47 $this->text->menu_title = 'Which Template File'; … … 41 50 42 51 /** 43 * Ajout de la page 52 * Inits. 53 */ 54 public function init() { 55 $this->nonce_value = wp_create_nonce( $this->nonce_name ); 56 } 57 58 /** 59 * Les actions à effectuer au cas où l'utilisateur vienne de cliquer sur un lien avec des paramètres. 60 */ 61 public function admin_init() { 62 if ( isset( $_GET[_WTF_OPTION_1] ) ) { 63 if ( wp_verify_nonce( $_GET[$this->nonce_name], $this->nonce_name ) ) { 64 if ( $_GET[_WTF_OPTION_1] == 'administrator' || $_GET[_WTF_OPTION_1] == 'all' ) { 65 update_option( _WTF_OPTION_1, $_GET[_WTF_OPTION_1] ); 66 $this->notice_msg = 'Setting updated !'; 67 $this->notice_class = 'updated'; 68 } 69 else { 70 $this->notice_msg = 'Bad setting value !'; 71 $this->notice_class = 'error'; 72 } 73 add_action( 'admin_notices', array( $this, 'my_admin_notice' ) ); 74 } 75 else { 76 $this->notice_msg = 'Bad nonce value, try again !'; 77 $this->notice_class = 'error'; 78 add_action( 'admin_notices', array( $this, 'my_admin_notice' ) ); 79 } 80 } 81 } 82 83 /** 84 * Ajout de code dans le <head>. 85 */ 86 public function admin_head() { 87 parent::admin_head( get_class() ); 88 } 89 90 /** 91 * Ajout de la page. 44 92 * @author Gilles Dumas <circusmind@gmail.com> 45 93 * @since 20150918 … … 47 95 */ 48 96 function add_plugin_page() { 49 50 97 $page_title = $this->text->tag_title; 51 98 $menu_title = $this->text->menu_title; 52 99 $capability = 'manage_options'; 53 100 $menu_slug = get_class(); 54 $function = array( $this, 'display_admin_page');101 $function = array( $this, 'display_admin_page' ); 55 102 $icon_url = null; 56 103 $position = '9996'; 57 58 add_menu_page($page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position); 104 add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position ); 59 105 } 60 106 61 107 /** 62 * Options page callback 63 * @author Gilles Dumas <circusmind@gmail.com> 64 * @since 20150918 65 */ 66 function display_admin_page() { 67 $this->display_my_admin_page(); 68 } 69 70 /** 71 * 108 * Options page callback. 72 109 * @author Gilles Dumas <circusmind@gmail.com> 73 110 * @since 20140729 74 111 */ 75 function display_ my_admin_page() {76 112 function display_admin_page() { 113 77 114 $title = $this->text->page_h2; 78 parent::display_box_begin( $title, 'display_admin_page');79 80 $wtf_option_1 = get_option( _WTF_OPTION_1);115 parent::display_box_begin( $title, 'display_admin_page' ); 116 117 $wtf_option_1 = get_option( _WTF_OPTION_1 ); 81 118 ?> 82 119 83 120 <form name="newsletters-filter" id="newsletters-filter" method="get" action="?"> 84 < !-- For plugins, we also need to ensure that the form posts back to our current page -->121 <input type="hidden" name="<?php echo $this->nonce_name; ?>" value="<?php echo $this->nonce_value; ?>" /> 85 122 <input type="hidden" name="page" value="<?php echo $_REQUEST['page']; ?>" /> 86 123 … … 89 126 <?php 90 127 $checked = ''; 91 if ( $wtf_option_1 == 'administrator' || $wtf_option_1 == false) {128 if ( $wtf_option_1 == 'administrator' || $wtf_option_1 == false ) { 92 129 $checked = 'checked'; 93 130 } … … 99 136 <?php 100 137 $checked = ''; 101 if ( $wtf_option_1 == 'all') {138 if ( $wtf_option_1 == 'all' ) { 102 139 $checked = 'checked'; 103 140 } … … 106 143 <input type="radio" name="<?php echo _WTF_OPTION_1; ?>" value="all" <?php echo $checked; ?>> 107 144 </label><br /><br /> 108 109 145 <input type="submit" class="button button-primary" /> 110 111 146 </form> 112 147 <?php 113 148 parent::display_box_stop(); 114 149 } 115 116 117 /** 118 * Les actions à effectuer au cas où l'utilisateur vienne de cliquer sur un lien 119 * avec des paramètres. 120 */ 121 public function page_init() { 122 if (isset($_GET[_WTF_OPTION_1])) { 123 if ($_GET[_WTF_OPTION_1] == 'administrator' || $_GET[_WTF_OPTION_1] == 'all') { 124 update_option(_WTF_OPTION_1, $_GET[_WTF_OPTION_1]); 125 $this->notice_msg = 'Setting updated !'; 126 $this->notice_class = 'updated'; 127 } 128 else { 129 $this->notice_msg = 'Bad setting value !'; 130 $this->notice_class = 'error'; 131 } 132 add_action( 'admin_notices', array( $this, 'my_admin_notice' )); 133 } 134 } 135 136 150 137 151 /** 138 152 * … … 144 158 </div> 145 159 <?php 146 // On ré-initialise ces deux variables147 160 $this->notice_class = $this->notice_msg = ''; 148 161 } 149 150 151 /**152 * Ajout de code dans le <head>153 */154 public function add_action_admin_head() {155 parent::admin_head(get_class());156 }157 158 159 162 160 163 /** … … 162 165 */ 163 166 function set_links_footer() { 164 165 167 $this->links_footer = []; 166 167 // // Lien vers page de tous les paiements168 // $this->links_footer[paiement_page::url()] = 'Les paiements';169 170 // // Lien vers page de tous les newsletters171 // $this->links_footer[newsletter_batch_page::url()] = 'Les newsletters';172 173 168 } 174 169 175 170 } 176 171 177 178 if( is_admin() ) 179 $wtf_admin_page = new wtf_admin_page; 180 181 172 if( is_admin() ) $wtf_admin_page = new wtf_admin_page; -
TabularUnified which-template-file/trunk/admin/class_page_admin.php ¶
r2273456 r2980000 3 3 * @author Gilles Dumas <circusmind@gmail.com> 4 4 * @since 20140713 5 * @version 20 1510285 * @version 20231017 6 6 */ 7 7 … … 9 9 10 10 /** 11 * Le nom de la classe fille qui a étendu celle-là 11 * Le nom de la classe fille qui a étendu celle-là. 12 12 */ 13 13 private $get_called_class; … … 27 27 /** 28 28 * Cette fonction renvoie l'url de cette page d'admin. 29 * Elle peut être appelée de n'importe où, notament de l'extérieur de cette classe.30 * Appelée de cette manière : newsletter_batch_page::url();31 * On peut aussi l'appeler en ajoutant des paramètres en faisant comme ça :32 * newsletter_batch_page::url(array('foo'=>'bar', 'foo2'=>'bar2'));33 29 * @link http://www.php.net/manual/en/function.get-called-class.php 34 30 */ 35 public static function url( $params=null) {36 $url = add_query_arg( array(31 public static function url( $params=null ) { 32 $url = add_query_arg( array( 37 33 'page' => 'wtf_admin_page' 38 ),39 admin_url( 'admin.php')40 );41 if ( !is_null($params)) {42 $url = add_query_arg( $params, $url);34 ), 35 admin_url( 'admin.php' ) 36 ); 37 if ( !is_null( $params ) ) { 38 $url = add_query_arg( $params, $url ); 43 39 } 44 40 return $url; … … 50 46 public function __destruct() { 51 47 } 52 53 48 54 49 /** 55 50 * Le code html au début de toute box. … … 59 54 * @param $str String Le titre de la box 60 55 */ 61 function display_box_begin( $box_title, $id=null) {56 function display_box_begin( $box_title, $id=null ) { 62 57 ?> 63 58 <div class="wrap"> 64 65 59 <div id="icon-users" class="icon32"><br /></div> 66 60 <h2><?php echo $box_title; ?></h2> … … 73 67 <?php 74 68 } 75 76 69 77 70 /** 78 71 * Le code html à la fin de toute box. … … 80 73 * @since 20140923 81 74 */ 82 function display_box_stop( $nb_total_items=0) {75 function display_box_stop( $nb_total_items=0 ) { 83 76 ?></div><!--/.wrap--><?php 84 77 $this->display_links_footer(); 85 78 } 86 87 79 88 80 /** 89 * Affiche les liens de bas de page 81 * Affiche les liens de bas de page. 90 82 */ 91 83 function display_links_footer() { 92 84 $this->set_links_footer(); 93 85 94 $count_links = count( $this->links_footer);95 if ( $count_links) {86 $count_links = count( $this->links_footer ); 87 if ( $count_links ) { 96 88 echo '<div id="links_footer_container" style="padding:10px 3px;margin:12px 3px;">'; 97 89 $count = 0; 98 foreach ( $this->links_footer as $href => $lbl) {90 foreach ( $this->links_footer as $href => $lbl ) { 99 91 echo '<a href="'.$href.'">'.$lbl.'</a>'; 100 92 $count++; 101 if ( $count != $count_links) {93 if ( $count != $count_links ) { 102 94 echo ' | '; 103 95 } … … 108 100 109 101 /** 110 * Ajout de code dans le <head> 102 * Ajout de code dans le <head>. 111 103 */ 112 104 function admin_head() { … … 116 108 /* Pour corriger le 65px que wp met par défaut */ 117 109 padding-bottom:0px; 118 /* parce que ! */119 110 float:none; 120 111 } … … 122 113 <?php 123 114 } 124 125 126 127 115 } 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 -
TabularUnified which-template-file/trunk/readme.txt ¶
r2979822 r2980000 4 4 Requires at least: 3.3.0 5 5 Tested up to: 6.3.2 6 Stable tag: 4. 8.06 Stable tag: 4.9.0 7 7 Requires PHP: 5.6 8 8 License: GPLv2 or later … … 52 52 == Changelog == 53 53 54 = 4.9 = 55 * Fix CSRF issue 56 54 57 = 4.8 = 55 58 * Compatibility with WP 6.3.2 … … 79 82 80 83 = 4.0 = 81 * Compatibility with wp4.4.284 * Compatibility with WP 4.4.2 82 85 * Bug fix for multi-sites 83 86 * Display the name of the template now for all users with admin bar (not just admninistrators) … … 85 88 86 89 = 3.1 = 87 * Compatibility with wp4.190 * Compatibility with WP 4.1 88 91 * Bug fix for child themes 89 92 … … 105 108 The color of the text is different regarding the origin of the template(the theme, a parent theme, or a plugin) 106 109 (icon author :http://www.megaicons.net/iconspack-1096/45043/) 107 108 == Installation ==109 110 Installation process is exactly the same than other WordPress plugins.111 Check this link if you need help : https://www.google.fr/search?q=how+to+install+a+wordpress+plugin&oq=how+to+install+a+wordpress112 113 1. Upload the plugin folder 'which-template-file' to the '/wp-content/plugins/' directory114 2. Activate the plugin through the 'Plugins' menu in WordPress115 3. Smile ;-)116 117 118 == Frequently Asked Questions ==119 120 = Why would I need this plugin ? =121 122 Just usefull if you are a WordPress theme developer.123 124 == Screenshots ==125 126 1. The template used owns to your theme127 1. The template used owns to the parent theme128 1. The template used owns to a plugin129 130 131 == Changelog ==132 133 = 4.6 =134 * Compatibility with WP 5.8135 136 = 4.3.0 =137 * Compatibility with WP 4.8.2138 139 = 4.2.2 =140 * Compatibility with PHP < 5.3141 142 = 4.2.1 =143 * Correction of an error in updating the plugin on v 4.2.0144 145 = 4.2.0 =146 * Adding an option to chose if every logged user can see the template file in the admin-bar, or just the admnistrators of the website.147 (with administrator role)148 By default, just the administrators can.149 150 = 4.1.1 =151 * Admin fix (the template name was added in the admin bar in the back-office too. Sorry for this)152 153 = 4.1 =154 * Notice fix155 156 = 4.0 =157 * Compatibility with wp 4.4.2158 * Bug fix for multi-sites159 * Display the name of the template now for all users with admin bar (not just admninistrators)160 * Different colors for the text regarding the origin of the template(the theme, a parent theme, or a plugin)161 162 = 3.1 =163 * Compatibility with wp 4.1164 * Bug fix for child themes165 166 = 3.0 =167 * Add the "title" attribute to see the whole path to the template file168 169 = 2.1 =170 * Fixing a bug for non admin171 172 = 2.0 =173 * Now the template name is shown in the admin bar just for the admin174 175 = 1.4 =176 * Small css change (adding !important to the color of the text)177 178 = 1.0 =179 * The first version -
TabularUnified which-template-file/trunk/which-template-file.php ¶
r2979822 r2980000 2 2 /* 3 3 Plugin Name: Which Template File 4 Description: Plugin for developers. Display in the admin bar, the name of the template ( PHP file) for this page. Display with different colors if the template owns to the current theme, the theme parent, or a plugin. An option page allows to chose if every logged user car see the template file in the admin-bar, or just the admnistrators of the website. (with "administrator" role)5 Version: 4. 8.04 Description: Plugin for developers. Display in the admin bar, the name of the template ( PHP file ) for this page. Display with different colors if the template owns to the current theme, the theme parent, or a plugin. An option page allows to chose if every logged user car see the template file in the admin-bar, or just the admnistrators of the website. ( with "administrator" role ) 5 Version: 4.9.0 6 6 Author: Gilles Dumas 7 7 Author URI: https://gillesdumas.com 8 8 */ 9 9 10 define( '_WTF_OPTION_1', 'wtf_tpl_name_visibility');10 define( '_WTF_OPTION_1', 'wtf_tpl_name_visibility' ); 11 11 12 12 /** 13 * Display the name of the template used in the admin bar13 * Displays the name of the template used in the admin bar. 14 14 * 15 15 * @author Gilles Dumas <circusmind@gmail.com> … … 19 19 * @return array() 20 20 */ 21 add_action( 'admin_bar_menu', 'gwp_my_admin_bar_menu', 9999);22 function gwp_my_admin_bar_menu( $wp_admin_bar) {21 add_action( 'admin_bar_menu', 'gwp_my_admin_bar_menu', 9999 ); 22 function gwp_my_admin_bar_menu( $wp_admin_bar ) { 23 23 24 if ( is_admin()) {24 if ( is_admin() ) { 25 25 return; 26 26 } … … 28 28 global $user_ID, $template; 29 29 30 if ( $user_ID == 0) {30 if ( $user_ID == 0 ) { 31 31 return $template; 32 32 } 33 33 34 34 global $current_user; 35 if ( is_null($current_user)) {35 if ( is_null( $current_user ) ) { 36 36 return; 37 37 } 38 38 39 $wtf_option_1 = get_option( _WTF_OPTION_1);40 if ( $wtf_option_1 == 'administrator' || $wtf_option_1 == false) {39 $wtf_option_1 = get_option( _WTF_OPTION_1 ); 40 if ( $wtf_option_1 == 'administrator' || $wtf_option_1 == false ) { 41 41 // Alors le user connecté doit être administrator pour que l'on affiche le nom du tpl dans l'admin bar 42 if ( !in_array('administrator', $current_user->roles)) {42 if ( ! in_array( 'administrator', $current_user->roles ) ) { 43 43 return; 44 44 } 45 45 } 46 46 47 if ( strpos($template, '/') !== false) {48 $gwp_my_template_file = ltrim( strrchr($template, '/'), '/');47 if ( strpos( $template, '/' ) !== false ) { 48 $gwp_my_template_file = ltrim( strrchr( $template, '/' ), '/' ); 49 49 } 50 50 else { … … 53 53 54 54 // Check if the template is from the current theme, or from something else 55 // ( a plugin, a parent theme)55 // ( a plugin, a parent theme ) 56 56 57 57 $color = ''; 58 $theme = wp_get_theme();59 58 60 if ( strpos($template, get_stylesheet_directory()) !== false) {61 // The template comes from the current theme 59 if ( strpos( $template, get_stylesheet_directory() ) !== false ) { 60 // The template comes from the current theme. 62 61 $color = 'hotpink'; 63 62 } 64 elseif ( strpos($template, WP_PLUGIN_DIR) !== false) {65 // The template comes from a plugin 63 elseif ( strpos( $template, WP_PLUGIN_DIR ) !== false ) { 64 // The template comes from a plugin. 66 65 $color = '#80ff00'; // green color 67 66 $gwp_my_template_file.= ' ← plugin'; 68 67 } 69 elseif ( 68 elseif ( 70 69 get_stylesheet_directory_uri() != get_template_directory_uri() && 71 strpos( $template, get_stylesheet_directory()) === false70 strpos( $template, get_stylesheet_directory() ) === false 72 71 ) { 73 // The template comes from the parent theme 72 // The template comes from the parent theme. 74 73 $color = '#00bfff'; // blue color 75 74 $gwp_my_template_file.= ' ← parent theme'; 76 75 } 77 76 78 $args = array( 77 $args = array( 79 78 'id' => '_gwp_my_template_file', 80 79 'title' => '<span id="gwp-wtf" style="color:'.$color.' !important;">'.$gwp_my_template_file.'</span>', 81 'meta' => array( 80 'meta' => array( 82 81 'title' => $template, 83 82 'class' => 'class_gwp_my_template_file' 84 83 ) 85 84 ); 86 $wp_admin_bar->add_menu( $args);85 $wp_admin_bar->add_menu( $args ); 87 86 } 88 87 89 88 90 89 /** 91 * Add a link in the plugin option page90 * Adds a link in the plugin option page. 92 91 * 93 92 * @author Gilles Dumas <circusmind@gmail.com> 94 93 * @since 20160518 95 94 */ 96 function wtf_add_action_links ( $links) {97 $mylinks = array( '<a href="' . admin_url( 'admin.php?page=wtf_admin_page' ) . '">Settings</a>');98 return array_merge( $links, $mylinks);95 function wtf_add_action_links ( $links ) { 96 $mylinks = array( '<a href="' . admin_url( 'admin.php?page=wtf_admin_page' ) . '">Settings</a>' ); 97 return array_merge( $links, $mylinks ); 99 98 } 100 add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'wtf_add_action_links'); 101 99 add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'wtf_add_action_links' ); 102 100 103 101 /** 104 102 * Admin page 105 103 */ 106 if ( isset($_GET['page']) && ($_GET['page'] == 'wtf_admin_page')) {107 require( 'admin/class_page_admin.php');108 require( 'admin/add_menu_page.php');104 if ( isset( $_GET['page'] ) && ( $_GET['page'] == 'wtf_admin_page' ) ) { 105 require( 'admin/class_page_admin.php' ); 106 require( 'admin/add_menu_page.php' ); 109 107 } 110 111 108 112 109 /** … … 115 112 * @since 20160229 116 113 */ 117 add_action( 'wp_head', 'which_template_file_style');114 add_action( 'wp_head', 'which_template_file_style' ); 118 115 function which_template_file_style() { 119 116 ?> 120 <style type="text/css">117 <style> 121 118 .class_gwp_my_template_file { 122 119 cursor:help; … … 125 122 <?php 126 123 } 127 128 129 130 131 132
Note: See TracChangeset
for help on using the changeset viewer.