Skip to content
This repository has been archived by the owner on Feb 20, 2024. It is now read-only.

Commit

Permalink
Move 'do_link_to_module' method to Sensei core and check for implemen…
Browse files Browse the repository at this point in the history
…tation (#47)
  • Loading branch information
jom authored and donnapep committed Mar 27, 2018
1 parent f611461 commit 2ca37d0
Showing 1 changed file with 7 additions and 36 deletions.
43 changes: 7 additions & 36 deletions includes/class-sensei-course-progress-widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,49 +264,20 @@ public function form( $instance ) {
* Formats the title for each module in the course outline.
*
* @param WP_Term $module
*
* @return string
*/
private function get_module_title_content( WP_Term $module ) {
if ( $this->do_link_to_module( $module ) ) {
return '<a href="' . $module->url . '">' . esc_html( $module->name ) . '</a>';
}
return esc_html( $module->name );
} // End get_module_title_content()
$link_to_module = false;


/**
* Check if we should link to a module in the course outline.
*
* True if there is a module description or if the `taxonomy-module.php` template has been overridden.
*
* @param WP_Term $module
*
* @return bool
*/
private function do_link_to_module( WP_Term $module ) {
// Don't link to module when on the module page already.
if ( is_tax( 'module', $module->term_id ) ) {
return false;
if ( method_exists( Sensei()->modules, 'do_link_to_module' ) ) {
$link_to_module = Sensei()->modules->do_link_to_module( $module );
}

$description = trim( $module->description );
if ( ! empty( $description ) ) {
return true;
if ( $link_to_module ) {
return '<a href="' . $module->url . '">' . esc_html( $module->name ) . '</a>';
}

return $this->is_module_tax_template_overriden();
} // End do_link_to_module()
return esc_html( $module->name );
} // End get_module_title_content()

/**
* Checks if a module taxonomy template file has been overridden.
*
* @return bool True if taxonomy template has been overridden.
*/
private function is_module_tax_template_overriden() {
$file = 'taxonomy-module.php';
$find = array( $file, Sensei()->template_url . $file );
$template = locate_template( $find );
return (bool) $template;
} // End is_module_tax_template_overriden()
}

0 comments on commit 2ca37d0

Please sign in to comment.