/** * 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 outputs a Note Sidebar based on parameters. It will fallback to the placeholder if the current * page is being output in the Previewer. Otherwise it will return an empty string. */ public static function sidebar($sidebar_id, $post_id) { // Reference to sidebar HTML $sidebar_html = ''; // Grab the Note Sidebars instance $note_sidebars = Note_Sidebars(); $registered_sidebars = isset($note_sidebars->sidebars[$post_id]) ? (array) $note_sidebars->sidebars[$post_id] : array(); $note_sidebar_id = self::get_sidebar_id($sidebar_id, $post_id); // If the sidebar ID is in the array of registered sidebars for this post, it is already registered on Note_Sidebars::widgets_init() if (in_array($sidebar_id, $registered_sidebars)) { // If the sidebar is active if (is_active_sidebar($note_sidebar_id)) { ob_start(); // Note Sidebar arguments $sidebar_args = $note_sidebars->sidebar_args[$sidebar_id]; // CSS Classes $css_classes = array('note-sidebar', 'note-sidebar-active', 'note-cf', sprintf('note-%1$s-sidebar', $sidebar_id)); // Sanitize CSS classes $css_classes = array_filter($css_classes, 'sanitize_html_class'); ?> <div id="<?php echo esc_attr(self::get_sidebar_arg('id', $sidebar_args)); ?> " class="<?php echo esc_attr(implode(' ', $css_classes)); ?> " data-post-id="<?php echo esc_attr($post_id); ?> " data-note-sidebar-id="<?php echo esc_attr($sidebar_id); ?> " data-note-sidebar="true"> <?php echo is_customize_preview() && !is_admin() ? Note_Customizer::note_sidebar_ui_buttons() : false; ?> <?php // Remove Note UI filters // TODO: Remove? //remove_filter( 'dynamic_sidebar_before', array( $note_sidebars, 'dynamic_sidebar_before' ) ); //remove_filter( 'dynamic_sidebar_after', array( $note_sidebars, 'dynamic_sidebar_after' ) ); ?> <?php dynamic_sidebar($note_sidebar_id); ?> <?php // Re-add Note UI filters // TODO: Remove? //add_filter( 'dynamic_sidebar_before', array( $note_sidebars, 'dynamic_sidebar_before' ), 10, 2 ); //add_filter( 'dynamic_sidebar_after', array( $note_sidebars, 'dynamic_sidebar_after' ), 10 ,2 ); ?> </div> <?php $sidebar_html = ob_get_clean(); } else { if (is_customize_preview() && !is_admin()) { // Note Sidebar Placeholder (inactive sidebar) $sidebar_html = Note_Customizer::note_sidebar_placeholder($sidebar_id, $post_id, true); } } } else { if (is_customize_preview() && !is_admin()) { // Note Sidebar Placeholder (no registered sidebar) $sidebar_html = Note_Customizer::note_sidebar_placeholder($sidebar_id, $post_id); } } return $sidebar_html; }