suretriggers
/
src
/
Integrations
/
wp-user-manager
/
triggers
/
user-updates-account-information.php
user-removes-profile-cover-image.php
3 years ago
user-removes-profile-photo.php
3 years ago
user-updates-account-information.php
3 years ago
user-updates-cover-photo.php
3 years ago
user-updates-profile-description.php
3 years ago
user-updates-profile-photo.php
3 years ago
user-updates-account-information.php
114 lines
| 1 | <?php |
| 2 | /** |
| 3 | * UserUpdatesAccountInformation. |
| 4 | * php version 5.6 |
| 5 | * |
| 6 | * @category UserUpdatesAccountInformation |
| 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\WPUserManager\Triggers; |
| 15 | |
| 16 | use SureTriggers\Controllers\AutomationController; |
| 17 | use SureTriggers\Integrations\WordPress\WordPress; |
| 18 | use SureTriggers\Traits\SingletonLoader; |
| 19 | |
| 20 | /** |
| 21 | * UserUpdatesAccountInformation |
| 22 | * |
| 23 | * @category UserUpdatesAccountInformation |
| 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 UserUpdatesAccountInformation { |
| 31 | |
| 32 | /** |
| 33 | * Integration type. |
| 34 | * |
| 35 | * @var string |
| 36 | */ |
| 37 | public $integration = 'WPUserManager'; |
| 38 | |
| 39 | /** |
| 40 | * Trigger name. |
| 41 | * |
| 42 | * @var string |
| 43 | */ |
| 44 | public $trigger = 'wpuser_manager_user_updates_account_information'; |
| 45 | |
| 46 | use SingletonLoader; |
| 47 | |
| 48 | /** |
| 49 | * Constructor |
| 50 | * |
| 51 | * @since 1.0.0 |
| 52 | */ |
| 53 | public function __construct() { |
| 54 | add_filter( 'sure_trigger_register_trigger', [ $this, 'register' ] ); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Register action. |
| 59 | * |
| 60 | * @param array $triggers trigger data. |
| 61 | * |
| 62 | * @return array |
| 63 | */ |
| 64 | public function register( $triggers ) { |
| 65 | |
| 66 | $triggers[ $this->integration ][ $this->trigger ] = [ |
| 67 | 'label' => __( 'User Updates Account Information', 'suretriggers' ), |
| 68 | 'action' => $this->trigger, |
| 69 | 'common_action' => 'wpum_after_user_update', |
| 70 | 'function' => [ $this, 'trigger_listener' ], |
| 71 | 'priority' => 99, |
| 72 | 'accepted_args' => 3, |
| 73 | ]; |
| 74 | |
| 75 | return $triggers; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Trigger listener |
| 80 | * |
| 81 | * @param object $obj Object. |
| 82 | * @param array $values Value. |
| 83 | * @param int $updated_id Updated ID. |
| 84 | * |
| 85 | * @return void |
| 86 | */ |
| 87 | public function trigger_listener( $obj, $values, $updated_id ) { |
| 88 | if ( 0 === absint( $updated_id ) ) { |
| 89 | return; |
| 90 | } |
| 91 | |
| 92 | unset( $values['account']['user_displayname'] ); |
| 93 | $context['user'] = $values; |
| 94 | $user_info = get_userdata( $updated_id ); |
| 95 | /** |
| 96 | * |
| 97 | * Ignore line |
| 98 | * |
| 99 | * @phpstan-ignore-next-line |
| 100 | */ |
| 101 | $context['user_account_user_displayname'] = $user_info->display_name; |
| 102 | |
| 103 | AutomationController::sure_trigger_handle_trigger( |
| 104 | [ |
| 105 | 'trigger' => $this->trigger, |
| 106 | 'wp_user_id' => $updated_id, |
| 107 | 'context' => $context, |
| 108 | ] |
| 109 | ); |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | UserUpdatesAccountInformation::get_instance(); |
| 114 |