__( "Display a list of your site's pages on your sidebar.", 'p2020' ), 'customize_selective_refresh' => true, ] ); add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_scripts' ] ); } /** * Overrides WP_Widget_Pages::udpate(). * * @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 = parent::update( $new_instance, $old_instance ); $instance['expanded'] = 'expanded' === $new_instance['expanded']; return $instance; } public function enqueue_scripts() { if ( is_active_widget( false, false, self::WIDGET_ID_BASE ) || is_active_widget( false, false, 'monster' ) || is_customize_preview() ) { wp_enqueue_script( 'p2020-sidebar-menu-toggler', get_template_directory_uri() . '/widgets/sidebar-menus/js/tree-toggler.js', [ 'jquery' ], filemtime( get_template_directory() . '/widgets/sidebar-menus/js/tree-toggler.js' ), true ); } } /** * Overrides WP_Widget_Pages::form(). */ public function form( $instance ) { // Defaults. $instance = wp_parse_args( (array) $instance, [ 'sortby' => 'menu_order', 'title' => __( 'Pages', 'p2020' ), 'exclude' => '', ] ); ?>


__( 'Pages', 'p2020' ), 'sortby' => 'menu_order', 'exclude' => '', ); $title = empty( $instance['title'] ) ? $default['title'] : $instance['title']; $title = apply_filters( 'widget_title', $title ); $sortby = empty( $instance['sortby'] ) ? $default['sortby'] : $instance['sortby']; $exclude = empty( $instance['exclude'] ) ? $default['exclude'] : $instance['exclude']; $expanded = ! empty( $instance['expanded'] ); // phpcs:disable WordPress.Security.EscapeOutput // Reason: HTML from theme echo $args['before_widget']; echo $this->widget_header( $title, $args['before_title'], $args['after_title'] ); echo $this->widget_content( $title, $sortby, $exclude, $expanded ); echo $args['after_widget']; // phpcs:enable WordPress.Security.EscapeOutput do_action( 'p2_widgets_stats', self::WIDGET_ID_BASE ); } private function widget_header( $title, $before_title, $after_title ) { $simple_menu = null; // phpcs:disable WordPress.Security.EscapeOutput // Reason: HTML from theme echo $before_title; echo esc_html( $title ); // Output actions menu if user has correct privileges. if ( is_user_member_of_blog() && current_user_can( 'publish_pages' ) ) { $new_page_url = Navigation\Urls::get_editor_page_url(); $manage_pages_url = Navigation\Urls::get_pages_url(); $simple_menu = new Navigation\Simple_Menu( 'p2020-page-menu-widget-menu', __( 'More', 'p2020' ) ); $simple_menu->add_item( __( 'New page', 'p2020' ), $new_page_url ); $simple_menu->add_item( __( 'Manage pages', 'p2020' ), $manage_pages_url ); } if ( $simple_menu ) { get_template_part( 'partials/ellipsis-menu', $simple_menu->get_type(), [ 'simple_menu' => $simple_menu ], ); } echo $after_title; // phpcs:enable WordPress.Security.EscapeOutput } private function widget_content( $title, $sortby, $exclude, $expanded ) { self::print_menu( $title, $sortby, $exclude, $expanded ); } public static function print_menu( $title, $sortby = 'menu_order', $exclude = '', $expanded = '' ) { echo ''; } public static function print_empty_state() { echo ''; } }