-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
185b587
commit 4adbad7
Showing
4 changed files
with
114 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
lifterlms/admin-pages/llms-reporting-courses-students-custom-columns.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
/** | ||
* Add custom columns and output data on the Courses > Students reporting for course export. | ||
* | ||
* You can add this recipe to your site by creating a custom plugin | ||
* or using the Code Snippets plugin available for free in the WordPress repository. | ||
* Read this companion documentation for step-by-step directions on either method. | ||
* https://lifterlms.com/docs/adding-custom-code/ | ||
*/ | ||
/** | ||
* Output data for a custom column on the student reporting for course export. | ||
* | ||
* @param string $value Default value being output | ||
* @param string $key Name of the custom field being output | ||
* @param obj $student LLMS_Student for the row | ||
* @param string $context Output context "display" or "export" | ||
* @return mixed | ||
*/ | ||
function course_students_table_column_data( $value, $key, $data, $context ) { | ||
|
||
if ( 'test' === $key ) { | ||
$value = 'Some Test'; | ||
} | ||
|
||
return $value; | ||
|
||
} | ||
add_filter( 'llms_table_get_data_course-students', 'course_students_table_column_data', 10, 4 ); | ||
|
||
/** | ||
* Add custom columns to the course students reporting table. | ||
* | ||
* @param array $cols Columns. | ||
* @return array $cols Columns. | ||
*/ | ||
function course_students_table_columns( $cols ) { | ||
|
||
$cols['test'] = array( | ||
'title' => __( 'Test Test', 'lifterlms' ), | ||
'export_only' => false, // set to false to show display screens but include in exports | ||
'exportable' => true, // set to false to exclude from exports | ||
); | ||
|
||
return $cols; | ||
} | ||
add_filter( 'llms_table_get_course-students_columns', 'course_students_table_columns', 10 ); |
32 changes: 32 additions & 0 deletions
32
lifterlms/courses-lessons/llms-get-course-ids-order-by-enrollments.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
/** | ||
* Get all the course IDs ordered by enrolled students in descending order. | ||
* | ||
* You can add this recipe to your site by creating a custom plugin | ||
* or using the Code Snippets plugin available for free in the WordPress repository. | ||
* Read this companion documentation for step-by-step directions on either method. | ||
* https://lifterlms.com/docs/adding-custom-code/ | ||
*/ | ||
function llms_get_courses_ids_order_by_enrollments() { | ||
// Get all the course IDs. | ||
$course_ids = get_posts( | ||
array( | ||
'post_type' => 'course', | ||
'posts_per_page' => -1, | ||
'fields' => 'ids', | ||
) | ||
); | ||
|
||
// Get the enrolled students count for each course. | ||
$enrollment_counts = array(); | ||
foreach ( $course_ids as $course_id ) { | ||
$course = new LLMS_Course( $course_id ); | ||
$enrollment_counts[ $course_id ] = $course->get_student_count(); | ||
} | ||
|
||
// Sort the array in descending order. | ||
arsort( $enrollment_counts ); | ||
|
||
return $enrollment_counts; | ||
} | ||
$desc_sorted_course_ids = llms_get_courses_ids_order_by_enrollments(); |
34 changes: 34 additions & 0 deletions
34
lifterlms/frontend-pages/llms-hiding-paid-access-plans-for-memberships-enrollments.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
/** | ||
* Hiding paid access plans for students enrolled in particular memberships. | ||
* | ||
* You can add this recipe to your site by creating a custom plugin | ||
* or using the Code Snippets plugin available for free in the WordPress repository. | ||
* Read this companion documentation for step-by-step directions on either method. | ||
* https://lifterlms.com/docs/adding-custom-code/ | ||
*/ | ||
function llms_product_is_purchasable( $purchasable, $product ) { | ||
|
||
$user_id = get_current_user_id(); | ||
$free_access_plans = $product->get_access_plans( true ); | ||
|
||
// Get membership restrictions. | ||
$membership_restrictions = array(); | ||
foreach ( $free_access_plans as $plan ) { | ||
$membership_restrictions[] = $plan->get( 'availability_restrictions' ); | ||
} | ||
|
||
// Merging the array. | ||
$membership_restrictions = array_merge( ...$membership_restrictions ); | ||
|
||
// Check if a user is enrolled in the memberships. | ||
foreach ( $membership_restrictions as $membership_id ) { | ||
if ( llms_is_user_enrolled( $user_id, $membership_id ) ) { | ||
$purchasable = false; | ||
} | ||
} | ||
|
||
return $purchasable; | ||
} | ||
|
||
add_filter( 'llms_product_is_purchasable', 'llms_product_is_purchasable', 10, 2 ); |