示例#1
0
 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;
 }
示例#2
0
 /**
  * This function sets up properties on this class and allows other plugins and themes
  * to adjust those properties by filtering.
  */
 public function init()
 {
     global $wp_version, $wp_customize, $wp_registered_widgets, $wp_registered_sidebars;
     // Load required assets
     $this->includes();
     // Grab the Note Widget instance
     if (function_exists('Note_Widget')) {
         $note_widget = Note_Widget();
     }
     // Determine HTML5 support
     $caption_html5_support = current_theme_supports('html5', 'caption');
     // Captions
     $gallery_html5_support = current_theme_supports('html5', 'gallery');
     // Galleries
     // Grab Note options
     $note_options = Note_Options::get_options();
     // Setup of Note Sidebar data if we're in the Customizer
     if (is_customize_preview()) {
         // Grab the Note Sidebars instance
         $note_sidebars = Note_Sidebars();
         // Grab Note Sidebar Customizer arguments
         $this->note_sidebar_args = Note_Sidebars::get_customizer_sidebar_args();
         // Loop through Note sidebars
         foreach ($note_sidebars->sidebars as $post_id => $note_sidebar_ids) {
             // Loop through Note sidebar locations
             foreach ($note_sidebars->sidebar_locations as $sidebar_location) {
                 // Loop through each sidebar within this location
                 foreach ($sidebar_location as $sidebar_id) {
                     // Add the sidebar ID to the list of registered sidebars
                     $this->note_sidebar_locations[] = Note_Sidebars::get_sidebar_id($sidebar_id, $post_id);
                 }
             }
             // Loop through registered Note Sidebar IDs
             foreach ($note_sidebar_ids as $sidebar_id) {
                 // Add the sidebar ID to the list of registered sidebars
                 $this->note_registered_sidebars[] = Note_Sidebars::get_sidebar_id($sidebar_id, $post_id);
             }
         }
         $this->note_unregistered_sidebars = array_values(array_diff($this->note_sidebar_locations, $this->note_registered_sidebars));
         $sidebars_widgets = array_merge(array('wp_inactive_widgets' => array()), array_fill_keys(array_keys($wp_registered_sidebars), array()), wp_get_sidebars_widgets());
         // Loop through sidebar widgets
         foreach ($sidebars_widgets as $sidebar_id => $sidebar_widget_ids) {
             if (empty($sidebar_widget_ids)) {
                 $sidebar_widget_ids = array();
             }
             // Unregistered Note Sidebars only
             if (in_array($sidebar_id, $this->note_unregistered_sidebars)) {
                 // Store a reference to sidebars that were previously active but are now inactive
                 $this->note_inactive_sidebars[] = $sidebar_id;
                 // Add a control for each inactive widget
                 foreach ($sidebar_widget_ids as $i => $widget_id) {
                     // Only widgets that are still registered
                     if (isset($wp_registered_widgets[$widget_id])) {
                         // Customizer is ready
                         if (is_a($wp_customize, 'WP_Customize_Manager')) {
                             $setting_id = $wp_customize->widgets->get_setting_id($widget_id);
                             // Store a reference to the Customizer setting ID for this inactive widget
                             $this->note_inactive_widgets[] = array('widget_id' => $widget_id, 'setting_id' => $setting_id);
                             if (!isset($this->note_inactive_sidebars_widgets[$sidebar_id])) {
                                 $this->note_inactive_sidebars_widgets[$sidebar_id] = array();
                             }
                             // Store a reference to the inactive widget attached to the sidebar ID
                             $this->note_inactive_sidebars_widgets[$sidebar_id][$i] = array('widget_id' => $widget_id, 'setting_id' => $setting_id);
                         }
                     }
                 }
             }
         }
     }
     // Note Widget Editor Types
     $this->note_editor_types = apply_filters('note_tinymce_editor_types', $this->note_editor_types, $this);
     // Setup Customizer localization
     $this->note_customizer_localize = apply_filters('note_customizer_localize', array('wp_version' => $wp_version, 'wp_major_version' => (int) substr($wp_version, 0, 1), 'sidebars' => array('registered' => $note_options['sidebars'], 'customizer' => array('setting' => 'note[sidebars]', 'section' => 'note_sidebars', 'control' => 'note_sidebars', 'section_prefix' => 'sidebar-widgets-', 'inactive_sidebars' => $this->note_inactive_sidebars, 'inactive_widgets' => $this->note_inactive_widgets, 'inactive_sidebars_widgets' => $this->note_inactive_sidebars_widgets), 'args' => $this->note_sidebar_args)), $this);
     // Setup Previewer localization
     $this->note_localize = apply_filters('note_localize', array('tinymce' => array('selector' => '.note-widget .widget-content', 'plugins' => implode(' ', array_unique(apply_filters('note_tinymce_plugins', array('paste', 'lists', 'hr', 'textcolor', 'colorpicker', 'wordpress', 'wplink', 'wpview', 'note_insert', 'note_image', 'note_placeholder'), $this))), 'blocks' => apply_filters('note_tinymce_blocks', array('wp_image', 'note_edit'), $this), 'toolbar' => apply_filters('note_tinymce_toolbar', array('formatselect', 'styleselect', 'forecolor', 'backcolor', 'bold', 'italic', 'link', 'unlink', 'bullist', 'numlist', 'outdent', 'indent', 'alignleft', 'aligncenter', 'alignright', 'alignjustify'), $this), 'formats' => array('alignleft' => array(array('selector' => 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,address', 'styles' => array('textAlign' => 'left')), array('selector' => 'img,table,dl.wp-caption', 'classes' => array('alignleft'))), 'aligncenter' => array(array('selector' => 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,address', 'styles' => array('textAlign' => 'center')), array('selector' => 'img,table,dl.wp-caption', 'classes' => array('aligncenter'))), 'alignright' => array(array('selector' => 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,address', 'styles' => array('textAlign' => 'right')), array('selector' => 'img,table,dl.wp-caption', 'classes' => array('alignright')))), 'preview_styles' => implode(' ', array_unique(apply_filters('note_tinymce_preview_styles', array('font-family', 'font-size', 'font-weight', 'font-style', 'text-decoration', 'text-transform', 'color', 'background-color', 'border', 'border-radius', 'outline', 'text-shadow'), $this))), 'style_formats' => apply_filters('note_tinymce_style_formats', array(array('title' => __('12px', 'note'), 'inline' => 'span', 'styles' => array('fontSize' => '12px')), array('title' => __('14px', 'note'), 'inline' => 'span', 'styles' => array('fontSize' => '14px')), array('title' => __('16px', 'note'), 'inline' => 'span', 'styles' => array('fontSize' => '16px')), array('title' => __('18px', 'note'), 'inline' => 'span', 'styles' => array('fontSize' => '18px')), array('title' => __('20px', 'note'), 'inline' => 'span', 'styles' => array('fontSize' => '20px')), array('title' => __('22px', 'note'), 'inline' => 'span', 'styles' => array('fontSize' => '22px')), array('title' => __('24px', 'note'), 'inline' => 'span', 'styles' => array('fontSize' => '24px')), array('title' => __('28px', 'note'), 'inline' => 'span', 'styles' => array('fontSize' => '28px')), array('title' => __('32px', 'note'), 'inline' => 'span', 'styles' => array('fontSize' => '32px')), array('title' => __('36px', 'note'), 'inline' => 'span', 'styles' => array('fontSize' => '36px')), array('title' => __('42px', 'note'), 'inline' => 'span', 'styles' => array('fontSize' => '42px')), array('title' => __('48px', 'note'), 'inline' => 'span', 'styles' => array('fontSize' => '48px')), array('title' => __('56px', 'note'), 'inline' => 'span', 'styles' => array('fontSize' => '56px')), array('title' => __('64px', 'note'), 'inline' => 'span', 'styles' => array('fontSize' => '64px')), array('title' => __('72px', 'note'), 'inline' => 'span', 'styles' => array('fontSize' => '72px'))), $this), 'theme' => 'note', 'inline' => true, 'relative_urls' => false, 'convert_urls' => false, 'browser_spellcheck' => true, 'entity_encoding' => 'named', 'placeholder' => apply_filters('note_tinymce_placeholder', __('Start typing here&hellip;', 'note'), $this), 'html5_support' => array('caption' => $caption_html5_support, 'gallery' => $gallery_html5_support), 'caption_html' => $caption_html5_support ? array('itemtag' => 'figure', 'icontag' => 'div', 'captiontag' => 'figcaption') : array('itemtag' => 'dl', 'icontag' => 'dt', 'captiontag' => 'dd'), 'gallery_html5_support' => array()), 'modal_commands' => array('activate' => array('tinymce' => array('BeforeExecCommand' => 'WP_Link', 'wpLoadImageForm'), 'document' => array('note-modal-open'), 'wp.media.events' => array('editor:image-edit')), 'deactivate' => array('tinymce' => array('wpLoadImageData', 'wpLoadImageForm' => array('wp.media.frame' => 'close')), 'document' => array('wplink-close', 'note-modal-close'), 'wp.media.events' => array('editor:frame-create' => array('event.frame' => 'close')))), 'widget' => array('id' => isset($note_widget) ? $note_widget->id_base : 'note-widget'), 'widgets' => array('defaults' => array(), 'settings' => array(), 'templates' => array()), 'modals' => array('register_sidebar' => array('title' => __('Add Note Sidebar', 'note'), 'content' => sprintf('%1$s <div class="inputs"><input type="checkbox" name="ignore-register-sidebar" id="note-ignore-register-sidebar" class="ignore-register-sidebar ignore-register-sidebar-modal" value="true" /> <label for="note-ignore-register-sidebar">%2$s</label></div>', __('Are you sure you want to add a sidebar to this location?', 'note'), __('Don\'t display this confirmation in the future', 'note')), 'submit_label' => __('Add Note Sidebar', 'note')), 'unregister_sidebar' => array('title' => __('Remove Note Sidebar', 'note'), 'content' => sprintf('%1$s', __('Are you sure you want to remove this sidebar?', 'note')), 'submit_label' => __('Remove Note Sidebar', 'note')))));
     // If we have editor types
     if (is_array($this->note_editor_types) && !empty($this->note_editor_types)) {
         // Adjust Note localization data (store TinyMCE data in an array under the 'default' key)
         $this->note_localize['tinymce'] = array('default' => $this->note_localize['tinymce']);
         // Shim for Conductor 1.2.* TODO: Remove in a future version
         if (!Note::conductor_has_flexbox_display()) {
             $this->note_localize['tinymce'] = array_merge($this->note_localize['tinymce'], $this->note_localize['tinymce']['default']);
         }
         // Loop through editor types for configuration
         foreach ($this->note_editor_types as $editor_type) {
             // Copy Note localization data
             $settings = $this->note_localize['tinymce']['default'];
             // Switch based on editor type
             switch ($editor_type) {
                 // Rich Text Only
                 case 'rich_text_only':
                     // Make plugins an array
                     $settings['plugins'] = explode(' ', $settings['plugins']);
                     // Search for the 'note_image' TinyMCE plugin in existing settings
                     $note_image = array_search('note_image', $settings['plugins']);
                     // If we have an index for the the 'note_image' TinyMCE plugin
                     if ($note_image !== false) {
                         // Remove the 'note_image' TinyMCE plugin
                         unset($settings['plugins'][$note_image]);
                         // Reset array keys to ensure JavaScript logic receives an array
                         $settings['plugins'] = array_values($settings['plugins']);
                     }
                     // Make plugins a string again
                     $settings['plugins'] = implode(' ', $settings['plugins']);
                     // Search for the 'wp_image' TinyMCE block in existing settings
                     $wp_image = array_search('wp_image', $settings['blocks']);
                     // If we have an index for the the 'wp_image' TinyMCE block
                     if ($wp_image !== false) {
                         // Remove the 'wp_image' TinyMCE block
                         unset($settings['blocks'][$wp_image]);
                         // Reset array keys to ensure JavaScript logic receives an array
                         $settings['blocks'] = array_values($settings['blocks']);
                     }
                     break;
                     // Media
                 // Media
                 case 'media':
                     // Add media blocks
                     $settings['media_blocks'] = array('wp_image');
                     // Reset the placeholder
                     $settings['placeholder'] = '';
                     break;
                     // Rich Text (Also default; just inherit from Note)
                 // Rich Text (Also default; just inherit from Note)
                 default:
                     // Do nothing (for now)
                     break;
             }
             // Allow filtering of plugins, toolbar items, and placeholder
             $settings['plugins'] = explode(' ', $settings['plugins']);
             $settings['plugins'] = implode(' ', array_unique(apply_filters('note_tinymce_editor_plugins', $settings['plugins'], $editor_type, $this)));
             $settings['blocks'] = apply_filters('note_tinymce_editor_blocks', $settings['blocks'], $editor_type, $this);
             $settings['toolbar'] = apply_filters('note_tinymce_editor_toolbar', $settings['toolbar'], $editor_type, $this);
             //$settings['block_formats'] = apply_filters( 'note_tinymce_editor_block_formats', $settings['block_formats'], $editor_type, $this );
             $settings['preview_styles'] = explode(' ', $settings['preview_styles']);
             $settings['preview_styles'] = implode(' ', array_unique(apply_filters('note_tinymce_editor_preview_styles', $settings['preview_styles'], $editor_type, $this)));
             $settings['style_formats'] = apply_filters('note_tinymce_editor_style_formats', $settings['style_formats'], $editor_type, $this);
             $settings['placeholder'] = apply_filters('note_tinymce_editor_placeholder', $settings['placeholder'], $editor_type, $this);
             // Add the Note editor type
             $settings['note_type'] = $editor_type;
             // Assign the configuration to the localization data
             $settings = apply_filters('note_tinymce_editor_settings', $settings, $editor_type, $this);
             $this->note_localize['tinymce'][$editor_type] = $settings;
         }
     }
     // Setup Previewer TinyMCE localization
     $this->note_tinymce_localize = apply_filters('note_tinymce_localize', array('wp_version' => $wp_version, 'wp_major_version' => (int) substr($wp_version, 0, 1)), $this);
 }
 /**
  * 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();
 }
示例#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);
     }
 }
示例#5
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);