Plugin Directory

Changeset 1307112


Ignore:
Timestamp:
12/13/2015 01:39:53 AM (10 years ago)
Author:
vmallder
Message:

Added plugin name and plugin version to constructor. Added default_sort keyword to settings.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tablemaster/trunk/admin/class-tablemaster-settings.php

    r1296986 r1307112  
    77class TableMaster_Settings {
    88
     9    /**
     10     * The ID of this plugin.
     11     *
     12     * @access   private
     13     * @var      string    $plugin_name    The ID of this plugin.
     14     */
     15    private $plugin_name;
     16
     17    /**
     18     * The version of this plugin.
     19     *
     20     * @access   private
     21     * @var      string    $version    The current version of this plugin.
     22     */
     23    private $version;
     24
    925    private $options_name = 'tablemaster_general_options';
    1026    private $settings_group = 'tablemaster_general_options_group';
    1127    private $settings_page = 'general_options_page';
    1228    private $settings_section = 'general_options_section';
    13    
     29
     30    // If you add default settings for keywords here, you need to add them to the arrays in the validate function. tablemaster_plugin_validate_input
    1431    private $plugin_default_settings = array(
    1532            "class"         => null,
    1633            'thead'         => 1,
    1734            'tfoot'         => 0,
    18             "nohead"        => 0,
    19             "style"         => null,
    20             "css"           => null,
     35            'nohead'        => 0,
     36            'style'         => null,
     37            'css'           => null,
    2138            'datatables'    => 0,
    2239            'rows'          => 10,  //valid choices are 10, 25, 50, 100
    2340            'buttons'       => 0,
    2441            'button_list'   => 'copy,csv,excel,pdf,print',  //valid choices are opy,csv,excel,pdf,print
    25             "new_window"    => 1
     42            'new_window'    => 1,
     43            'default_sort'  => 1
    2644         );
    2745
     
    3250    */
    3351    private static $instance;
    34     public function getInstance() {
     52    public function getInstance( $plugin_name, $plugin_version ) {
    3553        if (null == self::$instance) {
    36             self::$instance = new TableMaster_Settings;
     54            self::$instance = new TableMaster_Settings( $plugin_name, $plugin_version );
    3755        }
    3856        return self::$instance;
     
    4260     * Initialize the class and set its properties.
    4361     */
    44     public function __construct() {
     62    public function __construct( $plugin_name, $plugin_version ) {
     63   
     64        $this->plugin_name = $plugin_name;
     65        $this->version = $plugin_version;
    4566
    4667        add_action( 'admin_menu', array( &$this, 'create_tablemaster_settings_menu_item' ) );
     
    169190            add_option( $this->options_name, $this->plugin_default_settings );
    170191        }
     192       
     193        // In version 0.0.3, 'default_sort' was added.  But, if someone is upgrading for  when I added the 'default_sort' option. Want to set the default value for the new setting
     194        // in memory but, we don't want to reset all of the default values because the user might have already set some
     195        // settings values that we don't want to override.
     196       
     197        // Lets check to see what value the new option has by default (null, 0, etc?)
     198        $current_options = get_option( $this->options_name );
     199        if( !array_key_exists('default_sort', $current_options ) ){
     200            $current_options['default_sort'] = $this->plugin_default_settings['default_sort'];
     201            update_option( $this->options_name, $current_options );
     202        }
    171203
    172204        // Second, we register a section. This is necessary since all future options must belong to a section.
     
    271303        );
    272304
     305   
    273306        add_settings_field(
    274307            'rows',                     
     
    305338        );
    306339   
     340        // Next, we'll introduce the fields for toggling the visibility of content elements.
     341        add_settings_field(
     342            'default_sort',                     // ID used to identify the field throughout the plugin
     343            __( 'default_sort', 'tablemaster' ),                            // The label to the left of the option interface element
     344            array( &$this, 'tablemaster_render_checkbox'),  // The name of the function responsible for rendering the option interface
     345            $this->settings_page,   
     346            $this->settings_section,           
     347            array( 'default_sort',                              // The array of arguments to pass to the callback. In this case, just a description.
     348                __( 'Check this box if you want the DataTables jQuery plugin to determine the default sort order for your table. Note, if you use the \'sql\' keyword and your MySQL command contains an \'ORDER BY\' clause, you should uncheck this checkbox.', 'tablemaster')
     349            )
     350        );
     351
    307352    } // end register_tablemaster_settings
    308353
     
    371416    function tablemaster_plugin_validate_input( $input ) {
    372417
    373         $checkbox_array = array( 'thead', 'tfoot', 'nohead', 'datatables', 'buttons', 'new_window' );
     418        $checkbox_array = array( 'thead', 'tfoot', 'nohead', 'datatables', 'buttons', 'new_window', 'default_sort' );
    374419        $text_input_array = array( 'class', 'style', 'css', 'button_list', 'rows' );
    375420       
Note: See TracChangeset for help on using the changeset viewer.