Plugin Directory

Changeset 201945


Ignore:
Timestamp:
02/04/2010 09:22:13 PM (16 years ago)
Author:
silasco
Message:

Adoption of new plugin settings functions

Location:
wp-pear-debug/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • wp-pear-debug/trunk/readme.txt

    r194508 r201945  
    55Requires at least: 2.8
    66Tested up to: 2.9.1
    7 Stable tag: 1.4.2
     7Stable tag: 1.4.5
    88
    99This plugin incorporates the pear php_debug library into wordpress.
     
    1717
    1818Please feel free to discuss it [here:](http://www.communitymodder.com/Released-wordpress-plugins/wp-pear-debug-wordpress-plugin.html) Plugin Home.
     19
     20If you have used this plugin and it works please rate it and report the version of wordpress and the plugin version you are using.
    1921
    2022Unfortunately php_debug only works in php5 so this plugin will only work in php5. Also, the plugin makes use of php5 specific code in its own class.
  • wp-pear-debug/trunk/wp-pear-debug.php

    r194373 r201945  
    66 * Author: Community Modder
    77 * Plugin URI: http://www.communitymodder.com
    8  * Version: 1.4.2
     8 * Version: 1.4.5
    99 * =======================================================================
    1010 */
     
    3535    const WPD_GUEST_ROLE = 'guest';
    3636    const WPD_STATUS = 'status';
    37    
    38     //shortcut for getting and setting distinct option name                     
    39     protected static function opt($suffix)
    40     {
    41         return self::WPD_PREFIX.$suffix;
    42     }
     37    const WPD_OPTIONS_GROUP = 'wp_pear_debug_options';
     38    const WPD_SETTING_ROLE = 2;
     39    const WPD_SETTING_MAIN = 1;
     40
     41    //Array for options handler. Define static options and their types
     42    //WIll be useful in dynamic options builder in possibly 1.5
     43    protected static $settings = array(
     44                                    array('type'=> self::WPD_SETTING_ROLE,'key'=> self::WPD_GUEST_ROLE),
     45                                    array('type'=> self::WPD_SETTING_MAIN,'key'=> self::WPD_STATUS)
     46                                    ); 
    4347   
    4448    //return the path to the plugin folder
     
    165169        //add options page to the admin menu
    166170        add_action('admin_menu',array('wp_pear_debug','admin'));
     171        //Register settings for options page
     172        add_action('admin_init',array('wp_pear_debug','settings'));
    167173    }
    168174    //not using globals
     
    180186        //This method should gather most if not all the query info
    181187        //Use define('SAVEQUERIES',true); in wp-config.php for best results
    182         self::processQueries();
     188        self::_processQueries();
    183189        //Render debug information
    184190        self::get()->display();
     
    197203   
    198204    //add all available query data to debug
    199     private static function processQueries()
     205    private static function _processQueries()
    200206    {
    201207        foreach(self::getDB()->queries as $query)
     
    206212   
    207213    //May have to test for array result but doubtful
    208     private static function queryCaller($callers)
     214    public static function queryCaller($callers)
    209215    {
    210216        $aCallers = explode(',',$callers);
     
    213219   
    214220    //Database data in millionseconds. Change to seconds before output to user.
    215     private static function toSeconds($milli)
     221    public static function toSeconds($milli)
    216222    {
    217223        return $milli * 1000;
     
    221227    //This call provides a standard access method for the database
    222228    //May be a long way away but we might see the end of global wpdb
    223     private static function getDB()
     229    public static function getDB()
    224230    {
    225231        global $wpdb;
     
    317323        add_options_page('Debugger Options', 'Debugger', 10, '/wp-pear-debug/'.basename(__FILE__),array('wp_pear_debug','options'));
    318324    }
     325   
     326
     327   
     328    //shortcut for getting and setting distinct option name                     
     329    protected static function opt($suffix)
     330    {
     331        return self::WPD_PREFIX.$suffix;
     332    }
     333   
     334    //convert array of option names to add prefix: destinct name
     335    private static function opt_item(&$item,$key)
     336    {
     337        $item = array('type' => $item['type'], 'key' => self::opt($item['key']), 'def' => $item['key']);
     338    }
     339       
     340    //Return list of settings for plugin
     341    private static function getSettingFeilds()
     342    {
     343        //get our static settings
     344        $aSettings = self::$settings;
     345        //generate dynamic user role settings
     346        foreach(get_option(self::getDB()->prefix . 'user_roles')  as $key => $value)
     347        {
     348            $aSettings[] = array('type'=> self::WPD_SETTING_ROLE, 'key' => $key);
     349        }
     350        //add wpd prefix to each setting name
     351        array_walk($aSettings,array('wp_pear_debug','opt_item'));
     352       
     353        //Here you go. All the settings we need to update
     354        return $aSettings;
     355       
     356    }
     357   
     358    public static function settings()
     359    {
     360        foreach(self::getSettingFeilds() as $settingsField)
     361        {
     362            //Leave intval callback for now as all settings are integers
     363            register_setting( self::WPD_OPTIONS_GROUP , $settingsField['key'], 'intval' );
     364        }   
     365    }
    319366
    320367//Do I hear multi language? ha!
     
    325372<div class=wrap>
    326373  <form method="post" action="options.php">
    327   <?php wp_nonce_field('update-options'); ?>
    328374
    329375    <h3>Debugger Settings</h3>
     
    343389<div class="postbox">
    344390<table>
    345 <tr>
    346 <td  >
    347 
    348  <strong>Guests</strong>
    349 </td>
    350 <td>
    351 <select name="<?php echo self::opt(self::WPD_GUEST_ROLE); ?>">
    352 <option value="<?php echo self::WPD_STATUS_DISABLE;?>" <?php  if(get_option(self::opt(self::WPD_GUEST_ROLE)) == self::WPD_STATUS_DISABLE) echo "selected"; ?> >Disable</option>
    353 <option  value="<?php echo self::WPD_STATUS_FRONT;?>" <?php  if(get_option(self::opt(self::WPD_GUEST_ROLE)) == self::WPD_STATUS_FRONT) echo "selected"; ?> >Front End Only</option>
    354 </select>
    355 </td>
    356 </tr>
     391
    357392<?php
    358 $sKeys = self::opt(self::WPD_GUEST_ROLE).",".self::opt(self::WPD_STATUS);
    359 foreach(get_option(self::getDB()->prefix . 'user_roles')  as $key => $value)
    360 {
    361     //define the role key for options
    362     $role_opt = self::opt($key);
     393
     394foreach(self::getSettingFeilds() as $sField):
     395
     396        //we only want settings for roles
     397        if($sField['type'] != self::WPD_SETTING_ROLE):
     398            continue;
     399        endif; 
     400       
     401           
    363402    ?>
    364403    <tr>
    365404    <td>
    366 <strong><?php echo ucfirst($key); ?></strong>   
     405<strong><?php echo ucfirst($sField['def']); ?></strong>
    367406</td>
    368407<td>
    369 <select name="<?php echo $role_opt ?>">
    370 <option value="<?php echo self::WPD_STATUS_DISABLE;?>" <?php  if(get_option($role_opt)== self::WPD_STATUS_DISABLE) echo "selected"; ?> >Disable</option>   
    371 <option value="<?php echo self::WPD_STATUS_FRONT;?>" <?php  if(get_option($role_opt)== self::WPD_STATUS_FRONT) echo "selected"; ?> >Front End Only</option>
    372 <option value="<?php echo self::WPD_STATUS_ADMIN;?>" <?php  if(get_option($role_opt)== self::WPD_STATUS_ADMIN) echo "selected"; ?> >Admin Only</option>
    373 <option value="<?php echo self::WPD_STATUS_BOTH;?>" <?php  if(get_option($role_opt)== self::WPD_STATUS_BOTH) echo "selected"; ?> >Admin & Front End</option>   
     408<select name="<?php echo $sField['key']; ?>">   
     409<option value="<?php echo self::WPD_STATUS_DISABLE;?>" <?php  if(get_option($sField['key'])== self::WPD_STATUS_DISABLE) echo "selected"; ?> >Disable</option>   
     410<option value="<?php echo self::WPD_STATUS_FRONT;?>" <?php  if(get_option($sField['key'])== self::WPD_STATUS_FRONT) echo "selected"; ?> >Front End Only</option>   
     411
     412<? if($sField['def'] != self::WPD_GUEST_ROLE): ?>
     413<option value="<?php echo self::WPD_STATUS_ADMIN;?>" <?php  if(get_option($sField['key'])== self::WPD_STATUS_ADMIN) echo "selected"; ?> >Admin Only</option>   
     414<option value="<?php echo self::WPD_STATUS_BOTH;?>" <?php  if(get_option($sField['key'])== self::WPD_STATUS_BOTH) echo "selected"; ?> >Admin & Front End</option>   
     415<?php endif; ?>
    374416</select>   
    375 <?php
    376 $sKeys.=','.$role_opt."";
    377 }
    378 ?>
     417
    379418</td>
    380419</tr>
     420<?php endforeach; ?>
    381421</table>
    382422</div>
    383 <input type="hidden" name="action" value="update" />
    384 <input type="hidden" name="page_options" value="<?php echo $sKeys; ?>" />
     423<?php
     424//output hidden fields for settings (sweet)
     425settings_fields(self::WPD_OPTIONS_GROUP);
     426?>
    385427
    386428</div>
Note: See TracChangeset for help on using the changeset viewer.