WordPress.org

Making WordPress.org

Changeset 6088


Ignore:
Timestamp:
11/08/17 04:30:14 (5 weeks ago)
Author:
pento
Message:

Handbook: Allow showing the root page in the Handbook Pages widget.

The Gutenberg handbook doesn't have a link to the root page, so needs to show it in the menu. This changes adds an option (default disabled) to show the root page in the handbook widget.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/widgets.php

    r5959 r6088  
    2222    } 
    2323 
    24     function __construct() { 
    25         $widget_ops = array('classname' => 'widget_wporg_handbook_pages', 'description' => __( 'Your site’s Handbook Pages', 'wporg' ) ); 
     24    public function __construct() { 
     25        $widget_ops = array( 
     26            'classname' => 'widget_wporg_handbook_pages', 
     27            'description' => __( 'Your site’s Handbook Pages', 'wporg' ), 
     28            'customize_selective_refresh' => true, 
     29        ); 
    2630        WP_Widget::__construct( self::get_widget_id_base(), __( 'Handbook Pages', 'wporg' ), $widget_ops ); 
    2731    } 
    2832 
    29     function widget( $args, $instance ) { 
     33    public function widget( $args, $instance ) { 
    3034        $args['after_title'] = '</h2>' . "\n" . '<div class="menu-table-of-contents-container">' . "\n"; 
    3135        $args['after_widget'] = '</div>'; 
    3236 
    33         add_filter( 'widget_pages_args',    array( $this, 'handbook_post_type' ) ); 
     37        add_filter( 'widget_pages_args',    array( $this, 'handbook_post_type' ), 10, 2 ); 
    3438        add_filter( 'page_css_class',       array( $this, 'amend_page_css_class' ) ); 
    3539        parent::widget( $args, $instance ); 
     
    3842    } 
    3943 
    40     function handbook_post_type( $args ) { 
     44    public function form( $instance ) { 
     45        parent::form( $instance ); 
     46 
     47        $checked = $instance['show_home'] ? 'checked="checked"' : ''; 
     48        ?> 
     49        <p> 
     50            <input class="widefat" id="<?php echo esc_attr( $this->get_field_id('show_home') ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'show_home' ) ); ?>" type="checkbox" value="1" <?php echo $checked ?> /> 
     51            <label for="<?php echo esc_attr( $this->get_field_id( 'show_home' ) ); ?>"><?php _e( 'List the home page' ); ?></label> 
     52        </p> 
     53        <?php 
     54    } 
     55 
     56    public function update( $new_instance, $old_instance ) { 
     57        $instance = parent::update( $new_instance, $old_instance ); 
     58        $instance['show_home'] = (bool) $new_instance['show_home']; 
     59 
     60        return $instance; 
     61    } 
     62 
     63    public function handbook_post_type( $args, $instance ) { 
    4164        $post = get_post(); 
     65 
     66        if ( ! isset( $instance['show_home'] ) ) { 
     67            $instance['show_home'] = false; 
     68        } 
    4269 
    4370        $this->post_types = (array) apply_filters( 'handbook_post_types', $this->post_types ); 
     
    6087            $page = get_page_by_path( $slug, OBJECT, $post->post_type ); 
    6188        } 
    62         if ( $page ) { 
     89        if ( $page && ! $instance['show_home'] ) { 
    6390            $args['exclude'] = $page->ID; 
    6491        } 
     
    6794    } 
    6895 
    69     function append_suffix( $t ) { 
     96    public function append_suffix( $t ) { 
    7097        if ( in_array( $t, array( 'handbook', 'page' ) ) ) { 
    7198            return $t; 
     
    83110     * @return array 
    84111     */ 
    85     function amend_page_css_class( $css_class ) { 
     112    public function amend_page_css_class( $css_class ) { 
    86113        $class_name_map = array( 
    87114            'current_page_ancestor'  => 'current-menu-ancestor', 
Note: See TracChangeset for help on using the changeset viewer.