Skip to content

Commit e63974c

Browse files
authored
Merge branch 'master' into fix-wp-customizer-preview
2 parents 493668d + c7abf4a commit e63974c

9 files changed

Lines changed: 747 additions & 222 deletions

.travis.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,14 @@ php:
1515
- 7.0
1616
- 7.1
1717
- 7.2
18+
- 7.3
1819
- nightly
1920

2021
env:
2122
- WP_VERSION=latest WP_MULTISITE=0
2223
- WP_VERSION=latest WP_MULTISITE=1
2324

2425
matrix:
25-
include:
26-
- dist: precise
27-
php: 5.3
28-
env: WP_VERSION=latest WP_MULTISITE=0
2926
allow_failures:
3027
- php: nightly
3128

@@ -41,9 +38,17 @@ before_script:
4138
- |
4239
composer global require wp-coding-standards/wpcs
4340
phpcs --config-set installed_paths $HOME/.composer/vendor/wp-coding-standards/wpcs
41+
- |
42+
if [[ ${TRAVIS_PHP_VERSION:0:3} == "7.3" ]]; then
43+
composer require "szepeviktor/phpstan-wordpress:^0.5.0"
44+
fi
4445
4546
script:
4647
- phpcs --standard=phpcs.ruleset.xml $(find -name "*.php")
48+
- |
49+
if [[ ${TRAVIS_PHP_VERSION:0:3} == "7.3" ]]; then
50+
vendor/bin/phpstan analyze
51+
fi
4752
- phpunit
4853

4954
cache:

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
#CHANGELOG
22

3+
## [4.3.0]
4+
- Added an `aria-current` item.
5+
- Added `.nav-item` for the `<li>` and `.nav-link` for the `<a>` in fallback function.
6+
- Some escape improvements.
7+
- Don't pass `$attributes` to element closing function as it's ignored anyway.
8+
39
## [4.2.0]
410
- Fix typo in function name 'seporate'->'separate' (private function, no need to add back-compat).
511

README.md

Lines changed: 61 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
[![Code Coverage](https://scrutinizer-ci.com/g/wp-bootstrap/wp-bootstrap-navwalker/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/wp-bootstrap/wp-bootstrap-navwalker/?branch=master)
99
[![Build Status](https://scrutinizer-ci.com/g/wp-bootstrap/wp-bootstrap-navwalker/badges/build.png?b=master)](https://scrutinizer-ci.com/g/wp-bootstrap/wp-bootstrap-navwalker/build-status/master)
1010

11+
**This code in the main repo branch is undergoing a big shakeup to bring it in line with recent standards and to merge and test the backlog of PRs I have left for too long. Please use the v4.3.0 tag for stable version while this process happens. https://github.com/wp-bootstrap/wp-bootstrap-navwalker/releases/tag/v4.3.0**
12+
1113
A custom WordPress Nav Walker Class to fully implement the Bootstrap 4 navigation style in a custom theme using the WordPress built in menu manager.
1214

1315
## NOTES
@@ -18,113 +20,120 @@ This is a utility class that is intended to format your WordPress theme menu wit
1820

1921
*This walker is fully compliant with all Theme Review guidelines for wordpress.org theme submission.* It requires no modification to be compliant but you can optionally replace the `wp-bootstrap-navwalker` text domain (which appears twice in the `fallback` function) with the text domain of your theme.
2022

21-
### UPGRADE NOTES ###
23+
### Upgrade Notes
2224

23-
Between version 3 and version 4 of the walker there have been significant changes to the codebase. Version 4 of the walker is built to work with Bootstrap 4 and has not been tested for backwards compatibility with Bootstrap 3. A separate branch for Bootstrap 3 is maintained here: https://github.com/wp-bootstrap/wp-bootstrap-navwalker/tree/v3-branch
25+
Between version 3 and version 4 of the walker there have been significant changes to the codebase. Version 4 of the walker is built to work with Bootstrap 4 and has not been tested for backwards compatibility with Bootstrap 3. A separate branch for Bootstrap 3 is maintained here: <https://github.com/wp-bootstrap/wp-bootstrap-navwalker/tree/v3-branch>
2426

2527
Here is a list of the most notable changes:
2628

2729
- The filename has been changed and prefixed with `class-` to better fit PHP coding standards naming conventions.
28-
- New Name: `class-wp-bootstrap-navwalker.php`
29-
- Old Name: `wp-bootstrap-navwalker.php`
30+
- New Name: `class-wp-bootstrap-navwalker.php`
31+
- Old Name: `wp-bootstrap-navwalker.php`
3032
- Icon and link modifier handling is now done through the `CSS Classes` menu item input instead of the `Title` input.
3133
- Icon only items are possible using icon classes in combination with the `sr-only` classname.
3234

3335
## Installation
3436

35-
Place **class-wp-bootstrap-navwalker.php** in your WordPress theme folder `/wp-content/your-theme/`
37+
Place **class-wp-bootstrap-navwalker.php** in your WordPress theme folder `/wp-content/themes/your-theme/`
3638

37-
Open your WordPress themes **functions.php** file - `/wp-content/your-theme/functions.php` - and add the following code:
39+
Open your WordPress themes **functions.php** file - `/wp-content/themes/your-theme/functions.php` - and add the following code:
3840

3941
```php
40-
// Register Custom Navigation Walker
41-
require_once get_template_directory() . '/class-wp-bootstrap-navwalker.php';
42+
/**
43+
* Register Custom Navigation Walker
44+
*/
45+
function register_navwalker(){
46+
require_once get_template_directory() . '/class-wp-bootstrap-navwalker.php';
47+
}
48+
add_action( 'after_setup_theme', 'register_navwalker' );
4249
```
4350

4451
If you encounter errors with the above code use a check like this to return clean errors to help diagnose the problem.
4552

4653
```php
4754
if ( ! file_exists( get_template_directory() . '/class-wp-bootstrap-navwalker.php' ) ) {
48-
// file does not exist... return an error.
49-
return new WP_Error( 'class-wp-bootstrap-navwalker-missing', __( 'It appears the class-wp-bootstrap-navwalker.php file may be missing.', 'wp-bootstrap-navwalker' ) );
55+
// File does not exist... return an error.
56+
return new WP_Error( 'class-wp-bootstrap-navwalker-missing', __( 'It appears the class-wp-bootstrap-navwalker.php file may be missing.', 'wp-bootstrap-navwalker' ) );
5057
} else {
51-
// file exists... require it.
52-
require_once get_template_directory() . '/class-wp-bootstrap-navwalker.php';
58+
// File exists... require it.
59+
require_once get_template_directory() . '/class-wp-bootstrap-navwalker.php';
5360
}
5461
```
62+
5563
You will also need to declare a new menu in your `functions.php` file if one doesn't already exist.
5664

5765
```php
5866
register_nav_menus( array(
59-
'primary' => __( 'Primary Menu', 'THEMENAME' ),
67+
'primary' => __( 'Primary Menu', 'THEMENAME' ),
6068
) );
6169
```
70+
6271
## Usage
6372

6473
Add or update any `wp_nav_menu()` functions in your theme (often found in `header.php`) to use the new walker by adding a `'walker'` item to the wp_nav_menu args array.
6574

6675
```php
6776
wp_nav_menu( array(
68-
'theme_location' => 'primary',
69-
'depth' => 2, // 1 = no dropdowns, 2 = with dropdowns.
70-
'container' => 'div',
71-
'container_class' => 'collapse navbar-collapse',
72-
'container_id' => 'bs-example-navbar-collapse-1',
73-
'menu_class' => 'navbar-nav mr-auto',
74-
'fallback_cb' => 'WP_Bootstrap_Navwalker::fallback',
75-
'walker' => new WP_Bootstrap_Navwalker(),
77+
'theme_location' => 'primary',
78+
'depth' => 2, // 1 = no dropdowns, 2 = with dropdowns.
79+
'container' => 'div',
80+
'container_class' => 'collapse navbar-collapse',
81+
'container_id' => 'bs-example-navbar-collapse-1',
82+
'menu_class' => 'navbar-nav mr-auto',
83+
'fallback_cb' => 'WP_Bootstrap_Navwalker::fallback',
84+
'walker' => new WP_Bootstrap_Navwalker(),
7685
) );
7786
```
7887

7988
Your menu will now be formatted with the correct syntax and classes to implement Bootstrap dropdown navigation.
8089

81-
Typically the menu is wrapped with additional markup, here is an example of a ` fixed-top` menu that collapse for responsive navigation at the md breakpoint.
90+
Typically the menu is wrapped with additional markup, here is an example of a `fixed-top` menu that collapse for responsive navigation at the md breakpoint.
8291

8392
```php
8493
<nav class="navbar navbar-expand-md navbar-light bg-light" role="navigation">
8594
<div class="container">
86-
<!-- Brand and toggle get grouped for better mobile display -->
87-
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-controls="bs-example-navbar-collapse-1" aria-expanded="false" aria-label="Toggle navigation">
88-
<span class="navbar-toggler-icon"></span>
89-
</button>
90-
<a class="navbar-brand" href="#">Navbar</a>
91-
<?php
92-
wp_nav_menu( array(
93-
'theme_location' => 'primary',
94-
'depth' => 2,
95-
'container' => 'div',
96-
'container_class' => 'collapse navbar-collapse',
97-
'container_id' => 'bs-example-navbar-collapse-1',
98-
'menu_class' => 'nav navbar-nav',
99-
'fallback_cb' => 'WP_Bootstrap_Navwalker::fallback',
100-
'walker' => new WP_Bootstrap_Navwalker(),
101-
) );
102-
?>
103-
</div>
95+
<!-- Brand and toggle get grouped for better mobile display -->
96+
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-controls="bs-example-navbar-collapse-1" aria-expanded="false" aria-label="<?php esc_attr_e( 'Toggle navigation', 'your-theme-slug' ); ?>">
97+
<span class="navbar-toggler-icon"></span>
98+
</button>
99+
<a class="navbar-brand" href="#">Navbar</a>
100+
<?php
101+
wp_nav_menu( array(
102+
'theme_location' => 'primary',
103+
'depth' => 2,
104+
'container' => 'div',
105+
'container_class' => 'collapse navbar-collapse',
106+
'container_id' => 'bs-example-navbar-collapse-1',
107+
'menu_class' => 'nav navbar-nav',
108+
'fallback_cb' => 'WP_Bootstrap_Navwalker::fallback',
109+
'walker' => new WP_Bootstrap_Navwalker(),
110+
) );
111+
?>
112+
</div>
104113
</nav>
105114
```
106115

107116
To change your menu style add Bootstrap nav class names to the `menu_class` declaration.
108117

109118
Review options in the Bootstrap docs for more information on [nav classes](https://getbootstrap.com/components/#nav).
110119

111-
112120
### Displaying the Menu
113121

114122
To display the menu you must associate your menu with your theme location. You can do this by selecting your theme location in the *Theme Locations* list while editing a menu in the WordPress menu manager.
115123

116-
### Making this Walker the Default Walker for Nav Manus
124+
### Making this Walker the Default Walker for Nav Menus
117125

118126
There has been some interest in making this walker the default walker for all menus. That could result in some unexpected situations but it can be achieved by adding this function to your functions.php file.
119127

120128
```php
121129
function prefix_modify_nav_menu_args( $args ) {
122-
return array_merge( $args, array(
123-
'walker' => WP_Bootstrap_Navwalker(),
124-
) );
130+
return array_merge( $args, array(
131+
'walker' => new WP_Bootstrap_Navwalker(),
132+
) );
125133
}
126134
add_filter( 'wp_nav_menu_args', 'prefix_modify_nav_menu_args' );
127135
```
136+
128137
Simply updating the walker may not be enough to get menus working right, you may need to add wrappers or additional classes, you can do that via the above function as well.
129138

130139
### Menu Caching
@@ -133,31 +142,32 @@ On some sites generating a large menu that rarely ever changes on every page req
133142

134143
The biggest drawback to caching nav menus with this method is that it cannot easily apply the `.current-menu-item` or the `.active` class to the currently active item as WP decides what is currently active on page load - and since the menu is cached it only knows the active page that it was cached on originally.
135144

136-
You can decide yourself if you want to put up with those drawbacks for the benefit of removing the menu generation time on most page loads. You can follow this article by Dave Clements to see how we cached nav menus that were generated by this walker: https://www.doitwithwp.com/use-transients-speed-wordpress-menus/
145+
You can decide yourself if you want to put up with those drawbacks for the benefit of removing the menu generation time on most page loads. You can follow this article by Dave Clements to see how we cached nav menus that were generated by this walker: <https://www.doitwithwp.com/use-transients-speed-wordpress-menus/>
137146

138147
Be sure to set the `echo` argument to FALSE in `the wp_nav_menu()` call when doing this so that the results can be stored instead of echoed to the page.
139148

140149
See also:
141-
- https://generatewp.com/how-to-use-transients-to-speed-up-wordpress-menus/
142-
- https://vip-svn.wordpress.com/plugins/cache-nav-menu/cache-nav-menu.php
150+
151+
- <https://generatewp.com/how-to-use-transients-to-speed-up-wordpress-menus/>
152+
- <https://vip-svn.wordpress.com/plugins/cache-nav-menu/cache-nav-menu.php>
143153

144154
### Extras
145155

146156
This script included the ability to use Bootstrap nav link mods in your menus through the WordPress menu UI. Disabled links, dropdown headers and dropdown dividers are supported. Additionally icon support is built-in for Glyphicons and Font Awesome (note: you will need to include the icon stylesheets or assets separately).
147157

148158
#### Icons
149159

150-
To add an Icon to your link simply enter Glypicons or Font Awesome class names in the links **CSS Classes** field in the Menu UI and the walker class will do the rest. IE `glyphicons glyphicons-bullhorn` or `fa fa-arrow-left` or `fas fa-arrow-left`.
160+
To add an Icon to your link simply enter Glyphicons or Font Awesome class names in the links **CSS Classes** field in the Menu UI and the walker class will do the rest. IE `glyphicons glyphicons-bullhorn` or `fa fa-arrow-left` or `fas fa-arrow-left`.
151161

152162
#### Icon-Only Items
153163

154164
To make an item appear with the icon only apply the bootstrap screen reader class `sr-only` to the item alongside any icon classnames. This will then hide only the text that would appear as the link text.
155165

156166
#### Disabled Links
157167

158-
To set a disabled link simply add `disabled` to the **CSS Classes** field in the Menu UI and the walker class will do the rest. _Note: In addition to adding the .disabled class this will change the link `href` to `#` as well so that it is not a followable link._
168+
To set a disabled link simply add `disabled` to the **CSS Classes** field in the Menu UI and the walker class will do the rest. _Note: In addition to adding the .disabled class this will change the link `href` to `#` as well so that it is not a follow-able link._
159169

160-
#### Dropdown Headers, Dropdown Dividers & Dropdown Item Text.
170+
#### Dropdown Headers, Dropdown Dividers & Dropdown Item Text
161171

162172
Headers, dividers and text only items can be added within dropdowns by adding a Custom Link and adding either `dropdown-header`, `dropdown-divider` or `dropdown-item-text` into the **CSS Classes** input. _Note: This will remove the `href` on the item and change it to either a `<span>` for headers or a `<div>` for dividers._
163173

0 commit comments

Comments
 (0)