Ultimate Member – User Profile & Membership Plugin - Version 2.5.1

Version Description

Download this release

Release Info

Developer nsinelnikov
Plugin Icon 128x128 Ultimate Member – User Profile & Membership Plugin
Version 2.5.1
Comparing to
See all releases

Code changes from version 2.5.0 to 2.5.1

includes/admin/core/class-admin-builder.php CHANGED
@@ -1,1232 +1,1236 @@
1
- <?php
2
- namespace um\admin\core;
3
-
4
-
5
- if ( ! defined( 'ABSPATH' ) ) exit;
6
-
7
-
8
- if ( ! class_exists( 'um\admin\core\Admin_Builder' ) ) {
9
-
10
-
11
- /**
12
- * Class Admin_Builder
13
- * @package um\admin\core
14
- */
15
- class Admin_Builder {
16
-
17
-
18
- /**
19
- * @var
20
- */
21
- var $form_id;
22
-
23
-
24
- /**
25
- * Admin_Builder constructor.
26
- */
27
- function __construct() {
28
- add_action( 'um_admin_field_modal_header', array( &$this, 'add_message_handlers' ) );
29
- add_action( 'um_admin_field_modal_footer', array( &$this, 'add_conditional_support' ), 10, 4 );
30
- add_filter( 'um_admin_builder_skip_field_validation', array( &$this, 'skip_field_validation' ), 10, 3 );
31
- add_filter( 'um_admin_pre_save_field_to_form', array( &$this, 'um_admin_pre_save_field_to_form' ), 1 );
32
- add_filter( 'um_admin_pre_save_fields_hook', array( &$this, 'um_admin_pre_save_fields_hook' ), 1 );
33
- add_filter( 'um_admin_field_update_error_handling', array( &$this, 'um_admin_field_update_error_handling' ), 1, 2 );
34
- }
35
-
36
-
37
- /**
38
- * Apply a filter to handle errors for field updating in backend
39
- *
40
- * @param $errors
41
- * @param $array
42
- *
43
- * @return mixed
44
- */
45
- function um_admin_field_update_error_handling( $errors, $array ) {
46
- /**
47
- * @var $field_type
48
- */
49
- extract( $array );
50
-
51
- $field_attr = UM()->builtin()->get_core_field_attrs( $field_type );
52
-
53
- if ( isset( $field_attr['validate'] ) ) {
54
-
55
- $validate = $field_attr['validate'];
56
- foreach ( $validate as $post_input => $arr ) {
57
-
58
- $skip = apply_filters( 'um_admin_builder_skip_field_validation', false, $post_input, $array );
59
- if ( $skip ) {
60
- continue;
61
- }
62
-
63
- $mode = $arr['mode'];
64
-
65
- switch ( $mode ) {
66
-
67
- case 'numeric':
68
- if ( ! empty( $array['post'][ $post_input ] ) && ! is_numeric( $array['post'][ $post_input ] ) ){
69
- $errors[ $post_input ] = $validate[ $post_input ]['error'];
70
- }
71
- break;
72
-
73
- case 'unique':
74
- if ( ! isset( $array['post']['edit_mode'] ) ) {
75
- if ( UM()->builtin()->unique_field_err( $array['post'][ $post_input ] ) ) {
76
- $errors[ $post_input ] = UM()->builtin()->unique_field_err( $array['post'][ $post_input ] );
77
- }
78
- }
79
- break;
80
-
81
- case 'required':
82
- if ( $array['post'][ $post_input ] == '' ) {
83
- $errors[ $post_input ] = $validate[ $post_input ]['error'];
84
- }
85
- break;
86
-
87
- case 'range-start':
88
- if ( UM()->builtin()->date_range_start_err( $array['post'][ $post_input ] ) && $array['post']['_range'] == 'date_range' ) {
89
- $errors[ $post_input ] = UM()->builtin()->date_range_start_err( $array['post'][ $post_input ] );
90
- }
91
- break;
92
-
93
- case 'range-end':
94
- if ( UM()->builtin()->date_range_end_err( $array['post'][ $post_input ], $array['post']['_range_start'] ) && $array['post']['_range'] == 'date_range' ) {
95
- $errors[ $post_input ] = UM()->builtin()->date_range_end_err( $array['post'][ $post_input ], $array['post']['_range_start'] );
96
- }
97
- break;
98
-
99
- }
100
-
101
- }
102
-
103
- }
104
-
105
- return $errors;
106
-
107
- }
108
-
109
-
110
- /**
111
- * Some fields may require extra fields before saving
112
- *
113
- * @param $array
114
- *
115
- * @return mixed
116
- */
117
- function um_admin_pre_save_fields_hook( $array ) {
118
- /**
119
- * @var $form_id
120
- * @var $field_type
121
- */
122
- extract( $array );
123
-
124
- $fields_without_metakey = UM()->builtin()->get_fields_without_metakey();
125
-
126
- $fields = UM()->query()->get_attr( 'custom_fields', $form_id );
127
- $count = 1;
128
- if ( ! empty( $fields ) ) {
129
- $count = count( $fields ) + 1;
130
- }
131
-
132
- // set unique meta key
133
- if ( in_array( $field_type, $fields_without_metakey ) && ! isset( $array['post']['_metakey'] ) ) {
134
- $array['post']['_metakey'] = "um_{$field_type}_{$form_id}_{$count}";
135
- }
136
-
137
- // set position
138
- if ( ! isset( $array['post']['_position'] ) ) {
139
- $array['post']['_position'] = $count;
140
- }
141
-
142
- return $array;
143
- }
144
-
145
-
146
- /**
147
- * Modify field args just before it is saved into form
148
- *
149
- * @param $array
150
- *
151
- * @return mixed
152
- */
153
- function um_admin_pre_save_field_to_form( $array ){
154
- unset( $array['conditions'] );
155
- if ( isset($array['conditional_field']) && ! empty( $array['conditional_action'] ) && ! empty( $array['conditional_operator'] ) ) {
156
- $array['conditional_value'] = isset( $array['conditional_value'] ) ? $array['conditional_value'] : '';
157
- $array['conditions'][] = array( $array['conditional_action'], $array['conditional_field'], $array['conditional_operator'], $array['conditional_value'] );
158
- }
159
-
160
- if ( isset( $array['conditional_field1'] ) && ! empty( $array['conditional_action1'] ) && ! empty( $array['conditional_operator1'] ) ) {
161
- $array['conditional_value1'] = isset( $array['conditional_value1'] ) ? $array['conditional_value1'] : '';
162
- $array['conditions'][] = array( $array['conditional_action1'], $array['conditional_field1'], $array['conditional_operator1'], $array['conditional_value1'] );
163
- }
164
-
165
- if ( isset( $array['conditional_field2'] ) && ! empty( $array['conditional_action2'] ) && ! empty( $array['conditional_operator2'] ) ) {
166
- $array['conditional_value2'] = isset( $array['conditional_value2'] ) ? $array['conditional_value2'] : '';
167
- $array['conditions'][] = array( $array['conditional_action2'], $array['conditional_field2'], $array['conditional_operator2'], $array['conditional_value2'] );
168
- }
169
-
170
- if ( isset( $array['conditional_field3'] ) && ! empty( $array['conditional_action3'] ) && ! empty( $array['conditional_operator3'] ) ) {
171
- $array['conditional_value3'] = isset( $array['conditional_value3'] ) ? $array['conditional_value3'] : '';
172
- $array['conditions'][] = array( $array['conditional_action3'], $array['conditional_field3'], $array['conditional_operator3'], $array['conditional_value3'] );
173
- }
174
-
175
- if ( isset( $array['conditional_field4'] ) && ! empty( $array['conditional_action4'] ) && ! empty( $array['conditional_operator4'] ) ) {
176
- $array['conditional_value4'] = isset( $array['conditional_value4'] ) ? $array['conditional_value4'] : '';
177
- $array['conditions'][] = array( $array['conditional_action4'], $array['conditional_field4'], $array['conditional_operator4'], $array['conditional_value4'] );
178
- }
179
-
180
- return $array;
181
- }
182
-
183
-
184
- /**
185
- * Put status handler in modal
186
- */
187
- function add_message_handlers() {
188
- ?>
189
- <div class="um-admin-error-block"></div>
190
- <div class="um-admin-success-block"></div>
191
- <?php
192
- }
193
-
194
-
195
- /**
196
- * Footer of modal
197
- *
198
- * @param $form_id
199
- * @param $field_args
200
- * @param $in_edit
201
- * @param $edit_array
202
- */
203
- function add_conditional_support( $form_id, $field_args, $in_edit, $edit_array ) {
204
- $metabox = UM()->metabox();
205
-
206
- if ( isset( $field_args['conditional_support'] ) && $field_args['conditional_support'] == 0 ) {
207
- return;
208
- } ?>
209
-
210
- <div class="um-admin-btn-toggle">
211
-
212
- <?php if ( $in_edit ) { $metabox->in_edit = true; $metabox->edit_array = $edit_array; ?>
213
- <a href="javascript:void(0);"><i class="um-icon-plus"></i><?php _e( 'Manage conditional fields support' ); ?></a> <?php UM()->tooltip( __( 'Here you can setup conditional logic to show/hide this field based on specific fields value or conditions', 'ultimate-member' ) ); ?>
214
- <?php } else { ?>
215
- <a href="javascript:void(0);"><i class="um-icon-plus"></i><?php _e( 'Add conditional fields support' ); ?></a> <?php UM()->tooltip( __( 'Here you can setup conditional logic to show/hide this field based on specific fields value or conditions', 'ultimate-member' ) ); ?>
216
- <?php } ?>
217
-
218
- <div class="um-admin-btn-content">
219
- <div class="um-admin-cur-condition-template">
220
-
221
- <?php $metabox->field_input( '_conditional_action', $form_id ); ?>
222
- <?php $metabox->field_input( '_conditional_field', $form_id ); ?>
223
- <?php $metabox->field_input( '_conditional_operator', $form_id ); ?>
224
- <?php $metabox->field_input( '_conditional_value', $form_id ); ?>
225
-
226
- <p><a href="javascript:void(0);" class="um-admin-remove-condition button um-admin-tipsy-n" title="Remove condition"><i class="um-icon-close" style="margin-right:0!important"></i></a></p>
227
-
228
- <div class="um-admin-clear"></div>
229
- </div>
230
- <p class="um-admin-conditions-notice">
231
- <small>
232
- <?php _e( 'Use the condition operator `equals to` or `not equals` if the parent field has a single option.', 'ultimate-member' ); ?>
233
- <br><?php _e( 'Use the condition operator `greater than` or `less than` if the parent field is a number.', 'ultimate-member' ); ?>
234
- <br><?php _e( 'Use the condition operator `contains` if the parent field has multiple options.', 'ultimate-member' ); ?>
235
- </small>
236
- </p>
237
- <p><a href="javascript:void(0);" class="um-admin-new-condition button button-primary um-admin-tipsy-n" title="Add new condition"><?php _e( 'Add new rule', 'ultimate-member' ); ?></a></p>
238
- <p class="um-admin-reset-conditions"><a href="javascript:void(0);" class="button"><?php _e( 'Reset all rules', 'ultimate-member' ); ?></a></p>
239
-
240
- <div class="um-admin-clear"></div>
241
-
242
- <?php if ( isset( $edit_array['conditions'] ) && count( $edit_array['conditions'] ) != 0 ) {
243
-
244
- foreach ( $edit_array['conditions'] as $k => $arr ) {
245
-
246
- if ( $k == 0 ) $k = ''; ?>
247
-
248
- <div class="um-admin-cur-condition">
249
-
250
- <?php $metabox->field_input( '_conditional_action' . $k, $form_id ); ?>
251
- <?php $metabox->field_input( '_conditional_field' . $k , $form_id ); ?>
252
- <?php $metabox->field_input( '_conditional_operator' . $k, $form_id ); ?>
253
- <?php $metabox->field_input( '_conditional_value' . $k, $form_id ); ?>
254
-
255
- <p><a href="#" class="um-admin-remove-condition button um-admin-tipsy-n" title="Remove condition"><i class="um-icon-close" style="margin-right:0!important"></i></a></p>
256
-
257
- <div class="um-admin-clear"></div>
258
- </div>
259
-
260
- <?php
261
- }
262
-
263
- } else { ?>
264
-
265
- <div class="um-admin-cur-condition">
266
-
267
- <?php $metabox->field_input( '_conditional_action', $form_id ); ?>
268
- <?php $metabox->field_input( '_conditional_field', $form_id ); ?>
269
- <?php $metabox->field_input( '_conditional_operator', $form_id ); ?>
270
- <?php $metabox->field_input( '_conditional_value', $form_id ); ?>
271
-
272
- <p><a href="#" class="um-admin-remove-condition button um-admin-tipsy-n" title="Remove condition"><i class="um-icon-close" style="margin-right:0!important"></i></a></p>
273
-
274
- <div class="um-admin-clear"></div>
275
- </div>
276
-
277
- <?php } ?>
278
- </div>
279
- </div>
280
-
281
- <?php
282
- }
283
-
284
-
285
- /**
286
- * Update the builder area
287
- */
288
- function update_builder() {
289
- UM()->admin()->check_ajax_nonce();
290
-
291
- if ( ! is_user_logged_in() || ! current_user_can( 'manage_options' ) ) {
292
- wp_send_json_error( __( 'Please login as administrator', 'ultimate-member' ) );
293
- }
294
-
295
- ob_start();
296
-
297
- $this->form_id = absint( $_POST['form_id'] );
298
-
299
- $this->show_builder();
300
-
301
- $output = ob_get_clean();
302
-
303
- if ( is_array( $output ) ) {
304
- print_r( $output );
305
- } else {
306
- echo $output;
307
- }
308
- die;
309
- }
310
-
311
-
312
- /**
313
- * Sort array function
314
- *
315
- * @param array $arr
316
- * @param string $col
317
- * @param int $dir
318
- *
319
- * @return array
320
- */
321
- function array_sort_by_column( $arr, $col, $dir = SORT_ASC ) {
322
- $sort_col = array();
323
-
324
- foreach ( $arr as $key => $row ) {
325
- if ( ! empty( $row[ $col ] ) ) {
326
- $sort_col[ $key ] = $row[ $col ];
327
- }
328
- }
329
-
330
- if ( ! empty( $sort_col ) ) {
331
- array_multisort( $sort_col, $dir, $arr );
332
- }
333
-
334
- return $arr;
335
- }
336
-
337
-
338
- /**
339
- * Get fields in row
340
- *
341
- * @param $row_id
342
- *
343
- * @return string
344
- */
345
- function get_fields_by_row( $row_id ) {
346
-
347
- if ( empty( $this->global_fields ) || ! is_array( $this->global_fields ) ) {
348
- $this->global_fields = array();
349
- }
350
-
351
- foreach ( $this->global_fields as $key => $array ) {
352
- if ( ! isset( $array['in_row'] ) || ( isset( $array['in_row'] ) && $array['in_row'] == $row_id ) ) {
353
- $results[ $key ] = $array;
354
- unset( $this->global_fields[ $key ] );
355
- }
356
- }
357
-
358
- return ( isset ( $results ) ) ? $results : '';
359
- }
360
-
361
-
362
- /**
363
- * Get fields by sub row
364
- *
365
- * @param $row_fields
366
- * @param $subrow_id
367
- *
368
- * @return string
369
- */
370
- function get_fields_in_subrow( $row_fields, $subrow_id ) {
371
- if ( ! is_array( $row_fields ) ) {
372
- return '';
373
- }
374
-
375
- foreach( $row_fields as $key => $array ) {
376
- if ( ! isset( $array['in_sub_row'] ) || ( isset( $array['in_sub_row'] ) && $array['in_sub_row'] == $subrow_id ) ) {
377
- $results[ $key ] = $array;
378
- unset( $this->global_fields[ $key ] );
379
- }
380
- }
381
-
382
- return ( isset ( $results ) ) ? $results : '';
383
- }
384
-
385
-
386
- /**
387
- * Display the builder
388
- */
389
- function show_builder() {
390
-
391
- $fields = UM()->query()->get_attr( 'custom_fields', $this->form_id );
392
-
393
- if ( !isset( $fields ) || empty( $fields ) ) { ?>
394
-
395
- <div class="um-admin-drag-row">
396
-
397
- <!-- Master Row Actions -->
398
- <div class="um-admin-drag-row-icons">
399
- <a href="javascript:void(0);" class="um-admin-drag-rowsub-add um-admin-tipsy-n" title="<?php esc_attr_e( 'Add Row', 'ultimate-member' ); ?>" data-row_action="add_subrow"><i class="um-icon-plus"></i></a>
400
- <a href="javascript:void(0);" class="um-admin-drag-row-edit um-admin-tipsy-n" title="<?php esc_attr_e( 'Edit Row', 'ultimate-member' ); ?>" data-modal="UM_edit_row" data-modal-size="normal" data-dynamic-content="um_admin_edit_field_popup" data-arg1="row" data-arg2="<?php echo esc_attr( $this->form_id ); ?>" data-arg3="_um_row_1"><i class="um-faicon-pencil"></i></a>
401
- <span class="um-admin-drag-row-start"><i class="um-icon-arrow-move"></i></span>
402
- </div>
403
- <div class="um-admin-clear"></div>
404
-
405
- <div class="um-admin-drag-rowsubs">
406
- <div class="um-admin-drag-rowsub">
407
-
408
- <!-- Column Layout -->
409
- <div class="um-admin-drag-ctrls columns">
410
- <a href="javascript:void(0);" class="active" data-cols="1"></a>
411
- <a href="javascript:void(0);" data-cols="2"></a>
412
- <a href="javascript:void(0);" data-cols="3"></a>
413
- </div>
414
-
415
- <!-- Sub Row Actions -->
416
- <div class="um-admin-drag-rowsub-icons">
417
- <span class="um-admin-drag-rowsub-start"><i class="um-icon-arrow-move"></i></span>
418
- </div><div class="um-admin-clear"></div>
419
-
420
- <!-- Columns -->
421
- <div class="um-admin-drag-col">
422
-
423
- </div>
424
-
425
- <div class="um-admin-drag-col-dynamic"></div>
426
-
427
- <div class="um-admin-clear"></div>
428
-
429
- </div>
430
- </div>
431
-
432
- </div>
433
-
434
- <?php
435
-
436
- } else {
437
-
438
- if ( empty( $fields ) || ! is_array( $fields ) ) {
439
- $this->global_fields = array();
440
- } else {
441
- $this->global_fields = $fields;
442
- }
443
-
444
- foreach ( $this->global_fields as $key => $array ) {
445
- if ( $array['type'] == 'row' ) {
446
- $rows[ $key ] = $array;
447
- unset( $this->global_fields[ $key ] ); // not needed now
448
- }
449
-
450
- }
451
-
452
- if ( ! isset( $rows ) ) {
453
- $rows = array(
454
- '_um_row_1' => array(
455
- 'type' => 'row',
456
- 'id' => '_um_row_1',
457
- 'sub_rows' => 1,
458
- 'cols' => 1
459
- ),
460
- );
461
- }
462
-
463
- foreach ( $rows as $row_id => $array ) { ?>
464
-
465
- <div class="um-admin-drag-row" data-original="<?php echo esc_attr( $row_id ); ?>">
466
-
467
- <!-- Master Row Actions -->
468
- <div class="um-admin-drag-row-icons">
469
- <a href="javascript:void(0);" class="um-admin-drag-rowsub-add um-admin-tipsy-n" title="<?php esc_attr_e( 'Add Row', 'ultimate-member' ); ?>" data-row_action="add_subrow"><i class="um-icon-plus"></i></a>
470
- <a href="javascript:void(0);" class="um-admin-drag-row-edit um-admin-tipsy-n" title="<?php esc_attr_e( 'Edit Row', 'ultimate-member'); ?>" data-modal="UM_edit_row" data-modal-size="normal" data-dynamic-content="um_admin_edit_field_popup" data-arg1="row" data-arg2="<?php echo esc_attr( $this->form_id ); ?>" data-arg3="<?php echo esc_attr( $row_id ); ?>"><i class="um-faicon-pencil"></i></a>
471
- <span class="um-admin-drag-row-start"><i class="um-icon-arrow-move"></i></span>
472
- <?php if ( $row_id != '_um_row_1' ) {?>
473
- <a href="javascript:void(0);" class="um-admin-tipsy-n" title="<?php esc_attr_e( 'Delete Row', 'ultimate-member' ); ?>" data-remove_element="um-admin-drag-row"><i class="um-faicon-trash-o"></i></a>
474
- <?php } ?>
475
- </div><div class="um-admin-clear"></div>
476
-
477
- <div class="um-admin-drag-rowsubs">
478
-
479
- <?php $row_fields = $this->get_fields_by_row( $row_id );
480
-
481
- $sub_rows = ( isset( $array['sub_rows'] ) ) ? $array['sub_rows'] : 1;
482
- for ( $c = 0; $c < $sub_rows; $c++ ) {
483
-
484
- $subrow_fields = $this->get_fields_in_subrow( $row_fields, $c );
485
-
486
- ?>
487
-
488
- <div class="um-admin-drag-rowsub">
489
-
490
- <!-- Column Layout -->
491
- <div class="um-admin-drag-ctrls columns">
492
-
493
- <?php
494
-
495
- if ( ! isset( $array['cols'] ) ) {
496
- $col_num = 1;
497
- } elseif ( is_numeric( $array['cols'] ) ) {
498
- $col_num = (int) $array['cols'];
499
- } else {
500
- $col_split = explode( ':', $array['cols'] );
501
- $col_num = $col_split[ $c ];
502
- }
503
-
504
- for ( $i = 1; $i <= 3; $i++ ) {
505
- echo '<a href="javascript:void(0);" data-cols="'.$i.'" ';
506
- if ( $col_num == $i ) echo 'class="active"';
507
- echo '></a>';
508
- }
509
-
510
- ?>
511
-
512
- </div>
513
-
514
- <!-- Sub Row Actions -->
515
- <div class="um-admin-drag-rowsub-icons">
516
- <span class="um-admin-drag-rowsub-start"><i class="um-icon-arrow-move"></i></span>
517
- <?php if ( $c > 0 ) { ?><a href="javascript:void(0);" class="um-admin-tipsy-n" title="Delete Row" data-remove_element="um-admin-drag-rowsub"><i class="um-faicon-trash-o"></i></a><?php } ?>
518
- </div>
519
- <div class="um-admin-clear"></div>
520
-
521
- <!-- Columns -->
522
- <div class="um-admin-drag-col">
523
-
524
- <?php
525
-
526
- if ( is_array( $subrow_fields ) ) {
527
-
528
- $subrow_fields = $this->array_sort_by_column( $subrow_fields, 'position');
529
-
530
- foreach( $subrow_fields as $key => $keyarray ) {
531
- /**
532
- * @var $type
533
- * @var $title
534
- */
535
- extract( $keyarray );
536
-
537
- ?>
538
-
539
- <div class="um-admin-drag-fld um-admin-delete-area um-field-type-<?php echo $type; ?> <?php echo $key; ?>" data-group="<?php echo (isset($keyarray['in_group'])) ? $keyarray['in_group'] : ''; ?>" data-key="<?php echo $key; ?>" data-column="<?php echo ( isset($keyarray['in_column']) ) ? $keyarray['in_column'] : 1; ?>">
540
-
541
- <div class="um-admin-drag-fld-title um-field-type-<?php echo $type; ?>">
542
- <?php if ( $type == 'group' ) { ?>
543
- <i class="um-icon-plus"></i>
544
- <?php } else if ( isset($keyarray['icon']) && !empty( $keyarray['icon'] ) ) { ?>
545
- <i class="<?php echo $keyarray['icon']; ?>"></i>
546
- <?php } ?><?php echo ! empty( $keyarray['title'] ) ? $keyarray['title'] : __( '(no title)', 'ultimate-member' ); ?></div>
547
- <?php $field_name = isset( UM()->builtin()->core_fields[$type]['name'] ) ? UM()->builtin()->core_fields[$type]['name'] : ''; ?>
548
- <div class="um-admin-drag-fld-type um-field-type-<?php echo $type; ?>"><?php echo $field_name; ?></div>
549
- <div class="um-admin-drag-fld-icons um-field-type-<?php echo $type; ?>">
550
-
551
- <a href="javascript:void(0);" class="um-admin-tipsy-n" title="<?php esc_attr_e( 'Edit', 'ultimate-member' ) ?>" data-modal="UM_edit_field" data-modal-size="normal" data-dynamic-content="um_admin_edit_field_popup" data-arg1="<?php echo $type; ?>" data-arg2="<?php echo $this->form_id; ?>" data-arg3="<?php echo $key; ?>"><i class="um-faicon-pencil"></i></a>
552
-
553
- <a href="javascript:void(0);" class="um-admin-tipsy-n um_admin_duplicate_field" title="<?php esc_attr_e( 'Duplicate', 'ultimate-member' ) ?>" data-silent_action="um_admin_duplicate_field" data-arg1="<?php echo $key; ?>" data-arg2="<?php echo $this->form_id; ?>"><i class="um-faicon-files-o"></i></a>
554
-
555
- <?php if ( $type == 'group' ) { ?>
556
-
557
- <a href="javascript:void(0);" class="um-admin-tipsy-n" title="<?php esc_attr_e( 'Delete Group', 'ultimate-member' ) ?>" data-remove_element="um-admin-drag-fld.um-field-type-group" data-silent_action="um_admin_remove_field" data-arg1="<?php echo $key; ?>" data-arg2="<?php echo $this->form_id; ?>"><i class="um-faicon-trash-o"></i></a>
558
- <?php } else { ?>
559
-
560
- <a href="javascript:void(0);" class="um-admin-tipsy-n" title="<?php esc_attr_e( 'Delete', 'ultimate-member' ) ?>" data-silent_action="um_admin_remove_field" data-arg1="<?php echo $key; ?>" data-arg2="<?php echo $this->form_id; ?>"><i class="um-faicon-trash-o"></i></a>
561
-
562
- <?php } ?>
563
-
564
- </div><div class="um-admin-clear"></div>
565
-
566
- <?php if ( $type == 'group' ) { ?>
567
- <div class="um-admin-drag-group">
568
-
569
- </div>
570
- <?php } ?>
571
-
572
- </div>
573
-
574
- <?php
575
-
576
- } // end foreach
577
-
578
- } // end if
579
-
580
- ?>
581
-
582
- </div>
583
-
584
- <div class="um-admin-drag-col-dynamic"></div>
585
-
586
- <div class="um-admin-clear"></div>
587
-
588
- </div>
589
-
590
- <?php } ?>
591
-
592
- </div>
593
-
594
- </div>
595
-
596
- <?php
597
-
598
- } // rows loop
599
-
600
- } // if fields exist
601
-
602
- }
603
-
604
-
605
- /**
606
- *
607
- */
608
- function update_field() {
609
- UM()->admin()->check_ajax_nonce();
610
-
611
- if ( ! is_user_logged_in() || ! current_user_can( 'manage_options' ) ) {
612
- wp_send_json_error( __( 'Please login as administrator', 'ultimate-member' ) );
613
- }
614
-
615
- $output['error'] = null;
616
-
617
- $array = array(
618
- 'field_type' => sanitize_key( $_POST['_type'] ),
619
- 'form_id' => absint( $_POST['post_id'] ),
620
- 'args' => UM()->builtin()->get_core_field_attrs( sanitize_key( $_POST['_type'] ) ),
621
- 'post' => UM()->admin()->sanitize_builder_field_meta( $_POST ),
622
- );
623
-
624
- /**
625
- * UM hook
626
- *
627
- * @type filter
628
- * @title um_admin_pre_save_fields_hook
629
- * @description Filter field data before save
630
- * @input_vars
631
- * [{"var":"$array","type":"array","desc":"Save Field data"}]
632
- * @change_log
633
- * ["Since: 2.0"]
634
- * @usage add_filter( 'um_admin_pre_save_fields_hook', 'function_name', 10, 1 );
635
- * @example
636
- * <?php
637
- * add_filter( 'um_admin_pre_save_fields_hook', 'my_admin_pre_save_fields', 10, 1 );
638
- * function my_admin_pre_save_fields( $array ) {
639
- * // your code here
640
- * return $array;
641
- * }
642
- * ?>
643
- */
644
- $array = apply_filters( 'um_admin_pre_save_fields_hook', $array );
645
-
646
- /**
647
- * UM hook
648
- *
649
- * @type filter
650
- * @title um_admin_field_update_error_handling
651
- * @description Change error string on save field
652
- * @input_vars
653
- * [{"var":"$error","type":"string","desc":"Error String"},
654
- * {"var":"$array","type":"array","desc":"Save Field data"}]
655
- * @change_log
656
- * ["Since: 2.0"]
657
- * @usage add_filter( 'um_admin_field_update_error_handling', 'function_name', 10, 2 );
658
- * @example
659
- * <?php
660
- * add_filter( 'um_admin_field_update_error_handling', 'my_admin_field_update_error', 10, 2 );
661
- * function my_admin_field_update_error( $error, $array ) {
662
- * // your code here
663
- * return $error;
664
- * }
665
- * ?>
666
- */
667
- $output['error'] = apply_filters( 'um_admin_field_update_error_handling', $output['error'], $array );
668
-
669
- /**
670
- * @var $_metakey
671
- * @var $post_id
672
- */
673
- extract( $array['post'] );
674
-
675
- if ( empty( $output['error'] ) ) {
676
-
677
- $save = array();
678
- $save[ $_metakey ] = null;
679
- foreach ( $array['post'] as $key => $val ) {
680
-
681
- if ( substr( $key, 0, 1 ) === '_' && $val !== '' ) { // field attribute
682
- $new_key = ltrim ( $key, '_' );
683
-
684
- if ( $new_key == 'options' ) {
685
- //$save[ $_metakey ][$new_key] = explode(PHP_EOL, $val);
686
- $save[ $_metakey ][ $new_key ] = preg_split( '/[\r\n]+/', $val, -1, PREG_SPLIT_NO_EMPTY );
687
- } else {
688
- $save[ $_metakey ][ $new_key ] = $val;
689
- }
690
-
691
- } elseif ( strstr( $key, 'um_editor' ) ) {
692
-
693
- if ( 'block' === $array['post']['_type'] ) {
694
- $save[ $_metakey ]['content'] = wp_kses_post( $val );
695
- } else {
696
- $save[ $_metakey ]['content'] = sanitize_textarea_field( $val );
697
- }
698
- }
699
-
700
- }
701
-
702
- $field_ID = $_metakey;
703
- $field_args = $save[ $_metakey ];
704
-
705
- /**
706
- * UM hook
707
- *
708
- * @type filter
709
- * @title um_admin_pre_save_field_to_form
710
- * @description Change field options before save to form
711
- * @input_vars
712
- * [{"var":"$field_args","type":"array","desc":"Field Options"}]
713
- * @change_log
714
- * ["Since: 2.0"]
715
- * @usage add_filter( 'um_admin_pre_save_field_to_form', 'function_name', 10, 1 );
716
- * @example
717
- * <?php
718
- * add_filter( 'um_admin_pre_save_field_to_form', 'my_admin_pre_save_field_to_form', 10, 1 );
719
- * function my_admin_pre_save_field_to_form( $field_args ) {
720
- * // your code here
721
- * return $field_args;
722
- * }
723
- * ?>
724
- */
725
- $field_args = apply_filters( 'um_admin_pre_save_field_to_form', $field_args );
726
-
727
- UM()->fields()->update_field( $field_ID, $field_args, $post_id );
728
-
729
- /**
730
- * UM hook
731
- *
732
- * @type filter
733
- * @title um_admin_pre_save_field_to_db
734
- * @description Change field options before save to DB
735
- * @input_vars
736
- * [{"var":"$field_args","type":"array","desc":"Field Options"}]
737
- * @change_log
738
- * ["Since: 2.0"]
739
- * @usage add_filter( 'um_admin_pre_save_field_to_db', 'function_name', 10, 1 );
740
- * @example
741
- * <?php
742
- * add_filter( 'um_admin_pre_save_field_to_db', 'my_admin_pre_save_field_to_db', 10, 1 );
743
- * function my_admin_pre_save_field_to_form( $field_args ) {
744
- * // your code here
745
- * return $field_args;
746
- * }
747
- * ?>
748
- */
749
- $field_args = apply_filters( 'um_admin_pre_save_field_to_db', $field_args );
750
-
751
- if ( ! isset( $array['args']['form_only'] ) ) {
752
- if ( ! isset( UM()->builtin()->predefined_fields[ $field_ID ] ) ) {
753
- UM()->fields()->globally_update_field( $field_ID, $field_args );
754
- }
755
- }
756
-
757
- }
758
-
759
- $output = json_encode( $output );
760
- if ( is_array( $output ) ) {
761
- print_r( $output );
762
- } else {
763
- echo $output;
764
- }
765
- die;
766
- }
767
-
768
-
769
- /**
770
- *
771
- */
772
- function dynamic_modal_content() {
773
- UM()->admin()->check_ajax_nonce();
774
-
775
- if ( ! is_user_logged_in() || ! current_user_can( 'manage_options' ) ) {
776
- wp_send_json_error( __( 'Please login as administrator', 'ultimate-member' ) );
777
- }
778
-
779
- $metabox = UM()->metabox();
780
-
781
- /**
782
- * @var $act_id
783
- * @var $arg1
784
- * @var $arg2
785
- * @var $arg3
786
- */
787
- extract( $_POST );
788
-
789
- if ( isset( $arg1 ) ) {
790
- $arg1 = sanitize_text_field( $arg1 );
791
- }
792
-
793
- if ( isset( $arg2 ) ) {
794
- $arg2 = sanitize_text_field( $arg2 );
795
- }
796
-
797
- if ( isset( $arg3 ) ) {
798
- $arg3 = sanitize_text_field( $arg3 );
799
- }
800
-
801
- switch ( sanitize_key( $act_id ) ) {
802
-
803
- default:
804
-
805
- ob_start();
806
-
807
- /**
808
- * UM hook
809
- *
810
- * @type action
811
- * @title um_admin_ajax_modal_content__hook
812
- * @description Integration hook on ajax popup admin builder modal content
813
- * @input_vars
814
- * [{"var":"$act_id","type":"string","desc":"Ajax Action"}]
815
- * @change_log
816
- * ["Since: 2.0"]
817
- * @usage add_action( 'um_admin_ajax_modal_content__hook', 'function_name', 10, 1 );
818
- * @example
819
- * <?php
820
- * add_action( 'um_admin_ajax_modal_content__hook', 'my_admin_custom_hook', 10, 1 );
821
- * function um_admin_ajax_modal_content__hook( $act_id ) {
822
- * // your code here
823
- * }
824
- * ?>
825
- */
826
- do_action( 'um_admin_ajax_modal_content__hook', sanitize_key( $act_id ) );
827
- /**
828
- * UM hook
829
- *
830
- * @type action
831
- * @title um_admin_ajax_modal_content__hook_{$act_id}
832
- * @description Integration hook on ajax popup admin builder modal content
833
- * @change_log
834
- * ["Since: 2.0"]
835
- * @usage add_action( 'um_admin_ajax_modal_content__hook_{$act_id}', 'function_name', 10 );
836
- * @example
837
- * <?php
838
- * add_action( 'um_admin_ajax_modal_content__hook_{$act_id}', 'my_admin_ajax_modal_content', 10 );
839
- * function my_admin_ajax_modal_content() {
840
- * // your code here
841
- * }
842
- * ?>
843
- */
844
- do_action( "um_admin_ajax_modal_content__hook_" . sanitize_key( $act_id ) );
845
-
846
- $output = ob_get_clean();
847
- break;
848
-
849
- case 'um_admin_fonticon_selector':
850
-
851
- ob_start(); ?>
852
-
853
- <div class="um-admin-metabox">
854
- <p class="_icon_search"><input type="text" name="_icon_search" id="_icon_search" value="" placeholder="<?php esc_attr_e('Search Icons...', 'ultimate-member' ); ?>" /></p>
855
- </div>
856
-
857
- <div class="um-admin-icons">
858
- <?php foreach( UM()->fonticons()->all as $icon ) { ?>
859
- <span data-code="<?php echo esc_attr( $icon ); ?>" title="<?php echo esc_attr( $icon ); ?>" class="um-admin-tipsy-n"><i class="<?php echo $icon; ?>"></i></span>
860
- <?php } ?>
861
- </div><div class="um-admin-clear"></div>
862
-
863
- <?php $output = ob_get_clean();
864
- break;
865
-
866
- case 'um_admin_show_fields':
867
-
868
- ob_start();
869
- $form_fields = UM()->query()->get_attr( 'custom_fields', $arg2 );
870
- $form_fields = array_values( array_filter( array_keys( $form_fields ) ) );
871
- //$form_fields = array_keys( $form_fields );
872
- ?>
873
-
874
- <h4><?php _e('Setup New Field','ultimate-member'); ?></h4>
875
- <div class="um-admin-btns">
876
-
877
- <?php if ( UM()->builtin()->core_fields ) {
878
- foreach ( UM()->builtin()->core_fields as $field_type => $array ) {
879
-
880
- if ( isset( $array['in_fields'] ) && $array['in_fields'] == false ) {
881
- continue;
882
- } ?>
883
-
884
- <a href="javascript:void(0);" class="button" data-modal="UM_add_field" data-modal-size="normal" data-dynamic-content="um_admin_new_field_popup" data-arg1="<?php echo esc_attr( $field_type ); ?>" data-arg2="<?php echo esc_attr( $arg2 ) ?>"><?php echo esc_html( $array['name'] ); ?></a>
885
-
886
- <?php }
887
- } ?>
888
-
889
- </div>
890
-
891
- <h4><?php _e('Predefined Fields','ultimate-member'); ?></h4>
892
- <div class="um-admin-btns">
893
-
894
- <?php if ( UM()->builtin()->predefined_fields ) {
895
- foreach ( UM()->builtin()->predefined_fields as $field_key => $array ) {
896
- if ( ! isset( $array['account_only'] ) && ! isset( $array['private_use'] ) ) { ?>
897
-
898
- <a href="javascript:void(0);" class="button" <?php disabled( in_array( $field_key, $form_fields, true ) ) ?> data-silent_action="um_admin_add_field_from_predefined" data-arg1="<?php echo esc_attr( $field_key ); ?>" data-arg2="<?php echo esc_attr( $arg2 ); ?>"><?php echo um_trim_string( stripslashes( $array['title'] ), 20 ); ?></a>
899
-
900
- <?php }
901
- }
902
- } else {
903
- echo '<p>' . __( 'None', 'ultimate-member' ) . '</p>';
904
- } ?>
905
-
906
- </div>
907
-
908
- <h4><?php _e( 'Custom Fields', 'ultimate-member' ); ?></h4>
909
- <div class="um-admin-btns">
910
-
911
- <?php
912
- if ( UM()->builtin()->custom_fields ) {
913
- foreach ( UM()->builtin()->custom_fields as $field_key => $array ) {
914
- if ( empty( $array['title'] ) || empty( $array['type'] ) ) {
915
- continue;
916
- } ?>
917
-
918
- <a href="javascript:void(0);" class="button with-icon" <?php disabled( in_array( $field_key, $form_fields, true ) ) ?> data-silent_action="um_admin_add_field_from_list" data-arg1="<?php echo esc_attr( $field_key ); ?>" data-arg2="<?php echo esc_attr( $arg2 ); ?>" title="<?php echo __( 'Meta Key', 'ultimate-member' ) . ' - ' . esc_attr( $field_key ); ?>"><?php echo um_trim_string( stripslashes( $array['title'] ), 20 ); ?> <small>(<?php echo ucfirst( $array['type'] ); ?>)</small><span class="remove"></span></a>
919
-
920
- <?php }
921
- } else {
922
- echo '<p>' . __( 'You did not create any custom fields', 'ultimate-member' ) . '</p>';
923
- } ?>
924
-
925
- </div>
926
-
927
- <?php $output = ob_get_clean();
928
- break;
929
-
930
- case 'um_admin_edit_field_popup':
931
-
932
- ob_start();
933
-
934
- $args = UM()->builtin()->get_core_field_attrs( $arg1 );
935
-
936
- $form_fields = UM()->query()->get_attr( 'custom_fields', $arg2 );
937
-
938
- $metabox->set_field_type = $arg1;
939
- $metabox->in_edit = true;
940
- $metabox->edit_array = $form_fields[ $arg3 ];
941
-
942
- if ( !isset( $metabox->edit_array['metakey'] ) ){
943
- $metabox->edit_array['metakey'] = $metabox->edit_array['id'];
944
- }
945
-
946
- if ( !isset( $metabox->edit_array['position'] ) ){
947
- $metabox->edit_array['position'] = $metabox->edit_array['id'];
948
- }
949
-
950
- extract( $args );
951
-
952
- if ( ! isset( $col1 ) ) {
953
-
954
- echo '<p>'. __( 'This field type is not setup correcty.', 'ultimate-member' ) . '</p>';
955
-
956
- } else {
957
-
958
- ?>
959
-
960
- <?php if ( isset( $metabox->edit_array['in_group'] ) ) { ?>
961
- <input type="hidden" name="_in_row" id="_in_row" value="<?php echo $metabox->edit_array['in_row']; ?>" />
962
- <input type="hidden" name="_in_sub_row" id="_in_sub_row" value="<?php echo $metabox->edit_array['in_sub_row']; ?>" />
963
- <input type="hidden" name="_in_column" id="_in_column" value="<?php echo $metabox->edit_array['in_column']; ?>" />
964
- <input type="hidden" name="_in_group" id="_in_group" value="<?php echo $metabox->edit_array['in_group']; ?>" />
965
- <?php } ?>
966
-
967
- <input type="hidden" name="_type" id="_type" value="<?php echo $arg1; ?>" />
968
-
969
- <input type="hidden" name="post_id" id="post_id" value="<?php echo $arg2; ?>" />
970
-
971
- <input type="hidden" name="edit_mode" id="edit_mode" value="true" />
972
-
973
- <input type="hidden" name="_metakey" id="_metakey" value="<?php echo $metabox->edit_array['metakey']; ?>" />
974
-
975
- <input type="hidden" name="_position" id="_position" value="<?php echo $metabox->edit_array['position']; ?>" />
976
-
977
- <?php if ( isset( $args['mce_content'] ) ) { ?>
978
- <div class="dynamic-mce-content"><?php echo ! empty( $metabox->edit_array['content'] ) ? $metabox->edit_array['content'] : ''; ?></div>
979
- <?php } ?>
980
-
981
- <?php $this->modal_header(); ?>
982
-
983
- <div class="um-admin-half">
984
-
985
- <?php if ( isset( $col1 ) ) { foreach( $col1 as $opt ) $metabox->field_input ( $opt, $arg2, $metabox->edit_array ); } ?>
986
-
987
- </div>
988
-
989
- <div class="um-admin-half um-admin-right">
990
-
991
- <?php if ( isset( $col2 ) ) { foreach( $col2 as $opt ) $metabox->field_input ( $opt, $arg2, $metabox->edit_array ); } ?>
992
-
993
- </div><div class="um-admin-clear"></div>
994
-
995
- <?php if ( isset( $col3 ) ) { foreach( $col3 as $opt ) $metabox->field_input ( $opt, $arg2, $metabox->edit_array ); } ?>
996
-
997
- <div class="um-admin-clear"></div>
998
-
999
- <?php if ( isset( $col_full ) ) {foreach( $col_full as $opt ) $metabox->field_input ( $opt, $arg2, $metabox->edit_array ); } ?>
1000
-
1001
- <?php $this->modal_footer( $arg2, $args, $metabox ); ?>
1002
-
1003
- <?php
1004
-
1005
- }
1006
-
1007
- $output = ob_get_clean();
1008
- break;
1009
-
1010
- case 'um_admin_new_field_popup':
1011
-
1012
- ob_start();
1013
-
1014
- $args = UM()->builtin()->get_core_field_attrs( $arg1 );
1015
-
1016
- $metabox->set_field_type = $arg1;
1017
-
1018
- /**
1019
- * @var $in_row
1020
- * @var $in_sub_row
1021
- * @var $in_column
1022
- * @var $in_group
1023
- */
1024
- extract( $args );
1025
-
1026
- if ( ! isset( $col1 ) ) {
1027
-
1028
- echo '<p>'. __( 'This field type is not setup correcty.', 'ultimate-member' ) . '</p>';
1029
-
1030
- } else {
1031
-
1032
- if ( $in_column ) { ?>
1033
- <input type="hidden" name="_in_row" id="_in_row" value="_um_row_<?php echo $in_row + 1; ?>" />
1034
- <input type="hidden" name="_in_sub_row" id="_in_sub_row" value="<?php echo $in_sub_row; ?>" />
1035
- <input type="hidden" name="_in_column" id="_in_column" value="<?php echo $in_column; ?>" />
1036
- <input type="hidden" name="_in_group" id="_in_group" value="<?php echo $in_group; ?>" />
1037
- <?php } ?>
1038
-
1039
- <input type="hidden" name="_type" id="_type" value="<?php echo $arg1; ?>" />
1040
-
1041
- <input type="hidden" name="post_id" id="post_id" value="<?php echo $arg2; ?>" />
1042
-
1043
- <?php $this->modal_header(); ?>
1044
-
1045
- <div class="um-admin-half">
1046
-
1047
- <?php if ( isset( $col1 ) ) { foreach( $col1 as $opt ) $metabox->field_input ( $opt ); } ?>
1048
-
1049
- </div>
1050
-
1051
- <div class="um-admin-half um-admin-right">
1052
-
1053
- <?php if ( isset( $col2 ) ) { foreach( $col2 as $opt ) $metabox->field_input ( $opt ); } ?>
1054
-
1055
- </div><div class="um-admin-clear"></div>
1056
-
1057
- <?php if ( isset( $col3 ) ) { foreach( $col3 as $opt ) $metabox->field_input ( $opt ); } ?>
1058
-
1059
- <div class="um-admin-clear"></div>
1060
-
1061
- <?php if ( isset( $col_full ) ) { foreach( $col_full as $opt ) $metabox->field_input ( $opt ); } ?>
1062
-
1063
- <?php $this->modal_footer( $arg2, $args, $metabox ); ?>
1064
-
1065
- <?php
1066
-
1067
- }
1068
-
1069
- $output = ob_get_clean();
1070
- break;
1071
-
1072
- case 'um_admin_preview_form':
1073
-
1074
- UM()->user()->preview = true;
1075
-
1076
- $mode = UM()->query()->get_attr('mode', $arg1 );
1077
-
1078
- if ( $mode == 'profile' ) {
1079
- UM()->fields()->editing = true;
1080
- }
1081
-
1082
- $output = '<div class="um-admin-preview-overlay"></div>';
1083
-
1084
- if ( version_compare( get_bloginfo('version'),'5.4', '<' ) ) {
1085
- $output .= do_shortcode('[ultimatemember form_id="' . $arg1 . '" /]');
1086
- } else {
1087
- $output .= apply_shortcodes('[ultimatemember form_id="' . $arg1 . '" /]');
1088
- }
1089
-
1090
- break;
1091
-
1092
- case 'um_admin_review_registration':
1093
- //$user_id = $arg1;
1094
-
1095
- if ( ! current_user_can( 'administrator' ) ) {
1096
- if ( ! um_can_view_profile( $arg1 ) ) {
1097
- $output = '';
1098
- break;
1099
- }
1100
- }
1101
-
1102
- um_fetch_user( $arg1 );
1103
-
1104
- UM()->user()->preview = true;
1105
-
1106
- $output = um_user_submitted_registration_formatted( true );
1107
-
1108
- um_reset_user();
1109
-
1110
- break;
1111
-
1112
- }
1113
-
1114
- if ( is_array( $output ) ) {
1115
- print_r( $output );
1116
- } else {
1117
- echo $output;
1118
- }
1119
- die;
1120
- }
1121
-
1122
-
1123
- /**
1124
- *
1125
- */
1126
- function modal_header() {
1127
- /**
1128
- * UM hook
1129
- *
1130
- * @type action
1131
- * @title um_admin_field_modal_header
1132
- * @description Modal Window Header
1133
- * @change_log
1134
- * ["Since: 2.0"]
1135
- * @usage add_action( 'um_admin_field_modal_header', 'function_name', 10 );
1136
- * @example
1137
- * <?php
1138
- * add_action( 'um_admin_field_modal_header', 'my_admin_field_modal_header', 10 );
1139
- * function my_admin_field_modal_header() {
1140
- * // your code here
1141
- * }
1142
- * ?>
1143
- */
1144
- do_action( 'um_admin_field_modal_header' );
1145
- }
1146
-
1147
-
1148
- /**
1149
- * Modal Footer loading
1150
- *
1151
- * @param $arg2
1152
- * @param $args
1153
- * @param $metabox
1154
- */
1155
- function modal_footer( $arg2, $args, $metabox ) {
1156
- /**
1157
- * UM hook
1158
- *
1159
- * @type action
1160
- * @title um_admin_field_modal_footer
1161
- * @description Modal Window Footer
1162
- * @input_vars
1163
- * [{"var":"$arg2","type":"string","desc":"Ajax Action"},
1164
- * {"var":"$args","type":"array","desc":"Modal window arguments"},
1165
- * {"var":"$in_edit","type":"bool","desc":"Is edit mode?"},
1166
- * {"var":"$edit_array","type":"array","desc":"Edit Array"}]
1167
- * @change_log
1168
- * ["Since: 2.0"]
1169
- * @usage add_action( 'um_admin_field_modal_footer', 'function_name', 10, 4 );
1170
- * @example
1171
- * <?php
1172
- * add_action( 'um_admin_field_modal_footer', 'my_admin_field_modal_footer', 10, 4 );
1173
- * function my_admin_field_modal_footer( $arg2, $args, $in_edit, $edit_array ) {
1174
- * // your code here
1175
- * }
1176
- * ?>
1177
- */
1178
- do_action( 'um_admin_field_modal_footer', $arg2, $args, $metabox->in_edit, ( isset( $metabox->edit_array ) ) ? $metabox->edit_array : '' );
1179
- }
1180
-
1181
-
1182
- /**
1183
- * Skip field validation for:
1184
- * - '_options' if Choices Callback specified
1185
- *
1186
- * @param boolean $skip
1187
- * @param string $post_input
1188
- * @param array $array
1189
- * @return boolean
1190
- */
1191
- public function skip_field_validation( $skip, $post_input, $array ) {
1192
- if ( $post_input === '_options' && isset( $array['post']['_custom_dropdown_options_source'] ) ) {
1193
- $skip = function_exists( wp_unslash( $array['post']['_custom_dropdown_options_source'] ) );
1194
- }
1195
-
1196
- return $skip;
1197
- }
1198
-
1199
-
1200
- /**
1201
- * Retrieves dropdown/multi-select options from a callback function
1202
- */
1203
- function populate_dropdown_options() {
1204
- UM()->admin()->check_ajax_nonce();
1205
-
1206
- if ( ! is_user_logged_in() || ! current_user_can( 'manage_options' ) ) {
1207
- wp_send_json_error( __( 'This is not possible for security reasons.', 'ultimate-member' ) );
1208
- }
1209
-
1210
- $arr_options = array();
1211
-
1212
- // we can not use `sanitize_key()` because it removes backslash needed for namespace and uppercase symbols
1213
- $um_callback_func = sanitize_text_field( $_POST['um_option_callback'] );
1214
- // removed added by sanitize slashes for the namespaces
1215
- $um_callback_func = wp_unslash( $um_callback_func );
1216
-
1217
- if ( empty( $um_callback_func ) ) {
1218
- $arr_options['status'] = 'empty';
1219
- $arr_options['function_name'] = $um_callback_func;
1220
- $arr_options['function_exists'] = function_exists( $um_callback_func );
1221
- }
1222
-
1223
- $arr_options['data'] = array();
1224
- if ( function_exists( $um_callback_func ) ) {
1225
- $arr_options['data'] = call_user_func( $um_callback_func );
1226
- }
1227
-
1228
- wp_send_json( $arr_options );
1229
- }
1230
-
1231
- }
1232
- }
 
 
 
 
1
+ <?php
2
+ namespace um\admin\core;
3
+
4
+
5
+ if ( ! defined( 'ABSPATH' ) ) exit;
6
+
7
+
8
+ if ( ! class_exists( 'um\admin\core\Admin_Builder' ) ) {
9
+
10
+
11
+ /**
12
+ * Class Admin_Builder
13
+ * @package um\admin\core
14
+ */
15
+ class Admin_Builder {
16
+
17
+
18
+ /**
19
+ * @var
20
+ */
21
+ var $form_id;
22
+
23
+
24
+ /**
25
+ * Admin_Builder constructor.
26
+ */
27
+ function __construct() {
28
+ add_action( 'um_admin_field_modal_header', array( &$this, 'add_message_handlers' ) );
29
+ add_action( 'um_admin_field_modal_footer', array( &$this, 'add_conditional_support' ), 10, 4 );
30
+ add_filter( 'um_admin_builder_skip_field_validation', array( &$this, 'skip_field_validation' ), 10, 3 );
31
+ add_filter( 'um_admin_pre_save_field_to_form', array( &$this, 'um_admin_pre_save_field_to_form' ), 1 );
32
+ add_filter( 'um_admin_pre_save_fields_hook', array( &$this, 'um_admin_pre_save_fields_hook' ), 1 );
33
+ add_filter( 'um_admin_field_update_error_handling', array( &$this, 'um_admin_field_update_error_handling' ), 1, 2 );
34
+ }
35
+
36
+
37
+ /**
38
+ * Apply a filter to handle errors for field updating in backend
39
+ *
40
+ * @param $errors
41
+ * @param $array
42
+ *
43
+ * @return mixed
44
+ */
45
+ function um_admin_field_update_error_handling( $errors, $array ) {
46
+ /**
47
+ * @var $field_type
48
+ */
49
+ extract( $array );
50
+
51
+ $field_attr = UM()->builtin()->get_core_field_attrs( $field_type );
52
+
53
+ if ( isset( $field_attr['validate'] ) ) {
54
+
55
+ $validate = $field_attr['validate'];
56
+ foreach ( $validate as $post_input => $arr ) {
57
+
58
+ $skip = apply_filters( 'um_admin_builder_skip_field_validation', false, $post_input, $array );
59
+ if ( $skip ) {
60
+ continue;
61
+ }
62
+
63
+ $mode = $arr['mode'];
64
+
65
+ switch ( $mode ) {
66
+
67
+ case 'numeric':
68
+ if ( ! empty( $array['post'][ $post_input ] ) && ! is_numeric( $array['post'][ $post_input ] ) ){
69
+ $errors[ $post_input ] = $validate[ $post_input ]['error'];
70
+ }
71
+ break;
72
+
73
+ case 'unique':
74
+ if ( ! isset( $array['post']['edit_mode'] ) ) {
75
+ if ( UM()->builtin()->unique_field_err( $array['post'][ $post_input ] ) ) {
76
+ $errors[ $post_input ] = UM()->builtin()->unique_field_err( $array['post'][ $post_input ] );
77
+ }
78
+ }
79
+ break;
80
+
81
+ case 'required':
82
+ if ( $array['post'][ $post_input ] == '' ) {
83
+ $errors[ $post_input ] = $validate[ $post_input ]['error'];
84
+ }
85
+ break;
86
+
87
+ case 'range-start':
88
+ if ( UM()->builtin()->date_range_start_err( $array['post'][ $post_input ] ) && $array['post']['_range'] == 'date_range' ) {
89
+ $errors[ $post_input ] = UM()->builtin()->date_range_start_err( $array['post'][ $post_input ] );
90
+ }
91
+ break;
92
+
93
+ case 'range-end':
94
+ if ( UM()->builtin()->date_range_end_err( $array['post'][ $post_input ], $array['post']['_range_start'] ) && $array['post']['_range'] == 'date_range' ) {
95
+ $errors[ $post_input ] = UM()->builtin()->date_range_end_err( $array['post'][ $post_input ], $array['post']['_range_start'] );
96
+ }
97
+ break;
98
+
99
+ }
100
+
101
+ }
102
+
103
+ }
104
+
105
+ return $errors;
106
+
107
+ }
108
+
109
+
110
+ /**
111
+ * Some fields may require extra fields before saving
112
+ *
113
+ * @param $array
114
+ *
115
+ * @return mixed
116
+ */
117
+ function um_admin_pre_save_fields_hook( $array ) {
118
+ /**
119
+ * @var $form_id
120
+ * @var $field_type
121
+ */
122
+ extract( $array );
123
+
124
+ $fields_without_metakey = UM()->builtin()->get_fields_without_metakey();
125
+
126
+ $fields = UM()->query()->get_attr( 'custom_fields', $form_id );
127
+ $count = 1;
128
+ if ( ! empty( $fields ) ) {
129
+ $count = count( $fields ) + 1;
130
+ }
131
+
132
+ // set unique meta key
133
+ if ( in_array( $field_type, $fields_without_metakey ) && ! isset( $array['post']['_metakey'] ) ) {
134
+ $array['post']['_metakey'] = "um_{$field_type}_{$form_id}_{$count}";
135
+ }
136
+
137
+ // set position
138
+ if ( ! isset( $array['post']['_position'] ) ) {
139
+ $array['post']['_position'] = $count;
140
+ }
141
+
142
+ return $array;
143
+ }
144
+
145
+
146
+ /**
147
+ * Modify field args just before it is saved into form
148
+ *
149
+ * @param $array
150
+ *
151
+ * @return mixed
152
+ */
153
+ function um_admin_pre_save_field_to_form( $array ){
154
+ unset( $array['conditions'] );
155
+ if ( isset($array['conditional_field']) && ! empty( $array['conditional_action'] ) && ! empty( $array['conditional_operator'] ) ) {
156
+ $array['conditional_value'] = isset( $array['conditional_value'] ) ? $array['conditional_value'] : '';
157
+ $array['conditions'][] = array( $array['conditional_action'], $array['conditional_field'], $array['conditional_operator'], $array['conditional_value'] );
158
+ }
159
+
160
+ if ( isset( $array['conditional_field1'] ) && ! empty( $array['conditional_action1'] ) && ! empty( $array['conditional_operator1'] ) ) {
161
+ $array['conditional_value1'] = isset( $array['conditional_value1'] ) ? $array['conditional_value1'] : '';
162
+ $array['conditions'][] = array( $array['conditional_action1'], $array['conditional_field1'], $array['conditional_operator1'], $array['conditional_value1'] );
163
+ }
164
+
165
+ if ( isset( $array['conditional_field2'] ) && ! empty( $array['conditional_action2'] ) && ! empty( $array['conditional_operator2'] ) ) {
166
+ $array['conditional_value2'] = isset( $array['conditional_value2'] ) ? $array['conditional_value2'] : '';
167
+ $array['conditions'][] = array( $array['conditional_action2'], $array['conditional_field2'], $array['conditional_operator2'], $array['conditional_value2'] );
168
+ }
169
+
170
+ if ( isset( $array['conditional_field3'] ) && ! empty( $array['conditional_action3'] ) && ! empty( $array['conditional_operator3'] ) ) {
171
+ $array['conditional_value3'] = isset( $array['conditional_value3'] ) ? $array['conditional_value3'] : '';
172
+ $array['conditions'][] = array( $array['conditional_action3'], $array['conditional_field3'], $array['conditional_operator3'], $array['conditional_value3'] );
173
+ }
174
+
175
+ if ( isset( $array['conditional_field4'] ) && ! empty( $array['conditional_action4'] ) && ! empty( $array['conditional_operator4'] ) ) {
176
+ $array['conditional_value4'] = isset( $array['conditional_value4'] ) ? $array['conditional_value4'] : '';
177
+ $array['conditions'][] = array( $array['conditional_action4'], $array['conditional_field4'], $array['conditional_operator4'], $array['conditional_value4'] );
178
+ }
179
+
180
+ return $array;
181
+ }
182
+
183
+
184
+ /**
185
+ * Put status handler in modal
186
+ */
187
+ function add_message_handlers() {
188
+ ?>
189
+ <div class="um-admin-error-block"></div>
190
+ <div class="um-admin-success-block"></div>
191
+ <?php
192
+ }
193
+
194
+
195
+ /**
196
+ * Footer of modal
197
+ *
198
+ * @param $form_id
199
+ * @param $field_args
200
+ * @param $in_edit
201
+ * @param $edit_array
202
+ */
203
+ function add_conditional_support( $form_id, $field_args, $in_edit, $edit_array ) {
204
+ $metabox = UM()->metabox();
205
+
206
+ if ( isset( $field_args['conditional_support'] ) && $field_args['conditional_support'] == 0 ) {
207
+ return;
208
+ } ?>
209
+
210
+ <div class="um-admin-btn-toggle">
211
+
212
+ <?php if ( $in_edit ) { $metabox->in_edit = true; $metabox->edit_array = $edit_array; ?>
213
+ <a href="javascript:void(0);"><i class="um-icon-plus"></i><?php _e( 'Manage conditional fields support' ); ?></a> <?php UM()->tooltip( __( 'Here you can setup conditional logic to show/hide this field based on specific fields value or conditions', 'ultimate-member' ) ); ?>
214
+ <?php } else { ?>
215
+ <a href="javascript:void(0);"><i class="um-icon-plus"></i><?php _e( 'Add conditional fields support' ); ?></a> <?php UM()->tooltip( __( 'Here you can setup conditional logic to show/hide this field based on specific fields value or conditions', 'ultimate-member' ) ); ?>
216
+ <?php } ?>
217
+
218
+ <div class="um-admin-btn-content">
219
+ <div class="um-admin-cur-condition-template">
220
+
221
+ <?php $metabox->field_input( '_conditional_action', $form_id ); ?>
222
+ <?php $metabox->field_input( '_conditional_field', $form_id ); ?>
223
+ <?php $metabox->field_input( '_conditional_operator', $form_id ); ?>
224
+ <?php $metabox->field_input( '_conditional_value', $form_id ); ?>
225
+
226
+ <p><a href="javascript:void(0);" class="um-admin-remove-condition button um-admin-tipsy-n" title="Remove condition"><i class="um-icon-close" style="margin-right:0!important"></i></a></p>
227
+
228
+ <div class="um-admin-clear"></div>
229
+ </div>
230
+ <p class="um-admin-conditions-notice">
231
+ <small>
232
+ <?php _e( 'Use the condition operator `equals to` or `not equals` if the parent field has a single option.', 'ultimate-member' ); ?>
233
+ <br><?php _e( 'Use the condition operator `greater than` or `less than` if the parent field is a number.', 'ultimate-member' ); ?>
234
+ <br><?php _e( 'Use the condition operator `contains` if the parent field has multiple options.', 'ultimate-member' ); ?>
235
+ </small>
236
+ </p>
237
+ <p><a href="javascript:void(0);" class="um-admin-new-condition button button-primary um-admin-tipsy-n" title="Add new condition"><?php _e( 'Add new rule', 'ultimate-member' ); ?></a></p>
238
+ <p class="um-admin-reset-conditions"><a href="javascript:void(0);" class="button"><?php _e( 'Reset all rules', 'ultimate-member' ); ?></a></p>
239
+
240
+ <div class="um-admin-clear"></div>
241
+
242
+ <?php if ( isset( $edit_array['conditions'] ) && count( $edit_array['conditions'] ) != 0 ) {
243
+
244
+ foreach ( $edit_array['conditions'] as $k => $arr ) {
245
+
246
+ if ( $k == 0 ) $k = ''; ?>
247
+
248
+ <div class="um-admin-cur-condition">
249
+
250
+ <?php $metabox->field_input( '_conditional_action' . $k, $form_id ); ?>
251
+ <?php $metabox->field_input( '_conditional_field' . $k , $form_id ); ?>
252
+ <?php $metabox->field_input( '_conditional_operator' . $k, $form_id ); ?>
253
+ <?php $metabox->field_input( '_conditional_value' . $k, $form_id ); ?>
254
+
255
+ <p><a href="#" class="um-admin-remove-condition button um-admin-tipsy-n" title="Remove condition"><i class="um-icon-close" style="margin-right:0!important"></i></a></p>
256
+
257
+ <div class="um-admin-clear"></div>
258
+ </div>
259
+
260
+ <?php
261
+ }
262
+
263
+ } else { ?>
264
+
265
+ <div class="um-admin-cur-condition">
266
+
267
+ <?php $metabox->field_input( '_conditional_action', $form_id ); ?>
268
+ <?php $metabox->field_input( '_conditional_field', $form_id ); ?>
269
+ <?php $metabox->field_input( '_conditional_operator', $form_id ); ?>
270
+ <?php $metabox->field_input( '_conditional_value', $form_id ); ?>
271
+
272
+ <p><a href="#" class="um-admin-remove-condition button um-admin-tipsy-n" title="Remove condition"><i class="um-icon-close" style="margin-right:0!important"></i></a></p>
273
+
274
+ <div class="um-admin-clear"></div>
275
+ </div>
276
+
277
+ <?php } ?>
278
+ </div>
279
+ </div>
280
+
281
+ <?php
282
+ }
283
+
284
+
285
+ /**
286
+ * Update the builder area
287
+ */
288
+ function update_builder() {
289
+ UM()->admin()->check_ajax_nonce();
290
+
291
+ if ( ! is_user_logged_in() || ! current_user_can( 'manage_options' ) ) {
292
+ wp_send_json_error( __( 'Please login as administrator', 'ultimate-member' ) );
293
+ }
294
+
295
+ ob_start();
296
+
297
+ $this->form_id = absint( $_POST['form_id'] );
298
+
299
+ $this->show_builder();
300
+
301
+ $output = ob_get_clean();
302
+
303
+ if ( is_array( $output ) ) {
304
+ print_r( $output );
305
+ } else {
306
+ echo $output;
307
+ }
308
+ die;
309
+ }
310
+
311
+
312
+ /**
313
+ * Sort array function
314
+ *
315
+ * @param array $arr
316
+ * @param string $col
317
+ * @param int $dir
318
+ *
319
+ * @return array
320
+ */
321
+ function array_sort_by_column( $arr, $col, $dir = SORT_ASC ) {
322
+ $sort_col = array();
323
+
324
+ foreach ( $arr as $key => $row ) {
325
+ if ( ! empty( $row[ $col ] ) ) {
326
+ $sort_col[ $key ] = $row[ $col ];
327
+ }
328
+ }
329
+
330
+ if ( ! empty( $sort_col ) ) {
331
+ array_multisort( $sort_col, $dir, $arr );
332
+ }
333
+
334
+ return $arr;
335
+ }
336
+
337
+
338
+ /**
339
+ * Get fields in row
340
+ *
341
+ * @param $row_id
342
+ *
343
+ * @return string
344
+ */
345
+ function get_fields_by_row( $row_id ) {
346
+
347
+ if ( empty( $this->global_fields ) || ! is_array( $this->global_fields ) ) {
348
+ $this->global_fields = array();
349
+ }
350
+
351
+ foreach ( $this->global_fields as $key => $array ) {
352
+ if ( ! isset( $array['in_row'] ) || ( isset( $array['in_row'] ) && $array['in_row'] == $row_id ) ) {
353
+ $results[ $key ] = $array;
354
+ unset( $this->global_fields[ $key ] );
355
+ }
356
+ }
357
+
358
+ return ( isset ( $results ) ) ? $results : '';
359
+ }
360
+
361
+
362
+ /**
363
+ * Get fields by sub row
364
+ *
365
+ * @param $row_fields
366
+ * @param $subrow_id
367
+ *
368
+ * @return string
369
+ */
370
+ function get_fields_in_subrow( $row_fields, $subrow_id ) {
371
+ if ( ! is_array( $row_fields ) ) {
372
+ return '';
373
+ }
374
+
375
+ foreach( $row_fields as $key => $array ) {
376
+ if ( ! isset( $array['in_sub_row'] ) || ( isset( $array['in_sub_row'] ) && $array['in_sub_row'] == $subrow_id ) ) {
377
+ $results[ $key ] = $array;
378
+ unset( $this->global_fields[ $key ] );
379
+ }
380
+ }
381
+
382
+ return ( isset ( $results ) ) ? $results : '';
383
+ }
384
+
385
+
386
+ /**
387
+ * Display the builder
388
+ */
389
+ function show_builder() {
390
+
391
+ $fields = UM()->query()->get_attr( 'custom_fields', $this->form_id );
392
+
393
+ if ( !isset( $fields ) || empty( $fields ) ) { ?>
394
+
395
+ <div class="um-admin-drag-row">
396
+
397
+ <!-- Master Row Actions -->
398
+ <div class="um-admin-drag-row-icons">
399
+ <a href="javascript:void(0);" class="um-admin-drag-rowsub-add um-admin-tipsy-n" title="<?php esc_attr_e( 'Add Row', 'ultimate-member' ); ?>" data-row_action="add_subrow"><i class="um-icon-plus"></i></a>
400
+ <a href="javascript:void(0);" class="um-admin-drag-row-edit um-admin-tipsy-n" title="<?php esc_attr_e( 'Edit Row', 'ultimate-member' ); ?>" data-modal="UM_edit_row" data-modal-size="normal" data-dynamic-content="um_admin_edit_field_popup" data-arg1="row" data-arg2="<?php echo esc_attr( $this->form_id ); ?>" data-arg3="_um_row_1"><i class="um-faicon-pencil"></i></a>
401
+ <span class="um-admin-drag-row-start"><i class="um-icon-arrow-move"></i></span>
402
+ </div>
403
+ <div class="um-admin-clear"></div>
404
+
405
+ <div class="um-admin-drag-rowsubs">
406
+ <div class="um-admin-drag-rowsub">
407
+
408
+ <!-- Column Layout -->
409
+ <div class="um-admin-drag-ctrls columns">
410
+ <a href="javascript:void(0);" class="active" data-cols="1"></a>
411
+ <a href="javascript:void(0);" data-cols="2"></a>
412
+ <a href="javascript:void(0);" data-cols="3"></a>
413
+ </div>
414
+
415
+ <!-- Sub Row Actions -->
416
+ <div class="um-admin-drag-rowsub-icons">
417
+ <span class="um-admin-drag-rowsub-start"><i class="um-icon-arrow-move"></i></span>
418
+ </div><div class="um-admin-clear"></div>
419
+
420
+ <!-- Columns -->
421
+ <div class="um-admin-drag-col">
422
+
423
+ </div>
424
+
425
+ <div class="um-admin-drag-col-dynamic"></div>
426
+
427
+ <div class="um-admin-clear"></div>
428
+
429
+ </div>
430
+ </div>
431
+
432
+ </div>
433
+
434
+ <?php
435
+
436
+ } else {
437
+
438
+ if ( empty( $fields ) || ! is_array( $fields ) ) {
439
+ $this->global_fields = array();
440
+ } else {
441
+ $this->global_fields = $fields;
442
+ }
443
+
444
+ foreach ( $this->global_fields as $key => $array ) {
445
+ if ( $array['type'] == 'row' ) {
446
+ $rows[ $key ] = $array;
447
+ unset( $this->global_fields[ $key ] ); // not needed now
448
+ }
449
+
450
+ }
451
+
452
+ if ( ! isset( $rows ) ) {
453
+ $rows = array(
454
+ '_um_row_1' => array(
455
+ 'type' => 'row',
456
+ 'id' => '_um_row_1',
457
+ 'sub_rows' => 1,
458
+ 'cols' => 1
459
+ ),
460
+ );
461
+ }
462
+
463
+ foreach ( $rows as $row_id => $array ) { ?>
464
+
465
+ <div class="um-admin-drag-row" data-original="<?php echo esc_attr( $row_id ); ?>">
466
+
467
+ <!-- Master Row Actions -->
468
+ <div class="um-admin-drag-row-icons">
469
+ <a href="javascript:void(0);" class="um-admin-drag-rowsub-add um-admin-tipsy-n" title="<?php esc_attr_e( 'Add Row', 'ultimate-member' ); ?>" data-row_action="add_subrow"><i class="um-icon-plus"></i></a>
470
+ <a href="javascript:void(0);" class="um-admin-drag-row-edit um-admin-tipsy-n" title="<?php esc_attr_e( 'Edit Row', 'ultimate-member'); ?>" data-modal="UM_edit_row" data-modal-size="normal" data-dynamic-content="um_admin_edit_field_popup" data-arg1="row" data-arg2="<?php echo esc_attr( $this->form_id ); ?>" data-arg3="<?php echo esc_attr( $row_id ); ?>"><i class="um-faicon-pencil"></i></a>
471
+ <span class="um-admin-drag-row-start"><i class="um-icon-arrow-move"></i></span>
472
+ <?php if ( $row_id != '_um_row_1' ) {?>
473
+ <a href="javascript:void(0);" class="um-admin-tipsy-n" title="<?php esc_attr_e( 'Delete Row', 'ultimate-member' ); ?>" data-remove_element="um-admin-drag-row"><i class="um-faicon-trash-o"></i></a>
474
+ <?php } ?>
475
+ </div><div class="um-admin-clear"></div>
476
+
477
+ <div class="um-admin-drag-rowsubs">
478
+
479
+ <?php $row_fields = $this->get_fields_by_row( $row_id );
480
+
481
+ $sub_rows = ( isset( $array['sub_rows'] ) ) ? $array['sub_rows'] : 1;
482
+ for ( $c = 0; $c < $sub_rows; $c++ ) {
483
+
484
+ $subrow_fields = $this->get_fields_in_subrow( $row_fields, $c );
485
+
486
+ ?>
487
+
488
+ <div class="um-admin-drag-rowsub">
489
+
490
+ <!-- Column Layout -->
491
+ <div class="um-admin-drag-ctrls columns">
492
+
493
+ <?php
494
+
495
+ if ( ! isset( $array['cols'] ) ) {
496
+ $col_num = 1;
497
+ } elseif ( is_numeric( $array['cols'] ) ) {
498
+ $col_num = (int) $array['cols'];
499
+ } else {
500
+ $col_split = explode( ':', $array['cols'] );
501
+ $col_num = $col_split[ $c ];
502
+ }
503
+
504
+ for ( $i = 1; $i <= 3; $i++ ) {
505
+ echo '<a href="javascript:void(0);" data-cols="'.$i.'" ';
506
+ if ( $col_num == $i ) echo 'class="active"';
507
+ echo '></a>';
508
+ }
509
+
510
+ ?>
511
+
512
+ </div>
513
+
514
+ <!-- Sub Row Actions -->
515
+ <div class="um-admin-drag-rowsub-icons">
516
+ <span class="um-admin-drag-rowsub-start"><i class="um-icon-arrow-move"></i></span>
517
+ <?php if ( $c > 0 ) { ?><a href="javascript:void(0);" class="um-admin-tipsy-n" title="Delete Row" data-remove_element="um-admin-drag-rowsub"><i class="um-faicon-trash-o"></i></a><?php } ?>
518
+ </div>
519
+ <div class="um-admin-clear"></div>
520
+
521
+ <!-- Columns -->
522
+ <div class="um-admin-drag-col">
523
+
524
+ <?php
525
+
526
+ if ( is_array( $subrow_fields ) ) {
527
+
528
+ $subrow_fields = $this->array_sort_by_column( $subrow_fields, 'position');
529
+
530
+ foreach( $subrow_fields as $key => $keyarray ) {
531
+ /**
532
+ * @var $type
533
+ * @var $title
534
+ */
535
+ extract( $keyarray );
536
+
537
+ ?>
538
+
539
+ <div class="um-admin-drag-fld um-admin-delete-area um-field-type-<?php echo $type; ?> <?php echo $key; ?>" data-group="<?php echo (isset($keyarray['in_group'])) ? $keyarray['in_group'] : ''; ?>" data-key="<?php echo $key; ?>" data-column="<?php echo ( isset($keyarray['in_column']) ) ? $keyarray['in_column'] : 1; ?>">
540
+
541
+ <div class="um-admin-drag-fld-title um-field-type-<?php echo $type; ?>">
542
+ <?php if ( $type == 'group' ) { ?>
543
+ <i class="um-icon-plus"></i>
544
+ <?php } else if ( isset($keyarray['icon']) && !empty( $keyarray['icon'] ) ) { ?>
545
+ <i class="<?php echo $keyarray['icon']; ?>"></i>
546
+ <?php } ?><?php echo ! empty( $keyarray['title'] ) ? $keyarray['title'] : __( '(no title)', 'ultimate-member' ); ?></div>
547
+ <?php $field_name = isset( UM()->builtin()->core_fields[$type]['name'] ) ? UM()->builtin()->core_fields[$type]['name'] : ''; ?>
548
+ <div class="um-admin-drag-fld-type um-field-type-<?php echo $type; ?>"><?php echo $field_name; ?></div>
549
+ <div class="um-admin-drag-fld-icons um-field-type-<?php echo $type; ?>">
550
+
551
+ <a href="javascript:void(0);" class="um-admin-tipsy-n" title="<?php esc_attr_e( 'Edit', 'ultimate-member' ) ?>" data-modal="UM_edit_field" data-modal-size="normal" data-dynamic-content="um_admin_edit_field_popup" data-arg1="<?php echo $type; ?>" data-arg2="<?php echo $this->form_id; ?>" data-arg3="<?php echo $key; ?>"><i class="um-faicon-pencil"></i></a>
552
+
553
+ <a href="javascript:void(0);" class="um-admin-tipsy-n um_admin_duplicate_field" title="<?php esc_attr_e( 'Duplicate', 'ultimate-member' ) ?>" data-silent_action="um_admin_duplicate_field" data-arg1="<?php echo $key; ?>" data-arg2="<?php echo $this->form_id; ?>"><i class="um-faicon-files-o"></i></a>
554
+
555
+ <?php if ( $type == 'group' ) { ?>
556
+
557
+ <a href="javascript:void(0);" class="um-admin-tipsy-n" title="<?php esc_attr_e( 'Delete Group', 'ultimate-member' ) ?>" data-remove_element="um-admin-drag-fld.um-field-type-group" data-silent_action="um_admin_remove_field" data-arg1="<?php echo $key; ?>" data-arg2="<?php echo $this->form_id; ?>"><i class="um-faicon-trash-o"></i></a>
558
+ <?php } else { ?>
559
+
560
+ <a href="javascript:void(0);" class="um-admin-tipsy-n" title="<?php esc_attr_e( 'Delete', 'ultimate-member' ) ?>" data-silent_action="um_admin_remove_field" data-arg1="<?php echo $key; ?>" data-arg2="<?php echo $this->form_id; ?>"><i class="um-faicon-trash-o"></i></a>
561
+
562
+ <?php } ?>
563
+
564
+ </div><div class="um-admin-clear"></div>
565
+
566
+ <?php if ( $type == 'group' ) { ?>
567
+ <div class="um-admin-drag-group">
568
+
569
+ </div>
570
+ <?php } ?>
571
+
572
+ </div>
573
+
574
+ <?php
575
+
576
+ } // end foreach
577
+
578
+ } // end if
579
+
580
+ ?>
581
+
582
+ </div>
583
+
584
+ <div class="um-admin-drag-col-dynamic"></div>
585
+
586
+ <div class="um-admin-clear"></div>
587
+
588
+ </div>
589
+
590
+ <?php } ?>
591
+
592
+ </div>
593
+
594
+ </div>
595
+
596
+ <?php
597
+
598
+ } // rows loop
599
+
600
+ } // if fields exist
601
+
602
+ }
603
+
604
+
605
+ /**
606
+ *
607
+ */
608
+ function update_field() {
609
+ UM()->admin()->check_ajax_nonce();
610
+
611
+ if ( ! is_user_logged_in() || ! current_user_can( 'manage_options' ) ) {
612
+ wp_send_json_error( __( 'Please login as administrator', 'ultimate-member' ) );
613
+ }
614
+
615
+ $output['error'] = null;
616
+
617
+ $array = array(
618
+ 'field_type' => sanitize_key( $_POST['_type'] ),
619
+ 'form_id' => absint( $_POST['post_id'] ),
620
+ 'args' => UM()->builtin()->get_core_field_attrs( sanitize_key( $_POST['_type'] ) ),
621
+ 'post' => UM()->admin()->sanitize_builder_field_meta( $_POST ),
622
+ );
623
+
624
+ /**
625
+ * UM hook
626
+ *
627
+ * @type filter
628
+ * @title um_admin_pre_save_fields_hook
629
+ * @description Filter field data before save
630
+ * @input_vars
631
+ * [{"var":"$array","type":"array","desc":"Save Field data"}]
632
+ * @change_log
633
+ * ["Since: 2.0"]
634
+ * @usage add_filter( 'um_admin_pre_save_fields_hook', 'function_name', 10, 1 );
635
+ * @example
636
+ * <?php
637
+ * add_filter( 'um_admin_pre_save_fields_hook', 'my_admin_pre_save_fields', 10, 1 );
638
+ * function my_admin_pre_save_fields( $array ) {
639
+ * // your code here
640
+ * return $array;
641
+ * }
642
+ * ?>
643
+ */
644
+ $array = apply_filters( 'um_admin_pre_save_fields_hook', $array );
645
+
646
+ /**
647
+ * UM hook
648
+ *
649
+ * @type filter
650
+ * @title um_admin_field_update_error_handling
651
+ * @description Change error string on save field
652
+ * @input_vars
653
+ * [{"var":"$error","type":"string","desc":"Error String"},
654
+ * {"var":"$array","type":"array","desc":"Save Field data"}]
655
+ * @change_log
656
+ * ["Since: 2.0"]
657
+ * @usage add_filter( 'um_admin_field_update_error_handling', 'function_name', 10, 2 );
658
+ * @example
659
+ * <?php
660
+ * add_filter( 'um_admin_field_update_error_handling', 'my_admin_field_update_error', 10, 2 );
661
+ * function my_admin_field_update_error( $error, $array ) {
662
+ * // your code here
663
+ * return $error;
664
+ * }
665
+ * ?>
666
+ */
667
+ $output['error'] = apply_filters( 'um_admin_field_update_error_handling', $output['error'], $array );
668
+
669
+ /**
670
+ * @var $_metakey
671
+ * @var $post_id
672
+ */
673
+ extract( $array['post'] );
674
+
675
+ if ( empty( $output['error'] ) ) {
676
+
677
+ $save = array();
678
+ $save[ $_metakey ] = null;
679
+ foreach ( $array['post'] as $key => $val ) {
680
+
681
+ if ( substr( $key, 0, 1 ) === '_' && $val !== '' ) { // field attribute
682
+ $new_key = ltrim ( $key, '_' );
683
+
684
+ if ( $new_key == 'options' ) {
685
+ //$save[ $_metakey ][$new_key] = explode(PHP_EOL, $val);
686
+ $save[ $_metakey ][ $new_key ] = preg_split( '/[\r\n]+/', $val, -1, PREG_SPLIT_NO_EMPTY );
687
+ } else {
688
+ $save[ $_metakey ][ $new_key ] = $val;
689
+ }
690
+
691
+ } elseif ( strstr( $key, 'um_editor' ) ) {
692
+
693
+ if ( 'block' === $array['post']['_type'] ) {
694
+ $save[ $_metakey ]['content'] = wp_kses_post( $val );
695
+ } else {
696
+ $save[ $_metakey ]['content'] = sanitize_textarea_field( $val );
697
+ }
698
+ }
699
+
700
+ }
701
+
702
+ $field_ID = $_metakey;
703
+ $field_args = $save[ $_metakey ];
704
+
705
+ /**
706
+ * UM hook
707
+ *
708
+ * @type filter
709
+ * @title um_admin_pre_save_field_to_form
710
+ * @description Change field options before save to form
711
+ * @input_vars
712
+ * [{"var":"$field_args","type":"array","desc":"Field Options"}]
713
+ * @change_log
714
+ * ["Since: 2.0"]
715
+ * @usage add_filter( 'um_admin_pre_save_field_to_form', 'function_name', 10, 1 );
716
+ * @example
717
+ * <?php
718
+ * add_filter( 'um_admin_pre_save_field_to_form', 'my_admin_pre_save_field_to_form', 10, 1 );
719
+ * function my_admin_pre_save_field_to_form( $field_args ) {
720
+ * // your code here
721
+ * return $field_args;
722
+ * }
723
+ * ?>
724
+ */
725
+ $field_args = apply_filters( 'um_admin_pre_save_field_to_form', $field_args );
726
+
727
+ UM()->fields()->update_field( $field_ID, $field_args, $post_id );
728
+
729
+ /**
730
+ * UM hook
731
+ *
732
+ * @type filter
733
+ * @title um_admin_pre_save_field_to_db
734
+ * @description Change field options before save to DB
735
+ * @input_vars
736
+ * [{"var":"$field_args","type":"array","desc":"Field Options"}]
737
+ * @change_log
738
+ * ["Since: 2.0"]
739
+ * @usage add_filter( 'um_admin_pre_save_field_to_db', 'function_name', 10, 1 );
740
+ * @example
741
+ * <?php
742
+ * add_filter( 'um_admin_pre_save_field_to_db', 'my_admin_pre_save_field_to_db', 10, 1 );
743
+ * function my_admin_pre_save_field_to_form( $field_args ) {
744
+ * // your code here
745
+ * return $field_args;
746
+ * }
747
+ * ?>
748
+ */
749
+ $field_args = apply_filters( 'um_admin_pre_save_field_to_db', $field_args );
750
+
751
+ if ( ! isset( $array['args']['form_only'] ) ) {
752
+ if ( ! isset( UM()->builtin()->predefined_fields[ $field_ID ] ) ) {
753
+ UM()->fields()->globally_update_field( $field_ID, $field_args );
754
+ }
755
+ }
756
+
757
+ }
758
+
759
+ $output = json_encode( $output );
760
+ if ( is_array( $output ) ) {
761
+ print_r( $output );
762
+ } else {
763
+ echo $output;
764
+ }
765
+ die;
766
+ }
767
+
768
+
769
+ /**
770
+ *
771
+ */
772
+ function dynamic_modal_content() {
773
+ UM()->admin()->check_ajax_nonce();
774
+
775
+ if ( ! is_user_logged_in() || ! current_user_can( 'manage_options' ) ) {
776
+ wp_send_json_error( __( 'Please login as administrator', 'ultimate-member' ) );
777
+ }
778
+
779
+ $metabox = UM()->metabox();
780
+
781
+ /**
782
+ * @var $act_id
783
+ * @var $arg1
784
+ * @var $arg2
785
+ * @var $arg3
786
+ */
787
+ extract( $_POST );
788
+
789
+ if ( isset( $arg1 ) ) {
790
+ $arg1 = sanitize_text_field( $arg1 );
791
+ }
792
+
793
+ if ( isset( $arg2 ) ) {
794
+ $arg2 = sanitize_text_field( $arg2 );
795
+ }
796
+
797
+ if ( isset( $arg3 ) ) {
798
+ $arg3 = sanitize_text_field( $arg3 );
799
+ }
800
+
801
+ switch ( sanitize_key( $act_id ) ) {
802
+
803
+ default:
804
+
805
+ ob_start();
806
+
807
+ /**
808
+ * UM hook
809
+ *
810
+ * @type action
811
+ * @title um_admin_ajax_modal_content__hook
812
+ * @description Integration hook on ajax popup admin builder modal content
813
+ * @input_vars
814
+ * [{"var":"$act_id","type":"string","desc":"Ajax Action"}]
815
+ * @change_log
816
+ * ["Since: 2.0"]
817
+ * @usage add_action( 'um_admin_ajax_modal_content__hook', 'function_name', 10, 1 );
818
+ * @example
819
+ * <?php
820
+ * add_action( 'um_admin_ajax_modal_content__hook', 'my_admin_custom_hook', 10, 1 );
821
+ * function um_admin_ajax_modal_content__hook( $act_id ) {
822
+ * // your code here
823
+ * }
824
+ * ?>
825
+ */
826
+ do_action( 'um_admin_ajax_modal_content__hook', sanitize_key( $act_id ) );
827
+ /**
828
+ * UM hook
829
+ *
830
+ * @type action
831
+ * @title um_admin_ajax_modal_content__hook_{$act_id}
832
+ * @description Integration hook on ajax popup admin builder modal content
833
+ * @change_log
834
+ * ["Since: 2.0"]
835
+ * @usage add_action( 'um_admin_ajax_modal_content__hook_{$act_id}', 'function_name', 10 );
836
+ * @example
837
+ * <?php
838
+ * add_action( 'um_admin_ajax_modal_content__hook_{$act_id}', 'my_admin_ajax_modal_content', 10 );
839
+ * function my_admin_ajax_modal_content() {
840
+ * // your code here
841
+ * }
842
+ * ?>
843
+ */
844
+ do_action( "um_admin_ajax_modal_content__hook_" . sanitize_key( $act_id ) );
845
+
846
+ $output = ob_get_clean();
847
+ break;
848
+
849
+ case 'um_admin_fonticon_selector':
850
+
851
+ ob_start(); ?>
852
+
853
+ <div class="um-admin-metabox">
854
+ <p class="_icon_search"><input type="text" name="_icon_search" id="_icon_search" value="" placeholder="<?php esc_attr_e('Search Icons...', 'ultimate-member' ); ?>" /></p>
855
+ </div>
856
+
857
+ <div class="um-admin-icons">
858
+ <?php foreach( UM()->fonticons()->all as $icon ) { ?>
859
+ <span data-code="<?php echo esc_attr( $icon ); ?>" title="<?php echo esc_attr( $icon ); ?>" class="um-admin-tipsy-n"><i class="<?php echo $icon; ?>"></i></span>
860
+ <?php } ?>
861
+ </div><div class="um-admin-clear"></div>
862
+
863
+ <?php $output = ob_get_clean();
864
+ break;
865
+
866
+ case 'um_admin_show_fields':
867
+
868
+ ob_start();
869
+ $form_fields = UM()->query()->get_attr( 'custom_fields', $arg2 );
870
+ $form_fields = array_values( array_filter( array_keys( $form_fields ) ) );
871
+ //$form_fields = array_keys( $form_fields );
872
+ ?>
873
+
874
+ <h4><?php _e('Setup New Field','ultimate-member'); ?></h4>
875
+ <div class="um-admin-btns">
876
+
877
+ <?php if ( UM()->builtin()->core_fields ) {
878
+ foreach ( UM()->builtin()->core_fields as $field_type => $array ) {
879
+
880
+ if ( isset( $array['in_fields'] ) && $array['in_fields'] == false ) {
881
+ continue;
882
+ } ?>
883
+
884
+ <a href="javascript:void(0);" class="button" data-modal="UM_add_field" data-modal-size="normal" data-dynamic-content="um_admin_new_field_popup" data-arg1="<?php echo esc_attr( $field_type ); ?>" data-arg2="<?php echo esc_attr( $arg2 ) ?>"><?php echo esc_html( $array['name'] ); ?></a>
885
+
886
+ <?php }
887
+ } ?>
888
+
889
+ </div>
890
+
891
+ <h4><?php _e('Predefined Fields','ultimate-member'); ?></h4>
892
+ <div class="um-admin-btns">
893
+
894
+ <?php if ( UM()->builtin()->predefined_fields ) {
895
+ foreach ( UM()->builtin()->predefined_fields as $field_key => $array ) {
896
+ if ( ! isset( $array['account_only'] ) && ! isset( $array['private_use'] ) ) { ?>
897
+
898
+ <a href="javascript:void(0);" class="button" <?php disabled( in_array( $field_key, $form_fields, true ) ) ?> data-silent_action="um_admin_add_field_from_predefined" data-arg1="<?php echo esc_attr( $field_key ); ?>" data-arg2="<?php echo esc_attr( $arg2 ); ?>"><?php echo um_trim_string( stripslashes( $array['title'] ), 20 ); ?></a>
899
+
900
+ <?php }
901
+ }
902
+ } else {
903
+ echo '<p>' . __( 'None', 'ultimate-member' ) . '</p>';
904
+ } ?>
905
+
906
+ </div>
907
+
908
+ <h4><?php _e( 'Custom Fields', 'ultimate-member' ); ?></h4>
909
+ <div class="um-admin-btns">
910
+
911
+ <?php
912
+ if ( UM()->builtin()->custom_fields ) {
913
+ foreach ( UM()->builtin()->custom_fields as $field_key => $array ) {
914
+ if ( empty( $array['title'] ) || empty( $array['type'] ) ) {
915
+ continue;
916
+ } ?>
917
+
918
+ <a href="javascript:void(0);" class="button with-icon" <?php disabled( in_array( $field_key, $form_fields, true ) ) ?> data-silent_action="um_admin_add_field_from_list" data-arg1="<?php echo esc_attr( $field_key ); ?>" data-arg2="<?php echo esc_attr( $arg2 ); ?>" title="<?php echo __( 'Meta Key', 'ultimate-member' ) . ' - ' . esc_attr( $field_key ); ?>"><?php echo um_trim_string( stripslashes( $array['title'] ), 20 ); ?> <small>(<?php echo ucfirst( $array['type'] ); ?>)</small><span class="remove"></span></a>
919
+
920
+ <?php }
921
+ } else {
922
+ echo '<p>' . __( 'You did not create any custom fields', 'ultimate-member' ) . '</p>';
923
+ } ?>
924
+
925
+ </div>
926
+
927
+ <?php $output = ob_get_clean();
928
+ break;
929
+
930
+ case 'um_admin_edit_field_popup':
931
+
932
+ ob_start();
933
+
934
+ $args = UM()->builtin()->get_core_field_attrs( $arg1 );
935
+
936
+ $form_fields = UM()->query()->get_attr( 'custom_fields', $arg2 );
937
+
938
+ $metabox->set_field_type = $arg1;
939
+ $metabox->in_edit = true;
940
+ $metabox->edit_array = $form_fields[ $arg3 ];
941
+
942
+ if ( !isset( $metabox->edit_array['metakey'] ) ){
943
+ $metabox->edit_array['metakey'] = $metabox->edit_array['id'];
944
+ }
945
+
946
+ if ( !isset( $metabox->edit_array['position'] ) ){
947
+ $metabox->edit_array['position'] = $metabox->edit_array['id'];
948
+ }
949
+
950
+ extract( $args );
951
+
952
+ if ( ! isset( $col1 ) ) {
953
+
954
+ echo '<p>'. __( 'This field type is not setup correcty.', 'ultimate-member' ) . '</p>';
955
+
956
+ } else {
957
+
958
+ ?>
959
+
960
+ <?php if ( isset( $metabox->edit_array['in_group'] ) ) { ?>
961
+ <input type="hidden" name="_in_row" id="_in_row" value="<?php echo $metabox->edit_array['in_row']; ?>" />
962
+ <input type="hidden" name="_in_sub_row" id="_in_sub_row" value="<?php echo $metabox->edit_array['in_sub_row']; ?>" />
963
+ <input type="hidden" name="_in_column" id="_in_column" value="<?php echo $metabox->edit_array['in_column']; ?>" />
964
+ <input type="hidden" name="_in_group" id="_in_group" value="<?php echo $metabox->edit_array['in_group']; ?>" />
965
+ <?php } ?>
966
+
967
+ <input type="hidden" name="_type" id="_type" value="<?php echo $arg1; ?>" />
968
+
969
+ <input type="hidden" name="post_id" id="post_id" value="<?php echo $arg2; ?>" />
970
+
971
+ <input type="hidden" name="edit_mode" id="edit_mode" value="true" />
972
+
973
+ <input type="hidden" name="_metakey" id="_metakey" value="<?php echo $metabox->edit_array['metakey']; ?>" />
974
+
975
+ <input type="hidden" name="_position" id="_position" value="<?php echo $metabox->edit_array['position']; ?>" />
976
+
977
+ <?php if ( isset( $args['mce_content'] ) ) { ?>
978
+ <div class="dynamic-mce-content"><?php echo ! empty( $metabox->edit_array['content'] ) ? $metabox->edit_array['content'] : ''; ?></div>
979
+ <?php } ?>
980
+
981
+ <?php $this->modal_header(); ?>
982
+
983
+ <div class="um-admin-half">
984
+
985
+ <?php if ( isset( $col1 ) ) { foreach( $col1 as $opt ) $metabox->field_input ( $opt, $arg2, $metabox->edit_array ); } ?>
986
+
987
+ </div>
988
+
989
+ <div class="um-admin-half um-admin-right">
990
+
991
+ <?php if ( isset( $col2 ) ) { foreach( $col2 as $opt ) $metabox->field_input ( $opt, $arg2, $metabox->edit_array ); } ?>
992
+
993
+ </div><div class="um-admin-clear"></div>
994
+
995
+ <?php if ( isset( $col3 ) ) { foreach( $col3 as $opt ) $metabox->field_input ( $opt, $arg2, $metabox->edit_array ); } ?>
996
+
997
+ <div class="um-admin-clear"></div>
998
+
999
+ <?php if ( isset( $col_full ) ) {foreach( $col_full as $opt ) $metabox->field_input ( $opt, $arg2, $metabox->edit_array ); } ?>
1000
+
1001
+ <?php $this->modal_footer( $arg2, $args, $metabox ); ?>
1002
+
1003
+ <?php
1004
+
1005
+ }
1006
+
1007
+ $output = ob_get_clean();
1008
+ break;
1009
+
1010
+ case 'um_admin_new_field_popup':
1011
+
1012
+ ob_start();
1013
+
1014
+ $args = UM()->builtin()->get_core_field_attrs( $arg1 );
1015
+
1016
+ $metabox->set_field_type = $arg1;
1017
+
1018
+ /**
1019
+ * @var $in_row
1020
+ * @var $in_sub_row
1021
+ * @var $in_column
1022
+ * @var $in_group
1023
+ */
1024
+ extract( $args );
1025
+
1026
+ if ( ! isset( $col1 ) ) {
1027
+
1028
+ echo '<p>'. __( 'This field type is not setup correcty.', 'ultimate-member' ) . '</p>';
1029
+
1030
+ } else {
1031
+
1032
+ if ( $in_column ) { ?>
1033
+ <input type="hidden" name="_in_row" id="_in_row" value="_um_row_<?php echo $in_row + 1; ?>" />
1034
+ <input type="hidden" name="_in_sub_row" id="_in_sub_row" value="<?php echo $in_sub_row; ?>" />
1035
+ <input type="hidden" name="_in_column" id="_in_column" value="<?php echo $in_column; ?>" />
1036
+ <input type="hidden" name="_in_group" id="_in_group" value="<?php echo $in_group; ?>" />
1037
+ <?php } ?>
1038
+
1039
+ <input type="hidden" name="_type" id="_type" value="<?php echo $arg1; ?>" />
1040
+
1041
+ <input type="hidden" name="post_id" id="post_id" value="<?php echo $arg2; ?>" />
1042
+
1043
+ <?php $this->modal_header(); ?>
1044
+
1045
+ <div class="um-admin-half">
1046
+
1047
+ <?php if ( isset( $col1 ) ) { foreach( $col1 as $opt ) $metabox->field_input ( $opt ); } ?>
1048
+
1049
+ </div>
1050
+
1051
+ <div class="um-admin-half um-admin-right">
1052
+
1053
+ <?php if ( isset( $col2 ) ) { foreach( $col2 as $opt ) $metabox->field_input ( $opt ); } ?>
1054
+
1055
+ </div><div class="um-admin-clear"></div>
1056
+
1057
+ <?php if ( isset( $col3 ) ) { foreach( $col3 as $opt ) $metabox->field_input ( $opt ); } ?>
1058
+
1059
+ <div class="um-admin-clear"></div>
1060
+
1061
+ <?php if ( isset( $col_full ) ) { foreach( $col_full as $opt ) $metabox->field_input ( $opt ); } ?>
1062
+
1063
+ <?php $this->modal_footer( $arg2, $args, $metabox ); ?>
1064
+
1065
+ <?php
1066
+
1067
+ }
1068
+
1069
+ $output = ob_get_clean();
1070
+ break;
1071
+
1072
+ case 'um_admin_preview_form':
1073
+
1074
+ UM()->user()->preview = true;
1075
+
1076
+ $mode = UM()->query()->get_attr('mode', $arg1 );
1077
+
1078
+ if ( $mode == 'profile' ) {
1079
+ UM()->fields()->editing = true;
1080
+ }
1081
+
1082
+ $output = '<div class="um-admin-preview-overlay"></div>';
1083
+
1084
+ if ( version_compare( get_bloginfo('version'),'5.4', '<' ) ) {
1085
+ $output .= do_shortcode('[ultimatemember form_id="' . $arg1 . '" /]');
1086
+ } else {
1087
+ $output .= apply_shortcodes('[ultimatemember form_id="' . $arg1 . '" /]');
1088
+ }
1089
+
1090
+ break;
1091
+
1092
+ case 'um_admin_review_registration':
1093
+ //$user_id = $arg1;
1094
+
1095
+ if ( ! current_user_can( 'administrator' ) ) {
1096
+ if ( ! um_can_view_profile( $arg1 ) ) {
1097
+ $output = '';
1098
+ break;
1099
+ }
1100
+ }
1101
+
1102
+ um_fetch_user( $arg1 );
1103
+
1104
+ UM()->user()->preview = true;
1105
+
1106
+ $output = um_user_submitted_registration_formatted( true );
1107
+
1108
+ um_reset_user();
1109
+
1110
+ break;
1111
+
1112
+ }
1113
+
1114
+ if ( is_array( $output ) ) {
1115
+ print_r( $output );
1116
+ } else {
1117
+ echo $output;
1118
+ }
1119
+ die;
1120
+ }
1121
+
1122
+
1123
+ /**
1124
+ *
1125
+ */
1126
+ function modal_header() {
1127
+ /**
1128
+ * UM hook
1129
+ *
1130
+ * @type action
1131
+ * @title um_admin_field_modal_header
1132
+ * @description Modal Window Header
1133
+ * @change_log
1134
+ * ["Since: 2.0"]
1135
+ * @usage add_action( 'um_admin_field_modal_header', 'function_name', 10 );
1136
+ * @example
1137
+ * <?php
1138
+ * add_action( 'um_admin_field_modal_header', 'my_admin_field_modal_header', 10 );
1139
+ * function my_admin_field_modal_header() {
1140
+ * // your code here
1141
+ * }
1142
+ * ?>
1143
+ */
1144
+ do_action( 'um_admin_field_modal_header' );
1145
+ }
1146
+
1147
+
1148
+ /**
1149
+ * Modal Footer loading
1150
+ *
1151
+ * @param $arg2
1152
+ * @param $args
1153
+ * @param $metabox
1154
+ */
1155
+ function modal_footer( $arg2, $args, $metabox ) {
1156
+ /**
1157
+ * UM hook
1158
+ *
1159
+ * @type action
1160
+ * @title um_admin_field_modal_footer
1161
+ * @description Modal Window Footer
1162
+ * @input_vars
1163
+ * [{"var":"$arg2","type":"string","desc":"Ajax Action"},
1164
+ * {"var":"$args","type":"array","desc":"Modal window arguments"},
1165
+ * {"var":"$in_edit","type":"bool","desc":"Is edit mode?"},
1166
+ * {"var":"$edit_array","type":"array","desc":"Edit Array"}]
1167
+ * @change_log
1168
+ * ["Since: 2.0"]
1169
+ * @usage add_action( 'um_admin_field_modal_footer', 'function_name', 10, 4 );
1170
+ * @example
1171
+ * <?php
1172
+ * add_action( 'um_admin_field_modal_footer', 'my_admin_field_modal_footer', 10, 4 );
1173
+ * function my_admin_field_modal_footer( $arg2, $args, $in_edit, $edit_array ) {
1174
+ * // your code here
1175
+ * }
1176
+ * ?>
1177
+ */
1178
+ do_action( 'um_admin_field_modal_footer', $arg2, $args, $metabox->in_edit, ( isset( $metabox->edit_array ) ) ? $metabox->edit_array : '' );
1179
+ }
1180
+
1181
+
1182
+ /**
1183
+ * Skip field validation for:
1184
+ * - '_options' if Choices Callback specified
1185
+ *
1186
+ * @param boolean $skip
1187
+ * @param string $post_input
1188
+ * @param array $array
1189
+ * @return boolean
1190
+ */
1191
+ public function skip_field_validation( $skip, $post_input, $array ) {
1192
+ if ( $post_input === '_options' && isset( $array['post']['_custom_dropdown_options_source'] ) ) {
1193
+ $skip = function_exists( wp_unslash( $array['post']['_custom_dropdown_options_source'] ) );
1194
+ }
1195
+
1196
+ return $skip;
1197
+ }
1198
+
1199
+
1200
+ /**
1201
+ * Retrieves dropdown/multi-select options from a callback function
1202
+ */
1203
+ function populate_dropdown_options() {
1204
+ UM()->admin()->check_ajax_nonce();
1205
+
1206
+ if ( ! is_user_logged_in() || ! current_user_can( 'manage_options' ) ) {
1207
+ wp_send_json_error( __( 'This is not possible for security reasons.', 'ultimate-member' ) );
1208
+ }
1209
+
1210
+ $arr_options = array();
1211
+
1212
+ // we can not use `sanitize_key()` because it removes backslash needed for namespace and uppercase symbols
1213
+ $um_callback_func = sanitize_text_field( $_POST['um_option_callback'] );
1214
+ // removed added by sanitize slashes for the namespaces
1215
+ $um_callback_func = wp_unslash( $um_callback_func );
1216
+
1217
+ if ( empty( $um_callback_func ) ) {
1218
+ $arr_options['status'] = 'empty';
1219
+ $arr_options['function_name'] = $um_callback_func;
1220
+ $arr_options['function_exists'] = function_exists( $um_callback_func );
1221
+ }
1222
+
1223
+ if ( in_array( $um_callback_func, UM()->fields()->dropdown_options_source_blacklist(), true ) ) {
1224
+ wp_send_json_error( __( 'This is not possible for security reasons. Don\'t use internal PHP functions.', 'ultimate-member' ) );
1225
+ }
1226
+
1227
+ $arr_options['data'] = array();
1228
+ if ( function_exists( $um_callback_func ) ) {
1229
+ $arr_options['data'] = call_user_func( $um_callback_func );
1230
+ }
1231
+
1232
+ wp_send_json( $arr_options );
1233
+ }
1234
+
1235
+ }
1236
+ }
includes/admin/core/class-admin-settings.php CHANGED
@@ -1,3478 +1,3477 @@
1
- <?php
2
- namespace um\admin\core;
3
-
4
- if ( ! defined( 'ABSPATH' ) ) {
5
- exit;
6
- }
7
-
8
- if ( ! class_exists( 'um\admin\core\Admin_Settings' ) ) {
9
-
10
-
11
- /**
12
- * Class Admin_Settings
13
- * @package um\admin\core
14
- */
15
- class Admin_Settings {
16
-
17
-
18
- /**
19
- * @var array
20
- */
21
- public $settings_map;
22
-
23
-
24
- /**
25
- * @var array
26
- */
27
- public $settings_structure;
28
-
29
-
30
- /**
31
- * @var
32
- */
33
- private $previous_licenses;
34
-
35
-
36
- /**
37
- * @var
38
- */
39
- private $need_change_permalinks;
40
-
41
-
42
- private $gravatar_changed = false;
43
-
44
-
45
- /**
46
- * Admin_Settings constructor.
47
- */
48
- public function __construct() {
49
- //init settings structure
50
- add_action( 'admin_init', array( &$this, 'init_variables' ), 9 );
51
-
52
- //admin menu
53
- add_action( 'admin_menu', array( &$this, 'primary_admin_menu' ), 0 );
54
-
55
- //settings structure handlers
56
- add_action( 'um_settings_page_before_email__content', array( $this, 'settings_before_email_tab' ) );
57
- add_filter( 'um_settings_section_email__content', array( $this, 'settings_email_tab' ), 10, 1 );
58
-
59
- //enqueue wp_media for profiles tab
60
- add_action( 'um_settings_page_appearance__before_section', array( $this, 'settings_appearance_profile_tab' ) );
61
-
62
- //custom content for licenses tab
63
- add_filter( 'um_settings_section_licenses__content', array( $this, 'settings_licenses_tab' ), 10, 2 );
64
-
65
- add_filter( 'um_settings_section_install_info__content', array( $this, 'settings_install_info_tab' ), 10, 2 );
66
-
67
-
68
- add_filter( 'um_settings_structure', array( $this, 'sorting_licenses_options' ), 9999, 1 );
69
-
70
-
71
- //save handlers
72
- add_action( 'admin_init', array( $this, 'save_settings_handler' ), 10 );
73
-
74
- //save pages options
75
- add_action( 'um_settings_before_save', array( $this, 'check_permalinks_changes' ) );
76
- add_action( 'um_settings_save', array( $this, 'on_settings_save' ) );
77
-
78
-
79
- add_filter( 'um_change_settings_before_save', array( $this, 'save_email_templates' ) );
80
-
81
-
82
- //save licenses options
83
- add_action( 'um_settings_before_save', array( $this, 'before_licenses_save' ) );
84
- add_action( 'um_settings_save', array( $this, 'licenses_save' ) );
85
-
86
- add_filter( 'um_change_settings_before_save', array( $this, 'set_default_if_empty' ), 9, 1 );
87
- add_filter( 'um_change_settings_before_save', array( $this, 'remove_empty_values' ), 10, 1 );
88
-
89
- add_action( 'admin_init', array( &$this, 'um_download_install_info' ) );
90
- }
91
-
92
-
93
-
94
- public function same_page_update_ajax() {
95
- UM()->admin()->check_ajax_nonce();
96
-
97
- if ( empty( $_POST['cb_func'] ) ) {
98
- wp_send_json_error( __( 'Wrong callback', 'ultimate-member' ) );
99
- }
100
-
101
- $cb_func = sanitize_key( $_POST['cb_func'] );
102
-
103
- if ( 'um_usermeta_fields' === $cb_func ) {
104
- //first install metatable
105
- global $wpdb;
106
-
107
- $metakeys = array();
108
- foreach ( UM()->builtin()->all_user_fields as $all_user_field ) {
109
- $metakeys[] = $all_user_field['metakey'];
110
- }
111
-
112
- $metakeys = apply_filters( 'um_metadata_same_page_update_ajax', $metakeys, UM()->builtin()->all_user_fields );
113
-
114
- if ( is_multisite() ) {
115
-
116
- $sites = get_sites( array( 'fields' => 'ids' ) );
117
- foreach ( $sites as $blog_id ) {
118
- $metakeys[] = $wpdb->get_blog_prefix( $blog_id ) . 'capabilities';
119
- }
120
- } else {
121
- $blog_id = get_current_blog_id();
122
- $metakeys[] = $wpdb->get_blog_prefix( $blog_id ) . 'capabilities';
123
- }
124
-
125
- //member directory data
126
- $metakeys[] = 'um_member_directory_data';
127
- $metakeys[] = '_um_verified';
128
- $metakeys[] = '_money_spent';
129
- $metakeys[] = '_completed';
130
- $metakeys[] = '_reviews_avg';
131
-
132
- //myCred meta
133
- if ( function_exists( 'mycred_get_types' ) ) {
134
- $mycred_types = mycred_get_types();
135
- if ( ! empty( $mycred_types ) ) {
136
- foreach ( array_keys( $mycred_types ) as $point_type ) {
137
- $metakeys[] = $point_type;
138
- }
139
- }
140
- }
141
-
142
- $sortby_custom_keys = $wpdb->get_col( "SELECT DISTINCT meta_value FROM {$wpdb->postmeta} WHERE meta_key='_um_sortby_custom'" );
143
- if ( empty( $sortby_custom_keys ) ) {
144
- $sortby_custom_keys = array();
145
- }
146
-
147
- $sortby_custom_keys2 = $wpdb->get_col( "SELECT meta_value FROM {$wpdb->postmeta} WHERE meta_key='_um_sorting_fields'" );
148
- if ( ! empty( $sortby_custom_keys2 ) ) {
149
- foreach ( $sortby_custom_keys2 as $custom_val ) {
150
- $custom_val = maybe_unserialize( $custom_val );
151
-
152
- foreach ( $custom_val as $sort_value ) {
153
- if ( is_array( $sort_value ) ) {
154
- $field_keys = array_keys( $sort_value );
155
- $sortby_custom_keys[] = $field_keys[0];
156
- }
157
- }
158
- }
159
- }
160
-
161
- if ( ! empty( $sortby_custom_keys ) ) {
162
- $sortby_custom_keys = array_unique( $sortby_custom_keys );
163
- $metakeys = array_merge( $metakeys, $sortby_custom_keys );
164
- }
165
-
166
- $skip_fields = UM()->builtin()->get_fields_without_metakey();
167
- $skip_fields = array_merge( $skip_fields, UM()->member_directory()->core_search_fields );
168
-
169
- $real_usermeta = $wpdb->get_col( "SELECT DISTINCT meta_key FROM {$wpdb->usermeta}" );
170
- $real_usermeta = ! empty( $real_usermeta ) ? $real_usermeta : array();
171
- $real_usermeta = array_merge( $real_usermeta, array( 'um_member_directory_data' ) );
172
-
173
- if ( ! empty( $sortby_custom_keys ) ) {
174
- $real_usermeta = array_merge( $real_usermeta, $sortby_custom_keys );
175
- }
176
-
177
- $wp_usermeta_option = array_intersect( array_diff( $metakeys, $skip_fields ), $real_usermeta );
178
-
179
- update_option( 'um_usermeta_fields', array_values( $wp_usermeta_option ) );
180
-
181
- update_option( 'um_member_directory_update_meta', time() );
182
-
183
- UM()->options()->update( 'member_directory_own_table', true );
184
-
185
- wp_send_json_success();
186
- } elseif ( 'um_get_metadata' === $cb_func ) {
187
- global $wpdb;
188
-
189
- $wp_usermeta_option = get_option( 'um_usermeta_fields', array() );
190
-
191
- $count = $wpdb->get_var(
192
- "SELECT COUNT(*)
193
- FROM {$wpdb->usermeta}
194
- WHERE meta_key IN ('" . implode( "','", $wp_usermeta_option ) . "')"
195
- );
196
-
197
- wp_send_json_success( array( 'count' => $count ) );
198
- } elseif ( 'um_update_metadata_per_page' === $cb_func ) {
199
-
200
- if ( empty( $_POST['page'] ) ) {
201
- wp_send_json_error( __( 'Wrong data', 'ultimate-member' ) );
202
- }
203
-
204
- $per_page = 500;
205
- $wp_usermeta_option = get_option( 'um_usermeta_fields', array() );
206
-
207
- global $wpdb;
208
- $metadata = $wpdb->get_results(
209
- $wpdb->prepare(
210
- "SELECT *
211
- FROM {$wpdb->usermeta}
212
- WHERE meta_key IN ('" . implode( "','", $wp_usermeta_option ) . "')
213
- LIMIT %d, %d",
214
- ( absint( $_POST['page'] ) - 1 ) * $per_page,
215
- $per_page
216
- ),
217
- ARRAY_A
218
- );
219
-
220
- $values = array();
221
- foreach ( $metadata as $metarow ) {
222
- $values[] = $wpdb->prepare( '(%d, %s, %s)', $metarow['user_id'], $metarow['meta_key'], $metarow['meta_value'] );
223
- }
224
-
225
- if ( ! empty( $values ) ) {
226
- $wpdb->query(
227
- "INSERT INTO
228
- {$wpdb->prefix}um_metadata(user_id, um_key, um_value)
229
- VALUES " . implode( ',', $values )
230
- );
231
- }
232
-
233
- $from = ( absint( $_POST['page'] ) * $per_page ) - $per_page + 1;
234
- $to = absint( $_POST['page'] ) * $per_page;
235
-
236
- wp_send_json_success( array( 'message' => sprintf( __( 'Metadata from %1$s to %2$s was upgraded successfully...', 'ultimate-member' ), $from, $to ) ) );
237
- } else {
238
- do_action( 'um_same_page_update_ajax_action', $cb_func );
239
- }
240
- }
241
-
242
-
243
- /**
244
- *
245
- */
246
- public function init_variables() {
247
-
248
- $settings_map = array();
249
-
250
- $general_pages_fields = array(
251
- array(
252
- 'id' => 'pages_settings',
253
- 'type' => 'hidden',
254
- 'value' => true,
255
- 'is_option' => false,
256
- ),
257
- );
258
-
259
- $core_pages = UM()->config()->core_pages;
260
-
261
- foreach ( $core_pages as $page_s => $page ) {
262
- $have_pages = UM()->query()->wp_pages();
263
- $page_id = UM()->options()->get_core_page_id( $page_s );
264
-
265
- $page_title = ! empty( $page['title'] ) ? $page['title'] : '';
266
-
267
- if ( 'reached_maximum_limit' === $have_pages ) {
268
- $general_pages_fields[] = array(
269
- 'id' => $page_id,
270
- 'type' => 'text',
271
- // translators: %s: Page title
272
- 'label' => sprintf( __( '%s page', 'ultimate-member' ), $page_title ),
273
- 'placeholder' => __( 'Add page ID', 'ultimate-member' ),
274
- 'compiler' => true,
275
- 'size' => 'small',
276
- );
277
- } else {
278
- $general_pages_fields[] = array(
279
- 'id' => $page_id,
280
- 'type' => 'select',
281
- // translators: %s: Page title
282
- 'label' => sprintf( __( '%s page', 'ultimate-member' ), $page_title ),
283
- 'options' => UM()->query()->wp_pages(),
284
- 'placeholder' => __( 'Choose a page...', 'ultimate-member' ),
285
- 'compiler' => true,
286
- 'size' => 'small',
287
- );
288
- }
289
-
290
-
291
- $settings_map[ $page_id ] = array(
292
- 'sanitize' => 'absint',
293
- );
294
- }
295
-
296
- $appearances_profile_menu_fields = array(
297
- array(
298
- 'id' => 'profile_menu',
299
- 'type' => 'checkbox',
300
- 'label' => __( 'Enable profile menu', 'ultimate-member' ),
301
- ),
302
- );
303
-
304
- $settings_map['profile_menu'] = array(
305
- 'sanitize' => 'bool',
306
- );
307
-
308
- $tabs = UM()->profile()->tabs();
309
-
310
- $tabs_options = array();
311
- $tabs_condition = array();
312
- foreach ( $tabs as $id => $tab ) {
313
-
314
- if ( ! empty( $tab['hidden'] ) ) {
315
- continue;
316
- }
317
-
318
- if ( isset( $tab['name'] ) ) {
319
- $tabs_options[ $id ] = $tab['name'];
320
- $tabs_condition[] = 'profile_tab_' . $id;
321
- }
322
-
323
- if ( isset( $tab['default_privacy'] ) ) {
324
- $fields = array(
325
- array(
326
- 'id' => 'profile_tab_' . $id,
327
- 'type' => 'checkbox',
328
- // translators: %s: Tab title
329
- 'label' => sprintf( __( '%s Tab', 'ultimate-member' ), $tab['name'] ),
330
- 'conditional' => array( 'profile_menu', '=', 1 ),
331
- 'data' => array( 'fill_profile_menu_default_tab' => $id ),
332
- ),
333
- );
334
-
335
- $settings_map[ 'profile_tab_' . $id ] = array(
336
- 'sanitize' => 'bool',
337
- );
338
- } else {
339
-
340
- $fields = array(
341
- array(
342
- 'id' => 'profile_tab_' . $id,
343
- 'type' => 'checkbox',
344
- // translators: %s: Tab title
345
- 'label' => sprintf( __( '%s Tab', 'ultimate-member' ), $tab['name'] ),
346
- 'conditional' => array( 'profile_menu', '=', 1 ),
347
- 'data' => array( 'fill_profile_menu_default_tab' => $id ),
348
- ),
349
- array(
350
- 'id' => 'profile_tab_' . $id . '_privacy',
351
- 'type' => 'select',
352
- // translators: %s: Tab title
353
- 'label' => sprintf( __( 'Who can see %s Tab?', 'ultimate-member' ), $tab['name'] ),
354
- 'tooltip' => __( 'Select which users can view this tab.', 'ultimate-member' ),
355
- 'options' => UM()->profile()->tabs_privacy(),
356
- 'conditional' => array( 'profile_tab_' . $id, '=', 1 ),
357
- 'size' => 'small',
358
- ),
359
- array(
360
- 'id' => 'profile_tab_' . $id . '_roles',
361
- 'type' => 'select',
362
- 'multi' => true,
363
- 'label' => __( 'Allowed roles', 'ultimate-member' ),
364
- 'tooltip' => __( 'Select the the user roles allowed to view this tab.', 'ultimate-member' ),
365
- 'options' => UM()->roles()->get_roles(),
366
- 'placeholder' => __( 'Choose user roles...', 'ultimate-member' ),
367
- 'conditional' => array( 'profile_tab_' . $id . '_privacy', '=', array( '4', '5' ) ),
368
- 'size' => 'small',
369
- ),
370
- );
371
-
372
- $settings_map = array_merge(
373
- $settings_map,
374
- array(
375
- "profile_tab_{$id}" => array(
376
- 'sanitize' => 'bool',
377
- ),
378
- "profile_tab_{$id}_privacy" => array(
379
- 'sanitize' => array( UM()->admin(), 'sanitize_tabs_privacy' ),
380
- ),
381
- "profile_tab_{$id}_roles" => array(
382
- 'sanitize' => array( UM()->admin(), 'sanitize_existed_role' ),
383
- ),
384
- )
385
- );
386
- }
387
-
388
- $appearances_profile_menu_fields = array_merge( $appearances_profile_menu_fields, $fields );
389
- }
390
-
391
- $appearances_profile_menu_fields[] = array(
392
- 'id' => 'profile_menu_default_tab',
393
- 'type' => 'select',
394
- 'label' => __( 'Profile menu default tab', 'ultimate-member' ),
395
- 'tooltip' => __( 'This will be the default tab on user profile page', 'ultimate-member' ),
396
- 'options' => $tabs_options,
397
- 'conditional' => array( implode( '|', $tabs_condition ), '~', 1 ),
398
- 'size' => 'small',
399
- );
400
-
401
- $settings_map['profile_menu_default_tab'] = array(
402
- 'sanitize' => 'key',
403
- );
404
-
405
- $appearances_profile_menu_fields = array_merge(
406
- $appearances_profile_menu_fields,
407
- array(
408
- array(
409
- 'id' => 'profile_menu_icons',
410
- 'type' => 'checkbox',
411
- 'label' => __( 'Enable menu icons in desktop view', 'ultimate-member' ),
412
- 'conditional' => array( 'profile_menu', '=', 1 ),
413
- ),
414
- )
415
- );
416
-
417
- $settings_map['profile_menu_icons'] = array(
418
- 'sanitize' => 'bool',
419
- );
420
-
421
- $post_types_options = array();
422
- $all_post_types = get_post_types( array( 'public' => true ), 'objects' );
423
- foreach ( $all_post_types as $key => $post_type_data ) {
424
- $post_types_options[ $key ] = $post_type_data->labels->singular_name;
425
- }
426
-
427
- $duplicates = array();
428
- $taxonomies_options = array();
429
- $exclude_taxonomies = UM()->excluded_taxonomies();
430
- $all_taxonomies = get_taxonomies( array( 'public' => true ), 'objects' );
431
- foreach ( $all_taxonomies as $key => $taxonomy ) {
432
- if ( in_array( $key, $exclude_taxonomies, true ) ) {
433
- continue;
434
- }
435
-
436
- if ( ! in_array( $taxonomy->labels->singular_name, $duplicates, true ) ) {
437
- $duplicates[] = $taxonomy->labels->singular_name;
438
- $label = $taxonomy->labels->singular_name;
439
- } else {
440
- $label = $taxonomy->labels->singular_name . ' (' . $key . ')';
441
- }
442
-
443
- $taxonomies_options[ $key ] = $label;
444
- }
445
-
446
- $restricted_access_post_metabox_value = array();
447
- $restricted_access_post_metabox = UM()->options()->get( 'restricted_access_post_metabox' );
448
- if ( ! empty( $restricted_access_post_metabox ) && is_array( $restricted_access_post_metabox ) ) {
449
- foreach ( $restricted_access_post_metabox as $key => $value ) {
450
- if ( $value ) {
451
- $restricted_access_post_metabox_value[] = $key;
452
- }
453
- }
454
- }
455
-
456
-
457
- $restricted_access_taxonomy_metabox_value = array();
458
- $restricted_access_taxonomy_metabox = UM()->options()->get( 'restricted_access_taxonomy_metabox' );
459
- if ( ! empty( $restricted_access_taxonomy_metabox ) && is_array( $restricted_access_taxonomy_metabox ) ) {
460
- foreach ( $restricted_access_taxonomy_metabox as $key => $value ) {
461
- if ( $value ) {
462
- $restricted_access_taxonomy_metabox_value[] = $key;
463
- }
464
- }
465
- }
466
-
467
- $access_fields = array(
468
- array(
469
- 'id' => 'accessible',
470
- 'type' => 'select',
471
- 'label' => __( 'Global Site Access', 'ultimate-member' ),
472
- 'tooltip' => __( 'Globally control the access of your site, you can have separate restrict options per post/page by editing the desired item.', 'ultimate-member' ),
473
- 'options' => array(
474
- 0 => __( 'Site accessible to Everyone', 'ultimate-member' ),
475
- 2 => __( 'Site accessible to Logged In Users', 'ultimate-member' ),
476
- ),
477
- 'size' => 'medium',
478
- ),
479
- array(
480
- 'id' => 'access_redirect',
481
- 'type' => 'text',
482
- 'label' => __( 'Custom Redirect URL', 'ultimate-member' ),
483
- 'tooltip' => __( 'A logged out user will be redirected to this url If he is not permitted to access the site', 'ultimate-member' ),
484
- 'conditional' => array( 'accessible', '=', 2 ),
485
- ),
486
- array(
487
- 'id' => 'access_exclude_uris',
488
- 'type' => 'multi_text',
489
- 'label' => __( 'Exclude the following URLs', 'ultimate-member' ),
490
- 'tooltip' => __( 'Here you can exclude URLs beside the redirect URI to be accessible to everyone', 'ultimate-member' ),
491
- 'add_text' => __( 'Add New URL', 'ultimate-member' ),
492
- 'conditional' => array( 'accessible', '=', 2 ),
493
- 'show_default_number' => 0,
494
- ),
495
- array(
496
- 'id' => 'home_page_accessible',
497
- 'type' => 'checkbox',
498
- 'label' => __( 'Allow Homepage to be accessible', 'ultimate-member' ),
499
- 'conditional' => array( 'accessible', '=', 2 ),
500
- ),
501
- array(
502
- 'id' => 'category_page_accessible',
503
- 'type' => 'checkbox',
504
- 'label' => __( 'Allow Category pages to be accessible', 'ultimate-member' ),
505
- 'conditional' => array( 'accessible', '=', 2 ),
506
- ),
507
- array(
508
- 'id' => 'restricted_post_title_replace',
509
- 'type' => 'checkbox',
510
- 'label' => __( 'Replace the restricted Post Title', 'ultimate-member' ),
511
- 'tooltip' => __( 'Allow to replace the restricted post title to users that do not have permission to view the content', 'ultimate-member' ),
512
- ),
513
- array(
514
- 'id' => 'restricted_access_post_title',
515
- 'type' => 'text',
516
- 'label' => __( 'Restricted Access Post Title', 'ultimate-member' ),
517
- 'tooltip' => __( 'This is the post title shown to users that do not have permission to view the content', 'ultimate-member' ),
518
- 'conditional' => array( 'restricted_post_title_replace', '=', 1 ),
519
- ),
520
- array(
521
- 'id' => 'restricted_access_message',
522
- 'type' => 'wp_editor',
523
- 'label' => __( 'Restricted Access Message', 'ultimate-member' ),
524
- 'tooltip' => __( 'This is the message shown to users that do not have permission to view the content', 'ultimate-member' ),
525
- ),
526
- );
527
-
528
- $settings_map = array_merge(
529
- $settings_map,
530
- array(
531
- 'accessible' => array(
532
- 'sanitize' => 'int',
533
- ),
534
- 'access_redirect' => array(
535
- 'sanitize' => 'url',
536
- ),
537
- 'access_exclude_uris' => array(
538
- 'sanitize' => 'url',
539
- ),
540
- 'home_page_accessible' => array(
541
- 'sanitize' => 'bool',
542
- ),
543
- 'category_page_accessible' => array(
544
- 'sanitize' => 'bool',
545
- ),
546
- 'restricted_post_title_replace' => array(
547
- 'sanitize' => 'bool',
548
- ),
549
- 'restricted_access_post_title' => array(
550
- 'sanitize' => 'text',
551
- ),
552
- 'restricted_access_message' => array(
553
- 'sanitize' => 'wp_kses',
554
- ),
555
- )
556
- );
557
-
558
- global $wp_version;
559
- if ( version_compare( $wp_version, '5.0', '>=' ) ) {
560
- $access_fields = array_merge(
561
- $access_fields,
562
- array(
563
- array(
564
- 'id' => 'restricted_blocks',
565
- 'type' => 'checkbox',
566
- 'label' => __( 'Enable the "Content Restriction" settings for the Gutenberg Blocks', 'ultimate-member' ),
567
- ),
568
- array(
569
- 'id' => 'restricted_block_message',
570
- 'type' => 'textarea',
571
- 'label' => __( 'Restricted Access Block Message', 'ultimate-member' ),
572
- 'tooltip' => __( 'This is the message shown to users that do not have permission to view the block\'s content', 'ultimate-member' ),
573
- 'conditional' => array( 'restricted_blocks', '=', 1 ),
574
- ),
575
- )
576
- );
577
-
578
- $settings_map['restricted_blocks'] = array(
579
- 'sanitize' => 'bool',
580
- );
581
- $settings_map['restricted_block_message'] = array(
582
- 'sanitize' => 'textarea',
583
- );
584
- }
585
-
586
- $access_fields = array_merge(
587
- $access_fields,
588
- array(
589
- array(
590
- 'id' => 'restricted_access_post_metabox',
591
- 'type' => 'hidden',
592
- 'value' => '',
593
- ),
594
- array(
595
- 'id' => 'restricted_access_taxonomy_metabox',
596
- 'type' => 'hidden',
597
- 'value' => '',
598
- ),
599
- array(
600
- 'id' => 'restricted_access_post_metabox',
601
- 'type' => 'multi_checkbox',
602
- 'label' => __( 'Enable the "Content Restriction" settings for post types', 'ultimate-member' ),
603
- 'tooltip' => __( 'Check post types for which you plan to use the "Content Restriction" settings', 'ultimate-member' ),
604
- 'options' => $post_types_options,
605
- 'columns' => 3,
606
- 'value' => $restricted_access_post_metabox_value,
607
- 'default' => UM()->options()->get_default( 'restricted_access_post_metabox' ),
608
- ),
609
- array(
610
- 'id' => 'restricted_access_taxonomy_metabox',
611
- 'type' => 'multi_checkbox',
612
- 'label' => __( 'Enable the "Content Restriction" settings for taxonomies', 'ultimate-member' ),
613
- 'tooltip' => __( 'Check taxonomies for which you plan to use the "Content Restriction" settings', 'ultimate-member' ),
614
- 'options' => $taxonomies_options,
615
- 'columns' => 3,
616
- 'value' => $restricted_access_taxonomy_metabox_value,
617
- 'default' => UM()->options()->get_default( 'restricted_access_taxonomy_metabox' ),
618
- ),
619
- )
620
- );
621
-
622
- $settings_map = array_merge(
623
- $settings_map,
624
- array(
625
- 'restricted_access_post_metabox' => array(
626
- 'sanitize' => 'key',
627
- ),
628
- 'restricted_access_taxonomy_metabox' => array(
629
- 'sanitize' => 'key',
630
- ),
631
- )
632
- );
633
-
634
- $latest_update = get_option( 'um_member_directory_update_meta', false );
635
- $latest_truncate = get_option( 'um_member_directory_truncated', false );
636
-
637
- $same_page_update = array(
638
- 'id' => 'member_directory_own_table',
639
- 'type' => 'same_page_update',
640
- 'label' => __( 'Enable custom table for usermeta', 'ultimate-member' ),
641
- 'tooltip' => __( 'Check this box if you would like to enable the use of a custom table for user metadata. Improved performance for member directory searches.', 'ultimate-member' ),
642
- );
643
-
644
- if ( empty( $latest_update ) || ( ! empty( $latest_truncate ) && $latest_truncate > $latest_update ) ) {
645
- $same_page_update['upgrade_cb'] = 'sync_metatable';
646
- $same_page_update['upgrade_description'] = '<p>' . __( 'We recommend creating a backup of your site before running the update process. Do not exit the page before the update process has complete.', 'ultimate-member' ) . '</p>
647
- <p>' . __( 'After clicking the <strong>"Run"</strong> button, the update process will start. All information will be displayed in the field below.', 'ultimate-member' ) . '</p>
648
- <p>' . __( 'If the update was successful, you will see a corresponding message. Otherwise, contact technical support if the update failed.', 'ultimate-member' ) . '</p>';
649
- }
650
-
651
- $settings_map = array_merge(
652
- $settings_map,
653
- array(
654
- 'permalink_base' => array(
655
- 'sanitize' => 'key',
656
- ),
657
- 'display_name' => array(
658
- 'sanitize' => 'key',
659
- ),
660
- 'display_name_field' => array(
661
- 'sanitize' => 'text',
662
- ),
663
- 'author_redirect' => array(
664
- 'sanitize' => 'bool',
665
- ),
666
- 'members_page' => array(
667
- 'sanitize' => 'bool',
668
- ),
669
- 'use_gravatars' => array(
670
- 'sanitize' => 'bool',
671
- ),
672
- 'use_um_gravatar_default_builtin_image' => array(
673
- 'sanitize' => 'key',
674
- ),
675
- 'use_um_gravatar_default_image' => array(
676
- 'sanitize' => 'bool',
677
- ),
678
- 'require_strongpass' => array(
679
- 'sanitize' => 'bool',
680
- ),
681
- 'password_min_chars' => array(
682
- 'sanitize' => 'absint',
683
- ),
684
- 'password_max_chars' => array(
685
- 'sanitize' => 'absint',
686
- ),
687
- 'profile_noindex' => array(
688
- 'sanitize' => 'bool',
689
- ),
690
- 'activation_link_expiry_time' => array(
691
- 'sanitize' => 'absint',
692
- ),
693
- 'account_tab_password' => array(
694
- 'sanitize' => 'bool',
695
- ),
696
- 'account_tab_privacy' => array(
697
- 'sanitize' => 'bool',
698
- ),
699
- 'account_tab_notifications' => array(
700
- 'sanitize' => 'bool',
701
- ),
702
- 'account_tab_delete' => array(
703
- 'sanitize' => 'bool',
704
- ),
705
- 'delete_account_text' => array(
706
- 'sanitize' => 'textarea',
707
- ),
708
- 'delete_account_no_pass_required_text' => array(
709
- 'sanitize' => 'textarea',
710
- ),
711
- 'account_name' => array(
712
- 'sanitize' => 'bool',
713
- ),
714
- 'account_name_disable' => array(
715
- 'sanitize' => 'bool',
716
- ),
717
- 'account_name_require' => array(
718
- 'sanitize' => 'bool',
719
- ),
720
- 'account_email' => array(
721
- 'sanitize' => 'bool',
722
- ),
723
- 'account_general_password' => array(
724
- 'sanitize' => 'bool',
725
- ),
726
- 'account_hide_in_directory' => array(
727
- 'sanitize' => 'bool',
728
- ),
729
- 'account_hide_in_directory_default' => array(
730
- 'sanitize' => 'text',
731
- ),
732
- 'profile_photo_max_size' => array(
733
- 'sanitize' => 'absint',
734
- ),
735
- 'cover_photo_max_size' => array(
736
- 'sanitize' => 'absint',
737
- ),
738
- 'photo_thumb_sizes' => array(
739
- 'sanitize' => 'absint',
740
- ),
741
- 'cover_thumb_sizes' => array(
742
- 'sanitize' => 'absint',
743
- ),
744
- 'image_orientation_by_exif' => array(
745
- 'sanitize' => 'bool',
746
- ),
747
- 'image_compression' => array(
748
- 'sanitize' => 'absint',
749
- ),
750
- 'image_max_width' => array(
751
- 'sanitize' => 'absint',
752
- ),
753
- 'cover_min_width' => array(
754
- 'sanitize' => 'absint',
755
- ),
756
- 'enable_reset_password_limit' => array(
757
- 'sanitize' => 'bool',
758
- ),
759
- 'reset_password_limit_number' => array(
760
- 'sanitize' => 'absint',
761
- ),
762
- 'blocked_emails' => array(
763
- 'sanitize' => 'textarea',
764
- ),
765
- 'blocked_words' => array(
766
- 'sanitize' => 'textarea',
767
- ),
768
- 'allowed_choice_callbacks' => array(
769
- 'sanitize' => 'textarea',
770
- ),
771
- 'allow_url_redirect_confirm' => array(
772
- 'sanitize' => 'bool',
773
- ),
774
- 'admin_email' => array(
775
- 'sanitize' => 'text',
776
- ),
777
- 'mail_from' => array(
778
- 'sanitize' => 'text',
779
- ),
780
- 'mail_from_addr' => array(
781
- 'sanitize' => 'text',
782
- ),
783
- 'email_html' => array(
784
- 'sanitize' => 'bool',
785
- ),
786
- 'profile_template' => array(
787
- 'sanitize' => 'text',
788
- ),
789
- 'profile_max_width' => array(
790
- 'sanitize' => 'text',
791
- ),
792
- 'profile_area_max_width' => array(
793
- 'sanitize' => 'text',
794
- ),
795
- 'profile_icons' => array(
796
- 'sanitize' => 'key',
797
- ),
798
- 'profile_primary_btn_word' => array(
799
- 'sanitize' => 'text',
800
- ),
801
- 'profile_secondary_btn' => array(
802
- 'sanitize' => 'bool',
803
- ),
804
- 'profile_secondary_btn_word' => array(
805
- 'sanitize' => 'text',
806
- ),
807
- 'default_avatar' => array(
808
- 'sanitize' => 'url',
809
- ),
810
- 'default_cover' => array(
811
- 'sanitize' => 'url',
812
- ),
813
- 'disable_profile_photo_upload' => array(
814
- 'sanitize' => 'bool',
815
- ),
816
- 'profile_photosize' => array(
817
- 'sanitize' => array( UM()->admin(), 'sanitize_photosize' ),
818
- ),
819
- 'profile_cover_enabled' => array(
820
- 'sanitize' => 'bool',
821
- ),
822
- 'profile_coversize' => array(
823
- 'sanitize' => array( UM()->admin(), 'sanitize_cover_photosize' ),
824
- ),
825
- 'profile_cover_ratio' => array(
826
- 'sanitize' => 'text',
827
- ),
828
- 'profile_show_metaicon' => array(
829
- 'sanitize' => 'bool',
830
- ),
831
- 'profile_show_name' => array(
832
- 'sanitize' => 'bool',
833
- ),
834
- 'profile_show_social_links' => array(
835
- 'sanitize' => 'bool',
836
- ),
837
- 'profile_show_bio' => array(
838
- 'sanitize' => 'bool',
839
- ),
840
- 'profile_show_html_bio' => array(
841
- 'sanitize' => 'bool',
842
- ),
843
- 'profile_bio_maxchars' => array(
844
- 'sanitize' => 'absint',
845
- ),
846
- 'profile_header_menu' => array(
847
- 'sanitize' => 'key',
848
- ),
849
- 'profile_empty_text' => array(
850
- 'sanitize' => 'bool',
851
- ),
852
- 'profile_empty_text_emo' => array(
853
- 'sanitize' => 'bool',
854
- ),
855
- 'register_template' => array(
856
- 'sanitize' => 'text',
857
- ),
858
- 'register_max_width' => array(
859
- 'sanitize' => 'text',
860
- ),
861
- 'register_align' => array(
862
- 'sanitize' => 'key',
863
- ),
864
- 'register_icons' => array(
865
- 'sanitize' => 'key',
866
- ),
867
- 'register_primary_btn_word' => array(
868
- 'sanitize' => 'text',
869
- ),
870
- 'register_secondary_btn' => array(
871
- 'sanitize' => 'bool',
872
- ),
873
- 'register_secondary_btn_word' => array(
874
- 'sanitize' => 'text',
875
- ),
876
- 'register_secondary_btn_url' => array(
877
- 'sanitize' => 'url',
878
- ),
879
- 'register_role' => array(
880
- 'sanitize' => 'key',
881
- ),
882
- 'login_template' => array(
883
- 'sanitize' => 'text',
884
- ),
885
- 'login_max_width' => array(
886
- 'sanitize' => 'text',
887
- ),
888
- 'login_align' => array(
889
- 'sanitize' => 'key',
890
- ),
891
- 'login_icons' => array(
892
- 'sanitize' => 'key',
893
- ),
894
- 'login_primary_btn_word' => array(
895
- 'sanitize' => 'text',
896
- ),
897
- 'login_secondary_btn' => array(
898
- 'sanitize' => 'bool',
899
- ),
900
- 'login_secondary_btn_word' => array(
901
- 'sanitize' => 'text',
902
- ),
903
- 'login_secondary_btn_url' => array(
904
- 'sanitize' => 'url',
905
- ),
906
- 'login_forgot_pass_link' => array(
907
- 'sanitize' => 'bool',
908
- ),
909
- 'login_show_rememberme' => array(
910
- 'sanitize' => 'bool',
911
- ),
912
- 'form_asterisk' => array(
913
- 'sanitize' => 'bool',
914
- ),
915
- 'profile_title' => array(
916
- 'sanitize' => 'text',
917
- ),
918
- 'profile_desc' => array(
919
- 'sanitize' => 'textarea',
920
- ),
921
- 'um_profile_object_cache_stop' => array(
922
- 'sanitize' => 'bool',
923
- ),
924
- 'enable_blocks' => array(
925
- 'sanitize' => 'bool',
926
- ),
927
- 'rest_api_version' => array(
928
- 'sanitize' => 'text',
929
- ),
930
- 'uninstall_on_delete' => array(
931
- 'sanitize' => 'bool',
932
- ),
933
- )
934
- );
935
-
936
- $this->settings_map = apply_filters( 'um_settings_map', $settings_map );
937
-
938
- /**
939
- * UM hook
940
- *
941
- * @type filter
942
- * @title um_settings_structure
943
- * @description Extend UM Settings
944
- * @input_vars
945
- * [{"var":"$settings","type":"array","desc":"UM Settings"}]
946
- * @change_log
947
- * ["Since: 2.0"]
948
- * @usage add_filter( 'um_settings_structure', 'function_name', 10, 1 );
949
- * @example
950
- * <?php
951
- * add_filter( 'um_settings_structure', 'my_settings_structure', 10, 1 );
952
- * function my_settings_structure( $settings ) {
953
- * // your code here
954
- * return $settings;
955
- * }
956
- * ?>
957
- */
958
- $this->settings_structure = apply_filters(
959
- 'um_settings_structure',
960
- array(
961
- '' => array(
962
- 'title' => __( 'General', 'ultimate-member' ),
963
- 'sections' => array(
964
- '' => array(
965
- 'title' => __( 'Pages', 'ultimate-member' ),
966
- 'fields' => $general_pages_fields,
967
- ),
968
- 'users' => array(
969
- 'title' => __( 'Users', 'ultimate-member' ),
970
- 'fields' => array(
971
- array(
972
- 'id' => 'permalink_base',
973
- 'type' => 'select',
974
- 'size' => 'small',
975
- 'label' => __( 'Profile Permalink Base', 'ultimate-member' ),
976
- // translators: %s: Profile page URL
977
- 'tooltip' => sprintf( __( 'Here you can control the permalink structure of the user profile URL globally e.g. %s<strong>username</strong>/', 'ultimate-member' ), trailingslashit( um_get_core_page( 'user' ) ) ),
978
- 'options' => array(
979
- 'user_login' => __( 'Username', 'ultimate-member' ),
980
- 'name' => __( 'First and Last Name with \'.\'', 'ultimate-member' ),
981
- 'name_dash' => __( 'First and Last Name with \'-\'', 'ultimate-member' ),
982
- 'name_plus' => __( 'First and Last Name with \'+\'', 'ultimate-member' ),
983
- 'user_id' => __( 'User ID', 'ultimate-member' ),
984
- ),
985
- 'placeholder' => __( 'Select...', 'ultimate-member' ),
986
- ),
987
- array(
988
- 'id' => 'display_name',
989
- 'type' => 'select',
990
- 'size' => 'medium',
991
- 'label' => __( 'User Display Name', 'ultimate-member' ),
992
- 'tooltip' => __( 'This is the name that will be displayed for users on the front end of your site. Default setting uses first/last name as display name if it exists', 'ultimate-member' ),
993
- 'options' => array(
994
- 'default' => __( 'Default WP Display Name', 'ultimate-member' ),
995
- 'nickname' => __( 'Nickname', 'ultimate-member' ),
996
- 'username' => __( 'Username', 'ultimate-member' ),
997
- 'full_name' => __( 'First name & last name', 'ultimate-member' ),
998
- 'sur_name' => __( 'Last name & first name', 'ultimate-member' ),
999
- 'initial_name' => __( 'First name & first initial of last name', 'ultimate-member' ),
1000
- 'initial_name_f' => __( 'First initial of first name & last name', 'ultimate-member' ),
1001
- 'first_name' => __( 'First name only', 'ultimate-member' ),
1002
- 'field' => __( 'Custom field(s)', 'ultimate-member' ),
1003
- ),
1004
- 'placeholder' => __( 'Select...', 'ultimate-member' ),
1005
- ),
1006
- array(
1007
- 'id' => 'display_name_field',
1008
- 'type' => 'text',
1009
- 'label' => __( 'Display Name Custom Field(s)', 'ultimate-member' ),
1010
- 'tooltip' => __( 'Specify the custom field meta key or custom fields seperated by comma that you want to use to display users name on the frontend of your site', 'ultimate-member' ),
1011
- 'conditional' => array( 'display_name', '=', 'field' ),
1012
- ),
1013
- array(
1014
- 'id' => 'author_redirect',
1015
- 'type' => 'checkbox',
1016
- 'label' => __( 'Automatically redirect author page to their profile?', 'ultimate-member' ),
1017
- 'tooltip' => __( 'If enabled, author pages will automatically redirect to the user\'s profile page', 'ultimate-member' ),
1018
- ),
1019
- array(
1020
- 'id' => 'members_page',
1021
- 'type' => 'checkbox',
1022
- 'label' => __( 'Enable Members Directory', 'ultimate-member' ),
1023
- 'tooltip' => __( 'Control whether to enable or disable member directories on this site', 'ultimate-member' ),
1024
- ),
1025
- array(
1026
- 'id' => 'use_gravatars',
1027
- 'type' => 'checkbox',
1028
- 'label' => __( 'Use Gravatars?', 'ultimate-member' ),
1029
- 'tooltip' => __( 'Do you want to use gravatars instead of the default plugin profile photo (If the user did not upload a custom profile photo / avatar)', 'ultimate-member' ),
1030
- ),
1031
- array(
1032
- 'id' => 'use_um_gravatar_default_builtin_image',
1033
- 'type' => 'select',
1034
- 'label' => __( 'Use Gravatar builtin image', 'ultimate-member' ),
1035
- 'tooltip' => __( 'Gravatar has a number of built in options which you can also use as defaults', 'ultimate-member' ),
1036
- 'options' => array(
1037
- 'default' => __( 'Default', 'ultimate-member' ),
1038
- '404' => __( '404 ( File Not Found response )', 'ultimate-member' ),
1039
- 'mm' => __( 'Mystery Man', 'ultimate-member' ),
1040
- 'identicon' => __( 'Identicon', 'ultimate-member' ),
1041
- 'monsterid' => __( 'Monsterid', 'ultimate-member' ),
1042
- 'wavatar' => __( 'Wavatar', 'ultimate-member' ),
1043
- 'retro' => __( 'Retro', 'ultimate-member' ),
1044
- 'blank' => __( 'Blank ( a transparent PNG image )', 'ultimate-member' ),
1045
- ),
1046
- 'conditional' => array( 'use_gravatars', '=', 1 ),
1047
- 'size' => 'medium',
1048
- ),
1049
- array(
1050
- 'id' => 'use_um_gravatar_default_image',
1051
- 'type' => 'checkbox',
1052
- 'label' => __( 'Use Default plugin avatar as Gravatar\'s Default avatar', 'ultimate-member' ),
1053
- 'tooltip' => __( 'Do you want to use the plugin default avatar instead of the gravatar default photo (If the user did not upload a custom profile photo / avatar)', 'ultimate-member' ),
1054
- 'conditional' => array( 'use_um_gravatar_default_builtin_image', '=', 'default' ),
1055
- ),
1056
- array(
1057
- 'id' => 'require_strongpass',
1058
- 'type' => 'checkbox',
1059
- 'label' => __( 'Require a strong password?', 'ultimate-member' ),
1060
- 'tooltip' => __( 'Enable or disable a strong password rules common for all Ultimate Member forms.', 'ultimate-member' ),
1061
- ),
1062
- array(
1063
- 'id' => 'password_min_chars',
1064
- 'type' => 'number',
1065
- 'label' => __( 'Password minimum length', 'ultimate-member' ),
1066
- 'tooltip' => __( 'If you want to enable a minimum number of characters to be in password. User password field in the UM forms has own settings for that. Leave empty to use default value 8', 'ultimate-member' ),
1067
- 'size' => 'small',
1068
- ),
1069
- array(
1070
- 'id' => 'password_max_chars',
1071
- 'type' => 'number',
1072
- 'label' => __( 'Password maximum length', 'ultimate-member' ),
1073
- 'tooltip' => __( 'If you want to enable a maximum number of characters to be in password. User password field in the UM forms has own settings for that. Leave empty to use default value 30', 'ultimate-member' ),
1074
- 'size' => 'small',
1075
- ),
1076
- array(
1077
- 'id' => 'profile_noindex',
1078
- 'type' => 'select',
1079
- 'size' => 'small',
1080
- 'label' => __( 'Avoid indexing profile by search engines', 'ultimate-member' ),
1081
- 'tooltip' => __( 'Hides the profile page for robots. This setting can be overridden by individual role settings.', 'ultimate-member' ),
1082
- 'options' => array(
1083
- '0' => __( 'No', 'ultimate-member' ),
1084
- '1' => __( 'Yes', 'ultimate-member' ),
1085
- ),
1086
- ),
1087
- array(
1088
- 'id' => 'activation_link_expiry_time',
1089
- 'type' => 'number',
1090
- 'label' => __( 'Activation link lifetime', 'ultimate-member' ),
1091
- 'tooltip' => __( 'How long does an activation link live in seconds? Leave empty for endless links.', 'ultimate-member' ),
1092
- 'size' => 'small',
1093
- ),
1094
- ),
1095
- ),
1096
- 'account' => array(
1097
- 'title' => __( 'Account', 'ultimate-member' ),
1098
- 'fields' => array(
1099
- array(
1100
- 'id' => 'account_tab_password',
1101
- 'type' => 'checkbox',
1102
- 'label' => __( 'Password Account Tab', 'ultimate-member' ),
1103
- 'tooltip' => __( 'Enable/disable the Password account tab in account page', 'ultimate-member' ),
1104
- ),
1105
- array(
1106
- 'id' => 'account_tab_privacy',
1107
- 'type' => 'checkbox',
1108
- 'label' => __( 'Privacy Account Tab', 'ultimate-member' ),
1109
- 'tooltip' => __( 'Enable/disable the Privacy account tab in account page', 'ultimate-member' ),
1110
- ),
1111
- array(
1112
- 'id' => 'account_tab_notifications',
1113
- 'type' => 'checkbox',
1114
- 'label' => __( 'Notifications Account Tab', 'ultimate-member' ),
1115
- 'tooltip' => __( 'Enable/disable the Notifications account tab in account page', 'ultimate-member' ),
1116
- ),
1117
- array(
1118
- 'id' => 'account_tab_delete',
1119
- 'type' => 'checkbox',
1120
- 'label' => __( 'Delete Account Tab', 'ultimate-member' ),
1121
- 'tooltip' => __( 'Enable/disable the Delete account tab in account page', 'ultimate-member' ),
1122
- ),
1123
- array(
1124
- 'id' => 'delete_account_text',
1125
- 'type' => 'textarea', // bug with wp 4.4? should be editor
1126
- 'label' => __( 'Account Deletion Custom Text', 'ultimate-member' ),
1127
- 'tooltip' => __( 'This is custom text that will be displayed to users before they delete their accounts from your site when password is required.', 'ultimate-member' ),
1128
- 'args' => array(
1129
- 'textarea_rows' => 6,
1130
- ),
1131
- ),
1132
- array(
1133
- 'id' => 'delete_account_no_pass_required_text',
1134
- 'type' => 'textarea',
1135
- 'label' => __( 'Account Deletion without password Custom Text', 'ultimate-member' ),
1136
- 'tooltip' => __( 'This is custom text that will be displayed to users before they delete their accounts from your site when password isn\'t required.', 'ultimate-member' ),
1137
- 'args' => array(
1138
- 'textarea_rows' => 6,
1139
- ),
1140
- ),
1141
- array(
1142
- 'id' => 'account_name',
1143
- 'type' => 'checkbox',
1144
- 'label' => __( 'Add a First & Last Name fields', 'ultimate-member' ),
1145
- 'tooltip' => __( 'Whether to enable these fields on the user account page by default or hide them.', 'ultimate-member' ),
1146
- ),
1147
- array(
1148
- 'id' => 'account_name_disable',
1149
- 'type' => 'checkbox',
1150
- 'label' => __( 'Disable First & Last Name fields', 'ultimate-member' ),
1151
- 'tooltip' => __( 'Whether to allow users changing their first and last name in account page.', 'ultimate-member' ),
1152
- 'conditional' => array( 'account_name', '=', '1' ),
1153
- ),
1154
- array(
1155
- 'id' => 'account_name_require',
1156
- 'type' => 'checkbox',
1157
- 'label' => __( 'Require First & Last Name', 'ultimate-member' ),
1158
- 'tooltip' => __( 'Require first and last name?', 'ultimate-member' ),
1159
- 'conditional' => array( 'account_name', '=', '1' ),
1160
- ),
1161
- array(
1162
- 'id' => 'account_email',
1163
- 'type' => 'checkbox',
1164
- 'label' => __( 'Allow users to change e-mail', 'ultimate-member' ),
1165
- 'tooltip' => __( 'Whether to allow users changing their email in account page.', 'ultimate-member' ),
1166
- ),
1167
- array(
1168
- 'id' => 'account_general_password',
1169
- 'type' => 'checkbox',
1170
- 'label' => __( 'Password is required?', 'ultimate-member' ),
1171
- 'tooltip' => __( 'Password is required to save account data.', 'ultimate-member' ),
1172
- ),
1173
- array(
1174
- 'id' => 'account_hide_in_directory',
1175
- 'type' => 'checkbox',
1176
- 'label' => __( 'Allow users to hide their profiles from directory', 'ultimate-member' ),
1177
- 'tooltip' => __( 'Whether to allow users changing their profile visibility from member directory in account page.', 'ultimate-member' ),
1178
- 'conditional' => array( 'account_tab_privacy', '=', '1' ),
1179
- ),
1180
- array(
1181
- 'id' => 'account_hide_in_directory_default',
1182
- 'type' => 'select',
1183
- 'label' => __( 'Hide profiles from directory by default', 'ultimate-member' ),
1184
- 'tooltip' => __( 'Set default value for the "Hide my profile from directory" option', 'ultimate-member' ),
1185
- 'options' => array(
1186
- 'No' => __( 'No', 'ultimate-member' ),
1187
- 'Yes' => __( 'Yes', 'ultimate-member' ),
1188
- ),
1189
- 'size' => 'small',
1190
- 'conditional' => array( 'account_hide_in_directory', '=', '1' ),
1191
- ),
1192
- ),
1193
- ),
1194
- 'uploads' => array(
1195
- 'title' => __( 'Uploads', 'ultimate-member' ),
1196
- 'fields' => array(
1197
- array(
1198
- 'id' => 'profile_photo_max_size',
1199
- 'type' => 'text',
1200
- 'size' => 'small',
1201
- 'label' => __( 'Profile Photo Maximum File Size (bytes)', 'ultimate-member' ),
1202
- 'tooltip' => __( 'Sets a maximum size for the uploaded photo', 'ultimate-member' ),
1203
- ),
1204
- array(
1205
- 'id' => 'cover_photo_max_size',
1206
- 'type' => 'text',
1207
- 'size' => 'small',
1208
- 'label' => __( 'Cover Photo Maximum File Size (bytes)', 'ultimate-member' ),
1209
- 'tooltip' => __( 'Sets a maximum size for the uploaded cover', 'ultimate-member' ),
1210
- ),
1211
- array(
1212
- 'id' => 'photo_thumb_sizes',
1213
- 'type' => 'multi_text',
1214
- 'size' => 'small',
1215
- 'label' => __( 'Profile Photo Thumbnail Sizes (px)', 'ultimate-member' ),
1216
- 'tooltip' => __( 'Here you can define which thumbnail sizes will be created for each profile photo upload.', 'ultimate-member' ),
1217
- 'validate' => 'numeric',
1218
- 'add_text' => __( 'Add New Size', 'ultimate-member' ),
1219
- 'show_default_number' => 1,
1220
- ),
1221
- array(
1222
- 'id' => 'cover_thumb_sizes',
1223
- 'type' => 'multi_text',
1224
- 'size' => 'small',
1225
- 'label' => __( 'Cover Photo Thumbnail Sizes (px)', 'ultimate-member' ),
1226
- 'tooltip' => __( 'Here you can define which thumbnail sizes will be created for each cover photo upload.', 'ultimate-member' ),
1227
- 'validate' => 'numeric',
1228
- 'add_text' => __( 'Add New Size', 'ultimate-member' ),
1229
- 'show_default_number' => 1,
1230
- ),
1231
- array(
1232
- 'id' => 'image_orientation_by_exif',
1233
- 'type' => 'checkbox',
1234
- 'label' => __( 'Change image orientation', 'ultimate-member' ),
1235
- 'tooltip' => __( 'Rotate image to and use orientation by the camera EXIF data.', 'ultimate-member' ),
1236
- ),
1237
- array(
1238
- 'id' => 'image_compression',
1239
- 'type' => 'text',
1240
- 'size' => 'small',
1241
- 'label' => __( 'Image Quality', 'ultimate-member' ),
1242
- 'tooltip' => __( 'Quality is used to determine quality of image uploads, and ranges from 0 (worst quality, smaller file) to 100 (best quality, biggest file). The default range is 60.', 'ultimate-member' ),
1243
- ),
1244
-
1245
- array(
1246
- 'id' => 'image_max_width',
1247
- 'type' => 'text',
1248
- 'size' => 'small',
1249
- 'label' => __( 'Image Upload Maximum Width (px)', 'ultimate-member' ),
1250
- 'tooltip' => __( 'Any image upload above this width will be resized to this limit automatically.', 'ultimate-member' ),
1251
- ),
1252
-
1253
- array(
1254
- 'id' => 'cover_min_width',
1255
- 'type' => 'text',
1256
- 'size' => 'small',
1257
- 'label' => __( 'Cover Photo Minimum Width (px)', 'ultimate-member' ),
1258
- 'tooltip' => __( 'This will be the minimum width for cover photo uploads', 'ultimate-member' ),
1259
- ),
1260
- ),
1261
- ),
1262
- ),
1263
- ),
1264
- 'access' => array(
1265
- 'title' => __( 'Access', 'ultimate-member' ),
1266
- 'sections' => array(
1267
- '' => array(
1268
- 'title' => __( 'Restriction Content', 'ultimate-member' ),
1269
- 'fields' => $access_fields,
1270
- ),
1271
- 'other' => array(
1272
- 'title' => __( 'Other', 'ultimate-member' ),
1273
- 'fields' => array(
1274
- array(
1275
- 'id' => 'enable_reset_password_limit',
1276
- 'type' => 'checkbox',
1277
- 'label' => __( 'Enable the Reset Password Limit?', 'ultimate-member' ),
1278
- ),
1279
- array(
1280
- 'id' => 'reset_password_limit_number',
1281
- 'type' => 'text',
1282
- 'label' => __( 'Reset Password Limit', 'ultimate-member' ),
1283
- 'tooltip' => __( 'Set the maximum reset password limit. If reached the maximum limit, user will be locked from using this.', 'ultimate-member' ),
1284
- 'validate' => 'numeric',
1285
- 'conditional' => array( 'enable_reset_password_limit', '=', 1 ),
1286
- 'size' => 'small',
1287
- ),
1288
- array(
1289
- 'id' => 'blocked_emails',
1290
- 'type' => 'textarea',
1291
- 'label' => __( 'Blocked Email Addresses (Enter one email per line)', 'ultimate-member' ),
1292
- 'tooltip' => __( 'This will block the specified e-mail addresses from being able to sign up or sign in to your site. To block an entire domain, use something like *@domain.com', 'ultimate-member' ),
1293
- ),
1294
- array(
1295
- 'id' => 'blocked_words',
1296
- 'type' => 'textarea',
1297
- 'label' => __( 'Blacklist Words (Enter one word per line)', 'ultimate-member' ),
1298
- 'tooltip' => __( 'This option lets you specify blacklist of words to prevent anyone from signing up with such a word as their username', 'ultimate-member' ),
1299
- ),
1300
- array(
1301
- 'id' => 'allowed_choice_callbacks',
1302
- 'type' => 'textarea',
1303
- 'label' => __( 'Allowed Choice Callbacks (Enter one PHP function per line)', 'ultimate-member' ),
1304
- 'tooltip' => __( 'This option lets you specify the choice callback functions to prevent anyone from using 3rd-party functions that may put your site at risk.', 'ultimate-member' ),
1305
- ),
1306
- array(
1307
- 'id' => 'allow_url_redirect_confirm',
1308
- 'type' => 'checkbox',
1309
- 'label' => __( 'Allow external link redirect confirm', 'ultimate-member' ),
1310
- 'tooltip' => __( 'Using JS.confirm alert when you go to an external link.', 'ultimate-member' ),
1311
- ),
1312
- ),
1313
- ),
1314
- ),
1315
- ),
1316
- 'email' => array(
1317
- 'title' => __( 'Email', 'ultimate-member' ),
1318
- 'fields' => array(
1319
- array(
1320
- 'id' => 'admin_email',
1321
- 'type' => 'text',
1322
- 'label' => __( 'Admin E-mail Address', 'ultimate-member' ),
1323
- 'tooltip' => __( 'e.g. admin@companyname.com', 'ultimate-member' ),
1324
- ),
1325
- array(
1326
- 'id' => 'mail_from',
1327
- 'type' => 'text',
1328
- 'label' => __( 'Mail appears from', 'ultimate-member' ),
1329
- 'tooltip' => __( 'e.g. Site Name', 'ultimate-member' ),
1330
- ),
1331
- array(
1332
- 'id' => 'mail_from_addr',
1333
- 'type' => 'text',
1334
- 'label' => __( 'Mail appears from address', 'ultimate-member' ),
1335
- 'tooltip' => __( 'e.g. admin@companyname.com', 'ultimate-member' ),
1336
- ),
1337
- array(
1338
- 'id' => 'email_html',
1339
- 'type' => 'checkbox',
1340
- 'label' => __( 'Use HTML for E-mails?', 'ultimate-member' ),
1341
- 'tooltip' => __( 'If you plan use e-mails with HTML, please make sure that this option is enabled. Otherwise, HTML will be displayed as plain text.', 'ultimate-member' ),
1342
- ),
1343
- ),
1344
- ),
1345
- 'appearance' => array(
1346
- 'title' => __( 'Appearance', 'ultimate-member' ),
1347
- 'sections' => array(
1348
- '' => array(
1349
- 'title' => __( 'Profile', 'ultimate-member' ),
1350
- 'fields' => array(
1351
- array(
1352
- 'id' => 'profile_template',
1353
- 'type' => 'select',
1354
- 'label' => __( 'Profile Default Template', 'ultimate-member' ),
1355
- 'tooltip' => __( 'This will be the default template to output profile', 'ultimate-member' ),
1356
- 'default' => um_get_metadefault( 'profile_template' ),
1357
- 'options' => UM()->shortcodes()->get_templates( 'profile' ),
1358
- 'size' => 'small',
1359
- ),
1360
- array(
1361
- 'id' => 'profile_max_width',
1362
- 'type' => 'text',
1363
- 'label' => __( 'Profile Maximum Width', 'ultimate-member' ),
1364
- 'default' => um_get_metadefault( 'profile_max_width' ),
1365
- 'tooltip' => __( 'The maximum width this shortcode can take from the page width', 'ultimate-member' ),
1366
- 'size' => 'small',
1367
- ),
1368
- array(
1369
- 'id' => 'profile_area_max_width',
1370
- 'type' => 'text',
1371
- 'label' => __( 'Profile Area Maximum Width', 'ultimate-member' ),
1372
- 'default' => um_get_metadefault( 'profile_area_max_width' ),
1373
- 'tooltip' => __( 'The maximum width of the profile area inside profile (below profile header)', 'ultimate-member' ),
1374
- 'size' => 'small',
1375
- ),
1376
- array(
1377
- 'id' => 'profile_icons',
1378
- 'type' => 'select',
1379
- 'label' => __( 'Profile Field Icons', 'ultimate-member' ),
1380
- 'tooltip' => __( 'This is applicable for edit mode only', 'ultimate-member' ),
1381
- 'default' => um_get_metadefault( 'profile_icons' ),
1382
- 'options' => array(
1383
- 'field' => __( 'Show inside text field', 'ultimate-member' ),
1384
- 'label' => __( 'Show with label', 'ultimate-member' ),
1385
- 'off' => __( 'Turn off', 'ultimate-member' ),
1386
- ),
1387
- 'size' => 'small',
1388
- ),
1389
- array(
1390
- 'id' => 'profile_primary_btn_word',
1391
- 'type' => 'text',
1392
- 'label' => __( 'Profile Primary Button Text', 'ultimate-member' ),
1393
- 'default' => um_get_metadefault( 'profile_primary_btn_word' ),
1394
- 'tooltip' => __( 'The text that is used for updating profile button', 'ultimate-member' ),
1395
- 'size' => 'medium',
1396
- ),
1397
- array(
1398
- 'id' => 'profile_secondary_btn',
1399
- 'type' => 'checkbox',
1400
- 'label' => __( 'Profile Secondary Button', 'ultimate-member' ),
1401
- 'default' => um_get_metadefault( 'profile_secondary_btn' ),
1402
- 'tooltip' => __( 'Switch on/off the secondary button display in the form', 'ultimate-member' ),
1403
- ),
1404
- array(
1405
- 'id' => 'profile_secondary_btn_word',
1406
- 'type' => 'text',
1407
- 'label' => __( 'Profile Secondary Button Text', 'ultimate-member' ),
1408
- 'default' => um_get_metadefault( 'profile_secondary_btn_word' ),
1409
- 'tooltip' => __( 'The text that is used for cancelling update profile button', 'ultimate-member' ),
1410
- 'conditional' => array( 'profile_secondary_btn', '=', 1 ),
1411
- 'size' => 'medium',
1412
- ),
1413
- array(
1414
- 'id' => 'default_avatar',
1415
- 'type' => 'media',
1416
- 'label' => __( 'Default Profile Photo', 'ultimate-member' ),
1417
- 'tooltip' => __( 'You can change the default profile picture globally here. Please make sure that the photo is 300x300px.', 'ultimate-member' ),
1418
- 'upload_frame_title' => __( 'Select Default Profile Photo', 'ultimate-member' ),
1419
- 'default' => array(
1420
- 'url' => um_url . 'assets/img/default_avatar.jpg',
1421
- ),
1422
- ),
1423
- array(
1424
- 'id' => 'default_cover',
1425
- 'type' => 'media',
1426
- 'url' => true,
1427
- 'preview' => false,
1428
- 'label' => __( 'Default Cover Photo', 'ultimate-member' ),
1429
- 'tooltip' => __( 'You can change the default cover photo globally here. Please make sure that the default cover is large enough and respects the ratio you are using for cover photos.', 'ultimate-member' ),
1430
- 'upload_frame_title' => __( 'Select Default Cover Photo', 'ultimate-member' ),
1431
- ),
1432
- array(
1433
- 'id' => 'disable_profile_photo_upload',
1434
- 'type' => 'checkbox',
1435
- 'label' => __( 'Disable Profile Photo Upload', 'ultimate-member' ),
1436
- 'tooltip' => __( 'Switch on/off the profile photo uploader', 'ultimate-member' ),
1437
- 'default' => um_get_metadefault( 'disable_profile_photo_upload' ),
1438
- ),
1439
- array(
1440
- 'id' => 'profile_photosize',
1441
- 'type' => 'select',
1442
- 'label' => __( 'Profile Photo Size', 'ultimate-member' ),
1443
- 'default' => um_get_metadefault( 'profile_photosize' ),
1444
- 'options' => UM()->files()->get_profile_photo_size( 'photo_thumb_sizes' ),
1445
- 'tooltip' => __( 'The global default of profile photo size. This can be overridden by individual form settings', 'ultimate-member' ),
1446
- 'size' => 'small',
1447
- ),
1448
- array(
1449
- 'id' => 'profile_cover_enabled',
1450
- 'type' => 'checkbox',
1451
- 'label' => __( 'Profile Cover Photos', 'ultimate-member' ),
1452
- 'default' => um_get_metadefault( 'profile_cover_enabled' ),
1453
- 'tooltip' => __( 'Switch on/off the profile cover photos', 'ultimate-member' ),
1454
- ),
1455
- array(
1456
- 'id' => 'profile_coversize',
1457
- 'type' => 'select',
1458
- 'label' => __( 'Profile Cover Size', 'ultimate-member' ),
1459
- 'default' => um_get_metadefault( 'profile_coversize' ),
1460
- 'options' => UM()->files()->get_profile_photo_size( 'cover_thumb_sizes' ),
1461
- 'tooltip' => __( 'The global default width of cover photo size. This can be overridden by individual form settings', 'ultimate-member' ),
1462
- 'conditional' => array( 'profile_cover_enabled', '=', 1 ),
1463
- 'size' => 'small',
1464
- ),
1465
- array(
1466
- 'id' => 'profile_cover_ratio',
1467
- 'type' => 'select',
1468
- 'label' => __( 'Profile Cover Ratio', 'ultimate-member' ),
1469
- 'tooltip' => __( 'Choose global ratio for cover photos of profiles', 'ultimate-member' ),
1470
- 'default' => um_get_metadefault( 'profile_cover_ratio' ),
1471
- 'options' => array(
1472
- '1.6:1' => '1.6:1',
1473
- '2.7:1' => '2.7:1',
1474
- '2.2:1' => '2.2:1',
1475
- '3.2:1' => '3.2:1',
1476
- ),
1477
- 'conditional' => array( 'profile_cover_enabled', '=', 1 ),
1478
- 'size' => 'small',
1479
- ),
1480
- array(
1481
- 'id' => 'profile_show_metaicon',
1482
- 'type' => 'checkbox',
1483
- 'label' => __( 'Profile Header Meta Text Icon', 'ultimate-member' ),
1484
- 'default' => 0,
1485
- 'tooltip' => __( 'Display field icons for related user meta fields in header or not', 'ultimate-member' ),
1486
- ),
1487
- array(
1488
- 'id' => 'profile_show_name',
1489
- 'type' => 'checkbox',
1490
- 'label' => __( 'Show display name in profile header', 'ultimate-member' ),
1491
- 'default' => um_get_metadefault( 'profile_show_name' ),
1492
- 'tooltip' => __( 'Switch on/off the user name on profile header', 'ultimate-member' ),
1493
- ),
1494
- array(
1495
- 'id' => 'profile_show_social_links',
1496
- 'type' => 'checkbox',
1497
- 'label' => __( 'Show social links in profile header', 'ultimate-member' ),
1498
- 'default' => um_get_metadefault( 'profile_show_social_links' ),
1499
- 'tooltip' => __( 'Switch on/off the social links on profile header', 'ultimate-member' ),
1500
- ),
1501
- array(
1502
- 'id' => 'profile_show_bio',
1503
- 'type' => 'checkbox',
1504
- 'label' => __( 'Show user description in header', 'ultimate-member' ),
1505
- 'default' => um_get_metadefault( 'profile_show_bio' ),
1506
- 'tooltip' => __( 'Switch on/off the user description on profile header', 'ultimate-member' ),
1507
- ),
1508
- array(
1509
- 'id' => 'profile_show_html_bio',
1510
- 'type' => 'checkbox',
1511
- 'label' => __( 'Enable HTML support for user description', 'ultimate-member' ),
1512
- 'tooltip' => __( 'Switch on/off to enable/disable support for html tags on user description.', 'ultimate-member' ),
1513
- ),
1514
- array(
1515
- 'id' => 'profile_bio_maxchars',
1516
- 'type' => 'text',
1517
- 'label' => __( 'User description maximum chars', 'ultimate-member' ),
1518
- 'default' => um_get_metadefault( 'profile_bio_maxchars' ),
1519
- 'tooltip' => __( 'Maximum number of characters to allow in user description field in header.', 'ultimate-member' ),
1520
- 'conditional' => array( 'profile_show_bio', '=', 1 ),
1521
- 'size' => 'small',
1522
- ),
1523
- array(
1524
- 'id' => 'profile_header_menu',
1525
- 'type' => 'select',
1526
- 'label' => __( 'Profile Header Menu Position', 'ultimate-member' ),
1527
- 'default' => um_get_metadefault( 'profile_header_menu' ),
1528
- 'tooltip' => __( 'For incompatible themes, please make the menu open from left instead of bottom by default.', 'ultimate-member' ),
1529
- 'options' => array(
1530
- 'bc' => __( 'Bottom of Icon', 'ultimate-member' ),
1531
- 'lc' => __( 'Left of Icon (right for RTL)', 'ultimate-member' ),
1532
- ),
1533
- 'size' => 'small',
1534
- ),
1535
- array(
1536
- 'id' => 'profile_empty_text',
1537
- 'type' => 'checkbox',
1538
- 'label' => __( 'Show a custom message if profile is empty', 'ultimate-member' ),
1539
- 'default' => um_get_metadefault( 'profile_empty_text' ),
1540
- 'tooltip' => __( 'Switch on/off the custom message that appears when the profile is empty', 'ultimate-member' ),
1541
- ),
1542
- array(
1543
- 'id' => 'profile_empty_text_emo',
1544
- 'type' => 'checkbox',
1545
- 'label' => __( 'Show the emoticon', 'ultimate-member' ),
1546
- 'default' => um_get_metadefault( 'profile_empty_text_emo' ),
1547
- 'tooltip' => __( 'Switch on/off the emoticon (sad face) that appears above the message', 'ultimate-member' ),
1548
- 'conditional' => array( 'profile_empty_text', '=', 1 ),
1549
- ),
1550
- ),
1551
- ),
1552
- 'profile_menu' => array(
1553
- 'title' => __( 'Profile Menu', 'ultimate-member' ),
1554
- 'fields' => $appearances_profile_menu_fields,
1555
- ),
1556
- 'registration_form' => array(
1557
- 'title' => __( 'Registration Form', 'ultimate-member' ),
1558
- 'fields' => array(
1559
- array(
1560
- 'id' => 'register_template',
1561
- 'type' => 'select',
1562
- 'label' => __( 'Registration Default Template', 'ultimate-member' ),
1563
- 'tooltip' => __( 'This will be the default template to output registration', 'ultimate-member' ),
1564
- 'default' => um_get_metadefault( 'register_template' ),
1565
- 'options' => UM()->shortcodes()->get_templates( 'register' ),
1566
- 'size' => 'small',
1567
- ),
1568
- array(
1569
- 'id' => 'register_max_width',
1570
- 'type' => 'text',
1571
- 'label' => __( 'Registration Maximum Width', 'ultimate-member' ),
1572
- 'default' => um_get_metadefault( 'register_max_width' ),
1573
- 'tooltip' => __( 'The maximum width this shortcode can take from the page width', 'ultimate-member' ),
1574
- 'size' => 'small',
1575
- ),
1576
- array(
1577
- 'id' => 'register_align',
1578
- 'type' => 'select',
1579
- 'label' => __( 'Registration Shortcode Alignment', 'ultimate-member' ),
1580
- 'tooltip' => __( 'The shortcode is centered by default unless you specify otherwise here', 'ultimate-member' ),
1581
- 'default' => um_get_metadefault( 'register_align' ),
1582
- 'options' => array(
1583
- 'center' => __( 'Centered', 'ultimate-member' ),
1584
- 'left' => __( 'Left aligned', 'ultimate-member' ),
1585
- 'right' => __( 'Right aligned', 'ultimate-member' ),
1586
- ),
1587
- 'size' => 'small',
1588
- ),
1589
- array(
1590
- 'id' => 'register_icons',
1591
- 'type' => 'select',
1592
- 'label' => __( 'Registration Field Icons', 'ultimate-member' ),
1593
- 'tooltip' => __( 'This controls the display of field icons in the registration form', 'ultimate-member' ),
1594
- 'default' => um_get_metadefault( 'register_icons' ),
1595
- 'options' => array(
1596
- 'field' => __( 'Show inside text field', 'ultimate-member' ),
1597
- 'label' => __( 'Show with label', 'ultimate-member' ),
1598
- 'off' => __( 'Turn off', 'ultimate-member' ),
1599
- ),
1600
- 'size' => 'small',
1601
- ),
1602
- array(
1603
- 'id' => 'register_primary_btn_word',
1604
- 'type' => 'text',
1605
- 'label' => __( 'Registration Primary Button Text', 'ultimate-member' ),
1606
- 'default' => um_get_metadefault( 'register_primary_btn_word' ),
1607
- 'tooltip' => __( 'The text that is used for primary button text', 'ultimate-member' ),
1608
- 'size' => 'medium',
1609
- ),
1610
- array(
1611
- 'id' => 'register_secondary_btn',
1612
- 'type' => 'checkbox',
1613
- 'label' => __( 'Registration Secondary Button', 'ultimate-member' ),
1614
- 'default' => 1,
1615
- 'tooltip' => __( 'Switch on/off the secondary button display in the form', 'ultimate-member' ),
1616
- ),
1617
- array(
1618
- 'id' => 'register_secondary_btn_word',
1619
- 'type' => 'text',
1620
- 'label' => __( 'Registration Secondary Button Text', 'ultimate-member' ),
1621
- 'default' => um_get_metadefault( 'register_secondary_btn_word' ),
1622
- 'tooltip' => __( 'The text that is used for the secondary button text', 'ultimate-member' ),
1623
- 'conditional' => array( 'register_secondary_btn', '=', 1 ),
1624
- 'size' => 'medium',
1625
- ),
1626
- array(
1627
- 'id' => 'register_secondary_btn_url',
1628
- 'type' => 'text',
1629
- 'label' => __( 'Registration Secondary Button URL', 'ultimate-member' ),
1630
- 'default' => um_get_metadefault( 'register_secondary_btn_url' ),
1631
- 'tooltip' => __( 'You can replace default link for this button by entering custom URL', 'ultimate-member' ),
1632
- 'conditional' => array( 'register_secondary_btn', '=', 1 ),
1633
- 'size' => 'medium',
1634
- ),
1635
- array(
1636
- 'id' => 'register_role',
1637
- 'type' => 'select',
1638
- 'label' => __( 'Registration Default Role', 'ultimate-member' ),
1639
- 'tooltip' => __( 'This will be the default role assigned to users registering thru registration form', 'ultimate-member' ),
1640
- 'default' => um_get_metadefault( 'register_role' ),
1641
- 'options' => UM()->roles()->get_roles( __( 'Default', 'ultimate-member' ) ),
1642
- 'size' => 'small',
1643
- ),
1644
- ),
1645
- ),
1646
- 'login_form' => array(
1647
- 'title' => __( 'Login Form', 'ultimate-member' ),
1648
- 'fields' => array(
1649
- array(
1650
- 'id' => 'login_template',
1651
- 'type' => 'select',
1652
- 'label' => __( 'Login Default Template', 'ultimate-member' ),
1653
- 'tooltip' => __( 'This will be the default template to output login', 'ultimate-member' ),
1654
- 'default' => um_get_metadefault( 'login_template' ),
1655
- 'options' => UM()->shortcodes()->get_templates( 'login' ),
1656
- 'size' => 'small',
1657
- ),
1658
- array(
1659
- 'id' => 'login_max_width',
1660
- 'type' => 'text',
1661
- 'label' => __( 'Login Maximum Width', 'ultimate-member' ),
1662
- 'default' => um_get_metadefault( 'login_max_width' ),
1663
- 'tooltip' => __( 'The maximum width this shortcode can take from the page width', 'ultimate-member' ),
1664
- 'size' => 'small',
1665
- ),
1666
- array(
1667
- 'id' => 'login_align',
1668
- 'type' => 'select',
1669
- 'label' => __( 'Login Shortcode Alignment', 'ultimate-member' ),
1670
- 'tooltip' => __( 'The shortcode is centered by default unless you specify otherwise here', 'ultimate-member' ),
1671
- 'default' => um_get_metadefault( 'login_align' ),
1672
- 'options' => array(
1673
- 'center' => __( 'Centered', 'ultimate-member' ),
1674
- 'left' => __( 'Left aligned', 'ultimate-member' ),
1675
- 'right' => __( 'Right aligned', 'ultimate-member' ),
1676
- ),
1677
- 'size' => 'small',
1678
- ),
1679
- array(
1680
- 'id' => 'login_icons',
1681
- 'type' => 'select',
1682
- 'label' => __( 'Login Field Icons', 'ultimate-member' ),
1683
- 'tooltip' => __( 'This controls the display of field icons in the login form', 'ultimate-member' ),
1684
- 'default' => um_get_metadefault( 'login_icons' ),
1685
- 'options' => array(
1686
- 'field' => __( 'Show inside text field', 'ultimate-member' ),
1687
- 'label' => __( 'Show with label', 'ultimate-member' ),
1688
- 'off' => __( 'Turn off', 'ultimate-member' ),
1689
- ),
1690
- 'size' => 'small',
1691
- ),
1692
- array(
1693
- 'id' => 'login_primary_btn_word',
1694
- 'type' => 'text',
1695
- 'label' => __( 'Login Primary Button Text', 'ultimate-member' ),
1696
- 'default' => um_get_metadefault( 'login_primary_btn_word' ),
1697
- 'tooltip' => __( 'The text that is used for primary button text', 'ultimate-member' ),
1698
- 'size' => 'medium',
1699
- ),
1700
- array(
1701
- 'id' => 'login_secondary_btn',
1702
- 'type' => 'checkbox',
1703
- 'label' => __( 'Login Secondary Button', 'ultimate-member' ),
1704
- 'default' => 1,
1705
- 'tooltip' => __( 'Switch on/off the secondary button display in the form', 'ultimate-member' ),
1706
- ),
1707
- array(
1708
- 'id' => 'login_secondary_btn_word',
1709
- 'type' => 'text',
1710
- 'label' => __( 'Login Secondary Button Text', 'ultimate-member' ),
1711
- 'default' => um_get_metadefault( 'login_secondary_btn_word' ),
1712
- 'tooltip' => __( 'The text that is used for the secondary button text', 'ultimate-member' ),
1713
- 'conditional' => array( 'login_secondary_btn', '=', 1 ),
1714
- 'size' => 'medium',
1715
- ),
1716
- array(
1717
- 'id' => 'login_secondary_btn_url',
1718
- 'type' => 'text',
1719
- 'label' => __( 'Login Secondary Button URL', 'ultimate-member' ),
1720
- 'default' => um_get_metadefault( 'login_secondary_btn_url' ),
1721
- 'tooltip' => __( 'You can replace default link for this button by entering custom URL', 'ultimate-member' ),
1722
- 'conditional' => array( 'login_secondary_btn', '=', 1 ),
1723
- 'size' => 'medium',
1724
- ),
1725
- array(
1726
- 'id' => 'login_forgot_pass_link',
1727
- 'type' => 'checkbox',
1728
- 'label' => __( 'Login Forgot Password Link', 'ultimate-member' ),
1729
- 'default' => 1,
1730
- 'tooltip' => __( 'Switch on/off the forgot password link in login form', 'ultimate-member' ),
1731
- ),
1732
- array(
1733
- 'id' => 'login_show_rememberme',
1734
- 'type' => 'checkbox',
1735
- 'label' => __( 'Show "Remember Me"', 'ultimate-member' ),
1736
- 'default' => 1,
1737
- 'tooltip' => __( 'Allow users to choose If they want to stay signed in even after closing the browser. If you do not show this option, the default will be to not remember login session.', 'ultimate-member' ),
1738
- ),
1739
- ),
1740
- ),
1741
- ),
1742
- ),
1743
- 'extensions' => array(
1744
- 'title' => __( 'Extensions', 'ultimate-member' ),
1745
- ),
1746
- 'licenses' => array(
1747
- 'title' => __( 'Licenses', 'ultimate-member' ),
1748
- ),
1749
- 'misc' => array(
1750
- 'title' => __( 'Misc', 'ultimate-member' ),
1751
- 'fields' => array(
1752
- array(
1753
- 'id' => 'form_asterisk',
1754
- 'type' => 'checkbox',
1755
- 'label' => __( 'Show an asterisk for required fields', 'ultimate-member' ),
1756
- ),
1757
- array(
1758
- 'id' => 'profile_title',
1759
- 'type' => 'text',
1760
- 'label' => __( 'User Profile Title', 'ultimate-member' ),
1761
- 'tooltip' => __( 'This is the title that is displayed on a specific user profile', 'ultimate-member' ),
1762
- 'size' => 'medium',
1763
- ),
1764
- array(
1765
- 'id' => 'profile_desc',
1766
- 'type' => 'textarea',
1767
- 'label' => __( 'User Profile Dynamic Meta Description', 'ultimate-member' ),
1768
- 'tooltip' => __( 'This will be used in the meta description that is available for search-engines.', 'ultimate-member' ),
1769
- 'args' => array(
1770
- 'textarea_rows' => 6,
1771
- ),
1772
- ),
1773
- array(
1774
- 'id' => 'um_profile_object_cache_stop',
1775
- 'type' => 'checkbox',
1776
- 'label' => __( 'Disable Cache User Profile', 'ultimate-member' ),
1777
- 'tooltip' => __( 'Check this box if you would like to disable Ultimate Member user\'s cache.', 'ultimate-member' ),
1778
- ),
1779
- array(
1780
- 'id' => 'enable_blocks',
1781
- 'type' => 'checkbox',
1782
- 'label' => __( 'Enable Gutenberg Blocks', 'ultimate-member' ),
1783
- 'tooltip' => __( 'Check this box if you would like to use Ultimate Member blocks in Gutenberg editor. Important some themes have the conflicts with Gutenberg editor.', 'ultimate-member' ),
1784
- ),
1785
- array(
1786
- 'id' => 'rest_api_version',
1787
- 'type' => 'select',
1788
- 'label' => __( 'REST API version', 'ultimate-member' ),
1789
- 'tooltip' => __( 'This controls the REST API version, we recommend to use the last version', 'ultimate-member' ),
1790
- 'options' => array(
1791
- '1.0' => __( '1.0 version', 'ultimate-member' ),
1792
- '2.0' => __( '2.0 version', 'ultimate-member' ),
1793
- ),
1794
- ),
1795
- // backward compatibility option leave it disabled for better security and ability to exclude posts/terms pre-query
1796
- // otherwise we filtering only results and restricted posts/terms can be visible
1797
- array(
1798
- 'id' => 'disable_restriction_pre_queries',
1799
- 'type' => 'checkbox',
1800
- 'label' => __( 'Disable pre-queries for restriction content logic (advanced)', 'ultimate-member' ),
1801
- 'tooltip' => __( 'Please enable this option only in the cases when you have big or unnecessary queries on your site with active restriction logic. If you want to exclude posts only from the results queries instead of pre_get_posts and fully-hidden post logic also please enable this option. It activates the restriction content logic until 2.2.x version without latest security enhancements', 'ultimate-member' ),
1802
- ),
1803
- $same_page_update,
1804
- array(
1805
- 'id' => 'uninstall_on_delete',
1806
- 'type' => 'checkbox',
1807
- 'label' => __( 'Remove Data on Uninstall?', 'ultimate-member' ),
1808
- 'tooltip' => __( 'Check this box if you would like Ultimate Member to completely remove all of its data when the plugin/extensions are deleted.', 'ultimate-member' ),
1809
- ),
1810
- ),
1811
- ),
1812
- 'install_info' => array(
1813
- 'title' => __( 'Install Info', 'ultimate-member' ),
1814
- 'fields' => array(
1815
- array(
1816
- 'type' => 'install_info',
1817
- ),
1818
- ),
1819
- ),
1820
- )
1821
- );
1822
-
1823
- }
1824
-
1825
-
1826
- /**
1827
- * @param array $settings
1828
- *
1829
- * @return array
1830
- */
1831
- public function sorting_licenses_options( $settings ) {
1832
- //sorting licenses
1833
- if ( ! empty( $settings['licenses']['fields'] ) ) {
1834
- $licenses = $settings['licenses']['fields'];
1835
- @uasort( $licenses, function( $a, $b ) {
1836
- return strnatcasecmp( $a['label'], $b['label'] );
1837
- } );
1838
- $settings['licenses']['fields'] = $licenses;
1839
- }
1840
-
1841
- //sorting extensions by the title
1842
- if ( ! empty( $settings['extensions']['sections'] ) ) {
1843
- $extensions = $settings['extensions']['sections'];
1844
-
1845
- @uasort( $extensions, function( $a, $b ) {
1846
- return strnatcasecmp( $a['title'], $b['title'] );
1847
- } );
1848
-
1849
- $keys = array_keys( $extensions );
1850
- $temp = array(
1851
- '' => $extensions[ $keys[0] ],
1852
- );
1853
-
1854
- unset( $extensions[ $keys[0] ] );
1855
- $extensions = $temp + $extensions;
1856
-
1857
- $settings['extensions']['sections'] = $extensions;
1858
- }
1859
-
1860
- return $settings;
1861
- }
1862
-
1863
-
1864
- /**
1865
- * @param $tab
1866
- * @param $section
1867
- *
1868
- * @return array
1869
- */
1870
- function get_section_fields( $tab, $section ) {
1871
-
1872
- if ( empty( $this->settings_structure[ $tab ] ) ) {
1873
- return array();
1874
- }
1875
-
1876
- if ( ! empty( $this->settings_structure[ $tab ]['sections'][ $section ]['fields'] ) ) {
1877
- return $this->settings_structure[ $tab ]['sections'][ $section ]['fields'];
1878
- } elseif ( ! empty( $this->settings_structure[ $tab ]['fields'] ) ) {
1879
- return $this->settings_structure[ $tab ]['fields'];
1880
- }
1881
-
1882
- return array();
1883
- }
1884
-
1885
-
1886
- /**
1887
- * Setup admin menu
1888
- */
1889
- function primary_admin_menu() {
1890
- add_submenu_page( 'ultimatemember', __( 'Settings', 'ultimate-member' ), __( 'Settings', 'ultimate-member' ), 'manage_options', 'um_options', array( &$this, 'settings_page' ) );
1891
- }
1892
-
1893
-
1894
- /**
1895
- * Settings page callback
1896
- */
1897
- function settings_page() {
1898
- $current_tab = empty( $_GET['tab'] ) ? '' : sanitize_key( $_GET['tab'] );
1899
- $current_subtab = empty( $_GET['section'] ) ? '' : sanitize_key( $_GET['section'] );
1900
-
1901
- $settings_struct = $this->settings_structure[ $current_tab ];
1902
-
1903
- //remove not option hidden fields
1904
- if ( ! empty( $settings_struct['fields'] ) ) {
1905
- foreach ( $settings_struct['fields'] as $field_key => $field_options ) {
1906
-
1907
- if ( isset( $field_options['is_option'] ) && $field_options['is_option'] === false ) {
1908
- unset( $settings_struct['fields'][ $field_key ] );
1909
- }
1910
-
1911
- }
1912
- }
1913
-
1914
- if ( empty( $settings_struct['fields'] ) && empty( $settings_struct['sections'] ) ) {
1915
- um_js_redirect( add_query_arg( array( 'page' => 'um_options' ), admin_url( 'admin.php' ) ) );
1916
- }
1917
-
1918
- if ( ! empty( $settings_struct['sections'] ) ) {
1919
- if ( empty( $settings_struct['sections'][ $current_subtab ] ) ) {
1920
- um_js_redirect( add_query_arg( array( 'page' => 'um_options', 'tab' => $current_tab ), admin_url( 'admin.php' ) ) );
1921
- }
1922
- }
1923
-
1924
- echo '<div id="um-settings-wrap" class="wrap"><h2>' . __( 'Ultimate Member - Settings', 'ultimate-member' ) . '</h2>';
1925
-
1926
- echo $this->generate_tabs_menu() . $this->generate_subtabs_menu( $current_tab );
1927
-
1928
- /**
1929
- * UM hook
1930
- *
1931
- * @type action
1932
- * @title um_settings_page_before_{$current_tab}_{$current_subtab}_content
1933
- * @description Show some content before settings page content
1934
- * @change_log
1935
- * ["Since: 2.0"]
1936
- * @usage add_action( 'um_settings_page_before_{$current_tab}_{$current_subtab}_content', 'function_name', 10 );
1937
- * @example
1938
- * <?php
1939
- * add_action( 'um_settings_page_before_{$current_tab}_{$current_subtab}_content', 'my_settings_page_before', 10 );
1940
- * function my_settings_page_before() {
1941
- * // your code here
1942
- * }
1943
- * ?>
1944
- */
1945
- do_action( "um_settings_page_before_" . $current_tab . "_" . $current_subtab . "_content" );
1946
-
1947
- if ( in_array( $current_tab, apply_filters('um_settings_custom_tabs', array( 'licenses', 'install_info' ) ) ) || in_array( $current_subtab, apply_filters( 'um_settings_custom_subtabs', array(), $current_tab ) ) ) {
1948
-
1949
- /**
1950
- * UM hook
1951
- *
1952
- * @type action
1953
- * @title um_settings_page_{$current_tab}_{$current_subtab}_before_section
1954
- * @description Show some content before section content at settings page
1955
- * @change_log
1956
- * ["Since: 2.0"]
1957
- * @usage add_action( 'um_settings_page_{$current_tab}_{$current_subtab}_before_section', 'function_name', 10 );
1958
- * @example
1959
- * <?php
1960
- * add_action( 'um_settings_page_{$current_tab}_{$current_subtab}_before_section', 'my_settings_page_before_section', 10 );
1961
- * function my_settings_page_before_section() {
1962
- * // your code here
1963
- * }
1964
- * ?>
1965
- */
1966
- do_action( "um_settings_page_" . $current_tab . "_" . $current_subtab . "_before_section" );
1967
-
1968
- $section_fields = $this->get_section_fields( $current_tab, $current_subtab );
1969
- $settings_section = $this->render_settings_section( $section_fields, $current_tab, $current_subtab );
1970
-
1971
- /**
1972
- * UM hook
1973
- *
1974
- * @type filter
1975
- * @title um_settings_section_{$current_tab}_{$current_subtab}_content
1976
- *
1977
- * @description Render settings section
1978
- * @input_vars
1979
- * [{"var":"$content","type":"string","desc":"Section content"},
1980
- * {"var":"$section_fields","type":"array","desc":"Section Fields"}]
1981
- * @change_log
1982
- * ["Since: 2.0"]
1983
- * @usage add_filter( 'um_settings_section_{$current_tab}_{$current_subtab}_content', 'function_name', 10, 2 );
1984
- * @example
1985
- * <?php
1986
- * add_filter( 'um_settings_section_{$current_tab}_{$current_subtab}_content', 'my_settings_section', 10, 2 );
1987
- * function my_settings_section( $content ) {
1988
- * // your code here
1989
- * return $content;
1990
- * }
1991
- * ?>
1992
- */
1993
- echo apply_filters( 'um_settings_section_' . $current_tab . '_' . $current_subtab . '_content',
1994
- $settings_section,
1995
- $section_fields
1996
- );
1997
-
1998
- } else { ?>
1999
-
2000
- <form method="post" action="" name="um-settings-form" id="um-settings-form">
2001
- <input type="hidden" value="save" name="um-settings-action" />
2002
-
2003
- <?php
2004
- /**
2005
- * UM hook
2006
- *
2007
- * @type action
2008
- * @title um_settings_page_{$current_tab}_{$current_subtab}_before_section
2009
- * @description Show some content before section content at settings page
2010
- * @change_log
2011
- * ["Since: 2.0"]
2012
- * @usage add_action( 'um_settings_page_{$current_tab}_{$current_subtab}_before_section', 'function_name', 10 );
2013
- * @example
2014
- * <?php
2015
- * add_action( 'um_settings_page_{$current_tab}_{$current_subtab}_before_section', 'my_settings_page_before_section', 10 );
2016
- * function my_settings_page_before_section() {
2017
- * // your code here
2018
- * }
2019
- * ?>
2020
- */
2021
- do_action( "um_settings_page_" . $current_tab . "_" . $current_subtab . "_before_section" );
2022
-
2023
- $section_fields = $this->get_section_fields( $current_tab, $current_subtab );
2024
- $settings_section = $this->render_settings_section( $section_fields, $current_tab, $current_subtab );
2025
-
2026
- /**
2027
- * UM hook
2028
- *
2029
- * @type filter
2030
- * @title um_settings_section_{$current_tab}_{$current_subtab}_content
2031
- * @description Render settings section
2032
- * @input_vars
2033
- * [{"var":"$content","type":"string","desc":"Section content"},
2034
- * {"var":"$section_fields","type":"array","desc":"Section Fields"}]
2035
- * @change_log
2036
- * ["Since: 2.0"]
2037
- * @usage add_filter( 'um_settings_section_{$current_tab}_{$current_subtab}_content', 'function_name', 10, 2 );
2038
- * @example
2039
- * <?php
2040
- * add_filter( 'um_settings_section_{$current_tab}_{$current_subtab}_content', 'my_settings_section', 10, 2 );
2041
- * function my_settings_section( $content ) {
2042
- * // your code here
2043
- * return $content;
2044
- * }
2045
- * ?>
2046
- */
2047
- echo apply_filters( 'um_settings_section_' . $current_tab . '_' . $current_subtab . '_content',
2048
- $settings_section,
2049
- $section_fields
2050
- ); ?>
2051
-
2052
-
2053
- <p class="submit">
2054
- <input type="submit" name="submit" id="submit" class="button button-primary" value="<?php esc_attr_e( 'Save Changes', 'ultimate-member' ) ?>" />
2055
- <?php $um_settings_nonce = wp_create_nonce( 'um-settings-nonce' ); ?>
2056
- <input type="hidden" name="__umnonce" value="<?php echo esc_attr( $um_settings_nonce ); ?>" />
2057
- </p>
2058
- </form>
2059
-
2060
- <?php }
2061
- }
2062
-
2063
-
2064
- /**
2065
- * Generate pages tabs
2066
- *
2067
- * @param string $page
2068
- * @return string
2069
- */
2070
- function generate_tabs_menu( $page = 'settings' ) {
2071
-
2072
- $tabs = '<h2 class="nav-tab-wrapper um-nav-tab-wrapper">';
2073
-
2074
- switch( $page ) {
2075
- case 'settings':
2076
- $menu_tabs = array();
2077
- foreach ( $this->settings_structure as $slug => $tab ) {
2078
- if ( ! empty( $tab['fields'] ) ) {
2079
- foreach ( $tab['fields'] as $field_key => $field_options ) {
2080
- if ( isset( $field_options['is_option'] ) && $field_options['is_option'] === false ) {
2081
- unset( $tab['fields'][ $field_key ] );
2082
- }
2083
- }
2084
- }
2085
-
2086
- if ( ! empty( $tab['fields'] ) || ! empty( $tab['sections'] ) ) {
2087
- $menu_tabs[ $slug ] = $tab['title'];
2088
- }
2089
- }
2090
-
2091
- $current_tab = empty( $_GET['tab'] ) ? '' : sanitize_key( $_GET['tab'] );
2092
- foreach ( $menu_tabs as $name => $label ) {
2093
- $active = ( $current_tab == $name ) ? 'nav-tab-active' : '';
2094
- $tabs .= '<a href="' . esc_url( admin_url( 'admin.php?page=um_options' . ( empty( $name ) ? '' : '&tab=' . $name ) ) ) . '" class="nav-tab ' . esc_attr( $active ) . '">' .
2095
- $label .
2096
- '</a>';
2097
- }
2098
-
2099
- break;
2100
- default:
2101
- /**
2102
- * UM hook
2103
- *
2104
- * @type filter
2105
- * @title um_generate_tabs_menu_{$page}
2106
- * @description Generate tabs menu
2107
- * @input_vars
2108
- * [{"var":"$tabs","type":"array","desc":"UM menu tabs"}]
2109
- * @change_log
2110
- * ["Since: 2.0"]
2111
- * @usage add_filter( 'um_generate_tabs_menu_{$page}', 'function_name', 10, 1 );
2112
- * @example
2113
- * <?php
2114
- * add_filter( 'um_generate_tabs_menu_{$page}', 'my_tabs_menu', 10, 1 );
2115
- * function my_tabs_menu( $tabs ) {
2116
- * // your code here
2117
- * return $tabs;
2118
- * }
2119
- * ?>
2120
- */
2121
- $tabs = apply_filters( 'um_generate_tabs_menu_' . $page, $tabs );
2122
- break;
2123
- }
2124
-
2125
- return $tabs . '</h2>';
2126
- }
2127
-
2128
-
2129
- /**
2130
- * @param string $tab
2131
- *
2132
- * @return string
2133
- */
2134
- function generate_subtabs_menu( $tab = '' ) {
2135
- if ( empty( $this->settings_structure[ $tab ]['sections'] ) ) {
2136
- return '';
2137
- }
2138
-
2139
- $menu_subtabs = array();
2140
- foreach ( $this->settings_structure[ $tab ]['sections'] as $slug => $subtab ) {
2141
- $menu_subtabs[ $slug ] = $subtab['title'];
2142
- }
2143
-
2144
- $subtabs = '<div><ul class="subsubsub">';
2145
-
2146
- $current_tab = empty( $_GET['tab'] ) ? '' : sanitize_key( $_GET['tab'] );
2147
- $current_subtab = empty( $_GET['section'] ) ? '' : sanitize_key( $_GET['section'] );
2148
- foreach ( $menu_subtabs as $name => $label ) {
2149
- $active = ( $current_subtab == $name ) ? 'current' : '';
2150
- $subtabs .= '<a href="' . esc_url( admin_url( 'admin.php?page=um_options' . ( empty( $current_tab ) ? '' : '&tab=' . $current_tab ) . ( empty( $name ) ? '' : '&section=' . $name ) ) ) . '" class="' . $active . '">'
2151
- . $label .
2152
- '</a> | ';
2153
- }
2154
-
2155
- return substr( $subtabs, 0, -3 ) . '</ul></div>';
2156
- }
2157
-
2158
-
2159
- /**
2160
- * Handler for settings forms
2161
- * when "Save Settings" button click
2162
- *
2163
- */
2164
- function save_settings_handler() {
2165
-
2166
- if ( isset( $_POST['um-settings-action'] ) && 'save' === sanitize_key( $_POST['um-settings-action'] ) && ! empty( $_POST['um_options'] ) ) {
2167
-
2168
- $nonce = ! empty( $_POST['__umnonce'] ) ? $_POST['__umnonce'] : '';
2169
-
2170
- if ( ( ! wp_verify_nonce( $nonce, 'um-settings-nonce' ) || empty( $nonce ) ) || ! current_user_can( 'manage_options' ) ) {
2171
- // This nonce is not valid.
2172
- wp_die( __( 'Security Check', 'ultimate-member' ) );
2173
- }
2174
-
2175
- /**
2176
- * UM hook
2177
- *
2178
- * @type action
2179
- * @title um_settings_before_save
2180
- * @description Before settings save action
2181
- * @change_log
2182
- * ["Since: 2.0"]
2183
- * @usage add_action( 'um_settings_before_save', 'function_name', 10 );
2184
- * @example
2185
- * <?php
2186
- * add_action( 'um_settings_before_save', 'my_settings_before_save', 10 );
2187
- * function my_settings_before_save() {
2188
- * // your code here
2189
- * }
2190
- * ?>
2191
- */
2192
- do_action( "um_settings_before_save" );
2193
-
2194
- /**
2195
- * UM hook
2196
- *
2197
- * @type filter
2198
- * @title um_change_settings_before_save
2199
- * @description Change settings before save
2200
- * @input_vars
2201
- * [{"var":"$settings","type":"array","desc":"UM Settings on save"}]
2202
- * @change_log
2203
- * ["Since: 2.0"]
2204
- * @usage add_filter( 'um_change_settings_before_save', 'function_name', 10, 1 );
2205
- * @example
2206
- * <?php
2207
- * add_filter( 'um_change_settings_before_save', 'my_change_settings_before_save', 10, 1 );
2208
- * function my_change_settings_before_save( $settings ) {
2209
- * // your code here
2210
- * return $settings;
2211
- * }
2212
- * ?>
2213
- */
2214
- $settings = apply_filters( 'um_change_settings_before_save', $_POST['um_options'] );
2215
-
2216
- $settings = UM()->admin()->sanitize_options( $settings );
2217
-
2218
- foreach ( $settings as $key => $value ) {
2219
- UM()->options()->update( $key, $value );
2220
- }
2221
-
2222
- /**
2223
- * UM hook
2224
- *
2225
- * @type action
2226
- * @title um_settings_save
2227
- * @description After settings save action
2228
- * @change_log
2229
- * ["Since: 2.0"]
2230
- * @usage add_action( 'um_settings_save', 'function_name', 10 );
2231
- * @example
2232
- * <?php
2233
- * add_action( 'um_settings_save', 'my_settings_save', 10 );
2234
- * function my_settings_save() {
2235
- * // your code here
2236
- * }
2237
- * ?>
2238
- */
2239
- do_action( 'um_settings_save' );
2240
-
2241
- //redirect after save settings
2242
- $arg = array(
2243
- 'page' => 'um_options',
2244
- 'update' => 'settings_updated',
2245
- );
2246
-
2247
- if ( ! empty( $_GET['tab'] ) ) {
2248
- $arg['tab'] = sanitize_key( $_GET['tab'] );
2249
- }
2250
-
2251
- if ( ! empty( $_GET['section'] ) ) {
2252
- $arg['section'] = sanitize_key( $_GET['section'] );
2253
- }
2254
-
2255
- um_js_redirect( add_query_arg( $arg, admin_url( 'admin.php' ) ) );
2256
- }
2257
- }
2258
-
2259
-
2260
- function set_default_if_empty( $settings ) {
2261
- $tab = '';
2262
- if ( ! empty( $_GET['tab'] ) ) {
2263
- $tab = sanitize_key( $_GET['tab'] );
2264
- }
2265
-
2266
- $section = '';
2267
- if ( ! empty( $_GET['section'] ) ) {
2268
- $section = sanitize_key( $_GET['section'] );
2269
- }
2270
-
2271
-
2272
- if ( 'access' === $tab && empty( $section ) ) {
2273
- if ( ! array_key_exists( 'access_exclude_uris', $settings ) ) {
2274
- $settings['access_exclude_uris'] = array();
2275
- }
2276
- }
2277
-
2278
- return $settings;
2279
- }
2280
-
2281
-
2282
- /**
2283
- * Remove empty values from multi text fields
2284
- *
2285
- * @param $settings
2286
- * @return array
2287
- */
2288
- function remove_empty_values( $settings ) {
2289
- $tab = '';
2290
- if ( ! empty( $_GET['tab'] ) ) {
2291
- $tab = sanitize_key( $_GET['tab'] );
2292
- }
2293
-
2294
- $section = '';
2295
- if ( ! empty( $_GET['section'] ) ) {
2296
- $section = sanitize_key( $_GET['section'] );
2297
- }
2298
-
2299
- if ( isset( $this->settings_structure[ $tab ]['sections'][ $section ]['fields'] ) ) {
2300
- $fields = $this->settings_structure[ $tab ]['sections'][ $section ]['fields'];
2301
- } else {
2302
- $fields = $this->settings_structure[ $tab ]['fields'];
2303
- }
2304
-
2305
- if ( empty( $fields ) ) {
2306
- return $settings;
2307
- }
2308
-
2309
-
2310
- $filtered_settings = array();
2311
- foreach ( $settings as $key => $value ) {
2312
-
2313
- $filtered_settings[ $key ] = $value;
2314
-
2315
- foreach ( $fields as $field ) {
2316
- if ( $field['id'] == $key && isset( $field['type'] ) && $field['type'] == 'multi_text' ) {
2317
- $filtered_settings[ $key ] = array_filter( $settings[ $key ] );
2318
- }
2319
- }
2320
- }
2321
-
2322
- return $filtered_settings;
2323
- }
2324
-
2325
-
2326
- /**
2327
- *
2328
- */
2329
- function check_permalinks_changes() {
2330
- if ( ! empty( $_POST['um_options']['permalink_base'] ) ) {
2331
- if ( UM()->options()->get( 'permalink_base' ) !== $_POST['um_options']['permalink_base'] ) {
2332
- $this->need_change_permalinks = true;
2333
- }
2334
- }
2335
-
2336
- // set variable if gravatar settings were changed
2337
- // update for um_member_directory_data metakey
2338
- if ( isset( $_POST['um_options']['use_gravatars'] ) ) {
2339
- $use_gravatar = UM()->options()->get( 'use_gravatars' );
2340
- if ( ( empty( $use_gravatar ) && ! empty( $_POST['um_options']['use_gravatars'] ) ) || ( ! empty( $use_gravatar ) && empty( $_POST['um_options']['use_gravatars'] ) ) ) {
2341
- $this->gravatar_changed = true;
2342
- }
2343
- }
2344
- }
2345
-
2346
-
2347
- /**
2348
- *
2349
- */
2350
- function on_settings_save() {
2351
- if ( ! empty( $_POST['um_options'] ) ) {
2352
-
2353
- if ( ! empty( $_POST['um_options']['pages_settings'] ) ) {
2354
- $post_ids = new \WP_Query( array(
2355
- 'post_type' => 'page',
2356
- 'meta_query' => array(
2357
- array(
2358
- 'key' => '_um_core',
2359
- 'compare' => 'EXISTS'
2360
- )
2361
- ),
2362
- 'posts_per_page' => -1,
2363
- 'fields' => 'ids'
2364
- ) );
2365
-
2366
- $post_ids = $post_ids->get_posts();
2367
-
2368
- if ( ! empty( $post_ids ) ) {
2369
- foreach ( $post_ids as $post_id ) {
2370
- delete_post_meta( $post_id, '_um_core' );
2371
- }
2372
- }
2373
-
2374
- foreach ( $_POST['um_options'] as $option_slug => $post_id ) {
2375
- $slug = str_replace( 'core_', '', $option_slug );
2376
- update_post_meta( $post_id, '_um_core', $slug );
2377
- }
2378
-
2379
- // reset rewrite rules after re-save pages
2380
- UM()->rewrite()->reset_rules();
2381
-
2382
- } elseif ( ! empty( $_POST['um_options']['permalink_base'] ) ) {
2383
- if ( ! empty( $this->need_change_permalinks ) ) {
2384
- $users = get_users( array(
2385
- 'fields' => 'ids',
2386
- ) );
2387
- if ( ! empty( $users ) ) {
2388
- foreach ( $users as $user_id ) {
2389
- UM()->user()->generate_profile_slug( $user_id );
2390
- }
2391
- }
2392
- }
2393
-
2394
-
2395
- // update for um_member_directory_data metakey
2396
- if ( isset( $_POST['um_options']['use_gravatars'] ) ) {
2397
- if ( $this->gravatar_changed ) {
2398
- global $wpdb;
2399
-
2400
- if ( ! empty( $_POST['um_options']['use_gravatars'] ) ) {
2401
-
2402
- $results = $wpdb->get_col(
2403
- "SELECT u.ID FROM {$wpdb->users} AS u
2404
- LEFT JOIN {$wpdb->usermeta} AS um ON ( um.user_id = u.ID AND um.meta_key = 'synced_gravatar_hashed_id' )
2405
- LEFT JOIN {$wpdb->usermeta} AS um2 ON ( um2.user_id = u.ID AND um2.meta_key = 'um_member_directory_data' )
2406
- WHERE um.meta_value != '' AND um.meta_value IS NOT NULL AND
2407
- um2.meta_value LIKE '%s:13:\"profile_photo\";b:0;%'"
2408
- );
2409
-
2410
- } else {
2411
-
2412
- $results = $wpdb->get_col(
2413
- "SELECT u.ID FROM {$wpdb->users} AS u
2414
- LEFT JOIN {$wpdb->usermeta} AS um ON ( um.user_id = u.ID AND ( um.meta_key = 'synced_profile_photo' || um.meta_key = 'profile_photo' ) )
2415
- LEFT JOIN {$wpdb->usermeta} AS um2 ON ( um2.user_id = u.ID AND um2.meta_key = 'um_member_directory_data' )
2416
- WHERE ( um.meta_value IS NULL OR um.meta_value = '' ) AND
2417
- um2.meta_value LIKE '%s:13:\"profile_photo\";b:1;%'"
2418
- );
2419
-
2420
- }
2421
-
2422
- if ( ! empty( $results ) ) {
2423
- foreach ( $results as $user_id ) {
2424
- $md_data = get_user_meta( $user_id, 'um_member_directory_data', true );
2425
- if ( ! empty( $md_data ) ) {
2426
- $md_data['profile_photo'] = ! empty( $_POST['um_options']['use_gravatars'] );
2427
- update_user_meta( $user_id, 'um_member_directory_data', $md_data );
2428
- }
2429
- }
2430
- }
2431
- }
2432
- }
2433
-
2434
- } elseif ( isset( $_POST['um_options']['member_directory_own_table'] ) ) {
2435
- if ( empty( $_POST['um_options']['member_directory_own_table'] ) ) {
2436
- global $wpdb;
2437
-
2438
- $results = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}um_metadata LIMIT 1", ARRAY_A );
2439
-
2440
- if ( ! empty( $results ) ) {
2441
- $wpdb->query("TRUNCATE TABLE {$wpdb->prefix}um_metadata" );
2442
- }
2443
-
2444
- update_option( 'um_member_directory_truncated', time() );
2445
- }
2446
- } elseif ( isset( $_POST['um_options']['account_hide_in_directory_default'] ) ) {
2447
-
2448
- global $wpdb;
2449
-
2450
- if ( $_POST['um_options']['account_hide_in_directory_default'] === 'No' ) {
2451
-
2452
- $results = $wpdb->get_col(
2453
- "SELECT u.ID FROM {$wpdb->users} AS u
2454
- LEFT JOIN {$wpdb->usermeta} AS um ON ( um.user_id = u.ID AND um.meta_key = 'hide_in_members' )
2455
- LEFT JOIN {$wpdb->usermeta} AS um2 ON ( um2.user_id = u.ID AND um2.meta_key = 'um_member_directory_data' )
2456
- WHERE um.meta_value IS NULL AND
2457
- um2.meta_value LIKE '%s:15:\"hide_in_members\";b:1;%'"
2458
- );
2459
-
2460
- } else {
2461
-
2462
- $results = $wpdb->get_col(
2463
- "SELECT u.ID FROM {$wpdb->users} AS u
2464
- LEFT JOIN {$wpdb->usermeta} AS um ON ( um.user_id = u.ID AND um.meta_key = 'hide_in_members' )
2465
- LEFT JOIN {$wpdb->usermeta} AS um2 ON ( um2.user_id = u.ID AND um2.meta_key = 'um_member_directory_data' )
2466
- WHERE um.meta_value IS NULL AND
2467
- um2.meta_value LIKE '%s:15:\"hide_in_members\";b:0;%'"
2468
- );
2469
-
2470
- }
2471
-
2472
- if ( ! empty( $results ) ) {
2473
- foreach ( $results as $user_id ) {
2474
- $md_data = get_user_meta( $user_id, 'um_member_directory_data', true );
2475
- if ( ! empty( $md_data ) ) {
2476
- $md_data['hide_in_members'] = ( $_POST['um_options']['account_hide_in_directory_default'] === 'No' ) ? false : true;
2477
- update_user_meta( $user_id, 'um_member_directory_data', $md_data );
2478
- }
2479
- }
2480
- }
2481
-
2482
- }
2483
- }
2484
- }
2485
-
2486
-
2487
- /**
2488
- *
2489
- */
2490
- function before_licenses_save() {
2491
- if ( empty( $_POST['um_options'] ) || empty( $_POST['licenses_settings'] ) ) {
2492
- return;
2493
- }
2494
-
2495
- foreach ( $_POST['um_options'] as $key => $value ) {
2496
- $this->previous_licenses[ sanitize_key( $key ) ] = UM()->options()->get( $key );
2497
- }
2498
- }
2499
-
2500
-
2501
- /**
2502
- *
2503
- */
2504
- function licenses_save() {
2505
- if ( empty( $_POST['um_options'] ) || empty( $_POST['licenses_settings'] ) ) {
2506
- return;
2507
- }
2508
-
2509
- foreach ( $_POST['um_options'] as $key => $value ) {
2510
- $key = sanitize_key( $key );
2511
- $value = sanitize_text_field( $value );
2512
-
2513
- $edd_action = '';
2514
- $license_key = '';
2515
- if ( empty( $this->previous_licenses[ $key ] ) && ! empty( $value ) || ( ! empty( $this->previous_licenses[ $key ] ) && ! empty( $value ) && $this->previous_licenses[ $key ] != $value ) ) {
2516
- $edd_action = 'activate_license';
2517
- $license_key = $value;
2518
- } elseif ( ! empty( $this->previous_licenses[ $key ] ) && empty( $value ) ) {
2519
- $edd_action = 'deactivate_license';
2520
- $license_key = $this->previous_licenses[ $key ];
2521
- } elseif ( ! empty( $this->previous_licenses[ $key ] ) && ! empty( $value ) ) {
2522
- $edd_action = 'check_license';
2523
- $license_key = $value;
2524
- }
2525
-
2526
- if ( empty( $edd_action ) ) {
2527
- continue;
2528
- }
2529
-
2530
- $item_name = false;
2531
- $version = false;
2532
- $author = false;
2533
- foreach ( $this->settings_structure['licenses']['fields'] as $field_data ) {
2534
- if ( $field_data['id'] == $key ) {
2535
- $item_name = ! empty( $field_data['item_name'] ) ? $field_data['item_name'] : false;
2536
- $version = ! empty( $field_data['version'] ) ? $field_data['version'] : false;
2537
- $author = ! empty( $field_data['author'] ) ? $field_data['author'] : false;
2538
- }
2539
- }
2540
-
2541
- $api_params = array(
2542
- 'edd_action' => $edd_action,
2543
- 'license' => $license_key,
2544
- 'item_name' => $item_name,
2545
- 'version' => $version,
2546
- 'author' => $author,
2547
- 'url' => home_url(),
2548
- );
2549
-
2550
- $request = wp_remote_post(
2551
- UM()->store_url,
2552
- array(
2553
- 'timeout' => UM()->request_timeout,
2554
- 'sslverify' => false,
2555
- 'body' => $api_params
2556
- )
2557
- );
2558
-
2559
- if ( ! is_wp_error( $request ) ) {
2560
- $request = json_decode( wp_remote_retrieve_body( $request ) );
2561
- } else {
2562
- $request = wp_remote_post(
2563
- UM()->store_url,
2564
- array(
2565
- 'timeout' => UM()->request_timeout,
2566
- 'sslverify' => true,
2567
- 'body' => $api_params
2568
- )
2569
- );
2570
-
2571
- if ( ! is_wp_error( $request ) ) {
2572
- $request = json_decode( wp_remote_retrieve_body( $request ) );
2573
- }
2574
- }
2575
-
2576
- $request = ( $request ) ? maybe_unserialize( $request ) : false;
2577
-
2578
- if ( $edd_action == 'activate_license' || $edd_action == 'check_license' ) {
2579
- update_option( "{$key}_edd_answer", $request );
2580
- } else {
2581
- delete_option( "{$key}_edd_answer" );
2582
- }
2583
-
2584
- }
2585
- }
2586
-
2587
-
2588
- /**
2589
- *
2590
- */
2591
- function settings_before_email_tab() {
2592
- $email_key = empty( $_GET['email'] ) ? '' : sanitize_key( $_GET['email'] );
2593
- $emails = UM()->config()->email_notifications;
2594
-
2595
- if ( empty( $email_key ) || empty( $emails[ $email_key ] ) ) {
2596
- include_once um_path . 'includes/admin/core/list-tables/emails-list-table.php';
2597
- }
2598
- }
2599
-
2600
-
2601
- /**
2602
- * @param $section
2603
- *
2604
- * @return string
2605
- */
2606
- function settings_email_tab( $section ) {
2607
- $email_key = empty( $_GET['email'] ) ? '' : sanitize_key( $_GET['email'] );
2608
- $emails = UM()->config()->email_notifications;
2609
-
2610
- if ( empty( $email_key ) || empty( $emails[ $email_key ] ) ) {
2611
- return $section;
2612
- }
2613
-
2614
- $in_theme = UM()->mail()->template_in_theme( $email_key );
2615
-
2616
- /**
2617
- * UM hook
2618
- *
2619
- * @type filter
2620
- * @title um_admin_settings_email_section_fields
2621
- * @description Extend UM Email Settings
2622
- * @input_vars
2623
- * [{"var":"$settings","type":"array","desc":"UM Email Settings"},
2624
- * {"var":"$email_key","type":"string","desc":"Email Key"}]
2625
- * @change_log
2626
- * ["Since: 2.0"]
2627
- * @usage add_filter( 'um_admin_settings_email_section_fields', 'function_name', 10, 2 );
2628
- * @example
2629
- * <?php
2630
- * add_filter( 'um_admin_settings_email_section_fields', 'my_admin_settings_email_section', 10, 2 );
2631
- * function my_admin_settings_email_section( $settings, $email_key ) {
2632
- * // your code here
2633
- * return $settings;
2634
- * }
2635
- * ?>
2636
- */
2637
- $section_fields = apply_filters( 'um_admin_settings_email_section_fields', array(
2638
- array(
2639
- 'id' => 'um_email_template',
2640
- 'type' => 'hidden',
2641
- 'value' => $email_key,
2642
- ),
2643
- array(
2644
- 'id' => $email_key . '_on',
2645
- 'type' => 'checkbox',
2646
- 'label' => $emails[ $email_key ]['title'],
2647
- 'tooltip' => $emails[ $email_key ]['description'],
2648
- ),
2649
- array(
2650
- 'id' => $email_key . '_sub',
2651
- 'type' => 'text',
2652
- 'label' => __( 'Subject Line', 'ultimate-member' ),
2653
- 'conditional' => array( $email_key . '_on', '=', 1 ),
2654
- 'tooltip' => __( 'This is the subject line of the e-mail', 'ultimate-member' ),
2655
- ),
2656
- array(
2657
- 'id' => $email_key,
2658
- 'type' => 'email_template',
2659
- 'label' => __( 'Message Body', 'ultimate-member' ),
2660
- 'conditional' => array( $email_key . '_on', '=', 1 ),
2661
- 'tooltip' => __( 'This is the content of the e-mail', 'ultimate-member' ),
2662
- 'value' => UM()->mail()->get_email_template( $email_key ),
2663
- 'in_theme' => $in_theme
2664
- ),
2665
- ), $email_key );
2666
-
2667
- return $this->render_settings_section( $section_fields, 'email', $email_key );
2668
- }
2669
-
2670
-
2671
- /**
2672
- *
2673
- */
2674
- function settings_appearance_profile_tab() {
2675
- wp_enqueue_media();
2676
- }
2677
-
2678
-
2679
- /**
2680
- * @param $html
2681
- * @param $section_fields
2682
- *
2683
- * @return string
2684
- */
2685
- function settings_licenses_tab( $html, $section_fields ) {
2686
- ob_start(); ?>
2687
-
2688
- <div class="wrap-licenses">
2689
- <input type="hidden" id="licenses_settings" name="licenses_settings" value="1">
2690
- <?php $um_settings_nonce = wp_create_nonce( 'um-settings-nonce' ); ?>
2691
- <input type="hidden" name="__umnonce" value="<?php echo esc_attr( $um_settings_nonce ); ?>" />
2692
- <table class="form-table um-settings-section">
2693
- <tbody>
2694
- <?php foreach ( $section_fields as $field_data ) {
2695
- $option_value = UM()->options()->get( $field_data['id'] );
2696
- $value = isset( $option_value ) && ! empty( $option_value ) ? $option_value : ( isset( $field_data['default'] ) ? $field_data['default'] : '' );
2697
-
2698
- $license = get_option( "{$field_data['id']}_edd_answer" );
2699
-
2700
- if ( is_object( $license ) && ! empty( $value ) ) {
2701
- // activate_license 'invalid' on anything other than valid, so if there was an error capture it
2702
- if ( empty( $license->success ) ) {
2703
-
2704
- if ( ! empty( $license->error ) ) {
2705
- switch ( $license->error ) {
2706
-
2707
- case 'expired' :
2708
-
2709
- $class = 'expired';
2710
- $messages[] = sprintf(
2711
- __( 'Your license key expired on %s. Please <a href="%s" target="_blank">renew your license key</a>.', 'ultimate-member' ),
2712
- date_i18n( get_option( 'date_format' ), strtotime( $license->expires, current_time( 'timestamp' ) ) ),
2713
- 'https://ultimatemember.com/checkout/?edd_license_key=' . $value . '&utm_campaign=admin&utm_source=licenses&utm_medium=expired'
2714
- );
2715
-
2716
- $license_status = 'license-' . $class . '-notice';
2717
-
2718
- break;
2719
-
2720
- case 'revoked' :
2721
-
2722
- $class = 'error';
2723
- $messages[] = sprintf(
2724
- __( 'Your license key has been disabled. Please <a href="%s" target="_blank">contact support</a> for more information.', 'ultimate-member' ),
2725
- 'https://ultimatemember.com/support?utm_campaign=admin&utm_source=licenses&utm_medium=revoked'
2726
- );
2727
-
2728
- $license_status = 'license-' . $class . '-notice';
2729
-
2730
- break;
2731
-
2732
- case 'missing' :
2733
-
2734
- $class = 'error';
2735
- $messages[] = sprintf(
2736
- __( 'Invalid license. Please <a href="%s" target="_blank">visit your account page</a> and verify it.', 'ultimate-member' ),
2737
- 'https://ultimatemember.com/account?utm_campaign=admin&utm_source=licenses&utm_medium=missing'
2738
- );
2739
-
2740
- $license_status = 'license-' . $class . '-notice';
2741
-
2742
- break;
2743
-
2744
- case 'invalid' :
2745
- case 'site_inactive' :
2746
-
2747
- $class = 'error';
2748
- $messages[] = sprintf(
2749
- __( 'Your %s is not active for this URL. Please <a href="%s" target="_blank">visit your account page</a> to manage your license key URLs.', 'ultimate-member' ),
2750
- $field_data['item_name'],
2751
- 'https://ultimatemember.com/account?utm_campaign=admin&utm_source=licenses&utm_medium=invalid'
2752
- );
2753
-
2754
- $license_status = 'license-' . $class . '-notice';
2755
-
2756
- break;
2757
-
2758
- case 'item_name_mismatch' :
2759
-
2760
- $class = 'error';
2761
- $messages[] = sprintf( __( 'This appears to be an invalid license key for %s.', 'ultimate-member' ), $field_data['item_name'] );
2762
-
2763
- $license_status = 'license-' . $class . '-notice';
2764
-
2765
- break;
2766
-
2767
- case 'no_activations_left':
2768
-
2769
- $class = 'error';
2770
- $messages[] = sprintf( __( 'Your license key has reached its activation limit. <a href="%s">View possible upgrades</a> now.', 'ultimate-member' ), 'https://ultimatemember.com/account' );
2771
-
2772
- $license_status = 'license-' . $class . '-notice';
2773
-
2774
- break;
2775
-
2776
- case 'license_not_activable':
2777
-
2778
- $class = 'error';
2779
- $messages[] = __( 'The key you entered belongs to a bundle, please use the product specific license key.', 'ultimate-member' );
2780
-
2781
- $license_status = 'license-' . $class . '-notice';
2782
- break;
2783
-
2784
- default :
2785
-
2786
- $class = 'error';
2787
- $error = ! empty( $license->error ) ? $license->error : __( 'unknown_error', 'ultimate-member' );
2788
- $messages[] = sprintf( __( 'There was an error with this license key: %s. Please <a href="%s">contact our support team</a>.', 'ultimate-member' ), $error, 'https://ultimatemember.com/support' );
2789
-
2790
- $license_status = 'license-' . $class . '-notice';
2791
- break;
2792
- }
2793
- } else {
2794
- $class = 'error';
2795
- $error = ! empty( $license->error ) ? $license->error : __( 'unknown_error', 'ultimate-member' );
2796
- $messages[] = sprintf( __( 'There was an error with this license key: %s. Please <a href="%s">contact our support team</a>.', 'ultimate-member' ), $error, 'https://ultimatemember.com/support' );
2797
-
2798
- $license_status = 'license-' . $class . '-notice';
2799
- }
2800
-
2801
- } elseif ( ! empty( $license->errors ) ) {
2802
-
2803
- $errors = array_keys( $license->errors );
2804
- $errors_data = array_values( $license->errors );
2805
-
2806
- $class = 'error';
2807
- $error = ! empty( $errors[0] ) ? $errors[0] : __( 'unknown_error', 'ultimate-member' );
2808
- $errors_data = ! empty( $errors_data[0][0] ) ? ', ' . $errors_data[0][0] : '';
2809
- $messages[] = sprintf( __( 'There was an error with this license key: %s%s. Please <a href="%s">contact our support team</a>.', 'ultimate-member' ), $error, $errors_data, 'https://ultimatemember.com/support' );
2810
-
2811
- $license_status = 'license-' . $class . '-notice';
2812
-
2813
- } else {
2814
-
2815
- switch( $license->license ) {
2816
-
2817
- case 'expired' :
2818
-
2819
- $class = 'expired';
2820
- $messages[] = sprintf(
2821
- __( 'Your license key expired on %s. Please <a href="%s" target="_blank">renew your license key</a>.', 'ultimate-member' ),
2822
- date_i18n( get_option( 'date_format' ), strtotime( $license->expires, current_time( 'timestamp' ) ) ),
2823
- 'https://ultimatemember.com/checkout/?edd_license_key=' . $value . '&utm_campaign=admin&utm_source=licenses&utm_medium=expired'
2824
- );
2825
-
2826
- $license_status = 'license-' . $class . '-notice';
2827
-
2828
- break;
2829
-
2830
- case 'revoked' :
2831
-
2832
- $class = 'error';
2833
- $messages[] = sprintf(
2834
- __( 'Your license key has been disabled. Please <a href="%s" target="_blank">contact support</a> for more information.', 'ultimate-member' ),
2835
- 'https://ultimatemember.com/support?utm_campaign=admin&utm_source=licenses&utm_medium=revoked'
2836
- );
2837
-
2838
- $license_status = 'license-' . $class . '-notice';
2839
-
2840
- break;
2841
-
2842
- case 'missing' :
2843
-
2844
- $class = 'error';
2845
- $messages[] = sprintf(
2846
- __( 'Invalid license. Please <a href="%s" target="_blank">visit your account page</a> and verify it.', 'ultimate-member' ),
2847
- 'https://ultimatemember.com/account?utm_campaign=admin&utm_source=licenses&utm_medium=missing'
2848
- );
2849
-
2850
- $license_status = 'license-' . $class . '-notice';
2851
-
2852
- break;
2853
-
2854
- case 'invalid' :
2855
- case 'site_inactive' :
2856
-
2857
- $class = 'error';
2858
- $messages[] = sprintf(
2859
- __( 'Your %s is not active for this URL. Please <a href="%s" target="_blank">visit your account page</a> to manage your license key URLs.', 'ultimate-member' ),
2860
- $field_data['item_name'],
2861
- 'https://ultimatemember.com/account?utm_campaign=admin&utm_source=licenses&utm_medium=invalid'
2862
- );
2863
-
2864
- $license_status = 'license-' . $class . '-notice';
2865
-
2866
- break;
2867
-
2868
- case 'item_name_mismatch' :
2869
-
2870
- $class = 'error';
2871
- $messages[] = sprintf( __( 'This appears to be an invalid license key for %s.', 'ultimate-member' ), $field_data['item_name'] );
2872
-
2873
- $license_status = 'license-' . $class . '-notice';
2874
-
2875
- break;
2876
-
2877
- case 'no_activations_left':
2878
-
2879
- $class = 'error';
2880
- $messages[] = sprintf( __( 'Your license key has reached its activation limit. <a href="%s">View possible upgrades</a> now.', 'ultimate-member' ), 'https://ultimatemember.com/account' );
2881
-
2882
- $license_status = 'license-' . $class . '-notice';
2883
-
2884
- break;
2885
-
2886
- case 'license_not_activable':
2887
-
2888
- $class = 'error';
2889
- $messages[] = __( 'The key you entered belongs to a bundle, please use the product specific license key.', 'ultimate-member' );
2890
-
2891
- $license_status = 'license-' . $class . '-notice';
2892
- break;
2893
-
2894
- case 'valid' :
2895
- default:
2896
-
2897
- $class = 'valid';
2898
-
2899
- $now = current_time( 'timestamp' );
2900
- $expiration = strtotime( $license->expires, $now );
2901
-
2902
- if( 'lifetime' === $license->expires ) {
2903
-
2904
- $messages[] = __( 'License key never expires.', 'ultimate-member' );
2905
-
2906
- $license_status = 'license-lifetime-notice';
2907
-
2908
- } elseif( $expiration > $now && $expiration - $now < ( DAY_IN_SECONDS * 30 ) ) {
2909
-
2910
- $messages[] = sprintf(
2911
- __( 'Your license key expires soon! It expires on %s. <a href="%s" target="_blank">Renew your license key</a>.', 'ultimate-member' ),
2912
- date_i18n( get_option( 'date_format' ), strtotime( $license->expires, current_time( 'timestamp' ) ) ),
2913
- 'https://ultimatemember.com/checkout/?edd_license_key=' . $value . '&utm_campaign=admin&utm_source=licenses&utm_medium=renew'
2914
- );
2915
-
2916
- $license_status = 'license-expires-soon-notice';
2917
-
2918
- } else {
2919
-
2920
- $messages[] = sprintf(
2921
- __( 'Your license key expires on %s.', 'ultimate-member' ),
2922
- date_i18n( get_option( 'date_format' ), strtotime( $license->expires, current_time( 'timestamp' ) ) )
2923
- );
2924
-
2925
- $license_status = 'license-expiration-date-notice';
2926
-
2927
- }
2928
-
2929
- break;
2930
-
2931
- }
2932
-
2933
- }
2934
-
2935
- } else {
2936
- $class = 'empty';
2937
-
2938
- $messages[] = sprintf(
2939
- __( 'To receive updates, please enter your valid %s license key.', 'ultimate-member' ),
2940
- $field_data['item_name']
2941
- );
2942
-
2943
- $license_status = null;
2944
-
2945
- } ?>
2946
-
2947
- <tr class="um-settings-line">
2948
- <th><label for="um_options_<?php echo esc_attr( $field_data['id'] ) ?>"><?php echo esc_html( $field_data['label'] ) ?></label></th>
2949
- <td>
2950
- <form method="post" action="" name="um-settings-form" class="um-settings-form">
2951
- <input type="hidden" value="save" name="um-settings-action" />
2952
- <input type="hidden" name="licenses_settings" value="1" />
2953
- <?php $um_settings_nonce = wp_create_nonce( 'um-settings-nonce' ); ?>
2954
- <input type="hidden" name="__umnonce" value="<?php echo esc_attr( $um_settings_nonce ); ?>" />
2955
- <input type="text" id="um_options_<?php echo esc_attr( $field_data['id'] ) ?>" name="um_options[<?php echo esc_attr( $field_data['id'] ) ?>]" value="<?php echo $value ?>" class="um-option-field um-long-field" data-field_id="<?php echo esc_attr( $field_data['id'] ) ?>" />
2956
- <?php if ( ! empty( $field_data['description'] ) ) { ?>
2957
- <div class="description"><?php echo $field_data['description'] ?></div>
2958
- <?php } ?>
2959
-
2960
- <?php if ( ! empty( $value ) && ( ( is_object( $license ) && 'valid' == $license->license ) || 'valid' == $license ) ) { ?>
2961
- <input type="button" class="button um_license_deactivate" id="<?php echo esc_attr( $field_data['id'] ) ?>_deactivate" value="<?php esc_attr_e( 'Clear License', 'ultimate-member' ) ?>"/>
2962
- <?php } elseif ( empty( $value ) ) { ?>
2963
- <input type="submit" name="submit" id="submit" class="button button-primary" value="<?php esc_attr_e( 'Activate', 'ultimate-member' ) ?>" />
2964
- <?php } else { ?>
2965
- <input type="submit" name="submit" id="submit" class="button button-primary" value="<?php esc_attr_e( 'Re-Activate', 'ultimate-member' ) ?>" />
2966
- <input type="button" class="button um_license_deactivate" id="<?php echo esc_attr( $field_data['id'] ) ?>_deactivate" value="<?php esc_attr_e( 'Clear License', 'ultimate-member' ) ?>"/>
2967
- <?php }
2968
-
2969
- if ( ! empty( $messages ) ) {
2970
- foreach ( $messages as $message ) { ?>
2971
- <div class="edd-license-data edd-license-<?php echo esc_attr( $class . ' ' . $license_status ) ?>">
2972
- <p><?php echo $message ?></p>
2973
- </div>
2974
- <?php }
2975
- } ?>
2976
- </form>
2977
- </td>
2978
- </tr>
2979
- <?php } ?>
2980
- </tbody>
2981
- </table>
2982
- </div>
2983
- <?php $section = ob_get_clean();
2984
-
2985
- return $section;
2986
- }
2987
-
2988
-
2989
- /**
2990
- * @param $html
2991
- * @param $section_fields
2992
- */
2993
- function settings_install_info_tab( $html, $section_fields ) {
2994
- global $wpdb;
2995
-
2996
- if ( ! class_exists( '\Browser' ) )
2997
- require_once um_path . 'includes/lib/browser.php';
2998
-
2999
- // Detect browser
3000
- $browser = new \Browser();
3001
-
3002
- // Get theme info
3003
- $theme_data = wp_get_theme();
3004
- $theme = $theme_data->Name . ' ' . $theme_data->Version;
3005
-
3006
- // Identify Hosting Provider
3007
- $host = um_get_host();
3008
-
3009
- um_fetch_user( get_current_user_id() );
3010
-
3011
- if ( isset( $this->content ) ) {
3012
- echo $this->content;
3013
- } else { ?>
3014
-
3015
- <h3>Install Info</h3>
3016
-
3017
- <form action="" method="post" dir="ltr">
3018
- <textarea style="width:70%; height:400px;" readonly="readonly" onclick="this.focus();this.select()" id="install-info-textarea" name="um-install-info" title="<?php _e( 'To copy the Install info, click below then press Ctrl + C (PC) or Cmd + C (Mac).', 'ultimate-member' ); ?>">
3019
- ### Begin Install Info ###
3020
-
3021
- ## Please include this information when posting support requests ##
3022
-
3023
- <?php
3024
- /**
3025
- * UM hook
3026
- *
3027
- * @type action
3028
- * @title um_install_info_before
3029
- * @description Before install info settings
3030
- * @change_log
3031
- * ["Since: 2.0"]
3032
- * @usage add_action( 'um_install_info_before', 'function_name', 10 );
3033
- * @example
3034
- * <?php
3035
- * add_action( 'um_install_info_before', 'my_install_info_before', 10 );
3036
- * function my_install_info_before() {
3037
- * // your code here
3038
- * }
3039
- * ?>
3040
- */
3041
- do_action( 'um_install_info_before' ); ?>
3042
-
3043
- --- Site Info ---
3044
-
3045
- Site URL: <?php echo site_url() . "\n"; ?>
3046
- Home URL: <?php echo home_url() . "\n"; ?>
3047
- Multisite: <?php echo is_multisite() ? 'Yes' . "\n" : 'No' . "\n" ?>
3048
-
3049
- --- Hosting Provider ---
3050
-
3051
- <?php if( $host ) : ?>
3052
- Host: <?php echo $host . "\n"; ?>
3053
- <?php endif; ?>
3054
-
3055
- --- User Browser ---
3056
-
3057
- <?php echo $browser ; ?>
3058
-
3059
- ---- Current User Details --
3060
-
3061
- <?php $user = wp_get_current_user(); ?>
3062
- Role: <?php echo implode( ', ', um_user( 'roles' ) ). "\n"; ?>
3063
-
3064
-
3065
- --- WordPress Configurations ---
3066
-
3067
- Version: <?php echo get_bloginfo( 'version' ) . "\n"; ?>
3068
- Language: <?php echo get_locale()."\n"; ?>
3069
- Permalink Structure: <?php echo get_option( 'permalink_structure' ) . "\n"; ?>
3070
- Active Theme: <?php echo $theme . "\n"; ?>
3071
- <?php $show_on_front = get_option( 'show_on_front' ); ?>
3072
- <?php if( $show_on_front == "posts" ): ?>
3073
- Show On Front: <?php echo get_option( 'show_on_front' ) . "/static\n" ?>
3074
- <?php elseif( $show_on_front == "page" ): ?>
3075
- Page On Front: <?php $id = get_option( 'page_on_front' ); echo get_the_title( $id ) . ' (#' . $id . ')' . "\n" ?>
3076
- Page For Posts: <?php $id = get_option( 'page_for_posts' ); echo get_the_title( $id ) . ' (#' . $id . ')' . "\n" ?>
3077
- <?php endif; ?>
3078
- ABSPATH: <?php echo ABSPATH."\n"; ?>
3079
- <?php $wp_count_posts = wp_count_posts(); ?>
3080
- All Posts/Pages: <?php echo array_sum((array)$wp_count_posts)."\n";?>
3081
- <?php
3082
- $request['cmd'] = '_notify-validate';
3083
-
3084
- $params = array(
3085
- 'sslverify' => false,
3086
- 'timeout' => 60,
3087
- 'user-agent' => 'UltimateMember/' . ultimatemember_version,
3088
- 'body' => $request
3089
- );
3090
-
3091
- $response = wp_remote_post( 'https://www.paypal.com/cgi-bin/webscr', $params );
3092
-
3093
- if ( ! is_wp_error( $response ) && $response['response']['code'] >= 200 && $response['response']['code'] < 300 ) {
3094
- $WP_REMOTE_POST = 'wp_remote_post() works' . "\n";
3095
- } else {
3096
- $WP_REMOTE_POST = 'wp_remote_post() does not work' . "\n";
3097
- }
3098
- ?>
3099
- WP Remote Post: <?php echo $WP_REMOTE_POST; ?>
3100
- WP_DEBUG: <?php echo defined( 'WP_DEBUG' ) ? WP_DEBUG ? 'Enabled' . "\n" : 'Disabled' . "\n" : 'Not set' . "\n" ?>
3101
- WP Table Prefix: <?php echo "Length: ". strlen( $wpdb->prefix ); echo ", Status:"; if ( strlen( $wpdb->prefix )>16 ) {echo " ERROR: Too Long";} else {echo " Acceptable";} echo "\n"; ?>
3102
- Memory Limit: <?php echo ( um_let_to_num( WP_MEMORY_LIMIT )/( 1024 ) )."MB"; ?><?php echo "\n"; ?>
3103
-
3104
-
3105
- --- UM Configurations ---
3106
-
3107
- Version: <?php echo ultimatemember_version . "\n"; ?>
3108
- Upgraded From: <?php echo get_option( 'um_last_version_upgrade', 'None' ) . "\n"; ?>
3109
- Current URL Method: <?php echo UM()->options()->get( 'current_url_method' ). "\n"; ?>
3110
- Cache User Profile: <?php if( UM()->options()->get( 'um_profile_object_cache_stop' ) == 1 ){ echo "No"; }else{ echo "Yes"; } echo "\n"; ?>
3111
- Generate Slugs on Directories: <?php if( UM()->options()->get( 'um_generate_slug_in_directory' ) == 1 ){ echo "No"; }else{ echo "Yes"; } echo "\n"; ?>
3112
- Force UTF-8 Encoding: <?php if( UM()->options()->get( 'um_force_utf8_strings' ) == 1 ){ echo "Yes"; }else{ echo "No"; } echo "\n"; ?>
3113
- JS/CSS Compression: <?php if ( defined('SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) { echo "Yes"; }else{ echo "No"; } echo "\n"; ?>
3114
- <?php if( is_multisite() ): ?>
3115
- Network Structure: <?php echo UM()->options()->get( 'network_permalink_structure' ). "\n"; ?>
3116
- <?php endif; ?>
3117
- Port Forwarding in URL: <?php if( UM()->options()->get( 'um_port_forwarding_url' ) == 1 ){ echo "Yes"; }else{ echo "No"; } echo "\n"; ?>
3118
- Exclude CSS/JS on Home: <?php if( UM()->options()->get( 'js_css_exlcude_home' ) == 1 ){ echo "Yes"; }else{ echo "No"; } echo "\n"; ?>
3119
-
3120
-
3121
- --- UM Pages Configuration ---
3122
-
3123
- <?php
3124
- /**
3125
- * UM hook
3126
- *
3127
- * @type action
3128
- * @title um_install_info_before_page_config
3129
- * @description Before page config install info
3130
- * @change_log
3131
- * ["Since: 2.0"]
3132
- * @usage add_action( 'um_install_info_before_page_config', 'function_name', 10 );
3133
- * @example
3134
- * <?php
3135
- * add_action( 'um_install_info_before_page_config', 'my_install_info_before_page_config', 10 );
3136
- * function my_install_info_before_page_config() {
3137
- * // your code here
3138
- * }
3139
- * ?>
3140
- */
3141
- do_action( "um_install_info_before_page_config" ); ?>
3142
- User: <?php echo get_permalink( UM()->options()->get('core_user') ) . "\n"; ?>
3143
- Account: <?php echo get_permalink( UM()->options()->get('core_account') ) . "\n"; ?>
3144
- Members: <?php echo get_permalink( UM()->options()->get('core_members') ) . "\n"; ?>
3145
- Register: <?php echo get_permalink( UM()->options()->get('core_register') ) . "\n"; ?>
3146
- Login: <?php echo get_permalink( UM()->options()->get('core_login') ) . "\n"; ?>
3147
- Logout: <?php echo get_permalink( UM()->options()->get('core_logout') ) . "\n"; ?>
3148
- Password Reset: <?php echo get_permalink( UM()->options()->get('core_password-reset') ) . "\n"; ?>
3149
- <?php
3150
- /**
3151
- * UM hook
3152
- *
3153
- * @type action
3154
- * @title um_install_info_after_page_config
3155
- * @description After page config install info
3156
- * @change_log
3157
- * ["Since: 2.0"]
3158
- * @usage add_action( 'um_install_info_after_page_config', 'function_name', 10 );
3159
- * @example
3160
- * <?php
3161
- * add_action( 'um_install_info_after_page_config', 'my_install_info_after_page_config', 10 );
3162
- * function my_install_info_after_page_config() {
3163
- * // your code here
3164
- * }
3165
- * ?>
3166
- */
3167
- do_action( "um_install_info_after_page_config" ); ?>
3168
-
3169
-
3170
- --- UM Users Configuration ---
3171
-
3172
- Default New User Role: <?php echo UM()->options()->get('register_role') . "\n"; ?>
3173
- Profile Permalink Base: <?php echo UM()->options()->get('permalink_base') . "\n"; ?>
3174
- User Display Name: <?php echo UM()->options()->get('display_name') . "\n"; ?>
3175
- Force Name to Uppercase: <?php echo $this->info_value( UM()->options()->get('force_display_name_capitlized'), 'yesno', true ); ?>
3176
- Redirect author to profile: <?php echo $this->info_value( UM()->options()->get('author_redirect'), 'yesno', true ); ?>
3177
- Enable Members Directory: <?php echo $this->info_value( UM()->options()->get('members_page'), 'yesno', true ); ?>
3178
- Use Gravatars: <?php echo $this->info_value( UM()->options()->get('use_gravatars'), 'yesno', true ); ?>
3179
- <?php if( UM()->options()->get('use_gravatars') ): ?>Gravatar builtin image: <?php echo UM()->options()->get('use_um_gravatar_default_builtin_image') . "\n"; ?>
3180
- UM Avatar as blank Gravatar: <?php echo $this->info_value( UM()->options()->get('use_um_gravatar_default_image'), 'yesno', true ); ?><?php endif; ?>
3181
- Require a strong password: <?php echo $this->info_value( UM()->options()->get('require_strongpass'), 'onoff', true ); ?>
3182
-
3183
-
3184
- --- UM Access Configuration ---
3185
-
3186
- Panic Key: <?php echo UM()->options()->get('panic_key') . "\n"; ?>
3187
- Global Site Access: <?php $arr = array('Site accessible to Everyone','','Site accessible to Logged In Users'); echo $arr[ (int) UM()->options()->get('accessible') ] . "\n"; ?>
3188
- <?php if( UM()->options()->get('accessible') == 2 ) { ?>
3189
- Custom Redirect URL: <?php echo UM()->options()->get('access_redirect')."\n";?>
3190
- Exclude the following URLs:<?php echo "\t\t\t\t".implode("\t\n\t\t\t\t\t\t\t\t\t\t",UM()->options()->get('access_exclude_uris') )."\n";?>
3191
- <?php } ?>
3192
- Backend Login Screen for Guests: <?php echo $this->info_value( UM()->options()->get('wpadmin_login'), 'yesno', true ); ?>
3193
- <?php if( ! UM()->options()->get('wpadmin_login') ) { ?>
3194
- Redirect to alternative login page: <?php if( UM()->options()->get('wpadmin_login_redirect') == 'um_login_page' ){ echo um_get_core_page('login')."\n"; }else{ echo UM()->options()->get('wpadmin_login_redirect_url')."\n"; }?>
3195
- <?php } ?>
3196
- Backend Register Screen for Guests: <?php echo $this->info_value( UM()->options()->get('wpadmin_register'), 'yesno', true ); ?>
3197
- <?php if( ! UM()->options()->get('wpadmin_register') ) { ?>
3198
- Redirect to alternative register page: <?php if( UM()->options()->get('wpadmin_register_redirect') == 'um_register_page' ){ echo um_get_core_page('register')."\n"; }else{ echo UM()->options()->get('wpadmin_register_redirect_url')."\n"; }?>
3199
- <?php } ?>
3200
- Access Control widget for Admins only: <?php echo $this->info_value( UM()->options()->get('access_widget_admin_only'), 'yesno', true ); ?>
3201
- Enable the Reset Password Limit: <?php echo $this->info_value( UM()->options()->get('enable_reset_password_limit'), 'yesno', true ); ?>
3202
- <?php if( UM()->options()->get('enable_reset_password_limit') ) { ?>
3203
- Reset Password Limit: <?php echo UM()->options()->get('reset_password_limit_number') ?>
3204
- Disable Reset Password Limit for Admins: <?php echo $this->info_value( UM()->options()->get('disable_admin_reset_password_limit'), 'yesno', true ) ?>
3205
- <?php } ?>
3206
- <?php $blocked_ips = UM()->options()->get('blocked_ips'); if( ! empty( $blocked_ips ) ){ ?>
3207
- Blocked IP Addresses: <?php echo count( explode("\n",UM()->options()->get('blocked_ips') ) )."\n"; ?>
3208
- <?php } ?>
3209
- <?php $blocked_emails = UM()->options()->get('blocked_emails'); if( ! empty( $blocked_emails ) ){ ?>
3210
- Blocked Email Addresses: <?php echo count( explode("\n",UM()->options()->get('blocked_emails') ) )."\n"; ?>
3211
- <?php } ?>
3212
- <?php $blocked_words = UM()->options()->get('blocked_words'); if( ! empty( $blocked_words ) ){ ?>
3213
- Blacklist Words: <?php echo count( explode("\n",UM()->options()->get('blocked_words') ) )."\n"; ?>
3214
- <?php } ?>
3215
-
3216
-
3217
- --- UM Email Configurations ---
3218
-
3219
- Mail appears from: <?php $mail_from = UM()->options()->get('mail_from'); if( ! empty( $mail_from ) ){echo UM()->options()->get('mail_from');}else{echo "-";}; echo "\n";?>
3220
- Mail appears from address: <?php $mail_from_addr = UM()->options()->get('mail_from_addr'); if( ! empty( $mail_from_addr ) ){echo UM()->options()->get('mail_from_addr');}else{echo "-";}; echo "\n";?>
3221
- Use HTML for E-mails: <?php echo $this->info_value( UM()->options()->get('email_html'), 'yesno', true ); ?>
3222
- Account Welcome Email: <?php echo $this->info_value( UM()->options()->get('welcome_email_on'), 'yesno', true ); ?>
3223
- Account Activation Email: <?php echo $this->info_value( UM()->options()->get('checkmail_email_on'), 'yesno', true ); ?>
3224
- Pending Review Email: <?php echo $this->info_value( UM()->options()->get('pending_email_on'), 'yesno', true ); ?>
3225
- Account Approved Email: <?php echo $this->info_value( UM()->options()->get('approved_email_on'), 'yesno', true ); ?>
3226
- Account Rejected Email: <?php echo $this->info_value( UM()->options()->get('rejected_email_on'), 'yesno', true ); ?>
3227
- Account Deactivated Email: <?php echo $this->info_value( UM()->options()->get('inactive_email_on'), 'yesno', true ); ?>
3228
- Account Deleted Email: <?php echo $this->info_value( UM()->options()->get('deletion_email_on'), 'yesno', true ); ?>
3229
- Password Reset Email: <?php echo $this->info_value( UM()->options()->get('resetpw_email_on'), 'yesno', true ); ?>
3230
- Password Changed Email: <?php echo $this->info_value( UM()->options()->get('changedpw_email_on'), 'yesno', true ); ?>
3231
-
3232
-
3233
- --- UM Total Users ---
3234
-
3235
- <?php $result = count_users();
3236
- echo 'All Users('.$result['total_users'].")\n";
3237
- foreach( $result['avail_roles'] as $role => $count ) {
3238
- echo $role."(".$count.")\n";
3239
- } ?>
3240
-
3241
-
3242
- --- UM Roles ---
3243
-
3244
- <?php foreach( UM()->roles()->get_roles() as $role_id => $role ) {
3245
- echo $role." ({$role_id})\n";
3246
- } ?>
3247
-
3248
-
3249
- --- UM Custom Templates ---
3250
-
3251
- <?php // Show templates that have been copied to the theme's edd_templates dir
3252
- $dir = get_stylesheet_directory() . '/ultimate-member/templates/*.php';
3253
- if ( ! empty( $dir ) ) {
3254
- $found = glob( $dir );
3255
- if ( ! empty( $found ) ) {
3256
- foreach ( glob( $dir ) as $file ) {
3257
- echo "File: " . $file . "\n";
3258
- }
3259
- } else {
3260
- echo 'N/A'."\n";
3261
- }
3262
- } ?>
3263
-
3264
-
3265
- --- UM Email HTML Templates ---
3266
-
3267
- <?php $dir = get_stylesheet_directory() . '/ultimate-member/templates/emails/*.html';
3268
-
3269
- if ( ! empty( $dir ) ) {
3270
- $found = glob( $dir );
3271
- if ( ! empty( $found ) ){
3272
- foreach ( glob( $dir ) as $file ) {
3273
- echo "File: ". $file . "\n";
3274
- }
3275
- } else {
3276
- echo 'N/A'."\n";
3277
- }
3278
- } ?>
3279
-
3280
-
3281
- --- Web Server Configurations ---
3282
-
3283
- PHP Version: <?php echo PHP_VERSION . "\n"; ?>
3284
- MySQL Version: <?php echo $wpdb->db_version() . "\n"; ?>
3285
- Web Server Info: <?php echo $_SERVER['SERVER_SOFTWARE'] . "\n"; ?>
3286
-
3287
-
3288
- --- PHP Configurations ---
3289
-
3290
- PHP Memory Limit: <?php echo ini_get( 'memory_limit' ) . "\n"; ?>
3291
- PHP Upload Max Size: <?php echo ini_get( 'upload_max_filesize' ) . "\n"; ?>
3292
- PHP Post Max Size: <?php echo ini_get( 'post_max_size' ) . "\n"; ?>
3293
- PHP Upload Max Filesize: <?php echo ini_get( 'upload_max_filesize' ) . "\n"; ?>
3294
- PHP Time Limit: <?php echo ini_get( 'max_execution_time' ) . "\n"; ?>
3295
- PHP Max Input Vars: <?php echo ini_get( 'max_input_vars' ) . "\n"; ?>
3296
- PHP Arg Separator: <?php echo ini_get( 'arg_separator.output' ) . "\n"; ?>
3297
- PHP Allow URL File Open: <?php echo ini_get( 'allow_url_fopen' ) ? "Yes\n" : "No\n"; ?>
3298
-
3299
-
3300
- --- Web Server Extensions/Modules ---
3301
-
3302
- DISPLAY ERRORS: <?php echo ( ini_get( 'display_errors' ) ) ? 'On (' . ini_get( 'display_errors' ) . ')' : 'N/A'; ?><?php echo "\n"; ?>
3303
- FSOCKOPEN: <?php echo ( function_exists( 'fsockopen' ) ) ? 'Your server supports fsockopen.' : 'Your server does not support fsockopen.'; ?><?php echo "\n"; ?>
3304
- cURL: <?php echo ( function_exists( 'curl_init' ) ) ? 'Your server supports cURL.' : 'Your server does not support cURL.'; ?><?php echo "\n"; ?>
3305
- SOAP Client: <?php echo ( class_exists( 'SoapClient' ) ) ? 'Your server has the SOAP Client enabled.' : 'Your server does not have the SOAP Client enabled.'; ?><?php echo "\n"; ?>
3306
- SUHOSIN: <?php echo ( extension_loaded( 'suhosin' ) ) ? 'Your server has SUHOSIN installed.' : 'Your server does not have SUHOSIN installed.'; ?><?php echo "\n"; ?>
3307
- GD Library: <?php echo ( extension_loaded( 'gd' ) && function_exists('gd_info') ) ? 'PHP GD library is installed on your web server.' : 'PHP GD library is NOT installed on your web server.'; ?><?php echo "\n"; ?>
3308
- Mail: <?php echo ( function_exists('mail') ) ? 'PHP mail function exist on your web server.' : 'PHP mail function doesn\'t exist on your web server.'; ?><?php echo "\n"; ?>
3309
- Exif: <?php echo ( extension_loaded( 'exif' ) && function_exists('exif_imagetype') ) ? 'PHP Exif library is installed on your web server.' : 'PHP Exif library is NOT installed on your web server.'; ?><?php echo "\n"; ?>
3310
-
3311
-
3312
- --- Session Configurations ---
3313
-
3314
- Session: <?php echo isset( $_SESSION ) ? 'Enabled' : 'Disabled'; ?><?php echo "\n"; ?>
3315
- Session Name: <?php echo esc_html( ini_get( 'session.name' ) ); ?><?php echo "\n"; ?>
3316
- Cookie Path: <?php echo esc_html( ini_get( 'session.cookie_path' ) ); ?><?php echo "\n"; ?>
3317
- Save Path: <?php echo esc_html( ini_get( 'session.save_path' ) ); ?><?php echo "\n"; ?>
3318
- Use Cookies: <?php echo ini_get( 'session.use_cookies' ) ? 'On' : 'Off'; ?><?php echo "\n"; ?>
3319
- Use Only Cookies: <?php echo ini_get( 'session.use_only_cookies' ) ? 'On' : 'Off'; ?><?php echo "\n"; ?>
3320
-
3321
-
3322
- --- WordPress Active Plugins ---
3323
-
3324
- <?php $plugins = get_plugins();
3325
- $active_plugins = get_option( 'active_plugins', array() );
3326
-
3327
- foreach ( $plugins as $plugin_path => $plugin ) {
3328
- // If the plugin isn't active, don't show it.
3329
- if ( ! in_array( $plugin_path, $active_plugins ) )
3330
- continue;
3331
-
3332
- echo $plugin['Name'] . ': ' . $plugin['Version'] ."\n";
3333
- }
3334
-
3335
- if ( is_multisite() ) { ?>
3336
-
3337
- --- WordPress Network Active Plugins ---
3338
-
3339
- <?php $plugins = wp_get_active_network_plugins();
3340
- $active_plugins = get_site_option( 'active_sitewide_plugins', array() );
3341
-
3342
- foreach ( $plugins as $plugin_path ) {
3343
- $plugin_base = plugin_basename( $plugin_path );
3344
-
3345
- // If the plugin isn't active, don't show it.
3346
- if ( ! array_key_exists( $plugin_base, $active_plugins ) )
3347
- continue;
3348
-
3349
- $plugin = get_plugin_data( $plugin_path );
3350
-
3351
- echo $plugin['Name'] . ' :' . $plugin['Version'] . "\n";
3352
- }
3353
-
3354
- }
3355
-
3356
- /**
3357
- * UM hook
3358
- *
3359
- * @type action
3360
- * @title um_install_info_after
3361
- * @description After install info
3362
- * @change_log
3363
- * ["Since: 2.0"]
3364
- * @usage add_action( 'um_install_info_after', 'function_name', 10 );
3365
- * @example
3366
- * <?php
3367
- * add_action( 'um_install_info_after', 'my_install_info_after', 10 );
3368
- * function my_install_info_after() {
3369
- * // your code here
3370
- * }
3371
- * ?>
3372
- */
3373
- do_action( 'um_install_info_after' ); ?>
3374
-
3375
- ### End Install Info ###
3376
- </textarea>
3377
- <p class="submit">
3378
- <input type="hidden" name="um-addon-hook" value="download_install_info" />
3379
- <?php submit_button( 'Download Install Info File', 'primary', 'download_install_info', false ); ?>
3380
- </p>
3381
- </form>
3382
-
3383
- <?php }
3384
- }
3385
-
3386
-
3387
- /**
3388
- *
3389
- */
3390
- function um_download_install_info() {
3391
- if ( ! empty( $_POST['download_install_info'] ) ) {
3392
- nocache_headers();
3393
-
3394
- header( "Content-type: text/plain" );
3395
- header( 'Content-Disposition: attachment; filename="ultimatemember-install-info.txt"' );
3396
-
3397
- echo wp_strip_all_tags( sanitize_textarea_field( $_POST['um-install-info'] ) );
3398
- exit;
3399
- }
3400
- }
3401
-
3402
-
3403
- /**
3404
- * @param string $raw_value
3405
- * @param string $type
3406
- * @param string $default
3407
- *
3408
- * @return string
3409
- */
3410
- function info_value( $raw_value = '', $type = 'yesno', $default = '' ) {
3411
-
3412
- if ( $type == 'yesno' ) {
3413
- $raw_value = ( $default == $raw_value ) ? "Yes" : "No";
3414
- } elseif( $type == 'onoff' ) {
3415
- $raw_value = ( $default == $raw_value ) ? "On" : "Off";
3416
- }
3417
-
3418
- return $raw_value."\n";
3419
- }
3420
-
3421
-
3422
- /**
3423
- * Render settings section
3424
- *
3425
- * @param array $section_fields
3426
- * @param string $current_tab
3427
- * @param string $current_subtab
3428
- *
3429
- * @return string
3430
- */
3431
- function render_settings_section( $section_fields, $current_tab, $current_subtab ) {
3432
- ob_start();
3433
-
3434
- UM()->admin_forms_settings( array(
3435
- 'class' => 'um_options-' . $current_tab . '-' . $current_subtab . ' um-third-column',
3436
- 'prefix_id' => 'um_options',
3437
- 'fields' => $section_fields
3438
- ) )->render_form(); ?>
3439
-
3440
- <?php $section = ob_get_clean();
3441
-
3442
- return $section;
3443
- }
3444
-
3445
-
3446
- /**
3447
- * @param array $settings
3448
- *
3449
- * @return array
3450
- */
3451
- function save_email_templates( $settings ) {
3452
-
3453
- if ( empty( $settings['um_email_template'] ) ) {
3454
- return $settings;
3455
- }
3456
-
3457
- $template = $settings['um_email_template'];
3458
- $content = wp_kses_post( stripslashes( $settings[ $template ] ) );
3459
-
3460
- $theme_template_path = UM()->mail()->get_template_file( 'theme', $template );
3461
-
3462
- if ( ! file_exists( $theme_template_path ) ) {
3463
- UM()->mail()->copy_email_template( $template );
3464
- }
3465
-
3466
- $fp = fopen( $theme_template_path, "w" );
3467
- $result = fputs( $fp, $content );
3468
- fclose( $fp );
3469
-
3470
- if ( $result !== false ) {
3471
- unset( $settings['um_email_template'] );
3472
- unset( $settings[ $template ] );
3473
- }
3474
-
3475
- return $settings;
3476
- }
3477
- }
3478
- }
1
+ <?php
2
+ namespace um\admin\core;
3
+
4
+ if ( ! defined( 'ABSPATH' ) ) {
5
+ exit;
6
+ }
7
+
8
+ if ( ! class_exists( 'um\admin\core\Admin_Settings' ) ) {
9
+
10
+
11
+ /**
12
+ * Class Admin_Settings
13
+ * @package um\admin\core
14
+ */
15
+ class Admin_Settings {
16
+
17
+
18
+ /**
19
+ * @var array
20
+ */
21
+ public $settings_map;
22
+
23
+
24
+ /**
25
+ * @var array
26
+ */
27
+ public $settings_structure;
28
+
29
+
30
+ /**
31
+ * @var
32
+ */
33
+ private $previous_licenses;
34
+
35
+
36
+ /**
37
+ * @var
38
+ */
39
+ private $need_change_permalinks;
40
+
41
+
42
+ private $gravatar_changed = false;
43
+
44
+
45
+ /**
46
+ * Admin_Settings constructor.
47
+ */
48
+ public function __construct() {
49
+ //init settings structure
50
+ add_action( 'admin_init', array( &$this, 'init_variables' ), 9 );
51
+
52
+ //admin menu
53
+ add_action( 'admin_menu', array( &$this, 'primary_admin_menu' ), 0 );
54
+
55
+ //settings structure handlers
56
+ add_action( 'um_settings_page_before_email__content', array( $this, 'settings_before_email_tab' ) );
57
+ add_filter( 'um_settings_section_email__content', array( $this, 'settings_email_tab' ), 10, 1 );
58
+
59
+ //enqueue wp_media for profiles tab
60
+ add_action( 'um_settings_page_appearance__before_section', array( $this, 'settings_appearance_profile_tab' ) );
61
+
62
+ //custom content for licenses tab
63
+ add_filter( 'um_settings_section_licenses__content', array( $this, 'settings_licenses_tab' ), 10, 2 );
64
+
65
+ add_filter( 'um_settings_section_install_info__content', array( $this, 'settings_install_info_tab' ), 10, 2 );
66
+
67
+
68
+ add_filter( 'um_settings_structure', array( $this, 'sorting_licenses_options' ), 9999, 1 );
69
+
70
+
71
+ //save handlers
72
+ add_action( 'admin_init', array( $this, 'save_settings_handler' ), 10 );
73
+
74
+ //save pages options
75
+ add_action( 'um_settings_before_save', array( $this, 'check_permalinks_changes' ) );
76
+ add_action( 'um_settings_save', array( $this, 'on_settings_save' ) );
77
+
78
+
79
+ add_filter( 'um_change_settings_before_save', array( $this, 'save_email_templates' ) );
80
+
81
+
82
+ //save licenses options
83
+ add_action( 'um_settings_before_save', array( $this, 'before_licenses_save' ) );
84
+ add_action( 'um_settings_save', array( $this, 'licenses_save' ) );
85
+
86
+ add_filter( 'um_change_settings_before_save', array( $this, 'set_default_if_empty' ), 9, 1 );
87
+ add_filter( 'um_change_settings_before_save', array( $this, 'remove_empty_values' ), 10, 1 );
88
+
89
+ add_action( 'admin_init', array( &$this, 'um_download_install_info' ) );
90
+ }
91
+
92
+
93
+
94
+ public function same_page_update_ajax() {
95
+ UM()->admin()->check_ajax_nonce();
96
+
97
+ if ( empty( $_POST['cb_func'] ) ) {
98
+ wp_send_json_error( __( 'Wrong callback', 'ultimate-member' ) );
99
+ }
100
+
101
+ $cb_func = sanitize_key( $_POST['cb_func'] );
102
+
103
+ if ( 'um_usermeta_fields' === $cb_func ) {
104
+ //first install metatable
105
+ global $wpdb;
106
+
107
+ $metakeys = array();
108
+ foreach ( UM()->builtin()->all_user_fields as $all_user_field ) {
109
+ $metakeys[] = $all_user_field['metakey'];
110
+ }
111
+
112
+ $metakeys = apply_filters( 'um_metadata_same_page_update_ajax', $metakeys, UM()->builtin()->all_user_fields );
113
+
114
+ if ( is_multisite() ) {
115
+
116
+ $sites = get_sites( array( 'fields' => 'ids' ) );
117
+ foreach ( $sites as $blog_id ) {
118
+ $metakeys[] = $wpdb->get_blog_prefix( $blog_id ) . 'capabilities';
119
+ }
120
+ } else {
121
+ $blog_id = get_current_blog_id();
122
+ $metakeys[] = $wpdb->get_blog_prefix( $blog_id ) . 'capabilities';
123
+ }
124
+
125
+ //member directory data
126
+ $metakeys[] = 'um_member_directory_data';
127
+ $metakeys[] = '_um_verified';
128
+ $metakeys[] = '_money_spent';
129
+ $metakeys[] = '_completed';
130
+ $metakeys[] = '_reviews_avg';
131
+
132
+ //myCred meta
133
+ if ( function_exists( 'mycred_get_types' ) ) {
134
+ $mycred_types = mycred_get_types();
135
+ if ( ! empty( $mycred_types ) ) {
136
+ foreach ( array_keys( $mycred_types ) as $point_type ) {
137
+ $metakeys[] = $point_type;
138
+ }
139
+ }
140
+ }
141
+
142
+ $sortby_custom_keys = $wpdb->get_col( "SELECT DISTINCT meta_value FROM {$wpdb->postmeta} WHERE meta_key='_um_sortby_custom'" );
143
+ if ( empty( $sortby_custom_keys ) ) {
144
+ $sortby_custom_keys = array();
145
+ }
146
+
147
+ $sortby_custom_keys2 = $wpdb->get_col( "SELECT meta_value FROM {$wpdb->postmeta} WHERE meta_key='_um_sorting_fields'" );
148
+ if ( ! empty( $sortby_custom_keys2 ) ) {
149
+ foreach ( $sortby_custom_keys2 as $custom_val ) {
150
+ $custom_val = maybe_unserialize( $custom_val );
151
+
152
+ foreach ( $custom_val as $sort_value ) {
153
+ if ( is_array( $sort_value ) ) {
154
+ $field_keys = array_keys( $sort_value );
155
+ $sortby_custom_keys[] = $field_keys[0];
156
+ }
157
+ }
158
+ }
159
+ }
160
+
161
+ if ( ! empty( $sortby_custom_keys ) ) {
162
+ $sortby_custom_keys = array_unique( $sortby_custom_keys );
163
+ $metakeys = array_merge( $metakeys, $sortby_custom_keys );
164
+ }
165
+
166
+ $skip_fields = UM()->builtin()->get_fields_without_metakey();
167
+ $skip_fields = array_merge( $skip_fields, UM()->member_directory()->core_search_fields );
168
+
169
+ $real_usermeta = $wpdb->get_col( "SELECT DISTINCT meta_key FROM {$wpdb->usermeta}" );
170
+ $real_usermeta = ! empty( $real_usermeta ) ? $real_usermeta : array();
171
+ $real_usermeta = array_merge( $real_usermeta, array( 'um_member_directory_data' ) );
172
+
173
+ if ( ! empty( $sortby_custom_keys ) ) {
174
+ $real_usermeta = array_merge( $real_usermeta, $sortby_custom_keys );
175
+ }
176
+
177
+ $wp_usermeta_option = array_intersect( array_diff( $metakeys, $skip_fields ), $real_usermeta );
178
+
179
+ update_option( 'um_usermeta_fields', array_values( $wp_usermeta_option ) );
180
+
181
+ update_option( 'um_member_directory_update_meta', time() );
182
+
183
+ UM()->options()->update( 'member_directory_own_table', true );
184
+
185
+ wp_send_json_success();
186
+ } elseif ( 'um_get_metadata' === $cb_func ) {
187
+ global $wpdb;
188
+
189
+ $wp_usermeta_option = get_option( 'um_usermeta_fields', array() );
190
+
191
+ $count = $wpdb->get_var(
192
+ "SELECT COUNT(*)
193
+ FROM {$wpdb->usermeta}
194
+ WHERE meta_key IN ('" . implode( "','", $wp_usermeta_option ) . "')"
195
+ );
196
+
197
+ wp_send_json_success( array( 'count' => $count ) );
198
+ } elseif ( 'um_update_metadata_per_page' === $cb_func ) {
199
+
200
+ if ( empty( $_POST['page'] ) ) {
201
+ wp_send_json_error( __( 'Wrong data', 'ultimate-member' ) );
202
+ }
203
+
204
+ $per_page = 500;
205
+ $wp_usermeta_option = get_option( 'um_usermeta_fields', array() );
206
+
207
+ global $wpdb;
208
+ $metadata = $wpdb->get_results(
209
+ $wpdb->prepare(
210
+ "SELECT *
211
+ FROM {$wpdb->usermeta}
212
+ WHERE meta_key IN ('" . implode( "','", $wp_usermeta_option ) . "')
213
+ LIMIT %d, %d",
214
+ ( absint( $_POST['page'] ) - 1 ) * $per_page,
215
+ $per_page
216
+ ),
217
+ ARRAY_A
218
+ );
219
+
220
+ $values = array();
221
+ foreach ( $metadata as $metarow ) {
222
+ $values[] = $wpdb->prepare( '(%d, %s, %s)', $metarow['user_id'], $metarow['meta_key'], $metarow['meta_value'] );
223
+ }
224
+
225
+ if ( ! empty( $values ) ) {
226
+ $wpdb->query(
227
+ "INSERT INTO
228
+ {$wpdb->prefix}um_metadata(user_id, um_key, um_value)
229
+ VALUES " . implode( ',', $values )
230
+ );
231
+ }
232
+
233
+ $from = ( absint( $_POST['page'] ) * $per_page ) - $per_page + 1;
234
+ $to = absint( $_POST['page'] ) * $per_page;
235
+
236
+ wp_send_json_success( array( 'message' => sprintf( __( 'Metadata from %1$s to %2$s was upgraded successfully...', 'ultimate-member' ), $from, $to ) ) );
237
+ } else {
238
+ do_action( 'um_same_page_update_ajax_action', $cb_func );
239
+ }
240
+ }
241
+
242
+
243
+ /**
244
+ *
245
+ */
246
+ public function init_variables() {
247
+
248
+ $settings_map = array();
249
+
250
+ $general_pages_fields = array(
251
+ array(
252
+ 'id' => 'pages_settings',
253
+ 'type' => 'hidden',
254
+ 'value' => true,
255
+ 'is_option' => false,
256
+ ),
257
+ );
258
+
259
+ $core_pages = UM()->config()->core_pages;
260
+
261
+ foreach ( $core_pages as $page_s => $page ) {
262
+ $have_pages = UM()->query()->wp_pages();
263
+ $page_id = UM()->options()->get_core_page_id( $page_s );
264
+
265
+ $page_title = ! empty( $page['title'] ) ? $page['title'] : '';
266
+
267
+ if ( 'reached_maximum_limit' === $have_pages ) {
268
+ $general_pages_fields[] = array(
269
+ 'id' => $page_id,
270
+ 'type' => 'text',
271
+ // translators: %s: Page title
272
+ 'label' => sprintf( __( '%s page', 'ultimate-member' ), $page_title ),
273
+ 'placeholder' => __( 'Add page ID', 'ultimate-member' ),
274
+ 'compiler' => true,
275
+ 'size' => 'small',
276
+ );
277
+ } else {
278
+ $general_pages_fields[] = array(
279
+ 'id' => $page_id,
280
+ 'type' => 'select',
281
+ // translators: %s: Page title
282
+ 'label' => sprintf( __( '%s page', 'ultimate-member' ), $page_title ),
283
+ 'options' => UM()->query()->wp_pages(),
284
+ 'placeholder' => __( 'Choose a page...', 'ultimate-member' ),
285
+ 'compiler' => true,
286
+ 'size' => 'small',
287
+ );
288
+ }
289
+
290
+
291
+ $settings_map[ $page_id ] = array(
292
+ 'sanitize' => 'absint',
293
+ );
294
+ }
295
+
296
+ $appearances_profile_menu_fields = array(
297
+ array(
298
+ 'id' => 'profile_menu',
299
+ 'type' => 'checkbox',
300
+ 'label' => __( 'Enable profile menu', 'ultimate-member' ),
301
+ ),
302
+ );
303
+
304
+ $settings_map['profile_menu'] = array(
305
+ 'sanitize' => 'bool',
306
+ );
307
+
308
+ $tabs = UM()->profile()->tabs();
309
+
310
+ $tabs_options = array();
311
+ $tabs_condition = array();
312
+ foreach ( $tabs as $id => $tab ) {
313
+
314
+ if ( ! empty( $tab['hidden'] ) ) {
315
+ continue;
316
+ }
317
+
318
+ if ( isset( $tab['name'] ) ) {
319
+ $tabs_options[ $id ] = $tab['name'];
320
+ $tabs_condition[] = 'profile_tab_' . $id;
321
+ }
322
+
323
+ if ( isset( $tab['default_privacy'] ) ) {
324
+ $fields = array(
325
+ array(
326
+ 'id' => 'profile_tab_' . $id,
327
+ 'type' => 'checkbox',
328
+ // translators: %s: Tab title
329
+ 'label' => sprintf( __( '%s Tab', 'ultimate-member' ), $tab['name'] ),
330
+ 'conditional' => array( 'profile_menu', '=', 1 ),
331
+ 'data' => array( 'fill_profile_menu_default_tab' => $id ),
332
+ ),
333
+ );
334
+
335
+ $settings_map[ 'profile_tab_' . $id ] = array(
336
+ 'sanitize' => 'bool',
337
+ );
338
+ } else {
339
+
340
+ $fields = array(
341
+ array(
342
+ 'id' => 'profile_tab_' . $id,
343
+ 'type' => 'checkbox',
344
+ // translators: %s: Tab title
345
+ 'label' => sprintf( __( '%s Tab', 'ultimate-member' ), $tab['name'] ),
346
+ 'conditional' => array( 'profile_menu', '=', 1 ),
347
+ 'data' => array( 'fill_profile_menu_default_tab' => $id ),
348
+ ),
349
+ array(
350
+ 'id' => 'profile_tab_' . $id . '_privacy',
351
+ 'type' => 'select',
352
+ // translators: %s: Tab title
353
+ 'label' => sprintf( __( 'Who can see %s Tab?', 'ultimate-member' ), $tab['name'] ),
354
+ 'tooltip' => __( 'Select which users can view this tab.', 'ultimate-member' ),
355
+ 'options' => UM()->profile()->tabs_privacy(),
356
+ 'conditional' => array( 'profile_tab_' . $id, '=', 1 ),
357
+ 'size' => 'small',
358
+ ),
359
+ array(
360
+ 'id' => 'profile_tab_' . $id . '_roles',
361
+ 'type' => 'select',
362
+ 'multi' => true,
363
+ 'label' => __( 'Allowed roles', 'ultimate-member' ),
364
+ 'tooltip' => __( 'Select the the user roles allowed to view this tab.', 'ultimate-member' ),
365
+ 'options' => UM()->roles()->get_roles(),
366
+ 'placeholder' => __( 'Choose user roles...', 'ultimate-member' ),
367
+ 'conditional' => array( 'profile_tab_' . $id . '_privacy', '=', array( '4', '5' ) ),
368
+ 'size' => 'small',
369
+ ),
370
+ );
371
+
372
+ $settings_map = array_merge(
373
+ $settings_map,
374
+ array(
375
+ "profile_tab_{$id}" => array(
376
+ 'sanitize' => 'bool',
377
+ ),
378
+ "profile_tab_{$id}_privacy" => array(
379
+ 'sanitize' => array( UM()->admin(), 'sanitize_tabs_privacy' ),
380
+ ),
381
+ "profile_tab_{$id}_roles" => array(
382
+ 'sanitize' => array( UM()->admin(), 'sanitize_existed_role' ),
383
+ ),
384
+ )
385
+ );
386
+ }
387
+
388
+ $appearances_profile_menu_fields = array_merge( $appearances_profile_menu_fields, $fields );
389
+ }
390
+
391
+ $appearances_profile_menu_fields[] = array(
392
+ 'id' => 'profile_menu_default_tab',
393
+ 'type' => 'select',
394
+ 'label' => __( 'Profile menu default tab', 'ultimate-member' ),
395
+ 'tooltip' => __( 'This will be the default tab on user profile page', 'ultimate-member' ),
396
+ 'options' => $tabs_options,
397
+ 'conditional' => array( implode( '|', $tabs_condition ), '~', 1 ),
398
+ 'size' => 'small',
399
+ );
400
+
401
+ $settings_map['profile_menu_default_tab'] = array(
402
+ 'sanitize' => 'key',
403
+ );
404
+
405
+ $appearances_profile_menu_fields = array_merge(
406
+ $appearances_profile_menu_fields,
407
+ array(
408
+ array(
409
+ 'id' => 'profile_menu_icons',
410
+ 'type' => 'checkbox',
411
+ 'label' => __( 'Enable menu icons in desktop view', 'ultimate-member' ),
412
+ 'conditional' => array( 'profile_menu', '=', 1 ),
413
+ ),
414
+ )
415
+ );
416
+
417
+ $settings_map['profile_menu_icons'] = array(
418
+ 'sanitize' => 'bool',
419
+ );
420
+
421
+ $post_types_options = array();
422
+ $all_post_types = get_post_types( array( 'public' => true ), 'objects' );
423
+ foreach ( $all_post_types as $key => $post_type_data ) {
424
+ $post_types_options[ $key ] = $post_type_data->labels->singular_name;
425
+ }
426
+
427
+ $duplicates = array();
428
+ $taxonomies_options = array();
429
+ $exclude_taxonomies = UM()->excluded_taxonomies();
430
+ $all_taxonomies = get_taxonomies( array( 'public' => true ), 'objects' );
431
+ foreach ( $all_taxonomies as $key => $taxonomy ) {
432
+ if ( in_array( $key, $exclude_taxonomies, true ) ) {
433
+ continue;
434
+ }
435
+
436
+ if ( ! in_array( $taxonomy->labels->singular_name, $duplicates, true ) ) {
437
+ $duplicates[] = $taxonomy->labels->singular_name;
438
+ $label = $taxonomy->labels->singular_name;
439
+ } else {
440
+ $label = $taxonomy->labels->singular_name . ' (' . $key . ')';
441
+ }
442
+
443
+ $taxonomies_options[ $key ] = $label;
444
+ }
445
+
446
+ $restricted_access_post_metabox_value = array();
447
+ $restricted_access_post_metabox = UM()->options()->get( 'restricted_access_post_metabox' );
448
+ if ( ! empty( $restricted_access_post_metabox ) && is_array( $restricted_access_post_metabox ) ) {
449
+ foreach ( $restricted_access_post_metabox as $key => $value ) {
450
+ if ( $value ) {
451
+ $restricted_access_post_metabox_value[] = $key;
452
+ }
453
+ }
454
+ }
455
+
456
+
457
+ $restricted_access_taxonomy_metabox_value = array();
458
+ $restricted_access_taxonomy_metabox = UM()->options()->get( 'restricted_access_taxonomy_metabox' );
459
+ if ( ! empty( $restricted_access_taxonomy_metabox ) && is_array( $restricted_access_taxonomy_metabox ) ) {
460
+ foreach ( $restricted_access_taxonomy_metabox as $key => $value ) {
461
+ if ( $value ) {
462
+ $restricted_access_taxonomy_metabox_value[] = $key;
463
+ }
464
+ }
465
+ }
466
+
467
+ $access_fields = array(
468
+ array(
469
+ 'id' => 'accessible',
470
+ 'type' => 'select',
471
+ 'label' => __( 'Global Site Access', 'ultimate-member' ),
472
+ 'tooltip' => __( 'Globally control the access of your site, you can have separate restrict options per post/page by editing the desired item.', 'ultimate-member' ),
473
+ 'options' => array(
474
+ 0 => __( 'Site accessible to Everyone', 'ultimate-member' ),
475
+ 2 => __( 'Site accessible to Logged In Users', 'ultimate-member' ),
476
+ ),
477
+ 'size' => 'medium',
478
+ ),
479
+ array(
480
+ 'id' => 'access_redirect',
481
+ 'type' => 'text',
482
+ 'label' => __( 'Custom Redirect URL', 'ultimate-member' ),
483
+ 'tooltip' => __( 'A logged out user will be redirected to this url If he is not permitted to access the site', 'ultimate-member' ),
484
+ 'conditional' => array( 'accessible', '=', 2 ),
485
+ ),
486
+ array(
487
+ 'id' => 'access_exclude_uris',
488
+ 'type' => 'multi_text',
489
+ 'label' => __( 'Exclude the following URLs', 'ultimate-member' ),
490
+ 'tooltip' => __( 'Here you can exclude URLs beside the redirect URI to be accessible to everyone', 'ultimate-member' ),
491
+ 'add_text' => __( 'Add New URL', 'ultimate-member' ),
492
+ 'conditional' => array( 'accessible', '=', 2 ),
493
+ 'show_default_number' => 0,
494
+ ),
495
+ array(
496
+ 'id' => 'home_page_accessible',
497
+ 'type' => 'checkbox',
498
+ 'label' => __( 'Allow Homepage to be accessible', 'ultimate-member' ),
499
+ 'conditional' => array( 'accessible', '=', 2 ),
500
+ ),
501
+ array(
502
+ 'id' => 'category_page_accessible',
503
+ 'type' => 'checkbox',
504
+ 'label' => __( 'Allow Category pages to be accessible', 'ultimate-member' ),
505
+ 'conditional' => array( 'accessible', '=', 2 ),
506
+ ),
507
+ array(
508
+ 'id' => 'restricted_post_title_replace',
509
+ 'type' => 'checkbox',
510
+ 'label' => __( 'Replace the restricted Post Title', 'ultimate-member' ),
511
+ 'tooltip' => __( 'Allow to replace the restricted post title to users that do not have permission to view the content', 'ultimate-member' ),
512
+ ),
513
+ array(
514
+ 'id' => 'restricted_access_post_title',
515
+ 'type' => 'text',
516
+ 'label' => __( 'Restricted Access Post Title', 'ultimate-member' ),
517
+ 'tooltip' => __( 'This is the post title shown to users that do not have permission to view the content', 'ultimate-member' ),
518
+ 'conditional' => array( 'restricted_post_title_replace', '=', 1 ),
519
+ ),
520
+ array(
521
+ 'id' => 'restricted_access_message',
522
+ 'type' => 'wp_editor',
523
+ 'label' => __( 'Restricted Access Message', 'ultimate-member' ),
524
+ 'tooltip' => __( 'This is the message shown to users that do not have permission to view the content', 'ultimate-member' ),
525
+ ),
526
+ );
527
+
528
+ $settings_map = array_merge(
529
+ $settings_map,
530
+ array(
531
+ 'accessible' => array(
532
+ 'sanitize' => 'int',
533
+ ),
534
+ 'access_redirect' => array(
535
+ 'sanitize' => 'url',
536
+ ),
537
+ 'access_exclude_uris' => array(
538
+ 'sanitize' => 'url',
539
+ ),
540
+ 'home_page_accessible' => array(
541
+ 'sanitize' => 'bool',
542
+ ),
543
+ 'category_page_accessible' => array(
544
+ 'sanitize' => 'bool',
545
+ ),
546
+ 'restricted_post_title_replace' => array(
547
+ 'sanitize' => 'bool',
548
+ ),
549
+ 'restricted_access_post_title' => array(
550
+ 'sanitize' => 'text',
551
+ ),
552
+ 'restricted_access_message' => array(
553
+ 'sanitize' => 'wp_kses',
554
+ ),
555
+ )
556
+ );
557
+
558
+ global $wp_version;
559
+ if ( version_compare( $wp_version, '5.0', '>=' ) ) {
560
+ $access_fields = array_merge(
561
+ $access_fields,
562
+ array(
563
+ array(
564
+ 'id' => 'restricted_blocks',
565
+ 'type' => 'checkbox',
566
+ 'label' => __( 'Enable the "Content Restriction" settings for the Gutenberg Blocks', 'ultimate-member' ),
567
+ ),
568
+ array(
569
+ 'id' => 'restricted_block_message',
570
+ 'type' => 'textarea',
571
+ 'label' => __( 'Restricted Access Block Message', 'ultimate-member' ),
572
+ 'tooltip' => __( 'This is the message shown to users that do not have permission to view the block\'s content', 'ultimate-member' ),
573
+ 'conditional' => array( 'restricted_blocks', '=', 1 ),
574
+ ),
575
+ )
576
+ );
577
+
578
+ $settings_map['restricted_blocks'] = array(
579
+ 'sanitize' => 'bool',
580
+ );
581
+ $settings_map['restricted_block_message'] = array(
582
+ 'sanitize' => 'textarea',
583
+ );
584
+ }
585
+
586
+ $access_fields = array_merge(
587
+ $access_fields,
588
+ array(
589
+ array(
590
+ 'id' => 'restricted_access_post_metabox',
591
+ 'type' => 'hidden',
592
+ 'value' => '',
593
+ ),
594
+ array(
595
+ 'id' => 'restricted_access_taxonomy_metabox',
596
+ 'type' => 'hidden',
597
+ 'value' => '',
598
+ ),
599
+ array(
600
+ 'id' => 'restricted_access_post_metabox',
601
+ 'type' => 'multi_checkbox',
602
+ 'label' => __( 'Enable the "Content Restriction" settings for post types', 'ultimate-member' ),
603
+ 'tooltip' => __( 'Check post types for which you plan to use the "Content Restriction" settings', 'ultimate-member' ),
604
+ 'options' => $post_types_options,
605
+ 'columns' => 3,
606
+ 'value' => $restricted_access_post_metabox_value,
607
+ 'default' => UM()->options()->get_default( 'restricted_access_post_metabox' ),
608
+ ),
609
+ array(
610
+ 'id' => 'restricted_access_taxonomy_metabox',
611
+ 'type' => 'multi_checkbox',
612
+ 'label' => __( 'Enable the "Content Restriction" settings for taxonomies', 'ultimate-member' ),
613
+ 'tooltip' => __( 'Check taxonomies for which you plan to use the "Content Restriction" settings', 'ultimate-member' ),
614
+ 'options' => $taxonomies_options,
615
+ 'columns' => 3,
616
+ 'value' => $restricted_access_taxonomy_metabox_value,
617
+ 'default' => UM()->options()->get_default( 'restricted_access_taxonomy_metabox' ),
618
+ ),
619
+ )
620
+ );
621
+
622
+ $settings_map = array_merge(
623
+ $settings_map,
624
+ array(
625
+ 'restricted_access_post_metabox' => array(
626
+ 'sanitize' => 'key',
627
+ ),
628
+ 'restricted_access_taxonomy_metabox' => array(
629
+ 'sanitize' => 'key',
630
+ ),
631
+ )
632
+ );
633
+
634
+ $latest_update = get_option( 'um_member_directory_update_meta', false );
635
+ $latest_truncate = get_option( 'um_member_directory_truncated', false );
636
+
637
+ $same_page_update = array(
638
+ 'id' => 'member_directory_own_table',
639
+ 'type' => 'same_page_update',
640
+ 'label' => __( 'Enable custom table for usermeta', 'ultimate-member' ),
641
+ 'tooltip' => __( 'Check this box if you would like to enable the use of a custom table for user metadata. Improved performance for member directory searches.', 'ultimate-member' ),
642
+ );
643
+
644
+ if ( empty( $latest_update ) || ( ! empty( $latest_truncate ) && $latest_truncate > $latest_update ) ) {
645
+ $same_page_update['upgrade_cb'] = 'sync_metatable';
646
+ $same_page_update['upgrade_description'] = '<p>' . __( 'We recommend creating a backup of your site before running the update process. Do not exit the page before the update process has complete.', 'ultimate-member' ) . '</p>
647
+ <p>' . __( 'After clicking the <strong>"Run"</strong> button, the update process will start. All information will be displayed in the field below.', 'ultimate-member' ) . '</p>
648
+ <p>' . __( 'If the update was successful, you will see a corresponding message. Otherwise, contact technical support if the update failed.', 'ultimate-member' ) . '</p>';
649
+ }
650
+
651
+ $settings_map = array_merge(
652
+ $settings_map,
653
+ array(
654
+ 'permalink_base' => array(
655
+ 'sanitize' => 'key',
656
+ ),
657
+ 'display_name' => array(
658
+ 'sanitize' => 'key',
659
+ ),
660
+ 'display_name_field' => array(
661
+ 'sanitize' => 'text',
662
+ ),
663
+ 'author_redirect' => array(
664
+ 'sanitize' => 'bool',
665
+ ),
666
+ 'members_page' => array(
667
+ 'sanitize' => 'bool',
668
+ ),
669
+ 'use_gravatars' => array(
670
+ 'sanitize' => 'bool',
671
+ ),
672
+ 'use_um_gravatar_default_builtin_image' => array(
673
+ 'sanitize' => 'key',
674
+ ),
675
+ 'use_um_gravatar_default_image' => array(
676
+ 'sanitize' => 'bool',
677
+ ),
678
+ 'require_strongpass' => array(
679
+ 'sanitize' => 'bool',
680
+ ),
681
+ 'password_min_chars' => array(
682
+ 'sanitize' => 'absint',
683
+ ),
684
+ 'password_max_chars' => array(
685
+ 'sanitize' => 'absint',
686
+ ),
687
+ 'profile_noindex' => array(
688
+ 'sanitize' => 'bool',
689
+ ),
690
+ 'activation_link_expiry_time' => array(
691
+ 'sanitize' => 'absint',
692
+ ),
693
+ 'account_tab_password' => array(
694
+ 'sanitize' => 'bool',
695
+ ),
696
+ 'account_tab_privacy' => array(
697
+ 'sanitize' => 'bool',
698
+ ),
699
+ 'account_tab_notifications' => array(
700
+ 'sanitize' => 'bool',
701
+ ),
702
+ 'account_tab_delete' => array(
703
+ 'sanitize' => 'bool',
704
+ ),
705
+ 'delete_account_text' => array(
706
+ 'sanitize' => 'textarea',
707
+ ),
708
+ 'delete_account_no_pass_required_text' => array(
709
+ 'sanitize' => 'textarea',
710
+ ),
711
+ 'account_name' => array(
712
+ 'sanitize' => 'bool',
713
+ ),
714
+ 'account_name_disable' => array(
715
+ 'sanitize' => 'bool',
716
+ ),
717
+ 'account_name_require' => array(
718
+ 'sanitize' => 'bool',
719
+ ),
720
+ 'account_email' => array(
721
+ 'sanitize' => 'bool',
722
+ ),
723
+ 'account_general_password' => array(
724
+ 'sanitize' => 'bool',
725
+ ),
726
+ 'account_hide_in_directory' => array(
727
+ 'sanitize' => 'bool',
728
+ ),
729
+ 'account_hide_in_directory_default' => array(
730
+ 'sanitize' => 'text',
731
+ ),
732
+ 'profile_photo_max_size' => array(
733
+ 'sanitize' => 'absint',
734
+ ),
735
+ 'cover_photo_max_size' => array(
736
+ 'sanitize' => 'absint',
737
+ ),
738
+ 'photo_thumb_sizes' => array(
739
+ 'sanitize' => 'absint',
740
+ ),
741
+ 'cover_thumb_sizes' => array(
742
+ 'sanitize' => 'absint',
743
+ ),
744
+ 'image_orientation_by_exif' => array(
745
+ 'sanitize' => 'bool',
746
+ ),
747
+ 'image_compression' => array(
748
+ 'sanitize' => 'absint',
749
+ ),
750
+ 'image_max_width' => array(
751
+ 'sanitize' => 'absint',
752
+ ),
753
+ 'cover_min_width' => array(
754
+ 'sanitize' => 'absint',
755
+ ),
756
+ 'enable_reset_password_limit' => array(
757
+ 'sanitize' => 'bool',
758
+ ),
759
+ 'reset_password_limit_number' => array(
760
+ 'sanitize' => 'absint',
761
+ ),
762
+ 'blocked_emails' => array(
763
+ 'sanitize' => 'textarea',
764
+ ),
765
+ 'blocked_words' => array(
766
+ 'sanitize' => 'textarea',
767
+ ),
768
+ 'allowed_choice_callbacks' => array(
769
+ 'sanitize' => 'textarea',
770
+ ),
771
+ 'allow_url_redirect_confirm' => array(
772
+ 'sanitize' => 'bool',
773
+ ),
774
+ 'admin_email' => array(
775
+ 'sanitize' => 'text',
776
+ ),
777
+ 'mail_from' => array(
778
+ 'sanitize' => 'text',
779
+ ),
780
+ 'mail_from_addr' => array(
781
+ 'sanitize' => 'text',
782
+ ),
783
+ 'email_html' => array(
784
+ 'sanitize' => 'bool',
785
+ ),
786
+ 'profile_template' => array(
787
+ 'sanitize' => 'text',
788
+ ),
789
+ 'profile_max_width' => array(
790
+ 'sanitize' => 'text',
791
+ ),
792
+ 'profile_area_max_width' => array(
793
+ 'sanitize' => 'text',
794
+ ),
795
+ 'profile_icons' => array(
796
+ 'sanitize' => 'key',
797
+ ),
798
+ 'profile_primary_btn_word' => array(
799
+ 'sanitize' => 'text',
800
+ ),
801
+ 'profile_secondary_btn' => array(
802
+ 'sanitize' => 'bool',
803
+ ),
804
+ 'profile_secondary_btn_word' => array(
805
+ 'sanitize' => 'text',
806
+ ),
807
+ 'default_avatar' => array(
808
+ 'sanitize' => 'url',
809
+ ),
810
+ 'default_cover' => array(
811
+ 'sanitize' => 'url',
812
+ ),
813
+ 'disable_profile_photo_upload' => array(
814
+ 'sanitize' => 'bool',
815
+ ),
816
+ 'profile_photosize' => array(
817
+ 'sanitize' => array( UM()->admin(), 'sanitize_photosize' ),
818
+ ),
819
+ 'profile_cover_enabled' => array(
820
+ 'sanitize' => 'bool',
821
+ ),
822
+ 'profile_coversize' => array(
823
+ 'sanitize' => array( UM()->admin(), 'sanitize_cover_photosize' ),
824
+ ),
825
+ 'profile_cover_ratio' => array(
826
+ 'sanitize' => 'text',
827
+ ),
828
+ 'profile_show_metaicon' => array(
829
+ 'sanitize' => 'bool',
830
+ ),
831
+ 'profile_show_name' => array(
832
+ 'sanitize' => 'bool',
833
+ ),
834
+ 'profile_show_social_links' => array(
835
+ 'sanitize' => 'bool',
836
+ ),
837
+ 'profile_show_bio' => array(
838
+ 'sanitize' => 'bool',
839
+ ),
840
+ 'profile_show_html_bio' => array(
841
+ 'sanitize' => 'bool',
842
+ ),
843
+ 'profile_bio_maxchars' => array(
844
+ 'sanitize' => 'absint',
845
+ ),
846
+ 'profile_header_menu' => array(
847
+ 'sanitize' => 'key',
848
+ ),
849
+ 'profile_empty_text' => array(
850
+ 'sanitize' => 'bool',
851
+ ),
852
+ 'profile_empty_text_emo' => array(
853
+ 'sanitize' => 'bool',
854
+ ),
855
+ 'register_template' => array(
856
+ 'sanitize' => 'text',
857
+ ),
858
+ 'register_max_width' => array(
859
+ 'sanitize' => 'text',
860
+ ),
861
+ 'register_align' => array(
862
+ 'sanitize' => 'key',
863
+ ),
864
+ 'register_icons' => array(
865
+ 'sanitize' => 'key',
866
+ ),
867
+ 'register_primary_btn_word' => array(
868
+ 'sanitize' => 'text',
869
+ ),
870
+ 'register_secondary_btn' => array(
871
+ 'sanitize' => 'bool',
872
+ ),
873
+ 'register_secondary_btn_word' => array(
874
+ 'sanitize' => 'text',
875
+ ),
876
+ 'register_secondary_btn_url' => array(
877
+ 'sanitize' => 'url',
878
+ ),
879
+ 'register_role' => array(
880
+ 'sanitize' => 'key',
881
+ ),
882
+ 'login_template' => array(
883
+ 'sanitize' => 'text',
884
+ ),
885
+ 'login_max_width' => array(
886
+ 'sanitize' => 'text',
887
+ ),
888
+ 'login_align' => array(
889
+ 'sanitize' => 'key',
890
+ ),
891
+ 'login_icons' => array(
892
+ 'sanitize' => 'key',
893
+ ),
894
+ 'login_primary_btn_word' => array(
895
+ 'sanitize' => 'text',
896
+ ),
897
+ 'login_secondary_btn' => array(
898
+ 'sanitize' => 'bool',
899
+ ),
900
+ 'login_secondary_btn_word' => array(
901
+ 'sanitize' => 'text',
902
+ ),
903
+ 'login_secondary_btn_url' => array(
904
+ 'sanitize' => 'url',
905
+ ),
906
+ 'login_forgot_pass_link' => array(
907
+ 'sanitize' => 'bool',
908
+ ),
909
+ 'login_show_rememberme' => array(
910
+ 'sanitize' => 'bool',
911
+ ),
912
+ 'form_asterisk' => array(
913
+ 'sanitize' => 'bool',
914
+ ),
915
+ 'profile_title' => array(
916
+ 'sanitize' => 'text',
917
+ ),
918
+ 'profile_desc' => array(
919
+ 'sanitize' => 'textarea',
920
+ ),
921
+ 'um_profile_object_cache_stop' => array(
922
+ 'sanitize' => 'bool',
923
+ ),
924
+ 'enable_blocks' => array(
925
+ 'sanitize' => 'bool',
926
+ ),
927
+ 'rest_api_version' => array(
928
+ 'sanitize' => 'text',
929
+ ),
930
+ 'uninstall_on_delete' => array(
931
+ 'sanitize' => 'bool',
932
+ ),
933
+ )
934
+ );
935
+
936
+ $this->settings_map = apply_filters( 'um_settings_map', $settings_map );
937
+
938
+ /**
939
+ * UM hook
940
+ *
941
+ * @type filter
942
+ * @title um_settings_structure
943
+ * @description Extend UM Settings
944
+ * @input_vars
945
+ * [{"var":"$settings","type":"array","desc":"UM Settings"}]
946
+ * @change_log
947
+ * ["Since: 2.0"]
948
+ * @usage add_filter( 'um_settings_structure', 'function_name', 10, 1 );
949
+ * @example
950
+ * <?php
951
+ * add_filter( 'um_settings_structure', 'my_settings_structure', 10, 1 );
952
+ * function my_settings_structure( $settings ) {
953
+ * // your code here
954
+ * return $settings;
955
+ * }
956
+ * ?>
957
+ */
958
+ $this->settings_structure = apply_filters(
959
+ 'um_settings_structure',
960
+ array(
961
+ '' => array(
962
+ 'title' => __( 'General', 'ultimate-member' ),
963
+ 'sections' => array(
964
+ '' => array(
965
+ 'title' => __( 'Pages', 'ultimate-member' ),
966
+ 'fields' => $general_pages_fields,
967
+ ),
968
+ 'users' => array(
969
+ 'title' => __( 'Users', 'ultimate-member' ),
970
+ 'fields' => array(
971
+ array(
972
+ 'id' => 'permalink_base',
973
+ 'type' => 'select',
974
+ 'size' => 'small',
975
+ 'label' => __( 'Profile Permalink Base', 'ultimate-member' ),
976
+ // translators: %s: Profile page URL
977
+ 'tooltip' => sprintf( __( 'Here you can control the permalink structure of the user profile URL globally e.g. %s<strong>username</strong>/', 'ultimate-member' ), trailingslashit( um_get_core_page( 'user' ) ) ),
978
+ 'options' => array(
979
+ 'user_login' => __( 'Username', 'ultimate-member' ),
980
+ 'name' => __( 'First and Last Name with \'.\'', 'ultimate-member' ),
981
+ 'name_dash' => __( 'First and Last Name with \'-\'', 'ultimate-member' ),
982
+ 'name_plus' => __( 'First and Last Name with \'+\'', 'ultimate-member' ),
983
+ 'user_id' => __( 'User ID', 'ultimate-member' ),
984
+ ),
985
+ 'placeholder' => __( 'Select...', 'ultimate-member' ),
986
+ ),
987
+ array(
988
+ 'id' => 'display_name',
989
+ 'type' => 'select',
990
+ 'size' => 'medium',
991
+ 'label' => __( 'User Display Name', 'ultimate-member' ),
992
+ 'tooltip' => __( 'This is the name that will be displayed for users on the front end of your site. Default setting uses first/last name as display name if it exists', 'ultimate-member' ),
993
+ 'options' => array(
994
+ 'default' => __( 'Default WP Display Name', 'ultimate-member' ),
995
+ 'nickname' => __( 'Nickname', 'ultimate-member' ),
996
+ 'username' => __( 'Username', 'ultimate-member' ),
997
+ 'full_name' => __( 'First name & last name', 'ultimate-member' ),
998
+ 'sur_name' => __( 'Last name & first name', 'ultimate-member' ),
999
+ 'initial_name' => __( 'First name & first initial of last name', 'ultimate-member' ),
1000
+ 'initial_name_f' => __( 'First initial of first name & last name', 'ultimate-member' ),
1001
+ 'first_name' => __( 'First name only', 'ultimate-member' ),
1002
+ 'field' => __( 'Custom field(s)', 'ultimate-member' ),
1003
+ ),
1004
+ 'placeholder' => __( 'Select...', 'ultimate-member' ),
1005
+ ),
1006
+ array(
1007
+ 'id' => 'display_name_field',
1008
+ 'type' => 'text',
1009
+ 'label' => __( 'Display Name Custom Field(s)', 'ultimate-member' ),
1010
+ 'tooltip' => __( 'Specify the custom field meta key or custom fields seperated by comma that you want to use to display users name on the frontend of your site', 'ultimate-member' ),
1011
+ 'conditional' => array( 'display_name', '=', 'field' ),
1012
+ ),
1013
+ array(
1014
+ 'id' => 'author_redirect',
1015
+ 'type' => 'checkbox',
1016
+ 'label' => __( 'Automatically redirect author page to their profile?', 'ultimate-member' ),
1017
+ 'tooltip' => __( 'If enabled, author pages will automatically redirect to the user\'s profile page', 'ultimate-member' ),
1018
+ ),
1019
+ array(
1020
+ 'id' => 'members_page',
1021
+ 'type' => 'checkbox',
1022
+ 'label' => __( 'Enable Members Directory', 'ultimate-member' ),
1023
+ 'tooltip' => __( 'Control whether to enable or disable member directories on this site', 'ultimate-member' ),
1024
+ ),
1025
+ array(
1026
+ 'id' => 'use_gravatars',
1027
+ 'type' => 'checkbox',
1028
+ 'label' => __( 'Use Gravatars?', 'ultimate-member' ),
1029
+ 'tooltip' => __( 'Do you want to use gravatars instead of the default plugin profile photo (If the user did not upload a custom profile photo / avatar)', 'ultimate-member' ),
1030
+ ),
1031
+ array(
1032
+ 'id' => 'use_um_gravatar_default_builtin_image',
1033
+ 'type' => 'select',
1034
+ 'label' => __( 'Use Gravatar builtin image', 'ultimate-member' ),
1035
+ 'tooltip' => __( 'Gravatar has a number of built in options which you can also use as defaults', 'ultimate-member' ),
1036
+ 'options' => array(
1037
+ 'default' => __( 'Default', 'ultimate-member' ),
1038
+ '404' => __( '404 ( File Not Found response )', 'ultimate-member' ),
1039
+ 'mm' => __( 'Mystery Man', 'ultimate-member' ),
1040
+ 'identicon' => __( 'Identicon', 'ultimate-member' ),
1041
+ 'monsterid' => __( 'Monsterid', 'ultimate-member' ),
1042
+ 'wavatar' => __( 'Wavatar', 'ultimate-member' ),
1043
+ 'retro' => __( 'Retro', 'ultimate-member' ),
1044
+ 'blank' => __( 'Blank ( a transparent PNG image )', 'ultimate-member' ),
1045
+ ),
1046
+ 'conditional' => array( 'use_gravatars', '=', 1 ),
1047
+ 'size' => 'medium',
1048
+ ),
1049
+ array(
1050
+ 'id' => 'use_um_gravatar_default_image',
1051
+ 'type' => 'checkbox',
1052
+ 'label' => __( 'Use Default plugin avatar as Gravatar\'s Default avatar', 'ultimate-member' ),
1053
+ 'tooltip' => __( 'Do you want to use the plugin default avatar instead of the gravatar default photo (If the user did not upload a custom profile photo / avatar)', 'ultimate-member' ),
1054
+ 'conditional' => array( 'use_um_gravatar_default_builtin_image', '=', 'default' ),
1055
+ ),
1056
+ array(
1057
+ 'id' => 'require_strongpass',
1058
+ 'type' => 'checkbox',
1059
+ 'label' => __( 'Require a strong password?', 'ultimate-member' ),
1060
+ 'tooltip' => __( 'Enable or disable a strong password rules common for all Ultimate Member forms.', 'ultimate-member' ),
1061
+ ),
1062
+ array(
1063
+ 'id' => 'password_min_chars',
1064
+ 'type' => 'number',
1065
+ 'label' => __( 'Password minimum length', 'ultimate-member' ),
1066
+ 'tooltip' => __( 'If you want to enable a minimum number of characters to be in password. User password field in the UM forms has own settings for that. Leave empty to use default value 8', 'ultimate-member' ),
1067
+ 'size' => 'small',
1068
+ ),
1069
+ array(
1070
+ 'id' => 'password_max_chars',
1071
+ 'type' => 'number',
1072
+ 'label' => __( 'Password maximum length', 'ultimate-member' ),
1073
+ 'tooltip' => __( 'If you want to enable a maximum number of characters to be in password. User password field in the UM forms has own settings for that. Leave empty to use default value 30', 'ultimate-member' ),
1074
+ 'size' => 'small',
1075
+ ),
1076
+ array(
1077
+ 'id' => 'profile_noindex',
1078
+ 'type' => 'select',
1079
+ 'size' => 'small',
1080
+ 'label' => __( 'Avoid indexing profile by search engines', 'ultimate-member' ),
1081
+ 'tooltip' => __( 'Hides the profile page for robots. This setting can be overridden by individual role settings.', 'ultimate-member' ),
1082
+ 'options' => array(
1083
+ '0' => __( 'No', 'ultimate-member' ),
1084
+ '1' => __( 'Yes', 'ultimate-member' ),
1085
+ ),
1086
+ ),
1087
+ array(
1088
+ 'id' => 'activation_link_expiry_time',
1089
+ 'type' => 'number',
1090
+ 'label' => __( 'Activation link lifetime', 'ultimate-member' ),
1091
+ 'tooltip' => __( 'How long does an activation link live in seconds? Leave empty for endless links.', 'ultimate-member' ),
1092
+ 'size' => 'small',
1093
+ ),
1094
+ ),
1095
+ ),
1096
+ 'account' => array(
1097
+ 'title' => __( 'Account', 'ultimate-member' ),
1098
+ 'fields' => array(
1099
+ array(
1100
+ 'id' => 'account_tab_password',
1101
+ 'type' => 'checkbox',
1102
+ 'label' => __( 'Password Account Tab', 'ultimate-member' ),
1103
+ 'tooltip' => __( 'Enable/disable the Password account tab in account page', 'ultimate-member' ),
1104
+ ),
1105
+ array(
1106
+ 'id' => 'account_tab_privacy',
1107
+ 'type' => 'checkbox',
1108
+ 'label' => __( 'Privacy Account Tab', 'ultimate-member' ),
1109
+ 'tooltip' => __( 'Enable/disable the Privacy account tab in account page', 'ultimate-member' ),
1110
+ ),
1111
+ array(
1112
+ 'id' => 'account_tab_notifications',
1113
+ 'type' => 'checkbox',
1114
+ 'label' => __( 'Notifications Account Tab', 'ultimate-member' ),
1115
+ 'tooltip' => __( 'Enable/disable the Notifications account tab in account page', 'ultimate-member' ),
1116
+ ),
1117
+ array(
1118
+ 'id' => 'account_tab_delete',
1119
+ 'type' => 'checkbox',
1120
+ 'label' => __( 'Delete Account Tab', 'ultimate-member' ),
1121
+ 'tooltip' => __( 'Enable/disable the Delete account tab in account page', 'ultimate-member' ),
1122
+ ),
1123
+ array(
1124
+ 'id' => 'delete_account_text',
1125
+ 'type' => 'textarea', // bug with wp 4.4? should be editor
1126
+ 'label' => __( 'Account Deletion Custom Text', 'ultimate-member' ),
1127
+ 'tooltip' => __( 'This is custom text that will be displayed to users before they delete their accounts from your site when password is required.', 'ultimate-member' ),
1128
+ 'args' => array(
1129
+ 'textarea_rows' => 6,
1130
+ ),
1131
+ ),
1132
+ array(
1133
+ 'id' => 'delete_account_no_pass_required_text',
1134
+ 'type' => 'textarea',
1135
+ 'label' => __( 'Account Deletion without password Custom Text', 'ultimate-member' ),
1136
+ 'tooltip' => __( 'This is custom text that will be displayed to users before they delete their accounts from your site when password isn\'t required.', 'ultimate-member' ),
1137
+ 'args' => array(
1138
+ 'textarea_rows' => 6,
1139
+ ),
1140
+ ),
1141
+ array(
1142
+ 'id' => 'account_name',
1143
+ 'type' => 'checkbox',
1144
+ 'label' => __( 'Add a First & Last Name fields', 'ultimate-member' ),
1145
+ 'tooltip' => __( 'Whether to enable these fields on the user account page by default or hide them.', 'ultimate-member' ),
1146
+ ),
1147
+ array(
1148
+ 'id' => 'account_name_disable',
1149
+ 'type' => 'checkbox',
1150
+ 'label' => __( 'Disable First & Last Name fields', 'ultimate-member' ),
1151
+ 'tooltip' => __( 'Whether to allow users changing their first and last name in account page.', 'ultimate-member' ),
1152
+ 'conditional' => array( 'account_name', '=', '1' ),
1153
+ ),
1154
+ array(
1155
+ 'id' => 'account_name_require',
1156
+ 'type' => 'checkbox',
1157
+ 'label' => __( 'Require First & Last Name', 'ultimate-member' ),
1158
+ 'tooltip' => __( 'Require first and last name?', 'ultimate-member' ),
1159
+ 'conditional' => array( 'account_name', '=', '1' ),
1160
+ ),
1161
+ array(
1162
+ 'id' => 'account_email',
1163
+ 'type' => 'checkbox',
1164
+ 'label' => __( 'Allow users to change e-mail', 'ultimate-member' ),
1165
+ 'tooltip' => __( 'Whether to allow users changing their email in account page.', 'ultimate-member' ),
1166
+ ),
1167
+ array(
1168
+ 'id' => 'account_general_password',
1169
+ 'type' => 'checkbox',
1170
+ 'label' => __( 'Password is required?', 'ultimate-member' ),
1171
+ 'tooltip' => __( 'Password is required to save account data.', 'ultimate-member' ),
1172
+ ),
1173
+ array(
1174
+ 'id' => 'account_hide_in_directory',
1175
+ 'type' => 'checkbox',
1176
+ 'label' => __( 'Allow users to hide their profiles from directory', 'ultimate-member' ),
1177
+ 'tooltip' => __( 'Whether to allow users changing their profile visibility from member directory in account page.', 'ultimate-member' ),
1178
+ 'conditional' => array( 'account_tab_privacy', '=', '1' ),
1179
+ ),
1180
+ array(
1181
+ 'id' => 'account_hide_in_directory_default',
1182
+ 'type' => 'select',
1183
+ 'label' => __( 'Hide profiles from directory by default', 'ultimate-member' ),
1184
+ 'tooltip' => __( 'Set default value for the "Hide my profile from directory" option', 'ultimate-member' ),
1185
+ 'options' => array(
1186
+ 'No' => __( 'No', 'ultimate-member' ),
1187
+ 'Yes' => __( 'Yes', 'ultimate-member' ),
1188
+ ),
1189
+ 'size' => 'small',
1190
+ 'conditional' => array( 'account_hide_in_directory', '=', '1' ),
1191
+ ),
1192
+ ),
1193
+ ),
1194
+ 'uploads' => array(
1195
+ 'title' => __( 'Uploads', 'ultimate-member' ),
1196
+ 'fields' => array(
1197
+ array(
1198
+ 'id' => 'profile_photo_max_size',
1199
+ 'type' => 'text',
1200
+ 'size' => 'small',
1201
+ 'label' => __( 'Profile Photo Maximum File Size (bytes)', 'ultimate-member' ),
1202
+ 'tooltip' => __( 'Sets a maximum size for the uploaded photo', 'ultimate-member' ),
1203
+ ),
1204
+ array(
1205
+ 'id' => 'cover_photo_max_size',
1206
+ 'type' => 'text',
1207
+ 'size' => 'small',
1208
+ 'label' => __( 'Cover Photo Maximum File Size (bytes)', 'ultimate-member' ),
1209
+ 'tooltip' => __( 'Sets a maximum size for the uploaded cover', 'ultimate-member' ),
1210
+ ),
1211
+ array(
1212
+ 'id' => 'photo_thumb_sizes',
1213
+ 'type' => 'multi_text',
1214
+ 'size' => 'small',
1215
+ 'label' => __( 'Profile Photo Thumbnail Sizes (px)', 'ultimate-member' ),
1216
+ 'tooltip' => __( 'Here you can define which thumbnail sizes will be created for each profile photo upload.', 'ultimate-member' ),
1217
+ 'validate' => 'numeric',
1218
+ 'add_text' => __( 'Add New Size', 'ultimate-member' ),
1219
+ 'show_default_number' => 1,
1220
+ ),
1221
+ array(
1222
+ 'id' => 'cover_thumb_sizes',
1223
+ 'type' => 'multi_text',
1224
+ 'size' => 'small',
1225
+ 'label' => __( 'Cover Photo Thumbnail Sizes (px)', 'ultimate-member' ),
1226
+ 'tooltip' => __( 'Here you can define which thumbnail sizes will be created for each cover photo upload.', 'ultimate-member' ),
1227
+ 'validate' => 'numeric',
1228
+ 'add_text' => __( 'Add New Size', 'ultimate-member' ),
1229
+ 'show_default_number' => 1,
1230
+ ),
1231
+ array(
1232
+ 'id' => 'image_orientation_by_exif',
1233
+ 'type' => 'checkbox',
1234
+ 'label' => __( 'Change image orientation', 'ultimate-member' ),
1235
+ 'tooltip' => __( 'Rotate image to and use orientation by the camera EXIF data.', 'ultimate-member' ),
1236
+ ),
1237
+ array(
1238
+ 'id' => 'image_compression',
1239
+ 'type' => 'text',
1240
+ 'size' => 'small',
1241
+ 'label' => __( 'Image Quality', 'ultimate-member' ),
1242
+ 'tooltip' => __( 'Quality is used to determine quality of image uploads, and ranges from 0 (worst quality, smaller file) to 100 (best quality, biggest file). The default range is 60.', 'ultimate-member' ),
1243
+ ),
1244
+
1245
+ array(
1246
+ 'id' => 'image_max_width',
1247
+ 'type' => 'text',
1248
+ 'size' => 'small',
1249
+ 'label' => __( 'Image Upload Maximum Width (px)', 'ultimate-member' ),
1250
+ 'tooltip' => __( 'Any image upload above this width will be resized to this limit automatically.', 'ultimate-member' ),
1251
+ ),
1252
+
1253
+ array(
1254
+ 'id' => 'cover_min_width',
1255
+ 'type' => 'text',
1256
+ 'size' => 'small',
1257
+ 'label' => __( 'Cover Photo Minimum Width (px)', 'ultimate-member' ),
1258
+ 'tooltip' => __( 'This will be the minimum width for cover photo uploads', 'ultimate-member' ),
1259
+ ),
1260
+ ),
1261
+ ),
1262
+ ),
1263
+ ),
1264
+ 'access' => array(
1265
+ 'title' => __( 'Access', 'ultimate-member' ),
1266
+ 'sections' => array(
1267
+ '' => array(
1268
+ 'title' => __( 'Restriction Content', 'ultimate-member' ),
1269
+ 'fields' => $access_fields,
1270
+ ),
1271
+ 'other' => array(
1272
+ 'title' => __( 'Other', 'ultimate-member' ),
1273
+ 'fields' => array(
1274
+ array(
1275
+ 'id' => 'enable_reset_password_limit',
1276
+ 'type' => 'checkbox',
1277
+ 'label' => __( 'Enable the Reset Password Limit?', 'ultimate-member' ),
1278
+ ),
1279
+ array(
1280
+ 'id' => 'reset_password_limit_number',
1281
+ 'type' => 'text',
1282
+ 'label' => __( 'Reset Password Limit', 'ultimate-member' ),
1283
+ 'tooltip' => __( 'Set the maximum reset password limit. If reached the maximum limit, user will be locked from using this.', 'ultimate-member' ),
1284
+ 'validate' => 'numeric',
1285
+ 'conditional' => array( 'enable_reset_password_limit', '=', 1 ),
1286
+ 'size' => 'small',
1287
+ ),
1288
+ array(
1289
+ 'id' => 'blocked_emails',
1290
+ 'type' => 'textarea',
1291
+ 'label' => __( 'Blocked Email Addresses (Enter one email per line)', 'ultimate-member' ),
1292
+ 'tooltip' => __( 'This will block the specified e-mail addresses from being able to sign up or sign in to your site. To block an entire domain, use something like *@domain.com', 'ultimate-member' ),
1293
+ ),
1294
+ array(
1295
+ 'id' => 'blocked_words',
1296
+ 'type' => 'textarea',
1297
+ 'label' => __( 'Blacklist Words (Enter one word per line)', 'ultimate-member' ),
1298
+ 'tooltip' => __( 'This option lets you specify blacklist of words to prevent anyone from signing up with such a word as their username', 'ultimate-member' ),
1299
+ ),
1300
+ array(
1301
+ 'id' => 'allowed_choice_callbacks',
1302
+ 'type' => 'textarea',
1303
+ 'label' => __( 'Allowed Choice Callbacks (Enter one PHP function per line)', 'ultimate-member' ),
1304
+ 'tooltip' => __( 'This option lets you specify the choice callback functions to prevent anyone from using 3rd-party functions that may put your site at risk.', 'ultimate-member' ),
1305
+ ),
1306
+ array(
1307
+ 'id' => 'allow_url_redirect_confirm',
1308
+ 'type' => 'checkbox',
1309
+ 'label' => __( 'Allow external link redirect confirm', 'ultimate-member' ),
1310
+ 'tooltip' => __( 'Using JS.confirm alert when you go to an external link.', 'ultimate-member' ),
1311
+ ),
1312
+ ),
1313
+ ),
1314
+ ),
1315
+ ),
1316
+ 'email' => array(
1317
+ 'title' => __( 'Email', 'ultimate-member' ),
1318
+ 'fields' => array(
1319
+ array(
1320
+ 'id' => 'admin_email',
1321
+ 'type' => 'text',
1322
+ 'label' => __( 'Admin E-mail Address', 'ultimate-member' ),
1323
+ 'tooltip' => __( 'e.g. admin@companyname.com', 'ultimate-member' ),
1324
+ ),
1325
+ array(
1326
+ 'id' => 'mail_from',
1327
+ 'type' => 'text',
1328
+ 'label' => __( 'Mail appears from', 'ultimate-member' ),
1329
+ 'tooltip' => __( 'e.g. Site Name', 'ultimate-member' ),
1330
+ ),
1331
+ array(
1332
+ 'id' => 'mail_from_addr',
1333
+ 'type' => 'text',
1334
+ 'label' => __( 'Mail appears from address', 'ultimate-member' ),
1335
+ 'tooltip' => __( 'e.g. admin@companyname.com', 'ultimate-member' ),
1336
+ ),
1337
+ array(
1338
+ 'id' => 'email_html',
1339
+ 'type' => 'checkbox',
1340
+ 'label' => __( 'Use HTML for E-mails?', 'ultimate-member' ),
1341
+ 'tooltip' => __( 'If you plan use e-mails with HTML, please make sure that this option is enabled. Otherwise, HTML will be displayed as plain text.', 'ultimate-member' ),
1342
+ ),
1343
+ ),
1344
+ ),
1345
+ 'appearance' => array(
1346
+ 'title' => __( 'Appearance', 'ultimate-member' ),
1347
+ 'sections' => array(
1348
+ '' => array(
1349
+ 'title' => __( 'Profile', 'ultimate-member' ),
1350
+ 'fields' => array(
1351
+ array(
1352
+ 'id' => 'profile_template',
1353
+ 'type' => 'select',
1354
+ 'label' => __( 'Profile Default Template', 'ultimate-member' ),
1355
+ 'tooltip' => __( 'This will be the default template to output profile', 'ultimate-member' ),
1356
+ 'default' => um_get_metadefault( 'profile_template' ),
1357
+ 'options' => UM()->shortcodes()->get_templates( 'profile' ),
1358
+ 'size' => 'small',
1359
+ ),
1360
+ array(
1361
+ 'id' => 'profile_max_width',
1362
+ 'type' => 'text',
1363
+ 'label' => __( 'Profile Maximum Width', 'ultimate-member' ),
1364
+ 'default' => um_get_metadefault( 'profile_max_width' ),
1365
+ 'tooltip' => __( 'The maximum width this shortcode can take from the page width', 'ultimate-member' ),
1366
+ 'size' => 'small',
1367
+ ),
1368
+ array(
1369
+ 'id' => 'profile_area_max_width',
1370
+ 'type' => 'text',
1371
+ 'label' => __( 'Profile Area Maximum Width', 'ultimate-member' ),
1372
+ 'default' => um_get_metadefault( 'profile_area_max_width' ),
1373
+ 'tooltip' => __( 'The maximum width of the profile area inside profile (below profile header)', 'ultimate-member' ),
1374
+ 'size' => 'small',
1375
+ ),
1376
+ array(
1377
+ 'id' => 'profile_icons',
1378
+ 'type' => 'select',
1379
+ 'label' => __( 'Profile Field Icons', 'ultimate-member' ),
1380
+ 'tooltip' => __( 'This is applicable for edit mode only', 'ultimate-member' ),
1381
+ 'default' => um_get_metadefault( 'profile_icons' ),
1382
+ 'options' => array(
1383
+ 'field' => __( 'Show inside text field', 'ultimate-member' ),
1384
+ 'label' => __( 'Show with label', 'ultimate-member' ),
1385
+ 'off' => __( 'Turn off', 'ultimate-member' ),
1386
+ ),
1387
+ 'size' => 'small',
1388
+ ),
1389
+ array(
1390
+ 'id' => 'profile_primary_btn_word',
1391
+ 'type' => 'text',
1392
+ 'label' => __( 'Profile Primary Button Text', 'ultimate-member' ),
1393
+ 'default' => um_get_metadefault( 'profile_primary_btn_word' ),
1394
+ 'tooltip' => __( 'The text that is used for updating profile button', 'ultimate-member' ),
1395
+ 'size' => 'medium',
1396
+ ),
1397
+ array(
1398
+ 'id' => 'profile_secondary_btn',
1399
+ 'type' => 'checkbox',
1400
+ 'label' => __( 'Profile Secondary Button', 'ultimate-member' ),
1401
+ 'default' => um_get_metadefault( 'profile_secondary_btn' ),
1402
+ 'tooltip' => __( 'Switch on/off the secondary button display in the form', 'ultimate-member' ),
1403
+ ),
1404
+ array(
1405
+ 'id' => 'profile_secondary_btn_word',
1406
+ 'type' => 'text',
1407
+ 'label' => __( 'Profile Secondary Button Text', 'ultimate-member' ),
1408
+ 'default' => um_get_metadefault( 'profile_secondary_btn_word' ),
1409
+ 'tooltip' => __( 'The text that is used for cancelling update profile button', 'ultimate-member' ),
1410
+ 'conditional' => array( 'profile_secondary_btn', '=', 1 ),
1411
+ 'size' => 'medium',
1412
+ ),
1413
+ array(
1414
+ 'id' => 'default_avatar',
1415
+ 'type' => 'media',
1416
+ 'label' => __( 'Default Profile Photo', 'ultimate-member' ),
1417
+ 'tooltip' => __( 'You can change the default profile picture globally here. Please make sure that the photo is 300x300px.', 'ultimate-member' ),
1418
+ 'upload_frame_title' => __( 'Select Default Profile Photo', 'ultimate-member' ),
1419
+ 'default' => array(
1420
+ 'url' => um_url . 'assets/img/default_avatar.jpg',
1421
+ ),
1422
+ ),
1423
+ array(
1424
+ 'id' => 'default_cover',
1425
+ 'type' => 'media',
1426
+ 'url' => true,
1427
+ 'preview' => false,
1428
+ 'label' => __( 'Default Cover Photo', 'ultimate-member' ),
1429
+ 'tooltip' => __( 'You can change the default cover photo globally here. Please make sure that the default cover is large enough and respects the ratio you are using for cover photos.', 'ultimate-member' ),
1430
+ 'upload_frame_title' => __( 'Select Default Cover Photo', 'ultimate-member' ),
1431
+ ),
1432
+ array(
1433
+ 'id' => 'disable_profile_photo_upload',
1434
+ 'type' => 'checkbox',
1435
+ 'label' => __( 'Disable Profile Photo Upload', 'ultimate-member' ),
1436
+ 'tooltip' => __( 'Switch on/off the profile photo uploader', 'ultimate-member' ),
1437
+ 'default' => um_get_metadefault( 'disable_profile_photo_upload' ),
1438
+ ),
1439
+ array(
1440
+ 'id' => 'profile_photosize',
1441
+ 'type' => 'select',
1442
+ 'label' => __( 'Profile Photo Size', 'ultimate-member' ),
1443
+ 'default' => um_get_metadefault( 'profile_photosize' ),
1444
+ 'options' => UM()->files()->get_profile_photo_size( 'photo_thumb_sizes' ),
1445
+ 'tooltip' => __( 'The global default of profile photo size. This can be overridden by individual form settings', 'ultimate-member' ),
1446
+ 'size' => 'small',
1447
+ ),
1448
+ array(
1449
+ 'id' => 'profile_cover_enabled',
1450
+ 'type' => 'checkbox',
1451
+ 'label' => __( 'Profile Cover Photos', 'ultimate-member' ),
1452
+ 'default' => um_get_metadefault( 'profile_cover_enabled' ),
1453
+ 'tooltip' => __( 'Switch on/off the profile cover photos', 'ultimate-member' ),
1454
+ ),
1455
+ array(
1456
+ 'id' => 'profile_coversize',
1457
+ 'type' => 'select',
1458
+ 'label' => __( 'Profile Cover Size', 'ultimate-member' ),
1459
+ 'default' => um_get_metadefault( 'profile_coversize' ),
1460
+ 'options' => UM()->files()->get_profile_photo_size( 'cover_thumb_sizes' ),
1461
+ 'tooltip' => __( 'The global default width of cover photo size. This can be overridden by individual form settings', 'ultimate-member' ),
1462
+ 'conditional' => array( 'profile_cover_enabled', '=', 1 ),
1463
+ 'size' => 'small',
1464
+ ),
1465
+ array(
1466
+ 'id' => 'profile_cover_ratio',
1467
+ 'type' => 'select',
1468
+ 'label' => __( 'Profile Cover Ratio', 'ultimate-member' ),
1469
+ 'tooltip' => __( 'Choose global ratio for cover photos of profiles', 'ultimate-member' ),
1470
+ 'default' => um_get_metadefault( 'profile_cover_ratio' ),
1471
+ 'options' => array(
1472
+ '1.6:1' => '1.6:1',
1473
+ '2.7:1' => '2.7:1',
1474
+ '2.2:1' => '2.2:1',
1475
+ '3.2:1' => '3.2:1',
1476
+ ),
1477
+ 'conditional' => array( 'profile_cover_enabled', '=', 1 ),
1478
+ 'size' => 'small',
1479
+ ),
1480
+ array(
1481
+ 'id' => 'profile_show_metaicon',
1482
+ 'type' => 'checkbox',
1483
+ 'label' => __( 'Profile Header Meta Text Icon', 'ultimate-member' ),
1484
+ 'default' => 0,
1485
+ 'tooltip' => __( 'Display field icons for related user meta fields in header or not', 'ultimate-member' ),
1486
+ ),
1487
+ array(
1488
+ 'id' => 'profile_show_name',
1489
+ 'type' => 'checkbox',
1490
+ 'label' => __( 'Show display name in profile header', 'ultimate-member' ),
1491
+ 'default' => um_get_metadefault( 'profile_show_name' ),
1492
+ 'tooltip' => __( 'Switch on/off the user name on profile header', 'ultimate-member' ),
1493
+ ),
1494
+ array(
1495
+ 'id' => 'profile_show_social_links',
1496
+ 'type' => 'checkbox',
1497
+ 'label' => __( 'Show social links in profile header', 'ultimate-member' ),
1498
+ 'default' => um_get_metadefault( 'profile_show_social_links' ),
1499
+ 'tooltip' => __( 'Switch on/off the social links on profile header', 'ultimate-member' ),
1500
+ ),
1501
+ array(
1502
+ 'id' => 'profile_show_bio',
1503
+ 'type' => 'checkbox',
1504
+ 'label' => __( 'Show user description in header', 'ultimate-member' ),
1505
+ 'default' => um_get_metadefault( 'profile_show_bio' ),
1506
+ 'tooltip' => __( 'Switch on/off the user description on profile header', 'ultimate-member' ),
1507
+ ),
1508
+ array(
1509
+ 'id' => 'profile_show_html_bio',
1510
+ 'type' => 'checkbox',
1511
+ 'label' => __( 'Enable HTML support for user description', 'ultimate-member' ),
1512
+ 'tooltip' => __( 'Switch on/off to enable/disable support for html tags on user description.', 'ultimate-member' ),
1513
+ ),
1514
+ array(
1515
+ 'id' => 'profile_bio_maxchars',
1516
+ 'type' => 'text',
1517
+ 'label' => __( 'User description maximum chars', 'ultimate-member' ),
1518
+ 'default' => um_get_metadefault( 'profile_bio_maxchars' ),
1519
+ 'tooltip' => __( 'Maximum number of characters to allow in user description field in header.', 'ultimate-member' ),
1520
+ 'conditional' => array( 'profile_show_bio', '=', 1 ),
1521
+ 'size' => 'small',
1522
+ ),
1523
+ array(
1524
+ 'id' => 'profile_header_menu',
1525
+ 'type' => 'select',
1526
+ 'label' => __( 'Profile Header Menu Position', 'ultimate-member' ),
1527
+ 'default' => um_get_metadefault( 'profile_header_menu' ),
1528
+ 'tooltip' => __( 'For incompatible themes, please make the menu open from left instead of bottom by default.', 'ultimate-member' ),
1529
+ 'options' => array(
1530
+ 'bc' => __( 'Bottom of Icon', 'ultimate-member' ),
1531
+ 'lc' => __( 'Left of Icon (right for RTL)', 'ultimate-member' ),
1532
+ ),
1533
+ 'size' => 'small',
1534
+ ),
1535
+ array(
1536
+ 'id' => 'profile_empty_text',
1537
+ 'type' => 'checkbox',
1538
+ 'label' => __( 'Show a custom message if profile is empty', 'ultimate-member' ),
1539
+ 'default' => um_get_metadefault( 'profile_empty_text' ),
1540
+ 'tooltip' => __( 'Switch on/off the custom message that appears when the profile is empty', 'ultimate-member' ),
1541
+ ),
1542
+ array(
1543
+ 'id' => 'profile_empty_text_emo',
1544
+ 'type' => 'checkbox',
1545
+ 'label' => __( 'Show the emoticon', 'ultimate-member' ),
1546
+ 'default' => um_get_metadefault( 'profile_empty_text_emo' ),
1547
+ 'tooltip' => __( 'Switch on/off the emoticon (sad face) that appears above the message', 'ultimate-member' ),
1548
+ 'conditional' => array( 'profile_empty_text', '=', 1 ),
1549
+ ),
1550
+ ),
1551
+ ),
1552
+ 'profile_menu' => array(
1553
+ 'title' => __( 'Profile Menu', 'ultimate-member' ),
1554
+ 'fields' => $appearances_profile_menu_fields,
1555
+ ),
1556
+ 'registration_form' => array(
1557
+ 'title' => __( 'Registration Form', 'ultimate-member' ),
1558
+ 'fields' => array(
1559
+ array(
1560
+ 'id' => 'register_template',
1561
+ 'type' => 'select',
1562
+ 'label' => __( 'Registration Default Template', 'ultimate-member' ),
1563
+ 'tooltip' => __( 'This will be the default template to output registration', 'ultimate-member' ),
1564
+ 'default' => um_get_metadefault( 'register_template' ),
1565
+ 'options' => UM()->shortcodes()->get_templates( 'register' ),
1566
+ 'size' => 'small',
1567
+ ),
1568
+ array(
1569
+ 'id' => 'register_max_width',
1570
+ 'type' => 'text',
1571
+ 'label' => __( 'Registration Maximum Width', 'ultimate-member' ),
1572
+ 'default' => um_get_metadefault( 'register_max_width' ),
1573
+ 'tooltip' => __( 'The maximum width this shortcode can take from the page width', 'ultimate-member' ),
1574
+ 'size' => 'small',
1575
+ ),
1576
+ array(
1577
+ 'id' => 'register_align',
1578
+ 'type' => 'select',
1579
+ 'label' => __( 'Registration Shortcode Alignment', 'ultimate-member' ),
1580
+ 'tooltip' => __( 'The shortcode is centered by default unless you specify otherwise here', 'ultimate-member' ),
1581
+ 'default' => um_get_metadefault( 'register_align' ),
1582
+ 'options' => array(
1583
+ 'center' => __( 'Centered', 'ultimate-member' ),
1584
+ 'left' => __( 'Left aligned', 'ultimate-member' ),
1585
+ 'right' => __( 'Right aligned', 'ultimate-member' ),
1586
+ ),
1587
+ 'size' => 'small',
1588
+ ),
1589
+ array(
1590
+ 'id' => 'register_icons',
1591
+ 'type' => 'select',
1592
+ 'label' => __( 'Registration Field Icons', 'ultimate-member' ),
1593
+ 'tooltip' => __( 'This controls the display of field icons in the registration form', 'ultimate-member' ),
1594
+ 'default' => um_get_metadefault( 'register_icons' ),
1595
+ 'options' => array(
1596
+ 'field' => __( 'Show inside text field', 'ultimate-member' ),
1597
+ 'label' => __( 'Show with label', 'ultimate-member' ),
1598
+ 'off' => __( 'Turn off', 'ultimate-member' ),
1599
+ ),
1600
+ 'size' => 'small',
1601
+ ),
1602
+ array(
1603
+ 'id' => 'register_primary_btn_word',
1604
+ 'type' => 'text',
1605
+ 'label' => __( 'Registration Primary Button Text', 'ultimate-member' ),
1606
+ 'default' => um_get_metadefault( 'register_primary_btn_word' ),
1607
+ 'tooltip' => __( 'The text that is used for primary button text', 'ultimate-member' ),
1608
+ 'size' => 'medium',
1609
+ ),
1610
+ array(
1611
+ 'id' => 'register_secondary_btn',
1612
+ 'type' => 'checkbox',
1613
+ 'label' => __( 'Registration Secondary Button', 'ultimate-member' ),
1614
+ 'default' => 1,
1615
+ 'tooltip' => __( 'Switch on/off the secondary button display in the form', 'ultimate-member' ),
1616
+ ),
1617
+ array(
1618
+ 'id' => 'register_secondary_btn_word',
1619
+ 'type' => 'text',
1620
+ 'label' => __( 'Registration Secondary Button Text', 'ultimate-member' ),
1621
+ 'default' => um_get_metadefault( 'register_secondary_btn_word' ),
1622
+ 'tooltip' => __( 'The text that is used for the secondary button text', 'ultimate-member' ),
1623
+ 'conditional' => array( 'register_secondary_btn', '=', 1 ),
1624
+ 'size' => 'medium',
1625
+ ),
1626
+ array(
1627
+ 'id' => 'register_secondary_btn_url',
1628
+ 'type' => 'text',
1629
+ 'label' => __( 'Registration Secondary Button URL', 'ultimate-member' ),
1630
+ 'default' => um_get_metadefault( 'register_secondary_btn_url' ),
1631
+ 'tooltip' => __( 'You can replace default link for this button by entering custom URL', 'ultimate-member' ),
1632
+ 'conditional' => array( 'register_secondary_btn', '=', 1 ),
1633
+ 'size' => 'medium',
1634
+ ),
1635
+ array(
1636
+ 'id' => 'register_role',
1637
+ 'type' => 'select',
1638
+ 'label' => __( 'Registration Default Role', 'ultimate-member' ),
1639
+ 'tooltip' => __( 'This will be the default role assigned to users registering thru registration form', 'ultimate-member' ),
1640
+ 'default' => um_get_metadefault( 'register_role' ),
1641
+ 'options' => UM()->roles()->get_roles( __( 'Default', 'ultimate-member' ) ),
1642
+ 'size' => 'small',
1643
+ ),
1644
+ ),
1645
+ ),
1646
+ 'login_form' => array(
1647
+ 'title' => __( 'Login Form', 'ultimate-member' ),
1648
+ 'fields' => array(
1649
+ array(
1650
+ 'id' => 'login_template',
1651
+ 'type' => 'select',
1652
+ 'label' => __( 'Login Default Template', 'ultimate-member' ),
1653
+ 'tooltip' => __( 'This will be the default template to output login', 'ultimate-member' ),
1654
+ 'default' => um_get_metadefault( 'login_template' ),
1655
+ 'options' => UM()->shortcodes()->get_templates( 'login' ),
1656
+ 'size' => 'small',
1657
+ ),
1658
+ array(
1659
+ 'id' => 'login_max_width',
1660
+ 'type' => 'text',
1661
+ 'label' => __( 'Login Maximum Width', 'ultimate-member' ),
1662
+ 'default' => um_get_metadefault( 'login_max_width' ),
1663
+ 'tooltip' => __( 'The maximum width this shortcode can take from the page width', 'ultimate-member' ),
1664
+ 'size' => 'small',
1665
+ ),
1666
+ array(
1667
+ 'id' => 'login_align',
1668
+ 'type' => 'select',
1669
+ 'label' => __( 'Login Shortcode Alignment', 'ultimate-member' ),
1670
+ 'tooltip' => __( 'The shortcode is centered by default unless you specify otherwise here', 'ultimate-member' ),
1671
+ 'default' => um_get_metadefault( 'login_align' ),
1672
+ 'options' => array(
1673
+ 'center' => __( 'Centered', 'ultimate-member' ),
1674
+ 'left' => __( 'Left aligned', 'ultimate-member' ),
1675
+ 'right' => __( 'Right aligned', 'ultimate-member' ),
1676
+ ),
1677
+ 'size' => 'small',
1678
+ ),
1679
+ array(
1680
+ 'id' => 'login_icons',
1681
+ 'type' => 'select',
1682
+ 'label' => __( 'Login Field Icons', 'ultimate-member' ),
1683
+ 'tooltip' => __( 'This controls the display of field icons in the login form', 'ultimate-member' ),
1684
+ 'default' => um_get_metadefault( 'login_icons' ),
1685
+ 'options' => array(
1686
+ 'field' => __( 'Show inside text field', 'ultimate-member' ),
1687
+ 'label' => __( 'Show with label', 'ultimate-member' ),
1688
+ 'off' => __( 'Turn off', 'ultimate-member' ),
1689
+ ),
1690
+ 'size' => 'small',
1691
+ ),
1692
+ array(
1693
+ 'id' => 'login_primary_btn_word',
1694
+ 'type' => 'text',
1695
+ 'label' => __( 'Login Primary Button Text', 'ultimate-member' ),
1696
+ 'default' => um_get_metadefault( 'login_primary_btn_word' ),
1697
+ 'tooltip' => __( 'The text that is used for primary button text', 'ultimate-member' ),
1698
+ 'size' => 'medium',
1699
+ ),
1700
+ array(
1701
+ 'id' => 'login_secondary_btn',
1702
+ 'type' => 'checkbox',
1703
+ 'label' => __( 'Login Secondary Button', 'ultimate-member' ),
1704
+ 'default' => 1,
1705
+ 'tooltip' => __( 'Switch on/off the secondary button display in the form', 'ultimate-member' ),
1706
+ ),
1707
+ array(
1708
+ 'id' => 'login_secondary_btn_word',
1709
+ 'type' => 'text',
1710
+ 'label' => __( 'Login Secondary Button Text', 'ultimate-member' ),
1711
+ 'default' => um_get_metadefault( 'login_secondary_btn_word' ),
1712
+ 'tooltip' => __( 'The text that is used for the secondary button text', 'ultimate-member' ),
1713
+ 'conditional' => array( 'login_secondary_btn', '=', 1 ),
1714
+ 'size' => 'medium',
1715
+ ),
1716
+ array(
1717
+ 'id' => 'login_secondary_btn_url',
1718
+ 'type' => 'text',
1719
+ 'label' => __( 'Login Secondary Button URL', 'ultimate-member' ),
1720
+ 'default' => um_get_metadefault( 'login_secondary_btn_url' ),
1721
+ 'tooltip' => __( 'You can replace default link for this button by entering custom URL', 'ultimate-member' ),
1722
+ 'conditional' => array( 'login_secondary_btn', '=', 1 ),
1723
+ 'size' => 'medium',
1724
+ ),
1725
+ array(
1726
+ 'id' => 'login_forgot_pass_link',
1727
+ 'type' => 'checkbox',
1728
+ 'label' => __( 'Login Forgot Password Link', 'ultimate-member' ),
1729
+ 'default' => 1,
1730
+ 'tooltip' => __( 'Switch on/off the forgot password link in login form', 'ultimate-member' ),
1731
+ ),
1732
+ array(
1733
+ 'id' => 'login_show_rememberme',
1734
+ 'type' => 'checkbox',
1735
+ 'label' => __( 'Show "Remember Me"', 'ultimate-member' ),
1736
+ 'default' => 1,
1737
+ 'tooltip' => __( 'Allow users to choose If they want to stay signed in even after closing the browser. If you do not show this option, the default will be to not remember login session.', 'ultimate-member' ),
1738
+ ),
1739
+ ),
1740
+ ),
1741
+ ),
1742
+ ),
1743
+ 'extensions' => array(
1744
+ 'title' => __( 'Extensions', 'ultimate-member' ),
1745
+ ),
1746
+ 'licenses' => array(
1747
+ 'title' => __( 'Licenses', 'ultimate-member' ),
1748
+ ),
1749
+ 'misc' => array(
1750
+ 'title' => __( 'Misc', 'ultimate-member' ),
1751
+ 'fields' => array(
1752
+ array(
1753
+ 'id' => 'form_asterisk',
1754
+ 'type' => 'checkbox',
1755
+ 'label' => __( 'Show an asterisk for required fields', 'ultimate-member' ),
1756
+ ),
1757
+ array(
1758
+ 'id' => 'profile_title',
1759
+ 'type' => 'text',
1760
+ 'label' => __( 'User Profile Title', 'ultimate-member' ),
1761
+ 'tooltip' => __( 'This is the title that is displayed on a specific user profile', 'ultimate-member' ),
1762
+ 'size' => 'medium',
1763
+ ),
1764
+ array(
1765
+ 'id' => 'profile_desc',
1766
+ 'type' => 'textarea',
1767
+ 'label' => __( 'User Profile Dynamic Meta Description', 'ultimate-member' ),
1768
+ 'tooltip' => __( 'This will be used in the meta description that is available for search-engines.', 'ultimate-member' ),
1769
+ 'args' => array(
1770
+ 'textarea_rows' => 6,
1771
+ ),
1772
+ ),
1773
+ array(
1774
+ 'id' => 'um_profile_object_cache_stop',
1775
+ 'type' => 'checkbox',
1776
+ 'label' => __( 'Disable Cache User Profile', 'ultimate-member' ),
1777
+ 'tooltip' => __( 'Check this box if you would like to disable Ultimate Member user\'s cache.', 'ultimate-member' ),
1778
+ ),
1779
+ array(
1780
+ 'id' => 'enable_blocks',
1781
+ 'type' => 'checkbox',
1782
+ 'label' => __( 'Enable Gutenberg Blocks', 'ultimate-member' ),
1783
+ 'tooltip' => __( 'Check this box if you would like to use Ultimate Member blocks in Gutenberg editor. Important some themes have the conflicts with Gutenberg editor.', 'ultimate-member' ),
1784
+ ),
1785
+ array(
1786
+ 'id' => 'rest_api_version',
1787
+ 'type' => 'select',
1788
+ 'label' => __( 'REST API version', 'ultimate-member' ),
1789
+ 'tooltip' => __( 'This controls the REST API version, we recommend to use the last version', 'ultimate-member' ),
1790
+ 'options' => array(
1791
+ '1.0' => __( '1.0 version', 'ultimate-member' ),
1792
+ '2.0' => __( '2.0 version', 'ultimate-member' ),
1793
+ ),
1794
+ ),
1795
+ // backward compatibility option leave it disabled for better security and ability to exclude posts/terms pre-query
1796
+ // otherwise we filtering only results and restricted posts/terms can be visible
1797
+ array(
1798
+ 'id' => 'disable_restriction_pre_queries',
1799
+ 'type' => 'checkbox',
1800
+ 'label' => __( 'Disable pre-queries for restriction content logic (advanced)', 'ultimate-member' ),
1801
+ 'tooltip' => __( 'Please enable this option only in the cases when you have big or unnecessary queries on your site with active restriction logic. If you want to exclude posts only from the results queries instead of pre_get_posts and fully-hidden post logic also please enable this option. It activates the restriction content logic until 2.2.x version without latest security enhancements', 'ultimate-member' ),
1802
+ ),
1803
+ $same_page_update,
1804
+ array(
1805
+ 'id' => 'uninstall_on_delete',
1806
+ 'type' => 'checkbox',
1807
+ 'label' => __( 'Remove Data on Uninstall?', 'ultimate-member' ),
1808
+ 'tooltip' => __( 'Check this box if you would like Ultimate Member to completely remove all of its data when the plugin/extensions are deleted.', 'ultimate-member' ),
1809
+ ),
1810
+ ),
1811
+ ),
1812
+ 'install_info' => array(
1813
+ 'title' => __( 'Install Info', 'ultimate-member' ),
1814
+ 'fields' => array(
1815
+ array(
1816
+ 'type' => 'install_info',
1817
+ ),
1818
+ ),
1819
+ ),
1820
+ )
1821
+ );
1822
+
1823
+ }
1824
+
1825
+
1826
+ /**
1827
+ * @param array $settings
1828
+ *
1829
+ * @return array
1830
+ */
1831
+ public function sorting_licenses_options( $settings ) {
1832
+ //sorting licenses
1833
+ if ( ! empty( $settings['licenses']['fields'] ) ) {
1834
+ $licenses = $settings['licenses']['fields'];
1835
+ @uasort( $licenses, function( $a, $b ) {
1836
+ return strnatcasecmp( $a['label'], $b['label'] );
1837
+ } );
1838
+ $settings['licenses']['fields'] = $licenses;
1839
+ }
1840
+
1841
+ //sorting extensions by the title
1842
+ if ( ! empty( $settings['extensions']['sections'] ) ) {
1843
+ $extensions = $settings['extensions']['sections'];
1844
+
1845
+ @uasort( $extensions, function( $a, $b ) {
1846
+ return strnatcasecmp( $a['title'], $b['title'] );
1847
+ } );
1848
+
1849
+ $keys = array_keys( $extensions );
1850
+ $temp = array(
1851
+ '' => $extensions[ $keys[0] ],
1852
+ );
1853
+
1854
+ unset( $extensions[ $keys[0] ] );
1855
+ $extensions = $temp + $extensions;
1856
+
1857
+ $settings['extensions']['sections'] = $extensions;
1858
+ }
1859
+
1860
+ return $settings;
1861
+ }
1862
+
1863
+
1864
+ /**
1865
+ * @param $tab
1866
+ * @param $section
1867
+ *
1868
+ * @return array
1869
+ */
1870
+ function get_section_fields( $tab, $section ) {
1871
+
1872
+ if ( empty( $this->settings_structure[ $tab ] ) ) {
1873
+ return array();
1874
+ }
1875
+
1876
+ if ( ! empty( $this->settings_structure[ $tab ]['sections'][ $section ]['fields'] ) ) {
1877
+ return $this->settings_structure[ $tab ]['sections'][ $section ]['fields'];
1878
+ } elseif ( ! empty( $this->settings_structure[ $tab ]['fields'] ) ) {
1879
+ return $this->settings_structure[ $tab ]['fields'];
1880
+ }
1881
+
1882
+ return array();
1883
+ }
1884
+
1885
+
1886
+ /**
1887
+ * Setup admin menu
1888
+ */
1889
+ function primary_admin_menu() {
1890
+ add_submenu_page( 'ultimatemember', __( 'Settings', 'ultimate-member' ), __( 'Settings', 'ultimate-member' ), 'manage_options', 'um_options', array( &$this, 'settings_page' ) );
1891
+ }
1892
+
1893
+
1894
+ /**
1895
+ * Settings page callback
1896
+ */
1897
+ function settings_page() {
1898
+ $current_tab = empty( $_GET['tab'] ) ? '' : sanitize_key( $_GET['tab'] );
1899
+ $current_subtab = empty( $_GET['section'] ) ? '' : sanitize_key( $_GET['section'] );
1900
+
1901
+ $settings_struct = $this->settings_structure[ $current_tab ];
1902
+
1903
+ //remove not option hidden fields
1904
+ if ( ! empty( $settings_struct['fields'] ) ) {
1905
+ foreach ( $settings_struct['fields'] as $field_key => $field_options ) {
1906
+
1907
+ if ( isset( $field_options['is_option'] ) && $field_options['is_option'] === false ) {
1908
+ unset( $settings_struct['fields'][ $field_key ] );
1909
+ }
1910
+
1911
+ }
1912
+ }
1913
+
1914
+ if ( empty( $settings_struct['fields'] ) && empty( $settings_struct['sections'] ) ) {
1915
+ um_js_redirect( add_query_arg( array( 'page' => 'um_options' ), admin_url( 'admin.php' ) ) );
1916
+ }
1917
+
1918
+ if ( ! empty( $settings_struct['sections'] ) ) {
1919
+ if ( empty( $settings_struct['sections'][ $current_subtab ] ) ) {
1920
+ um_js_redirect( add_query_arg( array( 'page' => 'um_options', 'tab' => $current_tab ), admin_url( 'admin.php' ) ) );
1921
+ }
1922
+ }
1923
+
1924
+ echo '<div id="um-settings-wrap" class="wrap"><h2>' . __( 'Ultimate Member - Settings', 'ultimate-member' ) . '</h2>';
1925
+
1926
+ echo $this->generate_tabs_menu() . $this->generate_subtabs_menu( $current_tab );
1927
+
1928
+ /**
1929
+ * UM hook
1930
+ *
1931
+ * @type action
1932
+ * @title um_settings_page_before_{$current_tab}_{$current_subtab}_content
1933
+ * @description Show some content before settings page content
1934
+ * @change_log
1935
+ * ["Since: 2.0"]
1936
+ * @usage add_action( 'um_settings_page_before_{$current_tab}_{$current_subtab}_content', 'function_name', 10 );
1937
+ * @example
1938
+ * <?php
1939
+ * add_action( 'um_settings_page_before_{$current_tab}_{$current_subtab}_content', 'my_settings_page_before', 10 );
1940
+ * function my_settings_page_before() {
1941
+ * // your code here
1942
+ * }
1943
+ * ?>
1944
+ */
1945
+ do_action( "um_settings_page_before_" . $current_tab . "_" . $current_subtab . "_content" );
1946
+
1947
+ if ( in_array( $current_tab, apply_filters('um_settings_custom_tabs', array( 'licenses', 'install_info' ) ) ) || in_array( $current_subtab, apply_filters( 'um_settings_custom_subtabs', array(), $current_tab ) ) ) {
1948
+
1949
+ /**
1950
+ * UM hook
1951
+ *
1952
+ * @type action
1953
+ * @title um_settings_page_{$current_tab}_{$current_subtab}_before_section
1954
+ * @description Show some content before section content at settings page
1955
+ * @change_log
1956
+ * ["Since: 2.0"]
1957
+ * @usage add_action( 'um_settings_page_{$current_tab}_{$current_subtab}_before_section', 'function_name', 10 );
1958
+ * @example
1959
+ * <?php
1960
+ * add_action( 'um_settings_page_{$current_tab}_{$current_subtab}_before_section', 'my_settings_page_before_section', 10 );
1961
+ * function my_settings_page_before_section() {
1962
+ * // your code here
1963
+ * }
1964
+ * ?>
1965
+ */
1966
+ do_action( "um_settings_page_" . $current_tab . "_" . $current_subtab . "_before_section" );
1967
+
1968
+ $section_fields = $this->get_section_fields( $current_tab, $current_subtab );
1969
+ $settings_section = $this->render_settings_section( $section_fields, $current_tab, $current_subtab );
1970
+
1971
+ /**
1972
+ * UM hook
1973
+ *
1974
+ * @type filter
1975
+ * @title um_settings_section_{$current_tab}_{$current_subtab}_content
1976
+ *
1977
+ * @description Render settings section
1978
+ * @input_vars
1979
+ * [{"var":"$content","type":"string","desc":"Section content"},
1980
+ * {"var":"$section_fields","type":"array","desc":"Section Fields"}]
1981
+ * @change_log
1982
+ * ["Since: 2.0"]
1983
+ * @usage add_filter( 'um_settings_section_{$current_tab}_{$current_subtab}_content', 'function_name', 10, 2 );
1984
+ * @example
1985
+ * <?php
1986
+ * add_filter( 'um_settings_section_{$current_tab}_{$current_subtab}_content', 'my_settings_section', 10, 2 );
1987
+ * function my_settings_section( $content ) {
1988
+ * // your code here
1989
+ * return $content;
1990
+ * }
1991
+ * ?>
1992
+ */
1993
+ echo apply_filters( 'um_settings_section_' . $current_tab . '_' . $current_subtab . '_content',
1994
+ $settings_section,
1995
+ $section_fields
1996
+ );
1997
+
1998
+ } else { ?>
1999
+
2000
+ <form method="post" action="" name="um-settings-form" id="um-settings-form">
2001
+ <input type="hidden" value="save" name="um-settings-action" />
2002
+
2003
+ <?php
2004
+ /**
2005
+ * UM hook
2006
+ *
2007
+ * @type action
2008
+ * @title um_settings_page_{$current_tab}_{$current_subtab}_before_section
2009
+ * @description Show some content before section content at settings page
2010
+ * @change_log
2011
+ * ["Since: 2.0"]
2012
+ * @usage add_action( 'um_settings_page_{$current_tab}_{$current_subtab}_before_section', 'function_name', 10 );
2013
+ * @example
2014
+ * <?php
2015
+ * add_action( 'um_settings_page_{$current_tab}_{$current_subtab}_before_section', 'my_settings_page_before_section', 10 );
2016
+ * function my_settings_page_before_section() {
2017
+ * // your code here
2018
+ * }
2019
+ * ?>
2020
+ */
2021
+ do_action( "um_settings_page_" . $current_tab . "_" . $current_subtab . "_before_section" );
2022
+
2023
+ $section_fields = $this->get_section_fields( $current_tab, $current_subtab );
2024
+ $settings_section = $this->render_settings_section( $section_fields, $current_tab, $current_subtab );
2025
+
2026
+ /**
2027
+ * UM hook
2028
+ *
2029
+ * @type filter
2030
+ * @title um_settings_section_{$current_tab}_{$current_subtab}_content
2031
+ * @description Render settings section
2032
+ * @input_vars
2033
+ * [{"var":"$content","type":"string","desc":"Section content"},
2034
+ * {"var":"$section_fields","type":"array","desc":"Section Fields"}]
2035
+ * @change_log
2036
+ * ["Since: 2.0"]
2037
+ * @usage add_filter( 'um_settings_section_{$current_tab}_{$current_subtab}_content', 'function_name', 10, 2 );
2038
+ * @example
2039
+ * <?php
2040
+ * add_filter( 'um_settings_section_{$current_tab}_{$current_subtab}_content', 'my_settings_section', 10, 2 );
2041
+ * function my_settings_section( $content ) {
2042
+ * // your code here
2043
+ * return $content;
2044
+ * }
2045
+ * ?>
2046
+ */
2047
+ echo apply_filters( 'um_settings_section_' . $current_tab . '_' . $current_subtab . '_content',
2048
+ $settings_section,
2049
+ $section_fields
2050
+ ); ?>
2051
+
2052
+
2053
+ <p class="submit">
2054
+ <input type="submit" name="submit" id="submit" class="button button-primary" value="<?php esc_attr_e( 'Save Changes', 'ultimate-member' ) ?>" />
2055
+ <?php $um_settings_nonce = wp_create_nonce( 'um-settings-nonce' ); ?>
2056
+ <input type="hidden" name="__umnonce" value="<?php echo esc_attr( $um_settings_nonce ); ?>" />
2057
+ </p>
2058
+ </form>
2059
+
2060
+ <?php }
2061
+ }
2062
+
2063
+
2064
+ /**
2065
+ * Generate pages tabs
2066
+ *
2067
+ * @param string $page
2068
+ * @return string
2069
+ */
2070
+ function generate_tabs_menu( $page = 'settings' ) {
2071
+
2072
+ $tabs = '<h2 class="nav-tab-wrapper um-nav-tab-wrapper">';
2073
+
2074
+ switch( $page ) {
2075
+ case 'settings':
2076
+ $menu_tabs = array();
2077
+ foreach ( $this->settings_structure as $slug => $tab ) {
2078
+ if ( ! empty( $tab['fields'] ) ) {
2079
+ foreach ( $tab['fields'] as $field_key => $field_options ) {
2080
+ if ( isset( $field_options['is_option'] ) && $field_options['is_option'] === false ) {
2081
+ unset( $tab['fields'][ $field_key ] );
2082
+ }
2083
+ }
2084
+ }
2085
+
2086
+ if ( ! empty( $tab['fields'] ) || ! empty( $tab['sections'] ) ) {
2087
+ $menu_tabs[ $slug ] = $tab['title'];
2088
+ }
2089
+ }
2090
+
2091
+ $current_tab = empty( $_GET['tab'] ) ? '' : sanitize_key( $_GET['tab'] );
2092
+ foreach ( $menu_tabs as $name => $label ) {
2093
+ $active = ( $current_tab == $name ) ? 'nav-tab-active' : '';
2094
+ $tabs .= '<a href="' . esc_url( admin_url( 'admin.php?page=um_options' . ( empty( $name ) ? '' : '&tab=' . $name ) ) ) . '" class="nav-tab ' . esc_attr( $active ) . '">' .
2095
+ $label .
2096
+ '</a>';
2097
+ }
2098
+
2099
+ break;
2100
+ default:
2101
+ /**
2102
+ * UM hook
2103
+ *
2104
+ * @type filter
2105
+ * @title um_generate_tabs_menu_{$page}
2106
+ * @description Generate tabs menu
2107
+ * @input_vars
2108
+ * [{"var":"$tabs","type":"array","desc":"UM menu tabs"}]
2109
+ * @change_log
2110
+ * ["Since: 2.0"]
2111
+ * @usage add_filter( 'um_generate_tabs_menu_{$page}', 'function_name', 10, 1 );
2112
+ * @example
2113
+ * <?php
2114
+ * add_filter( 'um_generate_tabs_menu_{$page}', 'my_tabs_menu', 10, 1 );
2115
+ * function my_tabs_menu( $tabs ) {
2116
+ * // your code here
2117
+ * return $tabs;
2118
+ * }
2119
+ * ?>
2120
+ */
2121
+ $tabs = apply_filters( 'um_generate_tabs_menu_' . $page, $tabs );
2122
+ break;
2123
+ }
2124
+
2125
+ return $tabs . '</h2>';
2126
+ }
2127
+
2128
+
2129
+ /**
2130
+ * @param string $tab
2131
+ *
2132
+ * @return string
2133
+ */
2134
+ function generate_subtabs_menu( $tab = '' ) {
2135
+ if ( empty( $this->settings_structure[ $tab ]['sections'] ) ) {
2136
+ return '';
2137
+ }
2138
+
2139
+ $menu_subtabs = array();
2140
+ foreach ( $this->settings_structure[ $tab ]['sections'] as $slug => $subtab ) {
2141
+ $menu_subtabs[ $slug ] = $subtab['title'];
2142
+ }
2143
+
2144
+ $subtabs = '<div><ul class="subsubsub">';
2145
+
2146
+ $current_tab = empty( $_GET['tab'] ) ? '' : sanitize_key( $_GET['tab'] );
2147
+ $current_subtab = empty( $_GET['section'] ) ? '' : sanitize_key( $_GET['section'] );
2148
+ foreach ( $menu_subtabs as $name => $label ) {
2149
+ $active = ( $current_subtab == $name ) ? 'current' : '';
2150
+ $subtabs .= '<a href="' . esc_url( admin_url( 'admin.php?page=um_options' . ( empty( $current_tab ) ? '' : '&tab=' . $current_tab ) . ( empty( $name ) ? '' : '&section=' . $name ) ) ) . '" class="' . $active . '">'
2151
+ . $label .
2152
+ '</a> | ';
2153
+ }
2154
+
2155
+ return substr( $subtabs, 0, -3 ) . '</ul></div>';
2156
+ }
2157
+
2158
+
2159
+ /**
2160
+ * Handler for settings forms
2161
+ * when "Save Settings" button click
2162
+ *
2163
+ */
2164
+ function save_settings_handler() {
2165
+
2166
+ if ( isset( $_POST['um-settings-action'] ) && 'save' === sanitize_key( $_POST['um-settings-action'] ) && ! empty( $_POST['um_options'] ) ) {
2167
+
2168
+ $nonce = ! empty( $_POST['__umnonce'] ) ? $_POST['__umnonce'] : '';
2169
+
2170
+ if ( ( ! wp_verify_nonce( $nonce, 'um-settings-nonce' ) || empty( $nonce ) ) || ! current_user_can( 'manage_options' ) ) {
2171
+ // This nonce is not valid.
2172
+ wp_die( __( 'Security Check', 'ultimate-member' ) );
2173
+ }
2174
+
2175
+ /**
2176
+ * UM hook
2177
+ *
2178
+ * @type action
2179
+ * @title um_settings_before_save
2180
+ * @description Before settings save action
2181
+ * @change_log
2182
+ * ["Since: 2.0"]
2183
+ * @usage add_action( 'um_settings_before_save', 'function_name', 10 );
2184
+ * @example
2185
+ * <?php
2186
+ * add_action( 'um_settings_before_save', 'my_settings_before_save', 10 );
2187
+ * function my_settings_before_save() {
2188
+ * // your code here
2189
+ * }
2190
+ * ?>
2191
+ */
2192
+ do_action( "um_settings_before_save" );
2193
+
2194
+ /**
2195
+ * UM hook
2196
+ *
2197
+ * @type filter
2198
+ * @title um_change_settings_before_save
2199
+ * @description Change settings before save
2200
+ * @input_vars
2201
+ * [{"var":"$settings","type":"array","desc":"UM Settings on save"}]
2202
+ * @change_log
2203
+ * ["Since: 2.0"]
2204
+ * @usage add_filter( 'um_change_settings_before_save', 'function_name', 10, 1 );
2205
+ * @example
2206
+ * <?php
2207
+ * add_filter( 'um_change_settings_before_save', 'my_change_settings_before_save', 10, 1 );
2208
+ * function my_change_settings_before_save( $settings ) {
2209
+ * // your code here
2210
+ * return $settings;
2211
+ * }
2212
+ * ?>
2213
+ */
2214
+ $settings = apply_filters( 'um_change_settings_before_save', $_POST['um_options'] );
2215
+
2216
+ $settings = UM()->admin()->sanitize_options( $settings );
2217
+
2218
+ foreach ( $settings as $key => $value ) {
2219
+ UM()->options()->update( $key, $value );
2220
+ }
2221
+
2222
+ /**
2223
+ * UM hook
2224
+ *
2225
+ * @type action
2226
+ * @title um_settings_save
2227
+ * @description After settings save action
2228
+ * @change_log
2229
+ * ["Since: 2.0"]
2230
+ * @usage add_action( 'um_settings_save', 'function_name', 10 );
2231
+ * @example
2232
+ * <?php
2233
+ * add_action( 'um_settings_save', 'my_settings_save', 10 );
2234
+ * function my_settings_save() {
2235
+ * // your code here
2236
+ * }
2237
+ * ?>
2238
+ */
2239
+ do_action( 'um_settings_save' );
2240
+
2241
+ //redirect after save settings
2242
+ $arg = array(
2243
+ 'page' => 'um_options',
2244
+ 'update' => 'settings_updated',
2245
+ );
2246
+
2247
+ if ( ! empty( $_GET['tab'] ) ) {
2248
+ $arg['tab'] = sanitize_key( $_GET['tab'] );
2249
+ }
2250
+
2251
+ if ( ! empty( $_GET['section'] ) ) {
2252
+ $arg['section'] = sanitize_key( $_GET['section'] );
2253
+ }
2254
+
2255
+ um_js_redirect( add_query_arg( $arg, admin_url( 'admin.php' ) ) );
2256
+ }
2257
+ }
2258
+
2259
+
2260
+ function set_default_if_empty( $settings ) {
2261
+ $tab = '';
2262
+ if ( ! empty( $_GET['tab'] ) ) {
2263
+ $tab = sanitize_key( $_GET['tab'] );
2264
+ }
2265
+
2266
+ $section = '';
2267
+ if ( ! empty( $_GET['section'] ) ) {
2268
+ $section = sanitize_key( $_GET['section'] );
2269
+ }
2270
+
2271
+
2272
+ if ( 'access' === $tab && empty( $section ) ) {
2273
+ if ( ! array_key_exists( 'access_exclude_uris', $settings ) ) {
2274
+ $settings['access_exclude_uris'] = array();
2275
+ }
2276
+ }
2277
+
2278
+ return $settings;
2279
+ }
2280
+
2281
+
2282
+ /**
2283
+ * Remove empty values from multi text fields
2284
+ *
2285
+ * @param $settings
2286
+ * @return array
2287
+ */
2288
+ function remove_empty_values( $settings ) {
2289
+ $tab = '';
2290
+ if ( ! empty( $_GET['tab'] ) ) {
2291
+ $tab = sanitize_key( $_GET['tab'] );
2292
+ }
2293
+
2294
+ $section = '';
2295
+ if ( ! empty( $_GET['section'] ) ) {
2296
+ $section = sanitize_key( $_GET['section'] );
2297
+ }
2298
+
2299
+ if ( isset( $this->settings_structure[ $tab ]['sections'][ $section ]['fields'] ) ) {
2300
+ $fields = $this->settings_structure[ $tab ]['sections'][ $section ]['fields'];
2301
+ } else {
2302
+ $fields = $this->settings_structure[ $tab ]['fields'];
2303
+ }
2304
+
2305
+ if ( empty( $fields ) ) {
2306
+ return $settings;
2307
+ }
2308
+
2309
+
2310
+ $filtered_settings = array();
2311
+ foreach ( $settings as $key => $value ) {
2312
+
2313
+ $filtered_settings[ $key ] = $value;
2314
+
2315
+ foreach ( $fields as $field ) {
2316
+ if ( $field['id'] == $key && isset( $field['type'] ) && $field['type'] == 'multi_text' ) {
2317
+ $filtered_settings[ $key ] = array_filter( $settings[ $key ] );
2318
+ }
2319
+ }
2320
+ }
2321
+
2322
+ return $filtered_settings;
2323
+ }
2324
+
2325
+
2326
+ /**
2327
+ *
2328
+ */
2329
+ function check_permalinks_changes() {
2330
+ if ( ! empty( $_POST['um_options']['permalink_base'] ) ) {
2331
+ if ( UM()->options()->get( 'permalink_base' ) !== $_POST['um_options']['permalink_base'] ) {
2332
+ $this->need_change_permalinks = true;
2333
+ }
2334
+ }
2335
+
2336
+ // set variable if gravatar settings were changed
2337
+ // update for um_member_directory_data metakey
2338
+ if ( isset( $_POST['um_options']['use_gravatars'] ) ) {
2339
+ $use_gravatar = UM()->options()->get( 'use_gravatars' );
2340
+ if ( ( empty( $use_gravatar ) && ! empty( $_POST['um_options']['use_gravatars'] ) ) || ( ! empty( $use_gravatar ) && empty( $_POST['um_options']['use_gravatars'] ) ) ) {
2341
+ $this->gravatar_changed = true;
2342
+ }
2343
+ }
2344
+ }
2345
+
2346
+
2347
+ /**
2348
+ *
2349
+ */
2350
+ function on_settings_save() {
2351
+ if ( ! empty( $_POST['um_options'] ) ) {
2352
+
2353
+ if ( ! empty( $_POST['um_options']['pages_settings'] ) ) {
2354
+ $post_ids = new \WP_Query( array(
2355
+ 'post_type' => 'page',
2356
+ 'meta_query' => array(
2357
+ array(
2358
+ 'key' => '_um_core',
2359
+ 'compare' => 'EXISTS'
2360
+ )
2361
+ ),
2362
+ 'posts_per_page' => -1,
2363
+ 'fields' => 'ids'
2364
+ ) );
2365
+
2366
+ $post_ids = $post_ids->get_posts();
2367
+
2368
+ if ( ! empty( $post_ids ) ) {
2369
+ foreach ( $post_ids as $post_id ) {
2370
+ delete_post_meta( $post_id, '_um_core' );
2371
+ }
2372
+ }
2373
+
2374
+ foreach ( $_POST['um_options'] as $option_slug => $post_id ) {
2375
+ $slug = str_replace( 'core_', '', $option_slug );
2376
+ update_post_meta( $post_id, '_um_core', $slug );
2377
+ }
2378
+
2379
+ // reset rewrite rules after re-save pages
2380
+ UM()->rewrite()->reset_rules();
2381
+
2382
+ } elseif ( ! empty( $_POST['um_options']['permalink_base'] ) ) {
2383
+ if ( ! empty( $this->need_change_permalinks ) ) {
2384
+ $users = get_users( array(
2385
+ 'fields' => 'ids',
2386
+ ) );
2387
+ if ( ! empty( $users ) ) {
2388
+ foreach ( $users as $user_id ) {
2389
+ UM()->user()->generate_profile_slug( $user_id );
2390
+ }
2391
+ }
2392
+ }
2393
+
2394
+
2395
+ // update for um_member_directory_data metakey
2396
+ if ( isset( $_POST['um_options']['use_gravatars'] ) ) {
2397
+ if ( $this->gravatar_changed ) {
2398
+ global $wpdb;
2399
+
2400
+ if ( ! empty( $_POST['um_options']['use_gravatars'] ) ) {
2401
+
2402
+ $results = $wpdb->get_col(
2403
+ "SELECT u.ID FROM {$wpdb->users} AS u
2404
+ LEFT JOIN {$wpdb->usermeta} AS um ON ( um.user_id = u.ID AND um.meta_key = 'synced_gravatar_hashed_id' )
2405
+ LEFT JOIN {$wpdb->usermeta} AS um2 ON ( um2.user_id = u.ID AND um2.meta_key = 'um_member_directory_data' )
2406
+ WHERE um.meta_value != '' AND um.meta_value IS NOT NULL AND
2407
+ um2.meta_value LIKE '%s:13:\"profile_photo\";b:0;%'"
2408
+ );
2409
+
2410
+ } else {
2411
+
2412
+ $results = $wpdb->get_col(
2413
+ "SELECT u.ID FROM {$wpdb->users} AS u
2414
+ LEFT JOIN {$wpdb->usermeta} AS um ON ( um.user_id = u.ID AND ( um.meta_key = 'synced_profile_photo' || um.meta_key = 'profile_photo' ) )
2415
+ LEFT JOIN {$wpdb->usermeta} AS um2 ON ( um2.user_id = u.ID AND um2.meta_key = 'um_member_directory_data' )
2416
+ WHERE ( um.meta_value IS NULL OR um.meta_value = '' ) AND
2417
+ um2.meta_value LIKE '%s:13:\"profile_photo\";b:1;%'"
2418
+ );
2419
+
2420
+ }
2421
+
2422
+ if ( ! empty( $results ) ) {
2423
+ foreach ( $results as $user_id ) {
2424
+ $md_data = get_user_meta( $user_id, 'um_member_directory_data', true );
2425
+ if ( ! empty( $md_data ) ) {
2426
+ $md_data['profile_photo'] = ! empty( $_POST['um_options']['use_gravatars'] );
2427
+ update_user_meta( $user_id, 'um_member_directory_data', $md_data );
2428
+ }
2429
+ }
2430
+ }
2431
+ }
2432
+ }
2433
+
2434
+ } elseif ( isset( $_POST['um_options']['member_directory_own_table'] ) ) {
2435
+ if ( empty( $_POST['um_options']['member_directory_own_table'] ) ) {
2436
+ global $wpdb;
2437
+
2438
+ $results = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}um_metadata LIMIT 1", ARRAY_A );
2439
+
2440
+ if ( ! empty( $results ) ) {
2441
+ $wpdb->query("TRUNCATE TABLE {$wpdb->prefix}um_metadata" );
2442
+ }
2443
+
2444
+ update_option( 'um_member_directory_truncated', time() );
2445
+ }
2446
+ } elseif ( isset( $_POST['um_options']['account_hide_in_directory_default'] ) ) {
2447
+
2448
+ global $wpdb;
2449
+
2450
+ if ( $_POST['um_options']['account_hide_in_directory_default'] === 'No' ) {
2451
+
2452
+ $results = $wpdb->get_col(
2453
+ "SELECT u.ID FROM {$wpdb->users} AS u
2454
+ LEFT JOIN {$wpdb->usermeta} AS um ON ( um.user_id = u.ID AND um.meta_key = 'hide_in_members' )
2455
+ LEFT JOIN {$wpdb->usermeta} AS um2 ON ( um2.user_id = u.ID AND um2.meta_key = 'um_member_directory_data' )
2456
+ WHERE um.meta_value IS NULL AND
2457
+ um2.meta_value LIKE '%s:15:\"hide_in_members\";b:1;%'"
2458
+ );
2459
+
2460
+ } else {
2461
+
2462
+ $results = $wpdb->get_col(
2463
+ "SELECT u.ID FROM {$wpdb->users} AS u
2464
+ LEFT JOIN {$wpdb->usermeta} AS um ON ( um.user_id = u.ID AND um.meta_key = 'hide_in_members' )
2465
+ LEFT JOIN {$wpdb->usermeta} AS um2 ON ( um2.user_id = u.ID AND um2.meta_key = 'um_member_directory_data' )
2466
+ WHERE um.meta_value IS NULL AND
2467
+ um2.meta_value LIKE '%s:15:\"hide_in_members\";b:0;%'"
2468
+ );
2469
+
2470
+ }
2471
+
2472
+ if ( ! empty( $results ) ) {
2473
+ foreach ( $results as $user_id ) {
2474
+ $md_data = get_user_meta( $user_id, 'um_member_directory_data', true );
2475
+ if ( ! empty( $md_data ) ) {
2476
+ $md_data['hide_in_members'] = ( $_POST['um_options']['account_hide_in_directory_default'] === 'No' ) ? false : true;
2477
+ update_user_meta( $user_id, 'um_member_directory_data', $md_data );
2478
+ }
2479
+ }
2480
+ }
2481
+
2482
+ }
2483
+ }
2484
+ }
2485
+
2486
+
2487
+ /**
2488
+ *
2489
+ */
2490
+ function before_licenses_save() {
2491
+ if ( empty( $_POST['um_options'] ) || empty( $_POST['licenses_settings'] ) ) {
2492
+ return;
2493
+ }
2494
+
2495
+ foreach ( $_POST['um_options'] as $key => $value ) {
2496
+ $this->previous_licenses[ sanitize_key( $key ) ] = UM()->options()->get( $key );
2497
+ }
2498
+ }
2499
+
2500
+
2501
+ /**
2502
+ *
2503
+ */
2504
+ function licenses_save() {
2505
+ if ( empty( $_POST['um_options'] ) || empty( $_POST['licenses_settings'] ) ) {
2506
+ return;
2507
+ }
2508
+
2509
+ foreach ( $_POST['um_options'] as $key => $value ) {
2510
+ $key = sanitize_key( $key );
2511
+ $value = sanitize_text_field( $value );
2512
+
2513
+ $edd_action = '';
2514
+ $license_key = '';
2515
+ if ( empty( $this->previous_licenses[ $key ] ) && ! empty( $value ) || ( ! empty( $this->previous_licenses[ $key ] ) && ! empty( $value ) && $this->previous_licenses[ $key ] != $value ) ) {
2516
+ $edd_action = 'activate_license';
2517
+ $license_key = $value;
2518
+ } elseif ( ! empty( $this->previous_licenses[ $key ] ) && empty( $value ) ) {
2519
+ $edd_action = 'deactivate_license';
2520
+ $license_key = $this->previous_licenses[ $key ];
2521
+ } elseif ( ! empty( $this->previous_licenses[ $key ] ) && ! empty( $value ) ) {
2522
+ $edd_action = 'check_license';
2523
+ $license_key = $value;
2524
+ }
2525
+
2526
+ if ( empty( $edd_action ) ) {
2527
+ continue;
2528
+ }
2529
+
2530
+ $item_name = false;
2531
+ $version = false;
2532
+ $author = false;
2533
+ foreach ( $this->settings_structure['licenses']['fields'] as $field_data ) {
2534
+ if ( $field_data['id'] == $key ) {
2535
+ $item_name = ! empty( $field_data['item_name'] ) ? $field_data['item_name'] : false;
2536
+ $version = ! empty( $field_data['version'] ) ? $field_data['version'] : false;
2537
+ $author = ! empty( $field_data['author'] ) ? $field_data['author'] : false;
2538
+ }
2539
+ }
2540
+
2541
+ $api_params = array(
2542
+ 'edd_action' => $edd_action,
2543
+ 'license' => $license_key,
2544
+ 'item_name' => $item_name,
2545
+ 'version' => $version,
2546
+ 'author' => $author,
2547
+ 'url' => home_url(),
2548
+ );
2549
+
2550
+ $request = wp_remote_post(
2551
+ UM()->store_url,
2552
+ array(
2553
+ 'timeout' => UM()->request_timeout,
2554
+ 'sslverify' => false,
2555
+ 'body' => $api_params
2556
+ )
2557
+ );
2558
+
2559
+ if ( ! is_wp_error( $request ) ) {
2560
+ $request = json_decode( wp_remote_retrieve_body( $request ) );
2561
+ } else {
2562
+ $request = wp_remote_post(
2563
+ UM()->store_url,
2564
+ array(
2565
+ 'timeout' => UM()->request_timeout,
2566
+ 'sslverify' => true,
2567
+ 'body' => $api_params
2568
+ )
2569
+ );
2570
+
2571
+ if ( ! is_wp_error( $request ) ) {
2572
+ $request = json_decode( wp_remote_retrieve_body( $request ) );
2573
+ }
2574
+ }
2575
+
2576
+ $request = ( $request ) ? maybe_unserialize( $request ) : false;
2577
+
2578
+ if ( $edd_action == 'activate_license' || $edd_action == 'check_license' ) {
2579
+ update_option( "{$key}_edd_answer", $request );
2580
+ } else {
2581
+ delete_option( "{$key}_edd_answer" );
2582
+ }
2583
+
2584
+ }
2585
+ }
2586
+
2587
+
2588
+ /**
2589
+ *
2590
+ */
2591
+ function settings_before_email_tab() {
2592
+ $email_key = empty( $_GET['email'] ) ? '' : sanitize_key( $_GET['email'] );
2593
+ $emails = UM()->config()->email_notifications;
2594
+
2595
+ if ( empty( $email_key ) || empty( $emails[ $email_key ] ) ) {
2596
+ include_once um_path . 'includes/admin/core/list-tables/emails-list-table.php';
2597
+ }
2598
+ }
2599
+
2600
+
2601
+ /**
2602
+ * @param $section
2603
+ *
2604
+ * @return string
2605
+ */
2606
+ function settings_email_tab( $section ) {
2607
+ $email_key = empty( $_GET['email'] ) ? '' : sanitize_key( $_GET['email'] );
2608
+ $emails = UM()->config()->email_notifications;
2609
+
2610
+ if ( empty( $email_key ) || empty( $emails[ $email_key ] ) ) {
2611
+ return $section;
2612
+ }
2613
+
2614
+ $in_theme = UM()->mail()->template_in_theme( $email_key );
2615
+
2616
+ /**
2617
+ * UM hook
2618
+ *
2619
+ * @type filter
2620
+ * @title um_admin_settings_email_section_fields
2621
+ * @description Extend UM Email Settings
2622
+ * @input_vars
2623
+ * [{"var":"$settings","type":"array","desc":"UM Email Settings"},
2624
+ * {"var":"$email_key","type":"string","desc":"Email Key"}]
2625
+ * @change_log
2626
+ * ["Since: 2.0"]
2627
+ * @usage add_filter( 'um_admin_settings_email_section_fields', 'function_name', 10, 2 );
2628
+ * @example
2629
+ * <?php
2630
+ * add_filter( 'um_admin_settings_email_section_fields', 'my_admin_settings_email_section', 10, 2 );
2631
+ * function my_admin_settings_email_section( $settings, $email_key ) {
2632
+ * // your code here
2633
+ * return $settings;
2634
+ * }
2635
+ * ?>
2636
+ */
2637
+ $section_fields = apply_filters( 'um_admin_settings_email_section_fields', array(
2638
+ array(
2639
+ 'id' => 'um_email_template',
2640
+ 'type' => 'hidden',
2641
+ 'value' => $email_key,
2642
+ ),
2643
+ array(
2644
+ 'id' => $email_key . '_on',
2645
+ 'type' => 'checkbox',
2646
+ 'label' => $emails[ $email_key ]['title'],
2647
+ 'tooltip' => $emails[ $email_key ]['description'],
2648
+ ),
2649
+ array(
2650
+ 'id' => $email_key . '_sub',
2651
+ 'type' => 'text',
2652
+ 'label' => __( 'Subject Line', 'ultimate-member' ),
2653
+ 'conditional' => array( $email_key . '_on', '=', 1 ),
2654
+ 'tooltip' => __( 'This is the subject line of the e-mail', 'ultimate-member' ),
2655
+ ),
2656
+ array(
2657
+ 'id' => $email_key,
2658
+ 'type' => 'email_template',
2659
+ 'label' => __( 'Message Body', 'ultimate-member' ),
2660
+ 'conditional' => array( $email_key . '_on', '=', 1 ),
2661
+ 'tooltip' => __( 'This is the content of the e-mail', 'ultimate-member' ),
2662
+ 'value' => UM()->mail()->get_email_template( $email_key ),
2663
+ 'in_theme' => $in_theme
2664
+ ),
2665
+ ), $email_key );
2666
+
2667
+ return $this->render_settings_section( $section_fields, 'email', $email_key );
2668
+ }
2669
+
2670
+
2671
+ /**
2672
+ *
2673
+ */
2674
+ function settings_appearance_profile_tab() {
2675
+ wp_enqueue_media();
2676
+ }
2677
+
2678
+
2679
+ /**
2680
+ * @param $html
2681
+ * @param $section_fields
2682
+ *
2683
+ * @return string
2684
+ */
2685
+ function settings_licenses_tab( $html, $section_fields ) {
2686
+ ob_start(); ?>
2687
+
2688
+ <div class="wrap-licenses">
2689
+ <input type="hidden" id="licenses_settings" name="licenses_settings" value="1">
2690
+ <?php $um_settings_nonce = wp_create_nonce( 'um-settings-nonce' ); ?>
2691
+ <input type="hidden" name="__umnonce" value="<?php echo esc_attr( $um_settings_nonce ); ?>" />
2692
+ <table class="form-table um-settings-section">
2693
+ <tbody>
2694
+ <?php foreach ( $section_fields as $field_data ) {
2695
+ $option_value = UM()->options()->get( $field_data['id'] );
2696
+ $value = isset( $option_value ) && ! empty( $option_value ) ? $option_value : ( isset( $field_data['default'] ) ? $field_data['default'] : '' );
2697
+
2698
+ $license = get_option( "{$field_data['id']}_edd_answer" );
2699
+
2700
+ if ( is_object( $license ) && ! empty( $value ) ) {
2701
+ // activate_license 'invalid' on anything other than valid, so if there was an error capture it
2702
+ if ( empty( $license->success ) ) {
2703
+
2704
+ if ( ! empty( $license->error ) ) {
2705
+ switch ( $license->error ) {
2706
+
2707
+ case 'expired' :
2708
+
2709
+ $class = 'expired';
2710
+ $messages[] = sprintf(
2711
+ __( 'Your license key expired on %s. Please <a href="%s" target="_blank">renew your license key</a>.', 'ultimate-member' ),
2712
+ date_i18n( get_option( 'date_format' ), strtotime( $license->expires, current_time( 'timestamp' ) ) ),
2713
+ 'https://ultimatemember.com/checkout/?edd_license_key=' . $value . '&utm_campaign=admin&utm_source=licenses&utm_medium=expired'
2714
+ );
2715
+
2716
+ $license_status = 'license-' . $class . '-notice';
2717
+
2718
+ break;
2719
+
2720
+ case 'revoked' :
2721
+
2722
+ $class = 'error';
2723
+ $messages[] = sprintf(
2724
+ __( 'Your license key has been disabled. Please <a href="%s" target="_blank">contact support</a> for more information.', 'ultimate-member' ),
2725
+ 'https://ultimatemember.com/support?utm_campaign=admin&utm_source=licenses&utm_medium=revoked'
2726
+ );
2727
+
2728
+ $license_status = 'license-' . $class . '-notice';
2729
+
2730
+ break;
2731
+
2732
+ case 'missing' :
2733
+
2734
+ $class = 'error';
2735
+ $messages[] = sprintf(
2736
+ __( 'Invalid license. Please <a href="%s" target="_blank">visit your account page</a> and verify it.', 'ultimate-member' ),
2737
+ 'https://ultimatemember.com/account?utm_campaign=admin&utm_source=licenses&utm_medium=missing'
2738
+ );
2739
+
2740
+ $license_status = 'license-' . $class . '-notice';
2741
+
2742
+ break;
2743
+
2744
+ case 'invalid' :
2745
+ case 'site_inactive' :
2746
+
2747
+ $class = 'error';
2748
+ $messages[] = sprintf(
2749
+ __( 'Your %s is not active for this URL. Please <a href="%s" target="_blank">visit your account page</a> to manage your license key URLs.', 'ultimate-member' ),
2750
+ $field_data['item_name'],
2751
+ 'https://ultimatemember.com/account?utm_campaign=admin&utm_source=licenses&utm_medium=invalid'
2752
+ );
2753
+
2754
+ $license_status = 'license-' . $class . '-notice';
2755
+
2756
+ break;
2757
+
2758
+ case 'item_name_mismatch' :
2759
+
2760
+ $class = 'error';
2761
+ $messages[] = sprintf( __( 'This appears to be an invalid license key for %s.', 'ultimate-member' ), $field_data['item_name'] );
2762
+
2763
+ $license_status = 'license-' . $class . '-notice';
2764
+
2765
+ break;
2766
+
2767
+ case 'no_activations_left':
2768
+
2769
+ $class = 'error';
2770
+ $messages[] = sprintf( __( 'Your license key has reached its activation limit. <a href="%s">View possible upgrades</a> now.', 'ultimate-member' ), 'https://ultimatemember.com/account' );
2771
+
2772
+ $license_status = 'license-' . $class . '-notice';
2773
+
2774
+ break;
2775
+
2776
+ case 'license_not_activable':
2777
+
2778
+ $class = 'error';
2779
+ $messages[] = __( 'The key you entered belongs to a bundle, please use the product specific license key.', 'ultimate-member' );
2780
+
2781
+ $license_status = 'license-' . $class . '-notice';
2782
+ break;
2783
+
2784
+ default :
2785
+
2786
+ $class = 'error';
2787
+ $error = ! empty( $license->error ) ? $license->error : __( 'unknown_error', 'ultimate-member' );
2788
+ $messages[] = sprintf( __( 'There was an error with this license key: %s. Please <a href="%s">contact our support team</a>.', 'ultimate-member' ), $error, 'https://ultimatemember.com/support' );
2789
+
2790
+ $license_status = 'license-' . $class . '-notice';
2791
+ break;
2792
+ }
2793
+ } else {
2794
+ $class = 'error';
2795
+ $error = ! empty( $license->error ) ? $license->error : __( 'unknown_error', 'ultimate-member' );
2796
+ $messages[] = sprintf( __( 'There was an error with this license key: %s. Please <a href="%s">contact our support team</a>.', 'ultimate-member' ), $error, 'https://ultimatemember.com/support' );
2797
+
2798
+ $license_status = 'license-' . $class . '-notice';
2799
+ }
2800
+
2801
+ } elseif ( ! empty( $license->errors ) ) {
2802
+
2803
+ $errors = array_keys( $license->errors );
2804
+ $errors_data = array_values( $license->errors );
2805
+
2806
+ $class = 'error';
2807
+ $error = ! empty( $errors[0] ) ? $errors[0] : __( 'unknown_error', 'ultimate-member' );
2808
+ $errors_data = ! empty( $errors_data[0][0] ) ? ', ' . $errors_data[0][0] : '';
2809
+ $messages[] = sprintf( __( 'There was an error with this license key: %s%s. Please <a href="%s">contact our support team</a>.', 'ultimate-member' ), $error, $errors_data, 'https://ultimatemember.com/support' );
2810
+
2811
+ $license_status = 'license-' . $class . '-notice';
2812
+
2813
+ } else {
2814
+
2815
+ switch( $license->license ) {
2816
+
2817
+ case 'expired' :
2818
+
2819
+ $class = 'expired';
2820
+ $messages[] = sprintf(
2821
+ __( 'Your license key expired on %s. Please <a href="%s" target="_blank">renew your license key</a>.', 'ultimate-member' ),
2822
+ date_i18n( get_option( 'date_format' ), strtotime( $license->expires, current_time( 'timestamp' ) ) ),
2823
+ 'https://ultimatemember.com/checkout/?edd_license_key=' . $value . '&utm_campaign=admin&utm_source=licenses&utm_medium=expired'
2824
+ );
2825
+
2826
+ $license_status = 'license-' . $class . '-notice';
2827
+
2828
+ break;
2829
+
2830
+ case 'revoked' :
2831
+
2832
+ $class = 'error';
2833
+ $messages[] = sprintf(
2834
+ __( 'Your license key has been disabled. Please <a href="%s" target="_blank">contact support</a> for more information.', 'ultimate-member' ),
2835
+ 'https://ultimatemember.com/support?utm_campaign=admin&utm_source=licenses&utm_medium=revoked'
2836
+ );
2837
+
2838
+ $license_status = 'license-' . $class . '-notice';
2839
+
2840
+ break;
2841
+
2842
+ case 'missing' :
2843
+
2844
+ $class = 'error';
2845
+ $messages[] = sprintf(
2846
+ __( 'Invalid license. Please <a href="%s" target="_blank">visit your account page</a> and verify it.', 'ultimate-member' ),
2847
+ 'https://ultimatemember.com/account?utm_campaign=admin&utm_source=licenses&utm_medium=missing'
2848
+ );
2849
+
2850
+ $license_status = 'license-' . $class . '-notice';
2851
+
2852
+ break;
2853
+
2854
+ case 'invalid' :
2855
+ case 'site_inactive' :
2856
+
2857
+ $class = 'error';
2858
+ $messages[] = sprintf(
2859
+ __( 'Your %s is not active for this URL. Please <a href="%s" target="_blank">visit your account page</a> to manage your license key URLs.', 'ultimate-member' ),
2860
+ $field_data['item_name'],
2861
+ 'https://ultimatemember.com/account?utm_campaign=admin&utm_source=licenses&utm_medium=invalid'
2862
+ );
2863
+
2864
+ $license_status = 'license-' . $class . '-notice';
2865
+
2866
+ break;
2867
+
2868
+ case 'item_name_mismatch' :
2869
+
2870
+ $class = 'error';
2871
+ $messages[] = sprintf( __( 'This appears to be an invalid license key for %s.', 'ultimate-member' ), $field_data['item_name'] );
2872
+
2873
+ $license_status = 'license-' . $class . '-notice';
2874
+
2875
+ break;
2876
+
2877
+ case 'no_activations_left':
2878
+
2879
+ $class = 'error';
2880
+ $messages[] = sprintf( __( 'Your license key has reached its activation limit. <a href="%s">View possible upgrades</a> now.', 'ultimate-member' ), 'https://ultimatemember.com/account' );
2881
+
2882
+ $license_status = 'license-' . $class . '-notice';
2883
+
2884
+ break;
2885
+
2886
+ case 'license_not_activable':
2887
+
2888
+ $class = 'error';
2889
+ $messages[] = __( 'The key you entered belongs to a bundle, please use the product specific license key.', 'ultimate-member' );
2890
+
2891
+ $license_status = 'license-' . $class . '-notice';
2892
+ break;
2893
+
2894
+ case 'valid' :
2895
+ default:
2896
+
2897
+ $class = 'valid';
2898
+
2899
+ $now = current_time( 'timestamp' );
2900
+ $expiration = strtotime( $license->expires, $now );
2901
+
2902
+ if( 'lifetime' === $license->expires ) {
2903
+
2904
+ $messages[] = __( 'License key never expires.', 'ultimate-member' );
2905
+
2906
+ $license_status = 'license-lifetime-notice';
2907
+
2908
+ } elseif( $expiration > $now && $expiration - $now < ( DAY_IN_SECONDS * 30 ) ) {
2909
+
2910
+ $messages[] = sprintf(
2911
+ __( 'Your license key expires soon! It expires on %s. <a href="%s" target="_blank">Renew your license key</a>.', 'ultimate-member' ),
2912
+ date_i18n( get_option( 'date_format' ), strtotime( $license->expires, current_time( 'timestamp' ) ) ),
2913
+ 'https://ultimatemember.com/checkout/?edd_license_key=' . $value . '&utm_campaign=admin&utm_source=licenses&utm_medium=renew'
2914
+ );
2915
+
2916
+ $license_status = 'license-expires-soon-notice';
2917
+
2918
+ } else {
2919
+
2920
+ $messages[] = sprintf(
2921
+ __( 'Your license key expires on %s.', 'ultimate-member' ),
2922
+ date_i18n( get_option( 'date_format' ), strtotime( $license->expires, current_time( 'timestamp' ) ) )
2923
+ );
2924
+
2925
+ $license_status = 'license-expiration-date-notice';
2926
+
2927
+ }
2928
+
2929
+ break;
2930
+
2931
+ }
2932
+
2933
+ }
2934
+
2935
+ } else {
2936
+ $class = 'empty';
2937
+
2938
+ $messages[] = sprintf(
2939
+ __( 'To receive updates, please enter your valid %s license key.', 'ultimate-member' ),
2940
+ $field_data['item_name']
2941
+ );
2942
+
2943
+ $license_status = null;
2944
+
2945
+ } ?>
2946
+
2947
+ <tr class="um-settings-line">
2948
+ <th><label for="um_options_<?php echo esc_attr( $field_data['id'] ) ?>"><?php echo esc_html( $field_data['label'] ) ?></label></th>
2949
+ <td>
2950
+ <form method="post" action="" name="um-settings-form" class="um-settings-form">
2951
+ <input type="hidden" value="save" name="um-settings-action" />
2952
+ <input type="hidden" name="licenses_settings" value="1" />
2953
+ <?php $um_settings_nonce = wp_create_nonce( 'um-settings-nonce' ); ?>
2954
+ <input type="hidden" name="__umnonce" value="<?php echo esc_attr( $um_settings_nonce ); ?>" />
2955
+ <input type="text" id="um_options_<?php echo esc_attr( $field_data['id'] ) ?>" name="um_options[<?php echo esc_attr( $field_data['id'] ) ?>]" value="<?php echo $value ?>" class="um-option-field um-long-field" data-field_id="<?php echo esc_attr( $field_data['id'] ) ?>" />
2956
+ <?php if ( ! empty( $field_data['description'] ) ) { ?>
2957
+ <div class="description"><?php echo $field_data['description'] ?></div>
2958
+ <?php } ?>
2959
+
2960
+ <?php if ( ! empty( $value ) && ( ( is_object( $license ) && 'valid' == $license->license ) || 'valid' == $license ) ) { ?>
2961
+ <input type="button" class="button um_license_deactivate" id="<?php echo esc_attr( $field_data['id'] ) ?>_deactivate" value="<?php esc_attr_e( 'Clear License', 'ultimate-member' ) ?>"/>
2962
+ <?php } elseif ( empty( $value ) ) { ?>
2963
+ <input type="submit" name="submit" id="submit" class="button button-primary" value="<?php esc_attr_e( 'Activate', 'ultimate-member' ) ?>" />
2964
+ <?php } else { ?>
2965
+ <input type="submit" name="submit" id="submit" class="button button-primary" value="<?php esc_attr_e( 'Re-Activate', 'ultimate-member' ) ?>" />
2966
+ <input type="button" class="button um_license_deactivate" id="<?php echo esc_attr( $field_data['id'] ) ?>_deactivate" value="<?php esc_attr_e( 'Clear License', 'ultimate-member' ) ?>"/>
2967
+ <?php }
2968
+
2969
+ if ( ! empty( $messages ) ) {
2970
+ foreach ( $messages as $message ) { ?>
2971
+ <div class="edd-license-data edd-license-<?php echo esc_attr( $class . ' ' . $license_status ) ?>">
2972
+ <p><?php echo $message ?></p>
2973
+ </div>
2974
+ <?php }
2975
+ } ?>
2976
+ </form>
2977
+ </td>
2978
+ </tr>
2979
+ <?php } ?>
2980
+ </tbody>
2981
+ </table>
2982
+ </div>
2983
+ <?php $section = ob_get_clean();
2984
+
2985
+ return $section;
2986
+ }
2987
+
2988
+
2989
+ /**
2990
+ * @param $html
2991
+ * @param $section_fields
2992
+ */
2993
+ function settings_install_info_tab( $html, $section_fields ) {
2994
+ global $wpdb;
2995
+
2996
+ if ( ! class_exists( '\Browser' ) )
2997
+ require_once um_path . 'includes/lib/browser.php';
2998
+
2999
+ // Detect browser
3000
+ $browser = new \Browser();
3001
+
3002
+ // Get theme info
3003
+ $theme_data = wp_get_theme();
3004
+ $theme = $theme_data->Name . ' ' . $theme_data->Version;
3005
+
3006
+ // Identify Hosting Provider
3007
+ $host = um_get_host();
3008
+
3009
+ um_fetch_user( get_current_user_id() );
3010
+
3011
+ if ( isset( $this->content ) ) {
3012
+ echo $this->content;
3013
+ } else { ?>
3014
+
3015
+ <h3>Install Info</h3>
3016
+
3017
+ <form action="" method="post" dir="ltr">
3018
+ <textarea style="width:70%; height:400px;" readonly="readonly" onclick="this.focus();this.select()" id="install-info-textarea" name="um-install-info" title="<?php _e( 'To copy the Install info, click below then press Ctrl + C (PC) or Cmd + C (Mac).', 'ultimate-member' ); ?>">
3019
+ ### Begin Install Info ###
3020
+
3021
+ ## Please include this information when posting support requests ##
3022
+
3023
+ <?php
3024
+ /**
3025
+ * UM hook
3026
+ *
3027
+ * @type action
3028
+ * @title um_install_info_before
3029
+ * @description Before install info settings
3030
+ * @change_log
3031
+ * ["Since: 2.0"]
3032
+ * @usage add_action( 'um_install_info_before', 'function_name', 10 );
3033
+ * @example
3034
+ * <?php
3035
+ * add_action( 'um_install_info_before', 'my_install_info_before', 10 );
3036
+ * function my_install_info_before() {
3037
+ * // your code here
3038
+ * }
3039
+ * ?>
3040
+ */
3041
+ do_action( 'um_install_info_before' ); ?>
3042
+
3043
+ --- Site Info ---
3044
+
3045
+ Site URL: <?php echo site_url() . "\n"; ?>
3046
+ Home URL: <?php echo home_url() . "\n"; ?>
3047
+ Multisite: <?php echo is_multisite() ? 'Yes' . "\n" : 'No' . "\n" ?>
3048
+
3049
+ --- Hosting Provider ---
3050
+
3051
+ <?php if( $host ) : ?>
3052
+ Host: <?php echo $host . "\n"; ?>
3053
+ <?php endif; ?>
3054
+
3055
+ --- User Browser ---
3056
+
3057
+ <?php echo $browser ; ?>
3058
+
3059
+ ---- Current User Details --
3060
+
3061
+ <?php $user = wp_get_current_user(); ?>
3062
+ Role: <?php echo implode( ', ', um_user( 'roles' ) ). "\n"; ?>
3063
+
3064
+
3065
+ --- WordPress Configurations ---
3066
+
3067
+ Version: <?php echo get_bloginfo( 'version' ) . "\n"; ?>
3068
+ Language: <?php echo get_locale()."\n"; ?>
3069
+ Permalink Structure: <?php echo get_option( 'permalink_structure' ) . "\n"; ?>
3070
+ Active Theme: <?php echo $theme . "\n"; ?>
3071
+ <?php $show_on_front = get_option( 'show_on_front' ); ?>
3072
+ <?php if( $show_on_front == "posts" ): ?>
3073
+ Show On Front: <?php echo get_option( 'show_on_front' ) . "/static\n" ?>
3074
+ <?php elseif( $show_on_front == "page" ): ?>
3075
+ Page On Front: <?php $id = get_option( 'page_on_front' ); echo get_the_title( $id ) . ' (#' . $id . ')' . "\n" ?>
3076
+ Page For Posts: <?php $id = get_option( 'page_for_posts' ); echo get_the_title( $id ) . ' (#' . $id . ')' . "\n" ?>
3077
+ <?php endif; ?>
3078
+ ABSPATH: <?php echo ABSPATH."\n"; ?>
3079
+ <?php $wp_count_posts = wp_count_posts(); ?>
3080
+ All Posts/Pages: <?php echo array_sum((array)$wp_count_posts)."\n";?>
3081
+ <?php
3082
+ $request['cmd'] = '_notify-validate';
3083
+
3084
+ $params = array(
3085
+ 'sslverify' => false,
3086
+ 'timeout' => 60,
3087
+ 'user-agent' => 'UltimateMember/' . ultimatemember_version,
3088
+ 'body' => $request
3089
+ );
3090
+
3091
+ $response = wp_remote_post( 'https://www.paypal.com/cgi-bin/webscr', $params );
3092
+
3093
+ if ( ! is_wp_error( $response ) && $response['response']['code'] >= 200 && $response['response']['code'] < 300 ) {
3094
+ $WP_REMOTE_POST = 'wp_remote_post() works' . "\n";
3095
+ } else {
3096
+ $WP_REMOTE_POST = 'wp_remote_post() does not work' . "\n";
3097
+ }
3098
+ ?>
3099
+ WP Remote Post: <?php echo $WP_REMOTE_POST; ?>
3100
+ WP_DEBUG: <?php echo defined( 'WP_DEBUG' ) ? WP_DEBUG ? 'Enabled' . "\n" : 'Disabled' . "\n" : 'Not set' . "\n" ?>
3101
+ WP Table Prefix: <?php echo "Length: ". strlen( $wpdb->prefix ); echo ", Status:"; if ( strlen( $wpdb->prefix )>16 ) {echo " ERROR: Too Long";} else {echo " Acceptable";} echo "\n"; ?>
3102
+ Memory Limit: <?php echo ( um_let_to_num( WP_MEMORY_LIMIT )/( 1024 ) )."MB"; ?><?php echo "\n"; ?>
3103
+
3104
+
3105
+ --- UM Configurations ---
3106
+
3107
+ Version: <?php echo ultimatemember_version . "\n"; ?>
3108
+ Upgraded From: <?php echo get_option( 'um_last_version_upgrade', 'None' ) . "\n"; ?>
3109
+ Current URL Method: <?php echo UM()->options()->get( 'current_url_method' ). "\n"; ?>
3110
+ Cache User Profile: <?php if( UM()->options()->get( 'um_profile_object_cache_stop' ) == 1 ){ echo "No"; }else{ echo "Yes"; } echo "\n"; ?>
3111
+ Generate Slugs on Directories: <?php if( UM()->options()->get( 'um_generate_slug_in_directory' ) == 1 ){ echo "No"; }else{ echo "Yes"; } echo "\n"; ?>
3112
+ Force UTF-8 Encoding: <?php if( UM()->options()->get( 'um_force_utf8_strings' ) == 1 ){ echo "Yes"; }else{ echo "No"; } echo "\n"; ?>
3113
+ JS/CSS Compression: <?php if ( defined('SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) { echo "Yes"; }else{ echo "No"; } echo "\n"; ?>
3114
+ <?php if( is_multisite() ): ?>
3115
+ Network Structure: <?php echo UM()->options()->get( 'network_permalink_structure' ). "\n"; ?>
3116
+ <?php endif; ?>
3117
+ Port Forwarding in URL: <?php if( UM()->options()->get( 'um_port_forwarding_url' ) == 1 ){ echo "Yes"; }else{ echo "No"; } echo "\n"; ?>
3118
+ Exclude CSS/JS on Home: <?php if( UM()->options()->get( 'js_css_exlcude_home' ) == 1 ){ echo "Yes"; }else{ echo "No"; } echo "\n"; ?>
3119
+
3120
+
3121
+ --- UM Pages Configuration ---
3122
+
3123
+ <?php
3124
+ /**
3125
+ * UM hook
3126
+ *
3127
+ * @type action
3128
+ * @title um_install_info_before_page_config
3129
+ * @description Before page config install info
3130
+ * @change_log
3131
+ * ["Since: 2.0"]
3132
+ * @usage add_action( 'um_install_info_before_page_config', 'function_name', 10 );
3133
+ * @example
3134
+ * <?php
3135
+ * add_action( 'um_install_info_before_page_config', 'my_install_info_before_page_config', 10 );
3136
+ * function my_install_info_before_page_config() {
3137
+ * // your code here
3138
+ * }
3139
+ * ?>
3140
+ */
3141
+ do_action( "um_install_info_before_page_config" ); ?>
3142
+ User: <?php echo get_permalink( UM()->options()->get('core_user') ) . "\n"; ?>
3143
+ Account: <?php echo get_permalink( UM()->options()->get('core_account') ) . "\n"; ?>
3144
+ Members: <?php echo get_permalink( UM()->options()->get('core_members') ) . "\n"; ?>
3145
+ Register: <?php echo get_permalink( UM()->options()->get('core_register') ) . "\n"; ?>
3146
+ Login: <?php echo get_permalink( UM()->options()->get('core_login') ) . "\n"; ?>
3147
+ Logout: <?php echo get_permalink( UM()->options()->get('core_logout') ) . "\n"; ?>
3148
+ Password Reset: <?php echo get_permalink( UM()->options()->get('core_password-reset') ) . "\n"; ?>
3149
+ <?php
3150
+ /**
3151
+ * UM hook
3152
+ *
3153
+ * @type action
3154
+ * @title um_install_info_after_page_config
3155
+ * @description After page config install info
3156
+ * @change_log
3157
+ * ["Since: 2.0"]
3158
+ * @usage add_action( 'um_install_info_after_page_config', 'function_name', 10 );
3159
+ * @example
3160
+ * <?php
3161
+ * add_action( 'um_install_info_after_page_config', 'my_install_info_after_page_config', 10 );
3162
+ * function my_install_info_after_page_config() {
3163
+ * // your code here
3164
+ * }
3165
+ * ?>
3166
+ */
3167
+ do_action( "um_install_info_after_page_config" ); ?>
3168
+
3169
+
3170
+ --- UM Users Configuration ---
3171
+
3172
+ Default New User Role: <?php echo UM()->options()->get('register_role') . "\n"; ?>
3173
+ Profile Permalink Base: <?php echo UM()->options()->get('permalink_base') . "\n"; ?>
3174
+ User Display Name: <?php echo UM()->options()->get('display_name') . "\n"; ?>
3175
+ Redirect author to profile: <?php echo $this->info_value( UM()->options()->get('author_redirect'), 'yesno', true ); ?>
3176
+ Enable Members Directory: <?php echo $this->info_value( UM()->options()->get('members_page'), 'yesno', true ); ?>
3177
+ Use Gravatars: <?php echo $this->info_value( UM()->options()->get('use_gravatars'), 'yesno', true ); ?>
3178
+ <?php if( UM()->options()->get('use_gravatars') ): ?>Gravatar builtin image: <?php echo UM()->options()->get('use_um_gravatar_default_builtin_image') . "\n"; ?>
3179
+ UM Avatar as blank Gravatar: <?php echo $this->info_value( UM()->options()->get('use_um_gravatar_default_image'), 'yesno', true ); ?><?php endif; ?>
3180
+ Require a strong password: <?php echo $this->info_value( UM()->options()->get('require_strongpass'), 'onoff', true ); ?>
3181
+
3182
+
3183
+ --- UM Access Configuration ---
3184
+
3185
+ Panic Key: <?php echo UM()->options()->get('panic_key') . "\n"; ?>
3186
+ Global Site Access: <?php $arr = array('Site accessible to Everyone','','Site accessible to Logged In Users'); echo $arr[ (int) UM()->options()->get('accessible') ] . "\n"; ?>
3187
+ <?php if( UM()->options()->get('accessible') == 2 ) { ?>
3188
+ Custom Redirect URL: <?php echo UM()->options()->get('access_redirect')."\n";?>
3189
+ Exclude the following URLs:<?php echo "\t\t\t\t".implode("\t\n\t\t\t\t\t\t\t\t\t\t",UM()->options()->get('access_exclude_uris') )."\n";?>
3190
+ <?php } ?>
3191
+ Backend Login Screen for Guests: <?php echo $this->info_value( UM()->options()->get('wpadmin_login'), 'yesno', true ); ?>
3192
+ <?php if( ! UM()->options()->get('wpadmin_login') ) { ?>
3193
+ Redirect to alternative login page: <?php if( UM()->options()->get('wpadmin_login_redirect') == 'um_login_page' ){ echo um_get_core_page('login')."\n"; }else{ echo UM()->options()->get('wpadmin_login_redirect_url')."\n"; }?>
3194
+ <?php } ?>
3195
+ Backend Register Screen for Guests: <?php echo $this->info_value( UM()->options()->get('wpadmin_register'), 'yesno', true ); ?>
3196
+ <?php if( ! UM()->options()->get('wpadmin_register') ) { ?>
3197
+ Redirect to alternative register page: <?php if( UM()->options()->get('wpadmin_register_redirect') == 'um_register_page' ){ echo um_get_core_page('register')."\n"; }else{ echo UM()->options()->get('wpadmin_register_redirect_url')."\n"; }?>
3198
+ <?php } ?>
3199
+ Access Control widget for Admins only: <?php echo $this->info_value( UM()->options()->get('access_widget_admin_only'), 'yesno', true ); ?>
3200
+ Enable the Reset Password Limit: <?php echo $this->info_value( UM()->options()->get('enable_reset_password_limit'), 'yesno', true ); ?>
3201
+ <?php if( UM()->options()->get('enable_reset_password_limit') ) { ?>
3202
+ Reset Password Limit: <?php echo UM()->options()->get('reset_password_limit_number') ?>
3203
+ Disable Reset Password Limit for Admins: <?php echo $this->info_value( UM()->options()->get('disable_admin_reset_password_limit'), 'yesno', true ) ?>
3204
+ <?php } ?>
3205
+ <?php $blocked_ips = UM()->options()->get('blocked_ips'); if( ! empty( $blocked_ips ) ){ ?>
3206
+ Blocked IP Addresses: <?php echo count( explode("\n",UM()->options()->get('blocked_ips') ) )."\n"; ?>
3207
+ <?php } ?>
3208
+ <?php $blocked_emails = UM()->options()->get('blocked_emails'); if( ! empty( $blocked_emails ) ){ ?>
3209
+ Blocked Email Addresses: <?php echo count( explode("\n",UM()->options()->get('blocked_emails') ) )."\n"; ?>
3210
+ <?php } ?>
3211
+ <?php $blocked_words = UM()->options()->get('blocked_words'); if( ! empty( $blocked_words ) ){ ?>
3212
+ Blacklist Words: <?php echo count( explode("\n",UM()->options()->get('blocked_words') ) )."\n"; ?>
3213
+ <?php } ?>
3214
+
3215
+
3216
+ --- UM Email Configurations ---
3217
+
3218
+ Mail appears from: <?php $mail_from = UM()->options()->get('mail_from'); if( ! empty( $mail_from ) ){echo UM()->options()->get('mail_from');}else{echo "-";}; echo "\n";?>
3219
+ Mail appears from address: <?php $mail_from_addr = UM()->options()->get('mail_from_addr'); if( ! empty( $mail_from_addr ) ){echo UM()->options()->get('mail_from_addr');}else{echo "-";}; echo "\n";?>
3220
+ Use HTML for E-mails: <?php echo $this->info_value( UM()->options()->get('email_html'), 'yesno', true ); ?>
3221
+ Account Welcome Email: <?php echo $this->info_value( UM()->options()->get('welcome_email_on'), 'yesno', true ); ?>
3222
+ Account Activation Email: <?php echo $this->info_value( UM()->options()->get('checkmail_email_on'), 'yesno', true ); ?>
3223
+ Pending Review Email: <?php echo $this->info_value( UM()->options()->get('pending_email_on'), 'yesno', true ); ?>
3224
+ Account Approved Email: <?php echo $this->info_value( UM()->options()->get('approved_email_on'), 'yesno', true ); ?>
3225
+ Account Rejected Email: <?php echo $this->info_value( UM()->options()->get('rejected_email_on'), 'yesno', true ); ?>
3226
+ Account Deactivated Email: <?php echo $this->info_value( UM()->options()->get('inactive_email_on'), 'yesno', true ); ?>
3227
+ Account Deleted Email: <?php echo $this->info_value( UM()->options()->get('deletion_email_on'), 'yesno', true ); ?>
3228
+ Password Reset Email: <?php echo $this->info_value( UM()->options()->get('resetpw_email_on'), 'yesno', true ); ?>
3229
+ Password Changed Email: <?php echo $this->info_value( UM()->options()->get('changedpw_email_on'), 'yesno', true ); ?>
3230
+
3231
+
3232
+ --- UM Total Users ---
3233
+
3234
+ <?php $result = count_users();
3235
+ echo 'All Users('.$result['total_users'].")\n";
3236
+ foreach( $result['avail_roles'] as $role => $count ) {
3237
+ echo $role."(".$count.")\n";
3238
+ } ?>
3239
+
3240
+
3241
+ --- UM Roles ---
3242
+
3243
+ <?php foreach( UM()->roles()->get_roles() as $role_id => $role ) {
3244
+ echo $role." ({$role_id})\n";
3245
+ } ?>
3246
+
3247
+
3248
+ --- UM Custom Templates ---
3249
+
3250
+ <?php // Show templates that have been copied to the theme's edd_templates dir
3251
+ $dir = get_stylesheet_directory() . '/ultimate-member/templates/*.php';
3252
+ if ( ! empty( $dir ) ) {
3253
+ $found = glob( $dir );
3254
+ if ( ! empty( $found ) ) {
3255
+ foreach ( glob( $dir ) as $file ) {
3256
+ echo "File: " . $file . "\n";
3257
+ }
3258
+ } else {
3259
+ echo 'N/A'."\n";
3260
+ }
3261
+ } ?>
3262
+
3263
+
3264
+ --- UM Email HTML Templates ---
3265
+
3266
+ <?php $dir = get_stylesheet_directory() . '/ultimate-member/templates/emails/*.html';
3267
+
3268
+ if ( ! empty( $dir ) ) {
3269
+ $found = glob( $dir );
3270
+ if ( ! empty( $found ) ){
3271
+ foreach ( glob( $dir ) as $file ) {
3272
+ echo "File: ". $file . "\n";
3273
+ }
3274
+ } else {
3275
+ echo 'N/A'."\n";
3276
+ }
3277
+ } ?>
3278
+
3279
+
3280
+ --- Web Server Configurations ---
3281
+
3282
+ PHP Version: <?php echo PHP_VERSION . "\n"; ?>
3283
+ MySQL Version: <?php echo $wpdb->db_version() . "\n"; ?>
3284
+ Web Server Info: <?php echo $_SERVER['SERVER_SOFTWARE'] . "\n"; ?>
3285
+
3286
+
3287
+ --- PHP Configurations ---
3288
+
3289
+ PHP Memory Limit: <?php echo ini_get( 'memory_limit' ) . "\n"; ?>
3290
+ PHP Upload Max Size: <?php echo ini_get( 'upload_max_filesize' ) . "\n"; ?>
3291
+ PHP Post Max Size: <?php echo ini_get( 'post_max_size' ) . "\n"; ?>
3292
+ PHP Upload Max Filesize: <?php echo ini_get( 'upload_max_filesize' ) . "\n"; ?>
3293
+ PHP Time Limit: <?php echo ini_get( 'max_execution_time' ) . "\n"; ?>
3294
+ PHP Max Input Vars: <?php echo ini_get( 'max_input_vars' ) . "\n"; ?>
3295
+ PHP Arg Separator: <?php echo ini_get( 'arg_separator.output' ) . "\n"; ?>
3296
+ PHP Allow URL File Open: <?php echo ini_get( 'allow_url_fopen' ) ? "Yes\n" : "No\n"; ?>
3297
+
3298
+
3299
+ --- Web Server Extensions/Modules ---
3300
+
3301
+ DISPLAY ERRORS: <?php echo ( ini_get( 'display_errors' ) ) ? 'On (' . ini_get( 'display_errors' ) . ')' : 'N/A'; ?><?php echo "\n"; ?>
3302
+ FSOCKOPEN: <?php echo ( function_exists( 'fsockopen' ) ) ? 'Your server supports fsockopen.' : 'Your server does not support fsockopen.'; ?><?php echo "\n"; ?>
3303
+ cURL: <?php echo ( function_exists( 'curl_init' ) ) ? 'Your server supports cURL.' : 'Your server does not support cURL.'; ?><?php echo "\n"; ?>
3304
+ SOAP Client: <?php echo ( class_exists( 'SoapClient' ) ) ? 'Your server has the SOAP Client enabled.' : 'Your server does not have the SOAP Client enabled.'; ?><?php echo "\n"; ?>
3305
+ SUHOSIN: <?php echo ( extension_loaded( 'suhosin' ) ) ? 'Your server has SUHOSIN installed.' : 'Your server does not have SUHOSIN installed.'; ?><?php echo "\n"; ?>
3306
+ GD Library: <?php echo ( extension_loaded( 'gd' ) && function_exists('gd_info') ) ? 'PHP GD library is installed on your web server.' : 'PHP GD library is NOT installed on your web server.'; ?><?php echo "\n"; ?>
3307
+ Mail: <?php echo ( function_exists('mail') ) ? 'PHP mail function exist on your web server.' : 'PHP mail function doesn\'t exist on your web server.'; ?><?php echo "\n"; ?>
3308
+ Exif: <?php echo ( extension_loaded( 'exif' ) && function_exists('exif_imagetype') ) ? 'PHP Exif library is installed on your web server.' : 'PHP Exif library is NOT installed on your web server.'; ?><?php echo "\n"; ?>
3309
+
3310
+
3311
+ --- Session Configurations ---
3312
+
3313
+ Session: <?php echo isset( $_SESSION ) ? 'Enabled' : 'Disabled'; ?><?php echo "\n"; ?>
3314
+ Session Name: <?php echo esc_html( ini_get( 'session.name' ) ); ?><?php echo "\n"; ?>
3315
+ Cookie Path: <?php echo esc_html( ini_get( 'session.cookie_path' ) ); ?><?php echo "\n"; ?>
3316
+ Save Path: <?php echo esc_html( ini_get( 'session.save_path' ) ); ?><?php echo "\n"; ?>
3317
+ Use Cookies: <?php echo ini_get( 'session.use_cookies' ) ? 'On' : 'Off'; ?><?php echo "\n"; ?>
3318
+ Use Only Cookies: <?php echo ini_get( 'session.use_only_cookies' ) ? 'On' : 'Off'; ?><?php echo "\n"; ?>
3319
+
3320
+
3321
+ --- WordPress Active Plugins ---
3322
+
3323
+ <?php $plugins = get_plugins();
3324
+ $active_plugins = get_option( 'active_plugins', array() );
3325
+
3326
+ foreach ( $plugins as $plugin_path => $plugin ) {
3327
+ // If the plugin isn't active, don't show it.
3328
+ if ( ! in_array( $plugin_path, $active_plugins ) )
3329
+ continue;
3330
+
3331
+ echo $plugin['Name'] . ': ' . $plugin['Version'] ."\n";
3332
+ }
3333
+
3334
+ if ( is_multisite() ) { ?>
3335
+
3336
+ --- WordPress Network Active Plugins ---
3337
+
3338
+ <?php $plugins = wp_get_active_network_plugins();
3339
+ $active_plugins = get_site_option( 'active_sitewide_plugins', array() );
3340
+
3341
+ foreach ( $plugins as $plugin_path ) {
3342
+ $plugin_base = plugin_basename( $plugin_path );
3343
+
3344
+ // If the plugin isn't active, don't show it.
3345
+ if ( ! array_key_exists( $plugin_base, $active_plugins ) )
3346
+ continue;
3347
+
3348
+ $plugin = get_plugin_data( $plugin_path );
3349
+
3350
+ echo $plugin['Name'] . ' :' . $plugin['Version'] . "\n";
3351
+ }
3352
+
3353
+ }
3354
+
3355
+ /**
3356
+ * UM hook
3357
+ *
3358
+ * @type action
3359
+ * @title um_install_info_after
3360
+ * @description After install info
3361
+ * @change_log
3362
+ * ["Since: 2.0"]
3363
+ * @usage add_action( 'um_install_info_after', 'function_name', 10 );
3364
+ * @example
3365
+ * <?php
3366
+ * add_action( 'um_install_info_after', 'my_install_info_after', 10 );
3367
+ * function my_install_info_after() {
3368
+ * // your code here
3369
+ * }
3370
+ * ?>
3371
+ */
3372
+ do_action( 'um_install_info_after' ); ?>
3373
+
3374
+ ### End Install Info ###
3375
+ </textarea>
3376
+ <p class="submit">
3377
+ <input type="hidden" name="um-addon-hook" value="download_install_info" />
3378
+ <?php submit_button( 'Download Install Info File', 'primary', 'download_install_info', false ); ?>
3379
+ </p>
3380
+ </form>
3381
+
3382
+ <?php }
3383
+ }
3384
+
3385
+
3386
+ /**
3387
+ *
3388
+ */
3389
+ function um_download_install_info() {
3390
+ if ( ! empty( $_POST['download_install_info'] ) ) {
3391
+ nocache_headers();
3392
+
3393
+ header( "Content-type: text/plain" );
3394
+ header( 'Content-Disposition: attachment; filename="ultimatemember-install-info.txt"' );
3395
+
3396
+ echo wp_strip_all_tags( sanitize_textarea_field( $_POST['um-install-info'] ) );
3397
+ exit;
3398
+ }
3399
+ }
3400
+
3401
+
3402
+ /**
3403
+ * @param string $raw_value
3404
+ * @param string $type
3405
+ * @param string $default
3406
+ *
3407
+ * @return string
3408
+ */
3409
+ function info_value( $raw_value = '', $type = 'yesno', $default = '' ) {
3410
+
3411
+ if ( $type == 'yesno' ) {
3412
+ $raw_value = ( $default == $raw_value ) ? "Yes" : "No";
3413
+ } elseif( $type == 'onoff' ) {
3414
+ $raw_value = ( $default == $raw_value ) ? "On" : "Off";
3415
+ }
3416
+
3417
+ return $raw_value."\n";
3418
+ }
3419
+
3420
+
3421
+ /**
3422
+ * Render settings section
3423
+ *
3424
+ * @param array $section_fields
3425
+ * @param string $current_tab
3426
+ * @param string $current_subtab
3427
+ *
3428
+ * @return string
3429
+ */
3430
+ function render_settings_section( $section_fields, $current_tab, $current_subtab ) {
3431
+ ob_start();
3432
+
3433
+ UM()->admin_forms_settings( array(
3434
+ 'class' => 'um_options-' . $current_tab . '-' . $current_subtab . ' um-third-column',
3435
+ 'prefix_id' => 'um_options',
3436
+ 'fields' => $section_fields
3437
+ ) )->render_form(); ?>
3438
+
3439
+ <?php $section = ob_get_clean();
3440
+
3441
+ return $section;
3442
+ }
3443
+
3444
+
3445
+ /**
3446
+ * @param array $settings
3447
+ *
3448
+ * @return array
3449
+ */
3450
+ function save_email_templates( $settings ) {
3451
+
3452
+ if ( empty( $settings['um_email_template'] ) ) {
3453
+ return $settings;
3454
+ }
3455
+
3456
+ $template = $settings['um_email_template'];
3457
+ $content = wp_kses_post( stripslashes( $settings[ $template ] ) );
3458
+
3459
+ $theme_template_path = UM()->mail()->get_template_file( 'theme', $template );
3460
+
3461
+ if ( ! file_exists( $theme_template_path ) ) {
3462
+ UM()->mail()->copy_email_template( $template );
3463
+ }
3464
+
3465
+ $fp = fopen( $theme_template_path, "w" );
3466
+ $result = fputs( $fp, $content );
3467
+ fclose( $fp );
3468
+
3469
+ if ( $result !== false ) {
3470
+ unset( $settings['um_email_template'] );
3471
+ unset( $settings[ $template ] );
3472
+ }
3473
+
3474
+ return $settings;
3475
+ }
3476
+ }
3477
+ }
 
includes/admin/core/class-admin-upgrade.php CHANGED
@@ -356,10 +356,20 @@ if ( ! class_exists( 'um\admin\core\Admin_Upgrade' ) ) {
356
  if ( empty( $_POST['pack'] ) ) {
357
  exit('');
358
  } else {
359
- ob_start();
360
- include_once $this->packages_dir . sanitize_text_field( $_POST['pack'] ) . DIRECTORY_SEPARATOR . 'init.php';
361
- ob_get_flush();
362
- exit;
 
 
 
 
 
 
 
 
 
 
363
  }
364
  }
365
 
@@ -407,4 +417,4 @@ if ( ! class_exists( 'um\admin\core\Admin_Upgrade' ) ) {
407
  }
408
 
409
  }
410
- }
356
  if ( empty( $_POST['pack'] ) ) {
357
  exit('');
358
  } else {
359
+ $pack = sanitize_text_field( $_POST['pack'] );
360
+ if ( in_array( $pack, $this->necessary_packages, true ) ) {
361
+ $file = $this->packages_dir . $pack . DIRECTORY_SEPARATOR . 'init.php';
362
+ if ( file_exists( $file ) ) {
363
+ ob_start();
364
+ include_once $file;
365
+ ob_get_flush();
366
+ exit;
367
+ } else {
368
+ exit('');
369
+ }
370
+ } else {
371
+ exit('');
372
+ }
373
  }
374
  }
375
 
417
  }
418
 
419
  }
420
+ }
includes/core/class-access.php CHANGED
@@ -1,2136 +1,2141 @@
1
- <?php
2
- namespace um\core;
3
-
4
- // Exit if accessed directly
5
- if ( ! defined( 'ABSPATH' ) ) exit;
6
-
7
- if ( ! class_exists( 'um\core\Access' ) ) {
8
-
9
-
10
- /**
11
- * Class Access
12
- * @package um\core
13
- */
14
- class Access {
15
-
16
-
17
- /**
18
- * If true then we use individual restrict content options
19
- * for post
20
- *
21
- * @var bool
22
- */
23
- private $singular_page;
24
-
25
-
26
- /**
27
- * @var bool
28
- */
29
- private $redirect_handler;
30
-
31
-
32
- /**
33
- * @var bool
34
- */
35
- private $allow_access;
36
-
37
-
38
- private $ignore_exclude = false;
39
-
40
-
41
- /**
42
- * Access constructor.
43
- */
44
- function __construct() {
45
- $this->singular_page = false;
46
-
47
- $this->redirect_handler = false;
48
- $this->allow_access = false;
49
-
50
- // NEW HOOKS
51
-
52
- // Change recent posts widget query
53
- add_filter( 'widget_posts_args', array( &$this, 'exclude_restricted_posts_widget' ), 99, 1 );
54
- // Exclude pages displayed by wp_list_pages function
55
- add_filter( 'wp_list_pages_excludes', array( &$this, 'exclude_restricted_pages' ), 10, 1 );
56
- // Archives list change where based on restricted posts
57
- add_filter( 'getarchives_where', array( &$this, 'exclude_restricted_posts_archives_widget' ), 99, 2 );
58
-
59
- // Navigation line below the post content, change query to exclude restricted
60
- add_filter( 'get_next_post_where', array( &$this, 'exclude_navigation_posts' ), 99, 5 );
61
- add_filter( 'get_previous_post_where', array( &$this, 'exclude_navigation_posts' ), 99, 5 );
62
-
63
- // callbacks for changing posts query
64
- add_action( 'pre_get_posts', array( &$this, 'exclude_posts' ), 99, 1 );
65
- add_filter( 'posts_where', array( &$this, 'exclude_posts_where' ), 10, 2 );
66
- add_filter( 'wp_count_posts', array( &$this, 'custom_count_posts_handler' ), 99, 3 );
67
-
68
- // change the title of the post
69
- add_filter( 'the_title', array( &$this, 'filter_restricted_post_title' ), 10, 2 );
70
- // change the content of the restricted post
71
- add_filter( 'the_content', array( &$this, 'filter_restricted_post_content' ), 999999, 1 );
72
- // change the excerpt of the restricted post
73
- add_filter( 'get_the_excerpt', array( &$this, 'filter_restricted_post_excerpt' ), 999999, 2 );
74
-
75
- // filter attachment
76
- add_filter( 'wp_get_attachment_url', array( &$this, 'filter_attachment' ), 99, 2 );
77
- add_filter( 'has_post_thumbnail', array( &$this, 'filter_post_thumbnail' ), 99, 3 );
78
-
79
- // comments queries
80
- add_action( 'pre_get_comments', array( &$this, 'exclude_posts_comments' ), 99, 1 );
81
- add_filter( 'wp_count_comments', array( &$this, 'custom_comments_count_handler' ), 99, 2 );
82
- // comments RSS
83
- add_filter( 'comment_feed_where', array( &$this, 'exclude_posts_comments_feed' ), 99, 2 );
84
- // Disable comments if user has not permission to access current post
85
- add_filter( 'comments_open', array( $this, 'disable_comments_open' ), 99, 2 );
86
- add_filter( 'get_comments_number', array( $this, 'disable_comments_open_number' ), 99, 2 );
87
-
88
- // filter menu items
89
- add_filter( 'wp_nav_menu_objects', array( &$this, 'filter_menu' ), 99, 2 );
90
-
91
- // Gutenberg blocks restrictions
92
- add_filter( 'render_block', array( $this, 'restrict_blocks' ), 10, 2 );
93
-
94
- // there is posts (Posts/Page/CPT) filtration if site is accessible
95
- // there also will be redirects if they need
96
- // protect posts types
97
- add_filter( 'the_posts', array( &$this, 'filter_protected_posts' ), 99, 2 );
98
- // protect pages for wp_list_pages func
99
- add_filter( 'get_pages', array( &$this, 'filter_protected_posts' ), 99, 2 );
100
-
101
- // check the site's accessible more priority have Individual Post/Term Restriction settings
102
- add_action( 'template_redirect', array( &$this, 'template_redirect' ), 1000 );
103
- add_action( 'um_access_check_individual_term_settings', array( &$this, 'um_access_check_individual_term_settings' ) );
104
- add_action( 'um_access_check_global_settings', array( &$this, 'um_access_check_global_settings' ) );
105
-
106
- add_action( 'plugins_loaded', array( &$this, 'disable_restriction_pre_queries' ), 1 );
107
- }
108
-
109
-
110
- /**
111
- * Rollback function for old business logic to avoid security enhancements with 404 errors
112
- */
113
- function disable_restriction_pre_queries() {
114
- // callbacks for changing terms query
115
- add_action( 'pre_get_terms', array( &$this, 'exclude_hidden_terms_query' ), 99, 1 );
116
-
117
- if ( ! UM()->options()->get( 'disable_restriction_pre_queries' ) ) {
118
- return;
119
- }
120
-
121
- remove_action( 'pre_get_terms', array( &$this, 'exclude_hidden_terms_query' ), 99 );
122
- remove_filter( 'widget_posts_args', array( &$this, 'exclude_restricted_posts_widget' ), 99 );
123
- remove_filter( 'wp_list_pages_excludes', array( &$this, 'exclude_restricted_pages' ), 10 );
124
- remove_filter( 'getarchives_where', array( &$this, 'exclude_restricted_posts_archives_widget' ), 99 );
125
- remove_filter( 'get_next_post_where', array( &$this, 'exclude_navigation_posts' ), 99 );
126
- remove_filter( 'get_previous_post_where', array( &$this, 'exclude_navigation_posts' ), 99 );
127
- remove_action( 'pre_get_posts', array( &$this, 'exclude_posts' ), 99 );
128
- remove_filter( 'posts_where', array( &$this, 'exclude_posts_where' ), 10 );
129
- remove_filter( 'wp_count_posts', array( &$this, 'custom_count_posts_handler' ), 99 );
130
- }
131
-
132
-
133
- /**
134
- * Get array with restricted posts
135
- *
136
- * @param bool $force
137
- * @param bool|array|string $post_types
138
- *
139
- * @return array
140
- */
141
- function exclude_posts_array( $force = false, $post_types = false ) {
142
- if ( $this->ignore_exclude ) {
143
- return array();
144
- }
145
-
146
- static $cache = array();
147
-
148
- $cache_key = $force ? 'force' : 'default';
149
-
150
- // `force` cache contains all restricted post IDs we can get them all from cache instead new queries
151
- $force_cache_key = '';
152
- if ( 'default' === $cache_key ) {
153
- $force_cache_key = 'force';
154
- }
155
-
156
- // make $post_types as array if string
157
- if ( ! empty( $post_types ) ) {
158
- $post_types = is_array( $post_types ) ? $post_types : array( $post_types );
159
- $cache_key .= md5( serialize( $post_types ) );
160
- if ( ! empty( $force_cache_key ) ) {
161
- $force_cache_key .= md5( serialize( $post_types ) );
162
- }
163
- }
164
-
165
- if ( array_key_exists( $cache_key, $cache ) ) {
166
- return $cache[ $cache_key ];
167
- }
168
-
169
- $exclude_posts = array();
170
- if ( current_user_can( 'administrator' ) ) {
171
- $cache[ $cache_key ] = $exclude_posts;
172
- return $exclude_posts;
173
- }
174
-
175
- // @todo using Object Cache `wp_cache_get()` `wp_cache_set()` functions
176
-
177
- // `force` cache contains all restricted post IDs we can get them all from cache instead new queries
178
- if ( ! empty( $force_cache_key ) && array_key_exists( $force_cache_key, $cache ) ) {
179
- $post_ids = $cache[ $force_cache_key ];
180
-
181
- if ( ! empty( $post_ids ) ) {
182
- foreach ( $post_ids as $post_id ) {
183
- $content_restriction = $this->get_post_privacy_settings( $post_id );
184
- if ( ! empty( $content_restriction['_um_access_hide_from_queries'] ) ) {
185
- array_push( $exclude_posts, $post_id );
186
- }
187
- }
188
- }
189
- } else {
190
- $restricted_posts = UM()->options()->get( 'restricted_access_post_metabox' );
191
- if ( ! empty( $restricted_posts ) ) {
192
- $restricted_posts = array_keys( $restricted_posts );
193
- if ( ! empty( $post_types ) ) {
194
- $restricted_posts = array_intersect( $post_types, $restricted_posts );
195
- }
196
- }
197
-
198
- if ( ! empty( $restricted_posts ) ) {
199
- $this->ignore_exclude = true;
200
- // exclude all posts assigned to current term without individual restriction settings
201
- $post_ids = get_posts(
202
- array(
203
- 'fields' => 'ids',
204
- 'post_status' => 'any',
205
- 'post_type' => $restricted_posts,
206
- 'numberposts' => -1,
207
- 'meta_query' => array(
208
- array(
209
- 'key' => 'um_content_restriction',
210
- 'compare' => 'EXISTS',
211
- ),
212
- ),
213
- )
214
- );
215
-
216
- $this->ignore_exclude = false;
217
- }
218
-
219
- $post_ids = empty( $post_ids ) ? array() : $post_ids;
220
-
221
- $restricted_taxonomies = UM()->options()->get( 'restricted_access_taxonomy_metabox' );
222
-
223
- if ( ! empty( $restricted_taxonomies ) ) {
224
- $restricted_taxonomies = array_keys( $restricted_taxonomies );
225
- foreach ( $restricted_taxonomies as $k => $taxonomy ) {
226
- if ( ! taxonomy_exists( $taxonomy ) ) {
227
- unset( $restricted_taxonomies[ $k ] );
228
- }
229
- }
230
- $restricted_taxonomies = array_values( $restricted_taxonomies );
231
-
232
- if ( ! empty( $post_types ) ) {
233
- $taxonomies = array();
234
- foreach ( $post_types as $p_t ) {
235
- $taxonomies = array_merge( $taxonomies, get_object_taxonomies( $p_t ) );
236
- }
237
- $restricted_taxonomies = array_intersect( $taxonomies, $restricted_taxonomies );
238
- }
239
- }
240
-
241
- if ( ! empty( $restricted_taxonomies ) ) {
242
- global $wpdb;
243
-
244
- $terms = $wpdb->get_results(
245
- "SELECT tm.term_id AS term_id,
246
- tt.taxonomy AS taxonomy
247
- FROM {$wpdb->termmeta} tm
248
- LEFT JOIN {$wpdb->term_taxonomy} tt ON tt.term_id = tm.term_id
249
- WHERE tm.meta_key = 'um_content_restriction' AND
250
- tt.taxonomy IN('" . implode( "','", $restricted_taxonomies ) . "')",
251
- ARRAY_A
252
- );
253
-
254
- if ( ! empty( $terms ) ) {
255
- foreach ( $terms as $term ) {
256
- if ( ! $this->is_restricted_term( $term['term_id'] ) ) {
257
- continue;
258
- }
259
-
260
- $this->ignore_exclude = true;
261
- // exclude all posts assigned to current term without individual restriction settings
262
- $posts = get_posts(
263
- array(
264
- 'fields' => 'ids',
265
- 'post_status' => 'any',
266
- 'numberposts' => -1,
267
- 'tax_query' => array(
268
- array(
269
- 'taxonomy' => $term['taxonomy'],
270
- 'field' => 'id',
271
- 'terms' => $term['term_id'],
272
- ),
273
- ),
274
- 'meta_query' => array(
275
- 'relation' => 'OR',
276
- array(
277
- 'relation' => 'AND',
278
- array(
279
- 'key' => 'um_content_restriction',
280
- 'value' => 's:26:"_um_custom_access_settings";s:1:"1"',
281
- 'compare' => 'NOT LIKE',
282
- ),
283
- array(
284
- 'key' => 'um_content_restriction',
285
- 'value' => 's:26:"_um_custom_access_settings";b:1',
286
- 'compare' => 'NOT LIKE',
287
- ),
288
- ),
289
- array(
290
- 'key' => 'um_content_restriction',
291
- 'compare' => 'NOT EXISTS',
292
- ),
293
- ),
294
- )
295
- );
296
- $this->ignore_exclude = false;
297
-
298
- if ( empty( $posts ) ) {
299
- continue;
300
- }
301
-
302
- $post_ids = array_merge( $post_ids, $posts );
303
- }
304
- }
305
- }
306
-
307
- if ( ! empty( $post_ids ) ) {
308
- $post_ids = array_unique( $post_ids );
309
-
310
- foreach ( $post_ids as $post_id ) {
311
- // handle every post privacy setting based on post type maybe it's inactive for now
312
- // if individual restriction is enabled then get post terms restriction settings
313
- if ( $this->is_restricted( $post_id ) ) {
314
- if ( true === $force ) {
315
- array_push( $exclude_posts, $post_id );
316
- } else {
317
- $content_restriction = $this->get_post_privacy_settings( $post_id );
318
- if ( ! empty( $content_restriction['_um_access_hide_from_queries'] ) ) {
319
- array_push( $exclude_posts, $post_id );
320
- }
321
- }
322
- }
323
- }
324
- }
325
- }
326
-
327
- $exclude_posts = apply_filters( 'um_exclude_restricted_posts_ids', $exclude_posts, $force );
328
-
329
- $cache[ $cache_key ] = $exclude_posts;
330
- return $exclude_posts;
331
- }
332
-
333
-
334
-
335
- /**
336
- * Get array with restricted terms
337
- *
338
- * @param \WP_Term_Query $query
339
- *
340
- * @return array
341
- */
342
- function exclude_terms_array( $query ) {
343
- $exclude = array();
344
-
345
- $restricted_taxonomies = UM()->options()->get( 'restricted_access_taxonomy_metabox' );
346
- if ( ! empty( $restricted_taxonomies ) ) {
347
- $restricted_taxonomies = array_keys( $restricted_taxonomies );
348
- foreach ( $restricted_taxonomies as $k => $taxonomy ) {
349
- if ( ! taxonomy_exists( $taxonomy ) ) {
350
- unset( $restricted_taxonomies[ $k ] );
351
- }
352
- }
353
- $restricted_taxonomies = array_values( $restricted_taxonomies );
354
-
355
- if ( ! empty( $restricted_taxonomies ) ) {
356
- if ( isset( $query->query_vars['taxonomy'] ) && is_array( $query->query_vars['taxonomy'] ) ) {
357
- $restricted_taxonomies = array_intersect( $query->query_vars['taxonomy'], $restricted_taxonomies );
358
- } elseif ( ! empty( $query->query_vars['term_taxonomy_id'] ) ) {
359
- $term_taxonomy_ids = is_array( $query->query_vars['term_taxonomy_id'] ) ? $query->query_vars['term_taxonomy_id'] : array( $query->query_vars['term_taxonomy_id'] );
360
-
361
- global $wpdb;
362
- $tax_in_query = $wpdb->get_col( "SELECT DISTINCT taxonomy FROM {$wpdb->term_taxonomy} WHERE term_taxonomy_id IN('" . implode( "','", $term_taxonomy_ids ) . "')" );
363
- if ( ! empty( $tax_in_query ) ) {
364
- $restricted_taxonomies = array_intersect( $tax_in_query, $restricted_taxonomies );
365
- } else {
366
- $restricted_taxonomies = array();
367
- }
368
- }
369
- }
370
- }
371
-
372
- if ( empty( $restricted_taxonomies ) ) {
373
- return $exclude;
374
- }
375
-
376
- $cache_key = md5( serialize( $restricted_taxonomies ) );
377
-
378
- static $cache = array();
379
-
380
- if ( array_key_exists( $cache_key, $cache ) ) {
381
- return $cache[ $cache_key ];
382
- }
383
-
384
- $term_ids = get_terms(
385
- array(
386
- 'taxonomy' => $restricted_taxonomies,
387
- 'hide_empty' => false,
388
- 'fields' => 'ids',
389
- 'meta_query' => array(
390
- 'key' => 'um_content_restriction',
391
- 'compare' => 'EXISTS',
392
- ),
393
- 'um_ignore_exclude' => true,
394
- )
395
- );
396
-
397
- if ( empty( $term_ids ) || is_wp_error( $term_ids ) ) {
398
- $cache[ $cache_key ] = $exclude;
399
- return $exclude;
400
- }
401
-
402
- foreach ( $term_ids as $term_id ) {
403
- if ( $this->is_restricted_term( $term_id ) ) {
404
- $exclude[] = $term_id;
405
- }
406
- }
407
-
408
- $exclude = apply_filters( 'um_exclude_restricted_terms_ids', $exclude );
409
- $cache[ $cache_key ] = $exclude;
410
- return $exclude;
411
- }
412
-
413
-
414
- /**
415
- * @param \WP_Term_Query $query
416
- */
417
- function exclude_hidden_terms_query( $query ) {
418
- if ( current_user_can( 'administrator' ) || ! empty( $query->query_vars['um_ignore_exclude'] ) ) {
419
- return;
420
- }
421
-
422
- $exclude = $this->exclude_terms_array( $query );
423
- if ( ! empty( $exclude ) ) {
424
- $query->query_vars['exclude'] = ! empty( $query->query_vars['exclude'] ) ? wp_parse_id_list( $query->query_vars['exclude'] ) : $exclude;
425
- }
426
- }
427
-
428
-
429
- /**
430
- * @param \WP_Query $query
431
- */
432
- function exclude_posts( $query ) {
433
- if ( current_user_can( 'administrator' ) ) {
434
- return;
435
- }
436
-
437
- // use these functions is_search() || is_admin() for getting force hide all posts
438
- // don't handle `hide from WP_Query` and show 404 option for searching and wp-admin query
439
- if ( $query->is_main_query() || ! empty( $query->query_vars['um_main_query'] ) ) {
440
- $force = is_feed() || is_search() || is_admin();
441
-
442
- if ( is_object( $query ) ) {
443
- $is_singular = $query->is_singular();
444
- } else {
445
- $is_singular = ! empty( $query->is_singular ) ? true : false;
446
- }
447
-
448
- if ( ! $is_singular ) {
449
- // need to know what post type is here
450
- $q_values = ! empty( $query->query_vars['post_type'] ) ? $query->query_vars['post_type'] : array();
451
- if ( ! is_array( $q_values ) ) {
452
- $q_values = explode( ',', $query->query_vars['post_type'] );
453
- }
454
-
455
- // 'any' will cause the query var to be ignored.
456
- if ( in_array( 'any', $q_values, true ) || empty( $q_values ) ) {
457
- $exclude_posts = $this->exclude_posts_array( $force );
458
- } else {
459
- $exclude_posts = $this->exclude_posts_array( $force, $q_values );
460
- }
461
-
462
- if ( ! empty( $exclude_posts ) ) {
463
- $post__not_in = $query->get( 'post__not_in', array() );
464
- $query->set( 'post__not_in', array_merge( wp_parse_id_list( $post__not_in ), $exclude_posts ) );
465
- }
466
- }
467
- }
468
- }
469
-
470
-
471
- /**
472
- * Exclude restricted post from query if there is a single query that exclude post_not_in by default in \WP_Query
473
- *
474
- * @param string $where
475
- * @param \WP_Query $query
476
- *
477
- * @return mixed
478
- */
479
- function exclude_posts_where( $where, $query ) {
480
- if ( current_user_can( 'administrator' ) ) {
481
- return $where;
482
- }
483
-
484
- if ( ! $query->is_main_query() ) {
485
- return $where;
486
- }
487
-
488
- if ( ! empty( $query->query_vars['p'] ) && $this->is_restricted( $query->query_vars['p'] ) ) {
489
- $restriction_settings = $this->get_post_privacy_settings( $query->query_vars['p'] );
490
- if ( ! empty( $restriction_settings['_um_access_hide_from_queries'] ) && ! empty( $query->query_vars['post__not_in'] ) ) {
491
- global $wpdb;
492
- $post__not_in = implode( ',', array_map( 'absint', $query->query_vars['post__not_in'] ) );
493
- $where .= " AND {$wpdb->posts}.ID NOT IN ($post__not_in)";
494
- }
495
- }
496
-
497
- return $where;
498
- }
499
-
500
-
501
- /**
502
- * Change the posts count based on restriction settings
503
- *
504
- * @param object $counts Post counts
505
- * @param string $type Post type
506
- * @param string $perm The permission to determine if the posts are 'readable'
507
- * by the current user.
508
- *
509
- * @return object
510
- */
511
- function custom_count_posts_handler( $counts, $type = 'post', $perm = '' ) {
512
- if ( current_user_can( 'administrator' ) ) {
513
- return $counts;
514
- }
515
-
516
- global $wpdb;
517
-
518
- static $cache = array();
519
-
520
- $cache_key = _count_posts_cache_key( $type, $perm );
521
- $force = is_feed() || is_search() || is_admin();
522
- $cache_key .= $force ? 'force' : '';
523
-
524
- if ( array_key_exists( $cache_key, $cache ) ) {
525
- return $cache[ $cache_key ];
526
- }
527
-
528
- $exclude_posts = $this->exclude_posts_array( $force, array( $type ) );
529
- if ( empty( $exclude_posts ) ) {
530
- $cache[ $cache_key ] = $counts;
531
- return $counts;
532
- }
533
-
534
- $query = "SELECT post_status, COUNT( * ) AS num_posts FROM {$wpdb->posts} WHERE post_type = %s";
535
-
536
- if ( 'readable' === $perm && is_user_logged_in() ) {
537
- $post_type_object = get_post_type_object( $type );
538
- if ( ! current_user_can( $post_type_object->cap->read_private_posts ) ) {
539
- $query .= $wpdb->prepare(
540
- " AND (post_status != 'private' OR ( post_author = %d AND post_status = 'private' ))",
541
- get_current_user_id()
542
- );
543
- }
544
- }
545
-
546
- $query .= " AND ID NOT IN('" . implode( "','", $exclude_posts ) . "')";
547
-
548
- $query .= ' GROUP BY post_status';
549
-
550
- $results = (array) $wpdb->get_results( $wpdb->prepare( $query, $type ), ARRAY_A );
551
- $counts = array_fill_keys( get_post_stati(), 0 );
552
-
553
- foreach ( $results as $row ) {
554
- $counts[ $row['post_status'] ] = $row['num_posts'];
555
- }
556
-
557
- $counts = (object) $counts;
558
-
559
- $cache[ $cache_key ] = $counts;
560
- return $counts;
561
- }
562
-
563
-
564
- /**
565
- * Exclude restricted posts in Recent Posts widget
566
- *
567
- * @param array $array Query args
568
- *
569
- * @return array
570
- */
571
- function exclude_restricted_posts_widget( $array ) {
572
- if ( current_user_can( 'administrator' ) ) {
573
- return $array;
574
- }
575
-
576
- $exclude_posts = $this->exclude_posts_array( false, 'post' );
577
- if ( ! empty( $exclude_posts ) ) {
578
- $post__not_in = ! empty( $array['post__not_in'] ) ? $array['post__not_in'] : array();
579
- $array['post__not_in'] = array_merge( wp_parse_id_list( $post__not_in ), $exclude_posts );
580
- }
581
-
582
- return $array;
583
- }
584
-
585
-
586
- /**
587
- * Exclude restricted posts in Recent Posts widget
588
- *
589
- * @param array $array Query args
590
- *
591
- * @return array
592
- */
593
- function exclude_restricted_pages( $array ) {
594
- if ( current_user_can( 'administrator' ) ) {
595
- return $array;
596
- }
597
-
598
- $exclude_posts = $this->exclude_posts_array( false, 'page' );
599
- if ( ! empty( $exclude_posts ) ) {
600
- $array = array_merge( $array, $exclude_posts );
601
- }
602
-
603
- return $array;
604
- }
605
-
606
-
607
- /**
608
- * Exclude restricted posts in widgets
609
- *
610
- * @param string $sql_where
611
- * @param array $parsed_args
612
- *
613
- * @return string
614
- */
615
- function exclude_restricted_posts_archives_widget( $sql_where, $parsed_args = array() ) {
616
- if ( current_user_can( 'administrator' ) ) {
617
- return $sql_where;
618
- }
619
-
620
- $post_type = ! empty( $parsed_args['post_type'] ) ? $parsed_args['post_type'] : false;
621
-
622
- $exclude_posts = $this->exclude_posts_array( false, $post_type );
623
- if ( ! empty( $exclude_posts ) ) {
624
- $exclude_string = implode( ',', $exclude_posts );
625
- $sql_where .= ' AND ID NOT IN ( ' . $exclude_string . ' )';
626
- }
627
-
628
- return $sql_where;
629
- }
630
-
631
-
632
- /**
633
- * Exclude posts from next, previous navigation
634
- *
635
- * @param string $where
636
- * @param bool $in_same_term
637
- * @param string|array $excluded_terms
638
- * @param string $taxonomy
639
- * @param null|\WP_Post $post
640
- *
641
- * @return string
642
- */
643
- function exclude_navigation_posts( $where, $in_same_term = false, $excluded_terms = '', $taxonomy = 'category', $post = null ) {
644
- if ( current_user_can( 'administrator' ) ) {
645
- return $where;
646
- }
647
-
648
- if ( empty( $post ) ) {
649
- return $where;
650
- }
651
-
652
- $exclude_posts = $this->exclude_posts_array( false, $post->post_type );
653
- if ( ! empty( $exclude_posts ) ) {
654
- $exclude_string = implode( ',', $exclude_posts );
655
- $where .= ' AND ID NOT IN ( ' . $exclude_string . ' )';
656
- }
657
-
658
- return $where;
659
- }
660
-
661
-
662
- /**
663
- * Replace titles of restricted posts
664
- *
665
- * @param string $title
666
- * @param int|null $id
667
- *
668
- * @return string
669
- */
670
- function filter_restricted_post_title( $title, $id = null ) {
671
- if ( ! UM()->options()->get( 'restricted_post_title_replace' ) ) {
672
- return $title;
673
- }
674
-
675
- if ( current_user_can( 'administrator' ) ) {
676
- return $title;
677
- }
678
-
679
- if ( ! isset( $id ) ) {
680
- return $title;
681
- }
682
-
683
- if ( ! is_numeric( $id ) ) {
684
- $id = absint( $id );
685
- }
686
-
687
- $ignore = apply_filters( 'um_ignore_restricted_title', false, $id );
688
- if ( $ignore ) {
689
- return $title;
690
- }
691
-
692
- if ( $this->is_restricted( $id ) ) {
693
- $restricted_global_title = UM()->options()->get( 'restricted_access_post_title' );
694
- $title = stripslashes( $restricted_global_title );
695
- }
696
-
697
- return $title;
698
- }
699
-
700
-
701
- /**
702
- * Replace content of restricted posts
703
- *
704
- * @param string $content
705
- *
706
- * @return string
707
- */
708
- function filter_restricted_post_content( $content ) {
709
- if ( current_user_can( 'administrator' ) ) {
710
- return $content;
711
- }
712
-
713
- $id = get_the_ID();
714
- if ( ! $id || is_admin() ) {
715
- return $content;
716
- }
717
-
718
- $ignore = apply_filters( 'um_ignore_restricted_content', false, $id );
719
- if ( $ignore ) {
720
- return $content;
721
- }
722
-
723
- if ( $this->is_restricted( $id ) ) {
724
- $restriction = $this->get_post_privacy_settings( $id );
725
-
726
- if ( ! isset( $restriction['_um_restrict_by_custom_message'] ) || '0' == $restriction['_um_restrict_by_custom_message'] ) {
727
- $content = stripslashes( UM()->options()->get( 'restricted_access_message' ) );
728
- } elseif ( '1' == $restriction['_um_restrict_by_custom_message'] ) {
729
- $content = ! empty( $restriction['_um_restrict_custom_message'] ) ? stripslashes( $restriction['_um_restrict_custom_message'] ) : '';
730
- }
731
-
732
- // translators: %s: Restricted post message.
733
- $content = sprintf( __( '%s', 'ultimate-member' ), $content );
734
- }
735
-
736
- return $content;
737
- }
738
-
739
-
740
- /**
741
- * Replace excerpt of restricted posts
742
- *
743
- * @param string $post_excerpt
744
- * @param \WP_Post $post
745
- *
746
- * @return string
747
- */
748
- function filter_restricted_post_excerpt( $post_excerpt = '', $post = null ) {
749
- if ( empty( $post ) ) {
750
- return $post_excerpt;
751
- }
752
-
753
- if ( current_user_can( 'administrator' ) || is_admin() ) {
754
- return $post_excerpt;
755
- }
756
-
757
- $ignore = apply_filters( 'um_ignore_restricted_excerpt', false, $post->ID );
758
- if ( $ignore ) {
759
- return $post_excerpt;
760
- }
761
-
762
- if ( $this->is_restricted( $post->ID ) ) {
763
- $post_excerpt = '';
764
- }
765
-
766
- return $post_excerpt;
767
- }
768
-
769
-
770
- /**
771
- * Hide attachment if the post is restricted
772
- *
773
- * @param string $url
774
- * @param int $attachment_id
775
- *
776
- * @return boolean|string
777
- */
778
- function filter_attachment( $url, $attachment_id ) {
779
- if ( current_user_can( 'administrator' ) ) {
780
- return $url;
781
- }
782
-
783
- return ( $attachment_id && $this->is_restricted( $attachment_id ) ) ? false : $url;
784
- }
785
-
786
-
787
- /**
788
- * Hide attachment if the post is restricted
789
- *
790
- * @param $has_thumbnail
791
- * @param $post
792
- * @param $thumbnail_id
793
- *
794
- * @return bool
795
- */
796
- function filter_post_thumbnail( $has_thumbnail, $post = null, $thumbnail_id = false ) {
797
- if ( empty( $thumbnail_id ) ) {
798
- return $has_thumbnail;
799
- }
800
-
801
- if ( current_user_can( 'administrator' ) ) {
802
- return $has_thumbnail;
803
- }
804
-
805
- if ( $this->is_restricted( $thumbnail_id ) ) {
806
- $has_thumbnail = false;
807
- } elseif ( ! empty( $post ) && ! empty( $post->ID ) ) {
808
- if ( $this->is_restricted( $post->ID ) ) {
809
- $has_thumbnail = false;
810
- }
811
- } else {
812
- $post_id = get_the_ID();
813
- if ( false !== $post_id && $this->is_restricted( $post_id ) ) {
814
- $has_thumbnail = false;
815
- }
816
- }
817
-
818
- $has_thumbnail = apply_filters( 'um_restrict_post_thumbnail', $has_thumbnail, $post, $thumbnail_id );
819
-
820
- return $has_thumbnail;
821
- }
822
-
823
-
824
-
825
- /**
826
- * Exclude comments from restricted posts in widgets
827
- *
828
- * @param \WP_Comment_Query $query
829
- */
830
- function exclude_posts_comments( $query ) {
831
- if ( current_user_can( 'administrator' ) ) {
832
- return;
833
- }
834
-
835
- if ( ! empty( $query->query_vars['post_id'] ) ) {
836
- $exclude_posts = array();
837
- if ( $this->is_restricted( $query->query_vars['post_id'] ) ) {
838
- $exclude_posts[] = $query->query_vars['post_id'];
839
- }
840
- } else {
841
- $q_values = ! empty( $query->query_vars['post_type'] ) ? $query->query_vars['post_type'] : array();
842
- if ( ! is_array( $q_values ) ) {
843
- $q_values = explode( ',', $query->query_vars['post_type'] );
844
- }
845
-
846
- // 'any' will cause the query var to be ignored.
847
- if ( in_array( 'any', $q_values, true ) || empty( $q_values ) ) {
848
- $exclude_posts = $this->exclude_posts_array( true, $this->get_available_comments_post_types() );
849
- } else {
850
- $exclude_posts = $this->exclude_posts_array( true, $q_values );
851
- }
852
- }
853
-
854
- if ( ! empty( $exclude_posts ) ) {
855
- $post__not_in = ! empty( $query->query_vars['post__not_in'] ) ? $query->query_vars['post__not_in'] : array();
856
- $query->query_vars['post__not_in'] = array_merge( wp_parse_id_list( $post__not_in ), $exclude_posts );
857
- }
858
- }
859
-
860
-
861
- /**
862
- * @return array
863
- */
864
- function get_available_comments_post_types() {
865
- global $wp_taxonomies, $wpdb;
866
-
867
- $restricted_posts = UM()->options()->get( 'restricted_access_post_metabox' );
868
- if ( empty( $restricted_posts ) ) {
869
- $restricted_posts = array();
870
- }
871
- $restricted_posts = array_keys( $restricted_posts );
872
-
873
- $restricted_taxonomies = UM()->options()->get( 'restricted_access_taxonomy_metabox' );
874
- if ( ! empty( $restricted_taxonomies ) ) {
875
- $restricted_taxonomies = array_keys( $restricted_taxonomies );
876
- foreach ( $restricted_taxonomies as $k => $taxonomy ) {
877
- if ( taxonomy_exists( $taxonomy ) ) {
878
- $restricted_posts = array_merge( $restricted_posts, $wp_taxonomies[ $taxonomy ]->object_type );
879
- }
880
- }
881
- }
882
-
883
- $restricted_posts = array_unique( $restricted_posts );
884
- foreach ( $restricted_posts as $k => $post_type ) {
885
- if ( 'closed' === get_default_comment_status( $post_type ) ) {
886
- $open_comments = $wpdb->get_var( $wpdb->prepare(
887
- "SELECT ID
888
- FROM {$wpdb->posts}
889
- WHERE post_type = %s AND
890
- comment_status != 'closed'",
891
- $post_type
892
- ) );
893
-
894
- if ( empty( $open_comments ) ) {
895
- unset( $restricted_posts[ $k ] );
896
- }
897
- }
898
- }
899
-
900
- $restricted_posts = array_values( $restricted_posts );
901
-
902
- return $restricted_posts;
903
- }
904
-
905
-
906
- /**
907
- * Exclude comments from comments feed
908
- *
909
- * @param string $where
910
- * @param \WP_Query $query
911
- *
912
- * @return string
913
- */
914
- function exclude_posts_comments_feed( $where, $query ) {
915
- if ( current_user_can( 'administrator' ) ) {
916
- return $where;
917
- }
918
-
919
- $exclude_posts = $this->exclude_posts_array( true, $this->get_available_comments_post_types() );
920
- if ( ! empty( $exclude_posts ) ) {
921
- $exclude_string = implode( ',', $exclude_posts );
922
- $where .= ' AND comment_post_ID NOT IN ( ' . $exclude_string . ' )';
923
- }
924
-
925
- return $where;
926
- }
927
-
928
-
929
- /**
930
- * @param array|object $stats
931
- * @param int $post_id Post ID. Can be 0 for the whole website
932
- *
933
- * @return object
934
- */
935
- function custom_comments_count_handler( $stats = array(), $post_id = 0 ) {
936
- if ( ! empty( $stats ) || current_user_can( 'administrator' ) ) {
937
- return $stats;
938
- }
939
-
940
- if ( $post_id === 0 ) {
941
- $exclude_posts = $this->exclude_posts_array( true, $this->get_available_comments_post_types() );
942
- if ( empty( $exclude_posts ) ) {
943
- return $stats;
944
- }
945
- } else {
946
- $exclude_posts = array();
947
- if ( $this->is_restricted( $post_id ) ) {
948
- $exclude_posts[] = $post_id;
949
- }
950
- }
951
-
952
- $stats = $this->get_comment_count( $post_id, $exclude_posts );
953
- $stats['moderated'] = $stats['awaiting_moderation'];
954
- unset( $stats['awaiting_moderation'] );
955
-
956
- $stats_object = (object) $stats;
957
-
958
- return $stats_object;
959
- }
960
-
961
-
962
- /**
963
- * @param int $post_id
964
- * @param array $exclude_posts
965
- *
966
- * @return array
967
- */
968
- function get_comment_count( $post_id = 0, $exclude_posts = array() ) {
969
- static $cache = array();
970
-
971
- if ( isset( $cache[ $post_id ] ) ) {
972
- return $cache[ $post_id ];
973
- }
974
-
975
- global $wpdb;
976
-
977
- $post_id = (int) $post_id;
978
-
979
- $where = 'WHERE 1=1';
980
- if ( $post_id > 0 ) {
981
- $where .= $wpdb->prepare( ' AND comment_post_ID = %d', $post_id );
982
- }
983
-
984
- if ( ! empty( $exclude_posts ) ) {
985
- $exclude_string = implode( ',', $exclude_posts );
986
- $where .= ' AND comment_post_ID NOT IN ( ' . $exclude_string . ' )';
987
- }
988
-
989
- $totals = (array) $wpdb->get_results(
990
- "
991
- SELECT comment_approved, COUNT( * ) AS total
992
- FROM {$wpdb->comments}
993
- {$where}
994
- GROUP BY comment_approved
995
- ",
996
- ARRAY_A
997
- );
998
-
999
- $comment_count = array(
1000
- 'approved' => 0,
1001
- 'awaiting_moderation' => 0,
1002
- 'spam' => 0,
1003
- 'trash' => 0,
1004
- 'post-trashed' => 0,
1005
- 'total_comments' => 0,
1006
- 'all' => 0,
1007
- );
1008
-
1009
- foreach ( $totals as $row ) {
1010
- switch ( $row['comment_approved'] ) {
1011
- case 'trash':
1012
- $comment_count['trash'] = $row['total'];
1013
- break;
1014
- case 'post-trashed':
1015
- $comment_count['post-trashed'] = $row['total'];
1016
- break;
1017
- case 'spam':
1018
- $comment_count['spam'] = $row['total'];
1019
- $comment_count['total_comments'] += $row['total'];
1020
- break;
1021
- case '1':
1022
- $comment_count['approved'] = $row['total'];
1023
- $comment_count['total_comments'] += $row['total'];
1024
- $comment_count['all'] += $row['total'];
1025
- break;
1026
- case '0':
1027
- $comment_count['awaiting_moderation'] = $row['total'];
1028
- $comment_count['total_comments'] += $row['total'];
1029
- $comment_count['all'] += $row['total'];
1030
- break;
1031
- default:
1032
- break;
1033
- }
1034
- }
1035
-
1036
- $comment_count = array_map( 'intval', $comment_count );
1037
- $cache[ $post_id ] = $comment_count;
1038
-
1039
- return $comment_count;
1040
- }
1041
-
1042
-
1043
- /**
1044
- * Disable comments if user has not permission to access this post
1045
- *
1046
- * @param mixed $open
1047
- * @param int $post_id
1048
- * @return boolean
1049
- */
1050
- function disable_comments_open( $open, $post_id ) {
1051
- if ( current_user_can( 'administrator' ) ) {
1052
- return $open;
1053
- }
1054
-
1055
- static $cache = array();
1056
-
1057
- if ( isset( $cache[ $post_id ] ) ) {
1058
- return $cache[ $post_id ] ? $open : false;
1059
- }
1060
-
1061
- if ( ! $this->is_restricted( $post_id ) ) {
1062
- $cache[ $post_id ] = $open;
1063
- return $open;
1064
- }
1065
-
1066
- $open = false;
1067
-
1068
- $cache[ $post_id ] = $open;
1069
- return $open;
1070
- }
1071
-
1072
-
1073
- /**
1074
- * Disable comments if user has not permission to access this post
1075
- *
1076
- * @param int $count
1077
- * @param int $post_id
1078
- * @return boolean
1079
- */
1080
- function disable_comments_open_number( $count, $post_id = 0 ) {
1081
- if ( current_user_can( 'administrator' ) ) {
1082
- return $count;
1083
- }
1084
-
1085
- static $cache_number = array();
1086
-
1087
- if ( isset( $cache_number[ $post_id ] ) ) {
1088
- return $cache_number[ $post_id ];
1089
- }
1090
-
1091
- if ( ! $this->is_restricted( $post_id ) ) {
1092
- $cache_number[ $post_id ] = $count;
1093
- return $count;
1094
- }
1095
-
1096
- $count = 0;
1097
-
1098
- $cache_number[ $post_id ] = $count;
1099
- return $count;
1100
- }
1101
-
1102
-
1103
- /**
1104
- * Protect Post Types in menu query
1105
- * Restrict content new logic
1106
- * @param array $menu_items
1107
- * @param array $args
1108
- * @return array
1109
- */
1110
- function filter_menu( $menu_items, $args = array() ) {
1111
- //if empty
1112
- if ( empty( $menu_items ) ) {
1113
- return $menu_items;
1114
- }
1115
-
1116
- if ( current_user_can( 'administrator' ) ) {
1117
- return $menu_items;
1118
- }
1119
-
1120
- $filtered_items = array();
1121
-
1122
- //other filter
1123
- foreach ( $menu_items as $menu_item ) {
1124
- if ( ! empty( $menu_item->object_id ) && ! empty( $menu_item->object ) ) {
1125
- if ( isset( $menu_item->type ) && 'taxonomy' === $menu_item->type ) {
1126
- if ( ! $this->is_restricted_term( $menu_item->object_id ) ) {
1127
- $filtered_items[] = $menu_item;
1128
- continue;
1129
- }
1130
- } elseif ( isset( $menu_item->type ) && 'post_type' === $menu_item->type ) {
1131
- if ( ! $this->is_restricted( $menu_item->object_id ) ) {
1132
- $filtered_items[] = $menu_item;
1133
- continue;
1134
- } else {
1135
- $restriction_settings = $this->get_post_privacy_settings( $menu_item->object_id );
1136
- if ( empty( $restriction_settings['_um_access_hide_from_queries'] ) || ! UM()->options()->get( 'disable_restriction_pre_queries' ) ) {
1137
- $filtered_items[] = $this->maybe_replace_nav_menu_title( $menu_item );
1138
- continue;
1139
- }
1140
- }
1141
- } elseif ( isset( $menu_item->type ) && 'custom' === $menu_item->type ) {
1142
- $filtered_items[] = $menu_item;
1143
- continue;
1144
- } else {
1145
- $filtered_items[] = $menu_item;
1146
- continue;
1147
- }
1148
- } else {
1149
- //add all other posts
1150
- $filtered_items[] = $menu_item;
1151
- }
1152
- }
1153
-
1154
- return $filtered_items;
1155
- }
1156
-
1157
-
1158
- /**
1159
- * @param $block_content
1160
- * @param $block
1161
- *
1162
- * @return string
1163
- */
1164
- function restrict_blocks( $block_content, $block ) {
1165
- if ( is_admin() ) {
1166
- return $block_content;
1167
- }
1168
-
1169
- $restricted_blocks = UM()->options()->get( 'restricted_blocks' );
1170
- if ( empty( $restricted_blocks ) ) {
1171
- return $block_content;
1172
- }
1173
-
1174
- if ( is_user_logged_in() && current_user_can( 'administrator' ) ) {
1175
- return $block_content;
1176
- }
1177
-
1178
- if ( ! isset( $block['attrs']['um_is_restrict'] ) || $block['attrs']['um_is_restrict'] !== true ) {
1179
- return $block_content;
1180
- }
1181
-
1182
- if ( empty( $block['attrs']['um_who_access'] ) ) {
1183
- return $block_content;
1184
- }
1185
-
1186
- $default_message = UM()->options()->get( 'restricted_block_message' );
1187
- switch ( $block['attrs']['um_who_access'] ) {
1188
- case '1': {
1189
- if ( ! is_user_logged_in() ) {
1190
- $block_content = '';
1191
- if ( isset( $block['attrs']['um_message_type'] ) ) {
1192
- if ( $block['attrs']['um_message_type'] == '1' ) {
1193
- $block_content = $default_message;
1194
- } elseif ( $block['attrs']['um_message_type'] == '2' ) {
1195
- $block_content = $block['attrs']['um_message_content'];
1196
- }
1197
- }
1198
- } else {
1199
- $display = true;
1200
-
1201
- // What roles can access this content?
1202
- if ( ! empty( $block['attrs']['um_roles_access'] ) ) {
1203
- $display = false;
1204
- foreach ( $block['attrs']['um_roles_access'] as $role ) {
1205
- if ( current_user_can( $role ) ) {
1206
- $display = true;
1207
- }
1208
- }
1209
- }
1210
-
1211
- $display = apply_filters( 'um_loggedin_block_restriction', $display, $block );
1212
-
1213
- if ( ! $display ) {
1214
- $block_content = '';
1215
- if ( isset( $block['attrs']['um_message_type'] ) ) {
1216
- if ( $block['attrs']['um_message_type'] == '1' ) {
1217
- $block_content = $default_message;
1218
- } elseif ( $block['attrs']['um_message_type'] == '2' ) {
1219
- $block_content = $block['attrs']['um_message_content'];
1220
- }
1221
- }
1222
- }
1223
- }
1224
- break;
1225
- }
1226
- case '2': {
1227
- if ( is_user_logged_in() ) {
1228
- $block_content = '';
1229
- if ( isset( $block['attrs']['um_message_type'] ) ) {
1230
- if ( $block['attrs']['um_message_type'] == '1' ) {
1231
- $block_content = $default_message;
1232
- } elseif ( $block['attrs']['um_message_type'] == '2' ) {
1233
- $block_content = $block['attrs']['um_message_content'];
1234
- }
1235
- }
1236
- }
1237
- break;
1238
- }
1239
- }
1240
-
1241
- return $block_content;
1242
- }
1243
-
1244
-
1245
- /**
1246
- * @param \WP_Post $post
1247
- *
1248
- * @return \WP_Post
1249
- */
1250
- function maybe_replace_title( $post ) {
1251
- if ( ! UM()->options()->get( 'restricted_post_title_replace' ) ) {
1252
- return $post;
1253
- }
1254
-
1255
- if ( current_user_can( 'administrator' ) ) {
1256
- return $post;
1257
- }
1258
-
1259
- if ( ! is_a( $post, '\WP_Post' ) ) {
1260
- return $post;
1261
- }
1262
-
1263
- $ignore = apply_filters( 'um_ignore_restricted_title', false, $post->ID );
1264
- if ( $ignore ) {
1265
- return $post;
1266
- }
1267
-
1268
- $restricted_global_title = UM()->options()->get( 'restricted_access_post_title' );
1269
- $post->post_title = stripslashes( $restricted_global_title );
1270
-
1271
- return $post;
1272
- }
1273
-
1274
-
1275
- /**
1276
- * @param \WP_Post $nav_item
1277
- *
1278
- * @return \WP_Post
1279
- */
1280
- function maybe_replace_nav_menu_title( $nav_item ) {
1281
- if ( ! UM()->options()->get( 'restricted_post_title_replace' ) ) {
1282
- return $nav_item;
1283
- }
1284
-
1285
- if ( current_user_can( 'administrator' ) ) {
1286
- return $nav_item;
1287
- }
1288
-
1289
- if ( ! is_a( $nav_item, '\WP_Post' ) ) {
1290
- return $nav_item;
1291
- }
1292
-
1293
- $ignore = apply_filters( 'um_ignore_restricted_title', false, $nav_item->ID );
1294
- if ( $ignore ) {
1295
- return $nav_item;
1296
- }
1297
-
1298
- $restricted_global_title = UM()->options()->get( 'restricted_access_post_title' );
1299
- $nav_item->title = stripslashes( $restricted_global_title );
1300
-
1301
- return $nav_item;
1302
- }
1303
-
1304
-
1305
- /**
1306
- * Protect Post Types in query
1307
- * Restrict content new logic
1308
- *
1309
- * @param array $posts
1310
- * @param array|\WP_Query $query
1311
- * @return array
1312
- */
1313
- function filter_protected_posts( $posts, $query ) {
1314
- if ( current_user_can( 'administrator' ) ) {
1315
- return $posts;
1316
- }
1317
-
1318
- //Woocommerce AJAX fixes....remove filtration on wc-ajax which goes to Front Page
1319
- if ( ! empty( $_GET['wc-ajax'] ) && defined( 'WC_DOING_AJAX' ) && WC_DOING_AJAX ) {
1320
- return $posts;
1321
- }
1322
-
1323
- //if empty
1324
- if ( empty( $posts ) || is_admin() ) {
1325
- return $posts;
1326
- }
1327
-
1328
- if ( is_object( $query ) ) {
1329
- $is_singular = $query->is_singular();
1330
- } else {
1331
- $is_singular = ! empty( $query->is_singular ) ? true : false;
1332
- }
1333
-
1334
- if ( is_object( $query ) && is_a( $query, '\WP_Query' ) &&
1335
- ( $query->is_main_query() || ! empty( $query->query_vars['um_main_query'] ) ) ) {
1336
- if ( $is_singular ) {
1337
- if ( ! UM()->options()->get( 'disable_restriction_pre_queries' ) && $this->is_restricted( $posts[0]->ID ) ) {
1338
- $content_restriction = $this->get_post_privacy_settings( $posts[0]->ID );
1339
- if ( ! empty( $content_restriction['_um_access_hide_from_queries'] ) ) {
1340
- unset( $posts[0] );
1341
- return $posts;
1342
- }
1343
- }
1344
- }
1345
- }
1346
-
1347
- $filtered_posts = array();
1348
-
1349
- //other filter
1350
- foreach ( $posts as $post ) {
1351
- if ( is_user_logged_in() && isset( $post->post_author ) && $post->post_author == get_current_user_id() ) {
1352
- $filtered_posts[] = $post;
1353
- continue;
1354
- }
1355
-
1356
- $restriction = $this->get_post_privacy_settings( $post );
1357
- if ( ! $restriction ) {
1358
- $filtered_posts[] = $post;
1359
- continue;
1360
- }
1361
-
1362
- if ( $is_singular ) {
1363
- $this->singular_page = true;
1364
- }
1365
-
1366
- if ( ! $this->is_restricted( $post->ID ) ) {
1367
- $filtered_posts[] = $post;
1368
- continue;
1369
- } else {
1370
- if ( $is_singular ) {
1371
- if ( ! isset( $restriction['_um_noaccess_action'] ) || '0' == $restriction['_um_noaccess_action'] ) {
1372
- if ( UM()->options()->get( 'disable_restriction_pre_queries' ) || empty( $restriction['_um_access_hide_from_queries'] ) ) {
1373
- /**
1374
- * UM hook
1375
- *
1376
- * @type action
1377
- * @title um_access_fix_external_post_content
1378
- * @description Hook for 3-d party content filtration
1379
- * @change_log
1380
- * ["Since: 2.0"]
1381
- * @usage add_action( 'um_access_fix_external_post_content', 'function_name', 10 );
1382
- * @example
1383
- * <?php
1384
- * add_action( 'um_access_fix_external_post_content', 'my_access_fix_external_post_content', 10 );
1385
- * function my_access_fix_external_post_content() {
1386
- * // your code here
1387
- * }
1388
- * ?>
1389
- */
1390
- do_action( 'um_access_fix_external_post_content' );
1391
-
1392
- $filtered_posts[] = $this->maybe_replace_title( $post );
1393
- continue;
1394
- }
1395
- } elseif ( '1' == $restriction['_um_noaccess_action'] ) {
1396
- $curr = UM()->permalinks()->get_current_url();
1397
-
1398
- if ( ! isset( $restriction['_um_access_redirect'] ) || '0' == $restriction['_um_access_redirect'] ) {
1399
-
1400
- exit( wp_redirect( esc_url( add_query_arg( 'redirect_to', urlencode_deep( $curr ), um_get_core_page( 'login' ) ) ) ) );
1401
-
1402
- } elseif ( '1' == $restriction['_um_access_redirect'] ) {
1403
-
1404
- if ( ! empty( $restriction['_um_access_redirect_url'] ) ) {
1405
- $redirect = $restriction['_um_access_redirect_url'];
1406
- } else {
1407
- $redirect = esc_url( add_query_arg( 'redirect_to', urlencode_deep( $curr ), um_get_core_page( 'login' ) ) );
1408
- }
1409
-
1410
- exit( wp_redirect( $redirect ) );
1411
- }
1412
- }
1413
- } else {
1414
- if ( empty( $restriction['_um_access_hide_from_queries'] ) || ! UM()->options()->get( 'disable_restriction_pre_queries' ) ) {
1415
- $filtered_posts[] = $this->maybe_replace_title( $post );
1416
- continue;
1417
- }
1418
- }
1419
- }
1420
- }
1421
-
1422
- return $filtered_posts;
1423
- }
1424
-
1425
-
1426
- /**
1427
- * Set custom access actions and redirection
1428
- *
1429
- * Old global restrict content logic
1430
- */
1431
- function template_redirect() {
1432
- global $post, $wp_query;
1433
-
1434
- //if we logged by administrator it can access to all content
1435
- if ( current_user_can( 'administrator' ) ) {
1436
- return;
1437
- }
1438
-
1439
- if ( is_object( $wp_query ) ) {
1440
- $is_singular = $wp_query->is_singular();
1441
- } else {
1442
- $is_singular = ! empty( $wp_query->is_singular ) ? true : false;
1443
- }
1444
-
1445
- //if we use individual restrict content options skip this function
1446
- if ( $is_singular && $this->singular_page ) {
1447
- return;
1448
- }
1449
-
1450
- //also skip if we currently at wp-admin or 404 page
1451
- if ( is_admin() || is_404() ) {
1452
- return;
1453
- }
1454
-
1455
- //also skip if we currently at UM Register|Login|Reset Password pages
1456
- if ( um_is_core_post( $post, 'register' ) ||
1457
- um_is_core_post( $post, 'password-reset' ) ||
1458
- um_is_core_post( $post, 'login' ) ) {
1459
- return;
1460
- }
1461
-
1462
- /**
1463
- * UM hook
1464
- *
1465
- * @type action
1466
- * @title um_roles_add_meta_boxes_um_role_meta
1467
- * @description Check terms individual restrict options
1468
- * @change_log
1469
- * ["Since: 2.0"]
1470
- * @usage add_action( 'um_access_check_individual_term_settings', 'function_name', 10 );
1471
- * @example
1472
- * <?php
1473
- * add_action( 'um_access_check_individual_term_settings', 'my_access_check_individual_term_settings', 10 );
1474
- * function my_access_check_individual_term_settings() {
1475
- * // your code here
1476
- * }
1477
- * ?>
1478
- */
1479
- do_action( 'um_access_check_individual_term_settings' );
1480
- //exit from function if term page is accessible
1481
- if ( $this->check_access() ) {
1482
- return;
1483
- }
1484
-
1485
- /**
1486
- * UM hook
1487
- *
1488
- * @type action
1489
- * @title um_access_check_global_settings
1490
- * @description Check global restrict content options
1491
- * @change_log
1492
- * ["Since: 2.0"]
1493
- * @usage add_action( 'um_access_check_global_settings', 'function_name', 10 );
1494
- * @example
1495
- * <?php
1496
- * add_action( 'um_access_check_global_settings', 'my_access_check_global_settings', 10 );
1497
- * function my_access_check_global_settings() {
1498
- * // your code here
1499
- * }
1500
- * ?>
1501
- */
1502
- do_action( 'um_access_check_global_settings' );
1503
-
1504
- $this->check_access();
1505
- }
1506
-
1507
-
1508
- /**
1509
- * Check individual term Content Restriction settings
1510
- */
1511
- function um_access_check_individual_term_settings() {
1512
- //check only tax|tags|categories - skip archive, author, and date lists
1513
- if ( ! ( is_tax() || is_tag() || is_category() ) ) {
1514
- return;
1515
- }
1516
-
1517
- $term_id = null;
1518
- if ( is_tag() ) {
1519
- $term_id = get_query_var( 'tag_id' );
1520
- } elseif ( is_category() ) {
1521
- $term_id = get_query_var( 'cat' );
1522
- } elseif ( is_tax() ) {
1523
- $tax_name = get_query_var( 'taxonomy' );
1524
-
1525
- $term_name = get_query_var( 'term' );
1526
- $term = get_term_by( 'slug', $term_name, $tax_name );
1527
-
1528
- $term_id = ! empty( $term->term_id ) ? $term->term_id : $term_id;
1529
- }
1530
-
1531
- if ( ! isset( $term_id ) ) {
1532
- return;
1533
- }
1534
-
1535
- if ( $this->is_restricted_term( $term_id, true ) ) {
1536
- $restriction = get_term_meta( $term_id, 'um_content_restriction', true );
1537
- if ( '1' == $restriction['_um_noaccess_action'] ) {
1538
- $curr = UM()->permalinks()->get_current_url();
1539
-
1540
- if ( ! isset( $restriction['_um_access_redirect'] ) || '0' == $restriction['_um_access_redirect'] ) {
1541
-
1542
- $this->redirect_handler = $this->set_referer( esc_url( add_query_arg( 'redirect_to', urlencode_deep( $curr ), um_get_core_page( 'login' ) ) ), 'individual_term' );
1543
-
1544
- } elseif ( '1' == $restriction['_um_access_redirect'] ) {
1545
-
1546
- if ( ! empty( $restriction['_um_access_redirect_url'] ) ) {
1547
- $redirect = $restriction['_um_access_redirect_url'];
1548
- } else {
1549
- $redirect = esc_url( add_query_arg( 'redirect_to', urlencode_deep( $curr ), um_get_core_page( 'login' ) ) );
1550
- }
1551
-
1552
- $this->redirect_handler = $this->set_referer( $redirect, 'individual_term' );
1553
-
1554
- }
1555
- } else {
1556
- add_filter( 'tag_template', array( &$this, 'taxonomy_message' ), 10, 3 );
1557
- add_filter( 'archive_template', array( &$this, 'taxonomy_message' ), 10, 3 );
1558
- add_filter( 'category_template', array( &$this, 'taxonomy_message' ), 10, 3 );
1559
- add_filter( 'taxonomy_template', array( &$this, 'taxonomy_message' ), 10, 3 );
1560
- }
1561
- }
1562
- }
1563
-
1564
-
1565
- /**
1566
- * @param $template
1567
- * @param $type
1568
- * @param $templates
1569
- *
1570
- * @return string
1571
- */
1572
- function taxonomy_message( $template, $type, $templates ) {
1573
- return UM()->locate_template( 'restricted-taxonomy.php' );
1574
- }
1575
-
1576
-
1577
- /**
1578
- * Check global accessible settings
1579
- */
1580
- function um_access_check_global_settings() {
1581
- global $post;
1582
-
1583
- $curr = UM()->permalinks()->get_current_url();
1584
- $ms_empty_role_access = is_multisite() && is_user_logged_in() && ! UM()->roles()->get_priority_user_role( um_user( 'ID' ) );
1585
-
1586
- if ( is_front_page() ) {
1587
- if ( is_user_logged_in() && ! $ms_empty_role_access ) {
1588
-
1589
- $user_default_homepage = um_user( 'default_homepage' );
1590
- if ( ! empty( $user_default_homepage ) ) {
1591
- return;
1592
- }
1593
-
1594
- $redirect_homepage = um_user( 'redirect_homepage' );
1595
- /**
1596
- * UM hook
1597
- *
1598
- * @type filter
1599
- * @title um_custom_homepage_redirect_url
1600
- * @description Change custom homepage redirect
1601
- * @input_vars
1602
- * [{"var":"$url","type":"string","desc":"Redirect URL"},
1603
- * {"var":"$id","type":"int","desc":"User ID"}]
1604
- * @change_log
1605
- * ["Since: 2.0"]
1606
- * @usage
1607
- * <?php add_filter( 'um_custom_homepage_redirect_url', 'function_name', 10, 2 ); ?>
1608
- * @example
1609
- * <?php
1610
- * add_filter( 'um_custom_homepage_redirect_url', 'my_custom_homepage_redirect_url', 10, 2 );
1611
- * function my_custom_homepage_redirect_url( $url, $id ) {
1612
- * // your code here
1613
- * return $url;
1614
- * }
1615
- * ?>
1616
- */
1617
- $redirect_homepage = apply_filters( 'um_custom_homepage_redirect_url', $redirect_homepage, um_user( 'ID' ) );
1618
- $redirect_to = ! empty( $redirect_homepage ) ? $redirect_homepage : um_get_core_page( 'user' );
1619
- $this->redirect_handler = $this->set_referer( esc_url( add_query_arg( 'redirect_to', urlencode_deep( $curr ), $redirect_to ) ), 'custom_homepage' );
1620
-
1621
- } else {
1622
- $access = UM()->options()->get( 'accessible' );
1623
-
1624
- if ( $access == 2 ) {
1625
- //global settings for accessible home page
1626
- $home_page_accessible = UM()->options()->get( 'home_page_accessible' );
1627
-
1628
- if ( $home_page_accessible == 0 ) {
1629
- //get redirect URL if not set get login page by default
1630
- $redirect = UM()->options()->get( 'access_redirect' );
1631
- if ( ! $redirect ) {
1632
- $redirect = um_get_core_page( 'login' );
1633
- }
1634
-
1635
- $this->redirect_handler = $this->set_referer( esc_url( add_query_arg( 'redirect_to', urlencode_deep( $curr ), $redirect ) ), 'global' );
1636
- } else {
1637
- $this->allow_access = true;
1638
- return;
1639
- }
1640
- }
1641
- }
1642
- } elseif ( is_category() ) {
1643
- if ( ! is_user_logged_in() || $ms_empty_role_access ) {
1644
-
1645
- $access = UM()->options()->get( 'accessible' );
1646
-
1647
- if ( $access == 2 ) {
1648
- //global settings for accessible home page
1649
- $category_page_accessible = UM()->options()->get( 'category_page_accessible' );
1650
- if ( $category_page_accessible == 0 ) {
1651
- //get redirect URL if not set get login page by default
1652
- $redirect = UM()->options()->get( 'access_redirect' );
1653
- if ( ! $redirect ) {
1654
- $redirect = um_get_core_page( 'login' );
1655
- }
1656
-
1657
- $this->redirect_handler = $this->set_referer( esc_url( add_query_arg( 'redirect_to', urlencode_deep( $curr ), $redirect ) ), 'global' );
1658
- } else {
1659
- $this->allow_access = true;
1660
- return;
1661
- }
1662
- }
1663
- }
1664
- }
1665
-
1666
- $access = UM()->options()->get( 'accessible' );
1667
-
1668
- if ( $access == 2 && ( ! is_user_logged_in() || $ms_empty_role_access ) ) {
1669
-
1670
- //build exclude URLs pages
1671
- $redirects = array();
1672
- $redirects[] = trim( untrailingslashit( UM()->options()->get( 'access_redirect' ) ) );
1673
-
1674
- $exclude_uris = UM()->options()->get( 'access_exclude_uris' );
1675
- if ( ! empty( $exclude_uris ) ) {
1676
- $exclude_uris = array_map( 'trim', $exclude_uris );
1677
- $redirects = array_merge( $redirects, $exclude_uris );
1678
- }
1679
-
1680
- $redirects = array_unique( $redirects );
1681
-
1682
- $current_url = UM()->permalinks()->get_current_url( get_option( 'permalink_structure' ) );
1683
- $current_url = untrailingslashit( $current_url );
1684
- $current_url_slash = trailingslashit( $current_url );
1685
-
1686
- if ( ! ( isset( $post->ID ) && ( in_array( $current_url, $redirects ) || in_array( $current_url_slash, $redirects ) ) ) ) {
1687
- //if current page not in exclude URLs
1688
- //get redirect URL if not set get login page by default
1689
- $redirect = UM()->options()->get( 'access_redirect' );
1690
- if ( ! $redirect ) {
1691
- $redirect = um_get_core_page( 'login' );
1692
- }
1693
-
1694
- $this->redirect_handler = $this->set_referer( esc_url( add_query_arg( 'redirect_to', urlencode_deep( $curr ), $redirect ) ), 'global' );
1695
- } else {
1696
- $this->redirect_handler = false;
1697
- $this->allow_access = true;
1698
- }
1699
- }
1700
- }
1701
-
1702
-
1703
- /**
1704
- * Check access
1705
- *
1706
- * @return bool
1707
- */
1708
- function check_access() {
1709
- if ( $this->allow_access === true ) {
1710
- return true;
1711
- }
1712
-
1713
- if ( $this->redirect_handler ) {
1714
- wp_redirect( $this->redirect_handler );
1715
- exit;
1716
- }
1717
-
1718
- return false;
1719
- }
1720
-
1721
-
1722
- /**
1723
- * Sets a custom access referer in a redirect URL
1724
- *
1725
- * @param string $url
1726
- * @param string $referer
1727
- *
1728
- * @return string
1729
- */
1730
- function set_referer( $url, $referer ) {
1731
-
1732
- /**
1733
- * UM hook
1734
- *
1735
- * @type filter
1736
- * @title um_access_enable_referer
1737
- * @description Access Referrer Enable/Disable
1738
- * @input_vars
1739
- * [{"var":"$referrer","type":"bool","desc":"Access referrer"}]
1740
- * @change_log
1741
- * ["Since: 2.0"]
1742
- * @usage add_filter( 'um_access_enable_referer', 'function_name', 10, 1 );
1743
- * @example
1744
- * <?php
1745
- * add_filter( 'um_access_enable_referer', 'my_access_enable_referer', 10, 1 );
1746
- * function my_access_enable_referer( $referrer ) {
1747
- * // your code here
1748
- * return $referrer;
1749
- * }
1750
- * ?>
1751
- */
1752
- $enable_referer = apply_filters( 'um_access_enable_referer', false );
1753
- if ( ! $enable_referer ) {
1754
- return $url;
1755
- }
1756
-
1757
- $url = add_query_arg( 'um_ref', $referer, $url );
1758
- return $url;
1759
- }
1760
-
1761
-
1762
- /**
1763
- * Get privacy settings for post
1764
- * return false if post is not private
1765
- * Restrict content new logic
1766
- *
1767
- * @param \WP_Post|int $post Post ID or object
1768
- * @return bool|array
1769
- */
1770
- function get_post_privacy_settings( $post ) {
1771
- // break for incorrect post
1772
- if ( empty( $post ) ) {
1773
- return false;
1774
- }
1775
-
1776
- static $cache = array();
1777
-
1778
- $cache_key = is_numeric( $post ) ? $post : $post->ID;
1779
-
1780
- if ( isset( $cache[ $cache_key ] ) ) {
1781
- return $cache[ $cache_key ];
1782
- }
1783
-
1784
- if ( is_numeric( $post ) ) {
1785
- $post = get_post( $post );
1786
- }
1787
-
1788
- //if logged in administrator all pages are visible
1789
- if ( current_user_can( 'administrator' ) ) {
1790
- $cache[ $cache_key ] = false;
1791
- return false;
1792
- }
1793
-
1794
- $exclude = false;
1795
- //exclude from privacy UM default pages (except Members list and User(Profile) page)
1796
- if ( ! empty( $post->post_type ) && $post->post_type === 'page' ) {
1797
-
1798
- if ( um_is_core_post( $post, 'login' ) || um_is_core_post( $post, 'register' ) ||
1799
- um_is_core_post( $post, 'account' ) || um_is_core_post( $post, 'logout' ) ||
1800
- um_is_core_post( $post, 'password-reset' ) || ( is_user_logged_in() && um_is_core_post( $post, 'user' ) ) )
1801
- $exclude = true;
1802
- }
1803
-
1804
- $exclude = apply_filters( 'um_exclude_posts_from_privacy', $exclude, $post );
1805
- if ( $exclude ) {
1806
- $cache[ $cache_key ] = false;
1807
- return false;
1808
- }
1809
-
1810
- $restricted_posts = UM()->options()->get( 'restricted_access_post_metabox' );
1811
-
1812
- if ( ! empty( $post->post_type ) && ! empty( $restricted_posts[ $post->post_type ] ) ) {
1813
- $restriction = get_post_meta( $post->ID, 'um_content_restriction', true );
1814
-
1815
- if ( ! empty( $restriction['_um_custom_access_settings'] ) ) {
1816
- if ( ! isset( $restriction['_um_accessible'] ) ) {
1817
- $restricted_taxonomies = UM()->options()->get( 'restricted_access_taxonomy_metabox' );
1818
-
1819
- //get all taxonomies for current post type
1820
- $taxonomies = get_object_taxonomies( $post );
1821
-
1822
- //get all post terms
1823
- $terms = array();
1824
- if ( ! empty( $taxonomies ) ) {
1825
- foreach ( $taxonomies as $taxonomy ) {
1826
- if ( empty( $restricted_taxonomies[ $taxonomy ] ) ) {
1827
- continue;
1828
- }
1829
-
1830
- $terms = array_merge( $terms, wp_get_post_terms( $post->ID, $taxonomy, array( 'fields' => 'ids', 'um_ignore_exclude' => true, ) ) );
1831
- }
1832
- }
1833
-
1834
- //get restriction options for first term with privacy settigns
1835
- foreach ( $terms as $term_id ) {
1836
- $restriction = get_term_meta( $term_id, 'um_content_restriction', true );
1837
-
1838
- if ( ! empty( $restriction['_um_custom_access_settings'] ) ) {
1839
- if ( ! isset( $restriction['_um_accessible'] ) ) {
1840
- continue;
1841
- } else {
1842
- $cache[ $cache_key ] = $restriction;
1843
- return $restriction;
1844
- }
1845
- }
1846
- }
1847
-
1848
- $cache[ $cache_key ] = false;
1849
- return false;
1850
- } else {
1851
-
1852
- // set default redirect if Profile page is restricted for not-logged in users and showing message instead of redirect
1853
- // this snippet was added to make the same action for {site_url}/user and {site_url}/user/{user_slug} URLs
1854
- // by default {site_url}/user is redirected to Homepage in rewrite rules because hasn't found username in query when user is not logged in
1855
- if ( ! is_user_logged_in() && um_is_core_post( $post, 'user' ) && $restriction['_um_accessible'] == '2' && $restriction['_um_noaccess_action'] == '0' ) {
1856
- if ( isset( $restriction['_um_access_roles'] ) ) {
1857
- $restriction = array(
1858
- '_um_accessible' => '2',
1859
- '_um_access_roles' => $restriction['_um_access_roles'],
1860
- '_um_noaccess_action' => '1',
1861
- '_um_access_redirect' => '1',
1862
- '_um_access_redirect_url' => get_home_url( get_current_blog_id() )
1863
- );
1864
- } else {
1865
- $restriction = array(
1866
- '_um_accessible' => '2',
1867
- '_um_noaccess_action' => '1',
1868
- '_um_access_redirect' => '1',
1869
- '_um_access_redirect_url' => get_home_url( get_current_blog_id() )
1870
- );
1871
- }
1872
- }
1873
-
1874
- $restriction = apply_filters( 'um_post_content_restriction_settings', $restriction, $post );
1875
-
1876
- $cache[ $cache_key ] = $restriction;
1877
- return $restriction;
1878
- }
1879
- }
1880
- }
1881
-
1882
- //post hasn't privacy settings....check all terms of this post
1883
- $restricted_taxonomies = UM()->options()->get( 'restricted_access_taxonomy_metabox' );
1884
-
1885
- //get all taxonomies for current post type
1886
- $taxonomies = get_object_taxonomies( $post );
1887
-
1888
- //get all post terms
1889
- $terms = array();
1890
- if ( ! empty( $taxonomies ) ) {
1891
- foreach ( $taxonomies as $taxonomy ) {
1892
- if ( empty( $restricted_taxonomies[ $taxonomy ] ) ) {
1893
- continue;
1894
- }
1895
-
1896
- $terms = array_merge( $terms, wp_get_post_terms( $post->ID, $taxonomy, array( 'fields' => 'ids', 'um_ignore_exclude' => true, ) ) );
1897
- }
1898
- }
1899
-
1900
- //get restriction options for first term with privacy settings
1901
- foreach ( $terms as $term_id ) {
1902
- $restriction = get_term_meta( $term_id, 'um_content_restriction', true );
1903
-
1904
- if ( ! empty( $restriction['_um_custom_access_settings'] ) ) {
1905
- if ( ! isset( $restriction['_um_accessible'] ) ) {
1906
- continue;
1907
- } else {
1908
- $cache[ $cache_key ] = $restriction;
1909
- return $restriction;
1910
- }
1911
- }
1912
- }
1913
-
1914
- $cache[ $cache_key ] = false;
1915
- //post is public
1916
- return false;
1917
- }
1918
-
1919
-
1920
- /**
1921
- * Helper for checking if the user can some of the roles array
1922
- *
1923
- * @param $user_id
1924
- * @param $roles
1925
- * @return bool
1926
- */
1927
- function user_can( $user_id, $roles ) {
1928
- $user_can = false;
1929
-
1930
- if ( ! empty( $roles ) ) {
1931
- foreach ( $roles as $key => $value ) {
1932
- if ( ! empty( $value ) && user_can( $user_id, $key ) ) {
1933
- $user_can = true;
1934
- break;
1935
- }
1936
- }
1937
- }
1938
-
1939
- return $user_can;
1940
- }
1941
-
1942
-
1943
- /**
1944
- * Helper for 3rd-party integrations with content restriction settings
1945
- *
1946
- * @param array $restriction
1947
- *
1948
- * @return bool
1949
- */
1950
- function um_custom_restriction( $restriction ) {
1951
- /**
1952
- * UM hook
1953
- *
1954
- * @type filter
1955
- * @title um_custom_restriction
1956
- * @description Extend Sort Types for Member Directory
1957
- * @input_vars
1958
- * [{"var":"$custom_restriction","type":"bool","desc":"Custom Restriction"},
1959
- * {"var":"$restriction","type":"array","desc":"Restriction settings"}]
1960
- * @change_log
1961
- * ["Since: 2.0"]
1962
- * @usage add_filter( 'um_custom_restriction', 'function_name', 10, 2 );
1963
- * @example
1964
- * <?php
1965
- * add_filter( 'um_custom_restriction', 'my_custom_restriction', 10, 2 );
1966
- * function my_directory_sort_users_select( $custom_restriction, $restriction ) {
1967
- * // your code here
1968
- * return $custom_restriction;
1969
- * }
1970
- * ?>
1971
- */
1972
- return apply_filters( 'um_custom_restriction', true, $restriction );
1973
- }
1974
-
1975
-
1976
- /**
1977
- * Is post restricted?
1978
- *
1979
- * @param int $post_id
1980
- * @return bool
1981
- */
1982
- function is_restricted( $post_id ) {
1983
- // break for incorrect post
1984
- if ( empty( $post_id ) ) {
1985
- return false;
1986
- }
1987
-
1988
- static $cache = array();
1989
-
1990
- if ( isset( $cache[ $post_id ] ) ) {
1991
- return $cache[ $post_id ];
1992
- }
1993
-
1994
- if ( current_user_can( 'administrator' ) ) {
1995
- $cache[ $post_id ] = false;
1996
- return false;
1997
- }
1998
-
1999
- $post = get_post( $post_id );
2000
- if ( is_user_logged_in() && isset( $post->post_author ) && $post->post_author == get_current_user_id() ) {
2001
- $cache[ $post_id ] = false;
2002
- return false;
2003
- }
2004
-
2005
- $restricted = true;
2006
-
2007
- $restriction = $this->get_post_privacy_settings( $post_id );
2008
- if ( ! $restriction ) {
2009
- $restricted = false;
2010
- } else {
2011
- if ( '0' == $restriction['_um_accessible'] ) {
2012
- //post is private
2013
- $restricted = false;
2014
- } elseif ( '1' == $restriction['_um_accessible'] ) {
2015
- //if post for not logged in users and user is not logged in
2016
- if ( ! is_user_logged_in() ) {
2017
- $restricted = false;
2018
- }
2019
- } elseif ( '2' == $restriction['_um_accessible'] ) {
2020
- //if post for logged in users and user is not logged in
2021
- if ( is_user_logged_in() ) {
2022
- $custom_restrict = $this->um_custom_restriction( $restriction );
2023
-
2024
- if ( empty( $restriction['_um_access_roles'] ) || false === array_search( '1', $restriction['_um_access_roles'] ) ) {
2025
- if ( $custom_restrict ) {
2026
- $restricted = false;
2027
- }
2028
- } else {
2029
- $user_can = $this->user_can( get_current_user_id(), $restriction['_um_access_roles'] );
2030
-
2031
- if ( $user_can && $custom_restrict ) {
2032
- $restricted = false;
2033
- }
2034
- }
2035
- }
2036
- }
2037
- }
2038
-
2039
- $restricted = apply_filters( 'um_is_restricted_post', $restricted, $post_id );
2040
-
2041
- $cache[ $post_id ] = $restricted;
2042
-
2043
- return $restricted;
2044
- }
2045
-
2046
-
2047
- /**
2048
- * Is term restricted?
2049
- *
2050
- * @param int $term_id
2051
- * @param bool $on_term_page
2052
- * @return bool
2053
- */
2054
- function is_restricted_term( $term_id, $on_term_page = false ) {
2055
- static $cache = array();
2056
-
2057
- if ( isset( $cache[ $term_id ] ) ) {
2058
- return $cache[ $term_id ];
2059
- }
2060
-
2061
- if ( current_user_can( 'administrator' ) ) {
2062
- $cache[ $term_id ] = false;
2063
- return false;
2064
- }
2065
-
2066
- $restricted_taxonomies = UM()->options()->get( 'restricted_access_taxonomy_metabox' );
2067
- if ( empty( $restricted_taxonomies ) ) {
2068
- $cache[ $term_id ] = false;
2069
- return false;
2070
- }
2071
-
2072
- $term = get_term( $term_id );
2073
- if ( empty( $term->taxonomy ) || empty( $restricted_taxonomies[ $term->taxonomy ] ) ) {
2074
- $cache[ $term_id ] = false;
2075
- return false;
2076
- }
2077
-
2078
- $restricted = true;
2079
-
2080
- // $this->allow_access = true only in case if the
2081
-
2082
- $restriction = get_term_meta( $term_id, 'um_content_restriction', true );
2083
- if ( empty( $restriction ) ) {
2084
- $restricted = false;
2085
- } else {
2086
- if ( empty( $restriction['_um_custom_access_settings'] ) ) {
2087
- $restricted = false;
2088
- } else {
2089
- if ( '0' == $restriction['_um_accessible'] ) {
2090
- //term is private
2091
- $restricted = false;
2092
- if ( $on_term_page ) {
2093
- $this->allow_access = true;
2094
- }
2095
- } elseif ( '1' == $restriction['_um_accessible'] ) {
2096
- //if term for not logged in users and user is not logged in
2097
- if ( ! is_user_logged_in() ) {
2098
- $restricted = false;
2099
- if ( $on_term_page ) {
2100
- $this->allow_access = true;
2101
- }
2102
- }
2103
- } elseif ( '2' == $restriction['_um_accessible'] ) {
2104
- //if term for logged in users and user is not logged in
2105
- if ( is_user_logged_in() ) {
2106
- $custom_restrict = $this->um_custom_restriction( $restriction );
2107
-
2108
- if ( empty( $restriction['_um_access_roles'] ) || false === array_search( '1', $restriction['_um_access_roles'] ) ) {
2109
- if ( $custom_restrict ) {
2110
- $restricted = false;
2111
- if ( $on_term_page ) {
2112
- $this->allow_access = true;
2113
- }
2114
- }
2115
- } else {
2116
- $user_can = $this->user_can( get_current_user_id(), $restriction['_um_access_roles'] );
2117
-
2118
- if ( $user_can && $custom_restrict ) {
2119
- $restricted = false;
2120
- if ( $on_term_page ) {
2121
- $this->allow_access = true;
2122
- }
2123
- }
2124
- }
2125
- }
2126
- }
2127
- }
2128
- }
2129
-
2130
- $restricted = apply_filters( 'um_is_restricted_term', $restricted, $term_id, $on_term_page );
2131
-
2132
- $cache[ $term_id ] = $restricted;
2133
- return $restricted;
2134
- }
2135
- }
2136
- }
 
 
 
 
 
1
+ <?php
2
+ namespace um\core;
3
+
4
+ // Exit if accessed directly
5
+ if ( ! defined( 'ABSPATH' ) ) exit;
6
+
7
+ if ( ! class_exists( 'um\core\Access' ) ) {
8
+
9
+
10
+ /**
11
+ * Class Access
12
+ * @package um\core
13
+ */
14
+ class Access {
15
+
16
+
17
+ /**
18
+ * If true then we use individual restrict content options
19
+ * for post
20
+ *
21
+ * @var bool
22
+ */
23
+ private $singular_page;
24
+
25
+
26
+ /**
27
+ * @var bool
28
+ */
29
+ private $redirect_handler;
30
+
31
+
32
+ /**
33
+ * @var bool
34
+ */
35
+ private $allow_access;
36
+
37
+
38
+ private $ignore_exclude = false;
39
+
40
+
41
+ /**
42
+ * Access constructor.
43
+ */
44
+ function __construct() {
45
+ $this->singular_page = false;
46
+
47
+ $this->redirect_handler = false;
48
+ $this->allow_access = false;
49
+
50
+ // NEW HOOKS
51
+ // Navigation line below the post content, change query to exclude restricted
52
+ add_filter( 'get_next_post_where', array( &$this, 'exclude_navigation_posts' ), 99, 5 );
53
+ add_filter( 'get_previous_post_where', array( &$this, 'exclude_navigation_posts' ), 99, 5 );
54
+
55
+ // change the title of the post
56
+ add_filter( 'the_title', array( &$this, 'filter_restricted_post_title' ), 10, 2 );
57
+ // change the content of the restricted post
58
+ add_filter( 'the_content', array( &$this, 'filter_restricted_post_content' ), 999999, 1 );
59
+ // change the excerpt of the restricted post
60
+ add_filter( 'get_the_excerpt', array( &$this, 'filter_restricted_post_excerpt' ), 999999, 2 );
61
+
62
+ // filter attachment
63
+ add_filter( 'wp_get_attachment_url', array( &$this, 'filter_attachment' ), 99, 2 );
64
+ add_filter( 'has_post_thumbnail', array( &$this, 'filter_post_thumbnail' ), 99, 3 );
65
+
66
+ // comments queries
67
+ add_action( 'pre_get_comments', array( &$this, 'exclude_posts_comments' ), 99, 1 );
68
+ add_filter( 'wp_count_comments', array( &$this, 'custom_comments_count_handler' ), 99, 2 );
69
+ // comments RSS
70
+ add_filter( 'comment_feed_where', array( &$this, 'exclude_posts_comments_feed' ), 99, 2 );
71
+ // Disable comments if user has not permission to access current post
72
+ add_filter( 'comments_open', array( $this, 'disable_comments_open' ), 99, 2 );
73
+ add_filter( 'get_comments_number', array( $this, 'disable_comments_open_number' ), 99, 2 );
74
+
75
+ // filter menu items
76
+ add_filter( 'wp_nav_menu_objects', array( &$this, 'filter_menu' ), 99, 2 );
77
+
78
+ // Gutenberg blocks restrictions
79
+ add_filter( 'render_block', array( $this, 'restrict_blocks' ), 10, 2 );
80
+
81
+ // check the site's accessible more priority have Individual Post/Term Restriction settings
82
+ add_action( 'template_redirect', array( &$this, 'template_redirect' ), 1000 );
83
+ add_action( 'um_access_check_individual_term_settings', array( &$this, 'um_access_check_individual_term_settings' ) );
84
+ add_action( 'um_access_check_global_settings', array( &$this, 'um_access_check_global_settings' ) );
85
+
86
+ add_action( 'plugins_loaded', array( &$this, 'disable_restriction_pre_queries' ), 1 );
87
+ }
88
+
89
+
90
+ /**
91
+ * Rollback function for old business logic to avoid security enhancements with 404 errors
92
+ */
93
+ function disable_restriction_pre_queries() {
94
+ // Using inside plugins_loaded hook because of there can be earlier direct queries without hooks.
95
+ // Avoid using to not getting fatal error for not exists WordPress native functions.
96
+
97
+ // Change recent posts widget query.
98
+ add_filter( 'widget_posts_args', array( &$this, 'exclude_restricted_posts_widget' ), 99, 1 );
99
+ // Exclude pages displayed by wp_list_pages function.
100
+ add_filter( 'wp_list_pages_excludes', array( &$this, 'exclude_restricted_pages' ), 10, 1 );
101
+ // Archives list change where based on restricted posts.
102
+ add_filter( 'getarchives_where', array( &$this, 'exclude_restricted_posts_archives_widget' ), 99, 2 );
103
+
104
+ // Callbacks for changing posts query.
105
+ add_action( 'pre_get_posts', array( &$this, 'exclude_posts' ), 99, 1 );
106
+ add_filter( 'posts_where', array( &$this, 'exclude_posts_where' ), 10, 2 );
107
+ add_filter( 'wp_count_posts', array( &$this, 'custom_count_posts_handler' ), 99, 3 );
108
+
109
+ // Callbacks for changing terms query.
110
+ add_action( 'pre_get_terms', array( &$this, 'exclude_hidden_terms_query' ), 99, 1 );
111
+
112
+ // there is posts (Posts/Page/CPT) filtration if site is accessible
113
+ // there also will be redirects if they need
114
+ // protect posts types
115
+ add_filter( 'the_posts', array( &$this, 'filter_protected_posts' ), 99, 2 );
116
+ // protect pages for wp_list_pages func
117
+ add_filter( 'get_pages', array( &$this, 'filter_protected_posts' ), 99, 2 );
118
+
119
+ if ( ! UM()->options()->get( 'disable_restriction_pre_queries' ) ) {
120
+ return;
121
+ }
122
+
123
+ remove_action( 'pre_get_terms', array( &$this, 'exclude_hidden_terms_query' ), 99 );
124
+ remove_filter( 'widget_posts_args', array( &$this, 'exclude_restricted_posts_widget' ), 99 );
125
+ remove_filter( 'wp_list_pages_excludes', array( &$this, 'exclude_restricted_pages' ), 10 );
126
+ remove_filter( 'getarchives_where', array( &$this, 'exclude_restricted_posts_archives_widget' ), 99 );
127
+ remove_filter( 'get_next_post_where', array( &$this, 'exclude_navigation_posts' ), 99 );
128
+ remove_filter( 'get_previous_post_where', array( &$this, 'exclude_navigation_posts' ), 99 );
129
+ remove_action( 'pre_get_posts', array( &$this, 'exclude_posts' ), 99 );
130
+ remove_filter( 'posts_where', array( &$this, 'exclude_posts_where' ), 10 );
131
+ remove_filter( 'wp_count_posts', array( &$this, 'custom_count_posts_handler' ), 99 );
132
+ }
133
+
134
+
135
+ /**
136
+ * Get array with restricted posts
137
+ *
138
+ * @param bool $force
139
+ * @param bool|array|string $post_types
140
+ *
141
+ * @return array
142
+ */
143
+ function exclude_posts_array( $force = false, $post_types = false ) {
144
+ if ( $this->ignore_exclude ) {
145
+ return array();
146
+ }
147
+
148
+ static $cache = array();
149
+
150
+ $cache_key = $force ? 'force' : 'default';
151
+
152
+ // `force` cache contains all restricted post IDs we can get them all from cache instead new queries
153
+ $force_cache_key = '';
154
+ if ( 'default' === $cache_key ) {
155
+ $force_cache_key = 'force';
156
+ }
157
+
158
+ // make $post_types as array if string
159
+ if ( ! empty( $post_types ) ) {
160
+ $post_types = is_array( $post_types ) ? $post_types : array( $post_types );
161
+ $cache_key .= md5( serialize( $post_types ) );
162
+ if ( ! empty( $force_cache_key ) ) {
163
+ $force_cache_key .= md5( serialize( $post_types ) );
164
+ }
165
+ }
166
+
167
+ if ( array_key_exists( $cache_key, $cache ) ) {
168
+ return $cache[ $cache_key ];
169
+ }
170
+
171
+ $exclude_posts = array();
172
+ if ( current_user_can( 'administrator' ) ) {
173
+ $cache[ $cache_key ] = $exclude_posts;
174
+ return $exclude_posts;
175
+ }
176
+
177
+ // @todo using Object Cache `wp_cache_get()` `wp_cache_set()` functions
178
+
179
+ // `force` cache contains all restricted post IDs we can get them all from cache instead new queries
180
+ if ( ! empty( $force_cache_key ) && array_key_exists( $force_cache_key, $cache ) ) {
181
+ $post_ids = $cache[ $force_cache_key ];
182
+
183
+ if ( ! empty( $post_ids ) ) {
184
+ foreach ( $post_ids as $post_id ) {
185
+ $content_restriction = $this->get_post_privacy_settings( $post_id );
186
+ if ( ! empty( $content_restriction['_um_access_hide_from_queries'] ) ) {
187
+ array_push( $exclude_posts, $post_id );
188
+ }
189
+ }
190
+ }
191
+ } else {
192
+ $restricted_posts = UM()->options()->get( 'restricted_access_post_metabox' );
193
+ if ( ! empty( $restricted_posts ) ) {
194
+ $restricted_posts = array_keys( $restricted_posts );
195
+ if ( ! empty( $post_types ) ) {
196
+ $restricted_posts = array_intersect( $post_types, $restricted_posts );
197
+ }
198
+ }
199
+
200
+ if ( ! empty( $restricted_posts ) ) {
201
+ $this->ignore_exclude = true;
202
+ // exclude all posts assigned to current term without individual restriction settings
203
+ $post_ids = get_posts(
204
+ array(
205
+ 'fields' => 'ids',
206
+ 'post_status' => 'any',
207
+ 'post_type' => $restricted_posts,
208
+ 'numberposts' => -1,
209
+ 'meta_query' => array(
210
+ array(
211
+ 'key' => 'um_content_restriction',
212
+ 'compare' => 'EXISTS',
213
+ ),
214
+ ),
215
+ )
216
+ );
217
+
218
+ $this->ignore_exclude = false;
219
+ }
220
+
221
+ $post_ids = empty( $post_ids ) ? array() : $post_ids;
222
+
223
+ $restricted_taxonomies = UM()->options()->get( 'restricted_access_taxonomy_metabox' );
224
+
225
+ if ( ! empty( $restricted_taxonomies ) ) {
226
+ $restricted_taxonomies = array_keys( $restricted_taxonomies );
227
+ foreach ( $restricted_taxonomies as $k => $taxonomy ) {
228
+ if ( ! taxonomy_exists( $taxonomy ) ) {
229
+ unset( $restricted_taxonomies[ $k ] );
230
+ }
231
+ }
232
+ $restricted_taxonomies = array_values( $restricted_taxonomies );
233
+
234
+ if ( ! empty( $post_types ) ) {
235
+ $taxonomies = array();
236
+ foreach ( $post_types as $p_t ) {
237
+ $taxonomies = array_merge( $taxonomies, get_object_taxonomies( $p_t ) );
238
+ }
239
+ $restricted_taxonomies = array_intersect( $taxonomies, $restricted_taxonomies );
240
+ }
241
+ }
242
+
243
+ if ( ! empty( $restricted_taxonomies ) ) {
244
+ global $wpdb;
245
+
246
+ $terms = $wpdb->get_results(
247
+ "SELECT tm.term_id AS term_id,
248
+ tt.taxonomy AS taxonomy
249
+ FROM {$wpdb->termmeta} tm
250
+ LEFT JOIN {$wpdb->term_taxonomy} tt ON tt.term_id = tm.term_id
251
+ WHERE tm.meta_key = 'um_content_restriction' AND
252
+ tt.taxonomy IN('" . implode( "','", $restricted_taxonomies ) . "')",
253
+ ARRAY_A
254
+ );
255
+
256
+ if ( ! empty( $terms ) ) {
257
+ foreach ( $terms as $term ) {
258
+ if ( ! $this->is_restricted_term( $term['term_id'] ) ) {
259
+ continue;
260
+ }
261
+
262
+ $taxonomy_data = get_taxonomy( $term['taxonomy'] );
263
+
264
+ $this->ignore_exclude = true;
265
+ // exclude all posts assigned to current term without individual restriction settings
266
+ $posts = get_posts(
267
+ array(
268
+ 'fields' => 'ids',
269
+ 'post_status' => 'any',
270
+ 'post_type' => $taxonomy_data->object_type,
271
+ 'numberposts' => -1,
272
+ 'tax_query' => array(
273
+ array(
274
+ 'taxonomy' => $term['taxonomy'],
275
+ 'field' => 'id',
276
+ 'terms' => $term['term_id'],
277
+ ),
278
+ ),
279
+ 'meta_query' => array(
280
+ 'relation' => 'OR',
281
+ array(
282
+ 'relation' => 'AND',
283
+ array(
284
+ 'key' => 'um_content_restriction',
285
+ 'value' => 's:26:"_um_custom_access_settings";s:1:"1"',
286
+ 'compare' => 'NOT LIKE',
287
+ ),
288
+ array(
289
+ 'key' => 'um_content_restriction',
290
+ 'value' => 's:26:"_um_custom_access_settings";b:1',
291
+ 'compare' => 'NOT LIKE',
292
+ ),
293
+ ),
294
+ array(
295
+ 'key' => 'um_content_restriction',
296
+ 'compare' => 'NOT EXISTS',
297
+ ),
298
+ ),
299
+ )
300
+ );
301
+ $this->ignore_exclude = false;
302
+
303
+ if ( empty( $posts ) ) {
304
+ continue;
305
+ }
306
+
307
+ $post_ids = array_merge( $post_ids, $posts );
308
+ }
309
+ }
310
+ }
311
+
312
+ if ( ! empty( $post_ids ) ) {
313
+ $post_ids = array_unique( $post_ids );
314
+
315
+ foreach ( $post_ids as $post_id ) {
316
+ // handle every post privacy setting based on post type maybe it's inactive for now
317
+ // if individual restriction is enabled then get post terms restriction settings
318
+ if ( $this->is_restricted( $post_id ) ) {
319
+ if ( true === $force ) {
320
+ array_push( $exclude_posts, $post_id );
321
+ } else {
322
+ $content_restriction = $this->get_post_privacy_settings( $post_id );
323
+ if ( ! empty( $content_restriction['_um_access_hide_from_queries'] ) ) {
324
+ array_push( $exclude_posts, $post_id );
325
+ }
326
+ }
327
+ }
328
+ }
329
+ }
330
+ }
331
+
332
+ $exclude_posts = apply_filters( 'um_exclude_restricted_posts_ids', $exclude_posts, $force );
333
+
334
+ $cache[ $cache_key ] = $exclude_posts;
335
+ return $exclude_posts;
336
+ }
337
+
338
+
339
+
340
+ /**
341
+ * Get array with restricted terms
342
+ *
343
+ * @param \WP_Term_Query $query
344
+ *
345
+ * @return array
346
+ */
347
+ function exclude_terms_array( $query ) {
348
+ $exclude = array();
349
+
350
+ $restricted_taxonomies = UM()->options()->get( 'restricted_access_taxonomy_metabox' );
351
+ if ( ! empty( $restricted_taxonomies ) ) {
352
+ $restricted_taxonomies = array_keys( $restricted_taxonomies );
353
+ foreach ( $restricted_taxonomies as $k => $taxonomy ) {
354
+ if ( ! taxonomy_exists( $taxonomy ) ) {
355
+ unset( $restricted_taxonomies[ $k ] );
356
+ }
357
+ }
358
+ $restricted_taxonomies = array_values( $restricted_taxonomies );
359
+
360
+ if ( ! empty( $restricted_taxonomies ) ) {
361
+ if ( isset( $query->query_vars['taxonomy'] ) && is_array( $query->query_vars['taxonomy'] ) ) {
362
+ $restricted_taxonomies = array_intersect( $query->query_vars['taxonomy'], $restricted_taxonomies );
363
+ } elseif ( ! empty( $query->query_vars['term_taxonomy_id'] ) ) {
364
+ $term_taxonomy_ids = is_array( $query->query_vars['term_taxonomy_id'] ) ? $query->query_vars['term_taxonomy_id'] : array( $query->query_vars['term_taxonomy_id'] );
365
+
366
+ global $wpdb;
367
+ $tax_in_query = $wpdb->get_col( "SELECT DISTINCT taxonomy FROM {$wpdb->term_taxonomy} WHERE term_taxonomy_id IN('" . implode( "','", $term_taxonomy_ids ) . "')" );
368
+ if ( ! empty( $tax_in_query ) ) {
369
+ $restricted_taxonomies = array_intersect( $tax_in_query, $restricted_taxonomies );
370
+ } else {
371
+ $restricted_taxonomies = array();
372
+ }
373
+ }
374
+ }
375
+ }
376
+
377
+ if ( empty( $restricted_taxonomies ) ) {
378
+ return $exclude;
379
+ }
380
+
381
+ $cache_key = md5( serialize( $restricted_taxonomies ) );
382
+
383
+ static $cache = array();
384
+
385
+ if ( array_key_exists( $cache_key, $cache ) ) {
386
+ return $cache[ $cache_key ];
387
+ }
388
+
389
+ $term_ids = get_terms(
390
+ array(
391
+ 'taxonomy' => $restricted_taxonomies,
392
+ 'hide_empty' => false,
393
+ 'fields' => 'ids',
394
+ 'meta_query' => array(
395
+ 'key' => 'um_content_restriction',
396
+ 'compare' => 'EXISTS',
397
+ ),
398
+ 'um_ignore_exclude' => true,
399
+ )
400
+ );
401
+
402
+ if ( empty( $term_ids ) || is_wp_error( $term_ids ) ) {
403
+ $cache[ $cache_key ] = $exclude;
404
+ return $exclude;
405
+ }
406
+
407
+ foreach ( $term_ids as $term_id ) {
408
+ if ( $this->is_restricted_term( $term_id ) ) {
409
+ $exclude[] = $term_id;
410
+ }
411
+ }
412
+
413
+ $exclude = apply_filters( 'um_exclude_restricted_terms_ids', $exclude );
414
+ $cache[ $cache_key ] = $exclude;
415
+ return $exclude;
416
+ }
417
+
418
+
419
+ /**
420
+ * @param \WP_Term_Query $query
421
+ */
422
+ function exclude_hidden_terms_query( $query ) {
423
+ if ( current_user_can( 'administrator' ) || ! empty( $query->query_vars['um_ignore_exclude'] ) ) {
424
+ return;
425
+ }
426
+
427
+ $exclude = $this->exclude_terms_array( $query );
428
+ if ( ! empty( $exclude ) ) {
429
+ $query->query_vars['exclude'] = ! empty( $query->query_vars['exclude'] ) ? wp_parse_id_list( $query->query_vars['exclude'] ) : $exclude;
430
+ }
431
+ }
432
+
433
+
434
+ /**
435
+ * @param \WP_Query $query
436
+ */
437
+ function exclude_posts( $query ) {
438
+ if ( current_user_can( 'administrator' ) ) {
439
+ return;
440
+ }
441
+
442
+ // use these functions is_search() || is_admin() for getting force hide all posts
443
+ // don't handle `hide from WP_Query` and show 404 option for searching and wp-admin query
444
+ if ( $query->is_main_query() || ! empty( $query->query_vars['um_main_query'] ) ) {
445
+ $force = is_feed() || is_search() || is_admin();
446
+
447
+ if ( is_object( $query ) ) {
448
+ $is_singular = $query->is_singular();
449
+ } else {
450
+ $is_singular = ! empty( $query->is_singular ) ? true : false;
451
+ }
452
+
453
+ if ( ! $is_singular ) {
454
+ // need to know what post type is here
455
+ $q_values = ! empty( $query->query_vars['post_type'] ) ? $query->query_vars['post_type'] : array();
456
+ if ( ! is_array( $q_values ) ) {
457
+ $q_values = explode( ',', $query->query_vars['post_type'] );
458
+ }
459
+
460
+ // 'any' will cause the query var to be ignored.
461
+ if ( in_array( 'any', $q_values, true ) || empty( $q_values ) ) {
462
+ $exclude_posts = $this->exclude_posts_array( $force );
463
+ } else {
464
+ $exclude_posts = $this->exclude_posts_array( $force, $q_values );
465
+ }
466
+
467
+ if ( ! empty( $exclude_posts ) ) {
468
+ $post__not_in = $query->get( 'post__not_in', array() );
469
+ $query->set( 'post__not_in', array_merge( wp_parse_id_list( $post__not_in ), $exclude_posts ) );
470
+ }
471
+ }
472
+ }
473
+ }
474
+
475
+
476
+ /**
477
+ * Exclude restricted post from query if there is a single query that exclude post_not_in by default in \WP_Query
478
+ *
479
+ * @param string $where
480
+ * @param \WP_Query $query
481
+ *
482
+ * @return mixed
483
+ */
484
+ function exclude_posts_where( $where, $query ) {
485
+ if ( current_user_can( 'administrator' ) ) {
486
+ return $where;
487
+ }
488
+
489
+ if ( ! $query->is_main_query() ) {
490
+ return $where;
491
+ }
492
+
493
+ if ( ! empty( $query->query_vars['p'] ) && $this->is_restricted( $query->query_vars['p'] ) ) {
494
+ $restriction_settings = $this->get_post_privacy_settings( $query->query_vars['p'] );
495
+ if ( ! empty( $restriction_settings['_um_access_hide_from_queries'] ) && ! empty( $query->query_vars['post__not_in'] ) ) {
496
+ global $wpdb;
497
+ $post__not_in = implode( ',', array_map( 'absint', $query->query_vars['post__not_in'] ) );
498
+ $where .= " AND {$wpdb->posts}.ID NOT IN ($post__not_in)";
499
+ }
500
+ }
501
+
502
+ return $where;
503
+ }
504
+
505
+
506
+ /**
507
+ * Change the posts count based on restriction settings
508
+ *
509
+ * @param object $counts Post counts
510
+ * @param string $type Post type
511
+ * @param string $perm The permission to determine if the posts are 'readable'
512
+ * by the current user.
513
+ *
514
+ * @return object
515
+ */
516
+ function custom_count_posts_handler( $counts, $type = 'post', $perm = '' ) {
517
+ if ( current_user_can( 'administrator' ) ) {
518
+ return $counts;
519
+ }
520
+
521
+ global $wpdb;
522
+
523
+ static $cache = array();
524
+
525
+ $cache_key = _count_posts_cache_key( $type, $perm );
526
+ $force = is_feed() || is_search() || is_admin();
527
+ $cache_key .= $force ? 'force' : '';
528
+
529
+ if ( array_key_exists( $cache_key, $cache ) ) {
530
+ return $cache[ $cache_key ];
531
+ }
532
+
533
+ $exclude_posts = $this->exclude_posts_array( $force, array( $type ) );
534
+ if ( empty( $exclude_posts ) ) {
535
+ $cache[ $cache_key ] = $counts;
536
+ return $counts;
537
+ }
538
+
539
+ $query = "SELECT post_status, COUNT( * ) AS num_posts FROM {$wpdb->posts} WHERE post_type = %s";
540
+
541
+ if ( 'readable' === $perm && is_user_logged_in() ) {
542
+ $post_type_object = get_post_type_object( $type );
543
+ if ( ! current_user_can( $post_type_object->cap->read_private_posts ) ) {
544
+ $query .= $wpdb->prepare(
545
+ " AND (post_status != 'private' OR ( post_author = %d AND post_status = 'private' ))",
546
+ get_current_user_id()
547
+ );
548
+ }
549
+ }
550
+
551
+ $query .= " AND ID NOT IN('" . implode( "','", $exclude_posts ) . "')";
552
+
553
+ $query .= ' GROUP BY post_status';
554
+
555
+ $results = (array) $wpdb->get_results( $wpdb->prepare( $query, $type ), ARRAY_A );
556
+ $counts = array_fill_keys( get_post_stati(), 0 );
557
+
558
+ foreach ( $results as $row ) {
559
+ $counts[ $row['post_status'] ] = $row['num_posts'];
560
+ }
561
+
562
+ $counts = (object) $counts;
563
+
564
+ $cache[ $cache_key ] = $counts;
565
+ return $counts;
566
+ }
567
+
568
+
569
+ /**
570
+ * Exclude restricted posts in Recent Posts widget
571
+ *
572
+ * @param array $array Query args
573
+ *
574
+ * @return array
575
+ */
576
+ function exclude_restricted_posts_widget( $array ) {
577
+ if ( current_user_can( 'administrator' ) ) {
578
+ return $array;
579
+ }
580
+
581
+ $exclude_posts = $this->exclude_posts_array( false, 'post' );
582
+ if ( ! empty( $exclude_posts ) ) {
583
+ $post__not_in = ! empty( $array['post__not_in'] ) ? $array['post__not_in'] : array();
584
+ $array['post__not_in'] = array_merge( wp_parse_id_list( $post__not_in ), $exclude_posts );
585
+ }
586
+
587
+ return $array;
588
+ }
589
+
590
+
591
+ /**
592
+ * Exclude restricted posts in Recent Posts widget
593
+ *
594
+ * @param array $array Query args
595
+ *
596
+ * @return array
597
+ */
598
+ function exclude_restricted_pages( $array ) {
599
+ if ( current_user_can( 'administrator' ) ) {
600
+ return $array;
601
+ }
602
+
603
+ $exclude_posts = $this->exclude_posts_array( false, 'page' );
604
+ if ( ! empty( $exclude_posts ) ) {
605
+ $array = array_merge( $array, $exclude_posts );
606
+ }
607
+
608
+ return $array;
609
+ }
610
+
611
+
612
+ /**
613
+ * Exclude restricted posts in widgets
614
+ *
615
+ * @param string $sql_where
616
+ * @param array $parsed_args
617
+ *
618
+ * @return string
619
+ */
620
+ function exclude_restricted_posts_archives_widget( $sql_where, $parsed_args = array() ) {
621
+ if ( current_user_can( 'administrator' ) ) {
622
+ return $sql_where;
623
+ }
624
+
625
+ $post_type = ! empty( $parsed_args['post_type'] ) ? $parsed_args['post_type'] : false;
626
+
627
+ $exclude_posts = $this->exclude_posts_array( false, $post_type );
628
+ if ( ! empty( $exclude_posts ) ) {
629
+ $exclude_string = implode( ',', $exclude_posts );
630
+ $sql_where .= ' AND ID NOT IN ( ' . $exclude_string . ' )';
631
+ }
632
+
633
+ return $sql_where;
634
+ }
635
+
636
+
637
+ /**
638
+ * Exclude posts from next, previous navigation
639
+ *
640
+ * @param string $where
641
+ * @param bool $in_same_term
642
+ * @param string|array $excluded_terms
643
+ * @param string $taxonomy
644
+ * @param null|\WP_Post $post
645
+ *
646
+ * @return string
647
+ */
648
+ function exclude_navigation_posts( $where, $in_same_term = false, $excluded_terms = '', $taxonomy = 'category', $post = null ) {
649
+ if ( current_user_can( 'administrator' ) ) {
650
+ return $where;
651
+ }
652
+
653
+ if ( empty( $post ) ) {
654
+ return $where;
655
+ }
656
+
657
+ $exclude_posts = $this->exclude_posts_array( false, $post->post_type );
658
+ if ( ! empty( $exclude_posts ) ) {
659
+ $exclude_string = implode( ',', $exclude_posts );
660
+ $where .= ' AND ID NOT IN ( ' . $exclude_string . ' )';
661
+ }
662
+
663
+ return $where;
664
+ }
665
+
666
+
667
+ /**
668
+ * Replace titles of restricted posts
669
+ *
670
+ * @param string $title
671
+ * @param int|null $id
672
+ *
673
+ * @return string
674
+ */
675
+ function filter_restricted_post_title( $title, $id = null ) {
676
+ if ( ! UM()->options()->get( 'restricted_post_title_replace' ) ) {
677
+ return $title;
678
+ }
679
+
680
+ if ( current_user_can( 'administrator' ) ) {
681
+ return $title;
682
+ }
683
+
684
+ if ( ! isset( $id ) ) {
685
+ return $title;
686
+ }
687
+
688
+ if ( ! is_numeric( $id ) ) {
689
+ $id = absint( $id );
690
+ }
691
+
692
+ $ignore = apply_filters( 'um_ignore_restricted_title', false, $id );
693
+ if ( $ignore ) {
694
+ return $title;
695
+ }
696
+
697
+ if ( $this->is_restricted( $id ) ) {
698
+ $restricted_global_title = UM()->options()->get( 'restricted_access_post_title' );
699
+ $title = stripslashes( $restricted_global_title );
700
+ }
701
+
702
+ return $title;
703
+ }
704
+
705
+
706
+ /**
707
+ * Replace content of restricted posts
708
+ *
709
+ * @param string $content
710
+ *
711
+ * @return string
712
+ */
713
+ function filter_restricted_post_content( $content ) {
714
+ if ( current_user_can( 'administrator' ) ) {
715
+ return $content;
716
+ }
717
+
718
+ $id = get_the_ID();
719
+ if ( ! $id || is_admin() ) {
720
+ return $content;
721
+ }
722
+
723
+ $ignore = apply_filters( 'um_ignore_restricted_content', false, $id );
724
+ if ( $ignore ) {
725
+ return $content;
726
+ }
727
+
728
+ if ( $this->is_restricted( $id ) ) {
729
+ $restriction = $this->get_post_privacy_settings( $id );
730
+
731
+ if ( ! isset( $restriction['_um_restrict_by_custom_message'] ) || '0' == $restriction['_um_restrict_by_custom_message'] ) {
732
+ $content = stripslashes( UM()->options()->get( 'restricted_access_message' ) );
733
+ } elseif ( '1' == $restriction['_um_restrict_by_custom_message'] ) {
734
+ $content = ! empty( $restriction['_um_restrict_custom_message'] ) ? stripslashes( $restriction['_um_restrict_custom_message'] ) : '';
735
+ }
736
+
737
+ // translators: %s: Restricted post message.
738
+ $content = sprintf( __( '%s', 'ultimate-member' ), $content );
739
+ }
740
+
741
+ return $content;
742
+ }
743
+
744
+
745
+ /**
746
+ * Replace excerpt of restricted posts
747
+ *
748
+ * @param string $post_excerpt
749
+ * @param \WP_Post $post
750
+ *
751
+ * @return string
752
+ */
753
+ function filter_restricted_post_excerpt( $post_excerpt = '', $post = null ) {
754
+ if ( empty( $post ) ) {
755
+ return $post_excerpt;
756
+ }
757
+
758
+ if ( current_user_can( 'administrator' ) || is_admin() ) {
759
+ return $post_excerpt;
760
+ }
761
+
762
+ $ignore = apply_filters( 'um_ignore_restricted_excerpt', false, $post->ID );
763
+ if ( $ignore ) {
764
+ return $post_excerpt;
765
+ }
766
+
767
+ if ( $this->is_restricted( $post->ID ) ) {
768
+ $post_excerpt = '';
769
+ }
770
+
771
+ return $post_excerpt;
772
+ }
773
+
774
+
775
+ /**
776
+ * Hide attachment if the post is restricted
777
+ *
778
+ * @param string $url
779
+ * @param int $attachment_id
780
+ *
781
+ * @return boolean|string
782
+ */
783
+ function filter_attachment( $url, $attachment_id ) {
784
+ if ( current_user_can( 'administrator' ) ) {
785
+ return $url;
786
+ }
787
+
788
+ return ( $attachment_id && $this->is_restricted( $attachment_id ) ) ? false : $url;
789
+ }
790
+
791
+
792
+ /**
793
+ * Hide attachment if the post is restricted
794
+ *
795
+ * @param $has_thumbnail
796
+ * @param $post
797
+ * @param $thumbnail_id
798
+ *
799
+ * @return bool
800
+ */
801
+ function filter_post_thumbnail( $has_thumbnail, $post = null, $thumbnail_id = false ) {
802
+ if ( empty( $thumbnail_id ) ) {
803
+ return $has_thumbnail;
804
+ }
805
+
806
+ if ( current_user_can( 'administrator' ) ) {
807
+ return $has_thumbnail;
808
+ }
809
+
810
+ if ( $this->is_restricted( $thumbnail_id ) ) {
811
+ $has_thumbnail = false;
812
+ } elseif ( ! empty( $post ) && ! empty( $post->ID ) ) {
813
+ if ( $this->is_restricted( $post->ID ) ) {
814
+ $has_thumbnail = false;
815
+ }
816
+ } else {
817
+ $post_id = get_the_ID();
818
+ if ( false !== $post_id && $this->is_restricted( $post_id ) ) {
819
+ $has_thumbnail = false;
820
+ }
821
+ }
822
+
823
+ $has_thumbnail = apply_filters( 'um_restrict_post_thumbnail', $has_thumbnail, $post, $thumbnail_id );
824
+
825
+ return $has_thumbnail;
826
+ }
827
+
828
+
829
+
830
+ /**
831
+ * Exclude comments from restricted posts in widgets
832
+ *
833
+ * @param \WP_Comment_Query $query
834
+ */
835
+ function exclude_posts_comments( $query ) {
836
+ if ( current_user_can( 'administrator' ) ) {
837
+ return;
838
+ }
839
+
840
+ if ( ! empty( $query->query_vars['post_id'] ) ) {
841
+ $exclude_posts = array();
842
+ if ( $this->is_restricted( $query->query_vars['post_id'] ) ) {
843
+ $exclude_posts[] = $query->query_vars['post_id'];
844
+ }
845
+ } else {
846
+ $q_values = ! empty( $query->query_vars['post_type'] ) ? $query->query_vars['post_type'] : array();
847
+ if ( ! is_array( $q_values ) ) {
848
+ $q_values = explode( ',', $query->query_vars['post_type'] );
849
+ }
850
+
851
+ // 'any' will cause the query var to be ignored.
852
+ if ( in_array( 'any', $q_values, true ) || empty( $q_values ) ) {
853
+ $exclude_posts = $this->exclude_posts_array( true, $this->get_available_comments_post_types() );
854
+ } else {
855
+ $exclude_posts = $this->exclude_posts_array( true, $q_values );
856
+ }
857
+ }
858
+
859
+ if ( ! empty( $exclude_posts ) ) {
860
+ $post__not_in = ! empty( $query->query_vars['post__not_in'] ) ? $query->query_vars['post__not_in'] : array();
861
+ $query->query_vars['post__not_in'] = array_merge( wp_parse_id_list( $post__not_in ), $exclude_posts );
862
+ }
863
+ }
864
+
865
+
866
+ /**
867
+ * @return array
868
+ */
869
+ function get_available_comments_post_types() {
870
+ global $wp_taxonomies, $wpdb;
871
+
872
+ $restricted_posts = UM()->options()->get( 'restricted_access_post_metabox' );
873
+ if ( empty( $restricted_posts ) ) {
874
+ $restricted_posts = array();
875
+ }
876
+ $restricted_posts = array_keys( $restricted_posts );
877
+
878
+ $restricted_taxonomies = UM()->options()->get( 'restricted_access_taxonomy_metabox' );
879
+ if ( ! empty( $restricted_taxonomies ) ) {
880
+ $restricted_taxonomies = array_keys( $restricted_taxonomies );
881
+ foreach ( $restricted_taxonomies as $k => $taxonomy ) {
882
+ if ( taxonomy_exists( $taxonomy ) ) {
883
+ $restricted_posts = array_merge( $restricted_posts, $wp_taxonomies[ $taxonomy ]->object_type );
884
+ }
885
+ }
886
+ }
887
+
888
+ $restricted_posts = array_unique( $restricted_posts );
889
+ foreach ( $restricted_posts as $k => $post_type ) {
890
+ if ( 'closed' === get_default_comment_status( $post_type ) ) {
891
+ $open_comments = $wpdb->get_var( $wpdb->prepare(
892
+ "SELECT ID
893
+ FROM {$wpdb->posts}
894
+ WHERE post_type = %s AND
895
+ comment_status != 'closed'",
896
+ $post_type
897
+ ) );
898
+
899
+ if ( empty( $open_comments ) ) {
900
+ unset( $restricted_posts[ $k ] );
901
+ }
902
+ }
903
+ }
904
+
905
+ $restricted_posts = array_values( $restricted_posts );
906
+
907
+ return $restricted_posts;
908
+ }
909
+
910
+
911
+ /**
912
+ * Exclude comments from comments feed
913
+ *
914
+ * @param string $where
915
+ * @param \WP_Query $query
916
+ *
917
+ * @return string
918
+ */
919
+ function exclude_posts_comments_feed( $where, $query ) {
920
+ if ( current_user_can( 'administrator' ) ) {
921
+ return $where;
922
+ }
923
+
924
+ $exclude_posts = $this->exclude_posts_array( true, $this->get_available_comments_post_types() );
925
+ if ( ! empty( $exclude_posts ) ) {
926
+ $exclude_string = implode( ',', $exclude_posts );
927
+ $where .= ' AND comment_post_ID NOT IN ( ' . $exclude_string . ' )';
928
+ }
929
+
930
+ return $where;
931
+ }
932
+
933
+
934
+ /**
935
+ * @param array|object $stats
936
+ * @param int $post_id Post ID. Can be 0 for the whole website
937
+ *
938
+ * @return object
939
+ */
940
+ function custom_comments_count_handler( $stats = array(), $post_id = 0 ) {
941
+ if ( ! empty( $stats ) || current_user_can( 'administrator' ) ) {
942
+ return $stats;
943
+ }
944
+
945
+ if ( $post_id === 0 ) {
946
+ $exclude_posts = $this->exclude_posts_array( true, $this->get_available_comments_post_types() );
947
+ if ( empty( $exclude_posts ) ) {
948
+ return $stats;
949
+ }
950
+ } else {
951
+ $exclude_posts = array();
952
+ if ( $this->is_restricted( $post_id ) ) {
953
+ $exclude_posts[] = $post_id;
954
+ }
955
+ }
956
+
957
+ $stats = $this->get_comment_count( $post_id, $exclude_posts );
958
+ $stats['moderated'] = $stats['awaiting_moderation'];
959
+ unset( $stats['awaiting_moderation'] );
960
+
961
+ $stats_object = (object) $stats;
962
+
963
+ return $stats_object;
964
+ }
965
+
966
+
967
+ /**
968
+ * @param int $post_id
969
+ * @param array $exclude_posts
970
+ *
971
+ * @return array
972
+ */
973
+ function get_comment_count( $post_id = 0, $exclude_posts = array() ) {
974
+ static $cache = array();
975
+
976
+ if ( isset( $cache[ $post_id ] ) ) {
977
+ return $cache[ $post_id ];
978
+ }
979
+
980
+ global $wpdb;
981
+
982
+ $post_id = (int) $post_id;
983
+
984
+ $where = 'WHERE 1=1';
985
+ if ( $post_id > 0 ) {
986
+ $where .= $wpdb->prepare( ' AND comment_post_ID = %d', $post_id );
987
+ }
988
+
989
+ if ( ! empty( $exclude_posts ) ) {
990
+ $exclude_string = implode( ',', $exclude_posts );
991
+ $where .= ' AND comment_post_ID NOT IN ( ' . $exclude_string . ' )';
992
+ }
993
+
994
+ $totals = (array) $wpdb->get_results(
995
+ "
996
+ SELECT comment_approved, COUNT( * ) AS total
997
+ FROM {$wpdb->comments}
998
+ {$where}
999
+ GROUP BY comment_approved
1000
+ ",
1001
+ ARRAY_A
1002
+ );
1003
+
1004
+ $comment_count = array(
1005
+ 'approved' => 0,
1006
+ 'awaiting_moderation' => 0,
1007
+ 'spam' => 0,
1008
+ 'trash' => 0,
1009
+ 'post-trashed' => 0,
1010
+ 'total_comments' => 0,
1011
+ 'all' => 0,
1012
+ );
1013
+
1014
+ foreach ( $totals as $row ) {
1015
+ switch ( $row['comment_approved'] ) {
1016
+ case 'trash':
1017
+ $comment_count['trash'] = $row['total'];
1018
+ break;
1019
+ case 'post-trashed':
1020
+ $comment_count['post-trashed'] = $row['total'];
1021
+ break;
1022
+ case 'spam':
1023
+ $comment_count['spam'] = $row['total'];
1024
+ $comment_count['total_comments'] += $row['total'];
1025
+ break;
1026
+ case '1':
1027
+ $comment_count['approved'] = $row['total'];
1028
+ $comment_count['total_comments'] += $row['total'];
1029
+ $comment_count['all'] += $row['total'];
1030
+ break;
1031
+ case '0':
1032
+ $comment_count['awaiting_moderation'] = $row['total'];
1033
+ $comment_count['total_comments'] += $row['total'];
1034
+ $comment_count['all'] += $row['total'];
1035
+ break;
1036
+ default:
1037
+ break;
1038
+ }
1039
+ }
1040
+
1041
+ $comment_count = array_map( 'intval', $comment_count );
1042
+ $cache[ $post_id ] = $comment_count;
1043
+
1044
+ return $comment_count;
1045
+ }
1046
+
1047
+
1048
+ /**
1049
+ * Disable comments if user has not permission to access this post
1050
+ *
1051
+ * @param mixed $open
1052
+ * @param int $post_id
1053
+ * @return boolean
1054
+ */
1055
+ function disable_comments_open( $open, $post_id ) {
1056
+ if ( current_user_can( 'administrator' ) ) {
1057
+ return $open;
1058
+ }
1059
+
1060
+ static $cache = array();
1061
+
1062
+ if ( isset( $cache[ $post_id ] ) ) {
1063
+ return $cache[ $post_id ] ? $open : false;
1064
+ }
1065
+
1066
+ if ( ! $this->is_restricted( $post_id ) ) {
1067
+ $cache[ $post_id ] = $open;
1068
+ return $open;
1069
+ }
1070
+
1071
+ $open = false;
1072
+
1073
+ $cache[ $post_id ] = $open;
1074
+ return $open;
1075
+ }
1076
+
1077
+
1078
+ /**
1079
+ * Disable comments if user has not permission to access this post
1080
+ *
1081
+ * @param int $count
1082
+ * @param int $post_id
1083
+ * @return boolean
1084
+ */
1085
+ function disable_comments_open_number( $count, $post_id = 0 ) {
1086
+ if ( current_user_can( 'administrator' ) ) {
1087
+ return $count;
1088
+ }
1089
+
1090
+ static $cache_number = array();
1091
+
1092
+ if ( isset( $cache_number[ $post_id ] ) ) {
1093
+ return $cache_number[ $post_id ];
1094
+ }
1095
+
1096
+ if ( ! $this->is_restricted( $post_id ) ) {
1097
+ $cache_number[ $post_id ] = $count;
1098
+ return $count;
1099
+ }
1100
+
1101
+ $count = 0;
1102
+
1103
+ $cache_number[ $post_id ] = $count;
1104
+ return $count;
1105
+ }
1106
+
1107
+
1108
+ /**
1109
+ * Protect Post Types in menu query
1110
+ * Restrict content new logic
1111
+ * @param array $menu_items
1112
+ * @param array $args
1113
+ * @return array
1114
+ */
1115
+ function filter_menu( $menu_items, $args = array() ) {
1116
+ //if empty
1117
+ if ( empty( $menu_items ) ) {
1118
+ return $menu_items;
1119
+ }
1120
+
1121
+ if ( current_user_can( 'administrator' ) ) {
1122
+ return $menu_items;
1123
+ }
1124
+
1125
+ $filtered_items = array();
1126
+
1127
+ //other filter
1128
+ foreach ( $menu_items as $menu_item ) {
1129
+ if ( ! empty( $menu_item->object_id ) && ! empty( $menu_item->object ) ) {
1130
+ if ( isset( $menu_item->type ) && 'taxonomy' === $menu_item->type ) {
1131
+ if ( ! $this->is_restricted_term( $menu_item->object_id ) ) {
1132
+ $filtered_items[] = $menu_item;
1133
+ continue;
1134
+ }
1135
+ } elseif ( isset( $menu_item->type ) && 'post_type' === $menu_item->type ) {
1136
+ if ( ! $this->is_restricted( $menu_item->object_id ) ) {
1137
+ $filtered_items[] = $menu_item;
1138
+ continue;
1139
+ } else {
1140
+ $restriction_settings = $this->get_post_privacy_settings( $menu_item->object_id );
1141
+ if ( empty( $restriction_settings['_um_access_hide_from_queries'] ) || UM()->options()->get( 'disable_restriction_pre_queries' ) ) {
1142
+ $filtered_items[] = $this->maybe_replace_nav_menu_title( $menu_item );
1143
+ continue;
1144
+ }
1145
+ }
1146
+ } elseif ( isset( $menu_item->type ) && 'custom' === $menu_item->type ) {
1147
+ $filtered_items[] = $menu_item;
1148
+ continue;
1149
+ } else {
1150
+ $filtered_items[] = $menu_item;
1151
+ continue;
1152
+ }
1153
+ } else {
1154
+ //add all other posts
1155
+ $filtered_items[] = $menu_item;
1156
+ }
1157
+ }
1158
+
1159
+ return $filtered_items;
1160
+ }
1161
+
1162
+
1163
+ /**
1164
+ * @param $block_content
1165
+ * @param $block
1166
+ *
1167
+ * @return string
1168
+ */
1169
+ function restrict_blocks( $block_content, $block ) {
1170
+ if ( is_admin() ) {
1171
+ return $block_content;
1172
+ }
1173
+
1174
+ $restricted_blocks = UM()->options()->get( 'restricted_blocks' );
1175
+ if ( empty( $restricted_blocks ) ) {
1176
+ return $block_content;
1177
+ }
1178
+
1179
+ if ( is_user_logged_in() && current_user_can( 'administrator' ) ) {
1180
+ return $block_content;
1181
+ }
1182
+
1183
+ if ( ! isset( $block['attrs']['um_is_restrict'] ) || $block['attrs']['um_is_restrict'] !== true ) {
1184
+ return $block_content;
1185
+ }
1186
+
1187
+ if ( empty( $block['attrs']['um_who_access'] ) ) {
1188
+ return $block_content;
1189
+ }
1190
+
1191
+ $default_message = UM()->options()->get( 'restricted_block_message' );
1192
+ switch ( $block['attrs']['um_who_access'] ) {
1193
+ case '1': {
1194
+ if ( ! is_user_logged_in() ) {
1195
+ $block_content = '';
1196
+ if ( isset( $block['attrs']['um_message_type'] ) ) {
1197
+ if ( $block['attrs']['um_message_type'] == '1' ) {
1198
+ $block_content = $default_message;
1199
+ } elseif ( $block['attrs']['um_message_type'] == '2' ) {
1200
+ $block_content = $block['attrs']['um_message_content'];
1201
+ }
1202
+ }
1203
+ } else {
1204
+ $display = true;
1205
+
1206
+ // What roles can access this content?
1207
+ if ( ! empty( $block['attrs']['um_roles_access'] ) ) {
1208
+ $display = false;
1209
+ foreach ( $block['attrs']['um_roles_access'] as $role ) {
1210
+ if ( current_user_can( $role ) ) {
1211
+ $display = true;
1212
+ }
1213
+ }
1214
+ }
1215
+
1216
+ $display = apply_filters( 'um_loggedin_block_restriction', $display, $block );
1217
+
1218
+ if ( ! $display ) {
1219
+ $block_content = '';
1220
+ if ( isset( $block['attrs']['um_message_type'] ) ) {
1221
+ if ( $block['attrs']['um_message_type'] == '1' ) {
1222
+ $block_content = $default_message;
1223
+ } elseif ( $block['attrs']['um_message_type'] == '2' ) {
1224
+ $block_content = $block['attrs']['um_message_content'];
1225
+ }
1226
+ }
1227
+ }
1228
+ }
1229
+ break;
1230
+ }
1231
+ case '2': {
1232
+ if ( is_user_logged_in() ) {
1233
+ $block_content = '';
1234
+ if ( isset( $block['attrs']['um_message_type'] ) ) {
1235
+ if ( $block['attrs']['um_message_type'] == '1' ) {
1236
+ $block_content = $default_message;
1237
+ } elseif ( $block['attrs']['um_message_type'] == '2' ) {
1238
+ $block_content = $block['attrs']['um_message_content'];
1239
+ }
1240
+ }
1241
+ }
1242
+ break;
1243
+ }
1244
+ }
1245
+
1246
+ return $block_content;
1247
+ }
1248
+
1249
+
1250
+ /**
1251
+ * @param \WP_Post $post
1252
+ *
1253
+ * @return \WP_Post
1254
+ */
1255
+ function maybe_replace_title( $post ) {
1256
+ if ( ! UM()->options()->get( 'restricted_post_title_replace' ) ) {
1257
+ return $post;
1258
+ }
1259
+
1260
+ if ( current_user_can( 'administrator' ) ) {
1261
+ return $post;
1262
+ }
1263
+
1264
+ if ( ! is_a( $post, '\WP_Post' ) ) {
1265
+ return $post;
1266
+ }
1267
+
1268
+ $ignore = apply_filters( 'um_ignore_restricted_title', false, $post->ID );
1269
+ if ( $ignore ) {
1270
+ return $post;
1271
+ }
1272
+
1273
+ $restricted_global_title = UM()->options()->get( 'restricted_access_post_title' );
1274
+ $post->post_title = stripslashes( $restricted_global_title );
1275
+
1276
+ return $post;
1277
+ }
1278
+
1279
+
1280
+ /**
1281
+ * @param \WP_Post $nav_item
1282
+ *
1283
+ * @return \WP_Post
1284
+ */
1285
+ function maybe_replace_nav_menu_title( $nav_item ) {
1286
+ if ( ! UM()->options()->get( 'restricted_post_title_replace' ) ) {
1287
+ return $nav_item;
1288
+ }
1289
+
1290
+ if ( current_user_can( 'administrator' ) ) {
1291
+ return $nav_item;
1292
+ }
1293
+
1294
+ if ( ! is_a( $nav_item, '\WP_Post' ) ) {
1295
+ return $nav_item;
1296
+ }
1297
+
1298
+ $ignore = apply_filters( 'um_ignore_restricted_title', false, $nav_item->ID );
1299
+ if ( $ignore ) {
1300
+ return $nav_item;
1301
+ }
1302
+
1303
+ $restricted_global_title = UM()->options()->get( 'restricted_access_post_title' );
1304
+ $nav_item->title = stripslashes( $restricted_global_title );
1305
+
1306
+ return $nav_item;
1307
+ }
1308
+
1309
+
1310
+ /**
1311
+ * Protect Post Types in query
1312
+ * Restrict content new logic
1313
+ *
1314
+ * @param array $posts
1315
+ * @param array|\WP_Query $query
1316
+ * @return array
1317
+ */
1318
+ function filter_protected_posts( $posts, $query ) {
1319
+ if ( current_user_can( 'administrator' ) ) {
1320
+ return $posts;
1321
+ }
1322
+
1323
+ //Woocommerce AJAX fixes....remove filtration on wc-ajax which goes to Front Page
1324
+ if ( ! empty( $_GET['wc-ajax'] ) && defined( 'WC_DOING_AJAX' ) && WC_DOING_AJAX ) {
1325
+ return $posts;
1326
+ }
1327
+
1328
+ //if empty
1329
+ if ( empty( $posts ) || is_admin() ) {
1330
+ return $posts;
1331
+ }
1332
+
1333
+ if ( is_object( $query ) ) {
1334
+ $is_singular = $query->is_singular();
1335
+ } else {
1336
+ $is_singular = ! empty( $query->is_singular ) ? true : false;
1337
+ }
1338
+
1339
+ if ( is_object( $query ) && is_a( $query, '\WP_Query' ) &&
1340
+ ( $query->is_main_query() || ! empty( $query->query_vars['um_main_query'] ) ) ) {
1341
+ if ( $is_singular ) {
1342
+ if ( ! UM()->options()->get( 'disable_restriction_pre_queries' ) && $this->is_restricted( $posts[0]->ID ) ) {
1343
+ $content_restriction = $this->get_post_privacy_settings( $posts[0]->ID );
1344
+ if ( ! empty( $content_restriction['_um_access_hide_from_queries'] ) ) {
1345
+ unset( $posts[0] );
1346
+ return $posts;
1347
+ }
1348
+ }
1349
+ }
1350
+ }
1351
+
1352
+ $filtered_posts = array();
1353
+
1354
+ //other filter
1355
+ foreach ( $posts as $post ) {
1356
+ if ( is_user_logged_in() && isset( $post->post_author ) && $post->post_author == get_current_user_id() ) {
1357
+ $filtered_posts[] = $post;
1358
+ continue;
1359
+ }
1360
+
1361
+ $restriction = $this->get_post_privacy_settings( $post );
1362
+ if ( ! $restriction ) {
1363
+ $filtered_posts[] = $post;
1364
+ continue;
1365
+ }
1366
+
1367
+ if ( $is_singular ) {
1368
+ $this->singular_page = true;
1369
+ }
1370
+
1371
+ if ( ! $this->is_restricted( $post->ID ) ) {
1372
+ $filtered_posts[] = $post;
1373
+ continue;
1374
+ } else {
1375
+ if ( $is_singular ) {
1376
+ if ( ! isset( $restriction['_um_noaccess_action'] ) || '0' == $restriction['_um_noaccess_action'] ) {
1377
+ if ( UM()->options()->get( 'disable_restriction_pre_queries' ) || empty( $restriction['_um_access_hide_from_queries'] ) ) {
1378
+ /**
1379
+ * UM hook
1380
+ *
1381
+ * @type action
1382
+ * @title um_access_fix_external_post_content
1383
+ * @description Hook for 3-d party content filtration
1384
+ * @change_log
1385
+ * ["Since: 2.0"]
1386
+ * @usage add_action( 'um_access_fix_external_post_content', 'function_name', 10 );
1387
+ * @example
1388
+ * <?php
1389
+ * add_action( 'um_access_fix_external_post_content', 'my_access_fix_external_post_content', 10 );
1390
+ * function my_access_fix_external_post_content() {
1391
+ * // your code here
1392
+ * }
1393
+ * ?>
1394
+ */
1395
+ do_action( 'um_access_fix_external_post_content' );
1396
+
1397
+ $filtered_posts[] = $this->maybe_replace_title( $post );
1398
+ continue;
1399
+ }
1400
+ } elseif ( '1' == $restriction['_um_noaccess_action'] ) {
1401
+ $curr = UM()->permalinks()->get_current_url();
1402
+
1403
+ if ( ! isset( $restriction['_um_access_redirect'] ) || '0' == $restriction['_um_access_redirect'] ) {
1404
+
1405
+ exit( wp_redirect( esc_url( add_query_arg( 'redirect_to', urlencode_deep( $curr ), um_get_core_page( 'login' ) ) ) ) );
1406
+
1407
+ } elseif ( '1' == $restriction['_um_access_redirect'] ) {
1408
+
1409
+ if ( ! empty( $restriction['_um_access_redirect_url'] ) ) {
1410
+ $redirect = $restriction['_um_access_redirect_url'];
1411
+ } else {
1412
+ $redirect = esc_url( add_query_arg( 'redirect_to', urlencode_deep( $curr ), um_get_core_page( 'login' ) ) );
1413
+ }
1414
+
1415
+ exit( wp_redirect( $redirect ) );
1416
+ }
1417
+ }
1418
+ } else {
1419
+ if ( empty( $restriction['_um_access_hide_from_queries'] ) || UM()->options()->get( 'disable_restriction_pre_queries' ) ) {
1420
+ $filtered_posts[] = $this->maybe_replace_title( $post );
1421
+ continue;
1422
+ }
1423
+ }
1424
+ }
1425
+ }
1426
+
1427
+ return $filtered_posts;
1428
+ }
1429
+
1430
+
1431
+ /**
1432
+ * Set custom access actions and redirection
1433
+ *
1434
+ * Old global restrict content logic
1435
+ */
1436
+ function template_redirect() {
1437
+ global $post, $wp_query;
1438
+
1439
+ //if we logged by administrator it can access to all content
1440
+ if ( current_user_can( 'administrator' ) ) {
1441
+ return;
1442
+ }
1443
+
1444
+ if ( is_object( $wp_query ) ) {
1445
+ $is_singular = $wp_query->is_singular();
1446
+ } else {
1447
+ $is_singular = ! empty( $wp_query->is_singular ) ? true : false;
1448
+ }
1449
+
1450
+ //if we use individual restrict content options skip this function
1451
+ if ( $is_singular && $this->singular_page ) {
1452
+ return;
1453
+ }
1454
+
1455
+ //also skip if we currently at wp-admin or 404 page
1456
+ if ( is_admin() || is_404() ) {
1457
+ return;
1458
+ }
1459
+
1460
+ //also skip if we currently at UM Register|Login|Reset Password pages
1461
+ if ( um_is_core_post( $post, 'register' ) ||
1462
+ um_is_core_post( $post, 'password-reset' ) ||
1463
+ um_is_core_post( $post, 'login' ) ) {
1464
+ return;
1465
+ }
1466
+
1467
+ /**
1468
+ * UM hook
1469
+ *
1470
+ * @type action
1471
+ * @title um_roles_add_meta_boxes_um_role_meta
1472
+ * @description Check terms individual restrict options
1473
+ * @change_log
1474
+ * ["Since: 2.0"]
1475
+ * @usage add_action( 'um_access_check_individual_term_settings', 'function_name', 10 );
1476
+ * @example
1477
+ * <?php
1478
+ * add_action( 'um_access_check_individual_term_settings', 'my_access_check_individual_term_settings', 10 );
1479
+ * function my_access_check_individual_term_settings() {
1480
+ * // your code here
1481
+ * }
1482
+ * ?>
1483
+ */
1484
+ do_action( 'um_access_check_individual_term_settings' );
1485
+ //exit from function if term page is accessible
1486
+ if ( $this->check_access() ) {
1487
+ return;
1488
+ }
1489
+
1490
+ /**
1491
+ * UM hook
1492
+ *
1493
+ * @type action
1494
+ * @title um_access_check_global_settings
1495
+ * @description Check global restrict content options
1496
+ * @change_log
1497
+ * ["Since: 2.0"]
1498
+ * @usage add_action( 'um_access_check_global_settings', 'function_name', 10 );
1499
+ * @example
1500
+ * <?php
1501
+ * add_action( 'um_access_check_global_settings', 'my_access_check_global_settings', 10 );
1502
+ * function my_access_check_global_settings() {
1503
+ * // your code here
1504
+ * }
1505
+ * ?>
1506
+ */
1507
+ do_action( 'um_access_check_global_settings' );
1508
+
1509
+ $this->check_access();
1510
+ }
1511
+
1512
+
1513
+ /**
1514
+ * Check individual term Content Restriction settings
1515
+ */
1516
+ function um_access_check_individual_term_settings() {
1517
+ //check only tax|tags|categories - skip archive, author, and date lists
1518
+ if ( ! ( is_tax() || is_tag() || is_category() ) ) {
1519
+ return;
1520
+ }
1521
+
1522
+ $term_id = null;
1523
+ if ( is_tag() ) {
1524
+ $term_id = get_query_var( 'tag_id' );
1525
+ } elseif ( is_category() ) {
1526
+ $term_id = get_query_var( 'cat' );
1527
+ } elseif ( is_tax() ) {
1528
+ $tax_name = get_query_var( 'taxonomy' );
1529
+
1530
+ $term_name = get_query_var( 'term' );
1531
+ $term = get_term_by( 'slug', $term_name, $tax_name );
1532
+
1533
+ $term_id = ! empty( $term->term_id ) ? $term->term_id : $term_id;
1534
+ }
1535
+
1536
+ if ( ! isset( $term_id ) ) {
1537
+ return;
1538
+ }
1539
+
1540
+ if ( $this->is_restricted_term( $term_id, true ) ) {
1541
+ $restriction = get_term_meta( $term_id, 'um_content_restriction', true );
1542
+ if ( '1' == $restriction['_um_noaccess_action'] ) {
1543
+ $curr = UM()->permalinks()->get_current_url();
1544
+
1545
+ if ( ! isset( $restriction['_um_access_redirect'] ) || '0' == $restriction['_um_access_redirect'] ) {
1546
+
1547
+ $this->redirect_handler = $this->set_referer( esc_url( add_query_arg( 'redirect_to', urlencode_deep( $curr ), um_get_core_page( 'login' ) ) ), 'individual_term' );
1548
+
1549
+ } elseif ( '1' == $restriction['_um_access_redirect'] ) {
1550
+
1551
+ if ( ! empty( $restriction['_um_access_redirect_url'] ) ) {
1552
+ $redirect = $restriction['_um_access_redirect_url'];
1553
+ } else {
1554
+ $redirect = esc_url( add_query_arg( 'redirect_to', urlencode_deep( $curr ), um_get_core_page( 'login' ) ) );
1555
+ }
1556
+
1557
+ $this->redirect_handler = $this->set_referer( $redirect, 'individual_term' );
1558
+
1559
+ }
1560
+ } else {
1561
+ add_filter( 'tag_template', array( &$this, 'taxonomy_message' ), 10, 3 );
1562
+ add_filter( 'archive_template', array( &$this, 'taxonomy_message' ), 10, 3 );
1563
+ add_filter( 'category_template', array( &$this, 'taxonomy_message' ), 10, 3 );
1564
+ add_filter( 'taxonomy_template', array( &$this, 'taxonomy_message' ), 10, 3 );
1565
+ }
1566
+ }
1567
+ }
1568
+
1569
+
1570
+ /**
1571
+ * @param $template
1572
+ * @param $type
1573
+ * @param $templates
1574
+ *
1575
+ * @return string
1576
+ */
1577
+ function taxonomy_message( $template, $type, $templates ) {
1578
+ return UM()->locate_template( 'restricted-taxonomy.php' );
1579
+ }
1580
+
1581
+
1582
+ /**
1583
+ * Check global accessible settings
1584
+ */
1585
+ function um_access_check_global_settings() {
1586
+ global $post;
1587
+
1588
+ $curr = UM()->permalinks()->get_current_url();
1589
+ $ms_empty_role_access = is_multisite() && is_user_logged_in() && ! UM()->roles()->get_priority_user_role( um_user( 'ID' ) );
1590
+
1591
+ if ( is_front_page() ) {
1592
+ if ( is_user_logged_in() && ! $ms_empty_role_access ) {
1593
+
1594
+ $user_default_homepage = um_user( 'default_homepage' );
1595
+ if ( ! empty( $user_default_homepage ) ) {
1596
+ return;
1597
+ }
1598
+
1599
+ $redirect_homepage = um_user( 'redirect_homepage' );
1600
+ /**
1601
+ * UM hook
1602
+ *
1603
+ * @type filter
1604
+ * @title um_custom_homepage_redirect_url
1605
+ * @description Change custom homepage redirect
1606
+ * @input_vars
1607
+ * [{"var":"$url","type":"string","desc":"Redirect URL"},
1608
+ * {"var":"$id","type":"int","desc":"User ID"}]
1609
+ * @change_log
1610
+ * ["Since: 2.0"]
1611
+ * @usage
1612
+ * <?php add_filter( 'um_custom_homepage_redirect_url', 'function_name', 10, 2 ); ?>
1613
+ * @example
1614
+ * <?php
1615
+ * add_filter( 'um_custom_homepage_redirect_url', 'my_custom_homepage_redirect_url', 10, 2 );
1616
+ * function my_custom_homepage_redirect_url( $url, $id ) {
1617
+ * // your code here
1618
+ * return $url;
1619
+ * }
1620
+ * ?>
1621
+ */
1622
+ $redirect_homepage = apply_filters( 'um_custom_homepage_redirect_url', $redirect_homepage, um_user( 'ID' ) );
1623
+ $redirect_to = ! empty( $redirect_homepage ) ? $redirect_homepage : um_get_core_page( 'user' );
1624
+ $this->redirect_handler = $this->set_referer( esc_url( add_query_arg( 'redirect_to', urlencode_deep( $curr ), $redirect_to ) ), 'custom_homepage' );
1625
+
1626
+ } else {
1627
+ $access = UM()->options()->get( 'accessible' );
1628
+
1629
+ if ( $access == 2 ) {
1630
+ //global settings for accessible home page
1631
+ $home_page_accessible = UM()->options()->get( 'home_page_accessible' );
1632
+
1633
+ if ( $home_page_accessible == 0 ) {
1634
+ //get redirect URL if not set get login page by default
1635
+ $redirect = UM()->options()->get( 'access_redirect' );
1636
+ if ( ! $redirect ) {
1637
+ $redirect = um_get_core_page( 'login' );
1638
+ }
1639
+
1640
+ $this->redirect_handler = $this->set_referer( esc_url( add_query_arg( 'redirect_to', urlencode_deep( $curr ), $redirect ) ), 'global' );
1641
+ } else {
1642
+ $this->allow_access = true;
1643
+ return;
1644
+ }
1645
+ }
1646
+ }
1647
+ } elseif ( is_category() ) {
1648
+ if ( ! is_user_logged_in() || $ms_empty_role_access ) {
1649
+
1650
+ $access = UM()->options()->get( 'accessible' );
1651
+
1652
+ if ( $access == 2 ) {
1653
+ //global settings for accessible home page
1654
+ $category_page_accessible = UM()->options()->get( 'category_page_accessible' );
1655
+ if ( $category_page_accessible == 0 ) {
1656
+ //get redirect URL if not set get login page by default
1657
+ $redirect = UM()->options()->get( 'access_redirect' );
1658
+ if ( ! $redirect ) {
1659
+ $redirect = um_get_core_page( 'login' );
1660
+ }
1661
+
1662
+ $this->redirect_handler = $this->set_referer( esc_url( add_query_arg( 'redirect_to', urlencode_deep( $curr ), $redirect ) ), 'global' );
1663
+ } else {
1664
+ $this->allow_access = true;
1665
+ return;
1666
+ }
1667
+ }
1668
+ }
1669
+ }
1670
+
1671
+ $access = UM()->options()->get( 'accessible' );
1672
+
1673
+ if ( $access == 2 && ( ! is_user_logged_in() || $ms_empty_role_access ) ) {
1674
+
1675
+ //build exclude URLs pages
1676
+ $redirects = array();
1677
+ $redirects[] = trim( untrailingslashit( UM()->options()->get( 'access_redirect' ) ) );
1678
+
1679
+ $exclude_uris = UM()->options()->get( 'access_exclude_uris' );
1680
+ if ( ! empty( $exclude_uris ) ) {
1681
+ $exclude_uris = array_map( 'trim', $exclude_uris );
1682
+ $redirects = array_merge( $redirects, $exclude_uris );
1683
+ }
1684
+
1685
+ $redirects = array_unique( $redirects );
1686
+
1687
+ $current_url = UM()->permalinks()->get_current_url( get_option( 'permalink_structure' ) );
1688
+ $current_url = untrailingslashit( $current_url );
1689
+ $current_url_slash = trailingslashit( $current_url );
1690
+
1691
+ if ( ! ( isset( $post->ID ) && ( in_array( $current_url, $redirects ) || in_array( $current_url_slash, $redirects ) ) ) ) {
1692
+ //if current page not in exclude URLs
1693
+ //get redirect URL if not set get login page by default
1694
+ $redirect = UM()->options()->get( 'access_redirect' );
1695
+ if ( ! $redirect ) {
1696
+ $redirect = um_get_core_page( 'login' );
1697
+ }
1698
+
1699
+ $this->redirect_handler = $this->set_referer( esc_url( add_query_arg( 'redirect_to', urlencode_deep( $curr ), $redirect ) ), 'global' );
1700
+ } else {
1701
+ $this->redirect_handler = false;
1702
+ $this->allow_access = true;
1703
+ }
1704
+ }
1705
+ }
1706
+
1707
+
1708
+ /**
1709
+ * Check access
1710
+ *
1711
+ * @return bool
1712
+ */
1713
+ function check_access() {
1714
+ if ( $this->allow_access === true ) {
1715
+ return true;
1716
+ }
1717
+
1718
+ if ( $this->redirect_handler ) {
1719
+ wp_redirect( $this->redirect_handler );
1720
+ exit;
1721
+ }
1722
+
1723
+ return false;
1724
+ }
1725
+
1726
+
1727
+ /**
1728
+ * Sets a custom access referer in a redirect URL
1729
+ *
1730
+ * @param string $url
1731
+ * @param string $referer
1732
+ *
1733
+ * @return string
1734
+ */
1735
+ function set_referer( $url, $referer ) {
1736
+
1737
+ /**
1738
+ * UM hook
1739
+ *
1740
+ * @type filter
1741
+ * @title um_access_enable_referer
1742
+ * @description Access Referrer Enable/Disable
1743
+ * @input_vars
1744
+ * [{"var":"$referrer","type":"bool","desc":"Access referrer"}]
1745
+ * @change_log
1746
+ * ["Since: 2.0"]
1747
+ * @usage add_filter( 'um_access_enable_referer', 'function_name', 10, 1 );
1748
+ * @example
1749
+ * <?php
1750
+ * add_filter( 'um_access_enable_referer', 'my_access_enable_referer', 10, 1 );
1751
+ * function my_access_enable_referer( $referrer ) {
1752
+ * // your code here
1753
+ * return $referrer;
1754
+ * }
1755
+ * ?>
1756
+ */
1757
+ $enable_referer = apply_filters( 'um_access_enable_referer', false );
1758
+ if ( ! $enable_referer ) {
1759
+ return $url;
1760
+ }
1761
+
1762
+ $url = add_query_arg( 'um_ref', $referer, $url );
1763
+ return $url;
1764
+ }
1765
+
1766
+
1767
+ /**
1768
+ * Get privacy settings for post
1769
+ * return false if post is not private
1770
+ * Restrict content new logic
1771
+ *
1772
+ * @param \WP_Post|int $post Post ID or object
1773
+ * @return bool|array
1774
+ */
1775
+ function get_post_privacy_settings( $post ) {
1776
+ // break for incorrect post
1777
+ if ( empty( $post ) ) {
1778
+ return false;
1779
+ }
1780
+
1781
+ static $cache = array();
1782
+
1783
+ $cache_key = is_numeric( $post ) ? $post : $post->ID;
1784
+
1785
+ if ( isset( $cache[ $cache_key ] ) ) {
1786
+ return $cache[ $cache_key ];
1787
+ }
1788
+
1789
+ if ( is_numeric( $post ) ) {
1790
+ $post = get_post( $post );
1791
+ }
1792
+
1793
+ //if logged in administrator all pages are visible
1794
+ if ( current_user_can( 'administrator' ) ) {
1795
+ $cache[ $cache_key ] = false;
1796
+ return false;
1797
+ }
1798
+
1799
+ $exclude = false;
1800
+ //exclude from privacy UM default pages (except Members list and User(Profile) page)
1801
+ if ( ! empty( $post->post_type ) && $post->post_type === 'page' ) {
1802
+
1803
+ if ( um_is_core_post( $post, 'login' ) || um_is_core_post( $post, 'register' ) ||
1804
+ um_is_core_post( $post, 'account' ) || um_is_core_post( $post, 'logout' ) ||
1805
+ um_is_core_post( $post, 'password-reset' ) || ( is_user_logged_in() && um_is_core_post( $post, 'user' ) ) )
1806
+ $exclude = true;
1807
+ }
1808
+
1809
+ $exclude = apply_filters( 'um_exclude_posts_from_privacy', $exclude, $post );
1810
+ if ( $exclude ) {
1811
+ $cache[ $cache_key ] = false;
1812
+ return false;
1813
+ }
1814
+
1815
+ $restricted_posts = UM()->options()->get( 'restricted_access_post_metabox' );
1816
+
1817
+ if ( ! empty( $post->post_type ) && ! empty( $restricted_posts[ $post->post_type ] ) ) {
1818
+ $restriction = get_post_meta( $post->ID, 'um_content_restriction', true );
1819
+
1820
+ if ( ! empty( $restriction['_um_custom_access_settings'] ) ) {
1821
+ if ( ! isset( $restriction['_um_accessible'] ) ) {
1822
+ $restricted_taxonomies = UM()->options()->get( 'restricted_access_taxonomy_metabox' );
1823
+
1824
+ //get all taxonomies for current post type
1825
+ $taxonomies = get_object_taxonomies( $post );
1826
+
1827
+ //get all post terms
1828
+ $terms = array();
1829
+ if ( ! empty( $taxonomies ) ) {
1830
+ foreach ( $taxonomies as $taxonomy ) {
1831
+ if ( empty( $restricted_taxonomies[ $taxonomy ] ) ) {
1832
+ continue;
1833
+ }
1834
+
1835
+ $terms = array_merge( $terms, wp_get_post_terms( $post->ID, $taxonomy, array( 'fields' => 'ids', 'um_ignore_exclude' => true, ) ) );
1836
+ }
1837
+ }
1838
+
1839
+ //get restriction options for first term with privacy settigns
1840
+ foreach ( $terms as $term_id ) {
1841
+ $restriction = get_term_meta( $term_id, 'um_content_restriction', true );
1842
+
1843
+ if ( ! empty( $restriction['_um_custom_access_settings'] ) ) {
1844
+ if ( ! isset( $restriction['_um_accessible'] ) ) {
1845
+ continue;
1846
+ } else {
1847
+ $cache[ $cache_key ] = $restriction;
1848
+ return $restriction;
1849
+ }
1850
+ }
1851
+ }
1852
+
1853
+ $cache[ $cache_key ] = false;
1854
+ return false;
1855
+ } else {
1856
+
1857
+ // set default redirect if Profile page is restricted for not-logged in users and showing message instead of redirect
1858
+ // this snippet was added to make the same action for {site_url}/user and {site_url}/user/{user_slug} URLs
1859
+ // by default {site_url}/user is redirected to Homepage in rewrite rules because hasn't found username in query when user is not logged in
1860
+ if ( ! is_user_logged_in() && um_is_core_post( $post, 'user' ) && $restriction['_um_accessible'] == '2' && $restriction['_um_noaccess_action'] == '0' ) {
1861
+ if ( isset( $restriction['_um_access_roles'] ) ) {
1862
+ $restriction = array(
1863
+ '_um_accessible' => '2',
1864
+ '_um_access_roles' => $restriction['_um_access_roles'],
1865
+ '_um_noaccess_action' => '1',
1866
+ '_um_access_redirect' => '1',
1867
+ '_um_access_redirect_url' => get_home_url( get_current_blog_id() )
1868
+ );
1869
+ } else {
1870
+ $restriction = array(
1871
+ '_um_accessible' => '2',
1872
+ '_um_noaccess_action' => '1',
1873
+ '_um_access_redirect' => '1',
1874
+ '_um_access_redirect_url' => get_home_url( get_current_blog_id() )
1875
+ );
1876
+ }
1877
+ }
1878
+
1879
+ $restriction = apply_filters( 'um_post_content_restriction_settings', $restriction, $post );
1880
+
1881
+ $cache[ $cache_key ] = $restriction;
1882
+ return $restriction;
1883
+ }
1884
+ }
1885
+ }
1886
+
1887
+ //post hasn't privacy settings....check all terms of this post
1888
+ $restricted_taxonomies = UM()->options()->get( 'restricted_access_taxonomy_metabox' );
1889
+
1890
+ //get all taxonomies for current post type
1891
+ $taxonomies = get_object_taxonomies( $post );
1892
+
1893
+ //get all post terms
1894
+ $terms = array();
1895
+ if ( ! empty( $taxonomies ) ) {
1896
+ foreach ( $taxonomies as $taxonomy ) {
1897
+ if ( empty( $restricted_taxonomies[ $taxonomy ] ) ) {
1898
+ continue;
1899
+ }
1900
+
1901
+ $terms = array_merge( $terms, wp_get_post_terms( $post->ID, $taxonomy, array( 'fields' => 'ids', 'um_ignore_exclude' => true, ) ) );
1902
+ }
1903
+ }
1904
+
1905
+ //get restriction options for first term with privacy settings
1906
+ foreach ( $terms as $term_id ) {
1907
+ $restriction = get_term_meta( $term_id, 'um_content_restriction', true );
1908
+
1909
+ if ( ! empty( $restriction['_um_custom_access_settings'] ) ) {
1910
+ if ( ! isset( $restriction['_um_accessible'] ) ) {
1911
+ continue;
1912
+ } else {
1913
+ $cache[ $cache_key ] = $restriction;
1914
+ return $restriction;
1915
+ }
1916
+ }
1917
+ }
1918
+
1919
+ $cache[ $cache_key ] = false;
1920
+ //post is public
1921
+ return false;
1922
+ }
1923
+
1924
+
1925
+ /**
1926
+ * Helper for checking if the user can some of the roles array
1927
+ *
1928
+ * @param $user_id
1929
+ * @param $roles
1930
+ * @return bool
1931
+ */
1932
+ function user_can( $user_id, $roles ) {
1933
+ $user_can = false;
1934
+
1935
+ if ( ! empty( $roles ) ) {
1936
+ foreach ( $roles as $key => $value ) {
1937
+ if ( ! empty( $value ) && user_can( $user_id, $key ) ) {
1938
+ $user_can = true;
1939
+ break;
1940
+ }
1941
+ }
1942
+ }
1943
+
1944
+ return $user_can;
1945
+ }
1946
+
1947
+
1948
+ /**
1949
+ * Helper for 3rd-party integrations with content restriction settings
1950
+ *
1951
+ * @param array $restriction
1952
+ *
1953
+ * @return bool
1954
+ */
1955
+ function um_custom_restriction( $restriction ) {
1956
+ /**
1957
+ * UM hook
1958
+ *
1959
+ * @type filter
1960
+ * @title um_custom_restriction
1961
+ * @description Extend Sort Types for Member Directory
1962
+ * @input_vars
1963
+ * [{"var":"$custom_restriction","type":"bool","desc":"Custom Restriction"},
1964
+ * {"var":"$restriction","type":"array","desc":"Restriction settings"}]
1965
+ * @change_log
1966
+ * ["Since: 2.0"]
1967
+ * @usage add_filter( 'um_custom_restriction', 'function_name', 10, 2 );
1968
+ * @example
1969
+ * <?php
1970
+ * add_filter( 'um_custom_restriction', 'my_custom_restriction', 10, 2 );
1971
+ * function my_directory_sort_users_select( $custom_restriction, $restriction ) {
1972
+ * // your code here
1973
+ * return $custom_restriction;
1974
+ * }
1975
+ * ?>
1976
+ */
1977
+ return apply_filters( 'um_custom_restriction', true, $restriction );
1978
+ }
1979
+
1980
+
1981
+ /**
1982
+ * Is post restricted?
1983
+ *
1984
+ * @param int $post_id
1985
+ * @return bool
1986
+ */
1987
+ function is_restricted( $post_id ) {
1988
+ // break for incorrect post
1989
+ if ( empty( $post_id ) ) {
1990
+ return false;
1991
+ }
1992
+
1993
+ static $cache = array();
1994
+
1995
+ if ( isset( $cache[ $post_id ] ) ) {
1996
+ return $cache[ $post_id ];
1997
+ }
1998
+
1999
+ if ( current_user_can( 'administrator' ) ) {
2000
+ $cache[ $post_id ] = false;
2001
+ return false;
2002
+ }
2003
+
2004
+ $post = get_post( $post_id );
2005
+ if ( is_user_logged_in() && isset( $post->post_author ) && $post->post_author == get_current_user_id() ) {
2006
+ $cache[ $post_id ] = false;
2007
+ return false;
2008
+ }
2009
+
2010
+ $restricted = true;
2011
+
2012
+ $restriction = $this->get_post_privacy_settings( $post_id );
2013
+ if ( ! $restriction ) {
2014
+ $restricted = false;
2015
+ } else {
2016
+ if ( '0' == $restriction['_um_accessible'] ) {
2017
+ //post is private
2018
+ $restricted = false;
2019
+ } elseif ( '1' == $restriction['_um_accessible'] ) {
2020
+ //if post for not logged in users and user is not logged in
2021
+ if ( ! is_user_logged_in() ) {
2022
+ $restricted = false;
2023
+ }
2024
+ } elseif ( '2' == $restriction['_um_accessible'] ) {
2025
+ //if post for logged in users and user is not logged in
2026
+ if ( is_user_logged_in() ) {
2027
+ $custom_restrict = $this->um_custom_restriction( $restriction );
2028
+
2029
+ if ( empty( $restriction['_um_access_roles'] ) || false === array_search( '1', $restriction['_um_access_roles'] ) ) {
2030
+ if ( $custom_restrict ) {
2031
+ $restricted = false;
2032
+ }
2033
+ } else {
2034
+ $user_can = $this->user_can( get_current_user_id(), $restriction['_um_access_roles'] );
2035
+
2036
+ if ( $user_can && $custom_restrict ) {
2037
+ $restricted = false;
2038
+ }
2039
+ }
2040
+ }
2041
+ }
2042
+ }
2043
+
2044
+ $restricted = apply_filters( 'um_is_restricted_post', $restricted, $post_id );
2045
+
2046
+ $cache[ $post_id ] = $restricted;
2047
+
2048
+ return $restricted;
2049
+ }
2050
+
2051
+
2052
+ /**
2053
+ * Is term restricted?
2054
+ *
2055
+ * @param int $term_id
2056
+ * @param bool $on_term_page
2057
+ * @return bool
2058
+ */
2059
+ function is_restricted_term( $term_id, $on_term_page = false ) {
2060
+ static $cache = array();
2061
+
2062
+ if ( isset( $cache[ $term_id ] ) ) {
2063
+ return $cache[ $term_id ];
2064
+ }
2065
+
2066
+ if ( current_user_can( 'administrator' ) ) {
2067
+ $cache[ $term_id ] = false;
2068
+ return false;
2069
+ }
2070
+
2071
+ $restricted_taxonomies = UM()->options()->get( 'restricted_access_taxonomy_metabox' );
2072
+ if ( empty( $restricted_taxonomies ) ) {
2073
+ $cache[ $term_id ] = false;
2074
+ return false;
2075
+ }
2076
+
2077
+ $term = get_term( $term_id );
2078
+ if ( empty( $term->taxonomy ) || empty( $restricted_taxonomies[ $term->taxonomy ] ) ) {
2079
+ $cache[ $term_id ] = false;
2080
+ return false;
2081
+ }
2082
+
2083
+ $restricted = true;
2084
+
2085
+ // $this->allow_access = true only in case if the
2086
+
2087
+ $restriction = get_term_meta( $term_id, 'um_content_restriction', true );
2088
+ if ( empty( $restriction ) ) {
2089
+ $restricted = false;
2090
+ } else {
2091
+ if ( empty( $restriction['_um_custom_access_settings'] ) ) {
2092
+ $restricted = false;
2093
+ } else {
2094
+ if ( '0' == $restriction['_um_accessible'] ) {
2095
+ //term is private
2096
+ $restricted = false;
2097
+ if ( $on_term_page ) {
2098
+ $this->allow_access = true;
2099
+ }
2100
+ } elseif ( '1' == $restriction['_um_accessible'] ) {
2101
+ //if term for not logged in users and user is not logged in
2102
+ if ( ! is_user_logged_in() ) {
2103
+ $restricted = false;
2104
+ if ( $on_term_page ) {
2105
+ $this->allow_access = true;
2106
+ }
2107
+ }
2108
+ } elseif ( '2' == $restriction['_um_accessible'] ) {
2109
+ //if term for logged in users and user is not logged in
2110
+ if ( is_user_logged_in() ) {
2111
+ $custom_restrict = $this->um_custom_restriction( $restriction );
2112
+
2113
+ if ( empty( $restriction['_um_access_roles'] ) || false === array_search( '1', $restriction['_um_access_roles'] ) ) {
2114
+ if ( $custom_restrict ) {
2115
+ $restricted = false;
2116
+ if ( $on_term_page ) {
2117
+ $this->allow_access = true;
2118
+ }
2119
+ }
2120
+ } else {
2121
+ $user_can = $this->user_can( get_current_user_id(), $restriction['_um_access_roles'] );
2122
+
2123
+ if ( $user_can && $custom_restrict ) {
2124
+ $restricted = false;
2125
+ if ( $on_term_page ) {
2126
+ $this->allow_access = true;
2127
+ }
2128
+ }
2129
+ }
2130
+ }
2131
+ }
2132
+ }
2133
+ }
2134
+
2135
+ $restricted = apply_filters( 'um_is_restricted_term', $restricted, $term_id, $on_term_page );
2136
+
2137
+ $cache[ $term_id ] = $restricted;
2138
+ return $restricted;
2139
+ }
2140
+ }
2141
+ }
includes/core/class-builtin.php CHANGED
@@ -1058,21 +1058,24 @@ if ( ! class_exists( 'um\core\Builtin' ) ) {
1058
  ),
1059
 
1060
  'youtube' => array(
1061
- 'title' => __('YouTube','ultimate-member'),
1062
- 'metakey' => 'youtube',
1063
- 'type' => 'url',
1064
- 'label' => __('YouTube','ultimate-member'),
1065
- 'required' => 0,
1066
- 'public' => 1,
1067
- 'editable' => 1,
1068
  'url_target' => '_blank',
1069
- 'url_rel' => 'nofollow',
1070
- 'icon' => 'um-faicon-youtube',
1071
- 'validate' => 'youtube_url',
1072
- 'url_text' => 'YouTube',
1073
- 'advanced' => 'social',
1074
- 'color' => '#e52d27',
1075
- 'match' => 'https://youtube.com/',
 
 
 
1076
  ),
1077
 
1078
  'soundcloud' => array(
1058
  ),
1059
 
1060
  'youtube' => array(
1061
+ 'title' => __( 'YouTube', 'ultimate-member' ),
1062
+ 'metakey' => 'youtube',
1063
+ 'type' => 'url',
1064
+ 'label' => __( 'YouTube', 'ultimate-member' ),
1065
+ 'required' => 0,
1066
+ 'public' => 1,
1067
+ 'editable' => 1,
1068
  'url_target' => '_blank',
1069
+ 'url_rel' => 'nofollow',
1070
+ 'icon' => 'um-faicon-youtube',
1071
+ 'validate' => 'youtube_url',
1072
+ 'url_text' => __( 'YouTube', 'ultimate-member' ),
1073
+ 'advanced' => 'social',
1074
+ 'color' => '#e52d27',
1075
+ 'match' => array(
1076
+ 'https://youtube.com/',
1077
+ 'https://youtu.be/',
1078
+ ),
1079
  ),
1080
 
1081
  'soundcloud' => array(
includes/core/class-fields.php CHANGED
@@ -86,9 +86,10 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
86
  }
87
 
88
  foreach ( $social as $k => $arr ) {
89
- if ( um_profile( $k ) ) { ?>
 
90
 
91
- <a href="<?php echo esc_url( um_filtered_social_link( $k, $arr['match'] ) ); ?>"
92
  style="background: <?php echo esc_attr( $arr['color'] ); ?>;" target="_blank" class="um-tip-n"
93
  title="<?php echo esc_attr( $arr['title'] ); ?>"><i class="<?php echo esc_attr( $arr['icon'] ); ?>"></i></a>
94
 
@@ -146,17 +147,19 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
146
 
147
  if ( array_key_exists( 'custom_dropdown_options_source', $args ) ) {
148
  if ( function_exists( wp_unslash( $args['custom_dropdown_options_source'] ) ) ) {
149
- $allowed_callbacks = UM()->options()->get( 'allowed_choice_callbacks' );
150
- if ( ! empty( $allowed_callbacks ) ) {
151
- $allowed_callbacks = array_map( 'rtrim', explode( "\n", $allowed_callbacks ) );
152
- $allowed_callbacks[] = $args['custom_dropdown_options_source'];
153
- } else {
154
- $allowed_callbacks = array( $args['custom_dropdown_options_source'] );
155
- }
156
- $allowed_callbacks = array_unique( $allowed_callbacks );
157
- $allowed_callbacks = implode( "\r\n", $allowed_callbacks );
 
158
 
159
- UM()->options()->update( 'allowed_choice_callbacks', $allowed_callbacks );
 
160
  }
161
  }
162
 
@@ -201,19 +204,21 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
201
 
202
  if ( array_key_exists( 'custom_dropdown_options_source', $args ) ) {
203
  if ( function_exists( wp_unslash( $args['custom_dropdown_options_source'] ) ) ) {
204
- $allowed_callbacks = UM()->options()->get( 'allowed_choice_callbacks' );
205
- if ( ! empty( $allowed_callbacks ) ) {
206
- $allowed_callbacks = array_map( 'rtrim', explode( "\n", $allowed_callbacks ) );
207
- $allowed_callbacks[] = $args['custom_dropdown_options_source'];
208
- } else {
209
- $allowed_callbacks = array( $args['custom_dropdown_options_source'] );
210
- }
211
- $allowed_callbacks = array_unique( $allowed_callbacks );
212
- $allowed_callbacks = implode( "\r\n", $allowed_callbacks );
 
213
 
214
- UM()->options()->update( 'allowed_choice_callbacks', $allowed_callbacks );
215
 
216
- $args['custom_dropdown_options_source'] = wp_unslash( $args['custom_dropdown_options_source'] );
 
217
  }
218
  }
219
 
@@ -1291,6 +1296,18 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
1291
  return '';
1292
  }
1293
 
 
 
 
 
 
 
 
 
 
 
 
 
1294
 
1295
  /**
1296
  * Gets selected option value from a callback function
@@ -1305,6 +1322,10 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
1305
 
1306
  if ( in_array( $type, array( 'select', 'multiselect' ) ) && ! empty( $data['custom_dropdown_options_source'] ) ) {
1307
 
 
 
 
 
1308
  $has_custom_source = apply_filters( "um_has_dropdown_options_source__{$data['metakey']}", false );
1309
 
1310
  if ( $has_custom_source ) {
@@ -1372,6 +1393,10 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
1372
 
1373
  if ( in_array( $type, array( 'select', 'multiselect' ) ) && ! empty( $data['custom_dropdown_options_source'] ) ) {
1374
 
 
 
 
 
1375
  if ( function_exists( $data['custom_dropdown_options_source'] ) ) {
1376
  if ( isset( $data['parent_dropdown_relationship'] ) ) {
1377
  $arr_options = call_user_func( $data['custom_dropdown_options_source'], $data['parent_dropdown_relationship'] );
@@ -3037,7 +3062,9 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
3037
  if ( ! empty( $data['custom_dropdown_options_source'] ) && $has_parent_option && function_exists( $data['custom_dropdown_options_source'] ) &&
3038
  um_user( $data['parent_dropdown_relationship'] )
3039
  ) {
3040
- $options = call_user_func( $data['custom_dropdown_options_source'], $data['parent_dropdown_relationship'] );
 
 
3041
 
3042
  $disabled_by_parent_option = '';
3043
  if ( um_user( $form_key ) ) {
@@ -3053,10 +3080,11 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
3053
 
3054
  // Child dropdown
3055
  if ( $has_parent_option ) {
3056
-
3057
  if ( ! empty( $data['custom_dropdown_options_source'] ) && $has_parent_option &&
3058
  function_exists( $data['custom_dropdown_options_source'] ) && isset( UM()->form()->post_form[ $form_key ] ) ) {
3059
- $options = call_user_func( $data['custom_dropdown_options_source'], $data['parent_dropdown_relationship'] );
 
 
3060
  }
3061
  }
3062
 
@@ -3576,7 +3604,7 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
3576
 
3577
  $i++;
3578
  if ($i % 2 == 0) {
3579
- $col_class = 'right';
3580
  } else {
3581
  $col_class = '';
3582
  }
@@ -3703,7 +3731,7 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
3703
 
3704
  $i++;
3705
  if ( $i % 2 == 0 ) {
3706
- $col_class = 'right';
3707
  } else {
3708
  $col_class = '';
3709
  }
86
  }
87
 
88
  foreach ( $social as $k => $arr ) {
89
+ if ( um_profile( $k ) ) {
90
+ $match = is_array( $arr['match'] ) ? $arr['match'][0] : $arr['match']; ?>
91
 
92
+ <a href="<?php echo esc_url( um_filtered_social_link( $k, $match ) ); ?>"
93
  style="background: <?php echo esc_attr( $arr['color'] ); ?>;" target="_blank" class="um-tip-n"
94
  title="<?php echo esc_attr( $arr['title'] ); ?>"><i class="<?php echo esc_attr( $arr['icon'] ); ?>"></i></a>
95
 
147
 
148
  if ( array_key_exists( 'custom_dropdown_options_source', $args ) ) {
149
  if ( function_exists( wp_unslash( $args['custom_dropdown_options_source'] ) ) ) {
150
+ if ( ! in_array( $args['custom_dropdown_options_source'], UM()->fields()->dropdown_options_source_blacklist(), true ) ) {
151
+ $allowed_callbacks = UM()->options()->get( 'allowed_choice_callbacks' );
152
+ if ( ! empty( $allowed_callbacks ) ) {
153
+ $allowed_callbacks = array_map( 'rtrim', explode( "\n", $allowed_callbacks ) );
154
+ $allowed_callbacks[] = $args['custom_dropdown_options_source'];
155
+ } else {
156
+ $allowed_callbacks = array( $args['custom_dropdown_options_source'] );
157
+ }
158
+ $allowed_callbacks = array_unique( $allowed_callbacks );
159
+ $allowed_callbacks = implode( "\r\n", $allowed_callbacks );
160
 
161
+ UM()->options()->update( 'allowed_choice_callbacks', $allowed_callbacks );
162
+ }
163
  }
164
  }
165
 
204
 
205
  if ( array_key_exists( 'custom_dropdown_options_source', $args ) ) {
206
  if ( function_exists( wp_unslash( $args['custom_dropdown_options_source'] ) ) ) {
207
+ if ( ! in_array( $args['custom_dropdown_options_source'], UM()->fields()->dropdown_options_source_blacklist(), true ) ) {
208
+ $allowed_callbacks = UM()->options()->get( 'allowed_choice_callbacks' );
209
+ if ( ! empty( $allowed_callbacks ) ) {
210
+ $allowed_callbacks = array_map( 'rtrim', explode( "\n", $allowed_callbacks ) );
211
+ $allowed_callbacks[] = $args['custom_dropdown_options_source'];
212
+ } else {
213
+ $allowed_callbacks = array( $args['custom_dropdown_options_source'] );
214
+ }
215
+ $allowed_callbacks = array_unique( $allowed_callbacks );
216
+ $allowed_callbacks = implode( "\r\n", $allowed_callbacks );
217
 
218
+ UM()->options()->update( 'allowed_choice_callbacks', $allowed_callbacks );
219
 
220
+ $args['custom_dropdown_options_source'] = wp_unslash( $args['custom_dropdown_options_source'] );
221
+ }
222
  }
223
  }
224
 
1296
  return '';
1297
  }
1298
 
1299
+ /**
1300
+ * Getting the blacklist of the functions that cannot be used as callback.
1301
+ * All internal PHP functions are insecure for using inside callback functions.
1302
+ *
1303
+ * @return array
1304
+ */
1305
+ public function dropdown_options_source_blacklist() {
1306
+ $list = get_defined_functions();
1307
+ $blacklist = ! empty( $list['internal'] ) ? $list['internal'] : array();
1308
+ $blacklist = apply_filters( 'um_dropdown_options_source_blacklist', $blacklist );
1309
+ return $blacklist;
1310
+ }
1311
 
1312
  /**
1313
  * Gets selected option value from a callback function
1322
 
1323
  if ( in_array( $type, array( 'select', 'multiselect' ) ) && ! empty( $data['custom_dropdown_options_source'] ) ) {
1324
 
1325
+ if ( in_array( $data['custom_dropdown_options_source'], $this->dropdown_options_source_blacklist(), true ) ) {
1326
+ return $value;
1327
+ }
1328
+
1329
  $has_custom_source = apply_filters( "um_has_dropdown_options_source__{$data['metakey']}", false );
1330
 
1331
  if ( $has_custom_source ) {
1393
 
1394
  if ( in_array( $type, array( 'select', 'multiselect' ) ) && ! empty( $data['custom_dropdown_options_source'] ) ) {
1395
 
1396
+ if ( in_array( $data['custom_dropdown_options_source'], $this->dropdown_options_source_blacklist(), true ) ) {
1397
+ return $arr_options;
1398
+ }
1399
+
1400
  if ( function_exists( $data['custom_dropdown_options_source'] ) ) {
1401
  if ( isset( $data['parent_dropdown_relationship'] ) ) {
1402
  $arr_options = call_user_func( $data['custom_dropdown_options_source'], $data['parent_dropdown_relationship'] );
3062
  if ( ! empty( $data['custom_dropdown_options_source'] ) && $has_parent_option && function_exists( $data['custom_dropdown_options_source'] ) &&
3063
  um_user( $data['parent_dropdown_relationship'] )
3064
  ) {
3065
+ if ( ! in_array( $data['custom_dropdown_options_source'], $this->dropdown_options_source_blacklist(), true ) ) {
3066
+ $options = call_user_func( $data['custom_dropdown_options_source'], $data['parent_dropdown_relationship'] );
3067
+ }
3068
 
3069
  $disabled_by_parent_option = '';
3070
  if ( um_user( $form_key ) ) {
3080
 
3081
  // Child dropdown
3082
  if ( $has_parent_option ) {
 
3083
  if ( ! empty( $data['custom_dropdown_options_source'] ) && $has_parent_option &&
3084
  function_exists( $data['custom_dropdown_options_source'] ) && isset( UM()->form()->post_form[ $form_key ] ) ) {
3085
+ if ( ! in_array( $data['custom_dropdown_options_source'], $this->dropdown_options_source_blacklist(), true ) ) {
3086
+ $options = call_user_func( $data['custom_dropdown_options_source'], $data['parent_dropdown_relationship'] );
3087
+ }
3088
  }
3089
  }
3090
 
3604
 
3605
  $i++;
3606
  if ($i % 2 == 0) {
3607
+ $col_class = ' right ';
3608
  } else {
3609
  $col_class = '';
3610
  }
3731
 
3732
  $i++;
3733
  if ( $i % 2 == 0 ) {
3734
+ $col_class = ' right ';
3735
  } else {
3736
  $col_class = '';
3737
  }
includes/core/class-form.php CHANGED
@@ -1,837 +1,872 @@
1
- <?php
2
- namespace um\core;
3
-
4
- // Exit if accessed directly
5
- if ( ! defined( 'ABSPATH' ) ) exit;
6
-
7
- if ( ! class_exists( 'um\core\Form' ) ) {
8
-
9
-
10
- /**
11
- * Class Form
12
- * @package um\core
13
- */
14
- class Form {
15
-
16
-
17
- /**
18
- * @var null
19
- */
20
- public $form_suffix;
21
-
22
-
23
- /**
24
- * @var
25
- */
26
- var $form_id;
27
-
28
-
29
- /**
30
- * @var null
31
- */
32
- var $post_form = null;
33
-
34
-
35
- var $nonce = null;
36
-
37
-
38
- /**
39
- * Form constructor.
40
- */
41
- function __construct() {
42
-
43
- $this->form_suffix = null;
44
-
45
- $this->errors = null;
46
-
47
- $this->processing = null;
48
-
49
- add_action( 'template_redirect', array( &$this, 'form_init' ), 2 );
50
-
51
- add_action( 'init', array( &$this, 'field_declare' ), 10 );
52
-
53
- }
54
-
55
-
56
- /**
57
- *
58
- */
59
- public function ajax_muted_action() {
60
- UM()->check_ajax_nonce();
61
-
62
- /**
63
- * @var $user_id
64
- * @var $hook
65
- */
66
- extract( $_REQUEST );
67
-
68
- if ( isset( $user_id ) ) {
69
- $user_id = absint( $user_id );
70
- }
71
-
72
- if ( isset( $hook ) ) {
73
- $hook = sanitize_key( $hook );
74
- }
75
-
76
- if ( ! UM()->roles()->um_current_user_can( 'edit', $user_id ) ) {
77
- die( esc_html__( 'You can not edit this user', 'ultimate-member' ) );
78
- }
79
-
80
- switch ( $hook ) {
81
- default:
82
- /**
83
- * UM hook
84
- *
85
- * @type action
86
- * @title um_run_ajax_function__{$hook}
87
- * @description Action on AJAX muted action
88
- * @input_vars
89
- * [{"var":"$request","type":"int","desc":"Request"}]
90
- * @change_log
91
- * ["Since: 2.0"]
92
- * @usage add_action( 'um_run_ajax_function__{$hook}', 'function_name', 10, 1 );
93
- * @example
94
- * <?php
95
- * add_action( 'um_run_ajax_function__{$hook}', 'my_run_ajax_function', 10, 1 );
96
- * function my_run_ajax_function( $request ) {
97
- * // your code here
98
- * }
99
- * ?>
100
- */
101
- do_action( "um_run_ajax_function__{$hook}", $_REQUEST );
102
- break;
103
- }
104
- }
105
-
106
-
107
- /**
108
- *
109
- */
110
- public function ajax_select_options() {
111
- UM()->check_ajax_nonce();
112
-
113
- $arr_options = array();
114
- $arr_options['status'] = 'success';
115
- $arr_options['post'] = $_POST;
116
-
117
- // Callback validation
118
- if ( empty( $_POST['child_callback'] ) ) {
119
- $arr_options['status'] = 'error';
120
- $arr_options['message'] = __( 'Wrong callback.', 'ultimate-member' );
121
-
122
- wp_send_json( $arr_options );
123
- }
124
-
125
- $ajax_source_func = sanitize_text_field( $_POST['child_callback'] );
126
-
127
- if ( ! function_exists( $ajax_source_func ) ) {
128
- $arr_options['status'] = 'error';
129
- $arr_options['message'] = __( 'Wrong callback.', 'ultimate-member' );
130
-
131
- wp_send_json( $arr_options );
132
- }
133
-
134
- $allowed_callbacks = UM()->options()->get( 'allowed_choice_callbacks' );
135
-
136
- if ( empty( $allowed_callbacks ) ) {
137
- $arr_options['status'] = 'error';
138
- $arr_options['message'] = __( 'This is not possible for security reasons.', 'ultimate-member' );
139
- wp_send_json( $arr_options );
140
- }
141
-
142
- $allowed_callbacks = array_map( 'rtrim', explode( "\n", wp_unslash( $allowed_callbacks ) ) );
143
-
144
- if ( ! in_array( $ajax_source_func, $allowed_callbacks, true ) ) {
145
- $arr_options['status'] = 'error';
146
- $arr_options['message'] = __( 'This is not possible for security reasons.', 'ultimate-member' );
147
-
148
- wp_send_json( $arr_options );
149
- }
150
-
151
- if ( isset( $_POST['form_id'] ) ) {
152
- UM()->fields()->set_id = absint( $_POST['form_id'] );
153
- }
154
- UM()->fields()->set_mode = 'profile';
155
- $form_fields = UM()->fields()->get_fields();
156
- $arr_options['fields'] = $form_fields;
157
-
158
- if ( isset( $arr_options['post']['members_directory'] ) && 'yes' === $arr_options['post']['members_directory'] ) {
159
- global $wpdb;
160
-
161
- $values_array = $wpdb->get_col(
162
- $wpdb->prepare(
163
- "SELECT DISTINCT meta_value
164
- FROM $wpdb->usermeta
165
- WHERE meta_key = %s AND
166
- meta_value != ''",
167
- $arr_options['post']['child_name']
168
- )
169
- );
170
-
171
- if ( ! empty( $values_array ) ) {
172
- $parent_dropdown = isset( $arr_options['field']['parent_dropdown_relationship'] ) ? $arr_options['field']['parent_dropdown_relationship'] : '';
173
- $arr_options['items'] = call_user_func( $ajax_source_func, $parent_dropdown );
174
-
175
- if ( array_keys( $arr_options['items'] ) !== range( 0, count( $arr_options['items'] ) - 1 ) ) {
176
- // array with dropdown items is associative
177
- $arr_options['items'] = array_intersect_key( array_map( 'trim', $arr_options['items'] ), array_flip( $values_array ) );
178
- } else {
179
- // array with dropdown items has sequential numeric keys, starting from 0 and there are intersected values with $values_array
180
- $arr_options['items'] = array_intersect( $arr_options['items'], $values_array );
181
- }
182
- } else {
183
- $arr_options['items'] = array();
184
- }
185
-
186
- wp_send_json( $arr_options );
187
- } else {
188
- /**
189
- * UM hook
190
- *
191
- * @type filter
192
- * @title um_ajax_select_options__debug_mode
193
- * @description Activate debug mode for AJAX select options
194
- * @input_vars
195
- * [{"var":"$debug_mode","type":"bool","desc":"Enable Debug mode"}]
196
- * @change_log
197
- * ["Since: 2.0"]
198
- * @usage
199
- * <?php add_filter( 'um_ajax_select_options__debug_mode', 'function_name', 10, 1 ); ?>
200
- * @example
201
- * <?php
202
- * add_filter( 'um_ajax_select_options__debug_mode', 'my_ajax_select_options__debug_mode', 10, 1 );
203
- * function my_ajax_select_options__debug_mode( $debug_mode ) {
204
- * // your code here
205
- * return $debug_mode;
206
- * }
207
- * ?>
208
- */
209
- $debug = apply_filters( 'um_ajax_select_options__debug_mode', false );
210
- if ( $debug ) {
211
- $arr_options['debug'] = array(
212
- $_POST,
213
- $form_fields,
214
- );
215
- }
216
-
217
- if ( ! empty( $_POST['child_callback'] ) && isset( $form_fields[ $_POST['child_name'] ] ) ) {
218
- // If the requested callback function is added in the form or added in the field option, execute it with call_user_func.
219
- if ( isset( $form_fields[ $_POST['child_name'] ]['custom_dropdown_options_source'] ) &&
220
- ! empty( $form_fields[ $_POST['child_name'] ]['custom_dropdown_options_source'] ) &&
221
- $form_fields[ $_POST['child_name'] ]['custom_dropdown_options_source'] === $ajax_source_func ) {
222
-
223
- $arr_options['field'] = $form_fields[ $_POST['child_name'] ];
224
-
225
- $arr_options['items'] = call_user_func( $ajax_source_func, $arr_options['field']['parent_dropdown_relationship'] );
226
- } else {
227
- $arr_options['status'] = 'error';
228
- $arr_options['message'] = __( 'This is not possible for security reasons.', 'ultimate-member' );
229
- }
230
- }
231
-
232
- wp_send_json( $arr_options );
233
- }
234
- }
235
-
236
-
237
- /**
238
- * Count the form errors.
239
- * @return integer
240
- */
241
- public function count_errors() {
242
- $errors = $this->errors;
243
-
244
- if ( $errors && is_array( $errors ) ) {
245
- return count( $errors );
246
- }
247
-
248
- return 0;
249
- }
250
-
251
-
252
- /**
253
- * Appends field errors
254
- *
255
- * @param string $key
256
- * @param string $error
257
- */
258
- public function add_error( $key, $error ) {
259
- if ( ! isset( $this->errors[ $key ] ) ) {
260
- /**
261
- * UM hook
262
- *
263
- * @type filter
264
- * @title um_submit_form_error
265
- * @description Change error text on submit form
266
- * @input_vars
267
- * [{"var":"$error","type":"string","desc":"Error String"},
268
- * {"var":"$key","type":"string","desc":"Error Key"}]
269
- * @change_log
270
- * ["Since: 2.0"]
271
- * @usage
272
- * <?php add_filter( 'um_submit_form_error', 'function_name', 10, 2 ); ?>
273
- * @example
274
- * <?php
275
- * add_filter( 'um_submit_form_error', 'my_submit_form_error', 10, 2 );
276
- * function my_submit_form_error( $error, $key ) {
277
- * // your code here
278
- * return $error;
279
- * }
280
- * ?>
281
- */
282
- $this->errors[ $key ] = apply_filters( 'um_submit_form_error', $error, $key );
283
- }
284
- }
285
-
286
- /**
287
- * Appends field notices
288
- * @param string $key
289
- * @param string $notice
290
- */
291
- public function add_notice( $key, $notice ) {
292
- if ( ! isset( $this->notices[ $key ] ) ) {
293
- /**
294
- * UM hook
295
- *
296
- * @type filter
297
- * @title um_submit_form_notice
298
- * @description Change notice text on submit form
299
- * @input_vars
300
- * [{"var":"$notice","type":"string","desc":"notice String"},
301
- * {"var":"$key","type":"string","desc":"notice Key"}]
302
- * @change_log
303
- * ["Since: 2.0"]
304
- * @usage
305
- * <?php add_filter( 'um_submit_form_notice', 'function_name', 10, 2 ); ?>
306
- * @example
307
- * <?php
308
- * add_filter( 'um_submit_form_notice', 'my_submit_form_notice', 10, 2 );
309
- * function my_submit_form_notice( $notice, $key ) {
310
- * // your code here
311
- * return $notice;
312
- * }
313
- * ?>
314
- */
315
- $this->notices[ $key ] = apply_filters( 'um_submit_form_notice', $notice, $key );
316
- }
317
- }
318
-
319
-
320
- /**
321
- * If a form has errors
322
- *
323
- * @param string $key
324
- * @return boolean
325
- */
326
- public function has_error( $key ) {
327
- if ( isset( $this->errors[ $key ] ) ) {
328
- return true;
329
- }
330
- return false;
331
- }
332
-
333
-
334
- /**
335
- * If a form has notices/info
336
- *
337
- * @param string $key
338
- * @return boolean
339
- */
340
- public function has_notice( $key ) {
341
- if ( isset( $this->notices[ $key ] ) ) {
342
- return true;
343
- }
344
- return false;
345
- }
346
-
347
-
348
- /**
349
- * Return the errors as a WordPress Error object
350
- *
351
- * @return \WP_Error
352
- */
353
- function get_wp_error() {
354
- $wp_error = new \WP_Error();
355
- if ( $this->count_errors() > 0 ) {
356
- foreach ( $this->errors as $key => $value ) {
357
- $wp_error->add( $key, $value );
358
- }
359
- }
360
- return $wp_error;
361
- }
362
-
363
-
364
- /**
365
- * Declare all fields
366
- */
367
- public function field_declare() {
368
- if ( isset( UM()->builtin()->custom_fields ) ) {
369
- $this->all_fields = UM()->builtin()->custom_fields;
370
- } else {
371
- $this->all_fields = null;
372
- }
373
- }
374
-
375
-
376
- /**
377
- * Validate form on submit
378
- */
379
- public function form_init() {
380
- if ( isset( $_SERVER['REQUEST_METHOD'] ) ) {
381
- $http_post = ( 'POST' === $_SERVER['REQUEST_METHOD'] );
382
- } else {
383
- $http_post = 'POST';
384
- }
385
-
386
- if ( $http_post && ! is_admin() && isset( $_POST['form_id'] ) && is_numeric( $_POST['form_id'] ) ) {
387
-
388
- $this->form_id = absint( $_POST['form_id'] );
389
- if ( 'um_form' !== get_post_type( $this->form_id ) ) {
390
- return;
391
- }
392
-
393
- $this->form_status = get_post_status( $this->form_id );
394
- if ( 'publish' !== $this->form_status ) {
395
- return;
396
- }
397
-
398
- $this->form_data = UM()->query()->post_data( $this->form_id );
399
-
400
- /**
401
- * UM hook
402
- *
403
- * @type action
404
- * @title um_before_submit_form_post
405
- * @description Before submit form
406
- * @change_log
407
- * ["Since: 2.0"]
408
- * @usage add_action( 'um_before_submit_form_post', 'function_name', 10, 1 );
409
- * @example
410
- * <?php
411
- * add_action( 'um_before_submit_form_post', 'my_before_submit_form_post', 10, 1 );
412
- * function my_run_ajax_function( $post ) {
413
- * // your code here
414
- * }
415
- * ?>
416
- */
417
- do_action( 'um_before_submit_form_post' );
418
-
419
- /* save entire form as global */
420
- /**
421
- * UM hook
422
- *
423
- * @type filter
424
- * @title um_submit_post_form
425
- * @description Change submitted data on form submit
426
- * @input_vars
427
- * [{"var":"$data","type":"array","desc":"Submitted data"}]
428
- * @change_log
429
- * ["Since: 2.0"]
430
- * @usage
431
- * <?php add_filter( 'um_submit_post_form', 'function_name', 10, 1 ); ?>
432
- * @example
433
- * <?php
434
- * add_filter( 'um_submit_post_form', 'my_submit_post_form', 10, 1 );
435
- * function my_submit_post_form( $data ) {
436
- * // your code here
437
- * return $data;
438
- * }
439
- * ?>
440
- */
441
- $this->post_form = apply_filters( 'um_submit_post_form', $_POST );
442
-
443
- if ( isset( $this->post_form[ UM()->honeypot ] ) && '' !== $this->post_form[ UM()->honeypot ] ) {
444
- wp_die( esc_html__( 'Hello, spam bot!', 'ultimate-member' ) );
445
- }
446
-
447
- $this->post_form = $this->beautify( $this->post_form );
448
- $this->post_form = $this->sanitize( $this->post_form );
449
- $this->post_form['submitted'] = $this->post_form;
450
-
451
- $this->post_form = array_merge( $this->form_data, $this->post_form );
452
-
453
- // Remove role from post_form at first if role ! empty and there aren't custom fields with role name
454
- if ( ! empty( $_POST['role'] ) ) {
455
- if ( ! isset( $this->form_data['custom_fields'] ) || ! strstr( $this->form_data['custom_fields'], 'role_' ) ) {
456
- unset( $this->post_form['role'] );
457
- unset( $this->post_form['submitted']['role'] );
458
- }
459
- }
460
-
461
- // Secure sanitize of the submitted data
462
- if ( ! empty( $this->post_form ) ) {
463
- $this->post_form = array_diff_key( $this->post_form, array_flip( UM()->user()->banned_keys ) );
464
- }
465
- if ( ! empty( $this->post_form['submitted'] ) ) {
466
- $this->post_form['submitted'] = array_diff_key( $this->post_form['submitted'], array_flip( UM()->user()->banned_keys ) );
467
- }
468
-
469
- // set default role from settings on registration form
470
- if ( isset( $this->post_form['mode'] ) && 'register' === $this->post_form['mode'] ) {
471
- $role = $this->assigned_role( $this->form_id );
472
- $this->post_form['role'] = $role;
473
- }
474
-
475
- if ( isset( $this->form_data['custom_fields'] ) && strstr( $this->form_data['custom_fields'], 'role_' ) ) { // Secure selected role
476
-
477
- if ( ! empty( $_POST['role'] ) ) {
478
- $custom_field_roles = $this->custom_field_roles( $this->form_data['custom_fields'] );
479
-
480
- if ( ! empty( $custom_field_roles ) ) {
481
- if ( is_array( $_POST['role'] ) ) {
482
- $role = current( $_POST['role'] );
483
- $role = sanitize_key( $role );
484
- } else {
485
- $role = sanitize_key( $_POST['role'] );
486
- }
487
-
488
- global $wp_roles;
489
- $role_keys = array_map(
490
- function( $item ) {
491
- return 'um_' . $item;
492
- },
493
- get_option( 'um_roles', array() )
494
- );
495
- $exclude_roles = array_diff( array_keys( $wp_roles->roles ), array_merge( $role_keys, array( 'subscriber' ) ) );
496
-
497
- if ( ! empty( $role ) &&
498
- ( ! in_array( $role, $custom_field_roles, true ) || in_array( $role, $exclude_roles, true ) ) ) {
499
- wp_die( esc_html__( 'This is not possible for security reasons.', 'ultimate-member' ) );
500
- }
501
-
502
- $this->post_form['role'] = $role;
503
- $this->post_form['submitted']['role'] = $role;
504
- } else {
505
- unset( $this->post_form['role'] );
506
- unset( $this->post_form['submitted']['role'] );
507
-
508
- // set default role for registration form if custom field hasn't proper value
509
- if ( isset( $this->post_form['mode'] ) && 'register' === $this->post_form['mode'] ) {
510
- $role = $this->assigned_role( $this->form_id );
511
- $this->post_form['role'] = $role;
512
- }
513
- }
514
- }
515
- }
516
-
517
- /**
518
- * UM hook
519
- *
520
- * @type filter
521
- * @title um_submit_form_data
522
- * @description Change submitted data on form submit
523
- * @input_vars
524
- * [{"var":"$data","type":"array","desc":"Submitted data"},
525
- * {"var":"$mode","type":"string","desc":"Form mode"}]
526
- * @change_log
527
- * ["Since: 2.0"]
528
- * @usage
529
- * <?php add_filter( 'um_submit_form_data', 'function_name', 10, 2 ); ?>
530
- * @example
531
- * <?php
532
- * add_filter( 'um_submit_form_data', 'my_submit_form_data', 10, 2 );
533
- * function my_submit_form_data( $data ) {
534
- * // your code here
535
- * return $data;
536
- * }
537
- * ?>
538
- */
539
- $this->post_form = apply_filters( 'um_submit_form_data', $this->post_form, $this->post_form['mode'] );
540
-
541
- /* Continue based on form mode - pre-validation */
542
-