'avada_vertical_menu', 'description' => 'This widget replaces the Side Navigation Template.', ); $control_ops = array( 'id_base' => 'avada-vertical-menu-widget', ); parent::__construct( 'avada-vertical-menu-widget', 'Avada: Vertical Menu', $widget_ops, $control_ops ); $this->enqueue_script(); } /** * Echoes the widget content. * * @access public * @param array $args Display arguments including 'before_title', 'after_title', * 'before_widget', and 'after_widget'. * @param array $instance The settings for the particular instance of the widget. */ public function widget( $args, $instance ) { extract( $args ); $title = apply_filters( 'widget_title', isset( $instance['title'] ) ? $instance['title'] : '' ); echo $before_widget; // WPCS: XSS ok. if ( $title ) { echo $before_title . $title . $after_title; // WPCS: XSS ok. } // Dynamic Styles. $style = ''; echo $style; // WPCS: XSS ok. $nav_type = $instance['nav_type']; $widget_border_class = ( '' === $instance['border_color'] ? 'no-border' : '' ); if ( 'custom_menu' === $nav_type ) { // Get menu. $nav_menu = ! empty( $instance['nav_menu'] ) ? wp_get_nav_menu_object( $instance['nav_menu'] ) : false; if ( ! $nav_menu ) { echo $after_widget; // WPCS: XSS ok. return; } $link_before = ''; $link_after = ''; if ( ( 'left' === $instance['layout'] && ! is_rtl() ) || ( 'right' === $instance['layout'] && is_rtl() ) ) { $link_before = ''; $link_after = ''; } $nav_menu_args = array( 'fallback_cb' => '', 'menu' => $nav_menu, 'container_class' => 'fusion-vertical-menu-widget fusion-menu ' . $instance['behavior'] . ' ' . $instance['layout'] . ' ' . $widget_border_class, 'container_id' => 'fusion-' . esc_attr( $this->id ), 'container' => 'nav', 'item_spacing' => 'discard', 'link_before' => $link_before, 'link_after' => $link_after, ); wp_nav_menu( $nav_menu_args ); } elseif ( 'vertical_menu' === $nav_type ) { // Get page. $parent_page = ( ! empty( $instance['parent_page'] ) || '0' != $instance['parent_page'] ) ? $instance['parent_page'] : false; if ( ! $parent_page ) { echo $after_widget; // WPCS: XSS ok. return; } $html = ''; echo $html; // WPCS: XSS ok. } // End if(). echo $after_widget; // WPCS: XSS ok. } /** * Updates a particular instance of a widget. * * This function should check that `$new_instance` is set correctly. The newly-calculated * value of `$instance` should be returned. If false is returned, the instance won't be * saved/updated. * * @access public * @param array $new_instance New settings for this instance as input by the user via * WP_Widget::form(). * @param array $old_instance Old settings for this instance. * @return array Settings to save or bool false to cancel saving. */ public function update( $new_instance, $old_instance ) { $instance = $old_instance; $instance['title'] = isset( $new_instance['title'] ) ? $new_instance['title'] : ''; $instance['nav_type'] = isset( $new_instance['nav_type'] ) ? $new_instance['nav_type'] : ''; $instance['nav_menu'] = isset( $new_instance['nav_menu'] ) ? $new_instance['nav_menu'] : ''; $instance['parent_page'] = isset( $new_instance['parent_page'] ) ? $new_instance['parent_page'] : ''; $instance['behavior'] = isset( $new_instance['behavior'] ) ? $new_instance['behavior'] : ''; $instance['layout'] = isset( $new_instance['layout'] ) ? $new_instance['layout'] : ''; $instance['font_size'] = isset( $new_instance['font_size'] ) ? $new_instance['font_size'] : ''; $instance['border_color'] = isset( $new_instance['border_color'] ) ? $new_instance['border_color'] : ''; return $instance; } /** * Get array of pages which have got children. * * @access public * @return array Array of all pages which have got chidlren. */ public function get_pages_with_children() { $args = array( 'parent' => -1, 'post_type' => 'page', 'post_status' => 'publish', ); $pages = get_pages( $args ); $pages = array_filter( $pages, array( $this, 'exclude_parents' ) ); $parents = array(); foreach ( $pages as $page ) { $parents[ $page->post_parent ] = get_the_title( $page->post_parent ); } return $parents; } /** * Callback function for array_filter in get_pages_with_children method. * * This method chcecks if current pages array index has got parent set. * * @access public * @param array $element Current array element. * @return bool whether got parent or not. */ public function exclude_parents( $element ) { return isset( $element->post_parent ) && 0 !== $element->post_parent; } /** * Enqueues script. * * @access public * @return void */ public function enqueue_script() { $js_folder_suffix = '/assets/min/js'; $js_folder_url = Avada::$template_dir_url . $js_folder_suffix; $js_folder_path = Avada::$template_dir_path . $js_folder_suffix; Fusion_Dynamic_JS::enqueue_script( 'avada-vertical-menu-widget', $js_folder_url . '/general/avada-vertical-menu-widget.js', $js_folder_path . '/general/avada-vertical-menu-widget.js', array( 'jquery', 'jquery-hover-intent' ), '1', true ); } /** * Outputs the settings update form. * * @access public * @param array $instance Current settings. */ public function form( $instance ) { $defaults = array( 'title' => '', 'nav_type' => 'custom', 'nav_menu' => '', 'parent_page' => '', 'behavior' => 'hover', 'layout' => 'left', 'font_size' => '14px', 'border_color' => '', ); $instance = wp_parse_args( (array) $instance, $defaults ); // Get menus. $menus = wp_get_nav_menus(); $nav_menu = isset( $instance['nav_menu'] ) ? $instance['nav_menu'] : ''; // Get pages. $pages = $this->get_pages_with_children(); $parent_page = isset( $instance['parent_page'] ) ? $instance['parent_page'] : ''; ?>