Code Monkey home page Code Monkey logo

carbon-breadcrumbs's People

Contributors

stoyan0v avatar tyxla avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

carbon-breadcrumbs's Issues

WordPress 4.7 refactored wp_get_object_terms issues

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' ) );

Administration interface

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.

Carbon_Breadcrumb_Trail needs methods for removing items

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:

  1. Breadcrumb Item Title
  2. Breadcrumb Item Link URL
  3. Both 1) and 2) together

Considering this, the following methods would be helpful:

  • remove_item_by_title($title)
  • remove_item_by_link($link)
  • remove_item($title, $link)

Readme needs improvement and additional details

Readme should be improved and additional information should be added:

  • More usage examples
  • Information about the code structure & classes
  • Information and examples for extending and goung further
  • Additional use cases (for example, custom menus)

Allow home item text to be modified

An option for changing the text of the "Home" item should be added. That option would override the home item title in both cases:

  • when there is no page specified as a front page (currently in this case the item title is always "Home")
  • when there is a page specified as a front page (currently in this case the item title equals the title of the page)

Usage of the "carbon_breadcrumbs_item" filter triggers a fatal error

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

Add filters for breadcrumb item title and link

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:

  • Wrapping the breadcrumb item title in a carbon_breadcrumbs_item_title filter
  • Wrapping the breadcrumb item link in a carbon_breadcrumbs_item_link filter

Add schematagging

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;
  }

"Current" class for last breadcrumb item

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.

Yoast SEO - primary category integration

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.

Apply Filter Triggers `Too Few Arguments Fatal Error`

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:

$title = apply_filters( 'the_title', $title );

More info and a probable solution is here:

https://toolset.com/forums/topic/views-conflict-with-woocommerce/#post-616606

Fatal error caused by incompetability between Carbon_Breadcrumb_DB_Object and Carbon_Breadcrumb_Item_Post

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);

Carbon_Breadcrumbs class needs private __clone() and __wakeup()

  • In the Carbon_Breadcrumbs the magic method __clone() should be declared as private to prevent cloning of an instance of the class via the clone operator.
  • In the Carbon_Breadcrumbs the magic method __wakeup() should be declared as private to prevent unserializing of an instance of the class via unserialize().

Tests failed to install on OS X

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.