array('type' => 'bool', 'value' => 0), 'redact_posts' => array('type' => 'bool', 'value' => 0), 'redact_comments' => array('type' => 'bool', 'value' => 0) ); /** * Gets a singleton of this plugin * * Retrieves or creates the plugin singleton. * * @static * @access public * @since 0.0.1 * @return plugin singleton */ public static function get_instance () { if ( is_null( self::$_instance ) ) { self::$_instance = new self(); } return self::$_instance; } /** * Private constructor to keep the options page a singleton class. * * @access private * @since 0.0.1 * @return void */ private function __construct(){ if(is_admin()){ add_action('admin_init', array( $this, 'registerSettings' )); add_action('admin_menu', array( $this, 'add_plugin_options_page' ) ); add_action( 'wp_ajax_getRules', 'ajax_getRules' ); add_action( 'wp_ajax_updateRules', 'ajax_updateRules' ); add_action( 'wp_ajax_deleteRules', 'ajax_deleteRules' ); add_action( 'wp_ajax_addRules', 'ajax_addRules' ); } } /** * A helper function to return the redactor_options for classes to use. * * @access public * @since 0.0.1 * @return array redactor options */ public function get_options(){ return $this->sanitizeWithDefaults( get_option( 'redactor_options' ) ); } /** * Sanitizes user input when parsing option uploads * based on defaults and option types. * * @access public * @since 0.0.1 * @return array Sanitized options */ public function sanitizeWithDefaults($options){ if( !is_array( $options ) || empty( $options ) || ( false === $options ) ) $options = array(); //get all known keys to iterate through $valid_names = array_keys( $this->defaults ); $clean_options = array(); // loop through the valid keys and parse values from the incoming options array // into a sanitized array foreach( $valid_names as $option_name ) { if( isset( $options[$option_name] ) ){ $def = $this->defaults[$option_name]; //based on the type of option make sure the incoming option matches expected values switch($def['type']){ case 'bool': $clean_options[$option_name] = (1==$options[$option_name])? 1 : 0; break; } } else{ $clean_options[$option_name] = $this->defaults[$option_name]['value']; } } //unset the incoming options array, its sanitized now unset( $options ); return $clean_options; } /* * Registers the options with wordpress and tells the system how it needs to be rendered. * * @access public * @since 0.0.1 * @return void */ public function registerSettings(){ register_setting( 'redactor_options_group1', // Option group 'redactor_options', // Option name array( $this, 'sanitizeWithDefaults' ) // Sanitize ); add_settings_section( 'main_plugin_settings', // ID "Site-wide Plugin Settings", // Title null, // Callback datasync_PLUGIN_PRIVATE_NAME . '_settings_page' // Page ); add_settings_field( 'redact_wholeword', // ID 'Redact whole words', // Title array( $this, 'render_redact_wholeword' ), // Callback datasync_PLUGIN_PRIVATE_NAME . '_settings_page', // Page 'main_plugin_settings' // Section ); add_settings_field( 'redact_posts', // ID 'Redact post content', // Title array( $this, 'render_redact_posts' ), // Callback datasync_PLUGIN_PRIVATE_NAME . '_settings_page', // Page 'main_plugin_settings' // Section ); add_settings_field( 'redact_comments', // ID 'Redact post comments', // Title array( $this, 'render_redact_comments' ), // Callback datasync_PLUGIN_PRIVATE_NAME . '_settings_page', // Page 'main_plugin_settings' // Section ); } /** * Options page callback. Echos the rendering of the options page. * * @access public * @sinces 0.0.1 * @return void */ public function create_admin_page() { $this->options = $this->get_options(); ?>