Repository: twittem/wp-bootstrap-navwalker Branch: master Commit: 11791945df1e Files: 22 Total size: 119.6 KB Directory structure: gitextract_z5aidwga/ ├── .codeclimate.yml ├── .editorconfig ├── .gitattributes ├── .github/ │ ├── CONTRIBUTING.md │ ├── ISSUE_TEMPLATE.md │ └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── LICENSE.txt ├── README.md ├── bin/ │ └── install-wp-tests.sh ├── class-wp-bootstrap-navwalker.php ├── composer.json ├── phpcs.xml.dist ├── phpstan.neon.dist ├── phpunit.xml.dist └── tests/ ├── bootstrap.php ├── phpstan/ │ ├── class-wp-nav-menu-args.php │ └── class-wp-nav-menu-item.php └── test-navwalker.php ================================================ FILE CONTENTS ================================================ ================================================ FILE: .codeclimate.yml ================================================ --- version: "2" plugins: duplication: enabled: true config: languages: - php fixme: enabled: true markdownlint: enabled: true phpcodesniffer: enabled: true config: file_extensions: "php" standard: "WordPress-Docs,WordPress-Extra" phpmd: enabled: true checks: Controversial/CamelCaseMethodName: enabled: false Controversial/CamelCaseParameterName: enabled: false Controversial/CamelCasePropertyName: enabled: false Controversial/CamelCaseVariableName: enabled: false CleanCode/ElseExpression: enabled: false shellcheck: enabled: true exclude_patterns: - "**.dist" - "**.lock" - "**.json" - "**.txt" - "tests/*" - "vendor/**" ================================================ FILE: .editorconfig ================================================ # This file is for unifying the coding style for different editors and IDEs # editorconfig.org # WordPress Coding Standards # https://make.wordpress.org/core/handbook/coding-standards/ root = true [*] charset = utf-8 end_of_line = lf insert_final_newline = true trim_trailing_whitespace = true indent_style = tab [{.jshintrc,*.json,*.yml}] indent_style = space indent_size = 2 [{*.txt,wp-config-sample.php}] end_of_line = crlf ================================================ FILE: .gitattributes ================================================ # Set the default behavior, in case people don't have core.autocrlf set. * text=auto # Explicitly declare text files that will always be normalized and converted # to native line endings on checkout. .editorconfig text .gitattributes text .gitignore text *.json text *.md text *.txt text *.xml text *.yml text # Declare files that will always have LF line endings on checkout. *.php text eol=lf *.sh text eol=lf # Exclude from export. .* export-ignore bin export-ignore tests export-ignore *.dist export-ignore CODE_OF_CONDUCT.md export-ignore composer.* export-ignore ================================================ FILE: .github/CONTRIBUTING.md ================================================ # Want to contribute? Did you know that you could be instrumental in making the WP Bootstrap NavWalker more robust? If you use and love it, why not contribute to the project? ## Contributing for Everyone! Whether you can barely recognize a filter (or don’t know what that means) or you’ve already authored your own plugins, there are ways for you to pitch in. ### Create Bug Reports If you find a bug, just [file a GitHub issue](https://github.com/wp-bootstrap/wp-bootstrap-navwalker/issues), that’s all. If you want to prefix the title with a “Question:”, “Bug:”, or the general area of the application, that would be helpful, but by no means mandatory. If you have write access, add the appropriate labels. If you’re filing a bug, specific steps to reproduce are helpful. Please include the URL of the page that has the bug, along with what you expected to see and what happened instead. ### Write and submit a patch If you'd like to fix a bug, you can submit a Pull Request. #### Where to get started? If you'd like to contribute but don't know where to get started, you can take a look at existing issues: - ["Good First Bug"](https://github.com/wp-bootstrap/wp-bootstrap-navwalker/labels/%5BTYPE%5D%20GOOD%20FIRST%20BUG) issues are a good entry point to get familiar with the codebase. ================================================ FILE: .github/ISSUE_TEMPLATE.md ================================================ #### Steps to reproduce the issue: #### What I expected: #### What happened instead: ================================================ FILE: .github/PULL_REQUEST_TEMPLATE.md ================================================ Fixes # #### Changes proposed in this Pull Request: * #### Testing instructions: * #### Proposed changelog entry for your changes: ================================================ FILE: .gitignore ================================================ /vendor/ /phpcs.xml ================================================ FILE: .travis.yml ================================================ language: php os: - linux dist: bionic php: - 7.4 - 7.3 - 7.2 - 7.1 - nightly env: - WP_VERSION=latest WP_MULTISITE=0 PHPUNIT_VERSION="^5.7" - WP_VERSION=latest WP_MULTISITE=1 PHPUNIT_VERSION="^5.7" services: - mysql jobs: include: - php: 7.0 dist: xenial env: - WP_VERSION=latest WP_MULTISITE=0 PHPUNIT_VERSION="^5.7" - php: 7.0 dist: xenial env: - WP_VERSION=latest WP_MULTISITE=1 PHPUNIT_VERSION="^5.7" - php: 5.6 dist: xenial env: - WP_VERSION=latest WP_MULTISITE=0 PHPUNIT_VERSION="^5.7" - php: 5.6 dist: xenial env: - WP_VERSION=latest WP_MULTISITE=1 PHPUNIT_VERSION="^5.7" - name: "Coding Standars" php: 7.4 install: - composer require --dev wp-coding-standards/wpcs dealerdirect/phpcodesniffer-composer-installer # Counter wp-enforcer - rm -f ./phpcs.xml script: - vendor/bin/phpcs - name: "Static Analysis" php: 7.4 install: - composer require --dev szepeviktor/phpstan-wordpress script: - vendor/bin/phpstan analyze allow_failures: - php: nightly branches: only: - master cache: directories: - "${HOME}/.composer/cache" install: - bin/install-wp-tests.sh wordpress_test root "" localhost "${WP_VERSION}" - composer global require --dev "phpunit/phpunit=${PHPUNIT_VERSION}" script: - "${HOME}/.composer/vendor/bin/phpunit" notifications: email: on_success: never on_failure: change ================================================ FILE: CHANGELOG.md ================================================ #CHANGELOG ## [4.3.0] - Added an `aria-current` item. - Added `.nav-item` for the `
  • ` and `.nav-link` for the `` in fallback function. - Some escape improvements. - Don't pass `$attributes` to element closing function as it's ignored anyway. ## [4.2.0] - Fix typo in function name 'seporate'->'separate' (private function, no need to add back-compat). ## [4.1.0] - Prevent error `trying to get property of non-object` when no menu is set to a location using the walker. - Add `$depth` as 4th parameter passed to `nav_menu_link_attributes`. - Add support for `dropdown-item-text` linkmod type. ## [4.0.3] - Drop composer class autoload statement. ## [4.0.2] - Fix dropdown opener having empty string for href value. - More accurate regex matching of icon and linkmod classnames. - Changed composer package type to `library` from `wordpress-plugin` again. - Tests: Add unit tests for the function that separates classnames for the walker. - Fix case sensitive matching to now match mixes of upper and lower case. ## [4.0.1] - Fix untranslated string in fallback (this was lost in transition between v3 and v4, fixed again). ## [4.0.0] - Added a prefix on @since tags to highlight when they refer to WP core instead of this class. - Rework of `start_lvl()` and `start_el()` based on latest `Walker_Nav_Menu` Class from WP core. - Whitespace preservation method improvements. - Added `nav_menu_item_args` filter and `nav_menu_item_title` brought in at WP 4.4.0 - Use `the_title` filter prior to `nav_menu_item_title`. - Added a labelled-by attribute to dropdowns for accessibility. - Links inside dropdown have `.dropdown-item` instead of `.nav-link`. - Remove `` after parent dropdown items. - Support `echo` arg in fallback menu. props: @toddlevy - Add `.active` to parent when a child is current page. props: @zyberspace - Fix to correct output of dropdown atts and styles when depth passed to wp_nav_menu is <= 1. props: @chrisgeary92 - Move icon output to a local var instead of modifying and clearing a global object. - Reassign filtered classes back to $classes array so that updated classes can be accessed later if needed. props: @lf-jeremy - Update to work with Bootstrap v4. - Added `.nav-item` and `.nav-link` to `
  • ` and `` respectively. - Dropped support for using title attribute to add link modifiers and icons. - Added support for link modifiers and icons through WP Menu Builder 'classes' input. - Icon support is for Font Awesome 4/5 and Glyphicons icons. - Added unit tests for the `fallback` method. - Added code to handle icon-only menus. ## [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 - Fixed all reported issues by WP Enforcer. - Fixed several Code Climate issues. ## [2.0.4] - Updated fallback function to accept args array from `wp_nav_menu`. ## [2.0.3] - Included a fallback function that adds a link to the WordPress menu manager if no menu has been assigned to the theme location. ## [2.0.2] - Small tweak to ensure carets are only displayed on top level dropdowns. ## [2.0.1] - Added missing active class to active menu items. ## [2.0.0] - Class was completly re-written using the latest Wordpress 3.6 walker class. - Now full supports Bootstrap 3.0+ - Tested with wp_debug & the Theme Check plugin. --- All notable changes to this project will be documented in this file. Please read [Keep a Change Log](http://keepachangelog.com) for more information. This project adheres to [Semantic Versioning](http://semver.org). ================================================ FILE: CODE_OF_CONDUCT.md ================================================ # Contributor Covenant Code of Conduct ## Our Pledge In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. ## Our Standards Examples of behavior that contributes to creating a positive environment include: * Using welcoming and inclusive language * Being respectful of differing viewpoints and experiences * Gracefully accepting constructive criticism * Focusing on what is best for the community * Showing empathy towards other community members Examples of unacceptable behavior by participants include: * The use of sexualized language or imagery and unwelcome sexual attention or advances * Trolling, insulting/derogatory comments, and personal or political attacks * Public or private harassment * Publishing others' private information, such as a physical or electronic address, without explicit permission * Other conduct which could reasonably be considered inappropriate in a professional setting ## Our Responsibilities Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. ## Scope This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. ## Enforcement Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at brandon@imforza.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. ## Attribution This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] [homepage]: http://contributor-covenant.org [version]: http://contributor-covenant.org/version/1/4/ ================================================ FILE: LICENSE.txt ================================================ GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . ================================================ FILE: README.md ================================================ # WP Bootstrap Navwalker [![Code Climate](https://codeclimate.com/github/wp-bootstrap/wp-bootstrap-navwalker/badges/gpa.svg)](https://codeclimate.com/github/wp-bootstrap/wp-bootstrap-navwalker) [![Test Coverage](https://codeclimate.com/github/wp-bootstrap/wp-bootstrap-navwalker/badges/coverage.svg)](https://codeclimate.com/github/wp-bootstrap/wp-bootstrap-navwalker/coverage) [![Issue Count](https://codeclimate.com/github/wp-bootstrap/wp-bootstrap-navwalker/badges/issue_count.svg)](https://codeclimate.com/github/wp-bootstrap/wp-bootstrap-navwalker) [![Build Status](https://travis-ci.org/wp-bootstrap/wp-bootstrap-navwalker.svg?branch=master)](https://travis-ci.org/wp-bootstrap/wp-bootstrap-navwalker) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/wp-bootstrap/wp-bootstrap-navwalker/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/wp-bootstrap/wp-bootstrap-navwalker/?branch=master) [![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) **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** 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. ## NOTES This is a utility class that is intended to format your WordPress theme menu with the correct syntax and CSS classes to utilize the Bootstrap dropdown navigation. It does not include the required Bootstrap JS and CSS files - you will have to include them manually. ### WordPress.org Theme Compliance *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. ### Upgrade Notes 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: Here is a list of the most notable changes: - The filename has been changed and prefixed with `class-` to better fit PHP coding standards naming conventions. - New Name: `class-wp-bootstrap-navwalker.php` - Old Name: `wp-bootstrap-navwalker.php` - Icon and link modifier handling is now done through the `CSS Classes` menu item input instead of the `Title` input. - Icon only items are possible using icon classes in combination with the `sr-only` classname. ## Installation Place **class-wp-bootstrap-navwalker.php** in your WordPress theme folder `/wp-content/themes/your-theme/` Open your WordPress themes **functions.php** file - `/wp-content/themes/your-theme/functions.php` - and add the following code: ```php /** * Register Custom Navigation Walker */ function register_navwalker(){ require_once get_template_directory() . '/class-wp-bootstrap-navwalker.php'; } add_action( 'after_setup_theme', 'register_navwalker' ); ``` If you encounter errors with the above code use a check like this to return clean errors to help diagnose the problem. ```php if ( ! file_exists( get_template_directory() . '/class-wp-bootstrap-navwalker.php' ) ) { // File does not exist... return an error. return new WP_Error( 'class-wp-bootstrap-navwalker-missing', __( 'It appears the class-wp-bootstrap-navwalker.php file may be missing.', 'wp-bootstrap-navwalker' ) ); } else { // File exists... require it. require_once get_template_directory() . '/class-wp-bootstrap-navwalker.php'; } ``` You will also need to declare a new menu in your `functions.php` file if one doesn't already exist. ```php register_nav_menus( array( 'primary' => __( 'Primary Menu', 'THEMENAME' ), ) ); ``` ## Usage 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. ```php wp_nav_menu( array( 'theme_location' => 'primary', 'depth' => 2, // 1 = no dropdowns, 2 = with dropdowns. 'container' => 'div', 'container_class' => 'collapse navbar-collapse', 'container_id' => 'bs-example-navbar-collapse-1', 'menu_class' => 'navbar-nav mr-auto', '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. 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. ```php ``` To change your menu style add Bootstrap nav class names to the `menu_class` declaration. Review options in the Bootstrap docs for more information on [nav classes](https://getbootstrap.com/components/#nav). ### 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 while editing a menu in the WordPress menu manager. ### Making this Walker the Default Walker for Nav Menus 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 function prefix_modify_nav_menu_args( $args ) { return array_merge( $args, array( 'walker' => new WP_Bootstrap_Navwalker(), ) ); } add_filter( 'wp_nav_menu_args', 'prefix_modify_nav_menu_args' ); ``` 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. ### Usage with Bootstrap 5 Bootstrap 5 uses namespaced data attributes. All `data` attributes now include `bs` as an infix. The new attributes work just like the old ones. Here’s the menu toggle button from the example above with the renamed data attributes. ```php ``` The walker also adds a data attribute for dropdown toggles via the `start_el()` method. Paste this to your functions.php to make the walker use the infixed data attibute. ```php add_filter( 'nav_menu_link_attributes', 'prefix_bs5_dropdown_data_attribute', 20, 3 ); /** * Use namespaced data attribute for Bootstrap's dropdown toggles. * * @param array $atts HTML attributes applied to the item's `` element. * @param WP_Post $item The current menu item. * @param stdClass $args An object of wp_nav_menu() arguments. * @return array */ function prefix_bs5_dropdown_data_attribute( $atts, $item, $args ) { if ( is_a( $args->walker, 'WP_Bootstrap_Navwalker' ) ) { if ( array_key_exists( 'data-toggle', $atts ) ) { unset( $atts['data-toggle'] ); $atts['data-bs-toggle'] = 'dropdown'; } } return $atts; } ``` ### Menu Caching On some sites generating a large menu that rarely ever changes on every page request is an overhead that you may want to avoid. In those cases I can suggest you look at storing menu results in a transient. 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. 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: 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. See also: - - ### Extras 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). #### Icons 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`. #### Icon-Only Items 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. #### Disabled Links 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._ #### Dropdown Headers, Dropdown Dividers & Dropdown Item Text 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 `` for headers or a `
    ` for dividers._ ### Missing Edit Shortcut in Customizer Preview According to the documentation for [`wp_nav_menu()`](https://developer.wordpress.org/reference/functions/wp_nav_menu/) one has to provide an instance of the custom walker class in order to apply the custom walker to the menu. As the instance is not [JSON serializable](https://make.wordpress.org/core/2015/07/29/fast-previewing-changes-to-menus-in-the-customizer/) this will cause the menu edit shortcut to not appear in the Customizer preview. To fix this do the following: 1. Provide the class name string instead of the class instance as value for the 'walker' key in the array of wp_nav_menu's arguments, ```diff wp_nav_menu( array( 'theme_location' => 'primary', 'depth' => 2, // 1 = no dropdowns, 2 = with dropdowns. 'container' => 'div', 'container_class' => 'collapse navbar-collapse', 'container_id' => 'bs-example-navbar-collapse-1', 'menu_class' => 'navbar-nav mr-auto', 'fallback_cb' => 'WP_Bootstrap_Navwalker::fallback', - 'walker' => new WP_Bootstrap_Navwalker(), + 'walker' => 'WP_Bootstrap_Navwalker', ) ); ``` 2. re-add the class instance by adding this filter to your `functions.php` ```php function slug_provide_walker_instance( $args ) { if ( isset( $args['walker'] ) && is_string( $args['walker'] ) && class_exists( $args['walker'] ) ) { $args['walker'] = new $args['walker']; } return $args; } add_filter( 'wp_nav_menu_args', 'slug_provide_walker_instance', 1001 ); ``` ## Changelog Please see the [Changelog](https://github.com/wp-bootstrap/wp-bootstrap-navwalker/blob/master/CHANGELOG.md). ================================================ FILE: bin/install-wp-tests.sh ================================================ #!/usr/bin/env bash if [ $# -lt 3 ]; then echo "usage: $0 [db-host] [wp-version] [skip-database-creation]" exit 1 fi DB_NAME=$1 DB_USER=$2 DB_PASS=$3 DB_HOST=${4-localhost} WP_VERSION=${5-latest} SKIP_DB_CREATE=${6-false} WP_TESTS_DIR=${WP_TESTS_DIR-/tmp/wordpress-tests-lib} WP_CORE_DIR=${WP_CORE_DIR-/tmp/wordpress/} download() { if [ `which curl` ]; then curl -s "$1" > "$2"; elif [ `which wget` ]; then wget -nv -O "$2" "$1" fi } if [[ $WP_VERSION =~ [0-9]+\.[0-9]+(\.[0-9]+)? ]]; then WP_TESTS_TAG="tags/$WP_VERSION" elif [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then WP_TESTS_TAG="trunk" else # http serves a single offer, whereas https serves multiple. we only want one download http://api.wordpress.org/core/version-check/1.7/ /tmp/wp-latest.json grep '[0-9]+\.[0-9]+(\.[0-9]+)?' /tmp/wp-latest.json LATEST_VERSION=$(grep -o '"version":"[^"]*' /tmp/wp-latest.json | sed 's/"version":"//') if [[ -z "$LATEST_VERSION" ]]; then echo "Latest WordPress version could not be found" exit 1 fi WP_TESTS_TAG="tags/$LATEST_VERSION" fi set -ex install_wp() { if [ -d $WP_CORE_DIR ]; then return; fi mkdir -p $WP_CORE_DIR if [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then mkdir -p /tmp/wordpress-nightly download https://wordpress.org/nightly-builds/wordpress-latest.zip /tmp/wordpress-nightly/wordpress-nightly.zip unzip -q /tmp/wordpress-nightly/wordpress-nightly.zip -d /tmp/wordpress-nightly/ mv /tmp/wordpress-nightly/wordpress/* $WP_CORE_DIR else if [ $WP_VERSION == 'latest' ]; then local ARCHIVE_NAME='latest' else local ARCHIVE_NAME="wordpress-$WP_VERSION" fi download https://wordpress.org/${ARCHIVE_NAME}.tar.gz /tmp/wordpress.tar.gz tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C $WP_CORE_DIR fi download https://raw.github.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR/wp-content/db.php } install_test_suite() { # portable in-place argument for both GNU sed and Mac OSX sed if [[ $(uname -s) == 'Darwin' ]]; then local ioption='-i .bak' else local ioption='-i' fi # set up testing suite if it doesn't yet exist if [ ! -d $WP_TESTS_DIR ]; then # set up testing suite mkdir -p $WP_TESTS_DIR svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/includes/ $WP_TESTS_DIR/includes svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/data/ $WP_TESTS_DIR/data fi if [ ! -f wp-tests-config.php ]; then download https://develop.svn.wordpress.org/${WP_TESTS_TAG}/wp-tests-config-sample.php "$WP_TESTS_DIR"/wp-tests-config.php # remove all forward slashes in the end WP_CORE_DIR=$(echo $WP_CORE_DIR | sed "s:/\+$::") sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR/':" "$WP_TESTS_DIR"/wp-tests-config.php sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" "$WP_TESTS_DIR"/wp-tests-config.php sed $ioption "s/yourusernamehere/$DB_USER/" "$WP_TESTS_DIR"/wp-tests-config.php sed $ioption "s/yourpasswordhere/$DB_PASS/" "$WP_TESTS_DIR"/wp-tests-config.php sed $ioption "s|localhost|${DB_HOST}|" "$WP_TESTS_DIR"/wp-tests-config.php fi } install_db() { if [ ${SKIP_DB_CREATE} = "true" ]; then return 0 fi # parse DB_HOST for port or socket references local PARTS=(${DB_HOST//\:/ }) local DB_HOSTNAME=${PARTS[0]}; local DB_SOCK_OR_PORT=${PARTS[1]}; local EXTRA="" if ! [ -z $DB_HOSTNAME ] ; then if [ $(echo $DB_SOCK_OR_PORT | grep -e '^[0-9]\{1,\}$') ]; then EXTRA=" --host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp" elif ! [ -z $DB_SOCK_OR_PORT ] ; then EXTRA=" --socket=$DB_SOCK_OR_PORT" elif ! [ -z $DB_HOSTNAME ] ; then EXTRA=" --host=$DB_HOSTNAME --protocol=tcp" fi fi # create database mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA } install_wp install_test_suite install_db ================================================ FILE: class-wp-bootstrap-navwalker.php ================================================ item_spacing ) && 'discard' === $args->item_spacing ) { $t = ''; $n = ''; } else { $t = "\t"; $n = "\n"; } $indent = str_repeat( $t, $depth ); // Default class to add to the file. $classes = array( 'dropdown-menu' ); /** * Filters the CSS class(es) applied to a menu list element. * * @since WP 4.8.0 * * @param array $classes The CSS classes that are applied to the menu `'; // Menu container closing tag. if ( $show_container ) { $fallback_output .= ''; } // if $args has 'echo' key and it's true echo, otherwise return. if ( array_key_exists( 'echo', $args ) && $args['echo'] ) { // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped echo $fallback_output; } else { return $fallback_output; } } /** * Filter to ensure the items_Wrap argument contains microdata. * * @since 4.2.0 * * @param array $args The nav instance arguments. * @return array $args The altered nav instance arguments. */ public function add_schema_to_navbar_ul( $args ) { if ( isset( $args['items_wrap'] ) ) { $wrap = $args['items_wrap']; if ( strpos( $wrap, 'SiteNavigationElement' ) === false ) { $args['items_wrap'] = preg_replace( '/(>).*>?\%3\$s/', ' itemscope itemtype="http://www.schema.org/SiteNavigationElement"$0', $wrap ); } } return $args; } /** * Find any custom linkmod or icon classes and store in their holder * arrays then remove them from the main classes array. * * Supported linkmods: .disabled, .dropdown-header, .dropdown-divider, .sr-only * Supported iconsets: Font Awesome 4/5, Glypicons * * NOTE: This accepts the linkmod and icon arrays by reference. * * @since 4.0.0 * * @param array $classes an array of classes currently assigned to the item. * @param array $linkmod_classes an array to hold linkmod classes. * @param array $icon_classes an array to hold icon classes. * @param integer $depth an integer holding current depth level. * * @return array $classes a maybe modified array of classnames. */ private function separate_linkmods_and_icons_from_classes( $classes, &$linkmod_classes, &$icon_classes, $depth ) { // Loop through $classes array to find linkmod or icon classes. foreach ( $classes as $key => $class ) { /* * If any special classes are found, store the class in it's * holder array and and unset the item from $classes. */ if ( preg_match( '/^disabled|^sr-only/i', $class ) ) { // Test for .disabled or .sr-only classes. $linkmod_classes[] = $class; unset( $classes[ $key ] ); } elseif ( preg_match( '/^dropdown-header|^dropdown-divider|^dropdown-item-text/i', $class ) && $depth > 0 ) { /* * Test for .dropdown-header or .dropdown-divider and a * depth greater than 0 - IE inside a dropdown. */ $linkmod_classes[] = $class; unset( $classes[ $key ] ); } elseif ( preg_match( '/^fa-(\S*)?|^fa(s|r|l|b)?(\s?)?$/i', $class ) ) { // Font Awesome. $icon_classes[] = $class; unset( $classes[ $key ] ); } elseif ( preg_match( '/^glyphicon-(\S*)?|^glyphicon(\s?)$/i', $class ) ) { // Glyphicons. $icon_classes[] = $class; unset( $classes[ $key ] ); } } return $classes; } /** * Return a string containing a linkmod type and update $atts array * accordingly depending on the decided. * * @since 4.0.0 * * @param array $linkmod_classes array of any link modifier classes. * * @return string empty for default, a linkmod type string otherwise. */ private function get_linkmod_type( $linkmod_classes = array() ) { $linkmod_type = ''; // Loop through array of linkmod classes to handle their $atts. if ( ! empty( $linkmod_classes ) ) { foreach ( $linkmod_classes as $link_class ) { if ( ! empty( $link_class ) ) { // Check for special class types and set a flag for them. if ( 'dropdown-header' === $link_class ) { $linkmod_type = 'dropdown-header'; } elseif ( 'dropdown-divider' === $link_class ) { $linkmod_type = 'dropdown-divider'; } elseif ( 'dropdown-item-text' === $link_class ) { $linkmod_type = 'dropdown-item-text'; } } } } return $linkmod_type; } /** * Update the attributes of a nav item depending on the limkmod classes. * * @since 4.0.0 * * @param array $atts array of atts for the current link in nav item. * @param array $linkmod_classes an array of classes that modify link or nav item behaviors or displays. * * @return array maybe updated array of attributes for item. */ private function update_atts_for_linkmod_type( $atts = array(), $linkmod_classes = array() ) { if ( ! empty( $linkmod_classes ) ) { foreach ( $linkmod_classes as $link_class ) { if ( ! empty( $link_class ) ) { /* * Update $atts with a space and the extra classname * so long as it's not a sr-only class. */ if ( 'sr-only' !== $link_class ) { $atts['class'] .= ' ' . esc_attr( $link_class ); } // Check for special class types we need additional handling for. if ( 'disabled' === $link_class ) { // Convert link to '#' and unset open targets. $atts['href'] = '#'; unset( $atts['target'] ); } elseif ( 'dropdown-header' === $link_class || 'dropdown-divider' === $link_class || 'dropdown-item-text' === $link_class ) { // Store a type flag and unset href and target. unset( $atts['href'] ); unset( $atts['target'] ); } } } } return $atts; } /** * Wraps the passed text in a screen reader only class. * * @since 4.0.0 * * @param string $text the string of text to be wrapped in a screen reader class. * @return string the string wrapped in a span with the class. */ private function wrap_for_screen_reader( $text = '' ) { if ( $text ) { $text = '' . $text . ''; } return $text; } /** * Returns the correct opening element and attributes for a linkmod. * * @since 4.0.0 * * @param string $linkmod_type a sting containing a linkmod type flag. * @param string $attributes a string of attributes to add to the element. * * @return string a string with the openign tag for the element with attribibutes added. */ private function linkmod_element_open( $linkmod_type, $attributes = '' ) { $output = ''; if ( 'dropdown-item-text' === $linkmod_type ) { $output .= ''; } elseif ( 'dropdown-header' === $linkmod_type ) { /* * For a header use a span with the .h6 class instead of a real * header tag so that it doesn't confuse screen readers. */ $output .= ''; } elseif ( 'dropdown-divider' === $linkmod_type ) { // This is a divider. $output .= ''; } return $output; } /** * Flattens a multidimensional array to a simple array. * * @param array $array a multidimensional array. * * @return array a simple array */ public function flatten( $array ) { $result = array(); foreach ( $array as $element ) { if ( is_array( $element ) ) { array_push( $result, ...$this->flatten( $element ) ); } else { $result[] = $element; } } return $result; } } endif; ================================================ FILE: composer.json ================================================ { "name": "wp-bootstrap/wp-bootstrap-navwalker", "description": "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.", "type": "library", "license": "GPL-3.0+", "authors": [ { "name": "Brandon Hubbard" }, { "name": "William Patton", "email": "will@pattonwebz.com" } ], "support": { "issues": "https://github.com/wp-bootstrap/wp-bootstrap-navwalker/issues/", "source": "https://github.com/wp-bootstrap/wp-bootstrap-navwalker/" }, "require": { "composer/installers": "~1.0", "php": "^5.5 || ^7.0" }, "require-dev": { "stevegrunwell/wp-enforcer": "^0.5.0" }, "archive": { "exclude": ["/.*", "/composer.lock"] }, "scripts": { "post-install-cmd": [ "wp-enforcer" ], "post-update-cmd": [ "wp-enforcer" ] } } ================================================ FILE: phpcs.xml.dist ================================================ Generally-applicable sniffs for WordPress plugins ./class-wp-bootstrap-navwalker.php ./tests/ ================================================ FILE: phpstan.neon.dist ================================================ includes: - phar://phpstan.phar/conf/bleedingEdge.neon - vendor/szepeviktor/phpstan-wordpress/extension.neon parameters: level: 6 inferPrivatePropertyTypeFromConstructor: true checkMissingIterableValueType: false paths: - class-wp-bootstrap-navwalker.php scanFiles: - tests/phpstan/class-wp-nav-menu-args.php - tests/phpstan/class-wp-nav-menu-item.php - class-wp-bootstrap-navwalker.php ignoreErrors: # Uses func_get_args() - '#^Function apply_filters(_ref_array)? invoked with [34567] parameters, 2 required\.$#' # False item type in core. - message: "#^Parameter \\#2 \\$item \\(WP_Nav_Menu_Item\\) of method WP_Bootstrap_Navwalker\\:\\:start_el\\(\\) should be compatible with parameter \\$item \\(WP_Post\\) of method Walker_Nav_Menu\\:\\:start_el\\(\\)$#" path: class-wp-bootstrap-navwalker.php # $output passed by reference. - message: '#^Method WP_Bootstrap_Navwalker::(start_lvl|start_el)\(\) has no return typehint specified\.$#' path: class-wp-bootstrap-navwalker.php # Uncertain properties. - message: '#^Property WP_Nav_Menu_Args::\$\S+ \(string\) in isset\(\) is not nullable\.$#' path: class-wp-bootstrap-navwalker.php ================================================ FILE: phpunit.xml.dist ================================================ ./tests/ ================================================ FILE: tests/bootstrap.php ================================================ walker = new WP_Bootstrap_Navwalker(); // this is a test array of valid values that the fallback method will accept. $this->valid_sample_fallback_args = array( 'container' => 'div', 'container_id' => 'a_container_id', 'container_class' => 'a_container_class', 'menu_class' => 'a_menu_class', 'menu_id' => 'a_menu_id', 'echo' => true, ); // array of the possible linkmod typeflags. $this->valid_linkmod_typeflags = array( 'dropdown-header', 'dropdown-divider', 'dropdown-item-text', ); // array of all possible linkmods, including the valid typeflags. $this->valid_linkmod_classes = array_merge( $this->valid_linkmod_typeflags, array( 'disabled', 'sr-only', ) ); // array of valid font-awesome icon class starters plus some randomly // chosen icon classes and some variations of upper/lower case letters. $this->some_fontawesome_classes = array( 'fa', 'fas', 'fab', 'far', 'fal', 'fa-android', 'fa-css3', 'fa-home', 'fa-bluetooth-b', 'fa-chess-rook', 'fA-home', 'Fa-HoMe', 'fa-HomE', ); // array of valid glyphicon icon class starters plus some randomly // chosen icon classes and some variations of upper/lower case letters. $this->some_glyphicons_classes = array( 'glyphicon', 'glyphicon-asterisk', 'glyphicon-ok', 'glyphicon-file', 'glyphicon-hand-left', 'glyphicon-sd-video', 'glyphicon-subscript', 'glyphicon-grain', 'Glyphicon-file', 'Glyphicon-File', 'glyphicon-File', 'glYphiCon-fiLe', ); } /** * Test NavWalker File Exists. * * @access public * @return void */ public function test_navwalker_file_exists() { $this->assertFileExists( 'class-wp-bootstrap-navwalker.php' ); } /** * Test Start LVL Function. * * @access public * @return void */ public function test_startlvl_function_exists() { $wp_bootstrap_navwalker = $this->walker; $this->assertTrue( method_exists( $wp_bootstrap_navwalker, 'start_lvl' ), 'Class does not have method start_lvl.' ); } /** * Test Start El Function. * * @access public * @return void */ public function test_start_el_function_exists() { $wp_bootstrap_navwalker = $this->walker; $this->assertTrue( method_exists( $wp_bootstrap_navwalker, 'start_el' ), 'Class does not have method start_el.' ); } /** * Test for Display Element. * * @access public * @return void */ public function test_display_element_function_exists() { $wp_bootstrap_navwalker = $this->walker; $this->assertTrue( method_exists( $wp_bootstrap_navwalker, 'display_element' ), 'Class does not have method display_element.' ); } /** * Test Fallback function exists. * * @access public * @return void */ public function test_fallback_function_exists() { $wp_bootstrap_navwalker = $this->walker; $this->assertTrue( method_exists( $wp_bootstrap_navwalker, 'fallback' ), 'Class does not have method fallback.' ); } /** * Test Fallback method output for logged out users. * * Expects that for logged out users both echo and return requests should * produce empty strings. * * @access public * @return void */ public function test_fallback_function_output_loggedout() { // default is to echo reults, buffer. ob_start(); WP_Bootstrap_Navwalker::fallback( $this->valid_sample_fallback_args ); $fallback_output_echo = ob_get_clean(); // empty string expected when not logged in. $this->assertEmpty( $fallback_output_echo, 'Fallback output for logged out user created a non-empty string in echo mode.' ); // set 'echo' to false and request the markup returned. $fallback_output_return = WP_Bootstrap_Navwalker::fallback( array_merge( $this->valid_sample_fallback_args, array( 'echo' => false, ) ) ); // return and echo should result in the same values (both empty). $this->assertEquals( $fallback_output_echo, $fallback_output_return, 'Fallback output for logged out user created a non-empty string in return mode.' ); } /** * Test Fallback method output for logged in users. * * Expects strings to be produced with html markup and that they match when * requesting either a return or defaulting to echo. * * @access public * @return void */ public function test_fallback_function_output_loggedin() { // make an admin user and set it to be the current user. $user_id = $this->factory->user->create( array( 'role' => 'administrator' ) ); wp_set_current_user( $user_id ); // default is to echo results, buffer. ob_start(); WP_Bootstrap_Navwalker::fallback( $this->valid_sample_fallback_args ); $fallback_output_echo = ob_get_clean(); // rudimentary content test - confirm it opens a div with 2 expected // values and ends by closing a div. $match = ( preg_match( '/^(