← All changes
|
modules/logs/connectors/class-connector-client.php
+134
-144
5.0
→
6.2.1
View file →
| @@ -16,164 +16,154 @@ | ||
| 16 | 16 | * @package MainWP\Dashboard |
| 17 | 17 | */ |
| 18 | 18 | class Connector_Client extends Log_Connector { |
| 19 | 19 | |
| 20 | - /** | |
| 21 | - * Connector name. | |
| 22 | - * | |
| 23 | - * @var string Connector slug. | |
| 24 | - * */ | |
| 25 | - public $name = 'client'; | |
| 20 | + /** | |
| 21 | + * Connector name. | |
| 22 | + * | |
| 23 | + * @var string Connector slug. | |
| 24 | + * */ | |
| 25 | + public $name = 'client'; | |
| 26 | 26 | |
| 27 | 27 | |
| 28 | - /** | |
| 29 | - * Actions registered for this connector | |
| 30 | - * | |
| 31 | - * @var array | |
| 32 | - */ | |
| 33 | - public $actions = array( | |
| 34 | - 'mainwp_client_updated', | |
| 35 | - 'mainwp_client_deleted', | |
| 36 | - 'mainwp_client_suspend', | |
| 37 | - ); | |
| 28 | + /** | |
| 29 | + * Actions registered for this connector | |
| 30 | + * | |
| 31 | + * @var array | |
| 32 | + */ | |
| 33 | + public $actions = array( | |
| 34 | + 'mainwp_client_updated', | |
| 35 | + 'mainwp_client_deleted', | |
| 36 | + 'mainwp_client_suspend', | |
| 37 | + ); | |
| 38 | 38 | |
| 39 | - /** | |
| 40 | - * Return translated connector label | |
| 41 | - * | |
| 42 | - * @return string Translated connector label | |
| 43 | - */ | |
| 44 | - public function get_label() { | |
| 45 | - return esc_html__( 'Clients', 'mainwp' ); | |
| 46 | - } | |
| 39 | + /** | |
| 40 | + * Return translated connector label | |
| 41 | + * | |
| 42 | + * @return string Translated connector label | |
| 43 | + */ | |
| 44 | + public function get_label() { | |
| 45 | + return esc_html__( 'Clients', 'mainwp' ); | |
| 46 | + } | |
| 47 | 47 | |
| 48 | - /** | |
| 49 | - * Return translated action term labels | |
| 50 | - * | |
| 51 | - * @return array Action terms label translation | |
| 52 | - */ | |
| 53 | - public function get_action_labels() { | |
| 54 | - return array( | |
| 55 | - 'updated' => esc_html__( 'Updated', 'mainwp' ), | |
| 56 | - 'created' => esc_html__( 'Created', 'mainwp' ), | |
| 57 | - 'deleted' => esc_html__( 'Deleted', 'mainwp' ), | |
| 58 | - 'suspend' => esc_html__( 'Suspend', 'mainwp' ), | |
| 59 | - 'unsuspend' => esc_html__( 'Unsuspend', 'mainwp' ), | |
| 60 | - 'lead' => esc_html__( 'Lead', 'mainwp' ), | |
| 61 | - 'lost' => esc_html__( 'Lost', 'mainwp' ), | |
| 62 | - ); | |
| 63 | - } | |
| 48 | + /** | |
| 49 | + * Return translated action term labels | |
| 50 | + * | |
| 51 | + * @return array Action terms label translation | |
| 52 | + */ | |
| 53 | + public function get_action_labels() { | |
| 54 | + return array( | |
| 55 | + 'updated' => esc_html__( 'Updated', 'mainwp' ), | |
| 56 | + 'created' => esc_html__( 'Created', 'mainwp' ), | |
| 57 | + 'deleted' => esc_html__( 'Deleted', 'mainwp' ), | |
| 58 | + 'suspend' => esc_html__( 'Suspend', 'mainwp' ), | |
| 59 | + 'unsuspend' => esc_html__( 'Unsuspend', 'mainwp' ), | |
| 60 | + 'lead' => esc_html__( 'Lead', 'mainwp' ), | |
| 61 | + 'lost' => esc_html__( 'Lost', 'mainwp' ), | |
| 62 | + ); | |
| 63 | + } | |
| 64 | 64 | |
| 65 | - /** | |
| 66 | - * Return translated context labels | |
| 67 | - * | |
| 68 | - * @return array Context label translations | |
| 69 | - */ | |
| 70 | - public function get_context_labels() { | |
| 71 | - return array( | |
| 72 | - 'clients' => esc_html__( 'Clients', 'mainwp' ), | |
| 73 | - ); | |
| 74 | - } | |
| 65 | + /** | |
| 66 | + * Return translated context labels | |
| 67 | + * | |
| 68 | + * @return array Context label translations | |
| 69 | + */ | |
| 70 | + public function get_context_labels() { | |
| 71 | + return array( | |
| 72 | + 'clients' => esc_html__( 'Clients', 'mainwp' ), | |
| 73 | + ); | |
| 74 | + } | |
| 75 | 75 | |
| 76 | - /** | |
| 77 | - * Register log data. | |
| 78 | - */ | |
| 79 | - public function register() { //phpcs:ignore -- overrided. | |
| 80 | - parent::register(); | |
| 81 | - } | |
| 76 | + /** | |
| 77 | + * Log client update | |
| 78 | + * | |
| 79 | + * @action mainwp_client_updated | |
| 80 | + * | |
| 81 | + * @param object $client Client object. | |
| 82 | + * @param bool $created true add new, false updated. | |
| 83 | + */ | |
| 84 | + public function callback_mainwp_client_updated( $client, $created = false ) { | |
| 85 | + $action = $created ? 'created' : 'updated'; | |
| 86 | + $message = '%s'; | |
| 82 | 87 | |
| 83 | - /** | |
| 84 | - * Log client update | |
| 85 | - * | |
| 86 | - * @action mainwp_client_updated | |
| 87 | - * | |
| 88 | - * @param object $client Client object. | |
| 89 | - * @param bool $created true add new, false updated. | |
| 90 | - */ | |
| 91 | - public function callback_mainwp_client_updated( $client, $created = false ) { | |
| 92 | - $action = $created ? 'created' : 'updated'; | |
| 93 | - // translators: Placeholder refers to a client (e.g. "Jane Doe"). | |
| 94 | - $message = esc_html__( '%s', 'mainwp' ); | |
| 88 | + $state = 1; | |
| 89 | + $this->log( | |
| 90 | + $message, | |
| 91 | + array( | |
| 92 | + 'name' => $client->name, | |
| 93 | + 'client_id' => $client->client_id, | |
| 94 | + ), | |
| 95 | + 0, | |
| 96 | + 'clients', | |
| 97 | + $action, | |
| 98 | + $state | |
| 99 | + ); | |
| 100 | + } | |
| 95 | 101 | |
| 96 | - $state = 1; | |
| 97 | - $this->log( | |
| 98 | - $message, | |
| 99 | - array( | |
| 100 | - 'name' => $client->name, | |
| 101 | - 'client_id' => $client->client_id, | |
| 102 | - ), | |
| 103 | - 0, | |
| 104 | - 'clients', | |
| 105 | - $action, | |
| 106 | - $state | |
| 107 | - ); | |
| 108 | - } | |
| 102 | + /** | |
| 103 | + * Log client delete | |
| 104 | + * | |
| 105 | + * @action mainwp_client_deleted | |
| 106 | + * | |
| 107 | + * @param object $client Client deleted. | |
| 108 | + */ | |
| 109 | + public function callback_mainwp_client_deleted( $client ) { | |
| 110 | + $message = '%s'; | |
| 111 | + $state = 1; | |
| 112 | + $this->log( | |
| 113 | + $message, | |
| 114 | + array( | |
| 115 | + 'name' => $client->name, | |
| 116 | + 'client_id' => $client->client_id, | |
| 117 | + ), | |
| 118 | + 0, | |
| 119 | + 'clients', | |
| 120 | + 'deleted', | |
| 121 | + $state | |
| 122 | + ); | |
| 123 | + } | |
| 109 | 124 | |
| 110 | - /** | |
| 111 | - * Log client delete | |
| 112 | - * | |
| 113 | - * @action mainwp_client_deleted | |
| 114 | - * | |
| 115 | - * @param object $client Client deleted. | |
| 116 | - */ | |
| 117 | - public function callback_mainwp_client_deleted( $client ) { | |
| 118 | - // translators: Placeholder refers to a user display name (e.g. "Jane Doe"). | |
| 119 | - $message = esc_html__( '%s', 'mainwp' ); | |
| 120 | - $state = 1; | |
| 121 | - $this->log( | |
| 122 | - $message, | |
| 123 | - array( | |
| 124 | - 'name' => $client->name, | |
| 125 | - 'client_id' => $client->client_id, | |
| 126 | - ), | |
| 127 | - 0, | |
| 128 | - 'clients', | |
| 129 | - 'deleted', | |
| 130 | - $state | |
| 131 | - ); | |
| 132 | - } | |
| 125 | + /** | |
| 126 | + * Log client suspend/unsuspend. | |
| 127 | + * | |
| 128 | + * @action mainwp_client_suspend | |
| 129 | + * | |
| 130 | + * @param object $client Client deleted. | |
| 131 | + * @param bool $status client status. | |
| 132 | + */ | |
| 133 | + public function callback_mainwp_client_suspend( $client, $status ) { | |
| 133 | 134 | |
| 134 | - /** | |
| 135 | - * Log client suspend/unsuspend. | |
| 136 | - * | |
| 137 | - * @action mainwp_client_suspend | |
| 138 | - * | |
| 139 | - * @param object $client Client deleted. | |
| 140 | - * @param bool $status client status. | |
| 141 | - */ | |
| 142 | - public function callback_mainwp_client_suspend( $client, $status ) { | |
| 135 | + if ( ! is_object( $client ) ) { | |
| 136 | + return; | |
| 137 | + } | |
| 143 | 138 | |
| 144 | - if ( ! is_object( $client ) ) { | |
| 145 | - return; | |
| 146 | - } | |
| 139 | + $status = intval( $status ); | |
| 147 | 140 | |
| 148 | - $status = intval( $status ); | |
| 141 | + $action = 'unsuspend'; | |
| 149 | 142 | |
| 150 | - $action = 'unsuspend'; | |
| 143 | + if ( 0 === $status ) { | |
| 144 | + $action = 'unsuspend'; | |
| 145 | + } elseif ( 1 === $status ) { | |
| 146 | + $action = 'suspend'; // actived. | |
| 147 | + } elseif ( 2 === $status ) { | |
| 148 | + $action = 'lead'; | |
| 149 | + } elseif ( 3 === $status ) { | |
| 150 | + $action = 'lost'; | |
| 151 | + } | |
| 151 | 152 | |
| 152 | - if ( 0 === $status ) { | |
| 153 | - $action = 'unsuspend'; | |
| 154 | - } elseif ( 1 === $status ) { | |
| 155 | - $action = 'suspend'; // actived. | |
| 156 | - } elseif ( 2 === $status ) { | |
| 157 | - $action = 'lead'; | |
| 158 | - } elseif ( 3 === $status ) { | |
| 159 | - $action = 'lost'; | |
| 160 | - } | |
| 153 | + $message = '%s'; | |
| 161 | 154 | |
| 162 | - // translators: Placeholder refers to a client name (e.g. "Jane Doe"). | |
| 163 | - $message = esc_html__( '%s', 'mainwp' ); | |
| 164 | - | |
| 165 | - $state = 1; | |
| 166 | - $this->log( | |
| 167 | - $message, | |
| 168 | - array( | |
| 169 | - 'name' => $client->name, | |
| 170 | - 'client_id' => $client->client_id, | |
| 171 | - 'suspend_value' => $status, | |
| 172 | - ), | |
| 173 | - 0, | |
| 174 | - 'clients', | |
| 175 | - $action, | |
| 176 | - $state | |
| 177 | - ); | |
| 178 | - } | |
| 155 | + $state = 1; | |
| 156 | + $this->log( | |
| 157 | + $message, | |
| 158 | + array( | |
| 159 | + 'name' => $client->name, | |
| 160 | + 'client_id' => $client->client_id, | |
| 161 | + 'suspend_value' => $status, | |
| 162 | + ), | |
| 163 | + 0, | |
| 164 | + 'clients', | |
| 165 | + $action, | |
| 166 | + $state | |
| 167 | + ); | |
| 168 | + } | |
| 179 | 169 | } |