Plugin Directory

Changeset 2980000


Ignore:
Timestamp:
10/17/2023 10:38:43 AM (17 months ago)
Author:
gilles66
Message:

tagging version 4.9 for CSRF fixing

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  
    1010 *
    1111 * 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' ) );
    1313 *
    1414 * @author Gilles Dumas <circusmind@gmail.com>
     
    2020
    2121class 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
    2333    /**
    2434     * Start up
    2535     */
    2636    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() );
    3342       
    3443        $this->text = new stdClass;
    3544       
    36         // Il faut paramétrer tout ceci
     45        // Il faut paramétrer ceci.
    3746        $this->text->tag_title  = 'Which Template File Options';
    3847        $this->text->menu_title = 'Which Template File';
     
    4150
    4251    /**
    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.
    4492    * @author Gilles Dumas <circusmind@gmail.com>
    4593    * @since 20150918
     
    4795    */
    4896    function add_plugin_page() {
    49        
    5097        $page_title = $this->text->tag_title;
    5198        $menu_title = $this->text->menu_title;
    5299        $capability = 'manage_options';
    53100        $menu_slug  = get_class();
    54         $function   = array($this, 'display_admin_page');
     101        $function   = array( $this, 'display_admin_page' );
    55102        $icon_url   = null;
    56103        $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 );
    59105    }
    60106
    61107    /**
    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.
    72109    * @author Gilles Dumas <circusmind@gmail.com>
    73110    * @since 20140729
    74111    */
    75     function display_my_admin_page() {
    76        
     112    function display_admin_page() {
     113
    77114        $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 );
    81118        ?>
    82        
     119
    83120        <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; ?>" />
    85122            <input type="hidden" name="page" value="<?php echo $_REQUEST['page']; ?>" />
    86123           
     
    89126            <?php
    90127            $checked = '';
    91             if ($wtf_option_1 == 'administrator' || $wtf_option_1 == false) {
     128            if ( $wtf_option_1 == 'administrator' || $wtf_option_1 == false ) {
    92129                $checked = 'checked';
    93130            }
     
    99136            <?php
    100137            $checked = '';
    101             if ($wtf_option_1 == 'all') {
     138            if ( $wtf_option_1 == 'all' ) {
    102139                $checked = 'checked';
    103140            }
     
    106143                <input type="radio" name="<?php echo _WTF_OPTION_1; ?>" value="all" <?php echo $checked; ?>>
    107144            </label><br /><br />
    108            
    109145            <input type="submit" class="button button-primary" />
    110            
    111146        </form>
    112147        <?php
    113148        parent::display_box_stop();
    114149    }
    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
    137151    /**
    138152     *
     
    144158        </div>
    145159        <?php
    146         // On ré-initialise ces deux variables
    147160        $this->notice_class = $this->notice_msg = '';
    148161    }
    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    
    159162   
    160163    /**
     
    162165    */
    163166    function set_links_footer() {
    164        
    165167        $this->links_footer = [];
    166        
    167         // // Lien vers page de tous les paiements
    168         // $this->links_footer[paiement_page::url()] = 'Les paiements';
    169 
    170         // // Lien vers page de tous les newsletters
    171         // $this->links_footer[newsletter_batch_page::url()] = 'Les newsletters';
    172 
    173168    }
    174169   
    175170}
    176171
    177 
    178 if( is_admin() )
    179     $wtf_admin_page = new wtf_admin_page;
    180 
    181    
     172if( is_admin() ) $wtf_admin_page = new wtf_admin_page;
  • TabularUnified which-template-file/tags/4.9/admin/class_page_admin.php

    r2273456 r2980000  
    33 * @author Gilles Dumas <circusmind@gmail.com>
    44 * @since   20140713
    5  * @version 20151028
     5 * @version 20231017
    66 */
    77 
     
    99
    1010    /**
    11      * Le nom de la classe fille qui a étendu celle-là
     11     * Le nom de la classe fille qui a étendu celle-là.
    1212     */
    1313    private $get_called_class;
     
    2727    /**
    2828     * 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'));
    3329     * @link http://www.php.net/manual/en/function.get-called-class.php
    3430     */
    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(
    3733                '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 );
    4339        }
    4440        return $url;
     
    5046    public function __destruct() {
    5147    }
    52    
    53    
     48
    5449    /**
    5550    * Le code html au début de toute box.
     
    5954    * @param $str String Le titre de la box
    6055    */
    61     function display_box_begin($box_title, $id=null) {
     56    function display_box_begin( $box_title, $id=null ) {
    6257        ?>
    6358        <div class="wrap">
    64            
    6559            <div id="icon-users" class="icon32"><br /></div>
    6660            <h2><?php echo $box_title; ?></h2>
     
    7367        <?php
    7468    }
    75    
    76    
     69
    7770    /**
    7871    * Le code html à la fin de toute box.
     
    8073    * @since 20140923
    8174    */
    82     function display_box_stop($nb_total_items=0) {
     75    function display_box_stop( $nb_total_items=0 ) {
    8376        ?></div><!--/.wrap--><?php
    8477        $this->display_links_footer();
    8578    }
    86    
    8779
    8880    /**
    89     * Affiche les liens de bas de page
     81    * Affiche les liens de bas de page.
    9082    */
    9183    function display_links_footer() {
    9284        $this->set_links_footer();
    9385       
    94         $count_links = count($this->links_footer);
    95         if ($count_links) {
     86        $count_links = count( $this->links_footer );
     87        if ( $count_links ) {
    9688            echo '<div id="links_footer_container" style="padding:10px 3px;margin:12px 3px;">';
    9789                $count = 0;
    98                 foreach ($this->links_footer as $href => $lbl) {
     90                foreach ( $this->links_footer as $href => $lbl ) {
    9991                    echo '<a href="'.$href.'">'.$lbl.'</a>';
    10092                    $count++;
    101                     if ($count != $count_links) {
     93                    if ( $count != $count_links ) {
    10294                        echo ' | ';
    10395                    }
     
    108100   
    109101    /**
    110      * Ajout de code dans le <head>
     102     * Ajout de code dans le <head>.
    111103     */
    112104    function admin_head() {
     
    116108                /* Pour corriger le 65px que wp met par défaut */
    117109                padding-bottom:0px;
    118                 /* parce que ! */
    119110                float:none;
    120111            }
     
    122113        <?php
    123114    }
    124    
    125 
    126    
    127115}
    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  
    44Requires at least: 3.3.0
    55Tested up to: 6.3.2
    6 Stable tag: 4.8.0
     6Stable tag: 4.9.0
    77Requires PHP: 5.6
    88License: GPLv2 or later
     
    5252== Changelog ==
    5353
     54= 4.9 =
     55* Fix CSRF issue
     56
    5457= 4.8 =
    5558* Compatibility with WP 6.3.2
     
    7982
    8083= 4.0 =
    81 * Compatibility with wp 4.4.2
     84* Compatibility with WP 4.4.2
    8285* Bug fix for multi-sites
    8386* Display the name of the template now for all users with admin bar (not just admninistrators)
     
    8588
    8689= 3.1 =
    87 * Compatibility with wp 4.1
     90* Compatibility with WP 4.1
    8891* Bug fix for child themes
    8992
     
    105108The color of the text is different regarding the origin of the template(the theme, a parent theme, or a plugin)
    106109(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+wordpress
    112 
    113 1. Upload the plugin folder 'which-template-file' to the '/wp-content/plugins/' directory
    114 2. Activate the plugin through the 'Plugins' menu in WordPress
    115 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 theme
    127 1. The template used owns to the parent theme
    128 1. The template used owns to a plugin
    129 
    130 
    131 == Changelog ==
    132 
    133 = 4.6 =
    134 * Compatibility with WP 5.8
    135 
    136 = 4.3.0 =
    137 * Compatibility with WP 4.8.2
    138 
    139 = 4.2.2 =
    140 * Compatibility with PHP < 5.3
    141 
    142 = 4.2.1 =
    143 * Correction of an error in updating the plugin on v 4.2.0
    144 
    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 fix
    155 
    156 = 4.0 =
    157 * Compatibility with wp 4.4.2
    158 * Bug fix for multi-sites
    159 * 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.1
    164 * Bug fix for child themes
    165 
    166 = 3.0 =
    167 * Add the "title" attribute to see the whole path to the template file
    168 
    169 = 2.1 =
    170 * Fixing a bug for non admin
    171 
    172 = 2.0 =
    173 * Now the template name is shown in the admin bar just for the admin
    174 
    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  
    22/*
    33Plugin 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.0
     4Description: 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 )
     5Version: 4.9.0
    66Author: Gilles Dumas
    77Author URI: https://gillesdumas.com
    88*/
    99
    10 define('_WTF_OPTION_1', 'wtf_tpl_name_visibility');
     10define( '_WTF_OPTION_1', 'wtf_tpl_name_visibility' );
    1111
    1212/**
    13  * Display the name of the template used in the admin bar
     13 * Displays the name of the template used in the admin bar.
    1414 *
    1515 * @author Gilles Dumas <circusmind@gmail.com>
     
    1919 * @return array()
    2020 */
    21 add_action('admin_bar_menu', 'gwp_my_admin_bar_menu', 9999);
    22 function gwp_my_admin_bar_menu($wp_admin_bar) {
     21add_action(  'admin_bar_menu', 'gwp_my_admin_bar_menu', 9999  );
     22function gwp_my_admin_bar_menu( $wp_admin_bar ) {
    2323   
    24     if (is_admin()) {
     24    if ( is_admin() ) {
    2525        return;
    2626    }
     
    2828    global $user_ID, $template;
    2929   
    30     if ($user_ID == 0) {
     30    if ( $user_ID == 0 ) {
    3131        return $template;
    3232    }
    3333   
    3434    global $current_user;
    35     if (is_null($current_user)) {
     35    if ( is_null( $current_user ) ) {
    3636        return;
    3737    }
    3838   
    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 ) {
    4141        // 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 ) ) {
    4343            return;
    4444        }
    4545    }
    4646   
    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, '/' ), '/' );
    4949    }
    5050    else {
     
    5353   
    5454    // 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 )
    5656   
    5757    $color = '';
    58     $theme = wp_get_theme();
    5958   
    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.
    6261        $color = 'hotpink';
    6362    }
    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.
    6665        $color = '#80ff00'; // green color
    6766        $gwp_my_template_file.= ' &larr; plugin';
    6867    }
    69     elseif (
     68    elseif ( 
    7069        get_stylesheet_directory_uri() != get_template_directory_uri()  &&
    71         strpos($template, get_stylesheet_directory()) === false
     70        strpos( $template, get_stylesheet_directory() ) === false
    7271    ) {
    73         // The template comes from the parent theme
     72        // The template comes from the parent theme.
    7473        $color = '#00bfff'; // blue color
    7574        $gwp_my_template_file.= ' &larr; parent theme';
    7675    }
    7776   
    78     $args = array(
     77    $args = array( 
    7978        'id'      => '_gwp_my_template_file',
    8079        'title'   => '<span id="gwp-wtf" style="color:'.$color.' !important;">'.$gwp_my_template_file.'</span>',
    81         'meta'   => array(
     80        'meta'   => array( 
    8281            'title' => $template,
    8382            'class' => 'class_gwp_my_template_file'
    8483        )
    8584    );
    86     $wp_admin_bar->add_menu($args);
     85    $wp_admin_bar->add_menu( $args );
    8786}
    8887
    8988
    9089/**
    91  * Add a link in the plugin option page
     90 * Adds a link in the plugin option page.
    9291 *
    9392 * @author Gilles Dumas <circusmind@gmail.com>
    9493 * @since  20160518
    9594 */
    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);
     95function 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 );
    9998}
    100 add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'wtf_add_action_links');
    101 
     99add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'wtf_add_action_links' );
    102100
    103101/**
    104102 * Admin page
    105103 */
    106 if (isset($_GET['page']) && ($_GET['page'] == 'wtf_admin_page')) {
    107     require('admin/class_page_admin.php');
    108     require('admin/add_menu_page.php');
     104if ( isset( $_GET['page'] ) && ( $_GET['page'] == 'wtf_admin_page' ) ) {
     105    require( 'admin/class_page_admin.php' );
     106    require( 'admin/add_menu_page.php' );
    109107}
    110 
    111108
    112109/**
     
    115112 * @since  20160229
    116113 */
    117 add_action('wp_head', 'which_template_file_style');
     114add_action( 'wp_head', 'which_template_file_style' );
    118115function which_template_file_style() {
    119116    ?>
    120     <style type="text/css">
     117    <style>
    121118        .class_gwp_my_template_file {
    122119            cursor:help;
     
    125122    <?php
    126123}
    127 
    128 
    129 
    130 
    131 
    132  
  • TabularUnified which-template-file/trunk/admin/add_menu_page.php

    r2273456 r2980000  
    1010 *
    1111 * 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' ) );
    1313 *
    1414 * @author Gilles Dumas <circusmind@gmail.com>
     
    2020
    2121class 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
    2333    /**
    2434     * Start up
    2535     */
    2636    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() );
    3342       
    3443        $this->text = new stdClass;
    3544       
    36         // Il faut paramétrer tout ceci
     45        // Il faut paramétrer ceci.
    3746        $this->text->tag_title  = 'Which Template File Options';
    3847        $this->text->menu_title = 'Which Template File';
     
    4150
    4251    /**
    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.
    4492    * @author Gilles Dumas <circusmind@gmail.com>
    4593    * @since 20150918
     
    4795    */
    4896    function add_plugin_page() {
    49        
    5097        $page_title = $this->text->tag_title;
    5198        $menu_title = $this->text->menu_title;
    5299        $capability = 'manage_options';
    53100        $menu_slug  = get_class();
    54         $function   = array($this, 'display_admin_page');
     101        $function   = array( $this, 'display_admin_page' );
    55102        $icon_url   = null;
    56103        $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 );
    59105    }
    60106
    61107    /**
    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.
    72109    * @author Gilles Dumas <circusmind@gmail.com>
    73110    * @since 20140729
    74111    */
    75     function display_my_admin_page() {
    76        
     112    function display_admin_page() {
     113
    77114        $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 );
    81118        ?>
    82        
     119
    83120        <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; ?>" />
    85122            <input type="hidden" name="page" value="<?php echo $_REQUEST['page']; ?>" />
    86123           
     
    89126            <?php
    90127            $checked = '';
    91             if ($wtf_option_1 == 'administrator' || $wtf_option_1 == false) {
     128            if ( $wtf_option_1 == 'administrator' || $wtf_option_1 == false ) {
    92129                $checked = 'checked';
    93130            }
     
    99136            <?php
    100137            $checked = '';
    101             if ($wtf_option_1 == 'all') {
     138            if ( $wtf_option_1 == 'all' ) {
    102139                $checked = 'checked';
    103140            }
     
    106143                <input type="radio" name="<?php echo _WTF_OPTION_1; ?>" value="all" <?php echo $checked; ?>>
    107144            </label><br /><br />
    108            
    109145            <input type="submit" class="button button-primary" />
    110            
    111146        </form>
    112147        <?php
    113148        parent::display_box_stop();
    114149    }
    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
    137151    /**
    138152     *
     
    144158        </div>
    145159        <?php
    146         // On ré-initialise ces deux variables
    147160        $this->notice_class = $this->notice_msg = '';
    148161    }
    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    
    159162   
    160163    /**
     
    162165    */
    163166    function set_links_footer() {
    164        
    165167        $this->links_footer = [];
    166        
    167         // // Lien vers page de tous les paiements
    168         // $this->links_footer[paiement_page::url()] = 'Les paiements';
    169 
    170         // // Lien vers page de tous les newsletters
    171         // $this->links_footer[newsletter_batch_page::url()] = 'Les newsletters';
    172 
    173168    }
    174169   
    175170}
    176171
    177 
    178 if( is_admin() )
    179     $wtf_admin_page = new wtf_admin_page;
    180 
    181    
     172if( is_admin() ) $wtf_admin_page = new wtf_admin_page;
  • TabularUnified which-template-file/trunk/admin/class_page_admin.php

    r2273456 r2980000  
    33 * @author Gilles Dumas <circusmind@gmail.com>
    44 * @since   20140713
    5  * @version 20151028
     5 * @version 20231017
    66 */
    77 
     
    99
    1010    /**
    11      * Le nom de la classe fille qui a étendu celle-là
     11     * Le nom de la classe fille qui a étendu celle-là.
    1212     */
    1313    private $get_called_class;
     
    2727    /**
    2828     * 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'));
    3329     * @link http://www.php.net/manual/en/function.get-called-class.php
    3430     */
    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(
    3733                '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 );
    4339        }
    4440        return $url;
     
    5046    public function __destruct() {
    5147    }
    52    
    53    
     48
    5449    /**
    5550    * Le code html au début de toute box.
     
    5954    * @param $str String Le titre de la box
    6055    */
    61     function display_box_begin($box_title, $id=null) {
     56    function display_box_begin( $box_title, $id=null ) {
    6257        ?>
    6358        <div class="wrap">
    64            
    6559            <div id="icon-users" class="icon32"><br /></div>
    6660            <h2><?php echo $box_title; ?></h2>
     
    7367        <?php
    7468    }
    75    
    76    
     69
    7770    /**
    7871    * Le code html à la fin de toute box.
     
    8073    * @since 20140923
    8174    */
    82     function display_box_stop($nb_total_items=0) {
     75    function display_box_stop( $nb_total_items=0 ) {
    8376        ?></div><!--/.wrap--><?php
    8477        $this->display_links_footer();
    8578    }
    86    
    8779
    8880    /**
    89     * Affiche les liens de bas de page
     81    * Affiche les liens de bas de page.
    9082    */
    9183    function display_links_footer() {
    9284        $this->set_links_footer();
    9385       
    94         $count_links = count($this->links_footer);
    95         if ($count_links) {
     86        $count_links = count( $this->links_footer );
     87        if ( $count_links ) {
    9688            echo '<div id="links_footer_container" style="padding:10px 3px;margin:12px 3px;">';
    9789                $count = 0;
    98                 foreach ($this->links_footer as $href => $lbl) {
     90                foreach ( $this->links_footer as $href => $lbl ) {
    9991                    echo '<a href="'.$href.'">'.$lbl.'</a>';
    10092                    $count++;
    101                     if ($count != $count_links) {
     93                    if ( $count != $count_links ) {
    10294                        echo ' | ';
    10395                    }
     
    108100   
    109101    /**
    110      * Ajout de code dans le <head>
     102     * Ajout de code dans le <head>.
    111103     */
    112104    function admin_head() {
     
    116108                /* Pour corriger le 65px que wp met par défaut */
    117109                padding-bottom:0px;
    118                 /* parce que ! */
    119110                float:none;
    120111            }
     
    122113        <?php
    123114    }
    124    
    125 
    126    
    127115}
    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  
    44Requires at least: 3.3.0
    55Tested up to: 6.3.2
    6 Stable tag: 4.8.0
     6Stable tag: 4.9.0
    77Requires PHP: 5.6
    88License: GPLv2 or later
     
    5252== Changelog ==
    5353
     54= 4.9 =
     55* Fix CSRF issue
     56
    5457= 4.8 =
    5558* Compatibility with WP 6.3.2
     
    7982
    8083= 4.0 =
    81 * Compatibility with wp 4.4.2
     84* Compatibility with WP 4.4.2
    8285* Bug fix for multi-sites
    8386* Display the name of the template now for all users with admin bar (not just admninistrators)
     
    8588
    8689= 3.1 =
    87 * Compatibility with wp 4.1
     90* Compatibility with WP 4.1
    8891* Bug fix for child themes
    8992
     
    105108The color of the text is different regarding the origin of the template(the theme, a parent theme, or a plugin)
    106109(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+wordpress
    112 
    113 1. Upload the plugin folder 'which-template-file' to the '/wp-content/plugins/' directory
    114 2. Activate the plugin through the 'Plugins' menu in WordPress
    115 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 theme
    127 1. The template used owns to the parent theme
    128 1. The template used owns to a plugin
    129 
    130 
    131 == Changelog ==
    132 
    133 = 4.6 =
    134 * Compatibility with WP 5.8
    135 
    136 = 4.3.0 =
    137 * Compatibility with WP 4.8.2
    138 
    139 = 4.2.2 =
    140 * Compatibility with PHP < 5.3
    141 
    142 = 4.2.1 =
    143 * Correction of an error in updating the plugin on v 4.2.0
    144 
    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 fix
    155 
    156 = 4.0 =
    157 * Compatibility with wp 4.4.2
    158 * Bug fix for multi-sites
    159 * 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.1
    164 * Bug fix for child themes
    165 
    166 = 3.0 =
    167 * Add the "title" attribute to see the whole path to the template file
    168 
    169 = 2.1 =
    170 * Fixing a bug for non admin
    171 
    172 = 2.0 =
    173 * Now the template name is shown in the admin bar just for the admin
    174 
    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  
    22/*
    33Plugin 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.0
     4Description: 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 )
     5Version: 4.9.0
    66Author: Gilles Dumas
    77Author URI: https://gillesdumas.com
    88*/
    99
    10 define('_WTF_OPTION_1', 'wtf_tpl_name_visibility');
     10define( '_WTF_OPTION_1', 'wtf_tpl_name_visibility' );
    1111
    1212/**
    13  * Display the name of the template used in the admin bar
     13 * Displays the name of the template used in the admin bar.
    1414 *
    1515 * @author Gilles Dumas <circusmind@gmail.com>
     
    1919 * @return array()
    2020 */
    21 add_action('admin_bar_menu', 'gwp_my_admin_bar_menu', 9999);
    22 function gwp_my_admin_bar_menu($wp_admin_bar) {
     21add_action(  'admin_bar_menu', 'gwp_my_admin_bar_menu', 9999  );
     22function gwp_my_admin_bar_menu( $wp_admin_bar ) {
    2323   
    24     if (is_admin()) {
     24    if ( is_admin() ) {
    2525        return;
    2626    }
     
    2828    global $user_ID, $template;
    2929   
    30     if ($user_ID == 0) {
     30    if ( $user_ID == 0 ) {
    3131        return $template;
    3232    }
    3333   
    3434    global $current_user;
    35     if (is_null($current_user)) {
     35    if ( is_null( $current_user ) ) {
    3636        return;
    3737    }
    3838   
    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 ) {
    4141        // 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 ) ) {
    4343            return;
    4444        }
    4545    }
    4646   
    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, '/' ), '/' );
    4949    }
    5050    else {
     
    5353   
    5454    // 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 )
    5656   
    5757    $color = '';
    58     $theme = wp_get_theme();
    5958   
    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.
    6261        $color = 'hotpink';
    6362    }
    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.
    6665        $color = '#80ff00'; // green color
    6766        $gwp_my_template_file.= ' &larr; plugin';
    6867    }
    69     elseif (
     68    elseif ( 
    7069        get_stylesheet_directory_uri() != get_template_directory_uri()  &&
    71         strpos($template, get_stylesheet_directory()) === false
     70        strpos( $template, get_stylesheet_directory() ) === false
    7271    ) {
    73         // The template comes from the parent theme
     72        // The template comes from the parent theme.
    7473        $color = '#00bfff'; // blue color
    7574        $gwp_my_template_file.= ' &larr; parent theme';
    7675    }
    7776   
    78     $args = array(
     77    $args = array( 
    7978        'id'      => '_gwp_my_template_file',
    8079        'title'   => '<span id="gwp-wtf" style="color:'.$color.' !important;">'.$gwp_my_template_file.'</span>',
    81         'meta'   => array(
     80        'meta'   => array( 
    8281            'title' => $template,
    8382            'class' => 'class_gwp_my_template_file'
    8483        )
    8584    );
    86     $wp_admin_bar->add_menu($args);
     85    $wp_admin_bar->add_menu( $args );
    8786}
    8887
    8988
    9089/**
    91  * Add a link in the plugin option page
     90 * Adds a link in the plugin option page.
    9291 *
    9392 * @author Gilles Dumas <circusmind@gmail.com>
    9493 * @since  20160518
    9594 */
    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);
     95function 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 );
    9998}
    100 add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'wtf_add_action_links');
    101 
     99add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'wtf_add_action_links' );
    102100
    103101/**
    104102 * Admin page
    105103 */
    106 if (isset($_GET['page']) && ($_GET['page'] == 'wtf_admin_page')) {
    107     require('admin/class_page_admin.php');
    108     require('admin/add_menu_page.php');
     104if ( isset( $_GET['page'] ) && ( $_GET['page'] == 'wtf_admin_page' ) ) {
     105    require( 'admin/class_page_admin.php' );
     106    require( 'admin/add_menu_page.php' );
    109107}
    110 
    111108
    112109/**
     
    115112 * @since  20160229
    116113 */
    117 add_action('wp_head', 'which_template_file_style');
     114add_action( 'wp_head', 'which_template_file_style' );
    118115function which_template_file_style() {
    119116    ?>
    120     <style type="text/css">
     117    <style>
    121118        .class_gwp_my_template_file {
    122119            cursor:help;
     
    125122    <?php
    126123}
    127 
    128 
    129 
    130 
    131 
    132  
Note: See TracChangeset for help on using the changeset viewer.