Skip to content

Commit

Permalink
Merge branch 'master' into update/change-composer-package-type
Browse files Browse the repository at this point in the history
  • Loading branch information
pattonwebz committed Jan 20, 2018
2 parents d84220a + c98c669 commit 4c2ae91
Show file tree
Hide file tree
Showing 7 changed files with 249 additions and 173 deletions.
24 changes: 18 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
language: php
dist: trusty

notifications:
email:
Expand All @@ -10,24 +11,31 @@ branches:
- master

php:
- 5.3
- 5.6
- 7.0
- nightly

env:
- WP_VERSION=latest WP_MULTISITE=0
- WP_VERSION=latest WP_MULTISITE=1

matrix:
include:
- php: 5.3
- dist: precise
php: 5.3
env: WP_VERSION=latest WP_MULTISITE=0
- dist: precise
php: 5.3
env: WP_VERSION=latest WP_MULTISITE=1
allow_failures:
- php: nightly

before_script:
- bash bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION
- bash bin/install-wp-tests.sh wordpress_test root "" localhost $WP_VERSION
- export PATH="$HOME/.composer/vendor/bin:$PATH"
- |
if [[ ${TRAVIS_PHP_VERSION:0:3} == "7.0" ]]; then
composer global require "phpunit/phpunit=5.6.*"
if [[ ${TRAVIS_PHP_VERSION:0:1} == "7" ]]; then
composer global require "phpunit/phpunit=^5.6"
else
composer global require "phpunit/phpunit=4.8.*"
fi
Expand All @@ -36,5 +44,9 @@ before_script:
phpcs --config-set installed_paths $HOME/.composer/vendor/wp-coding-standards/wpcs
script:
- phpcs --standard=phpcs.ruleset.xml $(find . -name '*.php')
- phpcs --standard=phpcs.ruleset.xml $(find -name "*.php")
- phpunit

cache:
directories:
- $HOME/.composer/cache
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## [3.0.0]

- Fix untranslated string in fallback.
- Instruct screenreaders to ignore icons when present.
- Added basic unit tests and travis config.
- Swapped to IF statements with curly braces.
- Adds `$depth` arg for nav_menu_css_class filter.
- Fix sanitization function used for class output in fallback.
- Changed composer package type to `library` from `wordpress-plugin`.

## [2.0.5] - 2016-011-15
Expand Down
106 changes: 51 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,15 @@
[![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)
[![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)

A custom WordPress nav walker class to fully implement the Bootstrap 3.0+ navigation style in a custom theme using the WordPress built in menu manager.
A custom WordPress nav walker class to fully implement the Bootstrap 3.0+ navigation style in a custom theme using the WordPress built in menu manager. A working version of the walker for Bootstrap 4.0.0 can be found in the [`v4` branch](https://github.com/wp-bootstrap/wp-bootstrap-navwalker/tree/v4)

## NOTES

This is a utility class that is intended to format your WordPress theme menu with the correct syntax and classes to utilize the Bootstrap dropdown navigation, and does not include the required Bootstrap JS files. You will have to include them manually.
This is a utility class that is intended to format your WordPress theme menu with the correct syntax and classes to utilize the Bootstrap dropdown navigation. It does not include the required Bootstrap JS and CSS files. You will have to include those dependancies separately.

### Bootstrap 4

Bootstrap 4 beta is available and is now the default branch offered at the GitHub repo and on [GetBootstrap](https://getbootstrap.com). A working version of the walker for Bootstrap 4 can be found in the `v4` branch.

Acording to @mdo & team:

> Long story short, shipping a beta means we’re done breaking all your stuff until our next major version (v5).
Bootstrap 4.0.0 released January 2018 and is the default branch offered at the GitHub repo and on [GetBootstrap](https://getbootstrap.com).

## Installation

Expand All @@ -29,19 +25,21 @@ Place **wp-bootstrap-navwalker.php** in your WordPress theme folder `/wp-content
Open your WordPress themes **functions.php** file `/wp-content/your-theme/functions.php` and add the following code:

```php
<?php
// Register Custom Navigation Walker
require_once get_template_directory() . '/wp-bootstrap-navwalker.php';
```

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

```php
<?php
if ( ! file_exists( get_template_directory() . '/wp-bootstrap-navwalker.php' ) ) {
// file does not exist... return an error.
return new WP_Error( 'wp-bootstrap-navwalker-missing', __( 'It appears the wp-bootstrap-navwalker.php file may be missing.', 'wp-bootstrap-navwalker' ) );
} else {
// file exists... require it.
require_once get_template_directory . 'wp-bootstrap-navwalker.php';
require_once get_template_directory() . '/wp-bootstrap-navwalker.php';
}
```

Expand All @@ -50,61 +48,58 @@ if ( ! file_exists( get_template_directory() . '/wp-bootstrap-navwalker.php' ) )
Update your `wp_nav_menu()` function in `header.php` to use the new walker by adding a "walker" item to the wp_nav_menu array.

```php
<?php
wp_nav_menu( array(
'menu' => 'primary',
'theme_location' => 'primary',
'depth' => 2,
'container' => 'div',
'container_class' => 'collapse navbar-collapse',
'container_id' => 'bs-example-navbar-collapse-1',
'menu_class' => 'nav navbar-nav',
'fallback_cb' => 'WP_Bootstrap_Navwalker::fallback',
'walker' => new WP_Bootstrap_Navwalker())
);
?>
<?php
wp_nav_menu( array(
'theme_location' => 'primary',
'depth' => 2,
'container' => 'div',
'container_class' => 'collapse navbar-collapse',
'container_id' => 'bs-example-navbar-collapse-1',
'menu_class' => 'nav navbar-nav',
'fallback_cb' => 'WP_Bootstrap_Navwalker::fallback',
'walker' => new WP_Bootstrap_Navwalker(),
) );
```

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

You will also want to declare your new menu in your `functions.php` file.
You will also want to declare your new menu in your `functions.php` file if one is not already defined.

```php
<?php
register_nav_menus( array(
'primary' => __( 'Primary Menu', 'THEMENAME' ),
'primary' => __( 'Primary Menu', 'THEMENAME' ),
) );
```

Typically the menu is wrapped with additional markup, here is an example of a ` navbar-fixed-top` menu that collapse for responsive navigation.

```php
<nav class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="<?php echo home_url(); ?>">
<?php bloginfo('name'); ?>
</a>
</div>

<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="<?php echo home_url(); ?>">
<?php bloginfo('name'); ?>
</a>
</div>
<?php
wp_nav_menu( array(
'menu' => 'primary',
'theme_location' => 'primary',
'depth' => 2,
'container' => 'div',
'container_class' => 'collapse navbar-collapse',
'container_id' => 'bs-example-navbar-collapse-1',
'menu_class' => 'nav navbar-nav',
'fallback_cb' => 'WP_Bootstrap_Navwalker::fallback',
'walker' => new WP_Bootstrap_Navwalker())
);
wp_nav_menu( array(
'theme_location' => 'primary',
'depth' => 2,
'container' => 'div',
'container_class' => 'collapse navbar-collapse',
'container_id' => 'bs-example-navbar-collapse-1',
'menu_class' => 'nav navbar-nav',
'fallback_cb' => 'WP_Bootstrap_Navwalker::fallback',
'walker' => new WP_Bootstrap_Navwalker())
);
?>
</div>
</nav>
Expand All @@ -117,13 +112,14 @@ Review options in the Bootstrap docs for more information on [nav classes](https

### Displaying the Menu

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 wile editing a menu in the WordPress menu manager.
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.

### Making this Walker the Default Walker for Nav Manus

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.

```php
<?php
function prefix_modify_nav_menu_args( $args ) {
return array_merge( $args, array(
'walker' => WP_Bootstrap_Navwalker(),
Expand All @@ -135,24 +131,24 @@ Simply updating the walker may not be enough to get menus working right, you may

### Extras

This script included the ability to add Bootstrap dividers, dropdown headers, glyphicons and disables links to your menus through the WordPress menu UI.
This script included the ability to add Bootstrap dividers, dropdown headers, glyphicons and disabled links to your menus through the WordPress menu UI.

### Dividers
#### Dividers

Simply add a Link menu item with a **URL** of `#` and a **Link Text** or **Title Attribute** of `divider` (case-insensitive so ‘divider’ or ‘Divider’ will both work ) and the class will do the rest.

### Glyphicons
#### Glyphicons

To add an Icon to your link simple place the Glyphicon class name in the links **Title Attribute** field and the class will do the rest. IE `glyphicon-bullhorn`

### Dropdown Headers
#### Dropdown Headers

Adding a dropdown header is very similar, add a new link with a **URL** of `#` and a **Title Attribute** of `dropdown-header` (it matches the Bootstrap CSS class so it's easy to remember). set the **Navigation Label** to your header text and the class will do the rest.

### Disabled Links
#### Disabled Links

To set a disabled link simply set the **Title Attribute** to `disabled` and the class will do the rest.

### Changelog
## Changelog

Please see the [Changelog](https://github.com/wp-bootstrap/wp-bootstrap-navwalker/blob/master/CHANGELOG.md).
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@
"composer/installers": "~1.0"
},
"require-dev": {
"stevegrunwell/wp-enforcer": "^0.4.1"
"stevegrunwell/wp-enforcer": "^0.5.0"
},
"archive": {
"exclude": ["/.*", "/composer.lock"]
},
"scripts": {
"post-install-cmd": [
"wp-enforcer"
"wp-enforcer --ruleset=phpcs.ruleset.xml"
],
"post-update-cmd": [
"wp-enforcer"
"wp-enforcer --ruleset=phpcs.ruleset.xml"
]
}
}
Loading

0 comments on commit 4c2ae91

Please sign in to comment.