Hooks
Class adds additional missing hooks from Learndash
Description
Source
File: bp-integrations/learndash/learndash/Hooks.php
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | class Hooks { /** * Constructor * * @since BuddyBoss 1.0.0 */ public function __construct() { add_action( 'bp_ld_sync/init' , [ $this , 'init' ]); } /** * Add actions once integration is ready * * @since BuddyBoss 1.0.0 */ public function init() { // add some helpful missing hooks add_action( 'ld_group_postdata_updated' , [ $this , 'groupUpdated' ]); add_action( 'before_delete_post' , [ $this , 'groupDeleting' ]); // backward compet, we check the meta instead of using hook (hook not consistant) add_action( 'update_user_meta' , [ $this , 'checkLearndashGroupUpdateMeta' ], 10, 4); add_action( 'added_user_meta' , [ $this , 'checkLearndashGroupUpdateMeta' ], 10, 4); add_action( 'deleted_user_meta' , [ $this , 'checkLearndashGroupDeleteMeta' ], 10, 4); add_action( 'update_post_meta' , [ $this , 'checkLearndashCourseUpdateMeta' ], 10, 4); add_action( 'added_post_meta' , [ $this , 'checkLearndashCourseUpdateMeta' ], 10, 4); add_action( 'deleted_post_meta' , [ $this , 'checkLearndashCourseDeleteMeta' ], 10, 4); } /** * Sub action when ld gorup is created * * @since BuddyBoss 1.0.0 */ public function groupUpdated( $groupId ) { do_action( 'bp_ld_sync/learndash_group_updated' , $groupId ); } /** * Sub action before ld gorup is deleted * * @since BuddyBoss 1.0.0 */ public function groupDeleting( $groupId ) { global $wpdb ; $post = $wpdb ->get_row( $wpdb ->prepare( "SELECT * FROM $wpdb->posts WHERE ID = %d" , $groupId )); if ( $post ->post_type != 'groups' ) { return false; } do_action( 'bp_ld_sync/learndash_group_deleting' , $groupId ); add_action( 'delete_post' , [ $this , 'groupDeleted' ]); } /** * Sub action after ld gorup is deleted * * @since BuddyBoss 1.0.0 */ public function groupDeleted( $groupId ) { remove_action( 'delete_post' , [ $this , 'groupDeleted' ]); do_action( 'bp_ld_sync/learndash_group_deleted' , $groupId ); } /** * Sub actions when admin or user is added to ld group * * @since BuddyBoss 1.0.0 */ public function checkLearndashGroupUpdateMeta( $metaId , $userId , $metaKey , $metaValue ) { if ( $this ->isLearndashLeaderMeta( $metaKey )) { $groupId = $this ->getLeardashMetaGroupId( $metaKey ); return do_action( 'bp_ld_sync/learndash_group_admin_added' , $groupId , $userId ); } if ( $this ->isLearndashUserMeta( $metaKey )) { $groupId = $this ->getLeardashMetaGroupId( $metaKey ); return do_action( 'bp_ld_sync/learndash_group_user_added' , $groupId , $userId ); } } /** * Sub actions when admin or user is removed from ld group * * @since BuddyBoss 1.0.0 */ public function checkLearndashGroupDeleteMeta( $metaId , $userId , $metaKey , $metaValue ) { if ( $this ->isLearndashLeaderMeta( $metaKey )) { $groupId = $this ->getLeardashMetaGroupId( $metaKey ); return do_action( 'bp_ld_sync/learndash_group_admin_removed' , $groupId , $userId ); } if ( $this ->isLearndashUserMeta( $metaKey )) { $groupId = $this ->getLeardashMetaGroupId( $metaKey ); return do_action( 'bp_ld_sync/learndash_group_user_removed' , $groupId , $userId ); } } /** * sub action when a course is added to ld group * * @since BuddyBoss 1.0.0 */ public function checkLearndashCourseUpdateMeta( $metaId , $groupId , $metaKey , $metaValue ) { if ( $this ->isLearndashCourseMeta( $metaKey )) { $courseId = $this ->getLeardashMetaGroupId( $metaKey ); return do_action( 'bp_ld_sync/learndash_group_course_added' , $groupId , $courseId ); } } /** * Sub action when a course is deleted from ld group * * @since BuddyBoss 1.0.0 */ public function checkLearndashCourseDeleteMeta( $metaId , $groupId , $metaKey , $metaValue ) { if ( $this ->isLearndashCourseMeta( $metaKey )) { $courseId = $this ->getLeardashMetaGroupId( $metaKey ); return do_action( 'bp_ld_sync/learndash_group_course_deleted' , $groupId , $userId ); } } /** * If the key is a ld leader meta key * * @since BuddyBoss 1.0.0 */ protected function isLearndashLeaderMeta( $key ) { return strpos ( $key , 'learndash_group_leaders_' ) === 0; } /** * If the key is a ld user meta key * * @since BuddyBoss 1.0.0 */ protected function isLearndashUserMeta( $key ) { return strpos ( $key , 'learndash_group_users_' ) === 0; } /** * If the key is a ld course meta key * * @since BuddyBoss 1.0.0 */ protected function isLearndashCourseMeta( $key ) { return strpos ( $key , 'learndash_group_enrolled_' ) === 0; } /** * Get the gorup id from the meta key * * @since BuddyBoss 1.0.0 */ protected function getLeardashMetaGroupId( $key ) { $segments = explode ( '_' , $key ); return array_pop ( $segments ); } } |
Changelog
Version | Description |
---|---|
BuddyBoss 1.0.0 | Introduced. |
Methods
- __construct — Constructor
- checkLearndashCourseDeleteMeta — Sub action when a course is deleted from ld group
- checkLearndashCourseUpdateMeta — sub action when a course is added to ld group
- checkLearndashGroupDeleteMeta — Sub actions when admin or user is removed from ld group
- checkLearndashGroupUpdateMeta — Sub actions when admin or user is added to ld group
- getLeardashMetaGroupId — Get the gorup id from the meta key
- groupDeleted — Sub action after ld gorup is deleted
- groupDeleting — Sub action before ld gorup is deleted
- groupUpdated — Sub action when ld gorup is created
- init — Add actions once integration is ready
- isLearndashCourseMeta — If the key is a ld course meta key
- isLearndashLeaderMeta — If the key is a ld leader meta key
- isLearndashUserMeta — If the key is a ld user meta key
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.