add-user-group.php
10 months ago
enroll-to-course.php
10 months ago
find-course-taxonomy.php
10 months ago
find-user-group-leader-groups.php
5 months ago
find-user-groups.php
10 months ago
list-user-enrolled-courses.php
10 months ago
make-user-group-leader.php
2 years ago
mark-course-complete-for-user.php
10 months ago
mark-lesson-complete-for-user.php
10 months ago
mark-quiz-complete-for-user.php
10 months ago
mark-topic-complete-for-user.php
10 months ago
remove-from-course.php
10 months ago
remove-user-from-group-leader.php
10 months ago
remove-user-group.php
10 months ago
reset-user-course-progress.php
10 months ago
find-course-taxonomy.php
105 lines
| 1 | <?php |
| 2 | /** |
| 3 | * FindCourseTaxonomies. |
| 4 | * php version 5.6 |
| 5 | * |
| 6 | * @category FindCourseTaxonomies |
| 7 | * @package SureTriggers |
| 8 | * @author BSF |
| 9 | * @license https://www.gnu.org/licenses/gpl-3.0.html GPLv3 |
| 10 | * @link https://www.brainstormforce.com/ |
| 11 | * @since 1.0.0 |
| 12 | */ |
| 13 | |
| 14 | namespace SureTriggers\Integrations\LearnDash\Actions; |
| 15 | |
| 16 | use SureTriggers\Integrations\AutomateAction; |
| 17 | use SureTriggers\Traits\SingletonLoader; |
| 18 | |
| 19 | /** |
| 20 | * FindCourseTaxonomies |
| 21 | * |
| 22 | * @category FindCourseTaxonomies |
| 23 | * @package SureTriggers |
| 24 | */ |
| 25 | class FindCourseTaxonomies extends AutomateAction { |
| 26 | |
| 27 | /** |
| 28 | * Integration type. |
| 29 | * |
| 30 | * @var string |
| 31 | */ |
| 32 | public $integration = 'LearnDash'; |
| 33 | |
| 34 | /** |
| 35 | * Action name. |
| 36 | * |
| 37 | * @var string |
| 38 | */ |
| 39 | public $action = 'ld_find_course_taxonomies'; |
| 40 | |
| 41 | use SingletonLoader; |
| 42 | |
| 43 | /** |
| 44 | * Register an action. |
| 45 | * |
| 46 | * @param array $actions actions. |
| 47 | * @return array |
| 48 | */ |
| 49 | public function register( $actions ) { |
| 50 | $actions[ $this->integration ][ $this->action ] = [ |
| 51 | 'label' => __( 'Find Course Taxonomies', 'suretriggers' ), |
| 52 | 'action' => $this->action, |
| 53 | 'function' => [ $this, 'action_listener' ], |
| 54 | ]; |
| 55 | return $actions; |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Action listener. |
| 60 | * |
| 61 | * @param int $user_id user ID. |
| 62 | * @param int $automation_id automation ID. |
| 63 | * @param array $fields fields. |
| 64 | * @param array $selected_options selected options. |
| 65 | * |
| 66 | * @return array|false |
| 67 | */ |
| 68 | public function _action_listener( $user_id, $automation_id, $fields, $selected_options ) { |
| 69 | |
| 70 | $course_id = isset( $selected_options['sfwd-courses'] ) ? intval( $selected_options['sfwd-courses'] ) : 0; |
| 71 | |
| 72 | if ( empty( $course_id ) || get_post_type( $course_id ) !== 'sfwd-courses' ) { |
| 73 | return [ |
| 74 | 'message' => __( 'Invalid Course ID.', 'suretriggers' ), |
| 75 | |
| 76 | ]; |
| 77 | } |
| 78 | |
| 79 | |
| 80 | global $sfwd_lms; |
| 81 | $courses_taxonomies = $sfwd_lms->get_post_args_section( 'sfwd-courses', 'taxonomies' ); |
| 82 | |
| 83 | $course_taxonomies = []; |
| 84 | |
| 85 | if ( ! empty( $courses_taxonomies ) ) { |
| 86 | foreach ( $courses_taxonomies as $taxonomy_slug => $taxonomy ) { |
| 87 | if ( ! empty( $taxonomy['public'] ) ) { |
| 88 | $terms = get_the_terms( $course_id, $taxonomy_slug ); |
| 89 | if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) { |
| 90 | $course_taxonomies[ $taxonomy_slug ] = wp_list_pluck( $terms, 'name' ); |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | return [ |
| 97 | 'course_id' => $course_id, |
| 98 | 'taxonomies' => ! empty( $course_taxonomies ) ? $course_taxonomies : __( 'No taxonomies found.', 'suretriggers' ), |
| 99 | |
| 100 | ]; |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | FindCourseTaxonomies::get_instance(); |
| 105 |