Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/paid-memberships-pro/includes/abandoned-signups.php
Keine Baseline-Datei – Diff nur gegen leer.
1
-
1
+
<?php
2
+
3
+
/**
4
+
* Set up a user taxonomy to track users who were created during the PMPro
5
+
* checkout process but did not complete the checkout.
6
+
*
7
+
* @since 2.11
8
+
*/
9
+
function pmpro_abandoned_signups_taxonomy() {
10
+
// Register the taxonomy.
11
+
register_taxonomy(
12
+
'pmpro_abandoned_signup',
13
+
'user',
14
+
array(
15
+
'public' => false,
16
+
'default_term' => array(
17
+
'slug' => 'abandoned-signup',
18
+
),
19
+
)
20
+
);
21
+
}
22
+
add_action( 'init', 'pmpro_abandoned_signups_taxonomy', 1 );
23
+
24
+
/**
25
+
* Add the abandoned signup taxonomy to the user object when they are created during
26
+
* the PMPro checkout process.
27
+
*
28
+
* @since 2.11
29
+
*
30
+
* @param int $user_id The user ID.
31
+
*/
32
+
function pmpro_set_abandoned_signup_taxonomy( $user_id ) {
33
+
// Bail if the user ID is empty.
34
+
if ( empty( $user_id ) ) {
35
+
return;
36
+
}
37
+
38
+
// Add the abandoned signup taxonomy to the user.
39
+
wp_set_object_terms( $user_id, 'abandoned-signup', 'pmpro_abandoned_signup' );
40
+
}
41
+
add_action( 'pmpro_checkout_before_user_auth', 'pmpro_set_abandoned_signup_taxonomy', 10 );
42
+
43
+
/**
44
+
* After a checkout is complete, remove the abandoned signup taxonomy from the user.
45
+
*
46
+
* @since 2.11
47
+
*
48
+
* @param int $user_id The user ID.
49
+
*/
50
+
function pmpro_remove_abandoned_signup_taxonomy( $user_id ) {
51
+
// Bail if the user ID is empty.
52
+
if ( empty( $user_id ) ) {
53
+
return;
54
+
}
55
+
56
+
// Bail if the user doesn't have the adbandoned signup taxonomy.
57
+
if ( ! is_object_in_term( $user_id, 'pmpro_abandoned_signup', 'abandoned-signup' ) ) {
58
+
return;
59
+
}
60
+
61
+
// Remove the abandoned signup taxonomy from the user.
62
+
wp_remove_object_terms( $user_id, 'abandoned-signup', 'pmpro_abandoned_signup' );
63
+
}
64
+
add_action( 'pmpro_after_checkout', 'pmpro_remove_abandoned_signup_taxonomy' );
65
+
add_action( 'deleted_user', 'pmpro_remove_abandoned_signup_taxonomy' );
66
+
67
+
/**
68
+
* If a user loads any non-checkout page after their account is created
69
+
* during the checkout process, remove the abandoned signup taxonomy from
70
+
* the user.
71
+
*
72
+
* @since 2.11
73
+
*/
74
+
function pmpro_remove_abandoned_signup_taxonomy_on_page_load() {
75
+
$user_id = get_current_user_id();
76
+
77
+
// Bail if the user ID is empty.
78
+
if ( empty( $user_id ) ) {
79
+
return;
80
+
}
81
+
82
+
// Bail if the user is on the checkout page.
83
+
if ( pmpro_is_checkout() ) {
84
+
return;
85
+
}
86
+
87
+
// Remove the abandoned signup taxonomy from the user.
88
+
pmpro_remove_abandoned_signup_taxonomy( $user_id );
89
+
}
90
+
add_action( 'wp', 'pmpro_remove_abandoned_signup_taxonomy_on_page_load' );
91
+
92
+
/**
93
+
* Filter the views on the Users page to include a view for abandoned signups.
94
+
*
95
+
* @since 2.11
96
+
*
97
+
* @param array $views The views on the Users page.
98
+
*/
99
+
function pmpro_add_users_table_view_abandoned_signups( $views ) {
100
+
// Get the ID for the 'abandoned-signup' term.
101
+
$abandoned_signup_term = get_term_by( 'slug', 'abandoned-signup', 'pmpro_abandoned_signup' );
102
+
if ( empty( $abandoned_signup_term ) ) {
103
+
return $views;
104
+
}
105
+
106
+
// Get all users with the 'abandoned-signup' term.
107
+
$abandoned_signup_users = get_objects_in_term( $abandoned_signup_term->term_id, 'pmpro_abandoned_signup' );
108
+
109
+
// If there are no users with the 'abandoned-signup' term, bail.
110
+
if ( empty( $abandoned_signup_users ) ) {
111
+
return $views;
112
+
}
113
+
114
+
// Add the view for abandoned signups.
115
+
$views['pmpro-abandoned-signups'] = sprintf(
116
+
'<a href="%s"%s>%s <span class="count">(%d)</span></a>',
117
+
esc_url( add_query_arg( 'pmpro-abandoned-signups', '1', admin_url( 'users.php' ) ) ),
118
+
empty( $_REQUEST['pmpro-abandoned-signups'] ) ? '' : ' class="current"',
119
+
__( 'Potential Spam Checkouts', 'paid-memberships-pro' ),
120
+
count( $abandoned_signup_users )
121
+
);
122
+
123
+
return $views;
124
+
}
125
+
add_filter( 'views_users', 'pmpro_add_users_table_view_abandoned_signups' );
126
+
127
+
/**
128
+
* If the users table is being filtered by abandoned signups, add the user registered
129
+
* column to the table.
130
+
*
131
+
* @since 2.11
132
+
*
133
+
* @param array $columns The columns in the users table.
134
+
* @return array The updated columns in the users table.
135
+
*/
136
+
function pmpro_add_users_table_user_registered_column( $columns ) {
137
+
// Bail if we are not on the Users page or not filtering by abandoned signups.
138
+
if ( empty( $_REQUEST['pmpro-abandoned-signups'] ) ) {
139
+
return $columns;
140
+
}
141
+
142
+
// Add the registered column to the users table.
143
+
$columns['user_registered'] = __( 'Registered', 'paid-memberships-pro' );
144
+
return $columns;
145
+
}
146
+
add_filter( 'manage_users_columns', 'pmpro_add_users_table_user_registered_column' );
147
+
148
+
/**
149
+
* Make the registered column sortable.
150
+
*/
151
+
function pmpro_make_users_table_user_registered_column_sortable( $columns ) {
152
+
// Bail if we are not on the Users page or not filtering by abandoned signups.
153
+
if ( empty( $_REQUEST['pmpro-abandoned-signups'] ) ) {
154
+
return $columns;
155
+
}
156
+
157
+
// Make the registered column sortable.
158
+
$columns['user_registered'] = 'user_registered';
159
+
return $columns;
160
+
}
161
+
add_filter( 'manage_users_sortable_columns', 'pmpro_make_users_table_user_registered_column_sortable' );
162
+
163
+
/**
164
+
* Output the registered column for abandoned signups.
165
+
*
166
+
* @since 2.11
167
+
*
168
+
* @param string $output The output for the registered column.
169
+
* @param string $column_name The name of the column.
170
+
* @param int $user_id The user ID.
171
+
* @return string The updated output for the registered column.
172
+
*/
173
+
function pmpro_add_users_table_user_registered_column_output( $output, $column_name, $user_id ) {
174
+
// Bail if we are not on the Users page or not filtering by abandoned signups.
175
+
if ( empty( $_REQUEST['pmpro-abandoned-signups'] ) ) {
176
+
return $output;
177
+
}
178
+
179
+
// Bail if we are not on the registered column.
180
+
if ( 'user_registered' !== $column_name ) {
181
+
return $output;
182
+
}
183
+
184
+
// Get the user.
185
+
$user = get_userdata( $user_id );
186
+
187
+
// Get the registered date.
188
+
$registered_date = date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), strtotime( $user->user_registered ) );
189
+
190
+
// Update the output for the registered column.
191
+
$output = $registered_date;
192
+
return $output;
193
+
}
194
+
add_filter( 'manage_users_custom_column', 'pmpro_add_users_table_user_registered_column_output', 10, 3 );
195
+
196
+
/**
197
+
* Filter the users list table query args to only include users with the
198
+
* 'abandoned-signup' term if the 'pmpro-abandoned-signups' query arg is set.
199
+
*
200
+
* @since 2.11
201
+
*
202
+
* @param array $query_args The query args for the users list table.
203
+
* @return array The updated query args for the users list table.
204
+
*/
205
+
function pmpro_abandoned_signups_users_list_table_query_args( $query_args ) {
206
+
// Bail if we are not on the Users page or not filtering by abandoned signups.
207
+
if ( empty( $_REQUEST['pmpro-abandoned-signups'] ) ) {
208
+
return $query_args;
209
+
}
210
+
211
+
// Remove the role query arg so that we are querying all users.
212
+
unset( $query_args['role'] );
213
+
214
+
// Get the ID for the 'abandoned-signup' term.
215
+
$abandoned_signup_term = get_term_by( 'slug', 'abandoned-signup', 'pmpro_abandoned_signup' );
216
+
if ( empty( $abandoned_signup_term ) ) {
217
+
return $query_args;
218
+
}
219
+
220
+
// Get all users with the 'abandoned-signup' term.
221
+
$abandoned_signup_users = get_objects_in_term( $abandoned_signup_term->term_id, 'pmpro_abandoned_signup' );
222
+
223
+
// Update the user query to only include users with the 'abandoned-signup' term.
224
+
$query_args['include'] = $abandoned_signup_users;
225
+
226
+
return $query_args;
227
+
}
228
+
add_action( 'users_list_table_query_args', 'pmpro_abandoned_signups_users_list_table_query_args' );
229
+
230
+
/**
231
+
* Show a description on the Users page when filtering by abandoned signups.
232
+
*
233
+
* @since 2.11
234
+
*/
235
+
function pmpro_abandoned_signups_users_list_table_description() {
236
+
global $current_screen;
237
+
238
+
// Bail if we are not on the Users page or not filtering by abandoned signups.
239
+
if ( ! is_admin() || empty( $current_screen->id ) || 'users' !== $current_screen->id || empty( $_REQUEST['pmpro-abandoned-signups'] ) ) {
240
+
return;
241
+
}
242
+
243
+
// Get the ID for the 'abandoned-signup' term.
244
+
$abandoned_signup_term = get_term_by( 'slug', 'abandoned-signup', 'pmpro_abandoned_signup' );
245
+
if ( empty( $abandoned_signup_term ) ) {
246
+
return;
247
+
}
248
+
249
+
// Get all users with the 'abandoned-signup' term.
250
+
$abandoned_signup_users = get_objects_in_term( $abandoned_signup_term->term_id, 'pmpro_abandoned_signup' );
251
+
252
+
// Bail if there are no users with the 'abandoned-signup' term.
253
+
if ( empty( $abandoned_signup_users ) ) {
254
+
return;
255
+
}
256
+
257
+
// Use JavaScript to add the description box to the users table.
258
+
?>
259
+
<script>
260
+
jQuery( document ).ready( function( $ ) {
261
+
$( '.tablenav.top' ).after( '<div class="pmpro-abandoned-signup-description"><p><?php esc_html_e( "These are users who were created during the Paid Memberships Pro checkout process but haven't yet completed checkout or performed any other action on your site. You should periodically delete users from this list if the Registered date is more than a few days old.", 'paid-memberships-pro' ); ?></p></div>' );
262
+
} );
263
+
</script>
264
+
<?php
265
+
}
266
+
add_action( 'admin_head', 'pmpro_abandoned_signups_users_list_table_description' );
267
+