Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.13 KB | None | 0 0
  1. register_activation_hook( __FILE__, array( 'Wpe_Settings', 'settings_load' ) );
  2.  
  3. class Wpe_Settings {
  4.    
  5.     function __construct(){}
  6.     function __destruct() {}
  7.    
  8.     function settings_load()
  9.     {
  10.         update_option( 'wpe_settings', array( 'wpe_revision_control' => false ) );
  11.     }
  12.    
  13.     function settings_init()
  14.     {
  15.         register_setting( 'wpe_settings', 'wpe_settings' );
  16.         add_settings_section('revision_control_section', __('Post Revisions', 'wpe'), array( $this, 'revision_control_section_callback' ), 'writing' );
  17.         add_settings_field( 'wpe_revision_control', __('Disable Revisions', 'wpe'), array( $this, 'revision_control_setting_callback' ), 'writing', 'revision_control_section' );
  18.     }
  19.    
  20.     function revision_control_section_callback()
  21.     {
  22.         echo '<p>' . __('By default, post and page revisions have been <em>disabled</em> on your blog. This is to reduce the number of database queries and load across the WP Engine infrastructure. If you rely on, or need, post revisions you can re-enable them here. Note that this does not affect auto-save.','wpe' ) . '</p>';
  23.     }
  24.    
  25.     function revision_control_setting_callback()
  26.     {
  27.         $options = get_option( 'wpe_settings' );
  28.        
  29.         if( $options['wpe_revision_control'] == 'disabled' || !isset( $options ) )
  30.             $checked = 'checked="checked"';
  31.        
  32.         echo "<input {$checked} name='wpe_settings[wpe_revision_control]' id='wpe_revision_control' type='checkbox' class='code' />" . __('Disable Post Revisions','wpe');
  33.     }
  34. }
  35.  
  36. $wpe_rc = new Wpe_Settings;
  37. add_action('admin_init', array( $wpe_rc, 'settings_init') );
  38.  
  39. function wpe_save_settings()
  40. {
  41.     $settings = array();
  42.     if( isset($_POST['wpe_settings']) && $_POST['wpe_settings']['wpe_revision_control'] == 'on' )
  43.         $settings['wpe_revision_control'] = 'disabled';
  44.     else
  45.         $settings['wpe_revision_control'] = 'enabled';
  46.     //echo 'Pre: <pre>';print_r($settings);echo'</pre>'; <--- Both this and commented code below show proper data and DB is updated. When exit is removed, the DB value is blasted again to "enabled"
  47.     update_option( 'wpe_settings', $settings );
  48.     //echo 'Post: <pre>';print_r($_POST);echo'</pre>';exit;
  49. }
  50. add_action('plugins_loaded','wpe_save_settings');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement