diff --git a/README.md b/README.md index f947640..669bf9b 100644 --- a/README.md +++ b/README.md @@ -27,9 +27,9 @@ Please include the following header format when submitting a snippet ``` /** * Describe what the snippet does in one sentence. (i.e. Add a checkbox to the checkout page.) - * + * * Learn more at: https://lifterlms.com/link-to-content-if-available-or-remove-this-line/ - * + * * 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. diff --git a/lifterlms/admin-pages/llms-reporting-courses-students-custom-columns.php b/lifterlms/admin-pages/llms-reporting-courses-students-custom-columns.php new file mode 100644 index 0000000..1b69107 --- /dev/null +++ b/lifterlms/admin-pages/llms-reporting-courses-students-custom-columns.php @@ -0,0 +1,46 @@ + 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 ); diff --git a/lifterlms/courses-lessons/llms-get-course-ids-order-by-enrollments.php b/lifterlms/courses-lessons/llms-get-course-ids-order-by-enrollments.php new file mode 100644 index 0000000..a43d635 --- /dev/null +++ b/lifterlms/courses-lessons/llms-get-course-ids-order-by-enrollments.php @@ -0,0 +1,32 @@ + '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(); diff --git a/lifterlms/frontend-pages/llms-hiding-paid-access-plans-for-memberships-enrollments.php b/lifterlms/frontend-pages/llms-hiding-paid-access-plans-for-memberships-enrollments.php new file mode 100644 index 0000000..5491860 --- /dev/null +++ b/lifterlms/frontend-pages/llms-hiding-paid-access-plans-for-memberships-enrollments.php @@ -0,0 +1,34 @@ +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 );