sewmyheadon /
spurs
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * WP Bootstrap Navwalker |
||
| 4 | * |
||
| 5 | * @package WP-Bootstrap-Navwalker |
||
| 6 | */ |
||
| 7 | |||
| 8 | // Exit if accessed directly. |
||
| 9 | defined( 'ABSPATH' ) || exit; |
||
| 10 | |||
| 11 | /* |
||
| 12 | * Class Name: WP_Bootstrap_Navwalker |
||
| 13 | * Plugin Name: WP Bootstrap Navwalker |
||
| 14 | * Plugin URI: https://github.com/wp-bootstrap/wp-bootstrap-navwalker |
||
| 15 | * Description: A custom WordPress nav walker class to implement the Bootstrap 4 navigation style in a custom theme using the WordPress built in menu manager. |
||
| 16 | * Author: Edward McIntyre - @twittem, WP Bootstrap, William Patton - @pattonwebz |
||
| 17 | * Version: 4.1.0 |
||
| 18 | * Author URI: https://github.com/wp-bootstrap |
||
| 19 | * GitHub Plugin URI: https://github.com/wp-bootstrap/wp-bootstrap-navwalker |
||
| 20 | * GitHub Branch: master |
||
| 21 | * License: GPL-3.0+ |
||
| 22 | * License URI: http://www.gnu.org/licenses/gpl-3.0.txt |
||
| 23 | */ |
||
| 24 | |||
| 25 | /* Check if Class Exists. */ |
||
| 26 | if ( ! class_exists( 'Spurs_WP_Bootstrap_Navwalker' ) ) { |
||
| 27 | /** |
||
| 28 | * WP_Bootstrap_Navwalker class. |
||
| 29 | * |
||
| 30 | * @extends Walker_Nav_Menu |
||
| 31 | */ |
||
| 32 | class Spurs_WP_Bootstrap_Navwalker extends Walker_Nav_Menu { |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Starts the list before the elements are added. |
||
| 36 | * |
||
| 37 | * @param string $output Used to append additional content (passed by reference). |
||
| 38 | * @param int $depth Depth of menu item. Used for padding. |
||
| 39 | * @param stdClass $args An object of wp_nav_menu() arguments. |
||
|
0 ignored issues
–
show
|
|||
| 40 | * |
||
| 41 | * @see Walker_Nav_Menu::start_lvl() |
||
| 42 | * |
||
| 43 | * @since WP 3.0.0 |
||
| 44 | * |
||
| 45 | */ |
||
| 46 | public function start_lvl( &$output, $depth = 0, $args = array() ) { |
||
| 47 | View Code Duplication | if ( isset( $args->item_spacing ) && 'discard' === $args->item_spacing ) { |
|
| 48 | $t = ''; |
||
| 49 | $n = ''; |
||
| 50 | } else { |
||
| 51 | $t = "\t"; |
||
| 52 | $n = "\n"; |
||
| 53 | } |
||
| 54 | $indent = str_repeat( $t, $depth ); |
||
| 55 | // Default class to add to the file. |
||
| 56 | $classes = array( 'dropdown-menu' ); |
||
| 57 | /** |
||
| 58 | * Filters the CSS class(es) applied to a menu list element. |
||
| 59 | * |
||
| 60 | * @param array $classes The CSS classes that are applied to the menu `<ul>` element. |
||
| 61 | * @param stdClass $args An object of `wp_nav_menu()` arguments. |
||
| 62 | * @param int $depth Depth of menu item. Used for padding. |
||
| 63 | * |
||
| 64 | * @since WP 4.8.0 |
||
| 65 | * |
||
| 66 | */ |
||
| 67 | $class_names = join( ' ', apply_filters( 'nav_menu_submenu_css_class', $classes, $args, $depth ) ); |
||
| 68 | $class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : ''; |
||
| 69 | /** |
||
| 70 | * The `.dropdown-menu` container needs to have a labelledby |
||
| 71 | * attribute which points to it's trigger link. |
||
| 72 | * |
||
| 73 | * Form a string for the labelledby attribute from the the latest |
||
| 74 | * link with an id that was added to the $output. |
||
| 75 | */ |
||
| 76 | $labelledby = ''; |
||
| 77 | // find all links with an id in the output. |
||
| 78 | preg_match_all( '/(<a.*?id=\"|\')(.*?)\"|\'.*?>/im', $output, $matches ); |
||
| 79 | // with pointer at end of array check if we got an ID match. |
||
| 80 | if ( end( $matches[2] ) ) { |
||
| 81 | // build a string to use as aria-labelledby. |
||
| 82 | $labelledby = 'aria-labelledby="' . end( $matches[2] ) . '"'; |
||
| 83 | } |
||
| 84 | $output .= "{$n}{$indent}<ul$class_names $labelledby role=\"menu\">{$n}"; |
||
| 85 | } |
||
| 86 | |||
| 87 | /** |
||
| 88 | * Starts the element output. |
||
| 89 | * |
||
| 90 | * @param string $output Used to append additional content (passed by reference). |
||
| 91 | * @param WP_Post $item Menu item data object. |
||
| 92 | * @param int $depth Depth of menu item. Used for padding. |
||
| 93 | * @param stdClass $args An object of wp_nav_menu() arguments. |
||
|
0 ignored issues
–
show
Should the type for parameter
$args not be stdClass|array? Also, consider making the array more specific, something like array<String>, or String[].
This check looks for It makes a suggestion as to what type it considers more descriptive. In addition it
looks for parameters that have the generic type Most often this is a case of a parameter that can be null in addition to its declared types. Loading history...
|
|||
| 94 | * @param int $id Current item ID. |
||
| 95 | * |
||
| 96 | * @see Walker_Nav_Menu::start_el() |
||
| 97 | * |
||
| 98 | * @since WP 3.0.0 |
||
| 99 | * @since WP 4.4.0 The {@see 'nav_menu_item_args'} filter was added. |
||
| 100 | * |
||
| 101 | */ |
||
| 102 | public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) { |
||
| 103 | View Code Duplication | if ( isset( $args->item_spacing ) && 'discard' === $args->item_spacing ) { |
|
| 104 | $t = ''; |
||
| 105 | $n = ''; |
||
| 106 | } else { |
||
| 107 | $t = "\t"; |
||
| 108 | $n = "\n"; |
||
| 109 | } |
||
| 110 | $indent = ( $depth ) ? str_repeat( $t, $depth ) : ''; |
||
| 111 | |||
| 112 | $classes = empty( $item->classes ) ? array() : (array) $item->classes; |
||
| 113 | |||
| 114 | // Initialize some holder variables to store specially handled item |
||
| 115 | // wrappers and icons. |
||
| 116 | $linkmod_classes = array(); |
||
| 117 | $icon_classes = array(); |
||
| 118 | |||
| 119 | /** |
||
| 120 | * Get an updated $classes array without linkmod or icon classes. |
||
| 121 | * |
||
| 122 | * NOTE: linkmod and icon class arrays are passed by reference and |
||
| 123 | * are maybe modified before being used later in this function. |
||
| 124 | */ |
||
| 125 | $classes = self::seporate_linkmods_and_icons_from_classes( $classes, $linkmod_classes, $icon_classes, $depth ); |
||
| 126 | |||
| 127 | // Join any icon classes plucked from $classes into a string. |
||
| 128 | $icon_class_string = join( ' ', $icon_classes ); |
||
| 129 | |||
| 130 | /** |
||
| 131 | * Filters the arguments for a single nav menu item. |
||
| 132 | * |
||
| 133 | * WP 4.4.0 |
||
| 134 | * |
||
| 135 | * @param stdClass $args An object of wp_nav_menu() arguments. |
||
| 136 | * @param WP_Post $item Menu item data object. |
||
| 137 | * @param int $depth Depth of menu item. Used for padding. |
||
| 138 | */ |
||
| 139 | $args = apply_filters( 'nav_menu_item_args', $args, $item, $depth ); |
||
| 140 | |||
| 141 | // Add .dropdown or .active classes where they are needed. |
||
| 142 | if ( isset( $args->has_children ) && $args->has_children ) { |
||
| 143 | $classes[] = 'dropdown'; |
||
| 144 | } |
||
| 145 | if ( in_array( 'current-menu-item', $classes, true ) || in_array( 'current-menu-parent', $classes, true ) ) { |
||
| 146 | $classes[] = 'active'; |
||
| 147 | } |
||
| 148 | |||
| 149 | // Add some additional default classes to the item. |
||
| 150 | $classes[] = 'menu-item-' . $item->ID; |
||
| 151 | $classes[] = 'nav-item'; |
||
| 152 | |||
| 153 | // Allow filtering the classes. |
||
| 154 | $classes = apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args, $depth ); |
||
| 155 | |||
| 156 | // Form a string of classes in format: class="class_names". |
||
| 157 | $class_names = join( ' ', $classes ); |
||
| 158 | $class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : ''; |
||
| 159 | |||
| 160 | /** |
||
| 161 | * Filters the ID applied to a menu item's list item element. |
||
| 162 | * |
||
| 163 | * @param string $menu_id The ID that is applied to the menu item's `<li>` element. |
||
| 164 | * @param WP_Post $item The current menu item. |
||
| 165 | * @param stdClass $args An object of wp_nav_menu() arguments. |
||
| 166 | * @param int $depth Depth of menu item. Used for padding. |
||
| 167 | * |
||
| 168 | * @since WP 3.0.1 |
||
| 169 | * @since WP 4.1.0 The `$depth` parameter was added. |
||
| 170 | * |
||
| 171 | */ |
||
| 172 | $id = apply_filters( 'nav_menu_item_id', 'menu-item-' . $item->ID, $item, $args, $depth ); |
||
| 173 | $id = $id ? ' id="' . esc_attr( $id ) . '"' : ''; |
||
| 174 | |||
| 175 | $output .= $indent . '<li itemscope="itemscope" itemtype="https://www.schema.org/SiteNavigationElement"' . $id . $class_names . '>'; |
||
| 176 | |||
| 177 | // initialize array for holding the $atts for the link item. |
||
| 178 | $atts = array(); |
||
| 179 | |||
| 180 | // Set title from item to the $atts array - if title is empty then |
||
| 181 | // default to item title. |
||
| 182 | if ( empty( $item->attr_title ) ) { |
||
| 183 | $atts['title'] = ! empty( $item->title ) ? strip_tags( $item->title ) : ''; |
||
| 184 | } else { |
||
| 185 | $atts['title'] = $item->attr_title; |
||
| 186 | } |
||
| 187 | |||
| 188 | $atts['target'] = ! empty( $item->target ) ? $item->target : ''; |
||
| 189 | if ( '_blank' === $item->target && empty( $item->xfn ) ) { // Thanks to LukaszJaro, see https://github.com/understrap/understrap/issues/973 |
||
| 190 | $atts['rel'] = 'noopener noreferrer'; |
||
| 191 | } else { |
||
| 192 | $atts['rel'] = $item->xfn; |
||
| 193 | } |
||
| 194 | |||
| 195 | // If item has_children add atts to <a>. |
||
| 196 | if ( isset( $args->has_children ) && $args->has_children && 0 === $depth && $args->depth > 1 ) { |
||
| 197 | $atts['href'] = '#'; |
||
| 198 | $atts['data-toggle'] = 'dropdown'; |
||
| 199 | $atts['aria-haspopup'] = 'true'; |
||
| 200 | $atts['aria-expanded'] = 'false'; |
||
| 201 | $atts['class'] = 'dropdown-toggle nav-link'; |
||
| 202 | $atts['id'] = 'menu-item-dropdown-' . $item->ID; |
||
| 203 | } else { |
||
| 204 | $atts['href'] = ! empty( $item->url ) ? $item->url : '#'; |
||
| 205 | // Items in dropdowns use .dropdown-item instead of .nav-link. |
||
| 206 | if ( $depth > 0 ) { |
||
| 207 | $atts['class'] = 'dropdown-item'; |
||
| 208 | } else { |
||
| 209 | $atts['class'] = 'nav-link'; |
||
| 210 | } |
||
| 211 | } |
||
| 212 | |||
| 213 | // update atts of this item based on any custom linkmod classes. |
||
| 214 | $atts = self::update_atts_for_linkmod_type( $atts, $linkmod_classes ); |
||
| 215 | // Allow filtering of the $atts array before using it. |
||
| 216 | $atts = apply_filters( 'nav_menu_link_attributes', $atts, $item, $args, $depth ); |
||
| 217 | |||
| 218 | // Build a string of html containing all the atts for the item. |
||
| 219 | $attributes = ''; |
||
| 220 | foreach ( $atts as $attr => $value ) { |
||
| 221 | if ( ! empty( $value ) ) { |
||
| 222 | $value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value ); |
||
| 223 | $attributes .= ' ' . $attr . '="' . $value . '"'; |
||
| 224 | } |
||
| 225 | } |
||
| 226 | |||
| 227 | /** |
||
| 228 | * Set a typeflag to easily test if this is a linkmod or not. |
||
| 229 | */ |
||
| 230 | $linkmod_type = self::get_linkmod_type( $linkmod_classes ); |
||
| 231 | |||
| 232 | /** |
||
| 233 | * START appending the internal item contents to the output. |
||
| 234 | */ |
||
| 235 | $item_output = isset( $args->before ) ? $args->before : ''; |
||
| 236 | /** |
||
| 237 | * This is the start of the internal nav item. Depending on what |
||
| 238 | * kind of linkmod we have we may need different wrapper elements. |
||
| 239 | */ |
||
| 240 | if ( '' !== $linkmod_type ) { |
||
| 241 | // is linkmod, output the required element opener. |
||
| 242 | $item_output .= self::linkmod_element_open( $linkmod_type, $attributes ); |
||
| 243 | } else { |
||
| 244 | // With no link mod type set this must be a standard <a> tag. |
||
| 245 | $item_output .= '<a' . $attributes . '>'; |
||
| 246 | } |
||
| 247 | |||
| 248 | /** |
||
| 249 | * Initiate empty icon var, then if we have a string containing any |
||
| 250 | * icon classes form the icon markup with an <i> element. This is |
||
| 251 | * output inside of the item before the $title (the link text). |
||
| 252 | */ |
||
| 253 | $icon_html = ''; |
||
| 254 | if ( ! empty( $icon_class_string ) ) { |
||
| 255 | // append an <i> with the icon classes to what is output before links. |
||
| 256 | $icon_html = '<i class="' . esc_attr( $icon_class_string ) . '" aria-hidden="true"></i> '; |
||
| 257 | } |
||
| 258 | |||
| 259 | /** This filter is documented in wp-includes/post-template.php */ |
||
| 260 | $title = apply_filters( 'the_title', $item->title, $item->ID ); |
||
| 261 | |||
| 262 | /** |
||
| 263 | * Filters a menu item's title. |
||
| 264 | * |
||
| 265 | * @param string $title The menu item's title. |
||
| 266 | * @param WP_Post $item The current menu item. |
||
| 267 | * @param stdClass $args An object of wp_nav_menu() arguments. |
||
| 268 | * @param int $depth Depth of menu item. Used for padding. |
||
| 269 | * |
||
| 270 | * @since WP 4.4.0 |
||
| 271 | * |
||
| 272 | */ |
||
| 273 | $title = apply_filters( 'nav_menu_item_title', $title, $item, $args, $depth ); |
||
| 274 | |||
| 275 | /** |
||
| 276 | * If the .sr-only class was set apply to the nav items text only. |
||
| 277 | */ |
||
| 278 | if ( in_array( 'sr-only', $linkmod_classes, true ) ) { |
||
| 279 | $title = self::wrap_for_screen_reader( $title ); |
||
| 280 | $keys_to_unset = array_keys( $linkmod_classes, 'sr-only' ); |
||
| 281 | foreach ( $keys_to_unset as $k ) { |
||
| 282 | unset( $linkmod_classes[ $k ] ); |
||
| 283 | } |
||
| 284 | } |
||
| 285 | |||
| 286 | // Put the item contents into $output. |
||
| 287 | $item_output .= isset( $args->link_before ) ? $args->link_before . $icon_html . $title . $args->link_after : ''; |
||
| 288 | /** |
||
| 289 | * This is the end of the internal nav item. We need to close the |
||
| 290 | * correct element depending on the type of link or link mod. |
||
| 291 | */ |
||
| 292 | if ( '' !== $linkmod_type ) { |
||
| 293 | // is linkmod, output the required element opener. |
||
| 294 | $item_output .= self::linkmod_element_close( $linkmod_type, $attributes ); |
||
| 295 | } else { |
||
| 296 | // With no link mod type set this must be a standard <a> tag. |
||
| 297 | $item_output .= '</a>'; |
||
| 298 | } |
||
| 299 | |||
| 300 | $item_output .= isset( $args->after ) ? $args->after : ''; |
||
| 301 | |||
| 302 | /** |
||
| 303 | * END appending the internal item contents to the output. |
||
| 304 | */ |
||
| 305 | $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ); |
||
| 306 | |||
| 307 | } |
||
| 308 | |||
| 309 | /** |
||
| 310 | * Traverse elements to create list from elements. |
||
| 311 | * |
||
| 312 | * Display one element if the element doesn't have any children otherwise, |
||
| 313 | * display the element and its children. Will only traverse up to the max |
||
| 314 | * depth and no ignore elements under that depth. It is possible to set the |
||
| 315 | * max depth to include all depths, see walk() method. |
||
| 316 | * |
||
| 317 | * This method should not be called directly, use the walk() method instead. |
||
| 318 | * |
||
| 319 | * @param object $element Data object. |
||
| 320 | * @param array $children_elements List of elements to continue traversing (passed by reference). |
||
| 321 | * @param int $max_depth Max depth to traverse. |
||
| 322 | * @param int $depth Depth of current element. |
||
| 323 | * @param array $args An array of arguments. |
||
| 324 | * @param string $output Used to append additional content (passed by reference). |
||
| 325 | * |
||
| 326 | * @since WP 2.5.0 |
||
| 327 | * |
||
| 328 | * @see Walker::start_lvl() |
||
| 329 | * |
||
| 330 | */ |
||
| 331 | public function display_element( $element, &$children_elements, $max_depth, $depth, $args, &$output ) { |
||
| 332 | if ( ! $element ) { |
||
| 333 | return; |
||
| 334 | } |
||
| 335 | $id_field = $this->db_fields['id']; |
||
| 336 | // Display this element. |
||
| 337 | if ( is_object( $args[0] ) ) { |
||
| 338 | $args[0]->has_children = ! empty( $children_elements[ $element->$id_field ] ); |
||
| 339 | } |
||
| 340 | parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output ); |
||
| 341 | } |
||
| 342 | |||
| 343 | /** |
||
| 344 | * Menu Fallback |
||
| 345 | * ============= |
||
| 346 | * If this function is assigned to the wp_nav_menu's fallback_cb variable |
||
| 347 | * and a menu has not been assigned to the theme location in the WordPress |
||
| 348 | * menu manager the function with display nothing to a non-logged in user, |
||
| 349 | * and will add a link to the WordPress menu manager if logged in as an admin. |
||
| 350 | * |
||
| 351 | * @param array $args passed from the wp_nav_menu function. |
||
| 352 | * |
||
| 353 | * @return null|string |
||
| 354 | */ |
||
| 355 | public static function fallback( $args ) { |
||
| 356 | if ( current_user_can( 'edit_theme_options' ) ) { |
||
| 357 | |||
| 358 | /* Get Arguments. */ |
||
| 359 | $container = $args['container']; |
||
| 360 | $container_id = $args['container_id']; |
||
| 361 | $container_class = $args['container_class']; |
||
| 362 | $menu_class = $args['menu_class']; |
||
| 363 | $menu_id = $args['menu_id']; |
||
| 364 | |||
| 365 | // initialize var to store fallback html. |
||
| 366 | $fallback_output = ''; |
||
| 367 | |||
| 368 | if ( $container ) { |
||
| 369 | $fallback_output .= '<' . esc_attr( $container ); |
||
| 370 | if ( $container_id ) { |
||
| 371 | $fallback_output .= ' id="' . esc_attr( $container_id ) . '"'; |
||
| 372 | } |
||
| 373 | if ( $container_class ) { |
||
| 374 | $fallback_output .= ' class="' . esc_attr( $container_class ) . '"'; |
||
| 375 | } |
||
| 376 | $fallback_output .= '>'; |
||
| 377 | } |
||
| 378 | $fallback_output .= '<ul'; |
||
| 379 | if ( $menu_id ) { |
||
| 380 | $fallback_output .= ' id="' . esc_attr( $menu_id ) . '"'; |
||
| 381 | } |
||
| 382 | if ( $menu_class ) { |
||
| 383 | $fallback_output .= ' class="' . esc_attr( $menu_class ) . '"'; |
||
| 384 | } |
||
| 385 | $fallback_output .= '>'; |
||
| 386 | $fallback_output .= '<li><a href="' . esc_url( admin_url( 'nav-menus.php' ) ) . '" title="' . esc_attr__( 'Add a menu', 'sp' ) . '">' . esc_html__( 'Add a menu', 'sp' ) . '</a></li>'; |
||
| 387 | $fallback_output .= '</ul>'; |
||
| 388 | if ( $container ) { |
||
| 389 | $fallback_output .= '</' . esc_attr( $container ) . '>'; |
||
| 390 | } |
||
| 391 | |||
| 392 | // if $args has 'echo' key and it's true echo, otherwise return. |
||
| 393 | if ( array_key_exists( 'echo', $args ) && $args['echo'] ) { |
||
| 394 | echo $fallback_output; // WPCS: XSS OK. |
||
| 395 | } else { |
||
| 396 | return $fallback_output; |
||
| 397 | } |
||
| 398 | } |
||
| 399 | } |
||
| 400 | |||
| 401 | /** |
||
| 402 | * Find any custom linkmod or icon classes and store in their holder |
||
| 403 | * arrays then remove them from the main classes array. |
||
| 404 | * |
||
| 405 | * Supported linkmods: .disabled, .dropdown-header, .dropdown-divider, .sr-only |
||
| 406 | * Supported iconsets: Font Awesome 4/5, Glypicons |
||
| 407 | * |
||
| 408 | * NOTE: This accepts the linkmod and icon arrays by reference. |
||
| 409 | * |
||
| 410 | * @param array $classes an array of classes currently assigned to the item. |
||
| 411 | * @param array $linkmod_classes an array to hold linkmod classes. |
||
| 412 | * @param array $icon_classes an array to hold icon classes. |
||
| 413 | * @param integer $depth an integer holding current depth level. |
||
| 414 | * |
||
| 415 | * @return array $classes a maybe modified array of classnames. |
||
| 416 | * @since 4.0.0 |
||
| 417 | * |
||
| 418 | */ |
||
| 419 | private function seporate_linkmods_and_icons_from_classes( $classes, &$linkmod_classes, &$icon_classes, $depth ) { |
||
| 420 | // Loop through $classes array to find linkmod or icon classes. |
||
| 421 | foreach ( $classes as $key => $class ) { |
||
| 422 | // If any special classes are found, store the class in it's |
||
| 423 | // holder array and and unset the item from $classes. |
||
| 424 | if ( preg_match( '/^disabled|^sr-only/i', $class ) ) { |
||
| 425 | // Test for .disabled or .sr-only classes. |
||
| 426 | $linkmod_classes[] = $class; |
||
| 427 | unset( $classes[ $key ] ); |
||
| 428 | } elseif ( preg_match( '/^dropdown-header|^dropdown-divider|^dropdown-item-text/i', $class ) && $depth > 0 ) { |
||
| 429 | // Test for .dropdown-header or .dropdown-divider and a |
||
| 430 | // depth greater than 0 - IE inside a dropdown. |
||
| 431 | $linkmod_classes[] = $class; |
||
| 432 | unset( $classes[ $key ] ); |
||
| 433 | } elseif ( preg_match( '/^fa-(\S*)?|^fa(s|r|l|b)?(\s?)?$/i', $class ) ) { |
||
| 434 | // Font Awesome. |
||
| 435 | $icon_classes[] = $class; |
||
| 436 | unset( $classes[ $key ] ); |
||
| 437 | } elseif ( preg_match( '/^glyphicon-(\S*)?|^glyphicon(\s?)$/i', $class ) ) { |
||
| 438 | // Glyphicons. |
||
| 439 | $icon_classes[] = $class; |
||
| 440 | unset( $classes[ $key ] ); |
||
| 441 | } |
||
| 442 | } |
||
| 443 | |||
| 444 | return $classes; |
||
| 445 | } |
||
| 446 | |||
| 447 | /** |
||
| 448 | * Return a string containing a linkmod type and update $atts array |
||
| 449 | * accordingly depending on the decided. |
||
| 450 | * |
||
| 451 | * @param array $linkmod_classes array of any link modifier classes. |
||
| 452 | * |
||
| 453 | * @return string empty for default, a linkmod type string otherwise. |
||
| 454 | * @since 4.0.0 |
||
| 455 | * |
||
| 456 | */ |
||
| 457 | private function get_linkmod_type( $linkmod_classes = array() ) { |
||
| 458 | $linkmod_type = ''; |
||
| 459 | // Loop through array of linkmod classes to handle their $atts. |
||
| 460 | if ( ! empty( $linkmod_classes ) ) { |
||
| 461 | foreach ( $linkmod_classes as $link_class ) { |
||
| 462 | if ( ! empty( $link_class ) ) { |
||
| 463 | |||
| 464 | // check for special class types and set a flag for them. |
||
| 465 | if ( 'dropdown-header' === $link_class ) { |
||
| 466 | $linkmod_type = 'dropdown-header'; |
||
| 467 | } elseif ( 'dropdown-divider' === $link_class ) { |
||
| 468 | $linkmod_type = 'dropdown-divider'; |
||
| 469 | } elseif ( 'dropdown-item-text' === $link_class ) { |
||
| 470 | $linkmod_type = 'dropdown-item-text'; |
||
| 471 | } |
||
| 472 | } |
||
| 473 | } |
||
| 474 | } |
||
| 475 | |||
| 476 | return $linkmod_type; |
||
| 477 | } |
||
| 478 | |||
| 479 | /** |
||
| 480 | * Update the attributes of a nav item depending on the limkmod classes. |
||
| 481 | * |
||
| 482 | * @param array $atts array of atts for the current link in nav item. |
||
| 483 | * @param array $linkmod_classes an array of classes that modify link or nav item behaviors or displays. |
||
| 484 | * |
||
| 485 | * @return array maybe updated array of attributes for item. |
||
| 486 | * @since 4.0.0 |
||
| 487 | * |
||
| 488 | */ |
||
| 489 | private function update_atts_for_linkmod_type( $atts = array(), $linkmod_classes = array() ) { |
||
| 490 | if ( ! empty( $linkmod_classes ) ) { |
||
| 491 | foreach ( $linkmod_classes as $link_class ) { |
||
| 492 | if ( ! empty( $link_class ) ) { |
||
| 493 | // update $atts with a space and the extra classname... |
||
| 494 | // so long as it's not a sr-only class. |
||
| 495 | if ( 'sr-only' !== $link_class ) { |
||
| 496 | $atts['class'] .= ' ' . esc_attr( $link_class ); |
||
| 497 | } |
||
| 498 | // check for special class types we need additional handling for. |
||
| 499 | if ( 'disabled' === $link_class ) { |
||
| 500 | // Convert link to '#' and unset open targets. |
||
| 501 | $atts['href'] = '#'; |
||
| 502 | unset( $atts['target'] ); |
||
| 503 | } elseif ( 'dropdown-header' === $link_class || 'dropdown-divider' === $link_class || 'dropdown-item-text' === $link_class ) { |
||
| 504 | // Store a type flag and unset href and target. |
||
| 505 | unset( $atts['href'] ); |
||
| 506 | unset( $atts['target'] ); |
||
| 507 | } |
||
| 508 | } |
||
| 509 | } |
||
| 510 | } |
||
| 511 | |||
| 512 | return $atts; |
||
| 513 | } |
||
| 514 | |||
| 515 | /** |
||
| 516 | * Wraps the passed text in a screen reader only class. |
||
| 517 | * |
||
| 518 | * @param string $text the string of text to be wrapped in a screen reader class. |
||
| 519 | * |
||
| 520 | * @return string the string wrapped in a span with the class. |
||
| 521 | * @since 4.0.0 |
||
| 522 | * |
||
| 523 | */ |
||
| 524 | private function wrap_for_screen_reader( $text = '' ) { |
||
| 525 | if ( $text ) { |
||
| 526 | $text = '<span class="sr-only">' . $text . '</span>'; |
||
| 527 | } |
||
| 528 | |||
| 529 | return $text; |
||
| 530 | } |
||
| 531 | |||
| 532 | /** |
||
| 533 | * Returns the correct opening element and attributes for a linkmod. |
||
| 534 | * |
||
| 535 | * @param string $linkmod_type a sting containing a linkmod type flag. |
||
| 536 | * @param string $attributes a string of attributes to add to the element. |
||
| 537 | * |
||
| 538 | * @return string a string with the openign tag for the element with attribibutes added. |
||
| 539 | * @since 4.0.0 |
||
| 540 | * |
||
| 541 | */ |
||
| 542 | private function linkmod_element_open( $linkmod_type, $attributes = '' ) { |
||
| 543 | $output = ''; |
||
| 544 | if ( 'dropdown-item-text' === $linkmod_type ) { |
||
| 545 | $output .= '<span class="dropdown-item-text"' . $attributes . '>'; |
||
| 546 | } elseif ( 'dropdown-header' === $linkmod_type ) { |
||
| 547 | // For a header use a span with the .h6 class instead of a real |
||
| 548 | // header tag so that it doesn't confuse screen readers. |
||
| 549 | $output .= '<span class="dropdown-header h6"' . $attributes . '>'; |
||
| 550 | } elseif ( 'dropdown-divider' === $linkmod_type ) { |
||
| 551 | // this is a divider. |
||
| 552 | $output .= '<div class="dropdown-divider"' . $attributes . '>'; |
||
| 553 | } |
||
| 554 | |||
| 555 | return $output; |
||
| 556 | } |
||
| 557 | |||
| 558 | /** |
||
| 559 | * Return the correct closing tag for the linkmod element. |
||
| 560 | * |
||
| 561 | * @param string $linkmod_type a string containing a special linkmod type. |
||
| 562 | * |
||
| 563 | * @return string a string with the closing tag for this linkmod type. |
||
| 564 | * @since 4.0.0 |
||
| 565 | * |
||
| 566 | */ |
||
| 567 | private function linkmod_element_close( $linkmod_type ) { |
||
| 568 | $output = ''; |
||
| 569 | if ( 'dropdown-header' === $linkmod_type || 'dropdown-item-text' === $linkmod_type ) { |
||
| 570 | // For a header use a span with the .h6 class instead of a real |
||
| 571 | // header tag so that it doesn't confuse screen readers. |
||
| 572 | $output .= '</span>'; |
||
| 573 | } elseif ( 'dropdown-divider' === $linkmod_type ) { |
||
| 574 | // this is a divider. |
||
| 575 | $output .= '</div>'; |
||
| 576 | } |
||
| 577 | |||
| 578 | return $output; |
||
| 579 | } |
||
| 580 | } |
||
| 581 | } |
||
| 582 |
This check looks for
@paramannotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive. In addition it looks for parameters that have the generic type
arrayand suggests a stricter type likearray<String>.Most often this is a case of a parameter that can be null in addition to its declared types.