From 7086111ad4dd997e12a3220e1ee60c9b9bcf0bb8 Mon Sep 17 00:00:00 2001 From: Charles Date: Tue, 7 Jan 2020 13:06:14 +0100 Subject: Added wordpress --- .../widgets/class-wp-nav-menu-widget.php | 174 +++++++++++++++++++++ 1 file changed, 174 insertions(+) create mode 100644 srcs/wordpress/wp-includes/widgets/class-wp-nav-menu-widget.php (limited to 'srcs/wordpress/wp-includes/widgets/class-wp-nav-menu-widget.php') diff --git a/srcs/wordpress/wp-includes/widgets/class-wp-nav-menu-widget.php b/srcs/wordpress/wp-includes/widgets/class-wp-nav-menu-widget.php new file mode 100644 index 0000000..8f1a208 --- /dev/null +++ b/srcs/wordpress/wp-includes/widgets/class-wp-nav-menu-widget.php @@ -0,0 +1,174 @@ + __( 'Add a navigation menu to your sidebar.' ), + 'customize_selective_refresh' => true, + ); + parent::__construct( 'nav_menu', __( 'Navigation Menu' ), $widget_ops ); + } + + /** + * Outputs the content for the current Navigation Menu widget instance. + * + * @since 3.0.0 + * + * @param array $args Display arguments including 'before_title', 'after_title', + * 'before_widget', and 'after_widget'. + * @param array $instance Settings for the current Navigation Menu widget instance. + */ + public function widget( $args, $instance ) { + // Get menu + $nav_menu = ! empty( $instance['nav_menu'] ) ? wp_get_nav_menu_object( $instance['nav_menu'] ) : false; + + if ( ! $nav_menu ) { + return; + } + + $title = ! empty( $instance['title'] ) ? $instance['title'] : ''; + + /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ + $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); + + echo $args['before_widget']; + + if ( $title ) { + echo $args['before_title'] . $title . $args['after_title']; + } + + $nav_menu_args = array( + 'fallback_cb' => '', + 'menu' => $nav_menu, + ); + + /** + * Filters the arguments for the Navigation Menu widget. + * + * @since 4.2.0 + * @since 4.4.0 Added the `$instance` parameter. + * + * @param array $nav_menu_args { + * An array of arguments passed to wp_nav_menu() to retrieve a navigation menu. + * + * @type callable|bool $fallback_cb Callback to fire if the menu doesn't exist. Default empty. + * @type mixed $menu Menu ID, slug, or name. + * } + * @param WP_Term $nav_menu Nav menu object for the current menu. + * @param array $args Display arguments for the current widget. + * @param array $instance Array of settings for the current widget. + */ + wp_nav_menu( apply_filters( 'widget_nav_menu_args', $nav_menu_args, $nav_menu, $args, $instance ) ); + + echo $args['after_widget']; + } + + /** + * Handles updating settings for the current Navigation Menu widget instance. + * + * @since 3.0.0 + * + * @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 Updated settings to save. + */ + public function update( $new_instance, $old_instance ) { + $instance = array(); + if ( ! empty( $new_instance['title'] ) ) { + $instance['title'] = sanitize_text_field( $new_instance['title'] ); + } + if ( ! empty( $new_instance['nav_menu'] ) ) { + $instance['nav_menu'] = (int) $new_instance['nav_menu']; + } + return $instance; + } + + /** + * Outputs the settings form for the Navigation Menu widget. + * + * @since 3.0.0 + * + * @param array $instance Current settings. + * @global WP_Customize_Manager $wp_customize + */ + public function form( $instance ) { + global $wp_customize; + $title = isset( $instance['title'] ) ? $instance['title'] : ''; + $nav_menu = isset( $instance['nav_menu'] ) ? $instance['nav_menu'] : ''; + + // Get menus + $menus = wp_get_nav_menus(); + + $empty_menus_style = ''; + $not_empty_menus_style = ''; + if ( empty( $menus ) ) { + $empty_menus_style = ' style="display:none" '; + } else { + $not_empty_menus_style = ' style="display:none" '; + } + + $nav_menu_style = ''; + if ( ! $nav_menu ) { + $nav_menu_style = 'display: none;'; + } + + // If no menus exists, direct the user to go and create some. + ?> + + +