├── src ├── Contracts │ ├── Build.php │ ├── Query.php │ ├── Crumb.php │ └── Breadcrumbs.php ├── Crumb │ ├── Error.php │ ├── Archive.php │ ├── Paged.php │ ├── PagedComments.php │ ├── PagedSingular.php │ ├── Search.php │ ├── Network.php │ ├── Minute.php │ ├── Home.php │ ├── MinuteHour.php │ ├── Author.php │ ├── Week.php │ ├── Year.php │ ├── Post.php │ ├── Term.php │ ├── Month.php │ ├── Day.php │ ├── PostType.php │ └── Base.php ├── Query │ ├── Home.php │ ├── Error.php │ ├── Hour.php │ ├── Year.php │ ├── FrontPage.php │ ├── Minute.php │ ├── Search.php │ ├── MinuteHour.php │ ├── Month.php │ ├── Paged.php │ ├── Week.php │ ├── Day.php │ ├── Singular.php │ ├── Tax.php │ ├── Author.php │ ├── Base.php │ ├── Archive.php │ └── PostTypeArchive.php ├── Build │ ├── Network.php │ ├── RewriteFront.php │ ├── Paged.php │ ├── Post.php │ ├── TermAncestors.php │ ├── PostTerms.php │ ├── PostType.php │ ├── Base.php │ ├── Term.php │ ├── PostAncestors.php │ ├── Path.php │ ├── PostHierarchy.php │ └── MapRewriteTags.php ├── Util │ └── Helpers.php ├── Trail.php └── Breadcrumbs.php ├── composer.json ├── readme.md └── license.md /src/Contracts/Build.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright Copyright (c) 2018, Justin Tadlock 10 | * @link https://github.com/justintadlock/hybrid-breadcrumbs 11 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 12 | */ 13 | 14 | namespace Hybrid\Breadcrumbs\Contracts; 15 | 16 | /** 17 | * Build interface. 18 | * 19 | * @since 1.0.0 20 | * @access public 21 | */ 22 | interface Build { 23 | 24 | /** 25 | * Builds breadcrumbs. 26 | * 27 | * @since 1.0.0 28 | * @access public 29 | * @return void 30 | */ 31 | public function make(); 32 | } 33 | -------------------------------------------------------------------------------- /src/Contracts/Query.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright Copyright (c) 2018, Justin Tadlock 10 | * @link https://github.com/justintadlock/hybrid-breadcrumbs 11 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 12 | */ 13 | 14 | namespace Hybrid\Breadcrumbs\Contracts; 15 | 16 | /** 17 | * Query interface. 18 | * 19 | * @since 1.0.0 20 | * @access public 21 | */ 22 | interface Query { 23 | 24 | /** 25 | * Builds breadcrumbs. 26 | * 27 | * @since 1.0.0 28 | * @access public 29 | * @return void 30 | */ 31 | public function make(); 32 | } 33 | -------------------------------------------------------------------------------- /src/Crumb/Error.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright Copyright (c) 2018, Justin Tadlock 10 | * @link https://github.com/justintadlock/hybrid-breadcrumbs 11 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 12 | */ 13 | 14 | namespace Hybrid\Breadcrumbs\Crumb; 15 | 16 | /** 17 | * Error 404 crumb sub-class. 18 | * 19 | * @since 1.0.0 20 | * @access public 21 | */ 22 | class Error extends Base { 23 | 24 | /** 25 | * Returns a label for the crumb. 26 | * 27 | * @since 1.0.0 28 | * @access public 29 | * @return string 30 | */ 31 | public function label() { 32 | 33 | return $this->breadcrumbs->label( 'error_404' ); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "themehybrid/hybrid-breadcrumbs", 3 | "description" : "A powerful breadcrumb script for inclusion with WordPress themes.", 4 | "keywords" : [ "wordpress" ], 5 | "homepage" : "https://github.com/justintadlock/hybrid-breadcrumbs", 6 | "license" : "GPL-2.0-or-later", 7 | "authors" : [ 8 | { 9 | "name" : "Justin Tadlock", 10 | "email" : "justintadlock@gmail.com", 11 | "homepage" : "https://themehybrid.com", 12 | "role" : "Developer" 13 | } 14 | ], 15 | "support" : { 16 | "issues" : "https://github.com/themehybrid/hybrid-breadcrumbs/issues", 17 | "forum" : "https://themehybrid.com/board/topics" 18 | }, 19 | "autoload" : { 20 | "psr-4" : { 21 | "Hybrid\\Breadcrumbs\\" : "src/" 22 | } 23 | }, 24 | "require" : { 25 | "php" : ">=5.6" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Crumb/Archive.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright Copyright (c) 2018, Justin Tadlock 10 | * @link https://github.com/justintadlock/hybrid-breadcrumbs 11 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 12 | */ 13 | 14 | namespace Hybrid\Breadcrumbs\Crumb; 15 | 16 | /** 17 | * Archive crumb sub-class. 18 | * 19 | * @since 1.0.0 20 | * @access public 21 | */ 22 | class Archive extends Base { 23 | 24 | /** 25 | * Returns a label for the crumb. 26 | * 27 | * @since 1.0.0 28 | * @access public 29 | * @return string 30 | */ 31 | public function label() { 32 | 33 | return $this->breadcrumbs->label( 'archives' ); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Crumb/Paged.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright Copyright (c) 2018, Justin Tadlock 10 | * @link https://github.com/justintadlock/hybrid-breadcrumbs 11 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 12 | */ 13 | 14 | namespace Hybrid\Breadcrumbs\Crumb; 15 | 16 | /** 17 | * Paged crumb sub-class. 18 | * 19 | * @since 1.0.0 20 | * @access public 21 | */ 22 | class Paged extends Base { 23 | 24 | /** 25 | * Returns a label for the crumb. 26 | * 27 | * @since 1.0.0 28 | * @access public 29 | * @return string 30 | */ 31 | public function label() { 32 | 33 | return sprintf( 34 | $this->breadcrumbs->label( 'paged' ), 35 | number_format_i18n( absint( get_query_var( 'paged' ) ) ) 36 | ); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Query/Home.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright Copyright (c) 2018, Justin Tadlock 10 | * @link https://github.com/justintadlock/hybrid-breadcrumbs 11 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 12 | */ 13 | 14 | namespace Hybrid\Breadcrumbs\Query; 15 | 16 | /** 17 | * Home query sub-class. 18 | * 19 | * @since 1.0.0 20 | * @access public 21 | */ 22 | class Home extends Base { 23 | 24 | /** 25 | * Builds the breadcrumbs. 26 | * 27 | * @since 1.0.0 28 | * @access public 29 | * @return void 30 | */ 31 | public function make() { 32 | 33 | is_front_page() 34 | ? $this->breadcrumbs->query( 'FrontPage' ) 35 | : $this->breadcrumbs->query( 'Singular' ); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Crumb/PagedComments.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright Copyright (c) 2018, Justin Tadlock 10 | * @link https://github.com/justintadlock/hybrid-breadcrumbs 11 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 12 | */ 13 | 14 | namespace Hybrid\Breadcrumbs\Crumb; 15 | 16 | /** 17 | * Paged comments crumb sub-class. 18 | * 19 | * @since 1.0.0 20 | * @access public 21 | */ 22 | class PagedComments extends Base { 23 | 24 | /** 25 | * Returns a label for the crumb. 26 | * 27 | * @since 1.0.0 28 | * @access public 29 | * @return string 30 | */ 31 | public function label() { 32 | 33 | return sprintf( 34 | $this->breadcrumbs->label( 'paged_comments' ), 35 | number_format_i18n( absint( get_query_var( 'cpage' ) ) ) 36 | ); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Build/Network.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright Copyright (c) 2018, Justin Tadlock 10 | * @link https://github.com/justintadlock/hybrid-breadcrumbs 11 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 12 | */ 13 | 14 | namespace Hybrid\Breadcrumbs\Build; 15 | 16 | /** 17 | * Network build sub-class. 18 | * 19 | * @since 1.0.0 20 | * @access public 21 | */ 22 | class Network extends Base { 23 | 24 | /** 25 | * Builds the breadcrumbs. 26 | * 27 | * @since 1.0.0 28 | * @access public 29 | * @return void 30 | */ 31 | public function make() { 32 | 33 | if ( is_multisite() && $this->breadcrumbs->option( 'network' ) && ! is_main_site() ) { 34 | 35 | $this->breadcrumbs->crumb( 'Network' ); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Crumb/PagedSingular.php: -------------------------------------------------------------------------------- 1 | ` is used for a post. 6 | * 7 | * @package HybridBreadcrumbs 8 | * @author Justin Tadlock 9 | * @copyright Copyright (c) 2018, Justin Tadlock 10 | * @link https://github.com/justintadlock/hybrid-breadcrumbs 11 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 12 | */ 13 | 14 | namespace Hybrid\Breadcrumbs\Crumb; 15 | 16 | /** 17 | * Paged singular crumb sub-class. 18 | * 19 | * @since 1.0.0 20 | * @access public 21 | */ 22 | class PagedSingular extends Base { 23 | 24 | /** 25 | * Returns a label for the crumb. 26 | * 27 | * @since 1.0.0 28 | * @access public 29 | * @return string 30 | */ 31 | public function label() { 32 | 33 | return sprintf( 34 | $this->breadcrumbs->label( 'paged' ), 35 | number_format_i18n( absint( get_query_var( 'page' ) ) ) 36 | ); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Query/Error.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright Copyright (c) 2018, Justin Tadlock 10 | * @link https://github.com/justintadlock/hybrid-breadcrumbs 11 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 12 | */ 13 | 14 | namespace Hybrid\Breadcrumbs\Query; 15 | 16 | /** 17 | * Error query sub-class. 18 | * 19 | * @since 1.0.0 20 | * @access public 21 | */ 22 | class Error extends Base { 23 | 24 | /** 25 | * Builds the breadcrumbs. 26 | * 27 | * @since 1.0.0 28 | * @access public 29 | * @return void 30 | */ 31 | public function make() { 32 | 33 | // Build network crumbs. 34 | $this->breadcrumbs->build( 'Network' ); 35 | 36 | // Add site home crumb. 37 | $this->breadcrumbs->crumb( 'Home' ); 38 | 39 | // Add 404 crumb. 40 | $this->breadcrumbs->crumb( 'Error' ); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Crumb/Search.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright Copyright (c) 2018, Justin Tadlock 10 | * @link https://github.com/justintadlock/hybrid-breadcrumbs 11 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 12 | */ 13 | 14 | namespace Hybrid\Breadcrumbs\Crumb; 15 | 16 | /** 17 | * Search crumb sub-class. 18 | * 19 | * @since 1.0.0 20 | * @access public 21 | */ 22 | class Search extends Base { 23 | 24 | /** 25 | * Returns a label for the crumb. 26 | * 27 | * @since 1.0.0 28 | * @access public 29 | * @return string 30 | */ 31 | public function label() { 32 | 33 | return sprintf( $this->breadcrumbs->label( 'search' ), get_search_query() ); 34 | } 35 | 36 | /** 37 | * Returns a URL for the crumb. 38 | * 39 | * @since 1.0.0 40 | * @access public 41 | * @return string 42 | */ 43 | public function url() { 44 | 45 | return get_search_link(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/Crumb/Network.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright Copyright (c) 2018, Justin Tadlock 10 | * @link https://github.com/justintadlock/hybrid-breadcrumbs 11 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 12 | */ 13 | 14 | namespace Hybrid\Breadcrumbs\Crumb; 15 | 16 | /** 17 | * Network crumb sub-class. 18 | * 19 | * @since 1.0.0 20 | * @access public 21 | */ 22 | class Network extends Base { 23 | 24 | /** 25 | * Returns a label for the crumb. 26 | * 27 | * @since 1.0.0 28 | * @access public 29 | * @return string 30 | */ 31 | public function label() { 32 | 33 | return $this->breadcrumbs->label( 'home' ); 34 | } 35 | 36 | /** 37 | * Returns a URL for the crumb. 38 | * 39 | * @since 1.0.0 40 | * @access public 41 | * @return string 42 | */ 43 | public function url() { 44 | 45 | return network_home_url(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/Contracts/Crumb.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright Copyright (c) 2018, Justin Tadlock 10 | * @link https://github.com/justintadlock/hybrid-breadcrumbs 11 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 12 | */ 13 | 14 | namespace Hybrid\Breadcrumbs\Contracts; 15 | 16 | /** 17 | * Crumb interface. 18 | * 19 | * @since 1.0.0 20 | * @access public 21 | */ 22 | interface Crumb { 23 | 24 | /** 25 | * Returns a type for the crumb. 26 | * 27 | * @since 1.0.0 28 | * @access public 29 | * @return string 30 | */ 31 | public function type(); 32 | 33 | /** 34 | * Returns a text label for the crumb. 35 | * 36 | * @since 1.0.0 37 | * @access public 38 | * @return string 39 | */ 40 | public function label(); 41 | 42 | /** 43 | * Returns a URL for the crumb. 44 | * 45 | * @since 1.0.0 46 | * @access public 47 | * @return string 48 | */ 49 | public function url(); 50 | } 51 | -------------------------------------------------------------------------------- /src/Crumb/Minute.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright Copyright (c) 2018, Justin Tadlock 10 | * @link https://github.com/justintadlock/hybrid-breadcrumbs 11 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 12 | */ 13 | 14 | namespace Hybrid\Breadcrumbs\Crumb; 15 | 16 | /** 17 | * Minute crumb sub-class. 18 | * 19 | * @since 1.0.0 20 | * @access public 21 | */ 22 | class Minute extends Base { 23 | 24 | /** 25 | * Post object. 26 | * 27 | * @since 1.0.0 28 | * @access protected 29 | * @var \WP_Post 30 | */ 31 | protected $post = null; 32 | 33 | /** 34 | * Returns a label for the crumb. 35 | * 36 | * @since 1.0.0 37 | * @access public 38 | * @return string 39 | */ 40 | public function label() { 41 | 42 | return sprintf( 43 | $this->breadcrumbs->label( 'archive_minute' ), 44 | get_the_time( 45 | esc_html_x( 'i', 'minute archives time format', 'hybrid-core' ), 46 | $this->post 47 | ) 48 | ); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/Crumb/Home.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright Copyright (c) 2018, Justin Tadlock 10 | * @link https://github.com/justintadlock/hybrid-breadcrumbs 11 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 12 | */ 13 | 14 | namespace Hybrid\Breadcrumbs\Crumb; 15 | 16 | /** 17 | * Home crumb sub-class. 18 | * 19 | * @since 1.0.0 20 | * @access public 21 | */ 22 | class Home extends Base { 23 | 24 | /** 25 | * Returns a label for the crumb. 26 | * 27 | * @since 1.0.0 28 | * @access public 29 | * @return string 30 | */ 31 | public function label() { 32 | 33 | $network = $this->breadcrumbs->option( 'network' ) && ! is_main_site(); 34 | 35 | return $network ? get_bloginfo( 'name' ) : $this->breadcrumbs->label( 'home' ); 36 | } 37 | 38 | /** 39 | * Returns a URL for the crumb. 40 | * 41 | * @since 1.0.0 42 | * @access public 43 | * @return string 44 | */ 45 | public function url() { 46 | 47 | return user_trailingslashit( home_url() ); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/Query/Hour.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright Copyright (c) 2018, Justin Tadlock 10 | * @link https://github.com/justintadlock/hybrid-breadcrumbs 11 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 12 | */ 13 | 14 | namespace Hybrid\Breadcrumbs\Query; 15 | 16 | /** 17 | * Hour query sub-class. 18 | * 19 | * @since 1.0.0 20 | * @access public 21 | */ 22 | class Hour extends Base { 23 | 24 | /** 25 | * Builds the breadcrumbs. 26 | * 27 | * @since 1.0.0 28 | * @access public 29 | * @return void 30 | */ 31 | public function make() { 32 | 33 | // Build network crumbs. 34 | $this->breadcrumbs->build( 'Network' ); 35 | 36 | // Add site home crumb. 37 | $this->breadcrumbs->crumb( 'Home' ); 38 | 39 | // Build rewrite front crumbs. 40 | $this->breadcrumbs->build( 'RewriteFront' ); 41 | 42 | // Add hour crumb. 43 | $this->breadcrumbs->crumb( 'Hour' ); 44 | 45 | // Build paged crumbs. 46 | $this->breadcrumbs->build( 'Paged' ); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Query/Year.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright Copyright (c) 2018, Justin Tadlock 10 | * @link https://github.com/justintadlock/hybrid-breadcrumbs 11 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 12 | */ 13 | 14 | namespace Hybrid\Breadcrumbs\Query; 15 | 16 | /** 17 | * Year query sub-class. 18 | * 19 | * @since 1.0.0 20 | * @access public 21 | */ 22 | class Year extends Base { 23 | 24 | /** 25 | * Builds the breadcrumbs. 26 | * 27 | * @since 1.0.0 28 | * @access public 29 | * @return void 30 | */ 31 | public function make() { 32 | 33 | // Build network crumbs. 34 | $this->breadcrumbs->build( 'Network' ); 35 | 36 | // Add site home crumb. 37 | $this->breadcrumbs->crumb( 'Home' ); 38 | 39 | // Build rewrite front crumbs. 40 | $this->breadcrumbs->build( 'RewriteFront' ); 41 | 42 | // Add year crumb. 43 | $this->breadcrumbs->crumb( 'Year' ); 44 | 45 | // Build paged crumbs. 46 | $this->breadcrumbs->build( 'Paged' ); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Query/FrontPage.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright Copyright (c) 2018, Justin Tadlock 10 | * @link https://github.com/justintadlock/hybrid-breadcrumbs 11 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 12 | */ 13 | 14 | namespace Hybrid\Breadcrumbs\Query; 15 | 16 | use Hybrid\Breadcrumbs\Util\Helpers; 17 | 18 | /** 19 | * Front page query sub-class. 20 | * 21 | * @since 1.0.0 22 | * @access public 23 | */ 24 | class FrontPage extends Base { 25 | 26 | /** 27 | * Builds the breadcrumbs. 28 | * 29 | * @since 1.0.0 30 | * @access public 31 | * @return void 32 | */ 33 | public function make() { 34 | 35 | if ( $this->breadcrumbs->option( 'show_on_front' ) || Helpers::isPagedView() ) { 36 | 37 | // Build network crumbs. 38 | $this->breadcrumbs->build( 'Network' ); 39 | 40 | // Add site home crumb. 41 | $this->breadcrumbs->crumb( 'Home' ); 42 | 43 | // Build paged crumbs. 44 | $this->breadcrumbs->build( 'Paged' ); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/Crumb/MinuteHour.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright Copyright (c) 2018, Justin Tadlock 10 | * @link https://github.com/justintadlock/hybrid-breadcrumbs 11 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 12 | */ 13 | 14 | namespace Hybrid\Breadcrumbs\Crumb; 15 | 16 | /** 17 | * Minute + Hour crumb sub-class. 18 | * 19 | * @since 1.0.0 20 | * @access public 21 | */ 22 | class MinuteHour extends Base { 23 | 24 | /** 25 | * Post object. 26 | * 27 | * @since 1.0.0 28 | * @access protected 29 | * @var \WP_Post 30 | */ 31 | protected $post = null; 32 | 33 | /** 34 | * Returns a label for the crumb. 35 | * 36 | * @since 1.0.0 37 | * @access public 38 | * @return string 39 | */ 40 | public function label() { 41 | 42 | return sprintf( 43 | $this->breadcrumbs->label( 'archive_minute_hour' ), 44 | get_the_time( 45 | esc_html_x( 'g:i a', 'minute and hour archives time format', 'hybrid-core' ), 46 | $this->post 47 | ) 48 | ); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/Query/Minute.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright Copyright (c) 2018, Justin Tadlock 10 | * @link https://github.com/justintadlock/hybrid-breadcrumbs 11 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 12 | */ 13 | 14 | namespace Hybrid\Breadcrumbs\Query; 15 | 16 | /** 17 | * Minute query sub-class. 18 | * 19 | * @since 1.0.0 20 | * @access public 21 | */ 22 | class Minute extends Base { 23 | 24 | /** 25 | * Builds the breadcrumbs. 26 | * 27 | * @since 1.0.0 28 | * @access public 29 | * @return void 30 | */ 31 | public function make() { 32 | 33 | // Build network crumbs. 34 | $this->breadcrumbs->build( 'Network' ); 35 | 36 | // Add site home crumb. 37 | $this->breadcrumbs->crumb( 'Home' ); 38 | 39 | // Build rewrite front crumbs. 40 | $this->breadcrumbs->build( 'RewriteFront' ); 41 | 42 | // Add minute crumb. 43 | $this->breadcrumbs->crumb( 'Minute' ); 44 | 45 | // Build paged crumbs. 46 | $this->breadcrumbs->build( 'Paged' ); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Query/Search.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright Copyright (c) 2018, Justin Tadlock 10 | * @link https://github.com/justintadlock/hybrid-breadcrumbs 11 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 12 | */ 13 | 14 | namespace Hybrid\Breadcrumbs\Query; 15 | 16 | /** 17 | * Search query sub-class. 18 | * 19 | * @since 1.0.0 20 | * @access public 21 | */ 22 | class Search extends Base { 23 | 24 | /** 25 | * Builds the breadcrumbs. 26 | * 27 | * @since 1.0.0 28 | * @access public 29 | * @return void 30 | */ 31 | public function make() { 32 | 33 | // Build network crumbs. 34 | $this->breadcrumbs->build( 'Network' ); 35 | 36 | // Add site home crumb. 37 | $this->breadcrumbs->crumb( 'Home' ); 38 | 39 | // Build rewrite front crumbs. 40 | $this->breadcrumbs->build( 'RewriteFront' ); 41 | 42 | // Add search crumb. 43 | $this->breadcrumbs->crumb( 'Search' ); 44 | 45 | // Build paged crumbs. 46 | $this->breadcrumbs->build( 'Paged' ); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Query/MinuteHour.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright Copyright (c) 2018, Justin Tadlock 10 | * @link https://github.com/justintadlock/hybrid-breadcrumbs 11 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 12 | */ 13 | 14 | namespace Hybrid\Breadcrumbs\Query; 15 | 16 | /** 17 | * Minute + Hour query sub-class. 18 | * 19 | * @since 1.0.0 20 | * @access public 21 | */ 22 | class MinuteHour extends Base { 23 | 24 | /** 25 | * Builds the breadcrumbs. 26 | * 27 | * @since 1.0.0 28 | * @access public 29 | * @return void 30 | */ 31 | public function make() { 32 | 33 | // Build network crumbs. 34 | $this->breadcrumbs->build( 'Network' ); 35 | 36 | // Add site home crumb. 37 | $this->breadcrumbs->crumb( 'Home' ); 38 | 39 | // Build rewrite front crumbs. 40 | $this->breadcrumbs->build( 'RewriteFront' ); 41 | 42 | // Add minute-hour crumb. 43 | $this->breadcrumbs->crumb( 'MinuteHour' ); 44 | 45 | // Build paged crumbs. 46 | $this->breadcrumbs->build( 'Paged' ); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Crumb/Author.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright Copyright (c) 2018, Justin Tadlock 10 | * @link https://github.com/justintadlock/hybrid-breadcrumbs 11 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 12 | */ 13 | 14 | namespace Hybrid\Breadcrumbs\Crumb; 15 | 16 | /** 17 | * Author crumb sub-class. 18 | * 19 | * @since 1.0.0 20 | * @access public 21 | */ 22 | class Author extends Base { 23 | 24 | /** 25 | * User object. 26 | * 27 | * @since 1.0.0 28 | * @access protected 29 | * @var \WP_User 30 | */ 31 | protected $user; 32 | 33 | /** 34 | * Returns a label for the crumb. 35 | * 36 | * @since 1.0.0 37 | * @access public 38 | * @return string 39 | */ 40 | public function label() { 41 | 42 | return get_the_author_meta( 'display_name', $this->user->ID ); 43 | } 44 | 45 | /** 46 | * Returns a URL for the crumb. 47 | * 48 | * @since 1.0.0 49 | * @access public 50 | * @return string 51 | */ 52 | public function url() { 53 | 54 | return get_author_posts_url( $this->user->ID ); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/Query/Month.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright Copyright (c) 2018, Justin Tadlock 10 | * @link https://github.com/justintadlock/hybrid-breadcrumbs 11 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 12 | */ 13 | 14 | namespace Hybrid\Breadcrumbs\Query; 15 | 16 | /** 17 | * Month query sub-class. 18 | * 19 | * @since 1.0.0 20 | * @access public 21 | */ 22 | class Month extends Base { 23 | 24 | /** 25 | * Builds the breadcrumbs. 26 | * 27 | * @since 1.0.0 28 | * @access public 29 | * @return void 30 | */ 31 | public function make() { 32 | 33 | // Build network crumbs. 34 | $this->breadcrumbs->build( 'Network' ); 35 | 36 | // Add site home crumb. 37 | $this->breadcrumbs->crumb( 'Home' ); 38 | 39 | // Build rewrite front crumbs. 40 | $this->breadcrumbs->build( 'RewriteFront' ); 41 | 42 | // Add year and month crumbs. 43 | $this->breadcrumbs->crumb( 'Year' ); 44 | $this->breadcrumbs->crumb( 'Month' ); 45 | 46 | // Build paged crumbs. 47 | $this->breadcrumbs->build( 'Paged' ); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/Query/Paged.php: -------------------------------------------------------------------------------- 1 | 11 | * @copyright Copyright (c) 2018, Justin Tadlock 12 | * @link https://github.com/justintadlock/hybrid-breadcrumbs 13 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 14 | */ 15 | 16 | namespace Hybrid\Breadcrumbs\Query; 17 | 18 | /** 19 | * Paged query sub-class. 20 | * 21 | * @since 1.0.0 22 | * @access public 23 | */ 24 | class Paged extends Base { 25 | 26 | /** 27 | * Builds the breadcrumbs. 28 | * 29 | * @since 1.0.0 30 | * @access public 31 | * @return void 32 | */ 33 | public function make() { 34 | 35 | // Build network crumbs. 36 | $this->breadcrumbs->build( 'Network' ); 37 | 38 | // Add site home crumb. 39 | $this->breadcrumbs->crumb( 'Home' ); 40 | 41 | // Build rewrite front crumbs. 42 | $this->breadcrumbs->build( 'RewriteFront' ); 43 | 44 | // Build paged crumbs. 45 | $this->breadcrumbs->build( 'Paged' ); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/Query/Week.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright Copyright (c) 2018, Justin Tadlock 10 | * @link https://github.com/justintadlock/hybrid-breadcrumbs 11 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 12 | */ 13 | 14 | namespace Hybrid\Breadcrumbs\Query; 15 | 16 | /** 17 | * Week query sub-class. 18 | * 19 | * @since 1.0.0 20 | * @access public 21 | */ 22 | class WeekArchive extends Base { 23 | 24 | /** 25 | * Builds the breadcrumbs. 26 | * 27 | * @since 1.0.0 28 | * @access public 29 | * @return void 30 | */ 31 | public function make() { 32 | 33 | // Build network crumbs. 34 | $this->breadcrumbs->build( 'Network' ); 35 | 36 | // Add site home crumb. 37 | $this->breadcrumbs->crumb( 'Home' ); 38 | 39 | // Build rewrite front crumbs. 40 | $this->breadcrumbs->build( 'RewriteFront' ); 41 | 42 | // Add the year and week crumbs. 43 | $this->breadcrumbs->crumb( 'Year' ); 44 | $this->breadcrumbs->crumb( 'Week' ); 45 | 46 | // Build paged crumbs. 47 | $this->breadcrumbs->build( 'Paged' ); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/Query/Day.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright Copyright (c) 2018, Justin Tadlock 10 | * @link https://github.com/justintadlock/hybrid-breadcrumbs 11 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 12 | */ 13 | 14 | namespace Hybrid\Breadcrumbs\Query; 15 | 16 | /** 17 | * Day query sub-class. 18 | * 19 | * @since 1.0.0 20 | * @access public 21 | */ 22 | class Day extends Base { 23 | 24 | /** 25 | * Builds the breadcrumbs. 26 | * 27 | * @since 1.0.0 28 | * @access public 29 | * @return void 30 | */ 31 | public function make() { 32 | 33 | // Build network crumbs. 34 | $this->breadcrumbs->build( 'Network' ); 35 | 36 | // Add site home crumb. 37 | $this->breadcrumbs->crumb( 'Home' ); 38 | 39 | // Build rewrite front crumbs. 40 | $this->breadcrumbs->build( 'RewriteFront' ); 41 | 42 | // Add year, month, and day crumbs. 43 | $this->breadcrumbs->crumb( 'Year' ); 44 | $this->breadcrumbs->crumb( 'Month' ); 45 | $this->breadcrumbs->crumb( 'Day' ); 46 | 47 | // Build paged crumbs. 48 | $this->breadcrumbs->build( 'Paged' ); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/Crumb/Week.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright Copyright (c) 2018, Justin Tadlock 10 | * @link https://github.com/justintadlock/hybrid-breadcrumbs 11 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 12 | */ 13 | 14 | namespace Hybrid\Breadcrumbs\Crumb; 15 | 16 | /** 17 | * Week crumb sub-class. 18 | * 19 | * @since 1.0.0 20 | * @access public 21 | */ 22 | class Week extends Base { 23 | 24 | /** 25 | * Returns a label for the crumb. 26 | * 27 | * @since 1.0.0 28 | * @access public 29 | * @return string 30 | */ 31 | public function label() { 32 | 33 | return sprintf( 34 | $this->breadcrumbs->label( 'archive_week' ), 35 | get_the_time( 36 | esc_html_x( 'W', 'weekly archives date format', 'hybrid-core' ) 37 | ) 38 | ); 39 | } 40 | 41 | /** 42 | * Returns a URL for the crumb. 43 | * 44 | * @since 1.0.0 45 | * @access public 46 | * @return string 47 | */ 48 | public function url() { 49 | 50 | return add_query_arg( [ 51 | 'm' => get_the_time( 'Y' ), 52 | 'w' => get_the_time( 'W' ) 53 | ], user_trailingslashit( home_url() ) ); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/Build/RewriteFront.php: -------------------------------------------------------------------------------- 1 | 13 | * @copyright Copyright (c) 2018, Justin Tadlock 14 | * @link https://github.com/justintadlock/hybrid-breadcrumbs 15 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 16 | */ 17 | 18 | namespace Hybrid\Breadcrumbs\Build; 19 | 20 | /** 21 | * Rewrite front build sub-class. 22 | * 23 | * @since 1.0.0 24 | * @access public 25 | */ 26 | class RewriteFront extends Base { 27 | 28 | /** 29 | * Builds the breadcrumbs. 30 | * 31 | * @since 1.0.0 32 | * @access public 33 | * @return void 34 | */ 35 | public function make() { 36 | global $wp_rewrite; 37 | 38 | if ( $wp_rewrite->front ) { 39 | 40 | $this->breadcrumbs->build( 'Path', [ 41 | 'path' => $wp_rewrite->front 42 | ] ); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Crumb/Year.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright Copyright (c) 2018, Justin Tadlock 10 | * @link https://github.com/justintadlock/hybrid-breadcrumbs 11 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 12 | */ 13 | 14 | namespace Hybrid\Breadcrumbs\Crumb; 15 | 16 | /** 17 | * Year crumb sub-class. 18 | * 19 | * @since 1.0.0 20 | * @access public 21 | */ 22 | class Year extends Base { 23 | 24 | /** 25 | * Post object. 26 | * 27 | * @since 1.0.0 28 | * @access protected 29 | * @var \WP_Post 30 | */ 31 | protected $post = null; 32 | 33 | /** 34 | * Returns a label for the crumb. 35 | * 36 | * @since 1.0.0 37 | * @access public 38 | * @return string 39 | */ 40 | public function label() { 41 | 42 | return sprintf( 43 | $this->breadcrumbs->label( 'archive_year' ), 44 | get_the_time( 45 | esc_html_x( 'Y', 'yearly archives date format', 'hybrid-core' ), 46 | $this->post 47 | ) 48 | ); 49 | } 50 | 51 | /** 52 | * Returns a URL for the crumb. 53 | * 54 | * @since 1.0.0 55 | * @access public 56 | * @return string 57 | */ 58 | public function url() { 59 | 60 | return get_year_link( get_the_time( 'Y', $this->post ) ); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/Crumb/Post.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright Copyright (c) 2018, Justin Tadlock 10 | * @link https://github.com/justintadlock/hybrid-breadcrumbs 11 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 12 | */ 13 | 14 | namespace Hybrid\Breadcrumbs\Crumb; 15 | 16 | /** 17 | * Post crumb sub-class. 18 | * 19 | * @since 1.0.0 20 | * @access public 21 | */ 22 | class Post extends Base { 23 | 24 | /** 25 | * Post object. 26 | * 27 | * @since 1.0.0 28 | * @access protected 29 | * @var \WP_Post 30 | */ 31 | protected $post = null; 32 | 33 | /** 34 | * Returns a label for the crumb. 35 | * 36 | * @since 1.0.0 37 | * @access public 38 | * @return string 39 | */ 40 | public function label() { 41 | 42 | $post_id = $this->post->ID; 43 | 44 | if ( is_single( $post_id ) || is_page( $post_id ) || is_attachment( $post_id ) ) { 45 | 46 | return single_post_title( '', false ); 47 | } 48 | 49 | return get_the_title( $this->post->ID ); 50 | } 51 | 52 | /** 53 | * Returns a URL for the crumb. 54 | * 55 | * @since 1.0.0 56 | * @access public 57 | * @return string 58 | */ 59 | public function url() { 60 | 61 | return get_permalink( $this->post->ID ); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/Query/Singular.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright Copyright (c) 2018, Justin Tadlock 10 | * @link https://github.com/justintadlock/hybrid-breadcrumbs 11 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 12 | */ 13 | 14 | namespace Hybrid\Breadcrumbs\Query; 15 | 16 | /** 17 | * Singular query sub-class. 18 | * 19 | * @since 1.0.0 20 | * @access public 21 | */ 22 | class Singular extends Base { 23 | 24 | /** 25 | * Post object. 26 | * 27 | * @since 1.2.0 28 | * @access protected 29 | * @var \WP_Post 30 | */ 31 | protected $post; 32 | 33 | /** 34 | * Builds the breadcrumbs. 35 | * 36 | * @since 1.0.0 37 | * @access public 38 | * @return void 39 | */ 40 | public function make() { 41 | 42 | $post = $this->post ?: get_queried_object(); 43 | 44 | // Build network crumbs. 45 | $this->breadcrumbs->build( 'Network' ); 46 | 47 | // Add site home crumb. 48 | $this->breadcrumbs->crumb( 'Home' ); 49 | 50 | // Build post crumbs. 51 | $this->breadcrumbs->build( 'Post', [ 'post' => $post ] ); 52 | 53 | // Add post crumb. 54 | $this->breadcrumbs->crumb( 'Post', [ 'post' => $post ] ); 55 | 56 | // Build paged crumbs. 57 | $this->breadcrumbs->build( 'Paged' ); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/Query/Tax.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright Copyright (c) 2018, Justin Tadlock 10 | * @link https://github.com/justintadlock/hybrid-breadcrumbs 11 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 12 | */ 13 | 14 | namespace Hybrid\Breadcrumbs\Query; 15 | 16 | /** 17 | * Taxonomy query sub-class. 18 | * 19 | * @since 1.0.0 20 | * @access public 21 | */ 22 | class Tax extends Base { 23 | 24 | /** 25 | * Term object. 26 | * 27 | * @since 1.2.0 28 | * @access protected 29 | * @var \WP_Term 30 | */ 31 | protected $term; 32 | 33 | /** 34 | * Builds the breadcrumbs. 35 | * 36 | * @since 1.0.0 37 | * @access public 38 | * @return void 39 | */ 40 | public function make() { 41 | 42 | $term = $this->term ?: get_queried_object(); 43 | 44 | // Build network crumbs. 45 | $this->breadcrumbs->build( 'Network' ); 46 | 47 | // Add site home crumb. 48 | $this->breadcrumbs->crumb( 'Home' ); 49 | 50 | // Build term crumbs. 51 | $this->breadcrumbs->build( 'Term', [ 'term' => $term ] ); 52 | 53 | // Add term crumb. 54 | $this->breadcrumbs->crumb( 'Term', [ 'term' => $term ] ); 55 | 56 | // Build paged crumbs. 57 | $this->breadcrumbs->build( 'Paged' ); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/Crumb/Term.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright Copyright (c) 2018, Justin Tadlock 10 | * @link https://github.com/justintadlock/hybrid-breadcrumbs 11 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 12 | */ 13 | 14 | namespace Hybrid\Breadcrumbs\Crumb; 15 | 16 | /** 17 | * Term crumb sub-class. 18 | * 19 | * @since 1.0.0 20 | * @access public 21 | */ 22 | class Term extends Base { 23 | 24 | /** 25 | * Term object. 26 | * 27 | * @since 1.0.0 28 | * @access protected 29 | * @var \WP_Term 30 | */ 31 | protected $term; 32 | 33 | /** 34 | * Returns a label for the crumb. 35 | * 36 | * @since 1.0.0 37 | * @access public 38 | * @return string 39 | */ 40 | public function label() { 41 | 42 | $tax = $this->term->taxonomy; 43 | $term_id = $this->term->term_id; 44 | 45 | if ( is_tax( $tax, $term_id ) || is_category( $term_id ) || is_tag( $term_id ) ) { 46 | 47 | return single_term_title( '', false ); 48 | } 49 | 50 | return $this->term->name; 51 | } 52 | 53 | /** 54 | * Returns a URL for the crumb. 55 | * 56 | * @since 1.0.0 57 | * @access public 58 | * @return string 59 | */ 60 | public function url() { 61 | 62 | return get_term_link( $this->term, $this->term->taxonomy ); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/Crumb/Month.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright Copyright (c) 2018, Justin Tadlock 10 | * @link https://github.com/justintadlock/hybrid-breadcrumbs 11 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 12 | */ 13 | 14 | namespace Hybrid\Breadcrumbs\Crumb; 15 | 16 | /** 17 | * Month crumb sub-class. 18 | * 19 | * @since 1.0.0 20 | * @access public 21 | */ 22 | class Month extends Base { 23 | 24 | /** 25 | * Post object. 26 | * 27 | * @since 1.0.0 28 | * @access protected 29 | * @var \WP_Post 30 | */ 31 | protected $post = null; 32 | 33 | /** 34 | * Returns a label for the crumb. 35 | * 36 | * @since 1.0.0 37 | * @access public 38 | * @return string 39 | */ 40 | public function label() { 41 | 42 | return sprintf( 43 | $this->breadcrumbs->label( 'archive_month' ), 44 | get_the_time( 45 | esc_html_x( 'F', 'monthly archives date format', 'hybrid-core' ), 46 | $this->post 47 | ) 48 | ); 49 | } 50 | 51 | /** 52 | * Returns a URL for the crumb. 53 | * 54 | * @since 1.0.0 55 | * @access public 56 | * @return string 57 | */ 58 | public function url() { 59 | 60 | return get_month_link( 61 | get_the_time( 'Y', $this->post ), 62 | get_the_time( 'm', $this->post ) 63 | ); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/Crumb/Day.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright Copyright (c) 2018, Justin Tadlock 10 | * @link https://github.com/justintadlock/hybrid-breadcrumbs 11 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 12 | */ 13 | 14 | namespace Hybrid\Breadcrumbs\Crumb; 15 | 16 | /** 17 | * Day crumb sub-class. 18 | * 19 | * @since 1.0.0 20 | * @access public 21 | */ 22 | class Day extends Base { 23 | 24 | /** 25 | * Post object. 26 | * 27 | * @since 1.0.0 28 | * @access protected 29 | * @var \WP_Post 30 | */ 31 | protected $post = null; 32 | 33 | /** 34 | * Returns a label for the crumb. 35 | * 36 | * @since 1.0.0 37 | * @access public 38 | * @return string 39 | */ 40 | public function label() { 41 | 42 | return sprintf( 43 | $this->breadcrumbs->label( 'archive_day' ), 44 | get_the_time( 45 | esc_html_x( 'j', 'daily archives date format', 'hybrid-core' ), 46 | $this->post 47 | ) 48 | ); 49 | } 50 | 51 | /** 52 | * Returns a URL for the crumb. 53 | * 54 | * @since 1.0.0 55 | * @access public 56 | * @return string 57 | */ 58 | public function url() { 59 | 60 | return get_day_link( 61 | get_the_time( 'Y', $this->post ), 62 | get_the_time( 'm', $this->post ), 63 | get_the_time( 'd', $this->post ) 64 | ); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/Crumb/PostType.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright Copyright (c) 2018, Justin Tadlock 10 | * @link https://github.com/justintadlock/hybrid-breadcrumbs 11 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 12 | */ 13 | 14 | namespace Hybrid\Breadcrumbs\Crumb; 15 | 16 | /** 17 | * Post type crumb sub-class. 18 | * 19 | * @since 1.0.0 20 | * @access public 21 | */ 22 | class PostType extends Base { 23 | 24 | /** 25 | * Post type object. 26 | * 27 | * @since 1.0.0 28 | * @access protected 29 | * @var \WP_Post_Type 30 | */ 31 | protected $post_type; 32 | 33 | /** 34 | * Returns a label for the crumb. 35 | * 36 | * @since 1.0.0 37 | * @access public 38 | * @return string 39 | */ 40 | public function label() { 41 | 42 | if ( is_post_type_archive( $this->post_type->name ) ) { 43 | 44 | return post_type_archive_title( '', false ); 45 | } 46 | 47 | $labels = $this->post_type->labels; 48 | 49 | return apply_filters( 50 | 'post_type_archive_title', // Core WP filter hook. 51 | ! empty( $labels->archive_title ) ? $labels->archive_title : $labels->name, 52 | $this->post_type->name 53 | ); 54 | } 55 | 56 | /** 57 | * Returns a URL for the crumb. 58 | * 59 | * @since 1.0.0 60 | * @access public 61 | * @return string 62 | */ 63 | public function url() { 64 | 65 | return get_post_type_archive_link( $this->post_type->name ); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/Build/Paged.php: -------------------------------------------------------------------------------- 1 | `, and comments pagination. 8 | * 9 | * @package HybridBreadcrumbs 10 | * @author Justin Tadlock 11 | * @copyright Copyright (c) 2018, Justin Tadlock 12 | * @link https://github.com/justintadlock/hybrid-breadcrumbs 13 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 14 | */ 15 | 16 | namespace Hybrid\Breadcrumbs\Build; 17 | 18 | /** 19 | * Paged build sub-class. 20 | * 21 | * @since 1.0.0 22 | * @access public 23 | */ 24 | class Paged extends Base { 25 | 26 | /** 27 | * Post object. 28 | * 29 | * @since 1.0.0 30 | * @access protected 31 | * @var \WP_Post 32 | */ 33 | protected $post; 34 | 35 | /** 36 | * Builds the breadcrumbs. 37 | * 38 | * @since 1.0.0 39 | * @access public 40 | * @return void 41 | */ 42 | public function make() { 43 | 44 | // If viewing a paged archive-type page. 45 | if ( is_paged() ) { 46 | 47 | $this->breadcrumbs->crumb( 'Paged' ); 48 | 49 | // If viewing a paged singular post. 50 | } elseif ( is_singular() && 1 < get_query_var( 'page' ) ) { 51 | 52 | $this->breadcrumbs->crumb( 'PagedSingular' ); 53 | 54 | // If viewing a singular post with paged comments. 55 | } elseif ( is_singular() && get_option( 'page_comments' ) && 1 < get_query_var( 'cpage' ) ) { 56 | 57 | $this->breadcrumbs->crumb( 'PagedComments' ); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/Query/Author.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright Copyright (c) 2018, Justin Tadlock 10 | * @link https://github.com/justintadlock/hybrid-breadcrumbs 11 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 12 | */ 13 | 14 | namespace Hybrid\Breadcrumbs\Query; 15 | 16 | use WP_User; 17 | 18 | /** 19 | * Author query sub-class. 20 | * 21 | * @since 1.0.0 22 | * @access public 23 | */ 24 | class Author extends Base { 25 | 26 | /** 27 | * User object. 28 | * 29 | * @since 1.2.0 30 | * @access protected 31 | * @var \WP_User 32 | */ 33 | protected $user; 34 | 35 | /** 36 | * Builds the breadcrumbs. 37 | * 38 | * @since 1.0.0 39 | * @access public 40 | * @return void 41 | */ 42 | public function make() { 43 | global $wp_rewrite; 44 | 45 | $user = $this->user ?: new WP_User( get_query_var( 'author' ) ); 46 | 47 | // Build network crumbs. 48 | $this->breadcrumbs->build( 'Network' ); 49 | 50 | // Add site home crumb. 51 | $this->breadcrumbs->crumb( 'Home' ); 52 | 53 | // Build rewrite front crumbs. 54 | $this->breadcrumbs->build( 'RewriteFront' ); 55 | 56 | // If $author_base exists, check for parent pages. 57 | if ( ! empty( $wp_rewrite->author_base ) ) { 58 | 59 | $this->breadcrumbs->build( 'Path', [ 60 | 'page' => $wp_rewrite->author_base 61 | ] ); 62 | } 63 | 64 | // Add author crumb. 65 | $this->breadcrumbs->crumb( 'Author', [ 'user' => $user ] ); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/Util/Helpers.php: -------------------------------------------------------------------------------- 1 | 10 | * @copyright Copyright (c) 2018, Justin Tadlock 11 | * @link https://github.com/justintadlock/hybrid-breadcrumbs 12 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 13 | */ 14 | 15 | namespace Hybrid\Breadcrumbs\Util; 16 | 17 | /** 18 | * Helpers class. 19 | * 20 | * @since 1.0.0 21 | * @access public 22 | */ 23 | class Helpers { 24 | 25 | /** 26 | * Helper function for determining whether we're viewing a paginated page. 27 | * 28 | * @since 1.0.0 29 | * @access public 30 | * @return bool 31 | */ 32 | public static function isPagedView() { 33 | 34 | return is_paged() || 1 < get_query_var( 'page' ) || 1 < get_query_var( 'cpage' ); 35 | } 36 | 37 | /** 38 | * Gets post types by slug. This is needed because the `get_post_types()` 39 | * function doesn't exactly match the `has_archive` argument when it's 40 | * set as a string instead of a boolean. 41 | * 42 | * @since 1.0.0 43 | * @access public 44 | * @param string $slug 45 | * @return array 46 | */ 47 | public static function getPostTypesBySlug( $slug ) { 48 | 49 | $return = []; 50 | 51 | $post_types = get_post_types( [], 'objects' ); 52 | 53 | foreach ( $post_types as $type ) { 54 | 55 | if ( $slug === $type->has_archive || ( true === $type->has_archive && $slug === $type->rewrite['slug'] ) ) { 56 | 57 | $return[] = $type; 58 | } 59 | } 60 | 61 | return $return; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/Build/Post.php: -------------------------------------------------------------------------------- 1 | 10 | * @copyright Copyright (c) 2018, Justin Tadlock 11 | * @link https://github.com/justintadlock/hybrid-breadcrumbs 12 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 13 | */ 14 | 15 | namespace Hybrid\Breadcrumbs\Build; 16 | 17 | /** 18 | * Post build sub-class. 19 | * 20 | * @since 1.0.0 21 | * @access public 22 | */ 23 | class Post extends Base { 24 | 25 | /** 26 | * Post object. 27 | * 28 | * @since 1.0.0 29 | * @access protected 30 | * @var \WP_Post 31 | */ 32 | protected $post; 33 | 34 | /** 35 | * Builds the breadcrumbs. 36 | * 37 | * @since 1.0.0 38 | * @access public 39 | * @return void 40 | */ 41 | public function make() { 42 | 43 | // If the post has a parent, follow the parent trail. 44 | if ( 0 < $this->post->post_parent ) { 45 | 46 | $this->breadcrumbs->build( 'PostAncestors', [ 47 | 'post' => $this->post 48 | ] ); 49 | 50 | // If the post doesn't have a parent, get its hierarchy based off the post type. 51 | } else { 52 | 53 | $this->breadcrumbs->build( 'PostHierarchy', [ 54 | 'post' => $this->post 55 | ] ); 56 | } 57 | 58 | // Display terms for specific post type taxonomy if requested. 59 | if ( $this->breadcrumbs->postTaxonomy( $this->post->post_type ) ) { 60 | 61 | $this->breadcrumbs->build( 'PostTerms', [ 62 | 'post' => $this->post, 63 | 'taxonomy' => $this->breadcrumbs->postTaxonomy( $this->post->post_type ) 64 | ] ); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/Build/TermAncestors.php: -------------------------------------------------------------------------------- 1 | 10 | * @copyright Copyright (c) 2018, Justin Tadlock 11 | * @link https://github.com/justintadlock/hybrid-breadcrumbs 12 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 13 | */ 14 | 15 | namespace Hybrid\Breadcrumbs\Build; 16 | 17 | /** 18 | * Term ancestors build sub-class. 19 | * 20 | * @since 1.0.0 21 | * @access public 22 | */ 23 | class TermAncestors extends Base { 24 | 25 | /** 26 | * Term object. 27 | * 28 | * @since 1.0.0 29 | * @access protected 30 | * @var \WP_Term 31 | */ 32 | protected $term; 33 | 34 | /** 35 | * Builds the breadcrumbs. 36 | * 37 | * @since 1.0.0 38 | * @access public 39 | * @return void 40 | */ 41 | public function make() { 42 | 43 | $term_id = $this->term->parent; 44 | $taxonomy = $this->term->taxonomy; 45 | $parents = []; 46 | 47 | while ( $term_id ) { 48 | 49 | // Get the parent term. 50 | $term = get_term( $term_id, $taxonomy ); 51 | 52 | // Add the term link to the array of parent terms. 53 | $parents[] = $term; 54 | 55 | // Set the parent term's parent as the parent ID. 56 | $term_id = $term->parent; 57 | } 58 | 59 | // If we have parent terms, reverse the array to put them in the 60 | // proper order for the trail. 61 | if ( $parents ) { 62 | 63 | array_map( function( $parent ) { 64 | 65 | $this->breadcrumbs->crumb( 'Term', [ 'term' => $parent ] ); 66 | 67 | }, array_reverse( $parents ) ); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/Build/PostTerms.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright Copyright (c) 2018, Justin Tadlock 10 | * @link https://github.com/justintadlock/hybrid-breadcrumbs 11 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 12 | */ 13 | 14 | namespace Hybrid\Breadcrumbs\Build; 15 | 16 | /** 17 | * Post terms build sub-class. 18 | * 19 | * @since 1.0.0 20 | * @access public 21 | */ 22 | class PostTerms extends Base { 23 | 24 | /** 25 | * Post object. 26 | * 27 | * @since 1.0.0 28 | * @access protected 29 | * @var \WP_Post 30 | */ 31 | protected $post; 32 | 33 | /** 34 | * Taxonomy slug. 35 | * 36 | * @since 1.0.0 37 | * @access protected 38 | * @var string 39 | */ 40 | protected $taxonomy; 41 | 42 | /** 43 | * Builds the breadcrumbs. 44 | * 45 | * @since 1.0.0 46 | * @access public 47 | * @return void 48 | */ 49 | public function make() { 50 | 51 | // Get the post type. 52 | $post_type = get_post_type( $this->post->ID ); 53 | 54 | // Get the post categories. 55 | $terms = get_the_terms( $this->post->ID, $this->taxonomy ); 56 | 57 | // Check that categories were returned. 58 | if ( $terms && ! is_wp_error( $terms ) ) { 59 | 60 | // Sort the terms by ID and get the first category. 61 | $terms = wp_list_sort( $terms, 'term_id' ); 62 | 63 | $term = get_term( $terms[0], $this->taxonomy ); 64 | 65 | // If the category has a parent, add the hierarchy to the trail. 66 | if ( 0 < $term->parent ) { 67 | 68 | $this->breadcrumbs->build( 'TermAncestors', [ 69 | 'term' => $term 70 | ] ); 71 | } 72 | 73 | // Add term crumb. 74 | $this->breadcrumbs->crumb( 'Term', [ 'term' => $term ] ); 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/Query/Base.php: -------------------------------------------------------------------------------- 1 | 12 | * @copyright Copyright (c) 2018, Justin Tadlock 13 | * @link https://github.com/justintadlock/hybrid-breadcrumbs 14 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 15 | */ 16 | 17 | namespace Hybrid\Breadcrumbs\Query; 18 | 19 | use Hybrid\Breadcrumbs\Contracts\Breadcrumbs; 20 | use Hybrid\Breadcrumbs\Contracts\Query; 21 | 22 | /** 23 | * Base query class. 24 | * 25 | * @since 1.0.0 26 | * @access public 27 | */ 28 | abstract class Base implements Query { 29 | 30 | /** 31 | * Breadcrumbs object. 32 | * 33 | * @since 1.0.0 34 | * @access protected 35 | * @var Breadcrumbs 36 | */ 37 | protected $breadcrumbs; 38 | 39 | /** 40 | * Creates a new query object. Any data passed in within the `$data` 41 | * array will be automatically assigned to any existing properties, which 42 | * can be useful for sub-classes that have custom properties. 43 | * 44 | * @since 1.0.0 45 | * @access public 46 | * @param Breadcrumbs $breadcrumbs 47 | * @param array $data 48 | * @return void 49 | */ 50 | public function __construct( Breadcrumbs $breadcrumbs, array $data = [] ) { 51 | 52 | foreach ( array_keys( get_object_vars( $this ) ) as $key ) { 53 | 54 | if ( isset( $data[ $key ] ) ) { 55 | $this->$key = $data[ $key ]; 56 | } 57 | } 58 | 59 | $this->breadcrumbs = $breadcrumbs; 60 | } 61 | 62 | /** 63 | * Override this method in sub-classes to build out breadcrumbs. 64 | * 65 | * @since 1.0.0 66 | * @access public 67 | * @return void 68 | */ 69 | abstract public function make(); 70 | } 71 | -------------------------------------------------------------------------------- /src/Build/PostType.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright Copyright (c) 2018, Justin Tadlock 10 | * @link https://github.com/justintadlock/hybrid-breadcrumbs 11 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 12 | */ 13 | 14 | namespace Hybrid\Breadcrumbs\Build; 15 | 16 | /** 17 | * Post type build sub-class. 18 | * 19 | * @since 1.0.0 20 | * @access public 21 | */ 22 | class PostType extends Base { 23 | 24 | /** 25 | * Post type slug. 26 | * 27 | * @since 1.0.0 28 | * @access protected 29 | * @var \WP_Post_Type 30 | */ 31 | protected $post_type = ''; 32 | 33 | /** 34 | * Builds the breadcrumbs. 35 | * 36 | * @since 1.0.0 37 | * @access public 38 | * @return void 39 | */ 40 | public function make() { 41 | global $wp_rewrite; 42 | 43 | $type = is_string( $this->post_type ) 44 | ? get_post_type_object( $this->post_type ) 45 | : $this->post_type; 46 | 47 | if ( ! $type ) { 48 | return; 49 | } 50 | 51 | // If this the post type is `post`, add the posts page and bail. 52 | if ( 'post' === $type->name ) { 53 | 54 | $show_on_front = get_option( 'show_on_front' ); 55 | $post_id = get_option( 'page_for_posts' ); 56 | 57 | // Add post crumb if we have a posts page. 58 | if ( 'posts' !== $show_on_front && 0 < $post_id ) { 59 | 60 | $post = get_post( $post_id ); 61 | 62 | // If the posts page is the same as the rewrite 63 | // front path, we should've already handled that 64 | // scenario at this point. 65 | if ( trim( $wp_rewrite->front, '/' ) !== $post->post_name ) { 66 | 67 | $this->breadcrumbs->crumb( 'Post', [ 68 | 'post' => $post 69 | ] ); 70 | } 71 | } 72 | 73 | return; 74 | } 75 | 76 | // Add post type crumb. 77 | $this->breadcrumbs->crumb( 'PostType', [ 'post_type' => $type ] ); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/Build/Base.php: -------------------------------------------------------------------------------- 1 | 12 | * @copyright Copyright (c) 2018, Justin Tadlock 13 | * @link https://github.com/justintadlock/hybrid-breadcrumbs 14 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 15 | */ 16 | 17 | namespace Hybrid\Breadcrumbs\Build; 18 | 19 | use Hybrid\Breadcrumbs\Contracts\Breadcrumbs; 20 | use Hybrid\Breadcrumbs\Contracts\Build; 21 | 22 | /** 23 | * Base build class. 24 | * 25 | * @since 1.0.0 26 | * @access public 27 | */ 28 | abstract class Base implements Build { 29 | 30 | /** 31 | * Breadcrumbs object. 32 | * 33 | * @since 1.0.0 34 | * @access protected 35 | * @var Breadcrumbs 36 | */ 37 | protected $breadcrumbs; 38 | 39 | /** 40 | * Creates a new build object. Any data passed in within the `$data` 41 | * array will be automatically assigned to any existing properties, which 42 | * can be useful for sub-classes that have custom properties. 43 | * 44 | * @since 1.0.0 45 | * @access public 46 | * @param Breadcrumbs $breadcrumbs 47 | * @param array $data 48 | * @return void 49 | */ 50 | public function __construct( Breadcrumbs $breadcrumbs, array $data = [] ) { 51 | 52 | foreach ( array_keys( get_object_vars( $this ) ) as $key ) { 53 | 54 | if ( isset( $data[ $key ] ) ) { 55 | $this->$key = $data[ $key ]; 56 | } 57 | } 58 | 59 | $this->breadcrumbs = $breadcrumbs; 60 | } 61 | 62 | /** 63 | * This should be overwritten in a sub-class. It's where the work happens 64 | * to build out breadcrumbs. 65 | * 66 | * @since 1.0.0 67 | * @access public 68 | * @return void 69 | */ 70 | abstract public function make(); 71 | } 72 | -------------------------------------------------------------------------------- /src/Trail.php: -------------------------------------------------------------------------------- 1 | 10 | * @copyright Copyright (c) 2018, Justin Tadlock 11 | * @link https://github.com/justintadlock/hybrid-breadcrumbs 12 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 13 | */ 14 | 15 | namespace Hybrid\Breadcrumbs; 16 | 17 | /** 18 | * Trail class. 19 | * 20 | * @since 1.0.0 21 | * @access public 22 | */ 23 | class Trail { 24 | 25 | /** 26 | * Returns a new breadcrumbs object. 27 | * 28 | * @since 1.0.0 29 | * @access public 30 | * @param array $args 31 | * @return Breadcrumbs 32 | */ 33 | public static function breadcrumbs( array $args = [] ) { 34 | 35 | return new Breadcrumbs( $args ); 36 | } 37 | 38 | /** 39 | * Returns a new breadcrumbs object after calling its `make()` method. 40 | * 41 | * @since 1.0.0 42 | * @access public 43 | * @param array $args 44 | * @return Breadcrumbs 45 | */ 46 | public static function make( array $args = [] ) { 47 | 48 | return static::breadcrumbs( $args )->make(); 49 | } 50 | 51 | /** 52 | * Returns an array of `\Hybrid\Breadcrumbs\Contracts\Crumb` objects. 53 | * 54 | * @since 1.0.0 55 | * @access public 56 | * @param array $args 57 | * @return array 58 | */ 59 | public static function all( array $args = [] ) { 60 | 61 | return static::make( $args )->all(); 62 | } 63 | 64 | /** 65 | * Renders the breadcrumb trail output. 66 | * 67 | * @since 1.0.0 68 | * @access public 69 | * @param array $args 70 | * @return void 71 | */ 72 | public static function display( array $args = [] ) { 73 | 74 | static::make( $args )->display(); 75 | } 76 | 77 | /** 78 | * Returns the breadcrumb trail output. 79 | * 80 | * @since 1.0.0 81 | * @access public 82 | * @param array $args 83 | * @return string 84 | */ 85 | public static function render( array $args = [] ) { 86 | 87 | return static::make( $args )->render(); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/Build/Term.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright Copyright (c) 2018, Justin Tadlock 10 | * @link https://github.com/justintadlock/hybrid-breadcrumbs 11 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 12 | */ 13 | 14 | namespace Hybrid\Breadcrumbs\Build; 15 | 16 | use Hybrid\Breadcrumbs\Crumb\PostType; 17 | use Hybrid\Breadcrumbs\Util\Helpers; 18 | 19 | /** 20 | * Term build sub-class. 21 | * 22 | * @since 1.0.0 23 | * @access public 24 | */ 25 | class Term extends Base { 26 | 27 | /** 28 | * Term object. 29 | * 30 | * @since 1.0.0 31 | * @access protected 32 | * @var \WP_Term 33 | */ 34 | protected $term; 35 | 36 | /** 37 | * Builds the breadcrumbs. 38 | * 39 | * @since 1.0.0 40 | * @access public 41 | * @return void 42 | */ 43 | public function make() { 44 | 45 | $taxonomy = get_taxonomy( $this->term->taxonomy ); 46 | $done_post_type = false; 47 | 48 | // Will either be `false` or an array. 49 | $rewrite = $taxonomy->rewrite; 50 | 51 | // Build rewrite front crumbs if taxonomy uses it. 52 | if ( $rewrite && $rewrite['with_front'] ) { 53 | $this->breadcrumbs->build( 'RewriteFront' ); 54 | } 55 | 56 | // Build crumbs based on the rewrite slug. 57 | if ( $rewrite && $rewrite['slug'] ) { 58 | 59 | $path = trim( $rewrite['slug'], '/' ); 60 | 61 | // Build path crumbs. 62 | $this->breadcrumbs->build( 'Path', [ 'path' => $path ] ); 63 | 64 | // Check if we've added a post type crumb. 65 | foreach ( $this->breadcrumbs->all() as $crumb ) { 66 | if ( $crumb instanceof PostType ) { 67 | $done_post_type = true; 68 | break; 69 | } 70 | } 71 | } 72 | 73 | // If the taxonomy has a single post type. 74 | if ( ! $done_post_type && 1 === count( $taxonomy->object_type ) ) { 75 | $this->breadcrumbs->build( 'PostType', [ 76 | 'post_type' => get_post_type_object( $taxonomy->object_type[0] ) 77 | ] ); 78 | } 79 | 80 | // If the taxonomy is hierarchical, list the parent terms. 81 | if ( is_taxonomy_hierarchical( $taxonomy->name ) && $this->term->parent ) { 82 | 83 | $this->breadcrumbs->build( 'TermAncestors', [ 'term' => $this->term ] ); 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/Query/Archive.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright Copyright (c) 2018, Justin Tadlock 10 | * @link https://github.com/justintadlock/hybrid-breadcrumbs 11 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 12 | */ 13 | 14 | namespace Hybrid\Breadcrumbs\Query; 15 | 16 | /** 17 | * Archive query sub-class. 18 | * 19 | * @since 1.0.0 20 | * @access public 21 | */ 22 | class Archive extends Base { 23 | 24 | /** 25 | * Builds the breadcrumbs. 26 | * 27 | * @since 1.0.0 28 | * @access public 29 | * @return void 30 | */ 31 | public function make() { 32 | 33 | // Run through the conditionals to determine which type of 34 | // archive breadcrumbs to build. 35 | if ( is_post_type_archive() ) { 36 | 37 | $this->breadcrumbs->query( 'PostTypeArchive' ); 38 | 39 | } elseif ( is_category() || is_tag() || is_tax() ) { 40 | 41 | $this->breadcrumbs->query( 'Tax' ); 42 | 43 | } elseif ( is_author() ) { 44 | 45 | $this->breadcrumbs->query( 'Author' ); 46 | 47 | } elseif ( get_query_var( 'minute' ) && get_query_var( 'hour' ) ) { 48 | 49 | $this->breadcrumbs->query( 'MinuteHour' ); 50 | 51 | } elseif ( get_query_var( 'minute' ) ) { 52 | 53 | $this->breadcrumbs->query( 'Minute' ); 54 | 55 | } elseif ( get_query_var( 'hour' ) ) { 56 | 57 | $this->breadcrumbs->query( 'Hour' ); 58 | 59 | } elseif ( is_day() ) { 60 | 61 | $this->breadcrumbs->query( 'Day' ); 62 | 63 | } elseif ( get_query_var( 'week' ) ) { 64 | 65 | $this->breadcrumbs->query( 'Week' ); 66 | 67 | } elseif ( is_month() ) { 68 | 69 | $this->breadcrumbs->query( 'Month' ); 70 | 71 | } elseif ( is_year() ) { 72 | 73 | $this->breadcrumbs->query( 'Year' ); 74 | 75 | } else { 76 | // Build network crumbs. 77 | $this->breadcrumbs->build( 'Network' ); 78 | 79 | // Add site home crumb. 80 | $this->breadcrumbs->crumb( 'Home' ); 81 | 82 | // Build rewrite front crumbs if date/time query. 83 | if ( is_date() || is_time() ) { 84 | $this->breadcrumbs->build( 'RewriteFront' ); 85 | } 86 | 87 | // Add archive crumb. 88 | $this->breadcrumbs->crumb( 'Archive' ); 89 | 90 | // Build paged crumbs. 91 | $this->breadcrumbs->build( 'Paged' ); 92 | } 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/Build/PostAncestors.php: -------------------------------------------------------------------------------- 1 | 10 | * @copyright Copyright (c) 2018, Justin Tadlock 11 | * @link https://github.com/justintadlock/hybrid-breadcrumbs 12 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 13 | */ 14 | 15 | namespace Hybrid\Breadcrumbs\Build; 16 | 17 | /** 18 | * Post ancestors build sub-class. 19 | * 20 | * @since 1.0.0 21 | * @access public 22 | */ 23 | class PostAncestors extends Base { 24 | 25 | /** 26 | * Post object. 27 | * 28 | * @since 1.0.0 29 | * @access protected 30 | * @var \WP_Post 31 | */ 32 | protected $post; 33 | 34 | /** 35 | * Builds the breadcrumbs. 36 | * 37 | * @since 1.0.0 38 | * @access public 39 | * @return void 40 | */ 41 | public function make() { 42 | 43 | $post = $this->post; 44 | $post_id = $post->post_parent; 45 | $parents = []; 46 | 47 | while ( $post_id ) { 48 | 49 | $show_on_front = get_option( 'show_on_front' ); 50 | $page_on_front = get_option( 'page_on_front' ); 51 | 52 | // If we hit a post that's set as the front page, bail. 53 | if ( 'posts' !== $show_on_front && $post_id === $page_on_front ) { 54 | break; 55 | } 56 | 57 | // Get the parent post. 58 | $post = get_post( $post_id ); 59 | 60 | // Add the formatted post item to the array of parents. 61 | $parents[] = $post; 62 | 63 | // If there's no longer a post parent, break out of the loop. 64 | if ( 0 >= $post->post_parent ) { 65 | break; 66 | } 67 | 68 | // Change the post ID to the parent post to continue looping. 69 | $post_id = $post->post_parent; 70 | } 71 | 72 | // Get the post hierarchy based off the final parent post. 73 | $this->breadcrumbs->build( 'PostHierarchy', [ 'post' => $post ] ); 74 | 75 | // Display terms for specific post type taxonomy if requested. 76 | if ( $this->breadcrumbs->postTaxonomy( $post->post_type ) ) { 77 | 78 | $this->breadcrumbs->build( 'PostTerms', [ 79 | 'post' => $post, 80 | 'taxonomy' => $this->breadcrumbs->postTaxonomy( $post->post_type ) 81 | ] ); 82 | } 83 | 84 | if ( $parents ) { 85 | 86 | array_map( function( $parent ) { 87 | 88 | $this->breadcrumbs->crumb( 'Post', [ 'post' => $parent ] ); 89 | 90 | }, array_reverse( $parents ) ); 91 | } 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/Build/Path.php: -------------------------------------------------------------------------------- 1 | 10 | * @copyright Copyright (c) 2018, Justin Tadlock 11 | * @link https://github.com/justintadlock/hybrid-breadcrumbs 12 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 13 | */ 14 | 15 | namespace Hybrid\Breadcrumbs\Build; 16 | 17 | use Hybrid\Breadcrumbs\Util\Helpers; 18 | 19 | /** 20 | * Path build sub-class. 21 | * 22 | * @since 1.0.0 23 | * @access public 24 | */ 25 | class Path extends Base { 26 | 27 | /** 28 | * Path to search. 29 | * 30 | * @since 1.0.0 31 | * @access protected 32 | * @var string 33 | */ 34 | protected $path = ''; 35 | 36 | /** 37 | * Builds the breadcrumbs. 38 | * 39 | * @since 1.0.0 40 | * @access public 41 | * @return void 42 | */ 43 | public function make() { 44 | 45 | $path = trim( $this->path, '/' ); 46 | 47 | // If there's no path, return. 48 | if ( ! $path ) { 49 | return; 50 | } 51 | 52 | // Get parent post by the path. 53 | $post = get_page_by_path( $path ); 54 | 55 | // If the path is a post, run the parent crumbs and bail early. 56 | if ( $post ) { 57 | $this->breadcrumbs->build( 'PostAncestors', [ 'post' => $post ] ); 58 | 59 | $this->breadcrumbs->crumb( 'Post', [ 'post' => $post ] ); 60 | 61 | return; 62 | } 63 | 64 | // Split the $path into an array of strings. 65 | $matches = explode( '/', $path ); 66 | 67 | // If matches are found for the path. 68 | if ( $matches ) { 69 | 70 | // Reverse the array of matches to search for posts in 71 | // the proper order. 72 | $matches = array_reverse( $matches ); 73 | 74 | // Loop through each of the path matches. 75 | foreach ( $matches as $slug ) { 76 | 77 | // Get the parent post by the given path. 78 | $post = get_page_by_path( $slug ); 79 | 80 | // If a parent post is found, build the crumbs 81 | // and break out of the loop. 82 | if ( ! empty( $post ) && 0 < $post->ID ) { 83 | 84 | $this->breadcrumbs->build( 'PostAncestors', [ 85 | 'post' => $post 86 | ] ); 87 | 88 | $this->breadcrumbs->crumb( 'Post', [ 89 | 'post' => $post 90 | ] ); 91 | 92 | break; 93 | 94 | // If the slug matches a post type, let's build 95 | // that and break out of the loop. 96 | } elseif ( $types = Helpers::getPostTypesBySlug( $slug ) ) { 97 | 98 | $this->breadcrumbs->build( 'PostType', [ 99 | 'post_type' => $types[0] 100 | ] ); 101 | 102 | break; 103 | } 104 | } 105 | } 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /src/Crumb/Base.php: -------------------------------------------------------------------------------- 1 | 12 | * @copyright Copyright (c) 2018, Justin Tadlock 13 | * @link https://github.com/justintadlock/hybrid-breadcrumbs 14 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 15 | */ 16 | 17 | namespace Hybrid\Breadcrumbs\Crumb; 18 | 19 | use Hybrid\Breadcrumbs\Contracts\Breadcrumbs; 20 | use Hybrid\Breadcrumbs\Contracts\Crumb; 21 | 22 | /** 23 | * Base crumb class. 24 | * 25 | * @since 1.0.0 26 | * @access public 27 | */ 28 | abstract class Base implements Crumb { 29 | 30 | /** 31 | * Breadcrumbs object. 32 | * 33 | * @since 1.0.0 34 | * @access protected 35 | * @var Breadcrumbs 36 | */ 37 | protected $breadcrumbs; 38 | 39 | /** 40 | * Creates a new crumb object. Any data passed in within the `$data` 41 | * array will be automatically assigned to any existing properties, which 42 | * can be useful for sub-classes that have custom properties. 43 | * 44 | * @since 1.0.0 45 | * @access public 46 | * @param Breadcrumbs $breadcrumbs 47 | * @param array $data 48 | * @return void 49 | */ 50 | public function __construct( Breadcrumbs $breadcrumbs, array $data = [] ) { 51 | 52 | foreach ( array_keys( get_object_vars( $this ) ) as $key ) { 53 | 54 | if ( isset( $data[ $key ] ) ) { 55 | $this->$key = $data[ $key ]; 56 | } 57 | } 58 | 59 | $this->breadcrumbs = $breadcrumbs; 60 | } 61 | 62 | /** 63 | * Returns the type for the crumb. By default, we just use the PHP class 64 | * name to build the type. If wanting something custom, this should be 65 | * handled in a sub-class. 66 | * 67 | * @since 1.0.0 68 | * @access public 69 | * @return string 70 | */ 71 | public function type() { 72 | 73 | $class = explode( '\\', get_class( $this ) ); 74 | $class = array_pop( $class ); 75 | 76 | $pascal = preg_split( '/((?<=[a-z])(?=[A-Z])|(?=[A-Z][a-z]))/', $class, -1, PREG_SPLIT_NO_EMPTY ); 77 | 78 | return strtolower( join( '-', $pascal ) ); 79 | } 80 | 81 | /** 82 | * Returns a label for the crumb. 83 | * 84 | * @since 1.0.0 85 | * @access public 86 | * @return string 87 | */ 88 | public function label() { 89 | return ''; 90 | } 91 | 92 | /** 93 | * Returns a URL for the crumb. 94 | * 95 | * @since 1.0.0 96 | * @access public 97 | * @return string 98 | */ 99 | public function url() { 100 | return ''; 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /src/Build/PostHierarchy.php: -------------------------------------------------------------------------------- 1 | 10 | * @copyright Copyright (c) 2018, Justin Tadlock 11 | * @link https://github.com/justintadlock/hybrid-breadcrumbs 12 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 13 | */ 14 | 15 | namespace Hybrid\Breadcrumbs\Build; 16 | 17 | use Hybrid\Breadcrumbs\Crumb\PostType; 18 | 19 | /** 20 | * Post hierarchy build sub-class. 21 | * 22 | * @since 1.0.0 23 | * @access public 24 | */ 25 | class PostHierarchy extends Base { 26 | 27 | /** 28 | * Post object. 29 | * 30 | * @since 1.0.0 31 | * @access protected 32 | * @var \WP_Post 33 | */ 34 | protected $post; 35 | 36 | /** 37 | * Builds the breadcrumbs. 38 | * 39 | * @since 1.0.0 40 | * @access public 41 | * @return void 42 | */ 43 | public function make() { 44 | 45 | // Get the post type. 46 | $type = get_post_type_object( get_post_type( $this->post->ID ) ); 47 | 48 | // If this is the 'post' post type, get the rewrite front items, 49 | // map the rewrite tags, and bail early. 50 | if ( 'post' === $type->name ) { 51 | 52 | // Add $wp_rewrite->front to the trail. 53 | $this->breadcrumbs->build( 'RewriteFront' ); 54 | 55 | // Map the rewrite tags. 56 | $this->breadcrumbs->build( 'MapRewriteTags', [ 57 | 'post' => $this->post, 58 | 'path' => get_option( 'permalink_structure' ) 59 | ] ); 60 | 61 | return; 62 | } 63 | 64 | $rewrite = $type->rewrite; 65 | $done_post_type = false; 66 | 67 | // If the post type has rewrite rules. 68 | if ( $rewrite ) { 69 | 70 | // Build the rewrite front crumbs. 71 | if ( $rewrite['with_front'] ) { 72 | 73 | $this->breadcrumbs->build( 'RewriteFront' ); 74 | } 75 | 76 | // If there's a path, check for parents. 77 | if ( $rewrite['slug'] ) { 78 | $this->breadcrumbs->build( 'Path', [ 'path' => $rewrite['slug'] ] ); 79 | 80 | // Check if we've added a post type crumb. 81 | foreach ( $this->breadcrumbs->all() as $crumb ) { 82 | if ( $crumb instanceof PostType ) { 83 | $done_post_type = true; 84 | break; 85 | } 86 | } 87 | } 88 | } 89 | 90 | // Fall back to the post type crumb if not getting from path. 91 | if ( ! $done_post_type && $type->has_archive ) { 92 | $this->breadcrumbs->build( 'PostType', [ 'post_type' => $type ] ); 93 | } 94 | 95 | // Map the rewrite tags if there's a `%` in the slug. 96 | if ( $rewrite && false !== strpos( $rewrite['slug'], '%' ) ) { 97 | 98 | $this->breadcrumbs->build( 'MapRewriteTags', [ 99 | 'post' => $this->post, 100 | 'path' => $rewrite['slug'] 101 | ] ); 102 | } 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /src/Query/PostTypeArchive.php: -------------------------------------------------------------------------------- 1 | 10 | * @copyright Copyright (c) 2018, Justin Tadlock 11 | * @link https://github.com/justintadlock/hybrid-breadcrumbs 12 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 13 | */ 14 | 15 | namespace Hybrid\Breadcrumbs\Query; 16 | 17 | use Hybrid\Breadcrumbs\Crumb\PostType; 18 | 19 | /** 20 | * Post type archive query sub-class. 21 | * 22 | * @since 1.0.0 23 | * @access public 24 | */ 25 | class PostTypeArchive extends Base { 26 | 27 | /** 28 | * Post type object. 29 | * 30 | * @since 1.2.0 31 | * @access protected 32 | * @var \WP_Post_Type 33 | */ 34 | protected $post_type; 35 | 36 | /** 37 | * User object. 38 | * 39 | * @since 1.2.0 40 | * @access protected 41 | * @var \WP_User 42 | */ 43 | protected $user; 44 | 45 | /** 46 | * Builds the breadcrumbs. 47 | * 48 | * @since 1.0.0 49 | * @access public 50 | * @return void 51 | */ 52 | public function make() { 53 | 54 | $type = $this->post_type ?: get_post_type_object( get_query_var( 'post_type' ) ); 55 | 56 | $done_post_type = false; 57 | 58 | // Build network crumbs. 59 | $this->breadcrumbs->build( 'Network' ); 60 | 61 | // Add site home crumb. 62 | $this->breadcrumbs->crumb( 'Home' ); 63 | 64 | if ( false !== $type->rewrite ) { 65 | 66 | // Build rewrite front crumbs if post type uses it. 67 | if ( $type->rewrite['with_front'] ) { 68 | $this->breadcrumbs->build( 'RewriteFront' ); 69 | } 70 | 71 | // If there's a rewrite slug, check for parents. 72 | if ( ! empty( $type->rewrite['slug'] ) ) { 73 | $this->breadcrumbs->build( 'Path', [ 'path' => $type->rewrite['slug'] ] ); 74 | 75 | // Check if we've added a post type crumb. 76 | foreach ( $this->breadcrumbs->all() as $crumb ) { 77 | if ( $crumb instanceof PostType ) { 78 | $done_post_type = true; 79 | break; 80 | } 81 | } 82 | } 83 | } 84 | 85 | // Add post type crumb. 86 | if ( ! $done_post_type ) { 87 | $this->breadcrumbs->crumb( 'PostType', [ 'post_type' => $type ] ); 88 | } 89 | 90 | // If viewing a search page for the post type archive. 91 | if ( is_search() ) { 92 | 93 | // Add search crumb. 94 | $this->breadcrumbs->crumb( 'Search' ); 95 | } 96 | 97 | // If viewing a post type archive by author. 98 | if ( is_author() ) { 99 | 100 | $user = $this->user ?: new WP_User( get_query_var( 'author' ) ); 101 | 102 | // Add author crumb. 103 | $this->breadcrumbs->crumb( 'Author', [ 'user' => $user ] ); 104 | } 105 | 106 | // Build paged crumbs. 107 | $this->breadcrumbs->build( 'Paged' ); 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /src/Build/MapRewriteTags.php: -------------------------------------------------------------------------------- 1 | 12 | * @copyright Copyright (c) 2018, Justin Tadlock 13 | * @link https://github.com/justintadlock/hybrid-breadcrumbs 14 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 15 | */ 16 | 17 | namespace Hybrid\Breadcrumbs\Build; 18 | 19 | use WP_User; 20 | 21 | /** 22 | * Map rewrite tags build sub-class. 23 | * 24 | * @since 1.0.0 25 | * @access public 26 | */ 27 | class MapRewriteTags extends Base { 28 | 29 | /** 30 | * Post object. 31 | * 32 | * @since 1.0.0 33 | * @access protected 34 | * @var \WP_Post 35 | */ 36 | protected $post; 37 | 38 | /** 39 | * Permalink structure or path with possible `%tag%` names in it. 40 | * 41 | * @since 1.0.0 42 | * @access protected 43 | * @var string 44 | */ 45 | protected $path = ''; 46 | 47 | /** 48 | * Builds the breadcrumbs. 49 | * 50 | * @since 1.0.0 51 | * @access public 52 | * @return void 53 | */ 54 | public function make() { 55 | 56 | // Trim '/' from both sides of `$this->path`. 57 | $path = trim( $this->path, '/' ); 58 | 59 | // Split the $path into an array of strings. 60 | $matches = explode( '/', $path ); 61 | 62 | // Bail if no matches are found. 63 | if ( ! $matches ) { 64 | return; 65 | } 66 | 67 | // Loop through each of the matches, adding each to the $trail array. 68 | foreach ( $matches as $tag ) { 69 | 70 | // If using the %year% tag, add a link to the yearly archive. 71 | if ( '%year%' == $tag ) { 72 | 73 | $this->breadcrumbs->crumb( 'Year', [ 'post' => $this->post ] ); 74 | 75 | // If using the %monthnum% tag, add a link to the monthly archive. 76 | } elseif ( '%monthnum%' == $tag ) { 77 | 78 | $this->breadcrumbs->crumb( 'Month', [ 'post' => $this->post ] ); 79 | 80 | // If using the %day% tag, add a link to the daily archive. 81 | } elseif ( '%day%' == $tag ) { 82 | 83 | $this->breadcrumbs->crumb( 'Day', [ 'post' => $this->post ] ); 84 | 85 | // If using the %author% tag, add a link to the post author archive. 86 | } elseif ( '%author%' == $tag ) { 87 | 88 | $this->breadcrumbs->crumb( 'Author', [ 89 | 'user' => new WP_User( $this->post->post_author ) 90 | ] ); 91 | 92 | // If using the %category% tag, add a link to the first 93 | // category archive to match permalinks. 94 | } elseif ( taxonomy_exists( trim( $tag, '%' ) ) && $tag !== $this->breadcrumbs->postTaxonomy( $this->post->post_type ) ) { 95 | 96 | // Build post terms crumbs. 97 | $this->breadcrumbs->build( 'PostTerms', [ 98 | 'post' => $this->post, 99 | 'taxonomy' => trim( $tag, '%' ) 100 | ] ); 101 | } 102 | } 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /src/Contracts/Breadcrumbs.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright Copyright (c) 2018, Justin Tadlock 10 | * @link https://github.com/justintadlock/hybrid-breadcrumbs 11 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 12 | */ 13 | 14 | namespace Hybrid\Breadcrumbs\Contracts; 15 | 16 | /** 17 | * Breadcrumbs interface. 18 | * 19 | * @since 1.0.0 20 | * @access public 21 | */ 22 | interface Breadcrumbs { 23 | 24 | /** 25 | * Builds a new breadcrumbs object and returns it. 26 | * 27 | * @since 1.0.0 28 | * @access public 29 | * @return Breadcrumbs 30 | */ 31 | public function make(); 32 | 33 | /** 34 | * Renders the breadcrumbs HTML output. 35 | * 36 | * @since 1.0.0 37 | * @access public 38 | * @return void 39 | */ 40 | public function display(); 41 | 42 | /** 43 | * Returns the breadcrumbs HTML output. 44 | * 45 | * @since 1.0.0 46 | * @access public 47 | * @return string 48 | */ 49 | public function render(); 50 | 51 | /** 52 | * Returns the breadcrumbs in an array. 53 | * 54 | * @since 1.0.0 55 | * @access public 56 | * @return array 57 | */ 58 | public function all(); 59 | 60 | /** 61 | * Creates a new `\Hybrid\Breadcrumbs\Contracts\Query` object and runs 62 | * its `make()` method. 63 | * 64 | * @since 1.0.0 65 | * @access public 66 | * @param string $type 67 | * @param array $data 68 | * @return void 69 | */ 70 | public function query( $type, array $data = [] ); 71 | 72 | /** 73 | * Creates a new `\Hybrid\Breadcrumbs\Contracts\Build` object and runs 74 | * its `make()` method. 75 | * 76 | * @since 1.0.0 77 | * @access public 78 | * @param string $type 79 | * @param array $data 80 | * @return void 81 | */ 82 | public function build( $type, array $data = [] ); 83 | 84 | /** 85 | * Creates a new `\Hybrid\Breadcrumbs\Contracts\Crumb` object and adds 86 | * it to the array of crumbs. 87 | * 88 | * @since 1.0.0 89 | * @access public 90 | * @param string $type 91 | * @param array $data 92 | * @return void 93 | */ 94 | public function crumb( $type, array $data = [] ); 95 | 96 | /** 97 | * Returns a specific option or `false` if the option doesn't exist. 98 | * 99 | * @since 1.0.0 100 | * @access public 101 | * @param string $name 102 | * @return mixed 103 | */ 104 | public function option( $name ); 105 | 106 | /** 107 | * Returns a specific label or an empty string if it doesn't exist. 108 | * 109 | * @since 1.0.0 110 | * @access public 111 | * @param string $name 112 | * @return string 113 | */ 114 | public function label( $name ); 115 | 116 | /** 117 | * Returns a specific post taxonomy or an empty string if one isn't set. 118 | * 119 | * @since 1.0.0 120 | * @access public 121 | * @param string $post_type 122 | * @return string 123 | */ 124 | public function postTaxonomy( $post_type ); 125 | } 126 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Hybrid\\Breadcrumbs 2 | 3 | Hybrid Breadcrumbs is a drop-in package that theme authors can use to add breadcrumbs to their WordPress themes. 4 | 5 | The package is a developer-friendly project that aims to take out all the work of handling breadcrumbs. It is one of the most advanced and robust breadcrumb systems available that can handle nearly any setup to show the most accurate breadcrumbs for each page. 6 | 7 | This project was [originally launched in 2009](http://justintadlock.com/archives/2009/04/05/breadcrumb-trail-wordpress-plugin) as the Breadcrumb Trail plugin. Hybrid Breadcrumbs is a reimagining of that original script as a better drop-in package for theme authors to use. 8 | 9 | ## Requirements 10 | 11 | * WordPress 4.9+. 12 | * PHP 5.6+ (preferably 7+). 13 | * [Composer](https://getcomposer.org/) for managing PHP dependencies. 14 | 15 | ## Documentation 16 | 17 | The following docs are written with theme authors in mind because that'll be the most common use case. If including in a plugin, it shouldn't be much different. 18 | 19 | ### Installation 20 | 21 | First, you'll need to open your command line tool and change directories to your theme folder. 22 | 23 | ```bash 24 | cd path/to/wp-content/themes/ 25 | ``` 26 | 27 | Then, use Composer to install the package. 28 | 29 | ```bash 30 | composer require justintadlock/hybrid-breadcrumbs 31 | ``` 32 | 33 | Assuming you're not already including the Composer autoload file for your theme and are shipping this as part of your theme package, you'll want something like the following bit of code in your theme's `functions.php` to autoload this package (and any others). 34 | 35 | The Composer autoload file will automatically load up Hybrid Breadcrumbs for you and make its code available for you to use. 36 | 37 | ```php 38 | if ( file_exists( get_parent_theme_file_path( 'vendor/autoload.php' ) ) ) { 39 | require_once( get_parent_theme_file_path( 'vendor/autoload.php' ) ); 40 | } 41 | ``` 42 | 43 | ### Translations 44 | 45 | Because this script has a few internationalized text strings within it, you'll want to overwrite the textdomain or use something like this [one theme with two textdomains trick](https://gist.github.com/justintadlock/7a605c29ae26c80878d0) (the textdomain in this project is `'hybrid-core'`). 46 | 47 | If you're creating a theme using the [Hybrid Core framework](https://github.com/justintadlock/hybrid-core), you don't have to worry about this. Hybrid Core will appropriately handle translations for you. 48 | 49 | ### Usage 50 | 51 | Most developers will want to utilize the `Hybrid\Breadrumbs\Trail` class. It is a static wrapper class that essentially acts as _syntactic sugar_ for use in theme templates. 52 | 53 | Typically, a call like the following would go into your theme's `header.php` template but can be used anywhere you want to show the breadcrumb trail. 54 | 55 | ```php 56 | Hybrid\Breadcrumbs\Trail::display(); 57 | ``` 58 | 59 | _Note that the plugin's namespace is `Hybrid\Breadcrumbs`. If you're working within another namespace, you'll want to add a `use` statement after your own namespace call or call `\Hybrid\Breadcrumbs\Trail::display()` directly. I'll assume you know what you're doing if you're working with namespaces. Otherwise, stick to the above._ 60 | 61 | ### Static class 62 | 63 | The `Hybrid\Breadcrumbs\Trail` class has the following methods: 64 | 65 | ```php 66 | // Returns a new instance of the Hybrid\Breadcrumbs\Breadcrumbs class. 67 | Trail::breadcrumbs( array $args = [] ); 68 | 69 | // Makes a breadcrumb trail and returns an instance of the Hybrid\Breadcrumbs\Breadcrumbs. 70 | Trail::make( array $args = [] ); 71 | 72 | // Returns an array of Hybrid\Breadcrumbs\Crumb\* objects. 73 | Trail::all( array $args = [] ); 74 | 75 | // Displays the HTML output of the breadcrumb trail if it exists. 76 | Trail::display( array $args = [] ); 77 | 78 | // Returns the HTML output of the breadcrumb trail or an empty string. 79 | Trail::render( array $args = [] ); 80 | ``` 81 | 82 | ### Breadcrumbs class 83 | 84 | If you don't care for static classes and need to work directly with the object, that's fine too. You can create and use a the `Breadcrumbs` object like so: 85 | 86 | ```php 87 | // Create a new Breadcrumbs object. 88 | $trail = new \Hybrid\Breadcrumbs\Breadcrumbs( array $args = [] ); 89 | 90 | // Makes the breadcrumb trail and returns an instance of the object. 91 | $trail->make(); 92 | 93 | // Returns an array of Hybrid\Breadcrumbs\Crumb\* objects. 94 | $trail->all(); 95 | 96 | // Displays the HTML output of the breadcrumb trail if it exists. 97 | $trail->display(); 98 | 99 | // Returns the HTML output of the breadcrumb trail or an empty string. 100 | $trail->render(); 101 | ``` 102 | 103 | ### Parameters 104 | 105 | The `Breadcrumbs` class and the `Trail` class methods all accept a single parameter, which an array of optional arguments for setting up the breadcrumb trail. The following is a list of all the available options (see below for defaults). 106 | 107 | * `labels` - An array of labels. 108 | * `post_taxonomy` - An array of taxonomies to show for single posts based on post type. 109 | * `show_on_front` - Whether to show the breadcrumb trail on the site front page. 110 | * `show_trail_end` - Whether to display the final breadcrumb. 111 | * `network` - Whether to include the main site at the beginning of the trail on multisite. 112 | * `before` - HTML to display before. 113 | * `after` - HTML to display after. 114 | * `container_tag` - HTML tag to use for the container. 115 | * `title_tag` - HTML tag to use for the title. 116 | * `list_tag` - HTML tag to use for the list. 117 | * `item_tag` - HTML tag to use for each breadcrumb. 118 | * `container_class` - Class to use for the container. 119 | * `title_class` - Class to use for the title. 120 | * `list_class` - Class to use for the list. 121 | * `item_class` - Class to use for each breadcrumb. 122 | 123 | #### Default Parameters 124 | 125 | ```php 126 | $defaults = [ 127 | 'labels' => [], 128 | 'post_taxonomy' => [], 129 | 'show_on_front' => false, 130 | 'show_trail_end' => true, 131 | 'network' => false, 132 | 'before' => '', 133 | 'after' => '', 134 | 'container_tag' => 'nav', 135 | 'title_tag' => 'h2', 136 | 'list_tag' => 'ul', 137 | 'item_tag' => 'li', 138 | 'container_class' => 'breadcrumbs', 139 | 'title_class' => 'breadcrumbs__title', 140 | 'list_class' => 'breadcrumbs__trail', 141 | 'item_class' => 'breadcrumbs__crumb' 142 | ]; 143 | ``` 144 | 145 | #### Default Labels 146 | 147 | Labels are used for various breadcrumbs where WordPress doesn't provide a title/labels. 148 | 149 | ```php 150 | $defaults = [ 151 | 'title' => __( 'Browse:', 'hybrid-core' ), 152 | 'aria_label' => _x( 'Breadcrumbs', 'breadcrumbs aria label', 'hybrid-core' ), 153 | 'home' => __( 'Home', 'hybrid-core' ), 154 | 'error_404' => __( '404 Not Found', 'hybrid-core' ), 155 | 'archives' => __( 'Archives', 'hybrid-core' ), 156 | // Translators: %s is the search query. 157 | 'search' => __( 'Search results for: %s', 'hybrid-core' ), 158 | // Translators: %s is the page number. 159 | 'paged' => __( 'Page %s', 'hybrid-core' ), 160 | // Translators: %s is the page number. 161 | 'paged_comments' => __( 'Comment Page %s', 'hybrid-core' ), 162 | // Translators: Minute archive title. %s is the minute time format. 163 | 'archive_minute' => __( 'Minute %s', 'hybrid-core' ), 164 | // Translators: Weekly archive title. %s is the week date format. 165 | 'archive_week' => __( 'Week %s', 'hybrid-core' ), 166 | 167 | // "%s" is replaced with the translated date/time format. 168 | 'archive_minute_hour' => '%s', 169 | 'archive_hour' => '%s', 170 | 'archive_day' => '%s', 171 | 'archive_month' => '%s', 172 | 'archive_year' => '%s', 173 | ]; 174 | ``` 175 | 176 | #### Default Post Taxonomies 177 | 178 | By default, no post taxonomies are registered. However, if a site's post permalink structure is set to only `%postname%`, the following will be the default. 179 | 180 | ```php 181 | $defaults = [ 182 | 'post' => 'category' 183 | ]; 184 | ``` 185 | 186 | ## Copyright and License 187 | 188 | This project is licensed under the [GNU GPL](http://www.gnu.org/licenses/old-licenses/gpl-2.0.html), version 2 or later. 189 | 190 | 2018-2019 © [Justin Tadlock](http://justintadlock.com). 191 | -------------------------------------------------------------------------------- /src/Breadcrumbs.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright Copyright (c) 2018, Justin Tadlock 10 | * @link https://github.com/justintadlock/hybrid-breadcrumbs 11 | * @license https://www.gnu.org/licenses/old-licenses/gpl-2.0.html 12 | */ 13 | 14 | namespace Hybrid\Breadcrumbs; 15 | 16 | use Hybrid\Breadcrumbs\Contracts\Breadcrumbs as BreadcrumbsContract; 17 | 18 | /** 19 | * Breadcrumbs class. 20 | * 21 | * @since 1.0.0 22 | * @access public 23 | */ 24 | class Breadcrumbs implements BreadcrumbsContract { 25 | 26 | /** 27 | * The parsed arguments passed into the class. 28 | * 29 | * @since 1.0.0 30 | * @access protected 31 | * @var array 32 | */ 33 | protected $args = []; 34 | 35 | /** 36 | * Array of `Crumb` objects. 37 | * 38 | * @since 1.0.0 39 | * @access protected 40 | * @var array 41 | */ 42 | protected $crumbs = []; 43 | 44 | /** 45 | * Creates a new breadcrumbs object. 46 | * 47 | * @since 1.0.0 48 | * @access public 49 | * @param array $args 50 | * @return void 51 | */ 52 | public function __construct( array $args = [] ) { 53 | 54 | $defaults = [ 55 | 'labels' => [], 56 | 'post_taxonomy' => [], 57 | 'show_on_front' => false, 58 | 'show_trail_end' => true, 59 | 'network' => false, 60 | 'before' => '', 61 | 'after' => '', 62 | 'container_tag' => 'nav', 63 | 'title_tag' => 'h2', 64 | 'list_tag' => 'ul', 65 | 'item_tag' => 'li', 66 | 'container_class' => 'breadcrumbs', 67 | 'title_class' => 'breadcrumbs__title', 68 | 'list_class' => 'breadcrumbs__trail', 69 | 'item_class' => 'breadcrumbs__crumb', 70 | 'item_content_class' => 'breadcrumbs__crumb-content', 71 | 'post' => null, 72 | 'post_type' => null, 73 | 'term' => null, 74 | 'user' => null 75 | ]; 76 | 77 | $this->args = wp_parse_args( $args, $defaults ); 78 | 79 | $this->args['post_taxonomy'] = wp_parse_args( 80 | $this->args['post_taxonomy'], 81 | $this->defaultPostTaxonomies() 82 | ); 83 | 84 | $this->args['labels'] = wp_parse_args( 85 | $this->args['labels'], 86 | $this->defaultLabels() 87 | ); 88 | } 89 | 90 | /** 91 | * Returns an array of default labels. 92 | * 93 | * @since 1.0.0 94 | * @access protected 95 | * @return array 96 | */ 97 | protected function defaultLabels() { 98 | 99 | return [ 100 | 'title' => __( 'Browse:', 'hybrid-core' ), 101 | 'aria_label' => _x( 'Breadcrumbs', 'breadcrumbs aria label', 'hybrid-core' ), 102 | 'home' => __( 'Home', 'hybrid-core' ), 103 | 'error_404' => __( '404 Not Found', 'hybrid-core' ), 104 | 'archives' => __( 'Archives', 'hybrid-core' ), 105 | // Translators: %s is the search query. 106 | 'search' => __( 'Search results for: %s', 'hybrid-core' ), 107 | // Translators: %s is the page number. 108 | 'paged' => __( 'Page %s', 'hybrid-core' ), 109 | // Translators: %s is the page number. 110 | 'paged_comments' => __( 'Comment Page %s', 'hybrid-core' ), 111 | // Translators: Minute archive title. %s is the minute time format. 112 | 'archive_minute' => __( 'Minute %s', 'hybrid-core' ), 113 | // Translators: Weekly archive title. %s is the week date format. 114 | 'archive_week' => __( 'Week %s', 'hybrid-core' ), 115 | 116 | // "%s" is replaced with the translated date/time format. 117 | 'archive_minute_hour' => '%s', 118 | 'archive_hour' => '%s', 119 | 'archive_day' => '%s', 120 | 'archive_month' => '%s', 121 | 'archive_year' => '%s', 122 | ]; 123 | } 124 | 125 | /** 126 | * Returns an array of default post taxonomies. 127 | * 128 | * @since 1.0.0 129 | * @access protected 130 | * @return array 131 | */ 132 | protected function defaultPostTaxonomies() { 133 | 134 | $defaults = []; 135 | 136 | // If post permalink is set to `%postname%`, use the `category` taxonomy. 137 | if ( '%postname%' === trim( get_option( 'permalink_structure' ), '/' ) ) { 138 | $defaults['post'] = 'category'; 139 | } 140 | 141 | return $defaults; 142 | } 143 | 144 | /** 145 | * Returns an array of `Crumb` objects. 146 | * 147 | * @since 1.0.0 148 | * @access public 149 | * @return array 150 | */ 151 | public function all() { 152 | 153 | return $this->crumbs; 154 | } 155 | 156 | /** 157 | * Renders the breadcrumbs HTML output. 158 | * 159 | * @since 1.0.0 160 | * @access public 161 | * @return void 162 | */ 163 | public function display() { 164 | 165 | echo $this->render(); 166 | } 167 | 168 | /** 169 | * Returns the breadcrumbs HTML output. 170 | * 171 | * @since 1.0.0 172 | * @access public 173 | * @return string 174 | */ 175 | public function render() { 176 | 177 | $html = $container = $list = $title = ''; 178 | 179 | // Get an array of all the available breadcrumbs from the builder. 180 | $crumbs = $this->all(); 181 | 182 | if ( $crumbs ) { 183 | 184 | // HTML allowed in labels. Everything else gets stripped out. 185 | $allowed_html = [ 186 | 'abbr' => [ 'title' => true ], 187 | 'acronym' => [ 'title' => true ], 188 | 'code' => true, 189 | 'em' => true, 190 | 'strong' => true, 191 | 'i' => true, 192 | 'b' => true 193 | ]; 194 | 195 | $count = count( $crumbs ); 196 | $i = 1; 197 | $show_last = $this->option( 'show_trail_end' ); 198 | 199 | // Loop through each of the crumbs and build out a list. 200 | foreach ( $crumbs as $crumb ) { 201 | 202 | // Break out of the loop if this is the last item 203 | // and we're not supposed to show the trail end. 204 | if ( $i === $count && ! $show_last ) { 205 | break; 206 | } 207 | 208 | // Filter out any unwanted HTML from the label. 209 | $label = sprintf( 210 | '%s', 211 | wp_kses( $crumb->label(), $allowed_html ) 212 | ); 213 | 214 | // Get the crumb URL. 215 | $url = $crumb->url(); 216 | 217 | // Wrap the label with a link if the crumb has 218 | // one and this isn't the last item. 219 | if ( $url && $i !== $count ) { 220 | 221 | $item = sprintf( 222 | '%s', 223 | esc_url( $url ), 224 | esc_attr( $this->option( 'item_content_class' ) ), 225 | $label 226 | ); 227 | 228 | } else { 229 | 230 | $item = sprintf( 231 | '%s', 232 | esc_attr( $this->option( 'item_content_class' ) ), 233 | esc_url( $url ), 234 | $label 235 | ); 236 | } 237 | 238 | // Get the base class to build modifier classes from. 239 | $base_class = explode( ' ', $this->option( 'item_class' ) ); 240 | $base_class = array_shift( $base_class ); 241 | 242 | $classes = [ 243 | $this->option( 'item_class' ), 244 | sprintf( "{$base_class}--%s", $crumb->type() ) 245 | ]; 246 | 247 | // Build the list item. 248 | $list .= sprintf( 249 | '<%1$s class="%2$s" itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem">%3$s', 250 | tag_escape( $this->option( 'item_tag' ) ), 251 | esc_attr( join( ' ', $classes ) ), 252 | $item, 253 | $i 254 | ); 255 | 256 | ++$i; 257 | } 258 | 259 | // Build the list HTML. 260 | $list = sprintf( 261 | '<%1$s class="%2$s" itemscope itemtype="https://schema.org/BreadcrumbList">%3$s', 262 | tag_escape( $this->option( 'list_tag' ) ), 263 | esc_attr( $this->option( 'list_class' ) ), 264 | $list 265 | ); 266 | 267 | // Build the title HTML only if there's a label for it. 268 | if ( $this->label( 'title' ) ) { 269 | 270 | $title = sprintf( 271 | '<%1$s class="%2$s">%3$s', 272 | tag_escape( $this->option( 'title_tag' ) ), 273 | esc_attr( $this->option( 'title_class' ) ), 274 | $this->label( 'title' ) 275 | ); 276 | } 277 | 278 | if ( $tag = $this->option( 'container_tag' ) ) { 279 | $container = sprintf( 280 | '<%1$s class="%2$s" role="navigation" aria-label="%3$s" itemprop="breadcrumb">%4$s', 281 | tag_escape( $this->option( 'container_tag' ) ), 282 | esc_attr( $this->option( 'container_class' ) ), 283 | esc_attr( $this->label( 'aria_label' ) ), 284 | '%1$s%2$s' 285 | ); 286 | } 287 | 288 | // Build out the final breadcrumbs trail HTML. 289 | $html = sprintf( $container ?: '%1$s%2$s', $title, $list ); 290 | 291 | // Add before/after wrappers. 292 | $html = $this->option( 'before' ) . $html . $this->option( 'after' ); 293 | } 294 | 295 | return apply_filters( "hybrid/breadcrumbs/trail", $html, $crumbs, $this ); 296 | } 297 | 298 | /** 299 | * Runs through a series of conditionals based on the current WordPress 300 | * query. Once we figure out which page we're viewing, we create a new 301 | * `Query` object and let it build the breadcrumbs. 302 | * 303 | * @since 1.0.0 304 | * @access public 305 | * @return Breadcrumbs 306 | */ 307 | public function make() { 308 | 309 | // Call the query class associated with an object passed in. 310 | if ( $this->option( 'post' ) ) { 311 | $this->query( 'Singular', [ 'post' => $this->option( 'post' ) ] ); 312 | 313 | } elseif ( $this->option( 'post_type' ) ) { 314 | $this->query( 'PostTypeArchive', [ 'post_type' => $this->option( 'post_type' ) ] ); 315 | 316 | } elseif ( $this->option( 'term' ) ) { 317 | $this->query( 'Tax', [ 'term' => $this->option( 'term' ) ] ); 318 | 319 | } elseif ( $this->option( 'user' ) ) { 320 | $this->query( 'Author', [ 'user' => $this->option( 'user' ) ] ); 321 | } 322 | 323 | // This may not follow any sort of standards-based code 324 | // formatting rules, but you can damn well read it better! 325 | elseif ( is_front_page() ) { $this->query( 'FrontPage' ); } 326 | elseif ( is_home() ) { $this->query( 'Home' ); } 327 | elseif ( is_singular() ) { $this->query( 'Singular' ); } 328 | elseif ( is_archive() ) { $this->query( 'Archive' ); } 329 | elseif ( is_search() ) { $this->query( 'Search' ); } 330 | elseif ( is_404() ) { $this->query( 'Error' ); } 331 | elseif ( is_paged() ) { $this->query( 'Paged' ); } 332 | 333 | // Return the object for chaining methods. 334 | return $this; 335 | } 336 | 337 | /** 338 | * Creates a new `Query` object and runs its `make()` method. 339 | * 340 | * @since 1.0.0 341 | * @access public 342 | * @param string $type 343 | * @param array $data 344 | * @return void 345 | */ 346 | public function query( $type, array $data = [] ) { 347 | 348 | $class = apply_filters( 349 | "hybrid/breadcrumbs/query/{$type}", 350 | "\\Hybrid\\Breadcrumbs\\Query\\{$type}", 351 | $data 352 | ); 353 | 354 | $query = new $class( $this, $data ); 355 | 356 | $query->make(); 357 | } 358 | 359 | /** 360 | * Creates a new `Build` object and runs its `make()` method. 361 | * 362 | * @since 1.0.0 363 | * @access public 364 | * @param string $type 365 | * @param array $data 366 | * @return void 367 | */ 368 | public function build( $type, array $data = [] ) { 369 | 370 | $class = apply_filters( 371 | "hybrid/breadcrumbs/build/{$type}", 372 | "\\Hybrid\\Breadcrumbs\\Build\\{$type}", 373 | $data 374 | ); 375 | 376 | $build = new $class( $this, $data ); 377 | 378 | $build->make(); 379 | } 380 | 381 | /** 382 | * Creates a new `Crumb` object and adds it to the array of crumbs. 383 | * 384 | * @since 1.0.0 385 | * @access public 386 | * @param string $type 387 | * @param array $data 388 | * @return void 389 | */ 390 | public function crumb( $type, array $data = [] ) { 391 | 392 | $class = apply_filters( 393 | "hybrid/breadcrumbs/crumb/{$type}", 394 | "\\Hybrid\\Breadcrumbs\\Crumb\\{$type}", 395 | $data 396 | ); 397 | 398 | $this->crumbs[] = new $class( $this, $data ); 399 | } 400 | 401 | /** 402 | * Returns a specific option or `false` if the option doesn't exist. 403 | * 404 | * @since 1.0.0 405 | * @access public 406 | * @param string $name 407 | * @return mixed 408 | */ 409 | public function option( $name ) { 410 | 411 | return isset( $this->args[ $name ] ) ? $this->args[ $name ] : false; 412 | } 413 | 414 | /** 415 | * Returns a specific label or an empty string if it doesn't exist. 416 | * 417 | * @since 1.0.0 418 | * @access public 419 | * @param string $name 420 | * @return string 421 | */ 422 | public function label( $name ) { 423 | 424 | $labels = $this->option( 'labels' ); 425 | 426 | return isset( $labels[ $name ] ) ? $labels[ $name ] : ''; 427 | } 428 | 429 | /** 430 | * Returns a specific post taxonomy or an empty string if one isn't set. 431 | * 432 | * @since 1.0.0 433 | * @access public 434 | * @param string $post_type 435 | * @return string 436 | */ 437 | public function postTaxonomy( $post_type ) { 438 | 439 | $taxes = $this->option( 'post_taxonomy' ); 440 | 441 | return isset( $taxes[ $post_type ] ) ? $taxes[ $post_type ] : ''; 442 | } 443 | } 444 | -------------------------------------------------------------------------------- /license.md: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | --------------------------------------------------------------------------------