Changeset 8941 for sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/navigation.php
- Timestamp:
- 06/11/2019 08:52:54 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/navigation.php
r7723 r8941 9 9 10 10 /** 11 * Is the handbook table of contents produced by the handbook pages widget?12 *13 * @access private14 * @var bool15 */16 private static $using_pages_widget = false;17 18 /**19 11 * Initializes handbook navigation. 20 12 */ … … 27 19 */ 28 20 public static function do_init() { 29 // Note if the WPorg_Handbook_Pages_Widget widget is in use. 30 if ( is_active_widget( false, false, WPorg_Handbook_Pages_Widget::get_widget_id_base(), true ) ) { 31 self::$using_pages_widget = true; 32 } 21 // Determine how handbook sidebar menu is defined 22 add_action( 'wp', [ __CLASS__, 'determine_handbook_sidebar_menu_source' ] ); 33 23 34 24 // Override o2 navigation defaults. 35 25 add_filter( 'o2_post_fragment', array( __CLASS__, 'o2_post_fragment' ), 10, 2 ); 26 } 27 28 /** 29 * Determines the source for the handbook sidebar menu. 30 * 31 * @return string|false The handbook sidebar menu source. Either 'menu_widget', 32 * 'handbook_pages_widget'. False if not on a handbook 33 * page. Empty string if no sidebar menu of its of an 34 * unrecognized source. 35 */ 36 public static function determine_handbook_sidebar_menu_source() { 37 // Bail early if not a handbook. 38 if ( ! $post_type = wporg_get_current_handbook() ) { 39 return false; 40 } 41 42 $menu_source = ''; 43 44 $sidebars = wp_get_sidebars_widgets(); 45 if ( $sidebars && isset( $sidebars[ $post_type ] ) ) { 46 foreach ( $sidebars[ $post_type ] as $widget ) { 47 $widget_base = _get_widget_id_base( $widget ); 48 if ( 'nav_menu' === $widget_base ) { 49 $menu_source = 'menu_widget'; 50 } elseif( 'handbook_pages' === $widget_base ) { 51 $menu_source = 'handbook_pages_widget'; 52 } 53 if ( $menu_source ) { 54 break; 55 } 56 } 57 } 58 59 return $menu_source; 36 60 } 37 61 … … 53 77 } 54 78 55 if ( self::$using_pages_widget) {79 if ( 'handbook_pages_widget' === self::determine_handbook_sidebar_menu_source() ) { 56 80 $adjacent = self::get_adjacent_posts_via_handbook_pages_widget( $post_id ); 57 81 } else { … … 94 118 $prev = $next = false; 95 119 96 if ( self::$using_pages_widget) {120 if ( 'handbook_pages_widget' === self::determine_handbook_sidebar_menu_source() ) { 97 121 $adjacent = self::get_adjacent_posts_via_handbook_pages_widget(); 98 122 } else {
Note: See TracChangeset
for help on using the changeset viewer.