PluginProbe
Activity Logs, User Activity Tracking, Multisite Activity Log from Logtivity / trunk
Activity Logs, User Activity Tracking, Multisite Activity Log from Logtivity vtrunk
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 1.6.0 1.6.1 All 66 releases
logtivity / Loggers / Memberpress / Logtivity_Memberpress.php

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

201 lines 6.3 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, hello@logtivity.io
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 if (
119 MeprUtils::is_post_request()
120 && sanitize_text_field($_POST['mepr-process-account'] ?? null) == 'Y'
121 && wp_verify_nonce(sanitize_text_field($_POST['mepr_account_nonce'] ?? null), 'update_account')
122 ) {
123 $user = new Logtivity_Wp_User();
124
125 Logtivity::log()
126 ->setAction('Profile Updated')
127 ->setContext($user->getRole())
128 ->send();
129 }
130 }
131
132 public function transactionCreated($rowId, $args, $user_id)
133 {
134 (new Logtivity_Logger($user_id))
135 ->setAction('Transaction Created')
136 ->setContext($args['status'])
137 ->addMeta('Total', $args['total'])
138 ->addMeta('Transaction ID', $rowId)
139 ->addMeta('Transaction Type', $args['txn_type'])
140 ->addMeta('Subscription ID', $args['subscription_id'])
141 ->addMeta('Product ID', $args['product_id'])
142 ->send();
143
144 return $rowId;
145 }
146
147 public function transactionUpdated($rowId, $args, $user_id)
148 {
149 $log = (new Logtivity_Logger($user_id))
150 ->setAction('Transaction Updated')
151 ->setContext($args['status']);
152
153 if ($args['total'] != '0') {
154 $log->addMeta('Total', $args['total']);
155 }
156
157 $log->addMeta('Transaction ID', $args['id'])
158 ->addMeta('Transaction Type', $args['txn_type'])
159 ->addMeta('Subscription ID', $args['subscription_id'])
160 ->addMeta('Product ID', $args['product_id'])
161 ->send();
162
163 return $rowId;
164 }
165
166 public function emailSent($MeprBaseEmail, $values, $attachments)
167 {
168 (new Logtivity_Logger())
169 ->setAction(strip_tags($MeprBaseEmail->title) . ' Sent')
170 ->setContext($MeprBaseEmail->to)
171 ->send();
172 }
173
174 public function settingsUpdated($postData)
175 {
176 Logtivity::log()
177 ->setAction('Settings Updated')
178 ->setContext('Memberpress')
179 ->send();
180 }
181
182 /**
183 * @inheritDoc
184 */
185 protected function registerHooks(): void
186 {
187 add_action('mepr-event-member-signup-completed', [$this, 'freeSubscriptionCreated']);
188 add_action('mepr-event-subscription-created', [$this, 'subscriptionCreated']);
189 add_action('mepr-event-subscription-paused', [$this, 'subscriptionPaused']);
190 add_action('mepr-event-subscription-resumed', [$this, 'subscriptionResumed']);
191 add_action('mepr-event-subscription-stopped', [$this, 'subscriptionStopped']);
192 add_action('init', [$this, 'profileUpdated']);
193 add_filter('mepr_create_transaction', [$this, 'transactionCreated'], 10, 3);
194 add_filter('mepr_update_transaction', [$this, 'transactionUpdated'], 10, 3);
195 add_action('mepr_email_sent', [$this, 'emailSent'], 10, 3);
196 add_action('mepr-process-options', [$this, 'settingsUpdated'], 10, 1);
197 }
198 }
199
200 new Logtivity_Memberpress();
201