-
Notifications
You must be signed in to change notification settings - Fork 197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update sensei_results_links
filter to include the learner's user ID
#7048
Conversation
Codecov Report
@@ Coverage Diff @@
## trunk #7048 +/- ##
============================================
+ Coverage 48.03% 48.07% +0.04%
- Complexity 10465 10467 +2
============================================
Files 573 573
Lines 44151 44164 +13
Branches 402 402
============================================
+ Hits 21207 21234 +27
+ Misses 22617 22603 -14
Partials 327 327
... and 3 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey Mike, thanks for the help, and glad to see you again!
I've left some feedback, so let me know what you think.
includes/class-sensei-course.php
Outdated
* | ||
* @return {string} HTML output of the links. | ||
*/ | ||
$complete_html .= apply_filters( 'sensei_results_completed_links', '', $course_item->ID, $user->ID ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of introducing a new filter, do you think we can reuse the old one? I was thinking that we might refactor a bit to make the hook a bit more accessible. Let me know what you think of the following patch:
diff --git a/includes/class-sensei-course.php b/includes/class-sensei-course.php
index 5df6d9d9a..67d4d6388 100755
--- a/includes/class-sensei-course.php
+++ b/includes/class-sensei-course.php
@@ -2067,41 +2067,23 @@ class Sensei_Course {
$complete_html .= $this->get_progress_meter( 100 );
- if ( $manage ) {
- $has_quizzes = Sensei()->course->course_quizzes( $course_item->ID, true );
-
- // Output only if there is content to display
- if ( self::has_results_links( $course_item->ID ) || $has_quizzes ) {
- $complete_html .= '<p class="sensei-results-links">';
- $results_link = '';
-
- if ( $has_quizzes ) {
- $results_link = '<a class="button view-results" href="'
- . esc_url( self::get_view_results_link( $course_item->ID ) )
- . '">' . esc_html__( 'View Results', 'sensei-lms' )
- . '</a>';
- }
-
- /**
- * Filter documented in Sensei_Course::the_course_action_buttons
- */
- $complete_html .= apply_filters( 'sensei_results_links', $results_link, $course_item->ID );
- $complete_html .= '</p>';
+ $results_link = '';
+ if ( $manage && Sensei()->course->course_quizzes( $course_item->ID, true ) ) {
+ $results_link = '<a class="button view-results" href="'
+ . esc_url( self::get_view_results_link( $course_item->ID ) )
+ . '">' . esc_html__( 'View Results', 'sensei-lms' )
+ . '</a>';
+ }
- }
+ /**
+ * Filter documented in Sensei_Course::the_course_action_buttons
+ */
+ $results_links = apply_filters( 'sensei_results_links', $results_link, $course_item->ID );
+ if ( $results_links ) {
+ $complete_html .= '<p class="sensei-results-links">';
+ $complete_html .= $results_links;
+ $complete_html .= '</p>';
}
- /**
- * Publicly displays links related to the completed course
- *
- * @since 4.16.1
- * @hook sensei_results_completed_links
- *
- * @param {int} $course_id The ID of the course.
- * @param {int} $user_id The user ID of the learner.
- *
- * @return {string} HTML output of the links.
- */
- $complete_html .= apply_filters( 'sensei_results_completed_links', '', $course_item->ID, $user->ID );
$complete_html .= '</section>';
This should preserve the old logic and make it easier for third parties to hook in. I don't think we need the self::has_results_links
check in this case, so I've removed it from the logic.
LMKWYT.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @m1r0 !
I'm all for this if it won't have any unintended side effects. I added a new filter thinking having it applied inside the $manage
was intentional but if it isn't, this makes sense.
If that filter isn't supposed to be suppressed like that, your patch makes perfect sense!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
468d865
to
2584234
Compare
ac79bd0
to
fdbb06b
Compare
sensei_results_links
filter to include the learner's user ID
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks for the contribution! 🎉
Proposed Changes
sensei_results_links
filter to include the learner's user ID when displaying public profiles. This will be used to enable Sensei Certificates to publicly display the "View Certificate" button (Ref: Display View Certificate button on public learner profile woocommerce/sensei-certificates#341 )load_user_courses_content()
to display results links publiclyTesting Instructions
<site-url>/learner/<login>
) and checkAllow my Certificates to be publicly viewed
. Save the setting.Allow my Certificates to be publicly viewed
. Save the setting.Screenshot of public profile before the update
Screenshot of public profile after the update
New/Updated Hooks
sensei_results_links
insideload_user_courses_content()
to include a$user_id
parameterNew parameter:
$user_id
: The user ID of the learner being viewedPre-Merge Checklist