Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- register_activation_hook( __FILE__, array( 'Wpe_Settings', 'settings_load' ) );
- class Wpe_Settings {
- function __construct(){}
- function __destruct() {}
- function settings_load()
- {
- update_option( 'wpe_settings', array( 'wpe_revision_control' => false ) );
- }
- function settings_init()
- {
- register_setting( 'wpe_settings', 'wpe_settings' );
- add_settings_section('revision_control_section', __('Post Revisions', 'wpe'), array( $this, 'revision_control_section_callback' ), 'writing' );
- add_settings_field( 'wpe_revision_control', __('Disable Revisions', 'wpe'), array( $this, 'revision_control_setting_callback' ), 'writing', 'revision_control_section' );
- }
- function revision_control_section_callback()
- {
- 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>';
- }
- function revision_control_setting_callback()
- {
- $options = get_option( 'wpe_settings' );
- if( $options['wpe_revision_control'] == 'disabled' || !isset( $options ) )
- $checked = 'checked="checked"';
- echo "<input {$checked} name='wpe_settings[wpe_revision_control]' id='wpe_revision_control' type='checkbox' class='code' />" . __('Disable Post Revisions','wpe');
- }
- }
- $wpe_rc = new Wpe_Settings;
- add_action('admin_init', array( $wpe_rc, 'settings_init') );
- function wpe_save_settings()
- {
- $settings = array();
- if( isset($_POST['wpe_settings']) && $_POST['wpe_settings']['wpe_revision_control'] == 'on' )
- $settings['wpe_revision_control'] = 'disabled';
- else
- $settings['wpe_revision_control'] = 'enabled';
- //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"
- update_option( 'wpe_settings', $settings );
- //echo 'Post: <pre>';print_r($_POST);echo'</pre>';exit;
- }
- add_action('plugins_loaded','wpe_save_settings');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement