tyxla / carbon-breadcrumbs Goto Github PK
View Code? Open in Web Editor NEWA basic WordPress plugin for breadcrumbs with advanced capabilities for extending.
License: GNU General Public License v2.0
A basic WordPress plugin for breadcrumbs with advanced capabilities for extending.
License: GNU General Public License v2.0
Carbon_Breadcrumb_Trail_Setup.php - populate_category_items
$categories = wp_get_object_terms( get_the_ID(), $taxonomy, 'orderby=term_id' );
should be updated to
$categories = wp_get_object_terms( get_the_ID(), $taxonomy, array( 'orderby' => 'term_id' ) );
The Events Calendar (https://wordpress.org/plugins/the-events-calendar/) are "hacking" the query on wp_head
, failing to setup $post
and there should be a workaround for that in the single events template.
Build an administration interface for controlling the settings. Should be enabled by default only if the plugin is installed as a plugin (vs. included in a theme), but enabling should be possible by a separate constant.
There should be a filter for modifying the output of a single breadcrumb trail item.
Document the structure of $items
and explain what goes where.
Carbon_Breadcrumb_Trail could use methods for removing items from the trail. For the sake of easier usage, one would want to remove items by:
Considering this, the following methods would be helpful:
remove_item_by_title($title)
remove_item_by_link($link)
remove_item($title, $link)
Readme should be improved and additional information should be added:
Sorting needs to happen automatically right before rendering.
This way when implementing custom setup, developer wont have to manually sort the items.
Explain and document plugin structure and all classes to help developers when extending the plugin.
An option for changing the text of the "Home" item should be added. That option would override the home item title in both cases:
Write the WP plugin readme.
Test with all different template situations together with The Events Calendar plugin.
Some issues and unexpected behaviour has been reported with custom post types and/or custom taxonomies. This needs testing.
Add a setting in breadcrumb trail to control renderer class name, in addition to the filter in the constructor.
Use case:
add_filter( 'carbon_breadcrumbs_item', 'crb_modify_breadcrumbs_last_item' );
function crb_modify_breadcrumbs_last_item( $item ){ }
Output:
Fatal error: Call to a member function get_link() on a non-object in ..\carbon-breadcrumbs\includes\Carbon_Breadcrumb_Trail_Renderer.php on line 424
Currently, if there is a page set as page_on_front
, the home_item_title
will not be taken into consideration. The home_item_title
should always define the title of the home item.
When building the breadcrumb item trail output, the title and link of each item should allow filtering on a per-item basis. This can be achieved by:
carbon_breadcrumbs_item_title
filtercarbon_breadcrumbs_item_link
filterAbstract the breadcrumb visual options and rendering from the trail, possibly in a separate class.
Document all terms that are used within the library.
GREAT plugin, fantastic codebase: super clean & TESTED?! FTW!
Only downside is no schematagging out of the box :/. This is a pivotal SEO feature and I think this would greatly boost interest in your plugin.
Info: https://developers.google.com/search/docs/data-types/breadcrumbs#guidelines
Result should look like:
<ol itemscope itemtype="http://schema.org/BreadcrumbList">
<li itemprop="itemListElement" itemscope
itemtype="http://schema.org/ListItem">
<a itemscope itemtype="http://schema.org/WebPage"
itemprop="item" href="link.html">
<span itemprop="name">Crumb 1</span>
</a>
<meta itemprop="position" content="1" />
/
</li>
<li itemprop="itemListElement" itemscope
itemtype="http://schema.org/ListItem">
<a itemscope itemtype="http://schema.org/WebPage"
itemprop="item" href="link2.html">
<span itemprop="name">Crumb 2</span>
</a>
<meta itemprop="position" content="2" />
</li>
</ol>
Here's how I've shimmed it in:
<?php
$breadcrumbs = new Carbon_Breadcrumb_Trail(array(
'glue' => ' / ',
'link_before' => '<li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem">',
'link_after' => '</li>',
'wrapper_before' => '<ol class="breadcrumbs" itemscope itemtype="http://schema.org/BreadcrumbList">',
'wrapper_after' => '</ol>',
'title_before' => '<span itemprop="name">',
'title_after' => '</span>',
));
$breadcrumbs->setup();
echo $breadcrumbs->render(true); // WP_KSES strips itemprop, itemscope, etc, so bypassing!!!
add_filter('carbon_breadcrumbs_item_attributes', _'breadcrumb_schematags', 10, 2);
function breadcrumb_schematags($attributes, $item) {
if (!is_array($attributes)) $attributes = array();
$attributes['itemscope'] = null;
$attributes['itemtype'] = 'http://schema.org/WebPage';
$attributes['itemprop'] = 'item';
return $attributes;
}
add_filter('carbon_breadcrumbs_item_output', 'breadcrumb_item_position', 10, 5);
function breadcrumb_item_position($item_output, $item, $trail, $trail_renderer, $index){
// Add Position
$n = strrpos($item_output, '</li>');
$item_output = substr($item_output, 0, $n) . '<meta itemprop="position" content="'. $index .'" />' . substr($item_output, $n);
return $item_output;
}
It would be nice if there could be a class on the last breadcrumb item (which is basically the active item) if it is a link.
This way an alternative CSS styles could be added if we have to support browsers where :last-child
doesn't work.
Need to add more examples & developer-oriented documentation.
A fun and useful thing to have would be Yoast SEO integration for their feature "Primary Category".
Here is some reference code that I use to integrate the Yoast SEO Primary Category feature:
add_action( 'carbon_breadcrumbs_after_setup_trail', array( $this, 'modify_breadcrumbs' ) );
function modify_breadcrumbs( $trail ) {
global $post;
if ( ! is_singular( 'post' ) ) {
return;
}
$cats = get_the_category( $post->ID );
if ( empty( $cats ) || empty( $cats[0] ) ) {
return;
}
$cats = wp_list_sort( $cats, array(
'term_id' => 'ASC',
) );
/**
* Call the filter,
* triggering YoastSEO primary category modification
*/
$category_object = apply_filters( 'post_link_category', $cats[0], $cats, $post );
$term_id = $category_object->term_id;
/**
* Taxonomy breadcrumb is inserted at 700
* Removing it, and adding new one at the same priority
*/
$trail->remove_item_by_priority( 700 );
$terms = Carbon_Breadcrumb_Locator::factory( 'term', 'category' );
$items = $terms->get_items( 700, $term_id );
if ( $items ) {
$trail->add_item( $items );
}
}
Using post_link_category
can potentially lead to longer support, compared to YoastSEO internal methods.
Let me know if you are interested in this feature, and I will provide a fork.
This triggers a WordPress error in WordPress 4.9.18 when the apply_filter
is called:
Fatal error: Uncaught ArgumentCountError: Too few arguments to function WC_Template_Loader::unsupported_theme_title_filter(), 1 passed in
BASE\wp-includes\class-wp-hook.php on line 286 and exactly 2 expected in
BASE\wp-content\plugins\woocommerce\includes\class-wc-template-loader.php:399 Stack trace: #0
BASE\wp-includes\class-wp-hook.php(286): WC_Template_Loader::unsupported_theme_title_filter('A New Page') #1
BASE\wp-includes\plugin.php(203): WP_Hook->apply_filters('A New Page', Array) #2
BASE\wp-content\themes\braun-parts\vendor\tyxla\carbon-breadcrumbs\core\Carbon_Breadcrumb_Item_Post.php(30): apply_filters('the_title', 'A New Page') #3
BASE\wp-content\themes\ in
BASE\wp-content\plugins\woocommerce\includes\class-wc-template-loader.php on line 399
I triggered this by installing WooCommerce but I don't believe it is WooCommerce specific and I think the offending line is:
More info and a probable solution is here:
https://toolset.com/forums/topic/views-conflict-with-woocommerce/#post-616606
Abstract the breadcrumb rendering from the trail and implement a walker class for it.
The trail display settings would still be specified to the Carbon_Breadcrumb_Trail
class, however the render()
method would use a custom (overridable) walker for rendering the items.
Error:
Fatal error: Declaration of Carbon_Breadcrumb_Item_Post::set_id() must be compatible with that of Carbon_Breadcrumb_DB_Object::set_id() in /homepages/21/d320322082/htdocs/cayt/wp-content/themes/mentor/includes/carbon-breadcrumb/includes/Carbon_Breadcrumb_Item_Post.php on line 7
Possible cause: server configuration, as it appears only on a particular server
Possible Solution: The public method set_id
declared in the interface Carbon_Breadcrumb_DB_Object should be declared like:
public function set_id($id = 0);
__clone()
should be declared as private to prevent cloning of an instance of the class via the clone operator.__wakeup()
should be declared as private to prevent unserializing of an instance of the class via unserialize()
.When run the tests installation command provided in https://github.com/tyxla/carbon-breadcrumbs/blob/master/tests/README.md I get the following error:
expr: syntax error
The wp-tests-config.php
is the default one, missing database credentials.
Then if I run phpunit
I get the following error:
Warning: require_once(/path_to_project/wordpress/wp-content/plugins/carbon-breadcrumbs/tmp/wordpress-tests-lib/src//wp-includes/class-phpmailer.php): failed to open stream: No such file or directory in /path_to_project/wordpress/wp-content/plugins/carbon-breadcrumbs/tmp/wordpress-tests-lib/includes/mock-mailer.php on line 2
.
I checked for that directory and it's missing, so I guess something is broken in installation.
Mac OS X Sierra
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.