> * * @implements Widget * @extends Widget_Abstract */ class Page extends Widget_Abstract implements Widget { /** * Shared widget instance logic. * * @phpstan-use Instance */ use Instance; public const NAME = 'advanced_sidebar_menu'; public const TITLE = Menu_Abstract::TITLE; public const INCLUDE_PARENT = Menu_Abstract::INCLUDE_PARENT; public const INCLUDE_CHILDLESS_PARENT = Menu_Abstract::INCLUDE_CHILDLESS_PARENT; public const ORDER_BY = Menu_Abstract::ORDER_BY; public const EXCLUDE = Menu_Abstract::EXCLUDE; public const DISPLAY_ALL = Menu_Abstract::DISPLAY_ALL; public const LEVELS = Menu_Abstract::LEVELS; /** * Default values for the widget. * * @var DEFAULTS */ protected static $defaults = [ self::TITLE => '', self::INCLUDE_PARENT => '', self::INCLUDE_CHILDLESS_PARENT => '', self::ORDER_BY => 'menu_order', self::EXCLUDE => '', self::DISPLAY_ALL => '', self::LEVELS => '100', ]; /** * Register the widget. */ public function __construct() { $widget_ops = [ 'classname' => 'advanced-sidebar-menu advanced-sidebar-page', 'description' => __( 'Creates a menu of all the pages using the parent/child relationship', 'advanced-sidebar-menu' ), 'show_instance_in_rest' => true, ]; $control_ops = []; if ( ! wp_is_mobile() ) { $control_ops['width'] = 620; } parent::__construct( self::NAME, __( 'Advanced Sidebar - Pages', 'advanced-sidebar-menu' ), $widget_ops, $control_ops ); $this->hook(); } /** * Add the sections to the widget via actions. * * @notice Anything using the column actions must use the $widget class passed * via do_action instead of $this * * @return void */ protected function hook() { static $hooked; if ( null !== $hooked ) { return; } $hooked = true; add_action( 'advanced-sidebar-menu/widget/page/left-column', [ $this, 'box_display' ], 5, 2 ); add_action( 'advanced-sidebar-menu/widget/page/left-column', [ $this, 'box_order' ], 15, 2 ); add_action( 'advanced-sidebar-menu/widget/page/left-column', [ $this, 'box_exclude' ], 20, 2 ); } /** * Get the label for used post type. * * For adjusting widget option labels. * * @since 8.2.0 * * @param PAGE_SETTINGS $instance - Widget settings. * @param bool $single - Singular label or plural. * * @return string */ public function get_post_type_label( $instance, $single = true ) { $type = (string) apply_filters( 'advanced-sidebar-menu/widget/page/post-type-for-label', 'page', $this->control_options, $instance ); return Utils::instance()->get_post_type_label( $type, $single ); } /** * Get available options to order the pages by. * * @since 9.0.0 * * @return array */ public static function get_order_by_options() { return (array) apply_filters( 'advanced-sidebar-menu/widget/page/order-by-options', [ 'menu_order' => __( 'Page Order', 'advanced-sidebar-menu' ), 'post_title' => __( 'Title', 'advanced-sidebar-menu' ), 'post_date' => __( 'Published Date', 'advanced-sidebar-menu' ), ] ); } /** * Display options. * * @phpstan-param PAGE_SETTINGS $instance * * @param array $instance - Widget settings. * @param Page $widget - Registered widget arguments. * * @return void */ public function box_display( array $instance, Page $widget ) { $settings = $this->set_instance( $instance, static::$defaults ); ?>

checkbox( self::INCLUDE_PARENT ); ?>

checkbox( self::INCLUDE_CHILDLESS_PARENT ); ?>

checkbox( self::DISPLAY_ALL, self::LEVELS ); ?>

hide_element( self::DISPLAY_ALL, self::LEVELS ); } ?> >

set_instance( $instance, static::$defaults ); do_action( 'advanced-sidebar-menu/widget/page/before-form', $settings, $this ); ?>

set_instance( $instance, static::$defaults ); $menu = PageMenu::factory( $settings, $args ); do_action( 'advanced-sidebar-menu/widget/before-render', $menu, $this ); $menu->render(); do_action( 'advanced-sidebar-menu/widget/after-render', $menu, $this ); } }