PluginProbe
Activity Logs, User Activity Tracking, Multisite Activity Log from Logtivity / 3.3.10
Activity Logs, User Activity Tracking, Multisite Activity Log from Logtivity v3.3.10
3.3.10 3.3.9 3.3.8 trunk 1.0 1.1.0 1.10.0 1.11.0 1.11.1 1.12.0 1.13.0 1.14.0 1.15.0 1.16.0 1.17.0 1.17.1 1.18.0 1.19.0 1.2.0 1.20.0 1.20.1 1.3.0 1.3.1 1.4.0 1.5.0 All 68 releases
logtivity / Loggers / Memberpress / Logtivity_Memberpress.php

Logtivity_Memberpress.php in Activity Logs, User Activity Tracking, Multisite Activity Log from Logtivity 3.3.10, at Loggers/Memberpress/Logtivity_Memberpress.php

208 lines 6.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * @package Logtivity
5 * @contact logtivity.io, [email protected]
6 * @copyright 2024-2026 Logtivity. All rights reserved
7 * @license https://www.gnu.org/licenses/gpl.html GNU/GPL
8 *
9 * This file is part of Logtivity.
10 *
11 * Logtivity is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * Logtivity is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with Logtivity. If not, see <https://www.gnu.org/licenses/>.
23 */
24
25 class Logtivity_Memberpress extends Logtivity_Abstract_Logger
26 {
27 public function freeSubscriptionCreated($event): void
28 {
29 $user = $event->get_data();
30 $subscription = $this->getSubscription($user);
31
32 if ($subscription && $subscription->gateway == 'free') {
33 $product = $subscription->product();
34
35 Logtivity::log(
36 'Free Subscription Created',
37 [
38 'Subscription ID' => $subscription->id,
39 ]
40 )
41 ->setContext($product->post_title)
42 ->send();
43 }
44 }
45
46 protected function getSubscription($user)
47 {
48 foreach ($user->subscriptions() as $subscription) {
49 return $subscription;
50 }
51
52 return null;
53 }
54
55 /**
56 * @param $event
57 *
58 * @return void
59 */
60 public function subscriptionCreated($event): void
61 {
62 $subscription = $event->get_data();
63 $user = $subscription->user();
64 $product = $subscription->product();
65 $paymentMethod = $subscription->payment_method();
66
67 Logtivity::log(
68 'Subscription Created',
69 [
70 'Transaction Total' => $subscription->total,
71 'Payment Method' => $paymentMethod->name,
72 'Subscription ID' => $subscription->id,
73 ],
74 $user->ID
75 )
76 ->setContext($product->post_title)
77 ->send();
78 }
79
80 public function subscriptionPaused($event)
81 {
82 $subscription = $event->get_data();
83 $product = $subscription->product();
84
85 Logtivity::log()
86 ->setAction('Subscription Paused')
87 ->setContext($product->post_title)
88 ->addMeta('Subscription ID', $subscription->id)
89 ->send();
90 }
91
92 public function subscriptionResumed($event)
93 {
94 $subscription = $event->get_data();
95 $product = $subscription->product();
96
97 Logtivity::log()
98 ->setAction('Subscription Resumed')
99 ->setContext($product->post_title)
100 ->addMeta('Subscription ID', $subscription->id)
101 ->send();
102 }
103
104 public function subscriptionStopped($event)
105 {
106 $subscription = $event->get_data();
107 $product = $subscription->product();
108
109 Logtivity::log()
110 ->setAction('Subscription Stopped')
111 ->setContext($product->post_title)
112 ->addMeta('Subscription ID', $subscription->id)
113 ->send();
114 }
115
116 public function profileUpdated()
117 {
118 $processAccount = isset($_POST['mepr-process-account'])
119 ? sanitize_text_field(wp_unslash($_POST['mepr-process-account']))
120 : '';
121 $nonce = isset($_POST['mepr_account_nonce'])
122 ? sanitize_text_field(wp_unslash($_POST['mepr_account_nonce']))
123 : '';
124
125 if (
126 MeprUtils::is_post_request()
127 && $processAccount == 'Y'
128 && wp_verify_nonce($nonce, 'update_account')
129 ) {
130 $user = new Logtivity_Wp_User();
131
132 Logtivity::log()
133 ->setAction('Profile Updated')
134 ->setContext($user->getRole())
135 ->send();
136 }
137 }
138
139 public function transactionCreated($rowId, $args, $user_id)
140 {
141 (new Logtivity_Logger($user_id))
142 ->setAction('Transaction Created')
143 ->setContext($args['status'])
144 ->addMeta('Total', $args['total'])
145 ->addMeta('Transaction ID', $rowId)
146 ->addMeta('Transaction Type', $args['txn_type'])
147 ->addMeta('Subscription ID', $args['subscription_id'])
148 ->addMeta('Product ID', $args['product_id'])
149 ->send();
150
151 return $rowId;
152 }
153
154 public function transactionUpdated($rowId, $args, $user_id)
155 {
156 $log = (new Logtivity_Logger($user_id))
157 ->setAction('Transaction Updated')
158 ->setContext($args['status']);
159
160 if ($args['total'] != '0') {
161 $log->addMeta('Total', $args['total']);
162 }
163
164 $log->addMeta('Transaction ID', $args['id'])
165 ->addMeta('Transaction Type', $args['txn_type'])
166 ->addMeta('Subscription ID', $args['subscription_id'])
167 ->addMeta('Product ID', $args['product_id'])
168 ->send();
169
170 return $rowId;
171 }
172
173 public function emailSent($MeprBaseEmail, $values, $attachments)
174 {
175 (new Logtivity_Logger())
176 ->setAction(strip_tags($MeprBaseEmail->title) . ' Sent')
177 ->setContext($MeprBaseEmail->to)
178 ->send();
179 }
180
181 public function settingsUpdated($postData)
182 {
183 Logtivity::log()
184 ->setAction('Settings Updated')
185 ->setContext('Memberpress')
186 ->send();
187 }
188
189 /**
190 * @inheritDoc
191 */
192 protected function registerHooks(): void
193 {
194 add_action('mepr-event-member-signup-completed', [$this, 'freeSubscriptionCreated']);
195 add_action('mepr-event-subscription-created', [$this, 'subscriptionCreated']);
196 add_action('mepr-event-subscription-paused', [$this, 'subscriptionPaused']);
197 add_action('mepr-event-subscription-resumed', [$this, 'subscriptionResumed']);
198 add_action('mepr-event-subscription-stopped', [$this, 'subscriptionStopped']);
199 add_action('init', [$this, 'profileUpdated']);
200 add_filter('mepr_create_transaction', [$this, 'transactionCreated'], 10, 3);
201 add_filter('mepr_update_transaction', [$this, 'transactionUpdated'], 10, 3);
202 add_action('mepr_email_sent', [$this, 'emailSent'], 10, 3);
203 add_action('mepr-process-options', [$this, 'settingsUpdated'], 10, 1);
204 }
205 }
206
207 new Logtivity_Memberpress();
208