Example #1
0
 /**
  * This function returns the current option values for Note.
  */
 public static function get_options($option_name = false)
 {
     // If an option name is passed, return that value otherwise default to Note options
     if ($option_name) {
         return wp_parse_args(get_option($option_name), Note_Options::get_option_defaults($option_name));
     }
     return wp_parse_args(get_option(Note_Options::$option_name), Note_Options::get_option_defaults());
 }
 public function sanitize_option($input)
 {
     // TODO Reset to defaults?
     //if ( isset( $input['reset'] ) )
     //	return Note_Options::get_option_defaults();
     // Store the raw input values from the user which will be used in certain validation checks
     $raw_input = $input;
     // Parse arguments, replacing defaults with user input
     $input = wp_parse_args($input, Note_Options::get_option_defaults());
     // Note Sidebars
     if (!empty($input['sidebars']) && is_array($input['sidebars'])) {
         $note_sidebars = Note_Sidebars();
         // Grab the Note Sidebars instance
         // Sanitize sidebars
         $input['sidebars'] = $note_sidebars->sanitize_callback($input['sidebars']);
     } else {
         // Grab current version of Note Options
         $note_options = Note_Options::get_options();
         // Previously sanitized by the Customizer logic (@see Note_Sidebars::sanitize_callback())
         $input['sidebars'] = $note_options['sidebars'];
     }
     // Note Uninstall
     $input['uninstall']['data'] = isset($raw_input['uninstall']['data']) && $input['uninstall']['data'] ? true : false;
     // Remove Note data on uninstall (checking isset() here due to the nested arrays)
     return $input;
 }
Example #3
0
 /**
  * This function registers sections and settings for use in the Customizer.
  */
 public function customize_register($wp_customize)
 {
     // Bail if lower than WordPress 4.1
     if (Note::wp_version_compare('4.1', '<')) {
         return;
     }
     $note_option_defaults = Note_Options::get_option_defaults();
     $note_sidebars = Note_Sidebars();
     // Grab the Note Sidebars instance
     /**
      * Note
      */
     /*
      * Note Sidebars
      */
     // Setting (data is sanitized upon update_option() call using the sanitize function in Note_Admin_Options)
     $wp_customize->add_setting(new WP_Customize_Setting($wp_customize, 'note[sidebars]', array('default' => $note_option_defaults['sidebars'], 'type' => 'option', 'sanitize_callback' => array($note_sidebars, 'sanitize_callback'), 'sanitize_js_callback' => array($note_sidebars, 'sanitize_js_callback'))));
     // Section
     $wp_customize->add_section(new WP_Customize_Section($wp_customize, 'note_sidebars', array('title' => __('Note Sidebars', 'note'), 'priority' => 999)));
     // Control
     $wp_customize->add_control(new WP_Customize_Control($wp_customize, 'note_sidebars', array('label' => __('Note Sidebars', 'note'), 'section' => 'note_sidebars', 'settings' => 'note[sidebars]', 'input_attrs' => array('class' => 'note-sidebars note-hidden'), 'active_callback' => '__return_false')));
     /*
      * Note Temporary Sidebar
      */
     // Setting
     $wp_customize->add_setting(new WP_Customize_Setting($wp_customize, 'sidebars_widgets[note-temporary-inactive-sidebar]', array('default' => array(), 'type' => 'option', 'sanitize_callback' => array($wp_customize->widgets, 'sanitize_sidebar_widgets'), 'sanitize_js_callback' => array($wp_customize->widgets, 'sanitize_sidebar_widgets_js_instance'))));
     // Section
     $wp_customize->add_section(new WP_Customize_Sidebar_Section($wp_customize, 'sidebar-widgets-note-temporary-inactive-sidebar', array('title' => __('Note Temporary Inactive Sidebar', 'note'), 'description' => __('This is a temporary sidebar registered by Note in the Customizer only. It will hold inactive Note Sidebar widgets during a session', 'note'), 'priority' => 999, 'panel' => 'widgets', 'sidebar_id' => 'note-temporary-inactive-sidebar')));
     // Control
     $wp_customize->add_control(new WP_Widget_Area_Customize_Control($wp_customize, 'sidebars_widgets[note-temporary-inactive-sidebar]', array('section' => 'sidebar-widgets-note-temporary-inactive-sidebar', 'sidebar_id' => 'note-temporary-inactive-sidebar', 'priority' => 999, 'active_callback' => '__return_false')));
     /*
      * Inactive Widgets
      *
      * WordPress does not create controls for inactive widgets, but we need those controls
      * because sidebars can be removed and added dynamically. Only do this in the Customizer
      * and only do this for Note Sidebars.
      *
      * The Previewer controls are added in Note_Customizer::wp() after the core filters have been run.
      */
     // Admin
     if (is_admin()) {
         $this->register_inactive_note_widgets();
     }
 }
Example #4
0
 /**
  * This function registers all Note Sidebars based on options. It also adds the Note Sidebars setting to the
  * Customizer early to ensure widgets can be registered "on-time".
  *
  * This function also sets up properties on this class and allows other plugins and themes
  * to adjust those properties by filtering.
  */
 public function widgets_init()
 {
     // Bail if lower than WordPress 4.1
     if (Note::wp_version_compare('4.1', '<')) {
         return;
     }
     global $wp_customize;
     // Setup sidebar locations
     $this->sidebar_locations = apply_filters('note_sidebar_locations', array('content' => array('before' => 'content-before', 'after' => 'content-after')), $this);
     // Customizer Previewer only
     if (is_customize_preview() && !is_admin()) {
         // Register our Note Sidebar setting early to ensure the preview filter is triggered early enough
         $note_option_defaults = Note_Options::get_option_defaults();
         // Setting (data is sanitized upon update_option() call using the sanitize function in Note_Admin_Options)
         $setting = new WP_Customize_Setting($wp_customize, 'note[sidebars]', array('default' => $note_option_defaults['sidebars'], 'type' => 'option', 'sanitize_callback' => array($this, 'sanitize_callback')));
         $wp_customize->add_setting($setting);
         // Call the preview() function to enable Previewer filters
         $setting->preview();
         // Note Options
         $note_options = Note_Options::get_options();
         // Sidebars
         $this->sidebars = $note_options['sidebars'];
     }
     // Customizer only
     if (is_customize_preview()) {
         // Register Note temporary inactive sidebar
         register_sidebar(array('name' => __('Note Temporary Inactive Sidebar', 'note'), 'id' => 'note-temporary-inactive-sidebar', 'description' => __('This is a temporary sidebar registered by Note in the Customizer only. It will hold inactive Note Sidebar widgets during a Customizer session only.', 'note')));
     }
     // Register Note Sidebars
     if (is_array($this->sidebars)) {
         self::register_note_sidebars($this->sidebars);
     }
 }
 /**
  * This function creates the Note option in the database upon install.
  */
 public function admin_init()
 {
     add_option(Note_Options::$option_name, Note_Options::get_option_defaults());
 }
 /**
  * This function sets up all of the actions and filters on instance. It also loads (includes)
  * the required files and assets.
  */
 function __construct()
 {
     // Load options
     self::$options = Note_Options::get_options();
 }
Example #7
0
/**
 * Includes
 */
include_once 'note.php';
// Note Plugin
include_once 'includes/class-note-options.php';
// Note Options
include_once 'includes/class-note-sidebars.php';
// Note Template Functions
include_once 'includes/widgets/class-note-widget.php';
// Note Widget
/**
 * Uninstall
 */
// Fetch Note options
$note_options = Note_Options::get_options();
// Remove Note data upon uninstall
if ($note_options['uninstall']['data']) {
    // Widgets grouped by sidebar
    $sidebars_widgets = wp_get_sidebars_widgets();
    if (empty($sidebars_widgets)) {
        $sidebars_widgets = wp_get_widget_defaults();
    }
    // Unregister Note Sidebars
    if (is_array($note_options['sidebars'])) {
        // Loop through posts
        foreach ($note_options['sidebars'] as $post_id => $note_sidebar_ids) {
            // Loop through Note Sidebar IDs
            foreach ($note_sidebar_ids as $sidebar_id) {
                // Find the Note Sidebar ID for this sidebar
                $note_sidebar_id = Note_Sidebars::get_sidebar_id($sidebar_id, $post_id);