Changeset 1307112
- Timestamp:
- 12/13/2015 01:39:53 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tablemaster/trunk/admin/class-tablemaster-settings.php
r1296986 r1307112 7 7 class TableMaster_Settings { 8 8 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 9 25 private $options_name = 'tablemaster_general_options'; 10 26 private $settings_group = 'tablemaster_general_options_group'; 11 27 private $settings_page = 'general_options_page'; 12 28 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 14 31 private $plugin_default_settings = array( 15 32 "class" => null, 16 33 'thead' => 1, 17 34 'tfoot' => 0, 18 "nohead"=> 0,19 "style"=> null,20 "css"=> null,35 'nohead' => 0, 36 'style' => null, 37 'css' => null, 21 38 'datatables' => 0, 22 39 'rows' => 10, //valid choices are 10, 25, 50, 100 23 40 'buttons' => 0, 24 41 '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 26 44 ); 27 45 … … 32 50 */ 33 51 private static $instance; 34 public function getInstance( ) {52 public function getInstance( $plugin_name, $plugin_version ) { 35 53 if (null == self::$instance) { 36 self::$instance = new TableMaster_Settings ;54 self::$instance = new TableMaster_Settings( $plugin_name, $plugin_version ); 37 55 } 38 56 return self::$instance; … … 42 60 * Initialize the class and set its properties. 43 61 */ 44 public function __construct() { 62 public function __construct( $plugin_name, $plugin_version ) { 63 64 $this->plugin_name = $plugin_name; 65 $this->version = $plugin_version; 45 66 46 67 add_action( 'admin_menu', array( &$this, 'create_tablemaster_settings_menu_item' ) ); … … 169 190 add_option( $this->options_name, $this->plugin_default_settings ); 170 191 } 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 } 171 203 172 204 // Second, we register a section. This is necessary since all future options must belong to a section. … … 271 303 ); 272 304 305 273 306 add_settings_field( 274 307 'rows', … … 305 338 ); 306 339 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 307 352 } // end register_tablemaster_settings 308 353 … … 371 416 function tablemaster_plugin_validate_input( $input ) { 372 417 373 $checkbox_array = array( 'thead', 'tfoot', 'nohead', 'datatables', 'buttons', 'new_window' );418 $checkbox_array = array( 'thead', 'tfoot', 'nohead', 'datatables', 'buttons', 'new_window', 'default_sort' ); 374 419 $text_input_array = array( 'class', 'style', 'css', 'button_list', 'rows' ); 375 420
Note: See TracChangeset
for help on using the changeset viewer.