wishlist-member-add-update-user.php
10 months ago
wishlist-member-add-user.php
2 years ago
wishlist-member-check-if-user-is-member.php
11 months ago
wishlist-member-create-new-level.php
11 months ago
wishlist-member-delete-existing-member.php
11 months ago
wishlist-member-delete-level.php
11 months ago
wishlist-member-get-all-levels.php
11 months ago
wishlist-member-get-member-by-email.php
11 months ago
wishlist-member-get-member-by-username.php
11 months ago
wishlist-member-get-member-information.php
11 months ago
wishlist-member-get-specific-level-details.php
11 months ago
wishlist-member-get-specific-member-level.php
11 months ago
wishlist-member-remove-user.php
3 years ago
wishlist-member-update-existing-level.php
11 months ago
wishlist-member-remove-user.php
104 lines
| 1 | <?php |
| 2 | /** |
| 3 | * WishlistMemberRemoveUser. |
| 4 | * php version 5.6 |
| 5 | * |
| 6 | * @category WishlistMemberRemoveUser |
| 7 | * @package SureTriggers |
| 8 | * @author BSF <username@example.com> |
| 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\WishlistMember\Actions; |
| 15 | |
| 16 | use SureTriggers\Integrations\AutomateAction; |
| 17 | use SureTriggers\Integrations\WordPress\WordPress; |
| 18 | use SureTriggers\Traits\SingletonLoader; |
| 19 | |
| 20 | /** |
| 21 | * WishlistMemberRemoveUser |
| 22 | * |
| 23 | * @category WishlistMemberRemoveUser |
| 24 | * @package SureTriggers |
| 25 | * @author BSF <username@example.com> |
| 26 | * @license https://www.gnu.org/licenses/gpl-3.0.html GPLv3 |
| 27 | * @link https://www.brainstormforce.com/ |
| 28 | * @since 1.0.0 |
| 29 | */ |
| 30 | class WishlistMemberRemoveUser extends AutomateAction { |
| 31 | |
| 32 | |
| 33 | /** |
| 34 | * Integration type. |
| 35 | * |
| 36 | * @var string |
| 37 | */ |
| 38 | public $integration = 'WishlistMember'; |
| 39 | |
| 40 | /** |
| 41 | * Action name. |
| 42 | * |
| 43 | * @var string |
| 44 | */ |
| 45 | public $action = 'wishlistmember_remove_user_levels'; |
| 46 | |
| 47 | use SingletonLoader; |
| 48 | |
| 49 | /** |
| 50 | * Register a action. |
| 51 | * |
| 52 | * @param array $actions actions. |
| 53 | * @return array |
| 54 | */ |
| 55 | public function register( $actions ) { |
| 56 | |
| 57 | $actions[ $this->integration ][ $this->action ] = [ |
| 58 | 'label' => __( 'Remove User from Membership Level', 'suretriggers' ), |
| 59 | 'action' => $this->action, |
| 60 | 'function' => [ $this, 'action_listener' ], |
| 61 | ]; |
| 62 | |
| 63 | return $actions; |
| 64 | |
| 65 | } |
| 66 | |
| 67 | |
| 68 | /** |
| 69 | * Action listener. |
| 70 | * |
| 71 | * @param int $user_id user_id. |
| 72 | * @param int $automation_id automation_id. |
| 73 | * @param array $fields fields. |
| 74 | * @param array $selected_options selectedOptions. |
| 75 | * |
| 76 | * @return array|bool |
| 77 | */ |
| 78 | public function _action_listener( $user_id, $automation_id, $fields, $selected_options ) { |
| 79 | $wlm_level_id = $selected_options['wlm_remove_levels']; |
| 80 | |
| 81 | if ( empty( $user_id ) || empty( $wlm_level_id ) ) { |
| 82 | return false; |
| 83 | } |
| 84 | |
| 85 | wlmapi_remove_member_from_level( $wlm_level_id, $user_id ); |
| 86 | |
| 87 | $level = wlmapi_get_level( $wlm_level_id ); |
| 88 | |
| 89 | $context = []; |
| 90 | $context['level_id'] = $wlm_level_id; |
| 91 | |
| 92 | if ( isset( $level['level'] ) ) { |
| 93 | $context['level_name'] = $level['level']['name']; |
| 94 | } |
| 95 | |
| 96 | return array_merge( |
| 97 | WordPress::get_user_context( $user_id ), |
| 98 | $context |
| 99 | ); |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | WishlistMemberRemoveUser::get_instance(); |
| 104 |