/** * Function used to create instance of class. */ public static function instance() { if (is_null(self::$_instance)) { self::$_instance = new self(); } return self::$_instance; }
/** * This function determines whether the current sidebar is rendered on the front-end. */ public function active_callback() { // Grab the Note Sidebars instance $note_sidebars = Note_Sidebars(); // If we have a valid array of sidebars if (is_array($note_sidebars->sidebars)) { // Loop through posts foreach ($note_sidebars->sidebars as $post_id => $note_sidebar_ids) { // Loop through Note Sidebar IDs foreach ($note_sidebar_ids as $sidebar_id) { // Note Sidebar arguments for this sidebar $sidebar_args = Note_Sidebars::note_sidebar_args($sidebar_id, $post_id, false); // Generate a section ID $section_id = $this->section_prefix . Note_Sidebars::get_sidebar_arg('id', $sidebar_args); // If this sidebar ID matches the section ID, it is rendered on the front-end if ($this->id === $section_id) { return true; } } } } // Otherwise, the sidebar is not rendered on the front-end return false; }
/** * This function runs after the WP and WP_Query objects are set up. */ function wp() { // Bail if lower than WordPress 4.1 if (Note::wp_version_compare('4.1', '<')) { return; } // Note Sidebars (single content types only or if filter returns true) if (is_singular() || apply_filters('note_customizer_localize_sidebar_args', false, $this)) { // Grab Note Sidebar Customizer arguments (keep Customizer Sections/Controls active for Previewer) $this->note_sidebar_args = Note_Sidebars::get_customizer_sidebar_args(true); // Note Sidebar args if (!isset($this->note_localize['sidebars'])) { $this->note_localize['sidebars'] = array(); } $this->note_localize['sidebars']['args'] = apply_filters('note_localize_sidebar_args', $this->note_sidebar_args, $this); /* * Inactive Widgets * * WordPress does not create controls for inactive widgets, but we need those controls * because sidebars can be removed and added/re-added dynamically. Only do this in the * Customizer and only do this for Note Sidebars. */ $this->register_inactive_note_widgets(true); } }
$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); // Remove this sidebar if it was found in sidebars widgets if (isset($sidebars_widgets[$note_sidebar_id])) { unset($sidebars_widgets[$note_sidebar_id]); } } } // Update the sidebars/widgets wp_set_sidebars_widgets($sidebars_widgets); } // Grab an instance of the Note Widget and remove the settings $note_widget = Note_Widget(); delete_option($note_widget->option_name); // Delete the Note option delete_option(Note_Options::$option_name); }