false, self::INCLUDE_PARENT => false, self::INCLUDE_CHILDLESS_PARENT => false, self::ORDER_BY => 'menu_order', self::EXCLUDE => false, self::DISPLAY_ALL => false, self::LEVELS => 100, ]; /** * Register the widget. */ public function __construct() { $widget_ops = [ 'classname' => 'advanced-sidebar-menu', 'description' => __( 'Creates a menu of all the pages using the child/parent relationship', 'advanced-sidebar-menu' ), ]; $control_ops = [ 'width' => wp_is_mobile() ? false : 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. * * @param array $instance - Widget settings. * @param bool $single - Singular label or plural. * * @since 8.2.0 * * @return mixed */ public function get_post_type_label( $instance, $single = true ) { $post_type = get_post_type_object( apply_filters( 'advanced-sidebar-menu/widget/page/post-type-for-label', 'page', $this->control_options, $instance ) ); if ( null === $post_type ) { $post_type = get_post_type_object( 'page' ); // Sensible fallback. } return $single ? $post_type->labels->singular_name : $post_type->labels->name; } /** * Display options. * * @param array $instance - Widget settings. * @param Widget_Abstract $widget - Registered widget arguments. * * @return void */ public function box_display( array $instance, $widget ) { ?>
set_instance( $instance, self::$defaults ); do_action( 'advanced-sidebar-menu/widget/page/before-form', $instance, $this ); ?>render(); do_action( 'advanced-sidebar-menu/widget/after-render', $menu, $this ); } }