Skip to content

Commit

Permalink
Merge branch 'release/1.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Hemberger committed Apr 4, 2018
2 parents cb903da + 8eb7b94 commit 0637b37
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# LearnDash Yoast SEO Breadcrumbs
Use the correct course > lesson > topic hierarchy in Yoast SEO breadcrumbs.
Use the correct LearnDash Course > Lesson > Topic hierarchy in Yoast SEO breadcrumbs.
79 changes: 66 additions & 13 deletions learndash-yoast-breadcrumbs.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* Plugin Name: LearnDash Yoast SEO Breadcrumbs
* Plugin URI: https://bizbudding.com
* Description: Use the correct course > lesson > topic hierarchy in Yoast SEO breadcrumbs.
* Description: Use the correct LearnDash Course > Lesson > Topic hierarchy in Yoast SEO breadcrumbs.
* Version: 1.0.0
*
* Author: BizBudding, Mike Hemberger
Expand Down Expand Up @@ -46,8 +46,7 @@ public static function instance() {
self::$instance = new LD_Yoast_Breadcrumbs;
// Methods
self::$instance->setup_constants();
self::$instance->includes();
self::$instance->setup();
self::$instance->run();
}
return self::$instance;
}
Expand Down Expand Up @@ -113,25 +112,19 @@ private function setup_constants() {
define( 'LD_YOAST_BREADCRUMBS_PLUGIN_FILE', __FILE__ );
}

// Plugin Base Name
// Plugin Base Name.
if ( ! defined( 'LD_YOAST_BREADCRUMBS_BASENAME' ) ) {
define( 'LD_YOAST_BREADCRUMBS_BASENAME', dirname( plugin_basename( __FILE__ ) ) );
}

}

/**
* Include required files.
* Run this thing.
*
* @access private
* @since 1.0.0
* @return void
*/
private function includes() {
foreach ( glob( LD_YOAST_BREADCRUMBS_INCLUDES_DIR . '*.php' ) as $file ) { include $file; }
}

public function setup() {
public function run() {

add_action( 'admin_init', array( $this, 'updater' ) );
add_filter( 'wpseo_breadcrumb_links', array( $this, 'breadcrumb_links' ) );
Expand All @@ -151,9 +144,69 @@ public function updater() {
if ( ! class_exists( 'Puc_v4_Factory' ) ) {
require_once LD_YOAST_BREADCRUMBS_INCLUDES_DIR . 'vendor/plugin-update-checker/plugin-update-checker.php'; // 4.4
}
$updater = Puc_v4_Factory::buildUpdateChecker( 'https://github.com/maithemewp/mai-theme-engine/', __FILE__, 'textdomain' );
$updater = Puc_v4_Factory::buildUpdateChecker( 'https://github.com/bizbudding/learndash-yoast-breadcrumbs', __FILE__, 'learndash-yoast-breadcrumbs' );
}

/**
* Convert Yoast Breadcrumbs to follow LearnDash hierarchy.
*
* @param array $link The breadcrumbs array.
*
* @return array The modified breadcrumbs array.
*/
public function breadcrumb_links( $links ) {

// Bail if not a single learndash post.
if ( ! is_singular( array( 'sfwd-courses', 'sfwd-lessons', 'sfwd-quiz', 'sfwd-topic', 'sfwd-certificates' ) ) ) {
return $links;
}

$items = array();

// Don't add course link to the course page.
if ( ! is_singular( 'sfwd-courses' ) ) {

// Add course link.
$course_id = learndash_get_course_id( get_the_ID() );
if ( $course_id ) {
$items[] = array( 'id' => $course_id );
}

}

// Don't add lesson link to the lesson page.
if ( ! is_singular( 'sfwd-lessons' ) ) {

// Add lesson link.
$lesson_id = learndash_get_lesson_id( get_the_ID() );
if ( $lesson_id ) {
$items[] = array( 'id' => $lesson_id );
}

}

// Bail if no items.
if ( ! $items ) {
return $links;
}

// Remove last item, and store it.
$last = array_pop( $links );

// Merge existing with LearnDash items.
$links = array_merge( $links, $items );

// Add the last item back.
$links[] = $last;

return $links;
}

/**
* Flush permalinks just incase they get in the way of breadcrumb links.
*
* @return void
*/
public function activate() {
flush_rewrite_rules();
}
Expand Down

0 comments on commit 0637b37

Please sign in to comment.