Ultimate Member – User Profile & Membership Plugin - Version 2.4.1

Version Description

Download this release

Release Info

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

Code changes from version 2.4.0 to 2.4.1

assets/css/um-styles.css CHANGED
@@ -877,34 +877,40 @@ small.um-max-filesize span{
877
  right: 10px;
878
  }
879
 
880
- /* Customize Select2 CSS */
 
 
 
881
  .select2-container.select2-container--open {
882
- z-index: 9999999;
883
- }
884
  .select2.select2-container .select2-selection {
885
- display: block !important;
886
- height: 40px;
887
- padding: 0 0 0 12px !important;
888
- overflow: hidden !important;
889
- position: relative !important;
890
- white-space: nowrap !important;
891
- line-height: 35px !important;
892
- color: #666 !important;
893
- font-size: 15px !important;
894
- text-align: left !important;
895
- text-decoration: none !important;
896
- -moz-border-radius: 2px !important;
897
- -webkit-border-radius: 2px !important;
898
- border-radius: 2px !important;
899
- background-clip: padding-box !important;
900
- -webkit-touch-callout: none;
901
- -webkit-user-select: none;
902
- -moz-user-select: none;
903
- -ms-user-select: none;
904
- user-select: none;
905
- background: none !important;
906
- background-color: #fff !important;
907
- border: 1px solid #ddd !important;
 
 
 
908
  }
909
 
910
  .select2.select2-container .select2-selection .select2-selection__arrow {
@@ -922,51 +928,64 @@ small.um-max-filesize span{
922
  background: transparent !important;
923
  border-left: 0 !important;
924
  }
 
 
 
 
925
 
926
  .select2.select2-container .select2-selection .select2-selection__arrow:before {
927
  content: "\f3d0" !important;
928
- font-size: 27px !important;
929
- font-family: "Ionicons" !important;
930
- width: 100% !important;
931
- display: block;
932
- height: 100%;
933
- line-height: 35px;
934
- color: #aaaaaa;
 
 
935
  }
936
 
937
  .select2.select2-container .select2-selection .select2-selection__arrow b[role="presentation"] {
938
- display:none;
939
  }
940
 
941
  .select2-container.select2-container--open .select2-dropdown {
942
- border: 1px solid #ddd !important;
943
  border-radius: 0;
944
  }
945
 
946
  .select2-container.select2-container--open .select2-dropdown .select2-results li {
947
  list-style: none;
948
- display: list-item;
949
- background-image: none;
950
- font-size: 15px;
951
- margin: 5px !important;
952
- color: #666 !important;
953
- padding: 3px 7px 4px !important;
954
- cursor: pointer;
955
- min-height: 1em !important;
956
- }
957
 
958
  .select2.select2-container .select2-selection.select2-selection--multiple {
959
  height: auto !important;
960
  line-height: 0.8 !important;
 
 
961
  }
962
 
963
  .select2-container--default .select2-selection--single .select2-selection__rendered {
964
- padding-left: 0 !important;
965
  line-height: 37px;
 
 
 
 
 
 
966
  }
967
 
968
  .select2-container--default .select2-selection--multiple .select2-selection__rendered {
969
- line-height: 37px;
970
  box-sizing: border-box;
971
  list-style: none;
972
  margin: 0;
@@ -975,23 +994,36 @@ small.um-max-filesize span{
975
  width: 100%;
976
  font-size: 13px;
977
  }
 
 
 
 
978
 
979
  .select2-results li.select2-results__option.select2-results__option--highlighted {
980
- background: none !important;
981
- background: #f4f4f4 !important;
982
- color: #666 !important;
983
  }
984
  .select2-container--default .select2-results__option[aria-selected="true"] {
985
- background-color: #ddd;
986
  }
987
 
988
 
989
  .select2-container--default .select2-selection--single .select2-selection__clear,
990
  .select2-container--default .select2-selection--multiple .select2-selection__clear {
991
- right: 10px;
992
- font-size: 30px;
993
  color: #aaaaaa !important;
 
 
 
994
  margin: 0 !important;
 
 
 
 
 
 
 
 
995
  }
996
 
997
  .select2-container--default .select2-selection--multiple .select2-selection__clear {
@@ -999,13 +1031,28 @@ small.um-max-filesize span{
999
  }
1000
 
1001
  .select2-container--default .select2-selection--multiple .select2-selection__choice {
 
1002
  padding: 3px 3px 3px 5px;
1003
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
1004
 
1005
  .um .um-form .select2-container .select2-search.select2-search--inline > input {
1006
  border: none !important;
1007
  padding: 0 !important;
1008
  border-radius: 0 !important;
 
1009
  }
1010
 
1011
  .um .um-form .select2-container--default .select2-selection--multiple .select2-selection__rendered li {
@@ -1013,6 +1060,7 @@ small.um-max-filesize span{
1013
  text-overflow: ellipsis;
1014
  max-width: 100%;
1015
  box-sizing: border-box;
 
1016
  }
1017
 
1018
  /*
@@ -1042,10 +1090,6 @@ small.um-max-filesize span{
1042
  /*width: 100% !important;*/
1043
  /*}*/
1044
 
1045
-
1046
-
1047
-
1048
-
1049
  /* @todo maybe deprecated and used only for select and multiselect */
1050
  .um-field-select .um-field-area .um-field-icon,
1051
  .um-field-multiselect .um-field-area .um-field-icon {
877
  right: 10px;
878
  }
879
 
880
+ /*
881
+ - Customize Select2 CSS
882
+ */
883
+
884
  .select2-container.select2-container--open {
885
+ z-index: 9999999;
886
+ }
887
  .select2.select2-container .select2-selection {
888
+ display: block !important;
889
+ height: 40px;
890
+ padding: 0 0 0 12px !important;
891
+ overflow: hidden !important;
892
+ position: relative !important;
893
+ white-space: nowrap !important;
894
+ line-height: 35px !important;
895
+ color: #666 !important;
896
+ font-size: 15px !important;
897
+ text-align: left !important;
898
+ text-decoration: none !important;
899
+ -moz-border-radius: 2px !important;
900
+ -webkit-border-radius: 2px !important;
901
+ border-radius: 2px !important;
902
+ background-clip: padding-box !important;
903
+ -webkit-touch-callout: none;
904
+ -webkit-user-select: none;
905
+ -moz-user-select: none;
906
+ -ms-user-select: none;
907
+ user-select: none;
908
+ background: none !important;
909
+ background-color: #fff !important;
910
+ border: 1px solid #ddd !important;
911
+ }
912
+ .rtl .select2.select2-container .select2-selection {
913
+ padding: 0 12px 0 0 !important;
914
  }
915
 
916
  .select2.select2-container .select2-selection .select2-selection__arrow {
928
  background: transparent !important;
929
  border-left: 0 !important;
930
  }
931
+ .rtl .select2.select2-container .select2-selection .select2-selection__arrow {
932
+ right: initial !important;
933
+ left: 0 !important;
934
+ }
935
 
936
  .select2.select2-container .select2-selection .select2-selection__arrow:before {
937
  content: "\f3d0" !important;
938
+ font-size: 28px !important;
939
+ font-family: "Ionicons" !important;
940
+ font-weight: normal;
941
+ display: block;
942
+ height: 100%;
943
+ line-height: 40px;
944
+ min-width: 1em;
945
+ text-align: center;
946
+ color: #aaaaaa;
947
  }
948
 
949
  .select2.select2-container .select2-selection .select2-selection__arrow b[role="presentation"] {
950
+ display: none;
951
  }
952
 
953
  .select2-container.select2-container--open .select2-dropdown {
954
+ border: 1px solid #ddd !important;
955
  border-radius: 0;
956
  }
957
 
958
  .select2-container.select2-container--open .select2-dropdown .select2-results li {
959
  list-style: none;
960
+ display: list-item;
961
+ background-image: none;
962
+ font-size: 15px;
963
+ margin: 5px !important;
964
+ color: #666 !important;
965
+ padding: 3px 7px 4px !important;
966
+ cursor: pointer;
967
+ min-height: 1em !important;
968
+ }
969
 
970
  .select2.select2-container .select2-selection.select2-selection--multiple {
971
  height: auto !important;
972
  line-height: 0.8 !important;
973
+ min-height: 40px;
974
+ padding-bottom: 4px !important;
975
  }
976
 
977
  .select2-container--default .select2-selection--single .select2-selection__rendered {
 
978
  line-height: 37px;
979
+ padding-left: 0 !important;
980
+ padding-right: 24px !important;
981
+ }
982
+ .rtl .select2-container--default .select2-selection--single .select2-selection__rendered {
983
+ padding-left: 24px !important;
984
+ padding-right: 0 !important;
985
  }
986
 
987
  .select2-container--default .select2-selection--multiple .select2-selection__rendered {
988
+ line-height: 37px;
989
  box-sizing: border-box;
990
  list-style: none;
991
  margin: 0;
994
  width: 100%;
995
  font-size: 13px;
996
  }
997
+ .rtl .select2-container--default .select2-selection--multiple .select2-selection__rendered {
998
+ padding-left: 30px !important;
999
+ padding-right: 0 !important;
1000
+ }
1001
 
1002
  .select2-results li.select2-results__option.select2-results__option--highlighted {
1003
+ background: none !important;
1004
+ background: #f4f4f4 !important;
1005
+ color: #666 !important;
1006
  }
1007
  .select2-container--default .select2-results__option[aria-selected="true"] {
1008
+ background-color: #ddd;
1009
  }
1010
 
1011
 
1012
  .select2-container--default .select2-selection--single .select2-selection__clear,
1013
  .select2-container--default .select2-selection--multiple .select2-selection__clear {
 
 
1014
  color: #aaaaaa !important;
1015
+ font-size: 28px;
1016
+ font-weight: normal;
1017
+ line-height: 34px;
1018
  margin: 0 !important;
1019
+ right: 0;
1020
+ text-align: center;
1021
+ width: 1em;
1022
+ }
1023
+ .rtl .select2-container--default .select2-selection--single .select2-selection__clear,
1024
+ .rtl .select2-container--default .select2-selection--multiple .select2-selection__clear {
1025
+ left: 0;
1026
+ right: initial;
1027
  }
1028
 
1029
  .select2-container--default .select2-selection--multiple .select2-selection__clear {
1031
  }
1032
 
1033
  .select2-container--default .select2-selection--multiple .select2-selection__choice {
1034
+ margin: 5px 5px 0 0;
1035
  padding: 3px 3px 3px 5px;
1036
  }
1037
+ .rtl .select2-container--default .select2-selection--multiple .select2-selection__choice{
1038
+ margin: 5px 0 0 5px;
1039
+ max-height: 28px;
1040
+ padding: 3px 5px 3px 3px;
1041
+ }
1042
+
1043
+ .um .um-form .select2-container .select2-search.select2-search--inline{
1044
+ margin: 5px 5px 0 0;
1045
+ padding: 0px;
1046
+ }
1047
+ .rtl .um .um-form .select2-container .select2-search.select2-search--inline{
1048
+ margin: 5px 0 0 5px;
1049
+ }
1050
 
1051
  .um .um-form .select2-container .select2-search.select2-search--inline > input {
1052
  border: none !important;
1053
  padding: 0 !important;
1054
  border-radius: 0 !important;
1055
+ max-height: 28px;
1056
  }
1057
 
1058
  .um .um-form .select2-container--default .select2-selection--multiple .select2-selection__rendered li {
1060
  text-overflow: ellipsis;
1061
  max-width: 100%;
1062
  box-sizing: border-box;
1063
+ line-height: 20px;
1064
  }
1065
 
1066
  /*
1090
  /*width: 100% !important;*/
1091
  /*}*/
1092
 
 
 
 
 
1093
  /* @todo maybe deprecated and used only for select and multiselect */
1094
  .um-field-select .um-field-area .um-field-icon,
1095
  .um-field-multiselect .um-field-area .um-field-icon {
includes/admin/class-admin.php CHANGED
@@ -1,1980 +1,1980 @@
1
- <?php
2
- namespace um\admin;
3
-
4
- // Exit if accessed directly.
5
- if ( ! defined( 'ABSPATH' ) ) {
6
- exit;
7
- }
8
-
9
- if ( ! class_exists( 'um\admin\Admin' ) ) {
10
-
11
-
12
- /**
13
- * Class Admin
14
- * @package um\admin
15
- */
16
- class Admin extends Admin_Functions {
17
-
18
-
19
- /**
20
- * @var string
21
- */
22
- public $templates_path;
23
-
24
-
25
- /**
26
- * @var array
27
- */
28
- public $role_meta;
29
-
30
-
31
- /**
32
- * @var array
33
- */
34
- public $restriction_term_meta;
35
-
36
-
37
- /**
38
- * @var array
39
- */
40
- public $member_directory_meta;
41
-
42
-
43
- /**
44
- * @var array
45
- */
46
- public $form_meta;
47
-
48
-
49
- /**
50
- * @var array
51
- */
52
- public $builder_input;
53
-
54
-
55
- /**
56
- * @var array
57
- */
58
- public $restriction_post_meta;
59
-
60
-
61
- /**
62
- * Admin constructor.
63
- */
64
- public function __construct() {
65
- parent::__construct();
66
-
67
- $this->templates_path = um_path . 'includes/admin/templates/';
68
-
69
- add_action( 'admin_init', array( &$this, 'admin_init' ), 0 );
70
-
71
- $prefix = is_network_admin() ? 'network_admin_' : '';
72
- add_filter( "{$prefix}plugin_action_links_" . um_plugin, array( &$this, 'plugin_links' ) );
73
-
74
- add_action( 'um_admin_do_action__user_cache', array( &$this, 'user_cache' ) );
75
- add_action( 'um_admin_do_action__purge_temp', array( &$this, 'purge_temp' ) );
76
- add_action( 'um_admin_do_action__manual_upgrades_request', array( &$this, 'manual_upgrades_request' ) );
77
- add_action( 'um_admin_do_action__duplicate_form', array( &$this, 'duplicate_form' ) );
78
- add_action( 'um_admin_do_action__um_hide_locale_notice', array( &$this, 'um_hide_notice' ) );
79
- add_action( 'um_admin_do_action__um_can_register_notice', array( &$this, 'um_hide_notice' ) );
80
- add_action( 'um_admin_do_action__um_hide_exif_notice', array( &$this, 'um_hide_notice' ) );
81
- add_action( 'um_admin_do_action__user_action', array( &$this, 'user_action' ) );
82
-
83
- add_action( 'um_admin_do_action__install_core_pages', array( &$this, 'install_core_pages' ) );
84
-
85
- add_filter( 'admin_body_class', array( &$this, 'admin_body_class' ), 999 );
86
-
87
- add_action( 'parent_file', array( &$this, 'parent_file' ), 9 );
88
- add_filter( 'gettext', array( &$this, 'gettext' ), 10, 4 );
89
- add_filter( 'post_updated_messages', array( &$this, 'post_updated_messages' ) );
90
- }
91
-
92
-
93
- function init_variables() {
94
- $this->role_meta = apply_filters(
95
- 'um_role_meta_map',
96
- array(
97
- '_um_priority' => array(
98
- 'sanitize' => 'int',
99
- ),
100
- '_um_can_access_wpadmin' => array(
101
- 'sanitize' => 'bool',
102
- ),
103
- '_um_can_not_see_adminbar' => array(
104
- 'sanitize' => 'bool',
105
- ),
106
- '_um_can_edit_everyone' => array(
107
- 'sanitize' => 'bool',
108
- ),
109
- '_um_can_edit_roles' => array(
110
- 'sanitize' => array( $this, 'sanitize_existed_role' ),
111
- ),
112
- '_um_can_delete_everyone' => array(
113
- 'sanitize' => 'bool',
114
- ),
115
- '_um_can_delete_roles' => array(
116
- 'sanitize' => array( $this, 'sanitize_existed_role' ),
117
- ),
118
- '_um_can_edit_profile' => array(
119
- 'sanitize' => 'bool',
120
- ),
121
- '_um_can_delete_profile' => array(
122
- 'sanitize' => 'bool',
123
- ),
124
- '_um_can_view_all' => array(
125
- 'sanitize' => 'bool',
126
- ),
127
- '_um_can_view_roles' => array(
128
- 'sanitize' => array( $this, 'sanitize_existed_role' ),
129
- ),
130
- '_um_can_make_private_profile' => array(
131
- 'sanitize' => 'bool',
132
- ),
133
- '_um_can_access_private_profile' => array(
134
- 'sanitize' => 'bool',
135
- ),
136
- '_um_profile_noindex' => array(
137
- 'sanitize' => array( $this, 'sanitize_profile_noindex' ),
138
- ),
139
- '_um_default_homepage' => array(
140
- 'sanitize' => 'bool',
141
- ),
142
- '_um_redirect_homepage' => array(
143
- 'sanitize' => 'url',
144
- ),
145
- '_um_status' => array(
146
- 'sanitize' => 'sanitize_array_key',
147
- 'default' => 'approved',
148
- 'array' => array( 'approved', 'checkmail', 'pending' ),
149
- ),
150
- '_um_auto_approve_act' => array(
151
- 'sanitize' => 'sanitize_array_key',
152
- 'default' => 'redirect_profile',
153
- 'array' => array( 'redirect_profile', 'redirect_url' ),
154
- ),
155
- '_um_auto_approve_url' => array(
156
- 'sanitize' => 'url',
157
- ),
158
- '_um_login_email_activate' => array(
159
- 'sanitize' => 'bool',
160
- ),
161
- '_um_checkmail_action' => array(
162
- 'sanitize' => 'sanitize_array_key',
163
- 'default' => 'show_message',
164
- 'array' => array( 'show_message', 'redirect_url' ),
165
- ),
166
- '_um_checkmail_message' => array(
167
- 'sanitize' => 'textarea',
168
- ),
169
- '_um_checkmail_url' => array(
170
- 'sanitize' => 'url',
171
- ),
172
- '_um_url_email_activate' => array(
173
- 'sanitize' => 'url',
174
- ),
175
- '_um_pending_action' => array(
176
- 'sanitize' => 'sanitize_array_key',
177
- 'default' => 'show_message',
178
- 'array' => array( 'show_message', 'redirect_url' ),
179
- ),
180
- '_um_pending_message' => array(
181
- 'sanitize' => 'textarea',
182
- ),
183
- '_um_pending_url' => array(
184
- 'sanitize' => 'url',
185
- ),
186
- '_um_after_login' => array(
187
- 'sanitize' => 'sanitize_array_key',
188
- 'default' => 'redirect_profile',
189
- 'array' => array( 'redirect_profile', 'redirect_url', 'refresh', 'redirect_admin' ),
190
- ),
191
- '_um_login_redirect_url' => array(
192
- 'sanitize' => 'url',
193
- ),
194
- '_um_after_logout' => array(
195
- 'sanitize' => 'sanitize_array_key',
196
- 'default' => 'redirect_home',
197
- 'array' => array( 'redirect_home', 'redirect_url' ),
198
- ),
199
- '_um_logout_redirect_url' => array(
200
- 'sanitize' => 'url',
201
- ),
202
- '_um_after_delete' => array(
203
- 'sanitize' => 'sanitize_array_key',
204
- 'default' => 'redirect_home',
205
- 'array' => array( 'redirect_home', 'redirect_url' ),
206
- ),
207
- '_um_delete_redirect_url' => array(
208
- 'sanitize' => 'url',
209
- ),
210
- 'wp_capabilities' => array(
211
- 'sanitize' => array( $this, 'sanitize_wp_capabilities' ),
212
- ),
213
- )
214
- );
215
-
216
- $this->restriction_post_meta = apply_filters(
217
- 'um_restriction_post_meta_map',
218
- array(
219
- '_um_custom_access_settings' => array(
220
- 'sanitize' => 'bool',
221
- ),
222
- '_um_accessible' => array(
223
- 'sanitize' => 'int',
224
- ),
225
- '_um_access_roles' => array(
226
- 'sanitize' => array( $this, 'sanitize_restriction_existed_role' ),
227
- ),
228
- '_um_noaccess_action' => array(
229
- 'sanitize' => 'int',
230
- ),
231
- '_um_restrict_by_custom_message' => array(
232
- 'sanitize' => 'int',
233
- ),
234
- '_um_restrict_custom_message' => array(
235
- 'sanitize' => 'wp_kses',
236
- ),
237
- '_um_access_redirect' => array(
238
- 'sanitize' => 'int',
239
- ),
240
- '_um_access_redirect_url' => array(
241
- 'sanitize' => 'url',
242
- ),
243
- '_um_access_hide_from_queries' => array(
244
- 'sanitize' => 'bool',
245
- ),
246
- )
247
- );
248
-
249
- $this->restriction_term_meta = apply_filters(
250
- 'um_restriction_term_meta_map',
251
- array(
252
- '_um_custom_access_settings' => array(
253
- 'sanitize' => 'bool',
254
- ),
255
- '_um_accessible' => array(
256
- 'sanitize' => 'int',
257
- ),
258
- '_um_access_roles' => array(
259
- 'sanitize' => array( $this, 'sanitize_restriction_existed_role' ),
260
- ),
261
- '_um_noaccess_action' => array(
262
- 'sanitize' => 'int',
263
- ),
264
- '_um_restrict_by_custom_message' => array(
265
- 'sanitize' => 'int',
266
- ),
267
- '_um_restrict_custom_message' => array(
268
- 'sanitize' => 'wp_kses',
269
- ),
270
- '_um_access_redirect' => array(
271
- 'sanitize' => 'int',
272
- ),
273
- '_um_access_redirect_url' => array(
274
- 'sanitize' => 'url',
275
- ),
276
- '_um_access_hide_from_queries' => array(
277
- 'sanitize' => 'bool',
278
- ),
279
- )
280
- );
281
-
282
- $this->member_directory_meta = apply_filters(
283
- 'um_member_directory_meta_map',
284
- array(
285
- '_um_directory_template' => array(
286
- 'sanitize' => 'text',
287
- ),
288
- '_um_mode' => array(
289
- 'sanitize' => 'key',
290
- ),
291
- '_um_view_types' => array(
292
- 'sanitize' => array( $this, 'sanitize_md_view_types' ),
293
- ),
294
- '_um_default_view' => array(
295
- 'sanitize' => 'key',
296
- ),
297
- '_um_roles' => array(
298
- 'sanitize' => array( $this, 'sanitize_restriction_existed_role' ),
299
- ),
300
- '_um_has_profile_photo' => array(
301
- 'sanitize' => 'bool',
302
- ),
303
- '_um_show_these_users' => array(
304
- 'sanitize' => 'textarea',
305
- ),
306
- '_um_exclude_these_users' => array(
307
- 'sanitize' => 'textarea',
308
- ),
309
- '_um_must_search' => array(
310
- 'sanitize' => 'bool',
311
- ),
312
- '_um_max_users' => array(
313
- 'sanitize' => 'absint',
314
- ),
315
- '_um_profiles_per_page' => array(
316
- 'sanitize' => 'absint',
317
- ),
318
- '_um_profiles_per_page_mobile' => array(
319
- 'sanitize' => 'absint',
320
- ),
321
- '_um_directory_header' => array(
322
- 'sanitize' => 'text',
323
- ),
324
- '_um_directory_header_single' => array(
325
- 'sanitize' => 'text',
326
- ),
327
- '_um_directory_no_users' => array(
328
- 'sanitize' => 'text',
329
- ),
330
- '_um_profile_photo' => array(
331
- 'sanitize' => 'bool',
332
- ),
333
- '_um_cover_photos' => array(
334
- 'sanitize' => 'bool',
335
- ),
336
- '_um_show_name' => array(
337
- 'sanitize' => 'bool',
338
- ),
339
- '_um_show_tagline' => array(
340
- 'sanitize' => 'bool',
341
- ),
342
- '_um_tagline_fields' => array(
343
- 'sanitize' => array( $this, 'sanitize_user_field' ),
344
- ),
345
- '_um_show_userinfo' => array(
346
- 'sanitize' => 'bool',
347
- ),
348
- '_um_reveal_fields' => array(
349
- 'sanitize' => array( $this, 'sanitize_user_field' ),
350
- ),
351
- '_um_show_social' => array(
352
- 'sanitize' => 'bool',
353
- ),
354
- '_um_userinfo_animate' => array(
355
- 'sanitize' => 'bool',
356
- ),
357
- '_um_search' => array(
358
- 'sanitize' => 'bool',
359
- ),
360
- '_um_roles_can_search' => array(
361
- 'sanitize' => array( $this, 'sanitize_restriction_existed_role' ),
362
- ),
363
- '_um_filters' => array(
364
- 'sanitize' => 'bool',
365
- ),
366
- '_um_roles_can_filter' => array(
367
- 'sanitize' => array( $this, 'sanitize_restriction_existed_role' ),
368
- ),
369
- '_um_search_fields' => array(
370
- 'sanitize' => array( $this, 'sanitize_filter_fields' ),
371
- ),
372
- '_um_filters_expanded' => array(
373
- 'sanitize' => 'bool',
374
- ),
375
- '_um_filters_is_collapsible' => array(
376
- 'sanitize' => 'bool',
377
- ),
378
- '_um_search_filters' => array(
379
- 'sanitize' => array( $this, 'sanitize_filter_fields' ),
380
- ),
381
- '_um_sortby' => array(
382
- 'sanitize' => 'text',
383
- ),
384
- '_um_sortby_custom' => array(
385
- 'sanitize' => 'text',
386
- ),
387
- '_um_sortby_custom_label' => array(
388
- 'sanitize' => 'text',
389
- ),
390
- '_um_enable_sorting' => array(
391
- 'sanitize' => 'bool',
392
- ),
393
- '_um_sorting_fields' => array(
394
- 'sanitize' => array( $this, 'sanitize_md_sorting_fields' ),
395
- ),
396
- )
397
- );
398
-
399
- $this->form_meta = apply_filters(
400
- 'um_form_meta_map',
401
- array(
402
- '_um_mode' => array(
403
- 'sanitize' => 'key',
404
- ),
405
- '_um_register_use_gdpr' => array(
406
- 'sanitize' => 'bool',
407
- ),
408
- '_um_register_use_gdpr_content_id' => array(
409
- 'sanitize' => 'absint',
410
- ),
411
- '_um_register_use_gdpr_toggle_show' => array(
412
- 'sanitize' => 'text',
413
- ),
414
- '_um_register_use_gdpr_toggle_hide' => array(
415
- 'sanitize' => 'text',
416
- ),
417
- '_um_register_use_gdpr_agreement' => array(
418
- 'sanitize' => 'text',
419
- ),
420
- '_um_register_use_gdpr_error_text' => array(
421
- 'sanitize' => 'text',
422
- ),
423
- '_um_register_use_custom_settings' => array(
424
- 'sanitize' => 'bool',
425
- ),
426
- '_um_register_role' => array(
427
- 'sanitize' => 'key',
428
- ),
429
- '_um_register_template' => array(
430
- 'sanitize' => 'text',
431
- ),
432
- '_um_register_max_width' => array(
433
- 'sanitize' => 'text',
434
- ),
435
- '_um_register_icons' => array(
436
- 'sanitize' => 'key',
437
- ),
438
- '_um_register_primary_btn_word' => array(
439
- 'sanitize' => 'text',
440
- ),
441
- '_um_register_secondary_btn' => array(
442
- 'sanitize' => 'bool',
443
- ),
444
- '_um_register_secondary_btn_word' => array(
445
- 'sanitize' => 'text',
446
- ),
447
- '_um_login_after_login' => array(
448
- 'sanitize' => 'key',
449
- ),
450
- '_um_login_redirect_url' => array(
451
- 'sanitize' => 'url',
452
- ),
453
- '_um_login_use_custom_settings' => array(
454
- 'sanitize' => 'bool',
455
- ),
456
- '_um_login_template' => array(
457
- 'sanitize' => 'text',
458
- ),
459
- '_um_login_max_width' => array(
460
- 'sanitize' => 'text',
461
- ),
462
- '_um_login_icons' => array(
463
- 'sanitize' => 'key',
464
- ),
465
- '_um_login_primary_btn_word' => array(
466
- 'sanitize' => 'text',
467
- ),
468
- '_um_login_secondary_btn' => array(
469
- 'sanitize' => 'bool',
470
- ),
471
- '_um_login_secondary_btn_word' => array(
472
- 'sanitize' => 'text',
473
- ),
474
- '_um_login_forgot_pass_link' => array(
475
- 'sanitize' => 'bool',
476
- ),
477
- '_um_login_show_rememberme' => array(
478
- 'sanitize' => 'bool',
479
- ),
480
- '_um_profile_metafields' => array(
481
- 'sanitize' => array( $this, 'sanitize_user_field' ),
482
- ),
483
- '_um_profile_use_custom_settings' => array(
484
- 'sanitize' => 'bool',
485
- ),
486
- '_um_profile_role' => array(
487
- 'sanitize' => array( $this, 'sanitize_existed_role' ),
488
- ),
489
- '_um_profile_template' => array(
490
- 'sanitize' => 'text',
491
- ),
492
- '_um_profile_max_width' => array(
493
- 'sanitize' => 'text',
494
- ),
495
- '_um_profile_area_max_width' => array(
496
- 'sanitize' => 'text',
497
- ),
498
- '_um_profile_icons' => array(
499
- 'sanitize' => 'key',
500
- ),
501
- '_um_profile_primary_btn_word' => array(
502
- 'sanitize' => 'text',
503
- ),
504
- '_um_profile_secondary_btn' => array(
505
- 'sanitize' => 'bool',
506
- ),
507
- '_um_profile_secondary_btn_word' => array(
508
- 'sanitize' => 'text',
509
- ),
510
- '_um_profile_cover_enabled' => array(
511
- 'sanitize' => 'bool',
512
- ),
513
- '_um_profile_coversize' => array(
514
- 'sanitize' => 'absint',
515
- ),
516
- '_um_profile_cover_ratio' => array(
517
- 'sanitize' => 'text',
518
- ),
519
- '_um_profile_disable_photo_upload' => array(
520
- 'sanitize' => 'bool',
521
- ),
522
- '_um_profile_photosize' => array(
523
- 'sanitize' => array( $this, 'sanitize_photosize' ),
524
- ),
525
- '_um_profile_photo_required' => array(
526
- 'sanitize' => 'bool',
527
- ),
528
- '_um_profile_show_name' => array(
529
- 'sanitize' => 'bool',
530
- ),
531
- '_um_profile_show_social_links' => array(
532
- 'sanitize' => 'bool',
533
- ),
534
- '_um_profile_show_bio' => array(
535
- 'sanitize' => 'bool',
536
- ),
537
-
538
- )
539
- );
540
-
541
- $this->builder_input = apply_filters(
542
- 'um_builder_input_map',
543
- array(
544
- '_in_row' => array(
545
- 'sanitize' => 'key',
546
- ),
547
- '_in_sub_row' => array(
548
- 'sanitize' => 'absint',
549
- ),
550
- '_in_column' => array(
551
- 'sanitize' => 'absint',
552
- ),
553
- '_in_group' => array(
554
- 'sanitize' => 'absint',
555
- ),
556
- '_visibility' => array(
557
- 'sanitize' => 'key',
558
- ),
559
- '_conditional_action' => array(
560
- 'sanitize' => 'key',
561
- ),
562
- '_conditional_action1' => array(
563
- 'sanitize' => 'key',
564
- ),
565
- '_conditional_action2' => array(
566
- 'sanitize' => 'key',
567
- ),
568
- '_conditional_action3' => array(
569
- 'sanitize' => 'key',
570
- ),
571
- '_conditional_action4' => array(
572
- 'sanitize' => 'key',
573
- ),
574
- '_conditional_field' => array(
575
- 'sanitize' => 'text',
576
- ),
577
- '_conditional_field1' => array(
578
- 'sanitize' => 'text',
579
- ),
580
- '_conditional_field2' => array(
581
- 'sanitize' => 'text',
582
- ),
583
- '_conditional_field3' => array(
584
- 'sanitize' => 'text',
585
- ),
586
- '_conditional_field4' => array(
587
- 'sanitize' => 'text',
588
- ),
589
- '_conditional_operator' => array(
590
- 'sanitize' => 'text',
591
- ),
592
- '_conditional_operator1' => array(
593
- 'sanitize' => 'text',
594
- ),
595
- '_conditional_operator2' => array(
596
- 'sanitize' => 'text',
597
- ),
598
- '_conditional_operator3' => array(
599
- 'sanitize' => 'text',
600
- ),
601
- '_conditional_operator4' => array(
602
- 'sanitize' => 'text',
603
- ),
604
- '_conditional_value' => array(
605
- 'sanitize' => 'text',
606
- ),
607
- '_conditional_value1' => array(
608
- 'sanitize' => 'text',
609
- ),
610
- '_conditional_value2' => array(
611
- 'sanitize' => 'text',
612
- ),
613
- '_conditional_value3' => array(
614
- 'sanitize' => 'text',
615
- ),
616
- '_conditional_value4' => array(
617
- 'sanitize' => 'text',
618
- ),
619
- '_validate' => array(
620
- 'sanitize' => 'key',
621
- ),
622
- '_custom_validate' => array(
623
- 'sanitize' => 'text',
624
- ),
625
- '_icon' => array(
626
- 'sanitize' => 'key',
627
- ),
628
- '_css_class' => array(
629
- 'sanitize' => 'text',
630
- ),
631
- '_width' => array(
632
- 'sanitize' => 'absint',
633
- ),
634
- '_divider_text' => array(
635
- 'sanitize' => 'text',
636
- ),
637
- '_padding' => array(
638
- 'sanitize' => 'text',
639
- ),
640
- '_margin' => array(
641
- 'sanitize' => 'text',
642
- ),
643
- '_border' => array(
644
- 'sanitize' => 'text',
645
- ),
646
- '_borderstyle' => array(
647
- 'sanitize' => 'key',
648
- ),
649
- '_borderradius' => array(
650
- 'sanitize' => 'text',
651
- ),
652
- '_bordercolor' => array(
653
- 'sanitize' => 'text',
654
- ),
655
- '_heading' => array(
656
- 'sanitize' => 'bool',
657
- ),
658
- '_heading_text' => array(
659
- 'sanitize' => 'text',
660
- ),
661
- '_background' => array(
662
- 'sanitize' => 'text',
663
- ),
664
- '_heading_background_color' => array(
665
- 'sanitize' => 'text',
666
- ),
667
- '_heading_text_color' => array(
668
- 'sanitize' => 'text',
669
- ),
670
- '_text_color' => array(
671
- 'sanitize' => 'text',
672
- ),
673
- '_icon_color' => array(
674
- 'sanitize' => 'text',
675
- ),
676
- '_color' => array(
677
- 'sanitize' => 'text',
678
- ),
679
- '_url_text' => array(
680
- 'sanitize' => 'text',
681
- ),
682
- '_url_target' => array(
683
- 'sanitize' => 'key',
684
- ),
685
- '_url_rel' => array(
686
- 'sanitize' => 'key',
687
- ),
688
- '_force_good_pass' => array(
689
- 'sanitize' => 'bool',
690
- ),
691
- '_force_confirm_pass' => array(
692
- 'sanitize' => 'bool',
693
- ),
694
- '_style' => array(
695
- 'sanitize' => 'key',
696
- ),
697
- '_intervals' => array(
698
- 'sanitize' => 'absint',
699
- ),
700
- '_format' => array(
701
- 'sanitize' => 'text',
702
- ),
703
- '_format_custom' => array(
704
- 'sanitize' => 'text',
705
- ),
706
- '_pretty_format' => array(
707
- 'sanitize' => 'bool',
708
- ),
709
- '_disabled_weekdays' => array(
710
- 'sanitize' => 'absint',
711
- ),
712
- '_years' => array(
713
- 'sanitize' => 'absint',
714
- ),
715
- '_years_x' => array(
716
- 'sanitize' => 'key',
717
- ),
718
- '_range_start' => array(
719
- 'sanitize' => 'text',
720
- ),
721
- '_range_end' => array(
722
- 'sanitize' => 'text',
723
- ),
724
- '_range' => array(
725
- 'sanitize' => 'key',
726
- ),
727
- '_content' => array(
728
- 'sanitize' => 'textarea',
729
- ),
730
- '_crop' => array(
731
- 'sanitize' => 'int',
732
- ),
733
- '_allowed_types' => array(
734
- 'sanitize' => 'key',
735
- ),
736
- '_upload_text' => array(
737
- 'sanitize' => 'text',
738
- ),
739
- '_upload_help_text' => array(
740
- 'sanitize' => 'text',
741
- ),
742
- '_button_text' => array(
743
- 'sanitize' => 'text',
744
- ),
745
- '_max_size' => array(
746
- 'sanitize' => 'absint',
747
- ),
748
- '_height' => array(
749
- 'sanitize' => 'text',
750
- ),
751
- '_spacing' => array(
752
- 'sanitize' => 'text',
753
- ),
754
- '_is_multi' => array(
755
- 'sanitize' => 'bool',
756
- ),
757
- '_max_selections' => array(
758
- 'sanitize' => 'absint',
759
- ),
760
- '_min_selections' => array(
761
- 'sanitize' => 'absint',
762
- ),
763
- '_max_entries' => array(
764
- 'sanitize' => 'absint',
765
- ),
766
- '_max_words' => array(
767
- 'sanitize' => 'absint',
768
- ),
769
- '_min' => array(
770
- 'sanitize' => 'empty_int',
771
- ),
772
- '_max' => array(
773
- 'sanitize' => 'empty_int',
774
- ),
775
- '_min_chars' => array(
776
- 'sanitize' => 'absint',
777
- ),
778
- '_max_chars' => array(
779
- 'sanitize' => 'absint',
780
- ),
781
- '_html' => array(
782
- 'sanitize' => 'bool',
783
- ),
784
- '_options' => array(
785
- 'sanitize' => 'textarea',
786
- ),
787
- '_title' => array(
788
- 'sanitize' => 'text',
789
- ),
790
- '_id' => array(
791
- 'sanitize' => 'text',
792
- ),
793
- '_metakey' => array(
794
- 'sanitize' => 'text',
795
- ),
796
- '_help' => array(
797
- 'sanitize' => 'text',
798
- ),
799
- '_default' => array(
800
- 'sanitize' => 'text',
801
- ),
802
- '_label' => array(
803
- 'sanitize' => 'text',
804
- ),
805
- '_label_confirm_pass' => array(
806
- 'sanitize' => 'text',
807
- ),
808
- '_placeholder' => array(
809
- 'sanitize' => 'text',
810
- ),
811
- '_public' => array(
812
- 'sanitize' => 'text',
813
- ),
814
- '_roles' => array(
815
- 'sanitize' => array( $this, 'sanitize_existed_role' ),
816
- ),
817
- '_required' => array(
818
- 'sanitize' => 'bool',
819
- ),
820
- '_editable' => array(
821
- 'sanitize' => 'bool',
822
- ),
823
- '_number' => array(
824
- 'sanitize' => 'absint',
825
- ),
826
- '_custom_dropdown_options_source' => array(
827
- 'sanitize' => 'text',
828
- ),
829
- '_parent_dropdown_relationship' => array(
830
- 'sanitize' => 'text',
831
- ),
832
- )
833
- );
834
- }
835
-
836
-
837
- /**
838
- * @param array|string $value
839
- *
840
- * @return array|string
841
- */
842
- public function sanitize_md_sorting_fields( $value ) {
843
- $filter_fields = array_merge( UM()->member_directory()->sort_fields, array( 'other' => __( 'Other (Custom Field)', 'ultimate-member' ) ) );
844
- $filter_fields = array_keys( $filter_fields );
845
-
846
- if ( '' !== $value ) {
847
- $value = array_filter(
848
- $value,
849
- function( $v, $k ) use ( $filter_fields ) {
850
- if ( 'other_data' === $k ) {
851
- return true;
852
- } else {
853
- return in_array( sanitize_text_field( $v ), $filter_fields, true );
854
- }
855
- },
856
- ARRAY_FILTER_USE_BOTH
857
- );
858
-
859
- $value = array_map(
860
- function( $item ) {
861
- if ( is_array( $item ) ) {
862
- if ( isset( $item['meta_key'] ) ) {
863
- $item['meta_key'] = sanitize_text_field( $item['meta_key'] );
864
- }
865
- if ( isset( $item['label'] ) ) {
866
- $item['label'] = sanitize_text_field( $item['label'] );
867
- }
868
-
869
- return $item;
870
- } else {
871
- return sanitize_text_field( $item );
872
- }
873
- },
874
- $value
875
- );
876
- }
877
-
878
- return $value;
879
- }
880
-
881
-
882
- /**
883
- * @param array|string $value
884
- *
885
- * @return array|string
886
- */
887
- public function sanitize_filter_fields( $value ) {
888
- $filter_fields = array_keys( UM()->member_directory()->filter_fields );
889
-
890
- if ( '' !== $value ) {
891
- $value = array_filter(
892
- $value,
893
- function( $v, $k ) use ( $filter_fields ) {
894
- return in_array( sanitize_text_field( $v ), $filter_fields, true );
895
- },
896
- ARRAY_FILTER_USE_BOTH
897
- );
898
-
899
- $value = array_map( 'sanitize_text_field', $value );
900
- }
901
-
902
- return $value;
903
- }
904
-
905
-
906
- /**
907
- * @param array|string $value
908
- *
909
- * @return array|string
910
- */
911
- public function sanitize_user_field( $value ) {
912
- $user_fields = array_keys( UM()->builtin()->all_user_fields() );
913
-
914
- if ( '' !== $value ) {
915
- $value = array_filter(
916
- $value,
917
- function( $v, $k ) use ( $user_fields ) {
918
- return in_array( sanitize_text_field( $v ), $user_fields, true );
919
- },
920
- ARRAY_FILTER_USE_BOTH
921
- );
922
-
923
- $value = array_map( 'sanitize_text_field', $value );
924
- }
925
-
926
- return $value;
927
- }
928
-
929
-
930
- /**
931
- * @param array|string $value
932
- *
933
- * @return array|string
934
- */
935
- public function sanitize_md_view_types( $value ) {
936
- $view_types = array_map(
937
- function ( $item ) {
938
- return $item['title'];
939
- },
940
- UM()->member_directory()->view_types
941
- );
942
- $view_types = array_keys( $view_types );
943
-
944
- if ( '' !== $value ) {
945
- $value = array_filter(
946
- $value,
947
- function( $v, $k ) use ( $view_types ) {
948
- return in_array( sanitize_key( $k ), $view_types, true ) && 1 === (int) $v;
949
- },
950
- ARRAY_FILTER_USE_BOTH
951
- );
952
-
953
- $value = array_map( 'sanitize_key', $value );
954
- }
955
-
956
- return $value;
957
- }
958
-
959
-
960
- /**
961
- * @param array|string $value
962
- *
963
- * @return array|string
964
- */
965
- public function sanitize_photosize( $value ) {
966
- $sizes = UM()->files()->get_profile_photo_size( 'photo_thumb_sizes' );
967
- $sizes = array_keys( $sizes );
968
-
969
- if ( '' !== $value ) {
970
- $value = in_array( absint( $value ), $sizes, true ) ? absint( $value ) : '';
971
- }
972
-
973
- return $value;
974
- }
975
-
976
-
977
- /**
978
- * @param array|string $value
979
- *
980
- * @return array|string
981
- */
982
- public function sanitize_cover_photosize( $value ) {
983
- $sizes = UM()->files()->get_profile_photo_size( 'cover_thumb_sizes' );
984
- $sizes = array_keys( $sizes );
985
-
986
- if ( '' !== $value ) {
987
- $value = in_array( absint( $value ), $sizes, true ) ? absint( $value ) : '';
988
- }
989
-
990
- return $value;
991
- }
992
-
993
-
994
- /**
995
- * @param array|string $value
996
- *
997
- * @return array|string
998
- */
999
- public function sanitize_restriction_existed_role( $value ) {
1000
- $all_roles = array_keys( UM()->roles()->get_roles() );
1001
-
1002
- if ( '' !== $value ) {
1003
- $value = array_filter(
1004
- $value,
1005
- function( $v, $k ) use ( $all_roles ) {
1006
- return in_array( sanitize_key( $k ), $all_roles, true ) && 1 === (int) $v;
1007
- },
1008
- ARRAY_FILTER_USE_BOTH
1009
- );
1010
-
1011
- $value = array_map( 'sanitize_key', $value );
1012
- }
1013
-
1014
- return $value;
1015
- }
1016
-
1017
-
1018
- /**
1019
- * @param array|string $value
1020
- *
1021
- * @return array|string
1022
- */
1023
- public function sanitize_existed_role( $value ) {
1024
- $all_roles = array_keys( UM()->roles()->get_roles() );
1025
-
1026
- if ( '' !== $value ) {
1027
- $value = array_filter(
1028
- $value,
1029
- function( $v, $k ) use ( $all_roles ) {
1030
- return in_array( sanitize_key( $v ), $all_roles, true );
1031
- },
1032
- ARRAY_FILTER_USE_BOTH
1033
- );
1034
-
1035
- $value = array_map( 'sanitize_key', $value );
1036
- }
1037
-
1038
- return $value;
1039
- }
1040
-
1041
-
1042
- /**
1043
- * @param array|string $value
1044
- *
1045
- * @return array|string
1046
- */
1047
- public function sanitize_tabs_privacy( $value ) {
1048
- $all_privacy = array_keys( UM()->profile()->tabs_privacy() );
1049
-
1050
- if ( '' !== $value ) {
1051
- $value = in_array( absint( $value ), $all_privacy, true ) ? absint( $value ) : '';
1052
- }
1053
-
1054
- return $value;
1055
- }
1056
-
1057
-
1058
- /**
1059
- * @param $value
1060
- *
1061
- * @return bool|string
1062
- */
1063
- public function sanitize_profile_noindex( $value ) {
1064
- $value = '' !== $value ? (bool) $value : $value;
1065
- return $value;
1066
- }
1067
-
1068
-
1069
- /**
1070
- * @param $value
1071
- *
1072
- * @return array
1073
- */
1074
- public function sanitize_wp_capabilities( $value ) {
1075
- $value = array_map( 'boolval', array_filter( $value ) );
1076
- return $value;
1077
- }
1078
-
1079
-
1080
- /**
1081
- * Sanitize role meta fields when wp-admin form has been submitted
1082
- *
1083
- * @param array $data
1084
- *
1085
- * @return array
1086
- */
1087
- public function sanitize_role_meta( $data ) {
1088
- $sanitized = array();
1089
- foreach ( $data as $k => $v ) {
1090
- if ( ! array_key_exists( $k, $this->role_meta ) ) {
1091
- // @todo remove since 2.2.x and leave only continue
1092
- $sanitized[ $k ] = $v;
1093
- continue;
1094
- }
1095
-
1096
- if ( ! array_key_exists( 'sanitize', $this->role_meta[ $k ] ) ) {
1097
- // @todo remove since 2.2.x and leave only continue
1098
- $sanitized[ $k ] = $v;
1099
- continue;
1100
- }
1101
-
1102
- if ( is_callable( $this->role_meta[ $k ]['sanitize'], true, $callable_name ) ) {
1103
- add_filter( 'um_role_meta_sanitize_' . $k, $this->role_meta[ $k ]['sanitize'], 10, 1 );
1104
- }
1105
-
1106
- switch ( $this->role_meta[ $k ]['sanitize'] ) {
1107
- default:
1108
- $sanitized[ $k ] = apply_filters( 'um_role_meta_sanitize_' . $k, $data[ $k ] );
1109
- break;
1110
- case 'int':
1111
- $sanitized[ $k ] = (int) $v;
1112
- break;
1113
- case 'bool':
1114
- $sanitized[ $k ] = (bool) $v;
1115
- break;
1116
- case 'url':
1117
- $sanitized[ $k ] = esc_url_raw( $v );
1118
- break;
1119
- case 'textarea':
1120
- $sanitized[ $k ] = sanitize_textarea_field( $v );
1121
- break;
1122
- case 'sanitize_array_key':
1123
- if ( ! array_key_exists( 'default', $this->role_meta[ $k ] ) || ! array_key_exists( 'array', $this->role_meta[ $k ] ) ) {
1124
- continue 2;
1125
- }
1126
-
1127
- $sanitized[ $k ] = ! in_array( sanitize_key( $v ), $this->role_meta[ $k ]['array'], true ) ? $this->role_meta[ $k ]['default'] : sanitize_key( $v );
1128
- break;
1129
- }
1130
- }
1131
-
1132
- $data = $sanitized;
1133
-
1134
- $data = apply_filters( 'um_save_role_meta_sanitize', $data );
1135
-
1136
- return $data;
1137
- }
1138
-
1139
-
1140
- /**
1141
- * Sanitize post restriction meta fields when wp-admin form has been submitted
1142
- *
1143
- * @param array $data
1144
- *
1145
- * @return array
1146
- */
1147
- public function sanitize_post_restriction_meta( $data ) {
1148
- $sanitized = array();
1149
- foreach ( $data as $k => $v ) {
1150
- if ( ! array_key_exists( $k, $this->restriction_post_meta ) ) {
1151
- // @todo remove since 2.2.x and leave only continue
1152
- $sanitized[ $k ] = $v;
1153
- continue;
1154
- }
1155
-
1156
- if ( ! array_key_exists( 'sanitize', $this->restriction_post_meta[ $k ] ) ) {
1157
- // @todo remove since 2.2.x and leave only continue
1158
- $sanitized[ $k ] = $v;
1159
- continue;
1160
- }
1161
-
1162
- if ( is_callable( $this->restriction_post_meta[ $k ]['sanitize'], true, $callable_name ) ) {
1163
- add_filter( 'um_restriction_post_meta_sanitize_' . $k, $this->restriction_post_meta[ $k ]['sanitize'], 10, 1 );
1164
- }
1165
-
1166
- switch ( $this->restriction_post_meta[ $k ]['sanitize'] ) {
1167
- default:
1168
- $sanitized[ $k ] = apply_filters( 'um_restriction_post_meta_sanitize_' . $k, $data[ $k ] );
1169
- break;
1170
- case 'int':
1171
- $sanitized[ $k ] = (int) $v;
1172
- break;
1173
- case 'bool':
1174
- $sanitized[ $k ] = (bool) $v;
1175
- break;
1176
- case 'url':
1177
- $sanitized[ $k ] = esc_url_raw( $v );
1178
- break;
1179
- case 'textarea':
1180
- $sanitized[ $k ] = sanitize_textarea_field( $v );
1181
- break;
1182
- case 'wp_kses':
1183
- $sanitized[ $k ] = wp_kses_post( $v );
1184
- break;
1185
- }
1186
- }
1187
-
1188
- $data = $sanitized;
1189
-
1190
- $data = apply_filters( 'um_save_restriction_post_meta_sanitize', $data );
1191
-
1192
- return $data;
1193
- }
1194
-
1195
-
1196
- /**
1197
- * Sanitize term restriction meta fields when wp-admin form has been submitted
1198
- *
1199
- * @param array $data
1200
- *
1201
- * @return array
1202
- */
1203
- public function sanitize_term_restriction_meta( $data ) {
1204
- $sanitized = array();
1205
- foreach ( $data as $k => $v ) {
1206
- if ( ! array_key_exists( $k, $this->restriction_term_meta ) ) {
1207
- // @todo remove since 2.2.x and leave only continue
1208
- $sanitized[ $k ] = $v;
1209
- continue;
1210
- }
1211
-
1212
- if ( ! array_key_exists( 'sanitize', $this->restriction_term_meta[ $k ] ) ) {
1213
- // @todo remove since 2.2.x and leave only continue
1214
- $sanitized[ $k ] = $v;
1215
- continue;
1216
- }
1217
-
1218
- if ( is_callable( $this->restriction_term_meta[ $k ]['sanitize'], true, $callable_name ) ) {
1219
- add_filter( 'um_restriction_term_meta_sanitize_' . $k, $this->restriction_term_meta[ $k ]['sanitize'], 10, 1 );
1220
- }
1221
-
1222
- switch ( $this->restriction_term_meta[ $k ]['sanitize'] ) {
1223
- default:
1224
- $sanitized[ $k ] = apply_filters( 'um_restriction_term_meta_sanitize_' . $k, $data[ $k ] );
1225
- break;
1226
- case 'int':
1227
- $sanitized[ $k ] = (int) $v;
1228
- break;
1229
- case 'bool':
1230
- $sanitized[ $k ] = (bool) $v;
1231
- break;
1232
- case 'url':
1233
- $sanitized[ $k ] = esc_url_raw( $v );
1234
- break;
1235
- case 'textarea':
1236
- $sanitized[ $k ] = sanitize_textarea_field( $v );
1237
- break;
1238
- case 'wp_kses':
1239
- $sanitized[ $k ] = wp_kses_post( $v );
1240
- break;
1241
- }
1242
- }
1243
-
1244
- $data = $sanitized;
1245
-
1246
- $data = apply_filters( 'um_save_restriction_term_meta_sanitize', $data );
1247
-
1248
- return $data;
1249
- }
1250
-
1251
-
1252
- /**
1253
- * Sanitize member directory meta when wp-admin form has been submitted
1254
- *
1255
- * @todo checking all sanitize types
1256
- *
1257
- * @param array $data
1258
- *
1259
- * @return array
1260
- */
1261
- public function sanitize_member_directory_meta( $data ) {
1262
- $sanitized = array();
1263
- foreach ( $data as $k => $v ) {
1264
- if ( ! array_key_exists( $k, $this->member_directory_meta ) ) {
1265
- // @todo remove since 2.2.x and leave only continue
1266
- $sanitized[ $k ] = $v;
1267
- continue;
1268
- }
1269
-
1270
- if ( ! array_key_exists( 'sanitize', $this->member_directory_meta[ $k ] ) ) {
1271
- // @todo remove since 2.2.x and leave only continue
1272
- $sanitized[ $k ] = $v;
1273
- continue;
1274
- }
1275
-
1276
- if ( is_callable( $this->member_directory_meta[ $k ]['sanitize'], true, $callable_name ) ) {
1277
- add_filter( 'um_member_directory_meta_sanitize_' . $k, $this->member_directory_meta[ $k ]['sanitize'], 10, 1 );
1278
- }
1279
-
1280
- switch ( $this->member_directory_meta[ $k ]['sanitize'] ) {
1281
- default:
1282
- $sanitized[ $k ] = apply_filters( 'um_member_directory_meta_sanitize_' . $k, $data[ $k ] );
1283
- break;
1284
- case 'int':
1285
- $sanitized[ $k ] = (int) $v;
1286
- break;
1287
- case 'bool':
1288
- $sanitized[ $k ] = (bool) $v;
1289
- break;
1290
- case 'url':
1291
- if ( is_array( $v ) ) {
1292
- $sanitized[ $k ] = array_map( 'esc_url_raw', $v );
1293
- } else {
1294
- $sanitized[ $k ] = esc_url_raw( $v );
1295
- }
1296
- break;
1297
- case 'text':
1298
- $sanitized[ $k ] = sanitize_text_field( $v );
1299
- break;
1300
- case 'textarea':
1301
- $sanitized[ $k ] = sanitize_textarea_field( $v );
1302
- break;
1303
- case 'key':
1304
- if ( is_array( $v ) ) {
1305
- $sanitized[ $k ] = array_map( 'sanitize_key', $v );
1306
- } else {
1307
- $sanitized[ $k ] = sanitize_key( $v );
1308
- }
1309
- break;
1310
- case 'absint':
1311
- if ( is_array( $v ) ) {
1312
- $sanitized[ $k ] = array_map( 'absint', $v );
1313
- } else {
1314
- $sanitized[ $k ] = absint( $v );
1315
- }
1316
- break;
1317
- }
1318
- }
1319
-
1320
- $data = $sanitized;
1321
-
1322
- $data = apply_filters( 'um_save_member_directory_meta_sanitize', $data );
1323
-
1324
- return $data;
1325
- }
1326
-
1327
-
1328
- /**
1329
- * Sanitize builder field meta when wp-admin form has been submitted
1330
- *
1331
- * @todo checking all sanitize types
1332
- *
1333
- * @param array $data
1334
- *
1335
- * @return array
1336
- */
1337
- public function sanitize_builder_field_meta( $data ) {
1338
- $sanitized = array();
1339
- foreach ( $data as $k => $v ) {
1340
- if ( ! array_key_exists( $k, $this->builder_input ) ) {
1341
- // @todo remove since 2.2.x and leave only continue
1342
- $sanitized[ $k ] = $v;
1343
- continue;
1344
- }
1345
-
1346
- if ( ! array_key_exists( 'sanitize', $this->builder_input[ $k ] ) ) {
1347
- // @todo remove since 2.2.x and leave only continue
1348
- $sanitized[ $k ] = $v;
1349
- continue;
1350
- }
1351
-
1352
- if ( is_callable( $this->builder_input[ $k ]['sanitize'], true, $callable_name ) ) {
1353
- add_filter( 'um_builder_input_sanitize_' . $k, $this->builder_input[ $k ]['sanitize'], 10, 1 );
1354
- }
1355
-
1356
- switch ( $this->builder_input[ $k ]['sanitize'] ) {
1357
- default:
1358
- $sanitized[ $k ] = apply_filters( 'um_builder_input_sanitize_' . $k, $data[ $k ] );
1359
- break;
1360
- case 'int':
1361
- $sanitized[ $k ] = (int) $v;
1362
- break;
1363
- case 'empty_int':
1364
- $sanitized[ $k ] = ( '' !== $v ) ? (int) $v : '';
1365
- break;
1366
- case 'bool':
1367
- $sanitized[ $k ] = (bool) $v;
1368
- break;
1369
- case 'url':
1370
- if ( is_array( $v ) ) {
1371
- $sanitized[ $k ] = array_map( 'esc_url_raw', $v );
1372
- } else {
1373
- $sanitized[ $k ] = esc_url_raw( $v );
1374
- }
1375
- break;
1376
- case 'text':
1377
- $sanitized[ $k ] = sanitize_text_field( $v );
1378
- break;
1379
- case 'textarea':
1380
- $sanitized[ $k ] = sanitize_textarea_field( $v );
1381
- break;
1382
- case 'wp_kses':
1383
- $sanitized[ $k ] = wp_kses_post( $v );
1384
- break;
1385
- case 'key':
1386
- if ( is_array( $v ) ) {
1387
- $sanitized[ $k ] = array_map( 'sanitize_key', $v );
1388
- } else {
1389
- $sanitized[ $k ] = sanitize_key( $v );
1390
- }
1391
- break;
1392
- case 'absint':
1393
- if ( is_array( $v ) ) {
1394
- $sanitized[ $k ] = array_map( 'absint', $v );
1395
- } else {
1396
- $sanitized[ $k ] = absint( $v );
1397
- }
1398
- break;
1399
- case 'empty_absint':
1400
- if ( is_array( $v ) ) {
1401
- $sanitized[ $k ] = array_map( 'absint', $v );
1402
- } else {
1403
- $sanitized[ $k ] = ( '' !== $v ) ? absint( $v ) : '';
1404
- }
1405
- break;
1406
- }
1407
- }
1408
-
1409
- $data = $sanitized;
1410
-
1411
- $data = apply_filters( 'um_save_builder_input_sanitize', $data );
1412
-
1413
- return $data;
1414
- }
1415
-
1416
-
1417
- /**
1418
- * Sanitize form meta when wp-admin form has been submitted
1419
- *
1420
- * @todo checking all sanitize types
1421
- *
1422
- * @param array $data
1423
- *
1424
- * @return array
1425
- */
1426
- public function sanitize_form_meta( $data ) {
1427
- $sanitized = array();
1428
- foreach ( $data as $k => $v ) {
1429
- if ( ! array_key_exists( $k, $this->form_meta ) ) {
1430
- // @todo remove since 2.2.x and leave only continue
1431
- $sanitized[ $k ] = $v;
1432
- continue;
1433
- }
1434
-
1435
- if ( ! array_key_exists( 'sanitize', $this->form_meta[ $k ] ) ) {
1436
- // @todo remove since 2.2.x and leave only continue
1437
- $sanitized[ $k ] = $v;
1438
- continue;
1439
- }
1440
-
1441
- if ( is_callable( $this->form_meta[ $k ]['sanitize'], true, $callable_name ) ) {
1442
- add_filter( 'um_form_meta_sanitize_' . $k, $this->form_meta[ $k ]['sanitize'], 10, 1 );
1443
- }
1444
-
1445
- switch ( $this->form_meta[ $k ]['sanitize'] ) {
1446
- default:
1447
- $sanitized[ $k ] = apply_filters( 'um_form_meta_sanitize_' . $k, $data[ $k ] );
1448
- break;
1449
- case 'int':
1450
- $sanitized[ $k ] = (int) $v;
1451
- break;
1452
- case 'bool':
1453
- $sanitized[ $k ] = (bool) $v;
1454
- break;
1455
- case 'url':
1456
- if ( is_array( $v ) ) {
1457
- $sanitized[ $k ] = array_map( 'esc_url_raw', $v );
1458
- } else {
1459
- $sanitized[ $k ] = esc_url_raw( $v );
1460
- }
1461
- break;
1462
- case 'text':
1463
- $sanitized[ $k ] = sanitize_text_field( $v );
1464
- break;
1465
- case 'textarea':
1466
- $sanitized[ $k ] = sanitize_textarea_field( $v );
1467
- break;
1468
- case 'key':
1469
- if ( is_array( $v ) ) {
1470
- $sanitized[ $k ] = array_map( 'sanitize_key', $v );
1471
- } else {
1472
- $sanitized[ $k ] = sanitize_key( $v );
1473
- }
1474
- break;
1475
- case 'absint':
1476
- if ( is_array( $v ) ) {
1477
- $sanitized[ $k ] = array_map( 'absint', $v );
1478
- } else {
1479
- $sanitized[ $k ] = absint( $v );
1480
- }
1481
- break;
1482
- }
1483
- }
1484
-
1485
- $data = $sanitized;
1486
-
1487
- $data = apply_filters( 'um_save_form_meta_sanitize', $data );
1488
-
1489
- return $data;
1490
- }
1491
-
1492
-
1493
- /**
1494
- * Sanitize options when wp-admin form has been submitted
1495
- *
1496
- * @todo checking all sanitize types
1497
- *
1498
- * @param array $data
1499
- *
1500
- * @return array
1501
- */
1502
- public function sanitize_options( $data ) {
1503
- $sanitized = array();
1504
- foreach ( $data as $k => $v ) {
1505
- if ( ! array_key_exists( $k, UM()->admin_settings()->settings_map ) ) {
1506
- // @todo remove since 2.2.x and leave only continue
1507
- $sanitized[ $k ] = $v;
1508
- continue;
1509
- }
1510
-
1511
- if ( ! array_key_exists( 'sanitize', UM()->admin_settings()->settings_map[ $k ] ) ) {
1512
- // @todo remove since 2.2.x and leave only continue
1513
- $sanitized[ $k ] = $v;
1514
- continue;
1515
- }
1516
-
1517
- if ( is_callable( UM()->admin_settings()->settings_map[ $k ]['sanitize'], true, $callable_name ) ) {
1518
- add_filter( 'um_settings_sanitize_' . $k, UM()->admin_settings()->settings_map[ $k ]['sanitize'], 10, 1 );
1519
- }
1520
-
1521
- switch ( UM()->admin_settings()->settings_map[ $k ]['sanitize'] ) {
1522
- default:
1523
- $sanitized[ $k ] = apply_filters( 'um_settings_sanitize_' . $k, $v );
1524
- break;
1525
- case 'int':
1526
- $sanitized[ $k ] = (int) $v;
1527
- break;
1528
- case 'absint':
1529
- if ( is_array( $v ) ) {
1530
- $sanitized[ $k ] = array_map( 'absint', $v );
1531
- } else {
1532
- $sanitized[ $k ] = absint( $v );
1533
- }
1534
- break;
1535
- case 'key':
1536
- if ( is_array( $v ) ) {
1537
- $sanitized[ $k ] = array_map( 'sanitize_key', $v );
1538
- } else {
1539
- $sanitized[ $k ] = sanitize_key( $v );
1540
- }
1541
- break;
1542
- case 'bool':
1543
- $sanitized[ $k ] = (bool) $v;
1544
- break;
1545
- case 'url':
1546
- if ( is_array( $v ) ) {
1547
- $sanitized[ $k ] = array_map( 'esc_url_raw', $v );
1548
- } else {
1549
- $sanitized[ $k ] = esc_url_raw( $v );
1550
- }
1551
- break;
1552
- case 'wp_kses':
1553
- $sanitized[ $k ] = wp_kses_post( $v );
1554
- break;
1555
- case 'textarea':
1556
- $sanitized[ $k ] = sanitize_textarea_field( $v );
1557
- break;
1558
- case 'text':
1559
- $sanitized[ $k ] = sanitize_text_field( $v );
1560
- break;
1561
- }
1562
- }
1563
-
1564
- $data = $sanitized;
1565
-
1566
- $data = apply_filters( 'um_save_settings_sanitize', $data );
1567
-
1568
- return $data;
1569
- }
1570
-
1571
-
1572
- /**
1573
- * Adds class to our admin pages
1574
- *
1575
- * @param $classes
1576
- *
1577
- * @return string
1578
- */
1579
- public function admin_body_class( $classes ) {
1580
- if ( $this->is_um_screen() ) {
1581
- return "$classes um-admin";
1582
- }
1583
- return $classes;
1584
- }
1585
-
1586
-
1587
- /**
1588
- *
1589
- */
1590
- public function manual_upgrades_request() {
1591
- if ( ! is_admin() || ! current_user_can( 'manage_options' ) ) {
1592
- die();
1593
- }
1594
-
1595
- $last_request = get_option( 'um_last_manual_upgrades_request', false );
1596
-
1597
- if ( empty( $last_request ) || time() > $last_request + DAY_IN_SECONDS ) {
1598
-
1599
- if ( is_multisite() ) {
1600
- $blogs_ids = get_sites();
1601
- foreach( $blogs_ids as $b ) {
1602
- switch_to_blog( $b->blog_id );
1603
- wp_clean_update_cache();
1604
-
1605
- UM()->plugin_updater()->um_checklicenses();
1606
-
1607
- update_option( 'um_last_manual_upgrades_request', time() );
1608
- restore_current_blog();
1609
- }
1610
- } else {
1611
- wp_clean_update_cache();
1612
-
1613
- UM()->plugin_updater()->um_checklicenses();
1614
-
1615
- update_option( 'um_last_manual_upgrades_request', time() );
1616
- }
1617
-
1618
- $url = add_query_arg( array( 'page' => 'ultimatemember', 'update' => 'got_updates' ), admin_url( 'admin.php' ) );
1619
- } else {
1620
- $url = add_query_arg( array( 'page' => 'ultimatemember', 'update' => 'often_updates' ), admin_url( 'admin.php' ) );
1621
- }
1622
- exit( wp_redirect( $url ) );
1623
- }
1624
-
1625
-
1626
- /**
1627
- * Core pages installation
1628
- */
1629
- function install_core_pages() {
1630
- if ( ! is_admin() ) {
1631
- die();
1632
- }
1633
-
1634
- UM()->setup()->install_default_pages();
1635
-
1636
- //check empty pages in settings
1637
- $empty_pages = array();
1638
-
1639
- $pages = UM()->config()->permalinks;
1640
- if ( $pages && is_array( $pages ) ) {
1641
- foreach ( $pages as $slug => $page_id ) {
1642
- $page = get_post( $page_id );
1643
-
1644
- if ( ! isset( $page->ID ) && in_array( $slug, array_keys( UM()->config()->core_pages ) ) ) {
1645
- $empty_pages[] = $slug;
1646
- }
1647
- }
1648
- }
1649
-
1650
- //if there aren't empty pages - then hide pages notice
1651
- if ( empty( $empty_pages ) ) {
1652
- $hidden_notices = get_option( 'um_hidden_admin_notices', array() );
1653
- $hidden_notices[] = 'wrong_pages';
1654
-
1655
- update_option( 'um_hidden_admin_notices', $hidden_notices );
1656
- }
1657
-
1658
- $url = add_query_arg( array( 'page' => 'um_options' ), admin_url( 'admin.php' ) );
1659
- exit( wp_redirect( $url ) );
1660
- }
1661
-
1662
-
1663
- /**
1664
- * Clear all users cache
1665
- *
1666
- * @param $action
1667
- */
1668
- function user_cache( $action ) {
1669
- global $wpdb;
1670
- if ( ! is_admin() || ! current_user_can( 'manage_options' ) ) {
1671
- die();
1672
- }
1673
-
1674
- $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE 'um_cache_userdata_%'" );
1675
-
1676
- $url = add_query_arg( array( 'page' => 'ultimatemember', 'update' => 'cleared_cache' ), admin_url( 'admin.php' ) );
1677
- exit( wp_redirect( $url ) );
1678
- }
1679
-
1680
-
1681
- /**
1682
- * Purge temp uploads dir
1683
- * @param $action
1684
- */
1685
- function purge_temp( $action ) {
1686
- if ( ! is_admin() || ! current_user_can( 'manage_options' ) ) {
1687
- die();
1688
- }
1689
-
1690
- UM()->files()->remove_dir( UM()->files()->upload_temp );
1691
-
1692
- $url = add_query_arg( array( 'page' => 'ultimatemember', 'update' => 'purged_temp' ), admin_url( 'admin.php' ) );
1693
- exit( wp_redirect( $url ) );
1694
- }
1695
-
1696
-
1697
- /**
1698
- * Duplicate form
1699
- *
1700
- * @param $action
1701
- */
1702
- function duplicate_form( $action ) {
1703
- if ( ! is_admin() || ! current_user_can('manage_options') ) {
1704
- die();
1705
- }
1706
- if ( ! isset( $_REQUEST['post_id'] ) || ! is_numeric( $_REQUEST['post_id'] ) ) {
1707
- die();
1708
- }
1709
-
1710
- $post_id = absint( $_REQUEST['post_id'] );
1711
-
1712
- $n = array(
1713
- 'post_type' => 'um_form',
1714
- 'post_title' => sprintf( __( 'Duplicate of %s', 'ultimate-member' ), get_the_title( $post_id ) ),
1715
- 'post_status' => 'publish',
1716
- 'post_author' => get_current_user_id(),
1717
- );
1718
-
1719
- $n_id = wp_insert_post( $n );
1720
-
1721
- $n_fields = get_post_custom( $post_id );
1722
- foreach ( $n_fields as $key => $value ) {
1723
-
1724
- if ( $key == '_um_custom_fields' ) {
1725
- $the_value = unserialize( $value[0] );
1726
- } else {
1727
- $the_value = $value[0];
1728
- }
1729
-
1730
- update_post_meta( $n_id, $key, $the_value );
1731
-
1732
- }
1733
-
1734
- delete_post_meta( $n_id, '_um_core' );
1735
-
1736
- $url = admin_url( 'edit.php?post_type=um_form' );
1737
- $url = add_query_arg( 'update', 'form_duplicated', $url );
1738
-
1739
- exit( wp_redirect( $url ) );
1740
-
1741
- }
1742
-
1743
-
1744
- /**
1745
- * Action to hide notices in admin
1746
- *
1747
- * @param $action
1748
- */
1749
- function um_hide_notice( $action ) {
1750
- if ( ! is_admin() || ! current_user_can( 'manage_options' ) ) {
1751
- die();
1752
- }
1753
-
1754
- update_option( $action, 1 );
1755
- exit( wp_redirect( remove_query_arg( 'um_adm_action' ) ) );
1756
- }
1757
-
1758
-
1759
- /**
1760
- * Various user actions
1761
- *
1762
- * @param $action
1763
- */
1764
- function user_action( $action ) {
1765
- if ( ! is_admin() || ! current_user_can( 'edit_users' ) ) {
1766
- die();
1767
- }
1768
- if ( ! isset( $_REQUEST['sub'] ) ) {
1769
- die();
1770
- }
1771
- if ( ! isset( $_REQUEST['user_id'] ) ) {
1772
- die();
1773
- }
1774
-
1775
- um_fetch_user( absint( $_REQUEST['user_id'] ) );
1776
-
1777
- $subaction = sanitize_key( $_REQUEST['sub'] );
1778
-
1779
- /**
1780
- * UM hook
1781
- *
1782
- * @type action
1783
- * @title um_admin_user_action_hook
1784
- * @description Action on bulk user subaction
1785
- * @input_vars
1786
- * [{"var":"$subaction","type":"string","desc":"Bulk Subaction"}]
1787
- * @change_log
1788
- * ["Since: 2.0"]
1789
- * @usage add_action( 'um_admin_user_action_hook', 'function_name', 10, 1 );
1790
- * @example
1791
- * <?php
1792
- * add_action( 'um_admin_user_action_hook', 'my_admin_user_action', 10, 1 );
1793
- * function my_admin_user_action( $subaction ) {
1794
- * // your code here
1795
- * }
1796
- * ?>
1797
- */
1798
- do_action( 'um_admin_user_action_hook', $subaction );
1799
- /**
1800
- * UM hook
1801
- *
1802
- * @type action
1803
- * @title um_admin_user_action_{$subaction}_hook
1804
- * @description Action on bulk user subaction
1805
- * @change_log
1806
- * ["Since: 2.0"]
1807
- * @usage add_action( 'um_admin_user_action_{$subaction}_hook', 'function_name', 10 );
1808
- * @example
1809
- * <?php
1810
- * add_action( 'um_admin_user_action_{$subaction}_hook', 'my_admin_user_action', 10 );
1811
- * function my_admin_user_action() {
1812
- * // your code here
1813
- * }
1814
- * ?>
1815
- */
1816
- do_action( "um_admin_user_action_{$subaction}_hook" );
1817
-
1818
- um_reset_user();
1819
-
1820
- wp_redirect( add_query_arg( 'update', 'user_updated', admin_url( '?page=ultimatemember' ) ) );
1821
- exit;
1822
-
1823
- }
1824
-
1825
-
1826
- /**
1827
- * Add any custom links to plugin page
1828
- *
1829
- * @param array $links
1830
- *
1831
- * @return array
1832
- */
1833
- function plugin_links( $links ) {
1834
- $more_links[] = '<a href="http://docs.ultimatemember.com/">' . __( 'Docs', 'ultimate-member' ) . '</a>';
1835
- $more_links[] = '<a href="'.admin_url().'admin.php?page=um_options">' . __( 'Settings', 'ultimate-member' ) . '</a>';
1836
-
1837
- $links = $more_links + $links;
1838
- return $links;
1839
- }
1840
-
1841
-
1842
- /**
1843
- * Init admin action/filters + request handlers
1844
- */
1845
- function admin_init() {
1846
- $this->init_variables();
1847
-
1848
- if ( is_admin() && current_user_can( 'manage_options' ) && ! empty( $_REQUEST['um_adm_action'] ) ) {
1849
- $action = sanitize_key( $_REQUEST['um_adm_action'] );
1850
-
1851
- /**
1852
- * UM hook
1853
- *
1854
- * @type action
1855
- * @title um_admin_do_action__
1856
- * @description Make some action on custom admin action
1857
- * @input_vars
1858
- * [{"var":"$action","type":"string","desc":"Admin Action"}]
1859
- * @change_log
1860
- * ["Since: 2.0"]
1861
- * @usage add_action( 'um_admin_do_action__', 'function_name', 10, 1 );
1862
- * @example
1863
- * <?php
1864
- * add_action( 'um_admin_do_action__', 'my_admin_do_action', 10, 1 );
1865
- * function my_admin_do_action( $action ) {
1866
- * // your code here
1867
- * }
1868
- * ?>
1869
- */
1870
- do_action( 'um_admin_do_action__', $action );
1871
- /**
1872
- * UM hook
1873
- *
1874
- * @type action
1875
- * @title um_admin_do_action__{$action}
1876
- * @description Make some action on custom admin $action
1877
- * @input_vars
1878
- * [{"var":"$action","type":"string","desc":"Admin Action"}]
1879
- * @change_log
1880
- * ["Since: 2.0"]
1881
- * @usage add_action( 'um_admin_do_action__{$action}', 'function_name', 10, 1 );
1882
- * @example
1883
- * <?php
1884
- * add_action( 'um_admin_do_action__{$action}', 'my_admin_do_action', 10, 1 );
1885
- * function my_admin_do_action( $action ) {
1886
- * // your code here
1887
- * }
1888
- * ?>
1889
- */
1890
- do_action( "um_admin_do_action__{$action}", $action );
1891
- }
1892
- }
1893
-
1894
-
1895
- /**
1896
- * Updated post messages
1897
- *
1898
- * @param array $messages
1899
- *
1900
- * @return array
1901
- */
1902
- function post_updated_messages( $messages ) {
1903
- global $post_ID;
1904
-
1905
- $post_type = get_post_type( $post_ID );
1906
-
1907
- if ( $post_type == 'um_form' ) {
1908
- $messages['um_form'] = array(
1909
- 0 => '',
1910
- 1 => __( 'Form updated.', 'ultimate-member' ),
1911
- 2 => __( 'Custom field updated.', 'ultimate-member' ),
1912
- 3 => __( 'Custom field deleted.', 'ultimate-member' ),
1913
- 4 => __( 'Form updated.', 'ultimate-member' ),
1914
- 5 => isset( $_GET['revision'] ) ? __( 'Form restored to revision.', 'ultimate-member' ) : false,
1915
- 6 => __( 'Form created.', 'ultimate-member' ),
1916
- 7 => __( 'Form saved.', 'ultimate-member' ),
1917
- 8 => __( 'Form submitted.', 'ultimate-member' ),
1918
- 9 => __( 'Form scheduled.', 'ultimate-member' ),
1919
- 10 => __( 'Form draft updated.', 'ultimate-member' ),
1920
- );
1921
- }
1922
-
1923
- return $messages;
1924
- }
1925
-
1926
-
1927
- /**
1928
- * Gettext filters
1929
- *
1930
- * @param $translation
1931
- * @param $text
1932
- * @param $domain
1933
- *
1934
- * @return string
1935
- */
1936
- function gettext( $translation, $text, $domain ) {
1937
- global $post;
1938
- if ( isset( $post->post_type ) && $this->is_plugin_post_type() ) {
1939
- $translations = get_translations_for_domain( $domain );
1940
- if ( $text == 'Publish' ) {
1941
- return $translations->translate( 'Create' );
1942
- } elseif ( $text == 'Move to Trash' ) {
1943
- return $translations->translate( 'Delete' );
1944
- }
1945
- }
1946
-
1947
- return $translation;
1948
- }
1949
-
1950
-
1951
- /**
1952
- * Fix parent file for correct highlighting
1953
- *
1954
- * @param $parent_file
1955
- *
1956
- * @return string
1957
- */
1958
- function parent_file( $parent_file ) {
1959
- global $current_screen;
1960
- $screen_id = $current_screen->id;
1961
- if ( strstr( $screen_id, 'um_' ) ) {
1962
- $parent_file = 'ultimatemember';
1963
- }
1964
- return $parent_file;
1965
- }
1966
-
1967
-
1968
- /**
1969
- * @since 2.0
1970
- *
1971
- * @return core\Admin_Notices()
1972
- */
1973
- function notices() {
1974
- if ( empty( UM()->classes['admin_notices'] ) ) {
1975
- UM()->classes['admin_notices'] = new core\Admin_Notices();
1976
- }
1977
- return UM()->classes['admin_notices'];
1978
- }
1979
- }
1980
- }
1
+ <?php
2
+ namespace um\admin;
3
+
4
+ // Exit if accessed directly.
5
+ if ( ! defined( 'ABSPATH' ) ) {
6
+ exit;
7
+ }
8
+
9
+ if ( ! class_exists( 'um\admin\Admin' ) ) {
10
+
11
+
12
+ /**
13
+ * Class Admin
14
+ * @package um\admin
15
+ */
16
+ class Admin extends Admin_Functions {
17
+
18
+
19
+ /**
20
+ * @var string
21
+ */
22
+ public $templates_path;
23
+
24
+
25
+ /**
26
+ * @var array
27
+ */
28
+ public $role_meta;
29
+
30
+
31
+ /**
32
+ * @var array
33
+ */
34
+ public $restriction_term_meta;
35
+
36
+
37
+ /**
38
+ * @var array
39
+ */
40
+ public $member_directory_meta;
41
+
42
+
43
+ /**
44
+ * @var array
45
+ */
46
+ public $form_meta;
47
+
48
+
49
+ /**
50
+ * @var array
51
+ */
52
+ public $builder_input;
53
+
54
+
55
+ /**
56
+ * @var array
57
+ */
58
+ public $restriction_post_meta;
59
+
60
+
61
+ /**
62
+ * Admin constructor.
63
+ */
64
+ public function __construct() {
65
+ parent::__construct();
66
+
67
+ $this->templates_path = um_path . 'includes/admin/templates/';
68
+
69
+ add_action( 'admin_init', array( &$this, 'admin_init' ), 0 );
70
+
71
+ $prefix = is_network_admin() ? 'network_admin_' : '';
72
+ add_filter( "{$prefix}plugin_action_links_" . um_plugin, array( &$this, 'plugin_links' ) );
73
+
74
+ add_action( 'um_admin_do_action__user_cache', array( &$this, 'user_cache' ) );
75
+ add_action( 'um_admin_do_action__purge_temp', array( &$this, 'purge_temp' ) );
76
+ add_action( 'um_admin_do_action__manual_upgrades_request', array( &$this, 'manual_upgrades_request' ) );
77
+ add_action( 'um_admin_do_action__duplicate_form', array( &$this, 'duplicate_form' ) );
78
+ add_action( 'um_admin_do_action__um_hide_locale_notice', array( &$this, 'um_hide_notice' ) );
79
+ add_action( 'um_admin_do_action__um_can_register_notice', array( &$this, 'um_hide_notice' ) );
80
+ add_action( 'um_admin_do_action__um_hide_exif_notice', array( &$this, 'um_hide_notice' ) );
81
+ add_action( 'um_admin_do_action__user_action', array( &$this, 'user_action' ) );
82
+
83
+ add_action( 'um_admin_do_action__install_core_pages', array( &$this, 'install_core_pages' ) );
84
+
85
+ add_filter( 'admin_body_class', array( &$this, 'admin_body_class' ), 999 );
86
+
87
+ add_action( 'parent_file', array( &$this, 'parent_file' ), 9 );
88
+ add_filter( 'gettext', array( &$this, 'gettext' ), 10, 4 );
89
+ add_filter( 'post_updated_messages', array( &$this, 'post_updated_messages' ) );
90
+ }
91
+
92
+
93
+ function init_variables() {
94
+ $this->role_meta = apply_filters(
95
+ 'um_role_meta_map',
96
+ array(
97
+ '_um_priority' => array(
98
+ 'sanitize' => 'int',
99
+ ),
100
+ '_um_can_access_wpadmin' => array(
101
+ 'sanitize' => 'bool',
102
+ ),
103
+ '_um_can_not_see_adminbar' => array(
104
+ 'sanitize' => 'bool',
105
+ ),
106
+ '_um_can_edit_everyone' => array(
107
+ 'sanitize' => 'bool',
108
+ ),
109
+ '_um_can_edit_roles' => array(
110
+ 'sanitize' => array( $this, 'sanitize_existed_role' ),
111
+ ),
112
+ '_um_can_delete_everyone' => array(
113
+ 'sanitize' => 'bool',
114
+ ),
115
+ '_um_can_delete_roles' => array(
116
+ 'sanitize' => array( $this, 'sanitize_existed_role' ),
117
+ ),
118
+ '_um_can_edit_profile' => array(
119
+ 'sanitize' => 'bool',
120
+ ),
121
+ '_um_can_delete_profile' => array(
122
+ 'sanitize' => 'bool',
123
+ ),
124
+ '_um_can_view_all' => array(
125
+ 'sanitize' => 'bool',
126
+ ),
127
+ '_um_can_view_roles' => array(
128
+ 'sanitize' => array( $this, 'sanitize_existed_role' ),
129
+ ),
130
+ '_um_can_make_private_profile' => array(
131
+ 'sanitize' => 'bool',
132
+ ),
133
+ '_um_can_access_private_profile' => array(
134
+ 'sanitize' => 'bool',
135
+ ),
136
+ '_um_profile_noindex' => array(
137
+ 'sanitize' => array( $this, 'sanitize_profile_noindex' ),
138
+ ),
139
+ '_um_default_homepage' => array(
140
+ 'sanitize' => 'bool',
141
+ ),
142
+ '_um_redirect_homepage' => array(
143
+ 'sanitize' => 'url',
144
+ ),
145
+ '_um_status' => array(
146
+ 'sanitize' => 'sanitize_array_key',
147
+ 'default' => 'approved',
148
+ 'array' => array( 'approved', 'checkmail', 'pending' ),
149
+ ),
150
+ '_um_auto_approve_act' => array(
151
+ 'sanitize' => 'sanitize_array_key',
152
+ 'default' => 'redirect_profile',
153
+ 'array' => array( 'redirect_profile', 'redirect_url' ),
154
+ ),
155
+ '_um_auto_approve_url' => array(
156
+ 'sanitize' => 'url',
157
+ ),
158
+ '_um_login_email_activate' => array(
159
+ 'sanitize' => 'bool',
160
+ ),
161
+ '_um_checkmail_action' => array(
162
+ 'sanitize' => 'sanitize_array_key',
163
+ 'default' => 'show_message',
164
+ 'array' => array( 'show_message', 'redirect_url' ),
165
+ ),
166
+ '_um_checkmail_message' => array(
167
+ 'sanitize' => 'textarea',
168
+ ),
169
+ '_um_checkmail_url' => array(
170
+ 'sanitize' => 'url',
171
+ ),
172
+ '_um_url_email_activate' => array(
173
+ 'sanitize' => 'url',
174
+ ),
175
+ '_um_pending_action' => array(
176
+ 'sanitize' => 'sanitize_array_key',
177
+ 'default' => 'show_message',
178
+ 'array' => array( 'show_message', 'redirect_url' ),
179
+ ),
180
+ '_um_pending_message' => array(
181
+ 'sanitize' => 'textarea',
182
+ ),
183
+ '_um_pending_url' => array(
184
+ 'sanitize' => 'url',
185
+ ),
186
+ '_um_after_login' => array(
187
+ 'sanitize' => 'sanitize_array_key',
188
+ 'default' => 'redirect_profile',
189
+ 'array' => array( 'redirect_profile', 'redirect_url', 'refresh', 'redirect_admin' ),
190
+ ),
191
+ '_um_login_redirect_url' => array(
192
+ 'sanitize' => 'url',
193
+ ),
194
+ '_um_after_logout' => array(
195
+ 'sanitize' => 'sanitize_array_key',
196
+ 'default' => 'redirect_home',
197
+ 'array' => array( 'redirect_home', 'redirect_url' ),
198
+ ),
199
+ '_um_logout_redirect_url' => array(
200
+ 'sanitize' => 'url',
201
+ ),
202
+ '_um_after_delete' => array(
203
+ 'sanitize' => 'sanitize_array_key',
204
+ 'default' => 'redirect_home',
205
+ 'array' => array( 'redirect_home', 'redirect_url' ),
206
+ ),
207
+ '_um_delete_redirect_url' => array(
208
+ 'sanitize' => 'url',
209
+ ),
210
+ 'wp_capabilities' => array(
211
+ 'sanitize' => array( $this, 'sanitize_wp_capabilities' ),
212
+ ),
213
+ )
214
+ );
215
+
216
+ $this->restriction_post_meta = apply_filters(
217
+ 'um_restriction_post_meta_map',
218
+ array(
219
+ '_um_custom_access_settings' => array(
220
+ 'sanitize' => 'bool',
221
+ ),
222
+ '_um_accessible' => array(
223
+ 'sanitize' => 'int',
224
+ ),
225
+ '_um_access_roles' => array(
226
+ 'sanitize' => array( $this, 'sanitize_restriction_existed_role' ),
227
+ ),
228
+ '_um_noaccess_action' => array(
229
+ 'sanitize' => 'int',
230
+ ),
231
+ '_um_restrict_by_custom_message' => array(
232
+ 'sanitize' => 'int',
233
+ ),
234
+ '_um_restrict_custom_message' => array(
235
+ 'sanitize' => 'wp_kses',
236
+ ),
237
+ '_um_access_redirect' => array(
238
+ 'sanitize' => 'int',
239
+ ),
240
+ '_um_access_redirect_url' => array(
241
+ 'sanitize' => 'url',
242
+ ),
243
+ '_um_access_hide_from_queries' => array(
244
+ 'sanitize' => 'bool',
245
+ ),
246
+ )
247
+ );
248
+
249
+ $this->restriction_term_meta = apply_filters(
250
+ 'um_restriction_term_meta_map',
251
+ array(
252
+ '_um_custom_access_settings' => array(
253
+ 'sanitize' => 'bool',
254
+ ),
255
+ '_um_accessible' => array(
256
+ 'sanitize' => 'int',
257
+ ),
258
+ '_um_access_roles' => array(
259
+ 'sanitize' => array( $this, 'sanitize_restriction_existed_role' ),
260
+ ),
261
+ '_um_noaccess_action' => array(
262
+ 'sanitize' => 'int',
263
+ ),
264
+ '_um_restrict_by_custom_message' => array(
265
+ 'sanitize' => 'int',
266
+ ),
267
+ '_um_restrict_custom_message' => array(
268
+ 'sanitize' => 'wp_kses',
269
+ ),
270
+ '_um_access_redirect' => array(
271
+ 'sanitize' => 'int',
272
+ ),
273
+ '_um_access_redirect_url' => array(
274
+ 'sanitize' => 'url',
275
+ ),
276
+ '_um_access_hide_from_queries' => array(
277
+ 'sanitize' => 'bool',
278
+ ),
279
+ )
280
+ );
281
+
282
+ $this->member_directory_meta = apply_filters(
283
+ 'um_member_directory_meta_map',
284
+ array(
285
+ '_um_directory_template' => array(
286
+ 'sanitize' => 'text',
287
+ ),
288
+ '_um_mode' => array(
289
+ 'sanitize' => 'key',
290
+ ),
291
+ '_um_view_types' => array(
292
+ 'sanitize' => array( $this, 'sanitize_md_view_types' ),
293
+ ),
294
+ '_um_default_view' => array(
295
+ 'sanitize' => 'key',
296
+ ),
297
+ '_um_roles' => array(
298
+ 'sanitize' => array( $this, 'sanitize_restriction_existed_role' ),
299
+ ),
300
+ '_um_has_profile_photo' => array(
301
+ 'sanitize' => 'bool',
302
+ ),
303
+ '_um_show_these_users' => array(
304
+ 'sanitize' => 'textarea',
305
+ ),
306
+ '_um_exclude_these_users' => array(
307
+ 'sanitize' => 'textarea',
308
+ ),
309
+ '_um_must_search' => array(
310
+ 'sanitize' => 'bool',
311
+ ),
312
+ '_um_max_users' => array(
313
+ 'sanitize' => 'absint',
314
+ ),
315
+ '_um_profiles_per_page' => array(
316
+ 'sanitize' => 'absint',
317
+ ),
318
+ '_um_profiles_per_page_mobile' => array(
319
+ 'sanitize' => 'absint',
320
+ ),
321
+ '_um_directory_header' => array(
322
+ 'sanitize' => 'text',
323
+ ),
324
+ '_um_directory_header_single' => array(
325
+ 'sanitize' => 'text',
326
+ ),
327
+ '_um_directory_no_users' => array(
328
+ 'sanitize' => 'text',
329
+ ),
330
+ '_um_profile_photo' => array(
331
+ 'sanitize' => 'bool',
332
+ ),
333
+ '_um_cover_photos' => array(
334
+ 'sanitize' => 'bool',
335
+ ),
336
+ '_um_show_name' => array(
337
+ 'sanitize' => 'bool',
338
+ ),
339
+ '_um_show_tagline' => array(
340
+ 'sanitize' => 'bool',
341
+ ),
342
+ '_um_tagline_fields' => array(
343
+ 'sanitize' => array( $this, 'sanitize_user_field' ),
344
+ ),
345
+ '_um_show_userinfo' => array(
346
+ 'sanitize' => 'bool',
347
+ ),
348
+ '_um_reveal_fields' => array(
349
+ 'sanitize' => array( $this, 'sanitize_user_field' ),
350
+ ),
351
+ '_um_show_social' => array(
352
+ 'sanitize' => 'bool',
353
+ ),
354
+ '_um_userinfo_animate' => array(
355
+ 'sanitize' => 'bool',
356
+ ),
357
+ '_um_search' => array(
358
+ 'sanitize' => 'bool',
359
+ ),
360
+ '_um_roles_can_search' => array(
361
+ 'sanitize' => array( $this, 'sanitize_restriction_existed_role' ),
362
+ ),
363
+ '_um_filters' => array(
364
+ 'sanitize' => 'bool',
365
+ ),
366
+ '_um_roles_can_filter' => array(
367
+ 'sanitize' => array( $this, 'sanitize_restriction_existed_role' ),
368
+ ),
369
+ '_um_search_fields' => array(
370
+ 'sanitize' => array( $this, 'sanitize_filter_fields' ),
371
+ ),
372
+ '_um_filters_expanded' => array(
373
+ 'sanitize' => 'bool',
374
+ ),
375
+ '_um_filters_is_collapsible' => array(
376
+ 'sanitize' => 'bool',
377
+ ),
378
+ '_um_search_filters' => array(
379
+ 'sanitize' => array( $this, 'sanitize_filter_fields' ),
380
+ ),
381
+ '_um_sortby' => array(
382
+ 'sanitize' => 'text',
383
+ ),
384
+ '_um_sortby_custom' => array(
385
+ 'sanitize' => 'text',
386
+ ),
387
+ '_um_sortby_custom_label' => array(
388
+ 'sanitize' => 'text',
389
+ ),
390
+ '_um_enable_sorting' => array(
391
+ 'sanitize' => 'bool',
392
+ ),
393
+ '_um_sorting_fields' => array(
394
+ 'sanitize' => array( $this, 'sanitize_md_sorting_fields' ),
395
+ ),
396
+ )
397
+ );
398
+
399
+ $this->form_meta = apply_filters(
400
+ 'um_form_meta_map',
401
+ array(
402
+ '_um_mode' => array(
403
+ 'sanitize' => 'key',
404
+ ),
405
+ '_um_register_use_gdpr' => array(
406
+ 'sanitize' => 'bool',
407
+ ),
408
+ '_um_register_use_gdpr_content_id' => array(
409
+ 'sanitize' => 'absint',
410
+ ),
411
+ '_um_register_use_gdpr_toggle_show' => array(
412
+ 'sanitize' => 'text',
413
+ ),
414
+ '_um_register_use_gdpr_toggle_hide' => array(
415
+ 'sanitize' => 'text',
416
+ ),
417
+ '_um_register_use_gdpr_agreement' => array(
418
+ 'sanitize' => 'text',
419
+ ),
420
+ '_um_register_use_gdpr_error_text' => array(
421
+ 'sanitize' => 'text',
422
+ ),
423
+ '_um_register_use_custom_settings' => array(
424
+ 'sanitize' => 'bool',
425
+ ),
426
+ '_um_register_role' => array(
427
+ 'sanitize' => 'key',
428
+ ),
429
+ '_um_register_template' => array(
430
+ 'sanitize' => 'text',
431
+ ),
432
+ '_um_register_max_width' => array(
433
+ 'sanitize' => 'text',
434
+ ),
435
+ '_um_register_icons' => array(
436
+ 'sanitize' => 'key',
437
+ ),
438
+ '_um_register_primary_btn_word' => array(
439
+ 'sanitize' => 'text',
440
+ ),
441
+ '_um_register_secondary_btn' => array(
442
+ 'sanitize' => 'bool',
443
+ ),
444
+ '_um_register_secondary_btn_word' => array(
445
+ 'sanitize' => 'text',
446
+ ),
447
+ '_um_login_after_login' => array(
448
+ 'sanitize' => 'key',
449
+ ),
450
+ '_um_login_redirect_url' => array(
451
+ 'sanitize' => 'url',
452
+ ),
453
+ '_um_login_use_custom_settings' => array(
454
+ 'sanitize' => 'bool',
455
+ ),
456
+ '_um_login_template' => array(
457
+ 'sanitize' => 'text',
458
+ ),
459
+ '_um_login_max_width' => array(
460
+ 'sanitize' => 'text',
461
+ ),
462
+ '_um_login_icons' => array(
463
+ 'sanitize' => 'key',
464
+ ),
465
+ '_um_login_primary_btn_word' => array(
466
+ 'sanitize' => 'text',
467
+ ),
468
+ '_um_login_secondary_btn' => array(
469
+ 'sanitize' => 'bool',
470
+ ),
471
+ '_um_login_secondary_btn_word' => array(
472
+ 'sanitize' => 'text',
473
+ ),
474
+ '_um_login_forgot_pass_link' => array(
475
+ 'sanitize' => 'bool',
476
+ ),
477
+ '_um_login_show_rememberme' => array(
478
+ 'sanitize' => 'bool',
479
+ ),
480
+ '_um_profile_metafields' => array(
481
+ 'sanitize' => array( $this, 'sanitize_user_field' ),
482
+ ),
483
+ '_um_profile_use_custom_settings' => array(
484
+ 'sanitize' => 'bool',
485
+ ),
486
+ '_um_profile_role' => array(
487
+ 'sanitize' => array( $this, 'sanitize_existed_role' ),
488
+ ),
489
+ '_um_profile_template' => array(
490
+ 'sanitize' => 'text',
491
+ ),
492
+ '_um_profile_max_width' => array(
493
+ 'sanitize' => 'text',
494
+ ),
495
+ '_um_profile_area_max_width' => array(
496
+ 'sanitize' => 'text',
497
+ ),
498
+ '_um_profile_icons' => array(
499
+ 'sanitize' => 'key',
500
+ ),
501
+ '_um_profile_primary_btn_word' => array(
502
+ 'sanitize' => 'text',
503
+ ),
504
+ '_um_profile_secondary_btn' => array(
505
+ 'sanitize' => 'bool',
506
+ ),
507
+ '_um_profile_secondary_btn_word' => array(
508
+ 'sanitize' => 'text',
509
+ ),
510
+ '_um_profile_cover_enabled' => array(
511
+ 'sanitize' => 'bool',
512
+ ),
513
+ '_um_profile_coversize' => array(
514
+ 'sanitize' => 'absint',
515
+ ),
516
+ '_um_profile_cover_ratio' => array(
517
+ 'sanitize' => 'text',
518
+ ),
519
+ '_um_profile_disable_photo_upload' => array(
520
+ 'sanitize' => 'bool',
521
+ ),
522
+ '_um_profile_photosize' => array(
523
+ 'sanitize' => array( $this, 'sanitize_photosize' ),
524
+ ),
525
+ '_um_profile_photo_required' => array(
526
+ 'sanitize' => 'bool',
527
+ ),
528
+ '_um_profile_show_name' => array(
529
+ 'sanitize' => 'bool',
530
+ ),
531
+ '_um_profile_show_social_links' => array(
532
+ 'sanitize' => 'bool',
533
+ ),
534
+ '_um_profile_show_bio' => array(
535
+ 'sanitize' => 'bool',
536
+ ),
537
+
538
+ )
539
+ );
540
+
541
+ $this->builder_input = apply_filters(
542
+ 'um_builder_input_map',
543
+ array(
544
+ '_in_row' => array(
545
+ 'sanitize' => 'key',
546
+ ),
547
+ '_in_sub_row' => array(
548
+ 'sanitize' => 'absint',
549
+ ),
550
+ '_in_column' => array(
551
+ 'sanitize' => 'absint',
552
+ ),
553
+ '_in_group' => array(
554
+ 'sanitize' => 'absint',
555
+ ),
556
+ '_visibility' => array(
557
+ 'sanitize' => 'key',
558
+ ),
559
+ '_conditional_action' => array(
560
+ 'sanitize' => 'key',
561
+ ),
562
+ '_conditional_action1' => array(
563
+ 'sanitize' => 'key',
564
+ ),
565
+ '_conditional_action2' => array(
566
+ 'sanitize' => 'key',
567
+ ),
568
+ '_conditional_action3' => array(
569
+ 'sanitize' => 'key',
570
+ ),
571
+ '_conditional_action4' => array(
572
+ 'sanitize' => 'key',
573
+ ),
574
+ '_conditional_field' => array(
575
+ 'sanitize' => 'text',
576
+ ),
577
+ '_conditional_field1' => array(
578
+ 'sanitize' => 'text',
579
+ ),
580
+ '_conditional_field2' => array(
581
+ 'sanitize' => 'text',
582
+ ),
583
+ '_conditional_field3' => array(
584
+ 'sanitize' => 'text',
585
+ ),
586
+ '_conditional_field4' => array(
587
+ 'sanitize' => 'text',
588
+ ),
589
+ '_conditional_operator' => array(
590
+ 'sanitize' => 'text',
591
+ ),
592
+ '_conditional_operator1' => array(
593
+ 'sanitize' => 'text',
594
+ ),
595
+ '_conditional_operator2' => array(
596
+ 'sanitize' => 'text',
597
+ ),
598
+ '_conditional_operator3' => array(
599
+ 'sanitize' => 'text',
600
+ ),
601
+ '_conditional_operator4' => array(
602
+ 'sanitize' => 'text',
603
+ ),
604
+ '_conditional_value' => array(
605
+ 'sanitize' => 'text',
606
+ ),
607
+ '_conditional_value1' => array(
608
+ 'sanitize' => 'text',
609
+ ),
610
+ '_conditional_value2' => array(
611
+ 'sanitize' => 'text',
612
+ ),
613
+ '_conditional_value3' => array(
614
+ 'sanitize' => 'text',
615
+ ),
616
+ '_conditional_value4' => array(
617
+ 'sanitize' => 'text',
618
+ ),
619
+ '_validate' => array(
620
+ 'sanitize' => 'key',
621
+ ),
622
+ '_custom_validate' => array(
623
+ 'sanitize' => 'text',
624
+ ),
625
+ '_icon' => array(
626
+ 'sanitize' => 'key',
627
+ ),
628
+ '_css_class' => array(
629
+ 'sanitize' => 'text',
630
+ ),
631
+ '_width' => array(
632
+ 'sanitize' => 'absint',
633
+ ),
634
+ '_divider_text' => array(
635
+ 'sanitize' => 'text',
636
+ ),
637
+ '_padding' => array(
638
+ 'sanitize' => 'text',
639
+ ),
640
+ '_margin' => array(
641
+ 'sanitize' => 'text',
642
+ ),
643
+ '_border' => array(
644
+ 'sanitize' => 'text',
645
+ ),
646
+ '_borderstyle' => array(
647
+ 'sanitize' => 'key',
648
+ ),
649
+ '_borderradius' => array(
650
+ 'sanitize' => 'text',
651
+ ),
652
+ '_bordercolor' => array(
653
+ 'sanitize' => 'text',
654
+ ),
655
+ '_heading' => array(
656
+ 'sanitize' => 'bool',
657
+ ),
658
+ '_heading_text' => array(
659
+ 'sanitize' => 'text',
660
+ ),
661
+ '_background' => array(
662
+ 'sanitize' => 'text',
663
+ ),
664
+ '_heading_background_color' => array(
665
+ 'sanitize' => 'text',
666
+ ),
667
+ '_heading_text_color' => array(
668
+ 'sanitize' => 'text',
669
+ ),
670
+ '_text_color' => array(
671
+ 'sanitize' => 'text',
672
+ ),
673
+ '_icon_color' => array(
674
+ 'sanitize' => 'text',
675
+ ),
676
+ '_color' => array(
677
+ 'sanitize' => 'text',
678
+ ),
679
+ '_url_text' => array(
680
+ 'sanitize' => 'text',
681
+ ),
682
+ '_url_target' => array(
683
+ 'sanitize' => 'key',
684
+ ),
685
+ '_url_rel' => array(
686
+ 'sanitize' => 'key',
687
+ ),
688
+ '_force_good_pass' => array(
689
+ 'sanitize' => 'bool',
690
+ ),
691
+ '_force_confirm_pass' => array(
692
+ 'sanitize' => 'bool',
693
+ ),
694
+ '_style' => array(
695
+ 'sanitize' => 'key',
696
+ ),
697
+ '_intervals' => array(
698
+ 'sanitize' => 'absint',
699
+ ),
700
+ '_format' => array(
701
+ 'sanitize' => 'text',
702
+ ),
703
+ '_format_custom' => array(
704
+ 'sanitize' => 'text',
705
+ ),
706
+ '_pretty_format' => array(
707
+ 'sanitize' => 'bool',
708
+ ),
709
+ '_disabled_weekdays' => array(
710
+ 'sanitize' => 'absint',
711
+ ),
712
+ '_years' => array(
713
+ 'sanitize' => 'absint',
714
+ ),
715
+ '_years_x' => array(
716
+ 'sanitize' => 'key',
717
+ ),
718
+ '_range_start' => array(
719
+ 'sanitize' => 'text',
720
+ ),
721
+ '_range_end' => array(
722
+ 'sanitize' => 'text',
723
+ ),
724
+ '_range' => array(
725
+ 'sanitize' => 'key',
726
+ ),
727
+ '_content' => array(
728
+ 'sanitize' => 'textarea',
729
+ ),
730
+ '_crop' => array(
731
+ 'sanitize' => 'int',
732
+ ),
733
+ '_allowed_types' => array(
734
+ 'sanitize' => 'key',
735
+ ),
736
+ '_upload_text' => array(
737
+ 'sanitize' => 'text',
738
+ ),
739
+ '_upload_help_text' => array(
740
+ 'sanitize' => 'text',
741
+ ),
742
+ '_button_text' => array(
743
+ 'sanitize' => 'text',
744
+ ),
745
+ '_max_size' => array(
746
+ 'sanitize' => 'absint',
747
+ ),
748
+ '_height' => array(
749
+ 'sanitize' => 'text',
750
+ ),
751
+ '_spacing' => array(
752
+ 'sanitize' => 'text',
753
+ ),
754
+ '_is_multi' => array(
755
+ 'sanitize' => 'bool',
756
+ ),
757
+ '_max_selections' => array(
758
+ 'sanitize' => 'absint',
759
+ ),
760
+ '_min_selections' => array(
761
+ 'sanitize' => 'absint',
762
+ ),
763
+ '_max_entries' => array(
764
+ 'sanitize' => 'absint',
765
+ ),
766
+ '_max_words' => array(
767
+ 'sanitize' => 'absint',
768
+ ),
769
+ '_min' => array(
770
+ 'sanitize' => 'empty_int',
771
+ ),
772
+ '_max' => array(
773
+ 'sanitize' => 'empty_int',
774
+ ),
775
+ '_min_chars' => array(
776
+ 'sanitize' => 'absint',
777
+ ),
778
+ '_max_chars' => array(
779
+ 'sanitize' => 'absint',
780
+ ),
781
+ '_html' => array(
782
+ 'sanitize' => 'bool',
783
+ ),
784
+ '_options' => array(
785
+ 'sanitize' => 'textarea',
786
+ ),
787
+ '_title' => array(
788
+ 'sanitize' => 'text',
789
+ ),
790
+ '_id' => array(
791
+ 'sanitize' => 'text',
792
+ ),
793
+ '_metakey' => array(
794
+ 'sanitize' => 'text',
795
+ ),
796
+ '_help' => array(
797
+ 'sanitize' => 'text',
798
+ ),
799
+ '_default' => array(
800
+ 'sanitize' => 'text',
801
+ ),
802
+ '_label' => array(
803
+ 'sanitize' => 'text',
804
+ ),
805
+ '_label_confirm_pass' => array(
806
+ 'sanitize' => 'text',
807
+ ),
808
+ '_placeholder' => array(
809
+ 'sanitize' => 'text',
810
+ ),
811
+ '_public' => array(
812
+ 'sanitize' => 'text',
813
+ ),
814
+ '_roles' => array(
815
+ 'sanitize' => array( $this, 'sanitize_existed_role' ),
816
+ ),
817
+ '_required' => array(
818
+ 'sanitize' => 'bool',
819
+ ),
820
+ '_editable' => array(
821
+ 'sanitize' => 'bool',
822
+ ),
823
+ '_number' => array(
824
+ 'sanitize' => 'absint',
825
+ ),
826
+ '_custom_dropdown_options_source' => array(
827
+ 'sanitize' => 'text',
828
+ ),
829
+ '_parent_dropdown_relationship' => array(
830
+ 'sanitize' => 'text',
831
+ ),
832
+ )
833
+ );
834
+ }
835
+
836
+
837
+ /**
838
+ * @param array|string $value
839
+ *
840
+ * @return array|string
841
+ */
842
+ public function sanitize_md_sorting_fields( $value ) {
843
+ $filter_fields = array_merge( UM()->member_directory()->sort_fields, array( 'other' => __( 'Other (Custom Field)', 'ultimate-member' ) ) );
844
+ $filter_fields = array_keys( $filter_fields );
845
+
846
+ if ( '' !== $value ) {
847
+ $value = array_filter(
848
+ $value,
849
+ function( $v, $k ) use ( $filter_fields ) {
850
+ if ( 'other_data' === $k ) {
851
+ return true;
852
+ } else {
853
+ return in_array( sanitize_text_field( $v ), $filter_fields, true );
854
+ }
855
+ },
856
+ ARRAY_FILTER_USE_BOTH
857
+ );
858
+
859
+ $value = array_map(
860
+ function( $item ) {
861
+ if ( is_array( $item ) ) {
862
+ if ( isset( $item['meta_key'] ) ) {
863
+ $item['meta_key'] = sanitize_text_field( $item['meta_key'] );
864
+ }
865
+ if ( isset( $item['label'] ) ) {
866
+ $item['label'] = sanitize_text_field( $item['label'] );
867
+ }
868
+
869
+ return $item;
870
+ } else {
871
+ return sanitize_text_field( $item );
872
+ }
873
+ },
874
+ $value
875
+ );
876
+ }
877
+
878
+ return $value;
879
+ }
880
+
881
+
882
+ /**
883
+ * @param array|string $value
884
+ *
885
+ * @return array|string
886
+ */
887
+ public function sanitize_filter_fields( $value ) {
888
+ $filter_fields = array_keys( UM()->member_directory()->filter_fields );
889
+
890
+ if ( '' !== $value ) {
891
+ $value = array_filter(
892
+ $value,
893
+ function( $v, $k ) use ( $filter_fields ) {
894
+ return in_array( sanitize_text_field( $v ), $filter_fields, true );
895
+ },
896
+ ARRAY_FILTER_USE_BOTH
897
+ );
898
+
899
+ $value = array_map( 'sanitize_text_field', $value );
900
+ }
901
+
902
+ return $value;
903
+ }
904
+
905
+
906
+ /**
907
+ * @param array|string $value
908
+ *
909
+ * @return array|string
910
+ */
911
+ public function sanitize_user_field( $value ) {
912
+ $user_fields = array_keys( UM()->builtin()->all_user_fields() );
913
+
914
+ if ( '' !== $value ) {
915
+ $value = array_filter(
916
+ $value,
917
+ function( $v, $k ) use ( $user_fields ) {
918
+ return in_array( sanitize_text_field( $v ), $user_fields, true );
919
+ },
920
+ ARRAY_FILTER_USE_BOTH
921
+ );
922
+
923
+ $value = array_map( 'sanitize_text_field', $value );
924
+ }
925
+
926
+ return $value;
927
+ }
928
+
929
+
930
+ /**
931
+ * @param array|string $value
932
+ *
933
+ * @return array|string
934
+ */
935
+ public function sanitize_md_view_types( $value ) {
936
+ $view_types = array_map(
937
+ function ( $item ) {
938
+ return $item['title'];
939
+ },
940
+ UM()->member_directory()->view_types
941
+ );
942
+ $view_types = array_keys( $view_types );
943
+
944
+ if ( '' !== $value ) {
945
+ $value = array_filter(
946
+ $value,
947
+ function( $v, $k ) use ( $view_types ) {
948
+ return in_array( sanitize_key( $k ), $view_types, true ) && 1 === (int) $v;
949
+ },
950
+ ARRAY_FILTER_USE_BOTH
951
+ );
952
+
953
+ $value = array_map( 'sanitize_key', $value );
954
+ }
955
+
956
+ return $value;
957
+ }
958
+
959
+
960
+ /**
961
+ * @param array|string $value
962
+ *
963
+ * @return array|string
964
+ */
965
+ public function sanitize_photosize( $value ) {
966
+ $sizes = UM()->files()->get_profile_photo_size( 'photo_thumb_sizes' );
967
+ $sizes = array_keys( $sizes );
968
+
969
+ if ( '' !== $value ) {
970
+ $value = in_array( absint( $value ), $sizes, true ) ? absint( $value ) : '';
971
+ }
972
+
973
+ return $value;
974
+ }
975
+
976
+
977
+ /**
978
+ * @param array|string $value
979
+ *
980
+ * @return array|string
981
+ */
982
+ public function sanitize_cover_photosize( $value ) {
983
+ $sizes = UM()->files()->get_profile_photo_size( 'cover_thumb_sizes' );
984
+ $sizes = array_keys( $sizes );
985
+
986
+ if ( '' !== $value ) {
987
+ $value = in_array( absint( $value ), $sizes, true ) ? absint( $value ) : '';
988
+ }
989
+
990
+ return $value;
991
+ }
992
+
993
+
994
+ /**
995
+ * @param array|string $value
996
+ *
997
+ * @return array|string
998
+ */
999
+ public function sanitize_restriction_existed_role( $value ) {
1000
+ $all_roles = array_keys( UM()->roles()->get_roles() );
1001
+
1002
+ if ( '' !== $value ) {
1003
+ $value = array_filter(
1004
+ $value,
1005
+ function( $v, $k ) use ( $all_roles ) {
1006
+ return in_array( sanitize_key( $k ), $all_roles, true ) && 1 === (int) $v;
1007
+ },
1008
+ ARRAY_FILTER_USE_BOTH
1009
+ );
1010
+
1011
+ $value = array_map( 'sanitize_key', $value );
1012
+ }
1013
+
1014
+ return $value;
1015
+ }
1016
+
1017
+
1018
+ /**
1019
+ * @param array|string $value
1020
+ *
1021
+ * @return array|string
1022
+ */
1023
+ public function sanitize_existed_role( $value ) {
1024
+ $all_roles = array_keys( UM()->roles()->get_roles() );
1025
+
1026
+ if ( '' !== $value ) {
1027
+ $value = array_filter(
1028
+ $value,
1029
+ function( $v, $k ) use ( $all_roles ) {
1030
+ return in_array( sanitize_key( $v ), $all_roles, true );
1031
+ },
1032
+ ARRAY_FILTER_USE_BOTH
1033
+ );
1034
+
1035
+ $value = array_map( 'sanitize_key', $value );
1036
+ }
1037
+
1038
+ return $value;
1039
+ }
1040
+
1041
+
1042
+ /**
1043
+ * @param array|string $value
1044
+ *
1045
+ * @return array|string
1046
+ */
1047
+ public function sanitize_tabs_privacy( $value ) {
1048
+ $all_privacy = array_keys( UM()->profile()->tabs_privacy() );
1049
+
1050
+ if ( '' !== $value ) {
1051
+ $value = in_array( absint( $value ), $all_privacy, true ) ? absint( $value ) : '';
1052
+ }
1053
+
1054
+ return $value;
1055
+ }
1056
+
1057
+
1058
+ /**
1059
+ * @param $value
1060
+ *
1061
+ * @return bool|string
1062
+ */
1063
+ public function sanitize_profile_noindex( $value ) {
1064
+ $value = '' !== $value ? (bool) $value : $value;
1065
+ return $value;
1066
+ }
1067
+
1068
+
1069
+ /**
1070
+ * @param $value
1071
+ *
1072
+ * @return array
1073
+ */
1074
+ public function sanitize_wp_capabilities( $value ) {
1075
+ $value = array_map( 'boolval', array_filter( $value ) );
1076
+ return $value;
1077
+ }
1078
+
1079
+
1080
+ /**
1081
+ * Sanitize role meta fields when wp-admin form has been submitted
1082
+ *
1083
+ * @param array $data
1084
+ *
1085
+ * @return array
1086
+ */
1087
+ public function sanitize_role_meta( $data ) {
1088
+ $sanitized = array();
1089
+ foreach ( $data as $k => $v ) {
1090
+ if ( ! array_key_exists( $k, $this->role_meta ) ) {
1091
+ // @todo remove since 2.2.x and leave only continue
1092
+ $sanitized[ $k ] = $v;
1093
+ continue;
1094
+ }
1095
+
1096
+ if ( ! array_key_exists( 'sanitize', $this->role_meta[ $k ] ) ) {
1097
+ // @todo remove since 2.2.x and leave only continue
1098
+ $sanitized[ $k ] = $v;
1099
+ continue;
1100
+ }
1101
+
1102
+ if ( is_callable( $this->role_meta[ $k ]['sanitize'], true, $callable_name ) ) {
1103
+ add_filter( 'um_role_meta_sanitize_' . $k, $this->role_meta[ $k ]['sanitize'], 10, 1 );
1104
+ }
1105
+
1106
+ switch ( $this->role_meta[ $k ]['sanitize'] ) {
1107
+ default:
1108
+ $sanitized[ $k ] = apply_filters( 'um_role_meta_sanitize_' . $k, $data[ $k ] );
1109
+ break;
1110
+ case 'int':
1111
+ $sanitized[ $k ] = (int) $v;
1112
+ break;
1113
+ case 'bool':
1114
+ $sanitized[ $k ] = (bool) $v;
1115
+ break;
1116
+ case 'url':
1117
+ $sanitized[ $k ] = esc_url_raw( $v );
1118
+ break;
1119
+ case 'textarea':
1120
+ $sanitized[ $k ] = sanitize_textarea_field( $v );
1121
+ break;
1122
+ case 'sanitize_array_key':
1123
+ if ( ! array_key_exists( 'default', $this->role_meta[ $k ] ) || ! array_key_exists( 'array', $this->role_meta[ $k ] ) ) {
1124
+ continue 2;
1125
+ }
1126
+
1127
+ $sanitized[ $k ] = ! in_array( sanitize_key( $v ), $this->role_meta[ $k ]['array'], true ) ? $this->role_meta[ $k ]['default'] : sanitize_key( $v );
1128
+ break;
1129
+ }
1130
+ }
1131
+
1132
+ $data = $sanitized;
1133
+
1134
+ $data = apply_filters( 'um_save_role_meta_sanitize', $data );
1135
+
1136
+ return $data;
1137
+ }
1138
+
1139
+
1140
+ /**
1141
+ * Sanitize post restriction meta fields when wp-admin form has been submitted
1142
+ *
1143
+ * @param array $data
1144
+ *
1145
+ * @return array
1146
+ */
1147
+ public function sanitize_post_restriction_meta( $data ) {
1148
+ $sanitized = array();
1149
+ foreach ( $data as $k => $v ) {
1150
+ if ( ! array_key_exists( $k, $this->restriction_post_meta ) ) {
1151
+ // @todo remove since 2.2.x and leave only continue
1152
+ $sanitized[ $k ] = $v;
1153
+ continue;
1154
+ }
1155
+
1156
+ if ( ! array_key_exists( 'sanitize', $this->restriction_post_meta[ $k ] ) ) {
1157
+ // @todo remove since 2.2.x and leave only continue
1158
+ $sanitized[ $k ] = $v;
1159
+ continue;
1160
+ }
1161
+
1162
+ if ( is_callable( $this->restriction_post_meta[ $k ]['sanitize'], true, $callable_name ) ) {
1163
+ add_filter( 'um_restriction_post_meta_sanitize_' . $k, $this->restriction_post_meta[ $k ]['sanitize'], 10, 1 );
1164
+ }
1165
+
1166
+ switch ( $this->restriction_post_meta[ $k ]['sanitize'] ) {
1167
+ default:
1168
+ $sanitized[ $k ] = apply_filters( 'um_restriction_post_meta_sanitize_' . $k, $data[ $k ] );
1169
+ break;
1170
+ case 'int':
1171
+ $sanitized[ $k ] = (int) $v;
1172
+ break;
1173
+ case 'bool':
1174
+ $sanitized[ $k ] = (bool) $v;
1175
+ break;
1176
+ case 'url':
1177
+ $sanitized[ $k ] = esc_url_raw( $v );
1178
+ break;
1179
+ case 'textarea':
1180
+ $sanitized[ $k ] = sanitize_textarea_field( $v );
1181
+ break;
1182
+ case 'wp_kses':
1183
+ $sanitized[ $k ] = wp_kses_post( $v );
1184
+ break;
1185
+ }
1186
+ }
1187
+
1188
+ $data = $sanitized;
1189
+
1190
+ $data = apply_filters( 'um_save_restriction_post_meta_sanitize', $data );
1191
+
1192
+ return $data;
1193
+ }
1194
+
1195
+
1196
+ /**
1197
+ * Sanitize term restriction meta fields when wp-admin form has been submitted
1198
+ *
1199
+ * @param array $data
1200
+ *
1201
+ * @return array
1202
+ */
1203
+ public function sanitize_term_restriction_meta( $data ) {
1204
+ $sanitized = array();
1205
+ foreach ( $data as $k => $v ) {
1206
+ if ( ! array_key_exists( $k, $this->restriction_term_meta ) ) {
1207
+ // @todo remove since 2.2.x and leave only continue
1208
+ $sanitized[ $k ] = $v;
1209
+ continue;
1210
+ }
1211
+
1212
+ if ( ! array_key_exists( 'sanitize', $this->restriction_term_meta[ $k ] ) ) {
1213
+ // @todo remove since 2.2.x and leave only continue
1214
+ $sanitized[ $k ] = $v;
1215
+ continue;
1216
+ }
1217
+
1218
+ if ( is_callable( $this->restriction_term_meta[ $k ]['sanitize'], true, $callable_name ) ) {
1219
+ add_filter( 'um_restriction_term_meta_sanitize_' . $k, $this->restriction_term_meta[ $k ]['sanitize'], 10, 1 );
1220
+ }
1221
+
1222
+ switch ( $this->restriction_term_meta[ $k ]['sanitize'] ) {
1223
+ default:
1224
+ $sanitized[ $k ] = apply_filters( 'um_restriction_term_meta_sanitize_' . $k, $data[ $k ] );
1225
+ break;
1226
+ case 'int':
1227
+ $sanitized[ $k ] = (int) $v;
1228
+ break;
1229
+ case 'bool':
1230
+ $sanitized[ $k ] = (bool) $v;
1231
+ break;
1232
+ case 'url':
1233
+ $sanitized[ $k ] = esc_url_raw( $v );
1234
+ break;
1235
+ case 'textarea':
1236
+ $sanitized[ $k ] = sanitize_textarea_field( $v );
1237
+ break;
1238
+ case 'wp_kses':
1239
+ $sanitized[ $k ] = wp_kses_post( $v );
1240
+ break;
1241
+ }
1242
+ }
1243
+
1244
+ $data = $sanitized;
1245
+
1246
+ $data = apply_filters( 'um_save_restriction_term_meta_sanitize', $data );
1247
+
1248
+ return $data;
1249
+ }
1250
+
1251
+
1252
+ /**
1253
+ * Sanitize member directory meta when wp-admin form has been submitted
1254
+ *
1255
+ * @todo checking all sanitize types
1256
+ *
1257
+ * @param array $data
1258
+ *
1259
+ * @return array
1260
+ */
1261
+ public function sanitize_member_directory_meta( $data ) {
1262
+ $sanitized = array();
1263
+ foreach ( $data as $k => $v ) {
1264
+ if ( ! array_key_exists( $k, $this->member_directory_meta ) ) {
1265
+ // @todo remove since 2.2.x and leave only continue
1266
+ $sanitized[ $k ] = $v;
1267
+ continue;
1268
+ }
1269
+
1270
+ if ( ! array_key_exists( 'sanitize', $this->member_directory_meta[ $k ] ) ) {
1271
+ // @todo remove since 2.2.x and leave only continue
1272
+ $sanitized[ $k ] = $v;
1273
+ continue;
1274
+ }
1275
+
1276
+ if ( is_callable( $this->member_directory_meta[ $k ]['sanitize'], true, $callable_name ) ) {
1277
+ add_filter( 'um_member_directory_meta_sanitize_' . $k, $this->member_directory_meta[ $k ]['sanitize'], 10, 1 );
1278
+ }
1279
+
1280
+ switch ( $this->member_directory_meta[ $k ]['sanitize'] ) {
1281
+ default:
1282
+ $sanitized[ $k ] = apply_filters( 'um_member_directory_meta_sanitize_' . $k, $data[ $k ] );
1283
+ break;
1284
+ case 'int':
1285
+ $sanitized[ $k ] = (int) $v;
1286
+ break;
1287
+ case 'bool':
1288
+ $sanitized[ $k ] = (bool) $v;
1289
+ break;
1290
+ case 'url':
1291
+ if ( is_array( $v ) ) {
1292
+ $sanitized[ $k ] = array_map( 'esc_url_raw', $v );
1293
+ } else {
1294
+ $sanitized[ $k ] = esc_url_raw( $v );
1295
+ }
1296
+ break;
1297
+ case 'text':
1298
+ $sanitized[ $k ] = sanitize_text_field( $v );
1299
+ break;
1300
+ case 'textarea':
1301
+ $sanitized[ $k ] = sanitize_textarea_field( $v );
1302
+ break;
1303
+ case 'key':
1304
+ if ( is_array( $v ) ) {
1305
+ $sanitized[ $k ] = array_map( 'sanitize_key', $v );
1306
+ } else {
1307
+ $sanitized[ $k ] = sanitize_key( $v );
1308
+ }
1309
+ break;
1310
+ case 'absint':
1311
+ if ( is_array( $v ) ) {
1312
+ $sanitized[ $k ] = array_map( 'absint', $v );
1313
+ } else {
1314
+ $sanitized[ $k ] = absint( $v );
1315
+ }
1316
+ break;
1317
+ }
1318
+ }
1319
+
1320
+ $data = $sanitized;
1321
+
1322
+ $data = apply_filters( 'um_save_member_directory_meta_sanitize', $data );
1323
+
1324
+ return $data;
1325
+ }
1326
+
1327
+
1328
+ /**
1329
+ * Sanitize builder field meta when wp-admin form has been submitted
1330
+ *
1331
+ * @todo checking all sanitize types
1332
+ *
1333
+ * @param array $data
1334
+ *
1335
+ * @return array
1336
+ */
1337
+ public function sanitize_builder_field_meta( $data ) {
1338
+ $sanitized = array();
1339
+ foreach ( $data as $k => $v ) {
1340
+ if ( ! array_key_exists( $k, $this->builder_input ) ) {
1341
+ // @todo remove since 2.2.x and leave only continue
1342
+ $sanitized[ $k ] = $v;
1343
+ continue;
1344
+ }
1345
+
1346
+ if ( ! array_key_exists( 'sanitize', $this->builder_input[ $k ] ) ) {
1347
+ // @todo remove since 2.2.x and leave only continue
1348
+ $sanitized[ $k ] = $v;
1349
+ continue;
1350
+ }
1351
+
1352
+ if ( is_callable( $this->builder_input[ $k ]['sanitize'], true, $callable_name ) ) {
1353
+ add_filter( 'um_builder_input_sanitize_' . $k, $this->builder_input[ $k ]['sanitize'], 10, 1 );
1354
+ }
1355
+
1356
+ switch ( $this->builder_input[ $k ]['sanitize'] ) {
1357
+ default:
1358
+ $sanitized[ $k ] = apply_filters( 'um_builder_input_sanitize_' . $k, $data[ $k ] );
1359
+ break;
1360
+ case 'int':
1361
+ $sanitized[ $k ] = (int) $v;
1362
+ break;
1363
+ case 'empty_int':
1364
+ $sanitized[ $k ] = ( '' !== $v ) ? (int) $v : '';
1365
+ break;
1366
+ case 'bool':
1367
+ $sanitized[ $k ] = (bool) $v;
1368
+ break;
1369
+ case 'url':
1370
+ if ( is_array( $v ) ) {
1371
+ $sanitized[ $k ] = array_map( 'esc_url_raw', $v );
1372
+ } else {
1373
+ $sanitized[ $k ] = esc_url_raw( $v );
1374
+ }
1375
+ break;
1376
+ case 'text':
1377
+ $sanitized[ $k ] = sanitize_text_field( $v );
1378
+ break;
1379
+ case 'textarea':
1380
+ $sanitized[ $k ] = sanitize_textarea_field( $v );
1381
+ break;
1382
+ case 'wp_kses':
1383
+ $sanitized[ $k ] = wp_kses_post( $v );
1384
+ break;
1385
+ case 'key':
1386
+ if ( is_array( $v ) ) {
1387
+ $sanitized[ $k ] = array_map( 'sanitize_key', $v );
1388
+ } else {
1389
+ $sanitized[ $k ] = sanitize_key( $v );
1390
+ }
1391
+ break;
1392
+ case 'absint':
1393
+ if ( is_array( $v ) ) {
1394
+ $sanitized[ $k ] = array_map( 'absint', $v );
1395
+ } else {
1396
+ $sanitized[ $k ] = absint( $v );
1397
+ }
1398
+ break;
1399
+ case 'empty_absint':
1400
+ if ( is_array( $v ) ) {
1401
+ $sanitized[ $k ] = array_map( 'absint', $v );
1402
+ } else {
1403
+ $sanitized[ $k ] = ( '' !== $v ) ? absint( $v ) : '';
1404
+ }
1405
+ break;
1406
+ }
1407
+ }
1408
+
1409
+ $data = $sanitized;
1410
+
1411
+ $data = apply_filters( 'um_save_builder_input_sanitize', $data );
1412
+
1413
+ return $data;
1414
+ }
1415
+
1416
+
1417
+ /**
1418
+ * Sanitize form meta when wp-admin form has been submitted
1419
+ *
1420
+ * @todo checking all sanitize types
1421
+ *
1422
+ * @param array $data
1423
+ *
1424
+ * @return array
1425
+ */
1426
+ public function sanitize_form_meta( $data ) {
1427
+ $sanitized = array();
1428
+ foreach ( $data as $k => $v ) {
1429
+ if ( ! array_key_exists( $k, $this->form_meta ) ) {
1430
+ // @todo remove since 2.2.x and leave only continue
1431
+ $sanitized[ $k ] = $v;
1432
+ continue;
1433
+ }
1434
+
1435
+ if ( ! array_key_exists( 'sanitize', $this->form_meta[ $k ] ) ) {
1436
+ // @todo remove since 2.2.x and leave only continue
1437
+ $sanitized[ $k ] = $v;
1438
+ continue;
1439
+ }
1440
+
1441
+ if ( is_callable( $this->form_meta[ $k ]['sanitize'], true, $callable_name ) ) {
1442
+ add_filter( 'um_form_meta_sanitize_' . $k, $this->form_meta[ $k ]['sanitize'], 10, 1 );
1443
+ }
1444
+
1445
+ switch ( $this->form_meta[ $k ]['sanitize'] ) {
1446
+ default:
1447
+ $sanitized[ $k ] = apply_filters( 'um_form_meta_sanitize_' . $k, $data[ $k ] );
1448
+ break;
1449
+ case 'int':
1450
+ $sanitized[ $k ] = (int) $v;
1451
+ break;
1452
+ case 'bool':
1453
+ $sanitized[ $k ] = (bool) $v;
1454
+ break;
1455
+ case 'url':
1456
+ if ( is_array( $v ) ) {
1457
+ $sanitized[ $k ] = array_map( 'esc_url_raw', $v );
1458
+ } else {
1459
+ $sanitized[ $k ] = esc_url_raw( $v );
1460
+ }
1461
+ break;
1462
+ case 'text':
1463
+ $sanitized[ $k ] = sanitize_text_field( $v );
1464
+ break;
1465
+ case 'textarea':
1466
+ $sanitized[ $k ] = sanitize_textarea_field( $v );
1467
+ break;
1468
+ case 'key':
1469
+ if ( is_array( $v ) ) {
1470
+ $sanitized[ $k ] = array_map( 'sanitize_key', $v );
1471
+ } else {
1472
+ $sanitized[ $k ] = sanitize_key( $v );
1473
+ }
1474
+ break;
1475
+ case 'absint':
1476
+ if ( is_array( $v ) ) {
1477
+ $sanitized[ $k ] = array_map( 'absint', $v );
1478
+ } else {
1479
+ $sanitized[ $k ] = absint( $v );
1480
+ }
1481
+ break;
1482
+ }
1483
+ }
1484
+
1485
+ $data = $sanitized;
1486
+
1487
+ $data = apply_filters( 'um_save_form_meta_sanitize', $data );
1488
+
1489
+ return $data;
1490
+ }
1491
+
1492
+
1493
+ /**
1494
+ * Sanitize options when wp-admin form has been submitted
1495
+ *
1496
+ * @todo checking all sanitize types
1497
+ *
1498
+ * @param array $data
1499
+ *
1500
+ * @return array
1501
+ */
1502
+ public function sanitize_options( $data ) {
1503
+ $sanitized = array();
1504
+ foreach ( $data as $k => $v ) {
1505
+ if ( ! array_key_exists( $k, UM()->admin_settings()->settings_map ) ) {
1506
+ // @todo remove since 2.2.x and leave only continue
1507
+ $sanitized[ $k ] = $v;
1508
+ continue;
1509
+ }
1510
+
1511
+ if ( ! array_key_exists( 'sanitize', UM()->admin_settings()->settings_map[ $k ] ) ) {
1512
+ // @todo remove since 2.2.x and leave only continue
1513
+ $sanitized[ $k ] = $v;
1514
+ continue;
1515
+ }
1516
+
1517
+ if ( is_callable( UM()->admin_settings()->settings_map[ $k ]['sanitize'], true, $callable_name ) ) {
1518
+ add_filter( 'um_settings_sanitize_' . $k, UM()->admin_settings()->settings_map[ $k ]['sanitize'], 10, 1 );
1519
+ }
1520
+
1521
+ switch ( UM()->admin_settings()->settings_map[ $k ]['sanitize'] ) {
1522
+ default:
1523
+ $sanitized[ $k ] = apply_filters( 'um_settings_sanitize_' . $k, $v );
1524
+ break;
1525
+ case 'int':
1526
+ $sanitized[ $k ] = (int) $v;
1527
+ break;
1528
+ case 'absint':
1529
+ if ( is_array( $v ) ) {
1530
+ $sanitized[ $k ] = array_map( 'absint', $v );
1531
+ } else {
1532
+ $sanitized[ $k ] = absint( $v );
1533
+ }
1534
+ break;
1535
+ case 'key':
1536
+ if ( is_array( $v ) ) {
1537
+ $sanitized[ $k ] = array_map( 'sanitize_key', $v );
1538
+ } else {
1539
+ $sanitized[ $k ] = sanitize_key( $v );
1540
+ }
1541
+ break;
1542
+ case 'bool':
1543
+ $sanitized[ $k ] = (bool) $v;
1544
+ break;
1545
+ case 'url':
1546
+ if ( is_array( $v ) ) {
1547
+ $sanitized[ $k ] = array_map( 'esc_url_raw', $v );
1548
+ } else {
1549
+ $sanitized[ $k ] = esc_url_raw( $v );
1550
+ }
1551
+ break;
1552
+ case 'wp_kses':
1553
+ $sanitized[ $k ] = wp_kses_post( $v );
1554
+ break;
1555
+ case 'textarea':
1556
+ $sanitized[ $k ] = sanitize_textarea_field( $v );
1557
+ break;
1558
+ case 'text':
1559
+ $sanitized[ $k ] = sanitize_text_field( $v );
1560
+ break;
1561
+ }
1562
+ }
1563
+
1564
+ $data = $sanitized;
1565
+
1566
+ $data = apply_filters( 'um_save_settings_sanitize', $data );
1567
+
1568
+ return $data;
1569
+ }
1570
+
1571
+
1572
+ /**
1573
+ * Adds class to our admin pages
1574
+ *
1575
+ * @param $classes
1576
+ *
1577
+ * @return string
1578
+ */
1579
+ public function admin_body_class( $classes ) {
1580
+ if ( $this->is_um_screen() ) {
1581
+ return "$classes um-admin";
1582
+ }
1583
+ return $classes;
1584
+ }
1585
+
1586
+
1587
+ /**
1588
+ *
1589
+ */
1590
+ public function manual_upgrades_request() {
1591
+ if ( ! is_admin() || ! current_user_can( 'manage_options' ) ) {
1592
+ die();
1593
+ }
1594
+
1595
+ $last_request = get_option( 'um_last_manual_upgrades_request', false );
1596
+
1597
+ if ( empty( $last_request ) || time() > $last_request + DAY_IN_SECONDS ) {
1598
+
1599
+ if ( is_multisite() ) {
1600
+ $blogs_ids = get_sites();
1601
+ foreach( $blogs_ids as $b ) {
1602
+ switch_to_blog( $b->blog_id );
1603
+ wp_clean_update_cache();
1604
+
1605
+ UM()->plugin_updater()->um_checklicenses();
1606
+
1607
+ update_option( 'um_last_manual_upgrades_request', time() );
1608
+ restore_current_blog();
1609
+ }
1610
+ } else {
1611
+ wp_clean_update_cache();
1612
+
1613
+ UM()->plugin_updater()->um_checklicenses();
1614
+
1615
+ update_option( 'um_last_manual_upgrades_request', time() );
1616
+ }
1617
+
1618
+ $url = add_query_arg( array( 'page' => 'ultimatemember', 'update' => 'got_updates' ), admin_url( 'admin.php' ) );
1619
+ } else {
1620
+ $url = add_query_arg( array( 'page' => 'ultimatemember', 'update' => 'often_updates' ), admin_url( 'admin.php' ) );
1621
+ }
1622
+ exit( wp_redirect( $url ) );
1623
+ }
1624
+
1625
+
1626
+ /**
1627
+ * Core pages installation
1628
+ */
1629
+ function install_core_pages() {
1630
+ if ( ! is_admin() ) {
1631
+ die();
1632
+ }
1633
+
1634
+ UM()->setup()->install_default_pages();
1635
+
1636
+ //check empty pages in settings
1637
+ $empty_pages = array();
1638
+
1639
+ $pages = UM()->config()->permalinks;
1640
+ if ( $pages && is_array( $pages ) ) {
1641
+ foreach ( $pages as $slug => $page_id ) {
1642
+ $page = get_post( $page_id );
1643
+
1644
+ if ( ! isset( $page->ID ) && in_array( $slug, array_keys( UM()->config()->core_pages ) ) ) {
1645
+ $empty_pages[] = $slug;
1646
+ }
1647
+ }
1648
+ }
1649
+
1650
+ //if there aren't empty pages - then hide pages notice
1651
+ if ( empty( $empty_pages ) ) {
1652
+ $hidden_notices = get_option( 'um_hidden_admin_notices', array() );
1653
+ $hidden_notices[] = 'wrong_pages';
1654
+
1655
+ update_option( 'um_hidden_admin_notices', $hidden_notices );
1656
+ }
1657
+
1658
+ $url = add_query_arg( array( 'page' => 'um_options' ), admin_url( 'admin.php' ) );
1659
+ exit( wp_redirect( $url ) );
1660
+ }
1661
+
1662
+
1663
+ /**
1664
+ * Clear all users cache
1665
+ *
1666
+ * @param $action
1667
+ */
1668
+ function user_cache( $action ) {
1669
+ global $wpdb;
1670
+ if ( ! is_admin() || ! current_user_can( 'manage_options' ) ) {
1671
+ die();
1672
+ }
1673
+
1674
+ $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE 'um_cache_userdata_%'" );
1675
+
1676
+ $url = add_query_arg( array( 'page' => 'ultimatemember', 'update' => 'cleared_cache' ), admin_url( 'admin.php' ) );
1677
+ exit( wp_redirect( $url ) );
1678
+ }
1679
+
1680
+
1681
+ /**
1682
+ * Purge temp uploads dir
1683
+ * @param $action
1684
+ */
1685
+ function purge_temp( $action ) {
1686
+ if ( ! is_admin() || ! current_user_can( 'manage_options' ) ) {
1687
+ die();
1688
+ }
1689
+
1690
+ UM()->files()->remove_dir( UM()->files()->upload_temp );
1691
+
1692
+ $url = add_query_arg( array( 'page' => 'ultimatemember', 'update' => 'purged_temp' ), admin_url( 'admin.php' ) );
1693
+ exit( wp_redirect( $url ) );
1694
+ }
1695
+
1696
+
1697
+ /**
1698
+ * Duplicate form
1699
+ *
1700
+ * @param $action
1701
+ */
1702
+ function duplicate_form( $action ) {
1703
+ if ( ! is_admin() || ! current_user_can('manage_options') ) {
1704
+ die();
1705
+ }
1706
+ if ( ! isset( $_REQUEST['post_id'] ) || ! is_numeric( $_REQUEST['post_id'] ) ) {
1707
+ die();
1708
+ }
1709
+
1710
+ $post_id = absint( $_REQUEST['post_id'] );
1711
+
1712
+ $n = array(
1713
+ 'post_type' => 'um_form',
1714
+ 'post_title' => sprintf( __( 'Duplicate of %s', 'ultimate-member' ), get_the_title( $post_id ) ),
1715
+ 'post_status' => 'publish',
1716
+ 'post_author' => get_current_user_id(),
1717
+ );
1718
+
1719
+ $n_id = wp_insert_post( $n );
1720
+
1721
+ $n_fields = get_post_custom( $post_id );
1722
+ foreach ( $n_fields as $key => $value ) {
1723
+
1724
+ if ( $key == '_um_custom_fields' ) {
1725
+ $the_value = unserialize( $value[0] );
1726
+ } else {
1727
+ $the_value = $value[0];
1728
+ }
1729
+
1730
+ update_post_meta( $n_id, $key, $the_value );
1731
+
1732
+ }
1733
+
1734
+ delete_post_meta( $n_id, '_um_core' );
1735
+
1736
+ $url = admin_url( 'edit.php?post_type=um_form' );
1737
+ $url = add_query_arg( 'update', 'form_duplicated', $url );
1738
+
1739
+ exit( wp_redirect( $url ) );
1740
+
1741
+ }
1742
+
1743
+
1744
+ /**
1745
+ * Action to hide notices in admin
1746
+ *
1747
+ * @param $action
1748
+ */
1749
+ function um_hide_notice( $action ) {
1750
+ if ( ! is_admin() || ! current_user_can( 'manage_options' ) ) {
1751
+ die();
1752
+ }
1753
+
1754
+ update_option( $action, 1 );
1755
+ exit( wp_redirect( remove_query_arg( 'um_adm_action' ) ) );
1756
+ }
1757
+
1758
+
1759
+ /**
1760
+ * Various user actions
1761
+ *
1762
+ * @param $action
1763
+ */
1764
+ function user_action( $action ) {
1765
+ if ( ! is_admin() || ! current_user_can( 'edit_users' ) ) {
1766
+ die();
1767
+ }
1768
+ if ( ! isset( $_REQUEST['sub'] ) ) {
1769
+ die();
1770
+ }
1771
+ if ( ! isset( $_REQUEST['user_id'] ) ) {
1772
+ die();
1773
+ }
1774
+
1775
+ um_fetch_user( absint( $_REQUEST['user_id'] ) );
1776
+
1777
+ $subaction = sanitize_key( $_REQUEST['sub'] );
1778
+
1779
+ /**
1780
+ * UM hook
1781
+ *
1782
+ * @type action
1783
+ * @title um_admin_user_action_hook
1784
+ * @description Action on bulk user subaction
1785
+ * @input_vars
1786
+ * [{"var":"$subaction","type":"string","desc":"Bulk Subaction"}]
1787
+ * @change_log
1788
+ * ["Since: 2.0"]
1789
+ * @usage add_action( 'um_admin_user_action_hook', 'function_name', 10, 1 );
1790
+ * @example
1791
+ * <?php
1792
+ * add_action( 'um_admin_user_action_hook', 'my_admin_user_action', 10, 1 );
1793
+ * function my_admin_user_action( $subaction ) {
1794
+ * // your code here
1795
+ * }
1796
+ * ?>
1797
+ */
1798
+ do_action( 'um_admin_user_action_hook', $subaction );
1799
+ /**
1800
+ * UM hook
1801
+ *
1802
+ * @type action
1803
+ * @title um_admin_user_action_{$subaction}_hook
1804
+ * @description Action on bulk user subaction
1805
+ * @change_log
1806
+ * ["Since: 2.0"]
1807
+ * @usage add_action( 'um_admin_user_action_{$subaction}_hook', 'function_name', 10 );
1808
+ * @example
1809
+ * <?php
1810
+ * add_action( 'um_admin_user_action_{$subaction}_hook', 'my_admin_user_action', 10 );
1811
+ * function my_admin_user_action() {
1812
+ * // your code here
1813
+ * }
1814
+ * ?>
1815
+ */
1816
+ do_action( "um_admin_user_action_{$subaction}_hook" );
1817
+
1818
+ um_reset_user();
1819
+
1820
+ wp_redirect( add_query_arg( 'update', 'user_updated', admin_url( '?page=ultimatemember' ) ) );
1821
+ exit;
1822
+
1823
+ }
1824
+
1825
+
1826
+ /**
1827
+ * Add any custom links to plugin page
1828
+ *
1829
+ * @param array $links
1830
+ *
1831
+ * @return array
1832
+ */
1833
+ function plugin_links( $links ) {
1834
+ $more_links[] = '<a href="http://docs.ultimatemember.com/">' . __( 'Docs', 'ultimate-member' ) . '</a>';
1835
+ $more_links[] = '<a href="'.admin_url().'admin.php?page=um_options">' . __( 'Settings', 'ultimate-member' ) . '</a>';
1836
+
1837
+ $links = $more_links + $links;
1838
+ return $links;
1839
+ }
1840
+
1841
+
1842
+ /**
1843
+ * Init admin action/filters + request handlers
1844
+ */
1845
+ function admin_init() {
1846
+ $this->init_variables();
1847
+
1848
+ if ( is_admin() && current_user_can( 'manage_options' ) && ! empty( $_REQUEST['um_adm_action'] ) ) {
1849
+ $action = sanitize_key( $_REQUEST['um_adm_action'] );
1850
+
1851
+ /**
1852
+ * UM hook
1853
+ *
1854
+ * @type action
1855
+ * @title um_admin_do_action__
1856
+ * @description Make some action on custom admin action
1857
+ * @input_vars
1858
+ * [{"var":"$action","type":"string","desc":"Admin Action"}]
1859
+ * @change_log
1860
+ * ["Since: 2.0"]
1861
+ * @usage add_action( 'um_admin_do_action__', 'function_name', 10, 1 );
1862
+ * @example
1863
+ * <?php
1864
+ * add_action( 'um_admin_do_action__', 'my_admin_do_action', 10, 1 );
1865
+ * function my_admin_do_action( $action ) {
1866
+ * // your code here
1867
+ * }
1868
+ * ?>
1869
+ */
1870
+ do_action( 'um_admin_do_action__', $action );
1871
+ /**
1872
+ * UM hook
1873
+ *
1874
+ * @type action
1875
+ * @title um_admin_do_action__{$action}
1876
+ * @description Make some action on custom admin $action
1877
+ * @input_vars
1878
+ * [{"var":"$action","type":"string","desc":"Admin Action"}]
1879
+ * @change_log
1880
+ * ["Since: 2.0"]
1881
+ * @usage add_action( 'um_admin_do_action__{$action}', 'function_name', 10, 1 );
1882
+ * @example
1883
+ * <?php
1884
+ * add_action( 'um_admin_do_action__{$action}', 'my_admin_do_action', 10, 1 );
1885
+ * function my_admin_do_action( $action ) {
1886
+ * // your code here
1887
+ * }
1888
+ * ?>
1889
+ */
1890
+ do_action( "um_admin_do_action__{$action}", $action );
1891
+ }
1892
+ }
1893
+
1894
+
1895
+ /**
1896
+ * Updated post messages
1897
+ *
1898
+ * @param array $messages
1899
+ *
1900
+ * @return array
1901
+ */
1902
+ function post_updated_messages( $messages ) {
1903
+ global $post_ID;
1904
+
1905
+ $post_type = get_post_type( $post_ID );
1906
+
1907
+ if ( $post_type == 'um_form' ) {
1908
+ $messages['um_form'] = array(
1909
+ 0 => '',
1910
+ 1 => __( 'Form updated.', 'ultimate-member' ),
1911
+ 2 => __( 'Custom field updated.', 'ultimate-member' ),
1912
+ 3 => __( 'Custom field deleted.', 'ultimate-member' ),
1913
+ 4 => __( 'Form updated.', 'ultimate-member' ),
1914
+ 5 => isset( $_GET['revision'] ) ? __( 'Form restored to revision.', 'ultimate-member' ) : false,
1915
+ 6 => __( 'Form created.', 'ultimate-member' ),
1916
+ 7 => __( 'Form saved.', 'ultimate-member' ),
1917
+ 8 => __( 'Form submitted.', 'ultimate-member' ),
1918
+ 9 => __( 'Form scheduled.', 'ultimate-member' ),
1919
+ 10 => __( 'Form draft updated.', 'ultimate-member' ),
1920
+ );
1921
+ }
1922
+
1923
+ return $messages;
1924
+ }
1925
+
1926
+
1927
+ /**
1928
+ * Gettext filters
1929
+ *
1930
+ * @param $translation
1931
+ * @param $text
1932
+ * @param $domain
1933
+ *
1934
+ * @return string
1935
+ */
1936
+ function gettext( $translation, $text, $domain ) {
1937
+ global $post;
1938
+ if ( isset( $post->post_type ) && $this->is_plugin_post_type() ) {
1939
+ $translations = get_translations_for_domain( $domain );
1940
+ if ( $text == 'Publish' ) {
1941
+ return $translations->translate( 'Create' );
1942
+ } elseif ( $text == 'Move to Trash' ) {
1943
+ return $translations->translate( 'Delete' );
1944
+ }
1945
+ }
1946
+
1947
+ return $translation;
1948
+ }
1949
+
1950
+
1951
+ /**
1952
+ * Fix parent file for correct highlighting
1953
+ *
1954
+ * @param $parent_file
1955
+ *
1956
+ * @return string
1957
+ */
1958
+ function parent_file( $parent_file ) {
1959
+ global $current_screen;
1960
+ $screen_id = $current_screen->id;
1961
+ if ( strstr( $screen_id, 'um_' ) ) {
1962
+ $parent_file = 'ultimatemember';
1963
+ }
1964
+ return $parent_file;
1965
+ }
1966
+
1967
+
1968
+ /**
1969
+ * @since 2.0
1970
+ *
1971
+ * @return core\Admin_Notices()
1972
+ */
1973
+ function notices() {
1974
+ if ( empty( UM()->classes['admin_notices'] ) ) {
1975
+ UM()->classes['admin_notices'] = new core\Admin_Notices();
1976
+ }
1977
+ return UM()->classes['admin_notices'];
1978
+ }
1979
+ }
1980
+ }
includes/admin/core/class-admin-builder.php CHANGED
@@ -1,1228 +1,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, null, $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, null, $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, null, $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, null, $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( $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
- $um_callback_func = sanitize_key( $_POST['um_option_callback'] );
1213
- if ( empty( $um_callback_func ) ) {
1214
- $arr_options['status'] = 'empty';
1215
- $arr_options['function_name'] = $um_callback_func;
1216
- $arr_options['function_exists'] = function_exists( $um_callback_func );
1217
- }
1218
-
1219
- $arr_options['data'] = array();
1220
- if ( function_exists( $um_callback_func ) ) {
1221
- $arr_options['data'] = call_user_func( $um_callback_func );
1222
- }
1223
-
1224
- wp_send_json( $arr_options );
1225
- }
1226
-
1227
- }
1228
- }
 
 
 
 
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
+ }
includes/admin/core/class-admin-metabox.php CHANGED
@@ -1,2427 +1,2426 @@
1
- <?php
2
- namespace um\admin\core;
3
-
4
-
5
- if ( ! defined( 'ABSPATH' ) ) exit;
6
-
7
-
8
- if ( ! class_exists( 'um\admin\core\Admin_Metabox' ) ) {
9
-
10
-
11
- /**
12
- * Class Admin_Metabox
13
- *
14
- * @package um\admin\core
15
- */
16
- class Admin_Metabox {
17
-
18
-
19
- /**
20
- * @var bool
21
- */
22
- private $form_nonce_added = false;
23
-
24
-
25
- /**
26
- * @var bool
27
- */
28
- private $directory_nonce_added = false;
29
-
30
-
31
- /**
32
- * @var bool
33
- */
34
- private $custom_nonce_added = false;
35
-
36
-
37
- var $init_icon = false;
38
-
39
-
40
- /**
41
- * Admin_Metabox constructor.
42
- */
43
- function __construct() {
44
- $this->in_edit = false;
45
- $this->edit_mode_value = null;
46
- $this->edit_array = [];
47
-
48
- add_action( 'admin_head', array( &$this, 'admin_head' ), 9);
49
- add_action( 'admin_footer', array( &$this, 'load_modal_content' ), 9 );
50
-
51
- add_action( 'load-post.php', array( &$this, 'add_metabox' ), 9 );
52
- add_action( 'load-post-new.php', array( &$this, 'add_metabox' ), 9 );
53
-
54
- add_action( 'admin_init', array( &$this, 'add_taxonomy_metabox' ), 9 );
55
-
56
- //roles metaboxes
57
- add_action( 'um_roles_add_meta_boxes', array( &$this, 'add_metabox_role' ) );
58
-
59
- add_filter( 'um_builtin_validation_types_continue_loop', array( &$this, 'validation_types_continue_loop' ), 1, 4 );
60
- add_filter( 'um_restrict_content_hide_metabox', array( &$this, 'hide_metabox_restrict_content_shop' ), 10, 1 );
61
-
62
- add_filter( 'um_member_directory_meta_value_before_save', array( UM()->member_directory(), 'before_save_data' ), 10, 3 );
63
- }
64
-
65
-
66
- /**
67
- * Hide Woocommerce Shop page restrict content metabox
68
- * @param $hide
69
- *
70
- * @return bool
71
- */
72
- function hide_metabox_restrict_content_shop( $hide ) {
73
- if ( function_exists( 'wc_get_page_id' ) && ! empty( $_GET['post'] ) &&
74
- absint( $_GET['post'] ) == wc_get_page_id( 'shop' ) ) {
75
- return true;
76
- }
77
-
78
- return $hide;
79
- }
80
-
81
-
82
- /**
83
- * Filter validation types on loop
84
- *
85
- * @param $break
86
- * @param $key
87
- * @param $form_id
88
- * @param $field_array
89
- *
90
- * @return bool
91
- */
92
- function validation_types_continue_loop( $break, $key, $form_id, $field_array ) {
93
-
94
- // show unique username validation only for user_login field
95
- if ( isset( $field_array['metakey'] ) && $field_array['metakey'] == 'user_login' && $key !== 'unique_username' ) {
96
- return false;
97
- }
98
-
99
- return $break;
100
- }
101
-
102
-
103
- /**
104
- * Gets the role meta
105
- *
106
- * @param $id
107
- *
108
- * @return mixed
109
- */
110
- function get_custom_post_meta( $id ) {
111
- $all_meta = get_post_custom( $id );
112
- foreach ( $all_meta as $k => $v ) {
113
- if ( strstr( $k, '_um_' ) ) {
114
- $um_meta[ $k ] = $v;
115
- }
116
- }
117
- if ( isset( $um_meta ) ) {
118
- return $um_meta;
119
- }
120
-
121
- return false;
122
- }
123
-
124
-
125
- /**
126
- * Runs on admin head
127
- */
128
- function admin_head(){
129
- global $post;
130
- if ( UM()->admin()->is_plugin_post_type() && isset($post->ID) ){
131
- $this->postmeta = $this->get_custom_post_meta($post->ID);
132
- }
133
- }
134
-
135
-
136
- /**
137
- * Init the metaboxes
138
- */
139
- function add_metabox() {
140
- global $current_screen;
141
-
142
- if ( $current_screen->id == 'um_form' ) {
143
- add_action( 'add_meta_boxes', array(&$this, 'add_metabox_form'), 1 );
144
- add_action( 'save_post', array(&$this, 'save_metabox_form'), 10, 2 );
145
- }
146
-
147
- if ( $current_screen->id == 'um_directory' ) {
148
- add_action( 'add_meta_boxes', array(&$this, 'add_metabox_directory'), 1 );
149
- add_action( 'save_post', array(&$this, 'save_metabox_directory'), 10, 2 );
150
- }
151
-
152
- //restrict content metabox
153
- $post_types = UM()->options()->get( 'restricted_access_post_metabox' );
154
- if ( ! empty( $post_types[ $current_screen->id ] ) ) {
155
-
156
- /**
157
- * UM hook
158
- *
159
- * @type filter
160
- * @title um_restrict_content_hide_metabox
161
- * @description Show/Hide Restrict content metabox
162
- * @input_vars
163
- * [{"var":"$show","type":"bool","desc":"Show Metabox"}]
164
- * @change_log
165
- * ["Since: 2.0"]
166
- * @usage add_filter( 'um_restrict_content_hide_metabox', 'function_name', 10, 1 );
167
- * @example
168
- * <?php
169
- * add_filter( 'um_restrict_content_hide_metabox', 'my_restrict_content_hide_metabox', 10, 1 );
170
- * function my_restrict_content_hide_metabox( $show ) {
171
- * // your code here
172
- * return $show;
173
- * }
174
- * ?>
175
- */
176
- $hide_metabox = apply_filters( 'um_restrict_content_hide_metabox', false );
177
-
178
- if ( ! $hide_metabox ) {
179
- add_action( 'add_meta_boxes', array(&$this, 'add_metabox_restrict_content'), 1 );
180
- add_action( 'save_post', array( &$this, 'save_metabox_restrict_content' ), 10, 2 );
181
- }
182
-
183
- if ( $current_screen->id == 'attachment' ) {
184
- add_action( 'add_attachment', array( &$this, 'save_attachment_metabox_restrict_content' ), 10, 2 );
185
- add_action( 'edit_attachment', array( &$this, 'save_attachment_metabox_restrict_content' ), 10, 2 );
186
- }
187
- }
188
-
189
-
190
- add_action( 'save_post', array( &$this, 'save_metabox_custom' ), 10, 2 );
191
- }
192
-
193
-
194
- /**
195
- * @param $post_id
196
- * @param $post
197
- */
198
- public function save_metabox_custom( $post_id, $post ) {
199
- // validate nonce
200
- if ( ! isset( $_POST['um_admin_save_metabox_custom_nonce'] ) ||
201
- ! wp_verify_nonce( $_POST['um_admin_save_metabox_custom_nonce'], basename( __FILE__ ) ) ) {
202
- return;
203
- }
204
-
205
- /**
206
- * UM hook
207
- *
208
- * @type action
209
- * @title um_admin_custom_restrict_content_metaboxes
210
- * @description Save metabox custom with restrict content
211
- * @input_vars
212
- * [{"var":"$post_id","type":"int","desc":"Post ID"},
213
- * {"var":"$post","type":"array","desc":"Post data"}]
214
- * @change_log
215
- * ["Since: 2.0"]
216
- * @usage add_action( 'um_admin_custom_restrict_content_metaboxes', 'function_name', 10, 2 );
217
- * @example
218
- * <?php
219
- * add_action( 'um_admin_custom_restrict_content_metaboxes', 'my_admin_custom_restrict_content', 10, 2 );
220
- * function my_admin_custom_restrict_content( $post_id, $post ) {
221
- * // your code here
222
- * }
223
- * ?>
224
- */
225
- do_action( 'um_admin_custom_restrict_content_metaboxes', $post_id, $post );
226
- }
227
-
228
-
229
- /**
230
- *
231
- */
232
- function add_metabox_restrict_content() {
233
- global $current_screen;
234
-
235
- add_meta_box(
236
- 'um-admin-restrict-content',
237
- __( 'Ultimate Member: Content Restriction', 'ultimate-member' ),
238
- array( &$this, 'restrict_content_cb' ),
239
- $current_screen->id,
240
- 'normal',
241
- 'default'
242
- );
243
-
244
- /**
245
- * UM hook
246
- *
247
- * @type action
248
- * @title um_admin_custom_restrict_content_metaboxes
249
- * @description Add restrict content custom metabox
250
- * @change_log
251
- * ["Since: 2.0"]
252
- * @usage add_action( 'um_admin_custom_restrict_content_metaboxes', 'function_name', 10 );
253
- * @example
254
- * <?php
255
- * add_action( 'um_admin_custom_restrict_content_metaboxes', 'my_admin_custom_restrict_content', 10 );
256
- * function my_admin_custom_restrict_content() {
257
- * // your code here
258
- * }
259
- * ?>
260
- */
261
- do_action( 'um_admin_custom_restrict_content_metaboxes' );
262
- }
263
-
264
-
265
- /**
266
- * Content restriction metabox
267
- *
268
- * @param $object
269
- * @param $box
270
- */
271
- function restrict_content_cb( $object, $box ) {
272
- include_once UM()->admin()->templates_path . 'access/restrict_content.php';
273
- wp_nonce_field( basename( __FILE__ ), 'um_admin_save_metabox_restrict_content_nonce' );
274
- }
275
-
276
-
277
- /**
278
- * Init the metaboxes
279
- */
280
- function add_taxonomy_metabox() {
281
- //restrict content metabox
282
- $all_taxonomies = get_taxonomies( array( 'public' => true ) );
283
- $tax_types = UM()->options()->get( 'restricted_access_taxonomy_metabox' );
284
- $exclude_taxonomies = UM()->excluded_taxonomies();
285
-
286
- foreach ( $all_taxonomies as $key => $taxonomy ) {
287
- if ( in_array( $key, $exclude_taxonomies ) || empty( $tax_types[$key] ) )
288
- continue;
289
-
290
- add_action( $taxonomy . '_add_form_fields', array( &$this, 'um_category_access_fields_create' ) );
291
- add_action( $taxonomy . '_edit_form_fields', array( &$this, 'um_category_access_fields_edit' ) );
292
- add_action( 'create_' . $taxonomy, array( &$this, 'um_category_access_fields_save' ) );
293
- add_action( 'edited_' . $taxonomy, array( &$this, 'um_category_access_fields_save' ) );
294
- }
295
- }
296
-
297
-
298
- /**
299
- * @param $post_id
300
- * @param $post
301
- */
302
- function save_metabox_restrict_content( $post_id, $post ) {
303
- // validate nonce
304
- if ( ! isset( $_POST['um_admin_save_metabox_restrict_content_nonce'] ) ||
305
- ! wp_verify_nonce( $_POST['um_admin_save_metabox_restrict_content_nonce'], basename( __FILE__ ) ) ) {
306
- return;
307
- }
308
-
309
- // validate user
310
- $post_type = get_post_type_object( $post->post_type );
311
- if ( ! current_user_can( $post_type->cap->edit_post, $post_id ) ) {
312
- return;
313
- }
314
-
315
- if ( ! empty( $_POST['um_content_restriction'] ) && is_array( $_POST['um_content_restriction'] ) ) {
316
- $restriction_meta = UM()->admin()->sanitize_post_restriction_meta( $_POST['um_content_restriction'] );
317
-
318
- update_post_meta( $post_id, 'um_content_restriction', $restriction_meta );
319
- } else {
320
- delete_post_meta( $post_id, 'um_content_restriction' );
321
- }
322
- }
323
-
324
-
325
- /**
326
- * @param $post_id
327
- *
328
- */
329
- function save_attachment_metabox_restrict_content( $post_id ) {
330
- // validate nonce
331
- if ( ! isset( $_POST['um_admin_save_metabox_restrict_content_nonce'] )
332
- || ! wp_verify_nonce( $_POST['um_admin_save_metabox_restrict_content_nonce'], basename( __FILE__ ) ) ) {
333
- return;
334
- }
335
-
336
- $post = get_post( $post_id );
337
-
338
- // validate user
339
- $post_type = get_post_type_object( $post->post_type );
340
- if ( ! current_user_can( $post_type->cap->edit_post, $post_id ) ) {
341
- return;
342
- }
343
-
344
- if ( ! empty( $_POST['um_content_restriction'] ) && is_array( $_POST['um_content_restriction'] ) ) {
345
- $restriction_meta = UM()->admin()->sanitize_post_restriction_meta( $_POST['um_content_restriction'] );
346
-
347
- update_post_meta( $post_id, 'um_content_restriction', $restriction_meta );
348
- } else {
349
- delete_post_meta( $post_id, 'um_content_restriction' );
350
- }
351
- }
352
-
353
-
354
- /**
355
- *
356
- */
357
- function um_category_access_fields_create() {
358
- /**
359
- * UM hook
360
- *
361
- * @type filter
362
- * @title um_admin_category_access_settings_fields
363
- * @description Settings fields for terms
364
- * @input_vars
365
- * [{"var":"$access_settings_fields","type":"array","desc":"Settings Fields"},
366
- * {"var":"$data","type":"array","desc":"Settings Data"},
367
- * {"var":"$screen","type":"string","desc":"Category Screen"}]
368
- * @change_log
369
- * ["Since: 2.0"]
370
- * @usage add_filter( 'um_admin_category_access_settings_fields', 'function_name', 10, 3 );
371
- * @example
372
- * <?php
373
- * add_filter( 'um_admin_category_access_settings_fields', 'my_admin_category_access_settings_fields', 10, 3 );
374
- * function my_admin_category_access_settings_fields( $access_settings_fields, $data, $screen ) {
375
- * // your code here
376
- * $access_settings_fields[] = array(
377
- * 'id' => 'my-field-key',
378
- * 'type' => 'my-field-type',
379
- * 'label' => __( 'My field Label', 'ultimate-member' ),
380
- * 'description' => __( 'My Field Description', 'ultimate-member' ),
381
- * 'value' => ! empty( $data['_um_custom_access_settings'] ) ? $data['_um_custom_access_settings'] : 0,
382
- * );
383
- * return $access_settings_fields;
384
- * }
385
- * ?>
386
- */
387
- $fields = apply_filters( 'um_admin_category_access_settings_fields', array(
388
- array(
389
- 'id' => '_um_custom_access_settings',
390
- 'type' => 'checkbox',
391
- 'label' => __( 'Restrict access to this term and its posts?', 'ultimate-member' ),
392
- 'description' => __( 'Activate content restriction for this term and its posts. Affects only posts that do not have individual Restriction Content settings', 'ultimate-member' ),
393
- 'value' => 0,
394
- ),
395
- array(
396
- 'id' => '_um_accessible',
397
- 'type' => 'select',
398
- 'label' => __( 'Who can access this term and its posts?', 'ultimate-member' ),
399
- 'value' => '0',
400
- 'options' => array(
401
- '0' => __( 'Everyone', 'ultimate-member' ),
402
- '1' => __( 'Logged out users', 'ultimate-member' ),
403
- '2' => __( 'Logged in users', 'ultimate-member' ),
404
- ),
405
- 'conditional' => array( '_um_custom_access_settings', '=', '1' ),
406
- ),
407
- array(
408
- 'id' => '_um_access_roles',
409
- 'type' => 'multi_checkbox',
410
- 'label' => __( 'Select which roles can access this term and its posts', 'ultimate-member' ),
411
- 'description' => __( 'Leave empty if you want to display a term for all logged in users', 'ultimate-member' ),
412
- 'options' => UM()->roles()->get_roles( false ),
413
- 'columns' => 3,
414
- 'conditional' => array( '_um_accessible', '=', '2' ),
415
- ),
416
- array(
417
- 'id' => '_um_access_hide_from_queries',
418
- 'type' => 'checkbox',
419
- 'label' => UM()->options()->get( 'disable_restriction_pre_queries' ) ? __( 'Hide from queries', 'ultimate-member' ) : __( 'Would you like to display 404 error on the term\'s archive page and terms\' posts single pages when users haven\'t access?', 'ultimate-member' ),
420
- 'description' => UM()->options()->get( 'disable_restriction_pre_queries' ) ? __( 'Exclude only from WP queries results', 'ultimate-member' ) : __( 'Recommended to be enabled. Restricted term\'s archive page and all terms\' posts will be hidden by exclusion from WP Query. The safest and most effective method that hides post and its comments from all requests, RSS feeds, etc. on your site', 'ultimate-member' ),
421
- 'value' => 1,
422
- 'conditional' => array( '_um_accessible', '!=', '0' ),
423
- ),
424
- array(
425
- 'id' => '_um_noaccess_action',
426
- 'type' => 'select',
427
- 'label' => __( 'What happens when users without access try to view the term\'s post?', 'ultimate-member' ),
428
- 'description' => __( 'Action when users without access tries to view the term\'s post', 'ultimate-member' ),
429
- 'value' => '0',
430
- 'options' => array(
431
- '0' => __( 'Show access restricted message', 'ultimate-member' ),
432
- '1' => __( 'Redirect user', 'ultimate-member' ),
433
- ),
434
- 'conditional' => UM()->options()->get( 'disable_restriction_pre_queries' ) ? array( '_um_accessible', '!=', '0' ) : array( '_um_access_hide_from_queries', '=', '0' ),
435
- ),
436
- array(
437
- 'id' => '_um_restrict_by_custom_message',
438
- 'type' => 'select',
439
- 'label' => __( 'Restricted access message type', 'ultimate-member' ),
440
- 'description' => __( 'Would you like to use the global default message or apply a custom message to this term\'s post?', 'ultimate-member' ),
441
- 'value' => '0',
442
- 'options' => array(
443
- '0' => __( 'Global default message', 'ultimate-member' ),
444
- '1' => __( 'Custom message', 'ultimate-member' ),
445
- ),
446
- 'conditional' => array( '_um_noaccess_action', '=', '0' ),
447
- ),
448
- array(
449
- 'id' => '_um_restrict_custom_message',
450
- 'type' => 'wp_editor',
451
- 'label' => __( 'Custom restricted access message', 'ultimate-member' ),
452
- 'description' => __( 'You may replace global restricted access message here', 'ultimate-member' ),
453
- 'value' => '',
454
- 'conditional' => array( '_um_restrict_by_custom_message', '=', '1' ),
455
- ),
456
- array(
457
- 'id' => '_um_access_redirect',
458
- 'type' => 'select',
459
- 'label' => __( 'Where should users be redirected to?', 'ultimate-member' ),
460
- 'description' => __( 'Select redirect to page when user hasn\'t access to the term\'s post', 'ultimate-member' ),
461
- 'value' => '0',
462
- 'conditional' => array( '_um_noaccess_action', '=', '1' ),
463
- 'options' => array(
464
- '0' => __( 'Login page', 'ultimate-member' ),
465
- '1' => __( 'Custom URL', 'ultimate-member' ),
466
- ),
467
- ),
468
- array(
469
- 'id' => '_um_access_redirect_url',
470
- 'type' => 'text',
471
- 'label' => __( 'Redirect URL', 'ultimate-member' ),
472
- 'description' => __( 'Set full URL where do you want to redirect the user', 'ultimate-member' ),
473
- 'value' => '',
474
- 'conditional' => array( '_um_access_redirect', '=', '1' ),
475
- ),
476
- ), array(), 'create' );
477
-
478
- UM()->admin_forms(
479
- array(
480
- 'class' => 'um-restrict-content um-third-column',
481
- 'prefix_id' => 'um_content_restriction',
482
- 'without_wrapper' => true,
483
- 'div_line' => true,
484
- 'fields' => $fields,
485
- )
486
- )->render_form();
487
-
488
- wp_nonce_field( basename( __FILE__ ), 'um_admin_save_taxonomy_restrict_content_nonce' );
489
- }
490
-
491
-
492
- /**
493
- * @param $term
494
- */
495
- function um_category_access_fields_edit( $term ) {
496
- $termID = $term->term_id;
497
-
498
- $data = get_term_meta( $termID, 'um_content_restriction', true );
499
-
500
- $_um_access_roles_value = array();
501
- if ( ! empty( $data['_um_access_roles'] ) ) {
502
- foreach ( $data['_um_access_roles'] as $key => $value ) {
503
- if ( $value ) {
504
- $_um_access_roles_value[] = $key;
505
- }
506
- }
507
- }
508
-
509
- /**
510
- * UM hook
511
- *
512
- * @type filter
513
- * @title um_admin_category_access_settings_fields
514
- * @description Settings fields for terms
515
- * @input_vars
516
- * [{"var":"$access_settings_fields","type":"array","desc":"Settings Fields"},
517
- * {"var":"$data","type":"array","desc":"Settings Data"},
518
- * {"var":"$screen","type":"string","desc":"Category Screen"}]
519
- * @change_log
520
- * ["Since: 2.0"]
521
- * @usage add_filter( 'um_admin_category_access_settings_fields', 'function_name', 10, 3 );
522
- * @example
523
- * <?php
524
- * add_filter( 'um_admin_category_access_settings_fields', 'my_admin_category_access_settings_fields', 10, 3 );
525
- * function my_admin_category_access_settings_fields( $access_settings_fields, $data, $screen ) {
526
- * // your code here
527
- * $access_settings_fields[] = array(
528
- * 'id' => 'my-field-key',
529
- * 'type' => 'my-field-type',
530
- * 'label' => __( 'My field Label', 'ultimate-member' ),
531
- * 'description' => __( 'My Field Description', 'ultimate-member' ),
532
- * 'value' => ! empty( $data['_um_custom_access_settings'] ) ? $data['_um_custom_access_settings'] : 0,
533
- * );
534
- * return $access_settings_fields;
535
- * }
536
- * ?>
537
- */
538
- $fields = apply_filters( 'um_admin_category_access_settings_fields', array(
539
- array(
540
- 'id' => '_um_custom_access_settings',
541
- 'type' => 'checkbox',
542
- 'label' => __( 'Restrict access to this term and its posts?', 'ultimate-member' ),
543
- 'description' => __( 'Activate content restriction for this term and its posts. Affects only posts that do not have individual Restriction Content settings', 'ultimate-member' ),
544
- 'value' => ! empty( $data['_um_custom_access_settings'] ) ? $data['_um_custom_access_settings'] : 0,
545
- ),
546
- array(
547
- 'id' => '_um_accessible',
548
- 'type' => 'select',
549
- 'label' => __( 'Who can access this term and its posts?', 'ultimate-member' ),
550
- 'value' => ! empty( $data['_um_accessible'] ) ? $data['_um_accessible'] : '0',
551
- 'options' => array(
552
- '0' => __( 'Everyone', 'ultimate-member' ),
553
- '1' => __( 'Logged out users', 'ultimate-member' ),
554
- '2' => __( 'Logged in users', 'ultimate-member' ),
555
- ),
556
- 'conditional' => array( '_um_custom_access_settings', '=', '1' ),
557
- ),
558
- array(
559
- 'id' => '_um_access_roles',
560
- 'type' => 'multi_checkbox',
561
- 'label' => __( 'Select which roles can access this term and its posts', 'ultimate-member' ),
562
- 'description' => __( 'Leave empty if you want to display a term for all logged in users', 'ultimate-member' ),
563
- 'value' => $_um_access_roles_value,
564
- 'options' => UM()->roles()->get_roles( false ),
565
- 'columns' => 3,
566
- 'conditional' => array( '_um_accessible', '=', '2' ),
567
- ),
568
- array(
569
- 'id' => '_um_access_hide_from_queries',
570
- 'type' => 'checkbox',
571
- 'label' => UM()->options()->get( 'disable_restriction_pre_queries' ) ? __( 'Hide from queries', 'ultimate-member' ) : __( 'Would you like to display 404 error on the term\'s archive page and terms\' posts single pages when users haven\'t access?', 'ultimate-member' ),
572
- 'description' => UM()->options()->get( 'disable_restriction_pre_queries' ) ? __( 'Exclude only from WP queries results', 'ultimate-member' ) : __( 'Recommended to be enabled. Restricted term\'s archive page and all terms\' posts will be hidden by exclusion from WP Query. The safest and most effective method that hides post and its comments from all requests, RSS feeds, etc. on your site', 'ultimate-member' ),
573
- 'value' => ! empty( $data['_um_access_hide_from_queries'] ) ? $data['_um_access_hide_from_queries'] : '',
574
- 'conditional' => array( '_um_accessible', '!=', '0' ),
575
- ),
576
- array(
577
- 'id' => '_um_noaccess_action',
578
- 'type' => 'select',
579
- 'label' => __( 'What happens when users without access try to view the term\'s post?', 'ultimate-member' ),
580
- 'description' => __( 'Action when users without access tries to view the term\'s post', 'ultimate-member' ),
581
- 'value' => ! empty( $data['_um_noaccess_action'] ) ? $data['_um_noaccess_action'] : '0',
582
- 'options' => array(
583
- '0' => __( 'Show access restricted message', 'ultimate-member' ),
584
- '1' => __( 'Redirect user', 'ultimate-member' ),
585
- ),
586
- 'conditional' => UM()->options()->get( 'disable_restriction_pre_queries' ) ? array( '_um_accessible', '!=', '0' ) : array( '_um_access_hide_from_queries', '=', '0' ),
587
- ),
588
- array(
589
- 'id' => '_um_restrict_by_custom_message',
590
- 'type' => 'select',
591
- 'label' => __( 'Restricted access message type', 'ultimate-member' ),
592
- 'description' => __( 'Would you like to use the global default message or apply a custom message to this term\'s post?', 'ultimate-member' ),
593
- 'value' => ! empty( $data['_um_restrict_by_custom_message'] ) ? $data['_um_restrict_by_custom_message'] : '0',
594
- 'options' => array(
595
- '0' => __( 'Global default message', 'ultimate-member' ),
596
- '1' => __( 'Custom message', 'ultimate-member' ),
597
- ),
598
- 'conditional' => array( '_um_noaccess_action', '=', '0' ),
599
- ),
600
- array(
601
- 'id' => '_um_restrict_custom_message',
602
- 'type' => 'wp_editor',
603
- 'label' => __( 'Custom restricted access message', 'ultimate-member' ),
604
- 'description' => __( 'You may replace global restricted access message here', 'ultimate-member' ),
605
- 'value' => ! empty( $data['_um_restrict_custom_message'] ) ? $data['_um_restrict_custom_message'] : '',
606
- 'conditional' => array( '_um_restrict_by_custom_message', '=', '1' ),
607
- ),
608
- array(
609
- 'id' => '_um_access_redirect',
610
- 'type' => 'select',
611
- 'label' => __( 'Where should users be redirected to?', 'ultimate-member' ),
612
- 'description' => __( 'Select redirect to page when user hasn\'t access to the term\'s post', 'ultimate-member' ),
613
- 'value' => ! empty( $data['_um_access_redirect'] ) ? $data['_um_access_redirect'] : '0',
614
- 'options' => array(
615
- '0' => __( 'Login page', 'ultimate-member' ),
616
- '1' => __( 'Custom URL', 'ultimate-member' ),
617
- ),
618
- 'conditional' => array( '_um_noaccess_action', '=', '1' ),
619
- ),
620
- array(
621
- 'id' => '_um_access_redirect_url',
622
- 'type' => 'text',
623
- 'label' => __( 'Redirect URL', 'ultimate-member' ),
624
- 'description' => __( 'Set full URL where do you want to redirect the user', 'ultimate-member' ),
625
- 'value' => ! empty( $data['_um_access_redirect_url'] ) ? $data['_um_access_redirect_url'] : '',
626
- 'conditional' => array( '_um_access_redirect', '=', '1' ),
627
- ),
628
- ), $data, 'edit' );
629
-
630
- UM()->admin_forms(
631
- array(
632
- 'class' => 'um-restrict-content um-third-column',
633
- 'prefix_id' => 'um_content_restriction',
634
- 'without_wrapper' => true,
635
- 'fields' => $fields,
636
- )
637
- )->render_form();
638
-
639
- wp_nonce_field( basename( __FILE__ ), 'um_admin_save_taxonomy_restrict_content_nonce' );
640
- }
641
-
642
-
643
- /**
644
- * @param $termID
645
- *
646
- * @return mixed
647
- */
648
- function um_category_access_fields_save( $termID ) {
649
-
650
- // validate nonce
651
- if ( ! isset( $_REQUEST['um_admin_save_taxonomy_restrict_content_nonce'] ) || ! wp_verify_nonce( $_REQUEST['um_admin_save_taxonomy_restrict_content_nonce'], basename( __FILE__ ) ) ) {
652
- return $termID;
653
- }
654
-
655
- // validate user
656
- $term = get_term( $termID );
657
- $taxonomy = get_taxonomy( $term->taxonomy );
658
-
659
- if ( ! current_user_can( $taxonomy->cap->edit_terms, $termID ) ) {
660
- return $termID;
661
- }
662
-
663
- if ( ! empty( $_REQUEST['um_content_restriction'] ) && is_array( $_REQUEST['um_content_restriction'] ) ) {
664
- $restriction_meta = UM()->admin()->sanitize_term_restriction_meta( $_REQUEST['um_content_restriction'] );
665
-
666
- update_term_meta( $termID, 'um_content_restriction', $restriction_meta );
667
- } else {
668
- delete_term_meta( $termID, 'um_content_restriction' );
669
- }
670
-
671
- return $termID;
672
- }
673
-
674
-
675
- /**
676
- * Load a directory metabox
677
- *
678
- * @param $object
679
- * @param $box
680
- */
681
- function load_metabox_directory( $object, $box ) {
682
- $box['id'] = str_replace( 'um-admin-form-', '', $box['id'] );
683
-
684
- preg_match('#\{.*?\}#s', $box['id'], $matches );
685
-
686
- if ( isset( $matches[0] ) ) {
687
- $path = $matches[0];
688
- $box['id'] = preg_replace('~(\\{[^}]+\\})~','', $box['id'] );
689
- } else {
690
- $path = um_path;
691
- }
692
-
693
- $path = str_replace('{','', $path );
694
- $path = str_replace('}','', $path );
695
-
696
-
697
- include_once $path . 'includes/admin/templates/directory/'. $box['id'] . '.php';
698
- if ( ! $this->directory_nonce_added ) {
699
- $this->directory_nonce_added = true;
700
- wp_nonce_field( basename( __FILE__ ), 'um_admin_save_metabox_directory_nonce' );
701
- }
702
- }
703
-
704
-
705
- /**
706
- * Load a role metabox
707
- *
708
- * @param $object
709
- * @param $box
710
- */
711
- function load_metabox_role( $object, $box ) {
712
- global $post;
713
-
714
- $box['id'] = str_replace( 'um-admin-form-', '', $box['id'] );
715
-
716
- if ( $box['id'] == 'builder' ) {
717
- UM()->builder()->form_id = get_the_ID();
718
- }
719
-
720
- preg_match('#\{.*?\}#s', $box['id'], $matches);
721
-
722
- if ( isset($matches[0]) ){
723
- $path = $matches[0];
724
- $box['id'] = preg_replace('~(\\{[^}]+\\})~','', $box['id'] );
725
- } else {
726
- $path = um_path;
727
- }
728
-
729
- $path = str_replace('{','', $path );
730
- $path = str_replace('}','', $path );
731
-
732
- include_once $path . 'includes/admin/templates/role/'. $box['id'] . '.php';
733
- //wp_nonce_field( basename( __FILE__ ), 'um_admin_save_metabox_role_nonce' );
734
- }
735
-
736
-
737
- /**
738
- * Load a form metabox
739
- *
740
- * @param $object
741
- * @param $box
742
- */
743
- function load_metabox_form( $object, $box ) {
744
- global $post;
745
-
746
- $box['id'] = str_replace( 'um-admin-form-','', $box['id'] );
747
-
748
- if ( $box['id'] == 'builder' ) {
749
- UM()->builder()->form_id = get_the_ID();
750
- }
751
-
752
- preg_match('#\{.*?\}#s', $box['id'], $matches);
753
-
754
- if ( isset( $matches[0] ) ) {
755
- $path = $matches[0];
756
- $box['id'] = preg_replace('~(\\{[^}]+\\})~','', $box['id'] );
757
- } else {
758
- $path = um_path;
759
- }
760
-
761
- $path = str_replace('{','', $path );
762
- $path = str_replace('}','', $path );
763
-
764
- include_once $path . 'includes/admin/templates/form/'. $box['id'] . '.php';
765
-
766
- if ( ! $this->form_nonce_added ) {
767
- $this->form_nonce_added = true;
768
- wp_nonce_field( basename( __FILE__ ), 'um_admin_save_metabox_form_nonce' );
769
- }
770
- }
771
-
772
-
773
- /**
774
- * Load admin custom metabox
775
- *
776
- * @param $object
777
- * @param $box
778
- */
779
- function load_metabox_custom( $object, $box ) {
780
- global $post;
781
-
782
- $box['id'] = str_replace('um-admin-custom-','', $box['id']);
783
-
784
- preg_match('#\{.*?\}#s', $box['id'], $matches);
785
-
786
- if ( isset($matches[0]) ){
787
- $path = $matches[0];
788
- $box['id'] = preg_replace('~(\\{[^}]+\\})~','', $box['id'] );
789
- } else {
790
- $path = um_path;
791
- }
792
-
793
- $path = str_replace('{','', $path );
794
- $path = str_replace('}','', $path );
795
-
796
- include_once $path . 'includes/admin/templates/'. $box['id'] . '.php';
797
- if ( ! $this->custom_nonce_added ) {
798
- $this->custom_nonce_added = true;
799
- wp_nonce_field( basename( __FILE__ ), 'um_admin_save_metabox_custom_nonce' );
800
- }
801
- }
802
-
803
-
804
- /**
805
- * Add directory metabox
806
- */
807
- function add_metabox_directory() {
808
- add_meta_box( 'um-admin-form-general', __( 'General Options', 'ultimate-member' ), array( &$this, 'load_metabox_directory' ), 'um_directory', 'normal', 'default' );
809
- add_meta_box( 'um-admin-form-sorting', __( 'Sorting', 'ultimate-member' ), array( &$this, 'load_metabox_directory' ), 'um_directory', 'normal', 'default' );
810
- add_meta_box( 'um-admin-form-profile', __( 'Profile Card', 'ultimate-member' ), array( &$this, 'load_metabox_directory' ), 'um_directory', 'normal', 'default' );
811
- add_meta_box( 'um-admin-form-search', __( 'Search Options', 'ultimate-member' ), array( &$this, 'load_metabox_directory' ), 'um_directory', 'normal', 'default' );
812
- add_meta_box( 'um-admin-form-pagination', __( 'Results &amp; Pagination', 'ultimate-member' ), array( &$this, 'load_metabox_directory' ), 'um_directory', 'normal', 'default' );
813
- add_meta_box( 'um-admin-form-shortcode', __( 'Shortcode', 'ultimate-member' ), array( &$this, 'load_metabox_directory' ), 'um_directory', 'side', 'default' );
814
- add_meta_box( 'um-admin-form-appearance', __( 'Styling: General', 'ultimate-member' ), array( &$this, 'load_metabox_directory'), 'um_directory', 'side', 'default' );
815
- }
816
-
817
-
818
- /**
819
- * Add role metabox
820
- */
821
- function add_metabox_role() {
822
- $callback = array( &$this, 'load_metabox_role' );
823
-
824
- $roles_metaboxes = array(
825
- array(
826
- 'id' => 'um-admin-form-admin-permissions',
827
- 'title' => __( 'Administrative Permissions', 'ultimate-member' ),
828
- 'callback' => $callback,
829
- 'screen' => 'um_role_meta',
830
- 'context' => 'normal',
831
- 'priority' => 'default'
832
- ),
833
- array(
834
- 'id' => 'um-admin-form-general',
835
- 'title' => __( 'General Permissions', 'ultimate-member' ),
836
- 'callback' => $callback,
837
- 'screen' => 'um_role_meta',
838
- 'context' => 'normal',
839
- 'priority' => 'default'
840
- ),
841
- array(
842
- 'id' => 'um-admin-form-profile',
843
- 'title' => __( 'Profile Access', 'ultimate-member' ),
844
- 'callback' => $callback,
845
- 'screen' => 'um_role_meta',
846
- 'context' => 'normal',
847
- 'priority' => 'default'
848
- )
849
- );
850
-
851
- if ( ! isset( $_GET['id'] ) || 'administrator' !== sanitize_key( $_GET['id'] ) ) {
852
- $roles_metaboxes[] = array(
853
- 'id' => 'um-admin-form-home',
854
- 'title' => __( 'Homepage Options', 'ultimate-member' ),
855
- 'callback' => $callback,
856
- 'screen' => 'um_role_meta',
857
- 'context' => 'normal',
858
- 'priority' => 'default'
859
- );
860
- }
861
-
862
- $roles_metaboxes = array_merge( $roles_metaboxes, array(
863
- array(
864
- 'id' => 'um-admin-form-register',
865
- 'title' => __( 'Registration Options', 'ultimate-member' ),
866
- 'callback' => $callback,
867
- 'screen' => 'um_role_meta',
868
- 'context' => 'normal',
869
- 'priority' => 'default'
870
- ),
871
- array(
872
- 'id' => 'um-admin-form-login',
873
- 'title' => __( 'Login Options', 'ultimate-member' ),
874
- 'callback' => $callback,
875
- 'screen' => 'um_role_meta',
876
- 'context' => 'normal',
877
- 'priority' => 'default'
878
- ),
879
- array(
880
- 'id' => 'um-admin-form-logout',
881
- 'title' => __( 'Logout Options', 'ultimate-member' ),
882
- 'callback' => $callback,
883
- 'screen' => 'um_role_meta',
884
- 'context' => 'normal',
885
- 'priority' => 'default'
886
- ),
887
- array(
888
- 'id' => 'um-admin-form-delete',
889
- 'title' => __( 'Delete Options', 'ultimate-member' ),
890
- 'callback' => $callback,
891
- 'screen' => 'um_role_meta',
892
- 'context' => 'normal',
893
- 'priority' => 'default'
894
- ),
895
- array(
896
- 'id' => 'um-admin-form-publish',
897
- 'title' => __( 'Publish', 'ultimate-member' ),
898
- 'callback' => $callback,
899
- 'screen' => 'um_role_meta',
900
- 'context' => 'side',
901
- 'priority' => 'default'
902
- )
903
- ) );
904
-
905
- /**
906
- * UM hook
907
- *
908
- * @type filter
909
- * @title um_admin_role_metaboxes
910
- * @description Extend metaboxes at Add/Edit User Role
911
- * @input_vars
912
- * [{"var":"$roles_metaboxes","type":"array","desc":"Metaboxes at Add/Edit UM Role"}]
913
- * @change_log
914
- * ["Since: 2.0"]
915
- * @usage add_filter( 'um_admin_role_metaboxes', 'function_name', 10, 1 );
916
- * @example
917
- * <?php
918
- * add_filter( 'um_admin_role_metaboxes', 'my_admin_role_metaboxes', 10, 1 );
919
- * function my_admin_role_metaboxes( $roles_metaboxes ) {
920
- * // your code here
921
- * $roles_metaboxes[] = array(
922
- * 'id' => 'um-admin-form-your-custom',
923
- * 'title' => __( 'My Roles Metabox', 'ultimate-member' ),
924
- * 'callback' => 'my-metabox-callback',
925
- * 'screen' => 'um_role_meta',
926
- * 'context' => 'side',
927
- * 'priority' => 'default'
928
- * );
929
- *
930
- * return $roles_metaboxes;
931
- * }
932
- * ?>
933
- */
934
- $roles_metaboxes = apply_filters( 'um_admin_role_metaboxes', $roles_metaboxes );
935
-
936
- $wp_caps_metabox = false;
937
- if ( ! empty( $_GET['id'] ) ) {
938
- $data = get_option( 'um_role_' . sanitize_key( $_GET['id'] ) . '_meta' );
939
- if ( ! empty( $data['_um_is_custom'] ) ) {
940
- $wp_caps_metabox = true;
941
- }
942
- }
943
- if ( 'add' == sanitize_key( $_GET['tab'] ) || $wp_caps_metabox ) {
944
- $roles_metaboxes[] = array(
945
- 'id' => 'um-admin-form-wp-capabilities',
946
- 'title' => __( 'WP Capabilities', 'ultimate-member' ),
947
- 'callback' => $callback,
948
- 'screen' => 'um_role_meta',
949
- 'context' => 'normal',
950
- 'priority' => 'default'
951
- );
952
- }
953
-
954
-
955
- foreach ( $roles_metaboxes as $metabox ) {
956
- add_meta_box(
957
- $metabox['id'],
958
- $metabox['title'],
959
- $metabox['callback'],
960
- $metabox['screen'],
961
- $metabox['context'],
962
- $metabox['priority']
963
- );
964
- }
965
- }
966
-
967
-
968
- /**
969
- * Add form metabox
970
- */
971
- function add_metabox_form() {
972
-
973
- add_meta_box( 'um-admin-form-mode', __( 'Select Form Type', 'ultimate-member' ), array( &$this, 'load_metabox_form' ), 'um_form', 'normal', 'default' );
974
- add_meta_box( 'um-admin-form-builder', __( 'Form Builder', 'ultimate-member' ), array( &$this, 'load_metabox_form' ), 'um_form', 'normal', 'default' );
975
- add_meta_box( 'um-admin-form-shortcode', __( 'Shortcode', 'ultimate-member' ), array( &$this, 'load_metabox_form' ), 'um_form', 'side', 'default' );
976
-
977
- add_meta_box( 'um-admin-form-register_customize', __( 'Customize this form', 'ultimate-member' ), array( &$this, 'load_metabox_form' ), 'um_form', 'side', 'default' );
978
-
979
- /**
980
- * UM hook
981
- *
982
- * @type action
983
- * @title um_admin_custom_register_metaboxes
984
- * @description Add custom metaboxes for register form
985
- * @change_log
986
- * ["Since: 2.0"]
987
- * @usage add_action( 'um_admin_custom_register_metaboxes', 'function_name', 10 );
988
- * @example
989
- * <?php
990
- * add_action( 'um_admin_custom_register_metaboxes', 'my_admin_custom_register_metaboxes', 10 );
991
- * function my_admin_custom_register_metaboxes() {
992
- * // your code here
993
- * }
994
- * ?>
995
- */
996
- do_action( 'um_admin_custom_register_metaboxes' );
997
-
998
- add_meta_box( 'um-admin-form-profile_customize', __( 'Customize this form', 'ultimate-member' ), array( &$this, 'load_metabox_form' ), 'um_form', 'side', 'default' );
999
- add_meta_box( 'um-admin-form-profile_settings', __( 'User Meta', 'ultimate-member' ), array( &$this, 'load_metabox_form' ), 'um_form', 'side', 'default' );
1000
-
1001
- /**
1002
- * UM hook
1003
- *
1004
- * @type action
1005
- * @title um_admin_custom_profile_metaboxes
1006
- * @description Add custom metaboxes for profile form
1007
- * @change_log
1008
- * ["Since: 2.0"]
1009
- * @usage add_action( 'um_admin_custom_profile_metaboxes', 'function_name', 10 );
1010
- * @example
1011
- * <?php
1012
- * add_action( 'um_admin_custom_profile_metaboxes', 'my_admin_custom_profile_metaboxes', 10 );
1013
- * function my_admin_custom_profile_metaboxes() {
1014
- * // your code here
1015
- * }
1016
- * ?>
1017
- */
1018
- do_action( 'um_admin_custom_profile_metaboxes' );
1019
-
1020
- add_meta_box( 'um-admin-form-login_customize', __( 'Customize this form', 'ultimate-member' ), array( &$this, 'load_metabox_form' ), 'um_form', 'side', 'default' );
1021
- add_meta_box( 'um-admin-form-login_settings', __( 'Options', 'ultimate-member' ), array( &$this, 'load_metabox_form' ), 'um_form', 'side', 'default' );
1022
-
1023
- /**
1024
- * UM hook
1025
- *
1026
- * @type action
1027
- * @title um_admin_custom_login_metaboxes
1028
- * @description Add custom metaboxes for login form
1029
- * @change_log
1030
- * ["Since: 2.0"]
1031
- * @usage add_action( 'um_admin_custom_login_metaboxes', 'function_name', 10 );
1032
- * @example
1033
- * <?php
1034
- * add_action( 'um_admin_custom_login_metaboxes', 'my_admin_custom_login_metaboxes', 10 );
1035
- * function my_admin_custom_login_metaboxes() {
1036
- * // your code here
1037
- * }
1038
- * ?>
1039
- */
1040
- do_action( 'um_admin_custom_login_metaboxes' );
1041
- }
1042
-
1043
-
1044
- /**
1045
- * Save directory metabox
1046
- *
1047
- * @param $post_id
1048
- * @param $post
1049
- */
1050
- function save_metabox_directory( $post_id, $post ) {
1051
- global $wpdb;
1052
-
1053
- // validate nonce
1054
- if ( ! isset( $_POST['um_admin_save_metabox_directory_nonce'] ) ||
1055
- ! wp_verify_nonce( $_POST['um_admin_save_metabox_directory_nonce'], basename( __FILE__ ) ) ) {
1056
- return;
1057
- }
1058
-
1059
- // validate post type
1060
- if ( $post->post_type != 'um_directory' ) {
1061
- return;
1062
- }
1063
-
1064
- // validate user
1065
- $post_type = get_post_type_object( $post->post_type );
1066
- if ( ! current_user_can( $post_type->cap->edit_post, $post_id ) ) {
1067
- return;
1068
- }
1069
-
1070
- $where = array( 'ID' => $post_id );
1071
-
1072
- if ( empty( $_POST['post_title'] ) ) {
1073
- $_POST['post_title'] = sprintf( __( 'Directory #%s', 'ultimate-member' ), $post_id );
1074
- }
1075
-
1076
- $wpdb->update( $wpdb->posts, array( 'post_title' => sanitize_text_field( $_POST['post_title'] ) ), $where );
1077
-
1078
- do_action( 'um_before_member_directory_save', $post_id );
1079
-
1080
- // save
1081
- delete_post_meta( $post_id, '_um_roles' );
1082
- delete_post_meta( $post_id, '_um_tagline_fields' );
1083
- delete_post_meta( $post_id, '_um_reveal_fields' );
1084
- delete_post_meta( $post_id, '_um_search_fields' );
1085
- delete_post_meta( $post_id, '_um_roles_can_search' );
1086
- delete_post_meta( $post_id, '_um_roles_can_filter' );
1087
- delete_post_meta( $post_id, '_um_show_these_users' );
1088
- delete_post_meta( $post_id, '_um_exclude_these_users' );
1089
-
1090
- delete_post_meta( $post_id, '_um_search_filters' );
1091
- delete_post_meta( $post_id, '_um_search_filters_gmt' );
1092
-
1093
- delete_post_meta( $post_id, '_um_sorting_fields' );
1094
-
1095
- //save metadata
1096
- $metadata = UM()->admin()->sanitize_member_directory_meta( $_POST['um_metadata'] );
1097
- foreach ( $metadata as $k => $v ) {
1098
-
1099
- if ( $k == '_um_show_these_users' && trim( $v ) ) {
1100
- $v = preg_split( '/[\r\n]+/', $v, -1, PREG_SPLIT_NO_EMPTY );
1101
- }
1102
-
1103
- if ( $k == '_um_exclude_these_users' && trim( $v ) ) {
1104
- $v = preg_split( '/[\r\n]+/', $v, -1, PREG_SPLIT_NO_EMPTY );
1105
- }
1106
-
1107
- if ( strstr( $k, '_um_' ) ) {
1108
-
1109
- if ( $k === '_um_is_default' ) {
1110
-
1111
- $mode = UM()->query()->get_attr( 'mode', $post_id );
1112
-
1113
- if ( ! empty( $mode ) ) {
1114
-
1115
- $posts = $wpdb->get_col(
1116
- "SELECT post_id
1117
- FROM {$wpdb->postmeta}
1118
- WHERE meta_key = '_um_mode' AND
1119
- meta_value = 'directory'"
1120
- );
1121
-
1122
- foreach ( $posts as $p_id ) {
1123
- delete_post_meta( $p_id, '_um_is_default' );
1124
- }
1125
-
1126
- }
1127
-
1128
- }
1129
-
1130
- $v = apply_filters( 'um_member_directory_meta_value_before_save', $v, $k, $post_id );
1131
-
1132
- update_post_meta( $post_id, $k, $v );
1133
-
1134
- }
1135
- }
1136
-
1137
- update_post_meta( $post_id, '_um_search_filters_gmt', (int) $_POST['um-gmt-offset'] );
1138
- }
1139
-
1140
-
1141
- /**
1142
- * Save form metabox
1143
- *
1144
- * @param $post_id
1145
- * @param $post
1146
- */
1147
- function save_metabox_form( $post_id, $post ) {
1148
- global $wpdb;
1149
-
1150
- // validate nonce
1151
- if ( ! isset( $_POST['um_admin_save_metabox_form_nonce'] ) ||
1152
- ! wp_verify_nonce( $_POST['um_admin_save_metabox_form_nonce'], basename( __FILE__ ) ) ) {
1153
- return;
1154
- }
1155
-
1156
- // validate post type
1157
- if ( $post->post_type != 'um_form' ) {
1158
- return;
1159
- }
1160
-
1161
- // validate user
1162
- $post_type = get_post_type_object( $post->post_type );
1163
- if ( ! current_user_can( $post_type->cap->edit_post, $post_id ) ) {
1164
- return;
1165
- }
1166
-
1167
- $where = array( 'ID' => $post_id );
1168
- if ( empty( $_POST['post_title'] ) ) {
1169
- $_POST['post_title'] = sprintf( __( 'Form #%s', 'ultimate-member' ), $post_id );
1170
- }
1171
- $wpdb->update( $wpdb->posts, array( 'post_title' => sanitize_text_field( $_POST['post_title'] ) ), $where );
1172
-
1173
- // save
1174
- delete_post_meta( $post_id, '_um_profile_metafields' );
1175
-
1176
- $form_meta = UM()->admin()->sanitize_form_meta( $_POST['form'] );
1177
-
1178
- foreach ( $form_meta as $k => $v ) {
1179
- if ( strstr( $k, '_um_' ) ) {
1180
- if ( $k === '_um_is_default' ) {
1181
- $mode = UM()->query()->get_attr( 'mode', $post_id );
1182
- if ( ! empty( $mode ) ) {
1183
- $posts = $wpdb->get_col( $wpdb->prepare(
1184
- "SELECT post_id
1185
- FROM {$wpdb->postmeta}
1186
- WHERE meta_key = '_um_mode' AND
1187
- meta_value = %s",
1188
- $mode
1189
- ) );
1190
- foreach ( $posts as $p_id ) {
1191
- delete_post_meta( $p_id, '_um_is_default' );
1192
- }
1193
- }
1194
- }
1195
-
1196
- update_post_meta( $post_id, $k, $v );
1197
- }
1198
- }
1199
-
1200
- }
1201
-
1202
-
1203
- /**
1204
- * Load modal content
1205
- */
1206
- function load_modal_content() {
1207
- $screen = get_current_screen();
1208
-
1209
- if ( isset( $screen->id ) && strstr( $screen->id, 'um_form' ) ) {
1210
- foreach ( glob( um_path . 'includes/admin/templates/modal/forms/*.php' ) as $modal_content ) {
1211
- include_once $modal_content;
1212
- }
1213
- }
1214
-
1215
- if ( $this->init_icon ) {
1216
- include_once um_path . 'includes/admin/templates/modal/forms/fonticons.php';
1217
- }
1218
-
1219
- if ( $screen->id == 'users' ) {
1220
- include_once um_path . 'includes/admin/templates/modal/dynamic_registration_preview.php';
1221
- }
1222
-
1223
- // needed on forms only
1224
- if ( ! isset( $this->is_loaded ) && isset( $screen->id ) && strstr( $screen->id, 'um_form' ) ) {
1225
- $settings['textarea_rows'] = 8;
1226
-
1227
- echo '<div class="um-hidden-editor-edit" style="display:none;">';
1228
- wp_editor( '', 'um_editor_edit', $settings );
1229
- echo '</div>';
1230
-
1231
- echo '<div class="um-hidden-editor-new" style="display:none;">';
1232
- wp_editor( '', 'um_editor_new', $settings );
1233
- echo '</div>';
1234
-
1235
- $this->is_loaded = true;
1236
- }
1237
- }
1238
-
1239
-
1240
- /**
1241
- * Show field input for edit at modal field
1242
- *
1243
- * @param $attribute
1244
- * @param null $form_id
1245
- * @param array $field_args
1246
- */
1247
- function field_input( $attribute, $form_id = null, $field_args = array() ) {
1248
-
1249
- if ( $this->in_edit == true ) { // we're editing a field
1250
- $real_attr = substr( $attribute, 1 );
1251
- $this->edit_mode_value = isset( $this->edit_array[ $real_attr ] ) ? $this->edit_array[ $real_attr ] : null;
1252
- }
1253
-
1254
- switch ( $attribute ) {
1255
-
1256
- default:
1257
-
1258
- /**
1259
- * UM hook
1260
- *
1261
- * @type action
1262
- * @title um_admin_field_edit_hook{$attribute}
1263
- * @description Integration for 3-d party fields at wp-admin
1264
- * @input_vars
1265
- * [{"var":"$edit_mode_value","type":"string","desc":"Post ID"}]
1266
- * @change_log
1267
- * ["Since: 2.0"]
1268
- * @usage add_action( 'um_admin_field_edit_hook{$attribute}', 'function_name', 10, 1 );
1269
- * @example
1270
- * <?php
1271
- * add_action( 'um_admin_field_edit_hook{$attribute}', 'my_admin_field_edit', 10, 1 );
1272
- * function my_admin_field_edit( $edit_mode_value ) {
1273
- * // your code here
1274
- * }
1275
- * ?>
1276
- */
1277
- do_action( "um_admin_field_edit_hook{$attribute}", $this->edit_mode_value, $form_id, $this->edit_array );
1278
-
1279
- break;
1280
-
1281
- case '_visibility':
1282
- ?>
1283
-
1284
- <p><label for="_visibility"><?php _e( 'Visibility', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Select where this field should appear. This option should only be changed on the profile form and allows you to show a field in one mode only (edit or view) or in both modes.','ultimate-member' ) ); ?></label>
1285
- <select name="_visibility" id="_visibility" style="width: 100%">
1286
- <option value="all" <?php selected( 'all', $this->edit_mode_value ); ?>><?php _e( 'View everywhere', 'ultimate-member' ) ?></option>
1287
- <option value="edit" <?php selected( 'edit', $this->edit_mode_value ); ?>><?php _e( 'Edit mode only', 'ultimate-member' ) ?></option>
1288
- <option value="view" <?php selected( 'view', $this->edit_mode_value ); ?>><?php _e( 'View mode only', 'ultimate-member' ) ?></option>
1289
- </select>
1290
- </p>
1291
-
1292
- <?php
1293
- break;
1294
-
1295
- case '_conditional_action':
1296
- case '_conditional_action1':
1297
- case '_conditional_action2':
1298
- case '_conditional_action3':
1299
- case '_conditional_action4':
1300
- ?>
1301
-
1302
- <p>
1303
- <select name="<?php echo esc_attr( $attribute ); ?>" id="<?php echo esc_attr( $attribute ); ?>" style="width: 90px">
1304
-
1305
- <option></option>
1306
-
1307
- <?php $actions = array( 'show', 'hide' );
1308
- foreach ( $actions as $action ) { ?>
1309
-
1310
- <option value="<?php echo esc_attr( $action ); ?>" <?php selected( $action, $this->edit_mode_value ); ?>><?php echo $action; ?></option>
1311
-
1312
- <?php } ?>
1313
-
1314
- </select>
1315
-
1316
- &nbsp;&nbsp;<?php _e( 'If' ); ?>
1317
- </p>
1318
-
1319
- <?php
1320
- break;
1321
-
1322
- case '_conditional_field':
1323
- case '_conditional_field1':
1324
- case '_conditional_field2':
1325
- case '_conditional_field3':
1326
- case '_conditional_field4':
1327
- ?>
1328
-
1329
- <p>
1330
- <select name="<?php echo esc_attr( $attribute ); ?>" id="<?php echo esc_attr( $attribute ); ?>" style="width: 150px">
1331
-
1332
- <option></option>
1333
-
1334
- <?php $fields = UM()->query()->get_attr( 'custom_fields', $form_id );
1335
-
1336
- foreach ( $fields as $key => $array ) {
1337
- if ( isset( $array['title'] ) &&
1338
- ( ! isset( $this->edit_array['metakey'] ) || $key != $this->edit_array['metakey'] ) ) { ?>
1339
-
1340
- <option value="<?php echo esc_attr( $key ) ?>" <?php selected( $key, $this->edit_mode_value ) ?>><?php echo $array['title'] ?></option>
1341
-
1342
- <?php }
1343
- } ?>
1344
-
1345
- </select>
1346
- </p>
1347
-
1348
- <?php
1349
- break;
1350
-
1351
- case '_conditional_operator':
1352
- case '_conditional_operator1':
1353
- case '_conditional_operator2':
1354
- case '_conditional_operator3':
1355
- case '_conditional_operator4':
1356
- ?>
1357
-
1358
- <p>
1359
- <select name="<?php echo esc_attr( $attribute ); ?>" id="<?php echo esc_attr( $attribute ); ?>" style="width: 150px">
1360
-
1361
- <option></option>
1362
-
1363
- <?php $operators = array(
1364
- 'empty',
1365
- 'not empty',
1366
- 'equals to',
1367
- 'not equals',
1368
- 'greater than',
1369
- 'less than',
1370
- 'contains'
1371
- );
1372
-
1373
- foreach ( $operators as $operator ) { ?>
1374
-
1375
- <option value="<?php echo esc_attr( $operator ); ?>" <?php selected( $operator, $this->edit_mode_value ); ?>><?php echo $operator; ?></option>
1376
-
1377
- <?php } ?>
1378
-
1379
- </select>
1380
- </p>
1381
-
1382
- <?php
1383
- break;
1384
-
1385
- case '_conditional_value':
1386
- case '_conditional_value1':
1387
- case '_conditional_value2':
1388
- case '_conditional_value3':
1389
- case '_conditional_value4':
1390
- ?>
1391
-
1392
- <p>
1393
- <input type="text" name="<?php echo esc_attr( $attribute ); ?>" id="<?php echo esc_attr( $attribute ); ?>" value="<?php echo isset( $this->edit_mode_value ) ? $this->edit_mode_value : ''; ?>" placeholder="<?php esc_attr_e( 'Value', 'ultimate-member' ); ?>" style="width: 150px!important;position: relative;top: -1px;" />
1394
- </p>
1395
-
1396
- <?php
1397
- break;
1398
-
1399
- case '_validate':
1400
- ?>
1401
-
1402
- <p><label for="_validate"><?php _e( 'Validate', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Does this field require a special validation', 'ultimate-member' ) ); ?></label>
1403
- <select name="_validate" id="_validate" data-placeholder="<?php esc_attr_e( 'Select a validation type...', 'ultimate-member' ) ?>" class="um-adm-conditional" data-cond1="custom" data-cond1-show="_custom_validate" style="width: 100%">
1404
-
1405
- <option value="" <?php selected( '', $this->edit_mode_value ); ?>></option>
1406
-
1407
- <?php foreach( UM()->builtin()->validation_types() as $key => $name ) { ?>
1408
- <?php
1409
- /**
1410
- * UM hook
1411
- *
1412
- * @type filter
1413
- * @title um_builtin_validation_types_continue_loop
1414
- * @description Builtin Validation Types
1415
- * @input_vars
1416
- * [{"var":"$continue","type":"bool","desc":"Validate?"},
1417
- * {"var":"$key","type":"string","desc":"Field Key"},
1418
- * {"var":"$form_id","type":"int","desc":"Form ID"},
1419
- * {"var":"$field_args","type":"array","desc":"Field Settings"}]
1420
- * @change_log
1421
- * ["Since: 2.0"]
1422
- * @usage add_filter( 'um_builtin_validation_types_continue_loop', 'function_name', 10, 4 );
1423
- * @example
1424
- * <?php
1425
- * add_filter( 'um_builtin_validation_types_continue_loop', 'my_builtin_validation_types', 10, 4 );
1426
- * function my_builtin_validation_types( $continue, $key, $form_id, $field_args ) {
1427
- * // your code here
1428
- * return $continue;
1429
- * }
1430
- * ?>
1431
- */
1432
- $continue = apply_filters( "um_builtin_validation_types_continue_loop", true, $key, $form_id, $field_args );
1433
- if ( $continue ) { ?>
1434
- <option value="<?php echo esc_attr( $key ); ?>" <?php selected( $key, $this->edit_mode_value ); ?>><?php echo $name; ?></option>
1435
- <?php } ?>
1436
- <?php } ?>
1437
-
1438
- </select>
1439
- </p>
1440
-
1441
- <?php
1442
- break;
1443
-
1444
- case '_custom_validate':
1445
- ?>
1446
-
1447
- <p class="_custom_validate"><label for="_custom_validate"><?php _e( 'Custom Action', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'If you want to apply your custom validation, you can use action hooks to add custom validation. Please refer to documentation for further details.', 'ultimate-member' ) ); ?></label>
1448
- <input type="text" name="_custom_validate" id="_custom_validate" value="<?php echo ( $this->edit_mode_value ) ? $this->edit_mode_value : ''; ?>" />
1449
- </p>
1450
-
1451
- <?php
1452
- break;
1453
-
1454
- case '_icon':
1455
-
1456
- if ( $this->set_field_type == 'row' ) {
1457
- $back = 'UM_edit_row';
1458
-
1459
- ?>
1460
-
1461
- <p class="_heading_text"><label for="_icon"><?php _e( 'Icon', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Select an icon to appear in the field. Leave blank if you do not want an icon to show in the field.', 'ultimate-member' ) ); ?></label>
1462
-
1463
- <a href="javascript:void(0);" class="button" data-modal="UM_fonticons" data-modal-size="normal" data-dynamic-content="um_admin_fonticon_selector" data-arg1="" data-arg2="" data-back="<?php echo esc_attr( $back ); ?>"><?php _e( 'Choose Icon', 'ultimate-member' ) ?></a>
1464
-
1465
- <span class="um-admin-icon-value"><?php if ( $this->edit_mode_value ) { ?><i class="<?php echo $this->edit_mode_value; ?>"></i><?php } else { ?><?php _e( 'No Icon', 'ultimate-member' ) ?><?php } ?></span>
1466
-
1467
- <input type="hidden" name="_icon" id="_icon" value="<?php echo (isset( $this->edit_mode_value ) ) ? $this->edit_mode_value : ''; ?>" />
1468
-
1469
- <?php if ( $this->edit_mode_value ) { ?>
1470
- <span class="um-admin-icon-clear show"><i class="um-icon-android-cancel"></i></span>
1471
- <?php } else { ?>
1472
- <span class="um-admin-icon-clear"><i class="um-icon-android-cancel"></i></span>
1473
- <?php } ?>
1474
-
1475
- </p>
1476
-
1477
- <?php } else {
1478
-
1479
- if ( $this->in_edit ) {
1480
- $back = 'UM_edit_field';
1481
- } else {
1482
- $back = 'UM_add_field';
1483
- }
1484
-
1485
- ?>
1486
-
1487
- <div class="um-admin-tri">
1488
-
1489
- <p><label for="_icon"><?php _e( 'Icon', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Select an icon to appear in the field. Leave blank if you do not want an icon to show in the field.', 'ultimate-member' ) ); ?></label>
1490
-
1491
- <a href="javascript:void(0);" class="button" data-modal="UM_fonticons" data-modal-size="normal" data-dynamic-content="um_admin_fonticon_selector" data-arg1="" data-arg2="" data-back="<?php echo esc_attr( $back ); ?>"><?php _e( 'Choose Icon', 'ultimate-member' ) ?></a>
1492
-
1493
- <span class="um-admin-icon-value"><?php if ( $this->edit_mode_value ) { ?><i class="<?php echo $this->edit_mode_value; ?>"></i><?php } else { ?><?php _e( 'No Icon', 'ultimate-member' ) ?><?php } ?></span>
1494
-
1495
- <input type="hidden" name="_icon" id="_icon" value="<?php echo (isset( $this->edit_mode_value ) ) ? $this->edit_mode_value : ''; ?>" />
1496
-
1497
- <?php if ( $this->edit_mode_value ) { ?>
1498
- <span class="um-admin-icon-clear show"><i class="um-icon-android-cancel"></i></span>
1499
- <?php } else { ?>
1500
- <span class="um-admin-icon-clear"><i class="um-icon-android-cancel"></i></span>
1501
- <?php } ?>
1502
-
1503
- </p>
1504
-
1505
- </div>
1506
-
1507
- <?php
1508
-
1509
- }
1510
-
1511
- break;
1512
-
1513
- case '_css_class':
1514
- ?>
1515
-
1516
- <p><label for="_css_class"><?php _e( 'CSS Class', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Specify a custom CSS class to be applied to this element', 'ultimate-member' ) ); ?></label>
1517
- <input type="text" name="_css_class" id="_css_class" value="<?php echo ( $this->edit_mode_value ) ? $this->edit_mode_value : ''; ?>" />
1518
- </p>
1519
-
1520
- <?php
1521
- break;
1522
-
1523
- case '_width':
1524
- ?>
1525
-
1526
- <p><label for="_width"><?php _e( 'Thickness (in pixels)', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'This is the width in pixels, e.g. 4 or 2, etc', 'ultimate-member' ) ); ?></label>
1527
- <input type="text" name="_width" id="_width" value="<?php echo ( $this->edit_mode_value ) ? $this->edit_mode_value : 4; ?>" />
1528
- </p>
1529
-
1530
- <?php
1531
- break;
1532
-
1533
- case '_divider_text':
1534
- ?>
1535
-
1536
- <p><label for="_divider_text"><?php _e( 'Optional Text', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Optional text to include with the divider', 'ultimate-member' ) ); ?></label>
1537
- <input type="text" name="_divider_text" id="_divider_text" value="<?php echo ( $this->edit_mode_value ) ? $this->edit_mode_value : ''; ?>" />
1538
- </p>
1539
-
1540
- <?php
1541
- break;
1542
-
1543
- case '_padding':
1544
- ?>
1545
-
1546
- <p><label for="_padding"><?php _e( 'Padding', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Set padding for this section', 'ultimate-member' ) ); ?></label>
1547
- <input type="text" name="_padding" id="_padding" value="<?php echo ( $this->edit_mode_value ) ? $this->edit_mode_value : '0px 0px 0px 0px'; ?>" />
1548
- </p>
1549
-
1550
- <?php
1551
- break;
1552
-
1553
- case '_margin':
1554
- ?>
1555
-
1556
- <p><label for="_margin"><?php _e( 'Margin', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Set margin for this section', 'ultimate-member' ) ); ?></label>
1557
- <input type="text" name="_margin" id="_margin" value="<?php echo ( $this->edit_mode_value ) ? $this->edit_mode_value : '0px 0px 30px 0px'; ?>" />
1558
- </p>
1559
-
1560
- <?php
1561
- break;
1562
-
1563
- case '_border':
1564
- ?>
1565
-
1566
- <p><label for="_border"><?php _e( 'Border', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Set border for this section', 'ultimate-member' ) ); ?></label>
1567
- <input type="text" name="_border" id="_border" value="<?php echo ( $this->edit_mode_value ) ? $this->edit_mode_value : '0px 0px 0px 0px'; ?>" />
1568
- </p>
1569
-
1570
- <?php
1571
- break;
1572
-
1573
- case '_borderstyle':
1574
- ?>
1575
-
1576
- <p><label for="_borderstyle"><?php _e( 'Style', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Choose the border style', 'ultimate-member' ) ); ?></label>
1577
- <select name="_borderstyle" id="_borderstyle" style="width: 100%">
1578
- <option value="solid" <?php selected( 'solid', $this->edit_mode_value ); ?>><?php _e( 'Solid', 'ultimate-member' ) ?></option>
1579
- <option value="dotted" <?php selected( 'dotted', $this->edit_mode_value ); ?>><?php _e( 'Dotted', 'ultimate-member' ) ?></option>
1580
- <option value="dashed" <?php selected( 'dashed', $this->edit_mode_value ); ?>><?php _e( 'Dashed', 'ultimate-member' ) ?></option>
1581
- <option value="double" <?php selected( 'double', $this->edit_mode_value ); ?>><?php _e( 'Double', 'ultimate-member' ) ?></option>
1582
- </select>
1583
- </p>
1584
-
1585
- <?php
1586
- break;
1587
-
1588
- case '_borderradius':
1589
- ?>
1590
-
1591
- <p><label for="_borderradius"><?php _e( 'Border Radius', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Rounded corners can be applied by setting a pixels value here. e.g. 5px', 'ultimate-member' ) ); ?></label>
1592
- <input type="text" name="_borderradius" id="_borderradius" value="<?php echo ( $this->edit_mode_value ) ? $this->edit_mode_value : '0px'; ?>" />
1593
- </p>
1594
-
1595
- <?php
1596
- break;
1597
-
1598
- case '_bordercolor':
1599
- ?>
1600
-
1601
- <p><label for="_bordercolor"><?php _e( 'Border Color', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Give a color to this border', 'ultimate-member' ) ); ?></label>
1602
- <input type="text" name="_bordercolor" id="_bordercolor" class="um-admin-colorpicker" data-default-color="" value="<?php echo ( $this->edit_mode_value ) ? $this->edit_mode_value : ''; ?>" />
1603
- </p>
1604
-
1605
- <?php
1606
- break;
1607
-
1608
- case '_heading':
1609
- ?>
1610
-
1611
- <p><label for="_heading"><?php _e( 'Enable Row Heading', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Whether to enable a heading for this row', 'ultimate-member' ) ); ?></label>
1612
- <input type="checkbox" name="_heading" id="_heading" value="1" <?php checked( isset( $this->edit_mode_value ) ? $this->edit_mode_value : 0 ) ?> class="um-adm-conditional" data-cond1="1" data-cond1-show="_heading_text" data-cond1-hide="xxx" />
1613
- </p>
1614
-
1615
- <?php
1616
- break;
1617
-
1618
- case '_heading_text':
1619
- ?>
1620
-
1621
- <p class="_heading_text"><label for="_heading_text"><?php _e( 'Heading Text', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Enter the row heading text here', 'ultimate-member' ) ); ?></label>
1622
- <input type="text" name="_heading_text" id="_heading_text" value="<?php echo ( $this->edit_mode_value ) ? $this->edit_mode_value : ''; ?>" />
1623
- </p>
1624
-
1625
- <?php
1626
- break;
1627
-
1628
- case '_background':
1629
- ?>
1630
-
1631
- <p><label for="_background"><?php _e( 'Background Color', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'This will be the background of entire section', 'ultimate-member' ) ); ?></label>
1632
- <input type="text" name="_background" id="_background" class="um-admin-colorpicker" data-default-color="" value="<?php echo ( $this->edit_mode_value ) ? $this->edit_mode_value : ''; ?>" />
1633
- </p>
1634
-
1635
- <?php
1636
- break;
1637
-
1638
- case '_heading_background_color':
1639
- ?>
1640
-
1641
- <p class="_heading_text"><label for="_heading_background_color"><?php _e( 'Heading Background Color', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'This will be the background of the heading section', 'ultimate-member' ) ); ?></label>
1642
- <input type="text" name="_heading_background_color" id="_heading_background_color" class="um-admin-colorpicker" data-default-color="" value="<?php echo ( $this->edit_mode_value ) ? $this->edit_mode_value : ''; ?>" />
1643
- </p>
1644
-
1645
- <?php
1646
- break;
1647
-
1648
- case '_heading_text_color':
1649
- ?>
1650
-
1651
- <p class="_heading_text"><label for="_heading_text_color"><?php _e( 'Heading Text Color', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'This will be the text color of heading part only', 'ultimate-member' ) ); ?></label>
1652
- <input type="text" name="_heading_text_color" id="_heading_text_color" class="um-admin-colorpicker" data-default-color="" value="<?php echo ( $this->edit_mode_value ) ? $this->edit_mode_value : ''; ?>" />
1653
- </p>
1654
-
1655
- <?php
1656
- break;
1657
-
1658
- case '_text_color':
1659
- ?>
1660
-
1661
- <p><label for="_text_color"><?php _e( 'Text Color', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'This will be the text color of entire section', 'ultimate-member' ) ); ?></label>
1662
- <input type="text" name="_text_color" id="_text_color" class="um-admin-colorpicker" data-default-color="" value="<?php echo ( $this->edit_mode_value ) ? $this->edit_mode_value : ''; ?>" />
1663
- </p>
1664
-
1665
- <?php
1666
- break;
1667
-
1668
- case '_icon_color':
1669
- ?>
1670
-
1671
- <p class="_heading_text"><label for="_icon_color"><?php _e( 'Icon Color', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'This will be the color of selected icon. By default It will be the same color as heading text color', 'ultimate-member' ) ); ?></label>
1672
- <input type="text" name="_icon_color" id="_icon_color" class="um-admin-colorpicker" data-default-color="" value="<?php echo ( $this->edit_mode_value ) ? $this->edit_mode_value : ''; ?>" />
1673
- </p>
1674
-
1675
- <?php
1676
- break;
1677
-
1678
- case '_color':
1679
- ?>
1680
-
1681
- <p><label for="_color"><?php _e( 'Color', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Select a color for this divider', 'ultimate-member' ) ); ?></label>
1682
- <input type="text" name="_color" id="_color" class="um-admin-colorpicker" data-default-color="#eeeeee" value="<?php echo ( $this->edit_mode_value ) ? $this->edit_mode_value : '#eeeeee'; ?>" />
1683
- </p>
1684
-
1685
- <?php
1686
- break;
1687
-
1688
- case '_url_text':
1689
- ?>
1690
-
1691
- <p><label for="_url_text"><?php _e( 'URL Alt Text', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Entering custom text here will replace the url with a text link', 'ultimate-member' ) ); ?></label>
1692
- <input type="text" name="_url_text" id="_url_text" value="<?php echo ( $this->edit_mode_value ) ? $this->edit_mode_value : ''; ?>" />
1693
- </p>
1694
-
1695
- <?php
1696
- break;
1697
-
1698
- case '_url_target':
1699
- ?>
1700
-
1701
- <p><label for="_url_target"><?php _e( 'Link Target', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Choose whether to open this link in same window or in a new window', 'ultimate-member' ) ); ?></label>
1702
- <select name="_url_target" id="_url_target" style="width: 100%">
1703
- <option value="_blank" <?php selected( '_blank', $this->edit_mode_value ); ?>><?php _e( 'Open in new window', 'ultimate-member' ) ?></option>
1704
- <option value="_self" <?php selected( '_self', $this->edit_mode_value ); ?>><?php _e( 'Same window', 'ultimate-member' ) ?></option>
1705
- </select>
1706
- </p>
1707
-
1708
- <?php
1709
- break;
1710
-
1711
- case '_url_rel':
1712
- ?>
1713
-
1714
- <p><label for="_url_rel"><?php _e( 'SEO Follow', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Whether to follow or nofollow this link by search engines', 'ultimate-member' ) ); ?></label>
1715
- <select name="_url_rel" id="_url_rel" style="width: 100%">
1716
- <option value="follow" <?php selected( 'follow', $this->edit_mode_value ); ?>><?php _e( 'Follow', 'ultimate-member' ) ?></option>
1717
- <option value="nofollow" <?php selected( 'nofollow', $this->edit_mode_value ); ?>><?php _e( 'No-Follow', 'ultimate-member' ) ?></option>
1718
- </select>
1719
- </p>
1720
-
1721
- <?php
1722
- break;
1723
-
1724
- case '_force_good_pass':
1725
- ?>
1726
-
1727
- <p><label for="_force_good_pass"><?php _e( 'Force strong password?', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Turn on to force users to create a strong password (A combination of one lowercase letter, one uppercase letter, and one number). If turned on this option is only applied to register forms and not to login forms.', 'ultimate-member' ) ); ?></label>
1728
- <input type="checkbox" name="_force_good_pass" id="_force_good_pass" value="1" <?php checked( isset( $this->edit_mode_value ) ? $this->edit_mode_value : UM()->options()->get( 'require_strongpass' ) ) ?> />
1729
- </p>
1730
-
1731
- <?php
1732
- break;
1733
-
1734
- case '_force_confirm_pass':
1735
- ?>
1736
-
1737
- <p><label for="_force_confirm_pass"><?php _e( 'Automatically add a confirm password field?', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Turn on to add a confirm password field. If turned on the confirm password field will only show on register forms and not on login forms.', 'ultimate-member' ) ); ?></label>
1738
- <input type="checkbox" name="_force_confirm_pass" id="_force_confirm_pass" value="1" <?php checked( isset( $this->edit_mode_value ) ? $this->edit_mode_value : 0 ) ?> class="um-adm-conditional" data-cond1="1" data-cond1-show="_label_confirm_pass" data-cond1-hide="xxx" />
1739
- </p>
1740
-
1741
- <?php
1742
- break;
1743
-
1744
- case '_style':
1745
- ?>
1746
-
1747
- <p><label for="_style"><?php _e( 'Style', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'This is the line-style of divider', 'ultimate-member' ) ); ?></label>
1748
- <select name="_style" id="_style" style="width: 100%">
1749
- <option value="solid" <?php selected( 'solid', $this->edit_mode_value ); ?>><?php _e( 'Solid', 'ultimate-member' ) ?></option>
1750
- <option value="dotted" <?php selected( 'dotted', $this->edit_mode_value ); ?>><?php _e( 'Dotted', 'ultimate-member' ) ?></option>
1751
- <option value="dashed" <?php selected( 'dashed', $this->edit_mode_value ); ?>><?php _e( 'Dashed', 'ultimate-member' ) ?></option>
1752
- <option value="double" <?php selected( 'double', $this->edit_mode_value ); ?>><?php _e( 'Double', 'ultimate-member' ) ?></option>
1753
- </select>
1754
- </p>
1755
-
1756
- <?php
1757
- break;
1758
-
1759
- case '_intervals':
1760
-
1761
- ?>
1762
-
1763
- <p><label for="_intervals"><?php _e( 'Time Intervals (in minutes)', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Choose the minutes interval between each time in the time picker.', 'ultimate-member' ) ); ?></label>
1764
- <input type="text" name="_intervals" id="_intervals" value="<?php echo ( $this->edit_mode_value ) ? $this->edit_mode_value : 60; ?>" placeholder="<?php esc_attr_e( 'e.g. 30, 60, 120', 'ultimate-member' ) ?>" />
1765
- </p>
1766
-
1767
- <?php
1768
- break;
1769
-
1770
-
1771
- case '_format':
1772
-
1773
- if ( $this->set_field_type == 'date' ) {
1774
- ?>
1775
-
1776
- <p><label for="_format"><?php _e( 'Date User-Friendly Format', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'The display format of the date which is visible to user.', 'ultimate-member' ) ); ?></label>
1777
- <select name="_format" id="_format" style="width: 100%">
1778
- <option value="j M Y" <?php selected( 'j M Y', $this->edit_mode_value ); ?>><?php echo UM()->datetime()->get_time('j M Y'); ?></option>
1779
- <option value="M j Y" <?php selected( 'M j Y', $this->edit_mode_value ); ?>><?php echo UM()->datetime()->get_time('M j Y'); ?></option>
1780
- <option value="j F Y" <?php selected( 'j F Y', $this->edit_mode_value ); ?>><?php echo UM()->datetime()->get_time('j F Y'); ?></option>
1781
- <option value="F j Y" <?php selected( 'F j Y', $this->edit_mode_value ); ?>><?php echo UM()->datetime()->get_time('F j Y'); ?></option>
1782
- </select>
1783
- </p>
1784
-
1785
- <?php } else { ?>
1786
-
1787
- <p><label for="_format"><?php _e( 'Time Format', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Choose the displayed time-format for this field', 'ultimate-member' ) ); ?></label>
1788
- <select name="_format" id="_format" style="width: 100%">
1789
- <option value="g:i a" <?php selected( 'g:i a', $this->edit_mode_value ); ?>><?php echo UM()->datetime()->get_time('g:i a'); ?><?php _e( '( 12-hr format )', 'ultimate-member' ) ?></option>
1790
- <option value="g:i A" <?php selected( 'g:i A', $this->edit_mode_value ); ?>><?php echo UM()->datetime()->get_time('g:i A'); ?><?php _e( '( 12-hr format )', 'ultimate-member' ) ?></option>
1791
- <option value="H:i" <?php selected( 'H:i', $this->edit_mode_value ); ?>><?php echo UM()->datetime()->get_time('H:i'); ?><?php _e( '( 24-hr format )', 'ultimate-member' ) ?></option>
1792
- </select>
1793
- </p>
1794
-
1795
- <?php
1796
- }
1797
- break;
1798
-
1799
- case '_format_custom':
1800
- ?>
1801
-
1802
- <p><label for="_format_custom"><?php _e( 'Use custom Date format', 'ultimate-member' ); ?> <?php UM()->tooltip( __( 'This option overrides "Date User-Friendly Format" option. See https://www.php.net/manual/en/function.date.php', 'ultimate-member' ) ); ?></label>
1803
- <input type="text" name="_format_custom" id="_format_custom" value="<?php echo htmlspecialchars( $this->edit_mode_value, ENT_QUOTES ); ?>" placeholder="j M Y" />
1804
- </p>
1805
-
1806
- <?php
1807
- break;
1808
-
1809
- case '_pretty_format':
1810
- ?>
1811
-
1812
- <p><label for="_pretty_format"><?php _e( 'Displayed Date Format', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Whether you wish to show the date in full or only show the years e.g. 25 Years', 'ultimate-member' ) ); ?></label>
1813
- <select name="_pretty_format" id="_pretty_format" style="width: 100%">
1814
- <option value="0" <?php selected( 0, $this->edit_mode_value ); ?>><?php _e( 'Show full date', 'ultimate-member' ) ?></option>
1815
- <option value="1" <?php selected( 1, $this->edit_mode_value ); ?>><?php _e( 'Show years only', 'ultimate-member' ) ?></option>
1816
- </select>
1817
- </p>
1818
-
1819
- <?php
1820
- break;
1821
-
1822
- case '_disabled_weekdays':
1823
-
1824
- if ( isset( $this->edit_mode_value ) && is_array( $this->edit_mode_value ) ) {
1825
- $values = $this->edit_mode_value;
1826
- } else {
1827
- $values = array('');
1828
- }
1829
- ?>
1830
-
1831
- <p><label for="_disabled_weekdays"><?php _e( 'Disable specific weekdays', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Disable specific week days from being available for selection in this date picker', 'ultimate-member' ) ); ?></label>
1832
- <select name="_disabled_weekdays[]" id="_disabled_weekdays" multiple="multiple" style="width: 100%">
1833
- <option value="1" <?php if ( in_array( 1, $values ) ) { echo 'selected'; } ?>><?php _e( 'Sunday', 'ultimate-member' ) ?></option>
1834
- <option value="2" <?php if ( in_array( 2, $values ) ) { echo 'selected'; } ?>><?php _e( 'Monday', 'ultimate-member' ) ?></option>
1835
- <option value="3" <?php if ( in_array( 3, $values ) ) { echo 'selected'; } ?>><?php _e( 'Tuesday', 'ultimate-member' ) ?></option>
1836
- <option value="4" <?php if ( in_array( 4, $values ) ) { echo 'selected'; } ?>><?php _e( 'Wednesday', 'ultimate-member' ) ?></option>
1837
- <option value="5" <?php if ( in_array( 5, $values ) ) { echo 'selected'; } ?>><?php _e( 'Thursday', 'ultimate-member' ) ?></option>
1838
- <option value="6" <?php if ( in_array( 6, $values ) ) { echo 'selected'; } ?>><?php _e( 'Friday', 'ultimate-member' ) ?></option>
1839
- <option value="7" <?php if ( in_array( 7, $values ) ) { echo 'selected'; } ?>><?php _e( 'Saturday', 'ultimate-member' ) ?></option>
1840
- </select>
1841
- </p>
1842
-
1843
- <?php
1844
- break;
1845
-
1846
- case '_years':
1847
- ?>
1848
-
1849
- <p class="_years"><label for="_years"><?php _e( 'Number of Years to pick from', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Number of years available for the date selection. Default to last 50 years', 'ultimate-member' ) ); ?></label>
1850
- <input type="text" name="_years" id="_years" value="<?php echo ( $this->edit_mode_value ) ? $this->edit_mode_value : 50; ?>" />
1851
- </p>
1852
-
1853
- <?php
1854
- break;
1855
-
1856
- case '_years_x':
1857
- ?>
1858
-
1859
- <p class="_years"><label for="_years_x"><?php _e( 'Years Selection', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'This decides which years should be shown relative to today date', 'ultimate-member' ) ); ?></label>
1860
- <select name="_years_x" id="_years_x" style="width: 100%">
1861
- <option value="equal" <?php selected( 'equal', $this->edit_mode_value ); ?>><?php _e( 'Equal years before / after today', 'ultimate-member' ) ?></option>
1862
- <option value="past" <?php selected( 'past', $this->edit_mode_value ); ?>><?php _e( 'Past years only', 'ultimate-member' ) ?></option>
1863
- <option value="future" <?php selected( 'future', $this->edit_mode_value ); ?>><?php _e( 'Future years only', 'ultimate-member' ) ?></option>
1864
- </select>
1865
- </p>
1866
-
1867
- <?php
1868
- break;
1869
-
1870
- case '_range_start':
1871
- ?>
1872
-
1873
- <p class="_date_range"><label for="_range_start"><?php _e( 'Date Range Start', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Set the minimum date/day in range in the format YYYY/MM/DD', 'ultimate-member' ) ); ?></label>
1874
- <input type="text" name="_range_start" id="_range_start" value="<?php echo $this->edit_mode_value; ?>" placeholder="<?php esc_attr_e( 'YYYY/MM/DD', 'ultimate-member' ) ?>" />
1875
- </p>
1876
-
1877
- <?php
1878
- break;
1879
-
1880
- case '_range_end':
1881
- ?>
1882
-
1883
- <p class="_date_range"><label for="_range_end"><?php _e( 'Date Range End', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Set the maximum date/day in range in the format YYYY/MM/DD', 'ultimate-member' ) ); ?></label>
1884
- <input type="text" name="_range_end" id="_range_end" value="<?php echo $this->edit_mode_value; ?>" placeholder="<?php esc_attr_e( 'YYYY/MM/DD', 'ultimate-member' ) ?>" />
1885
- </p>
1886
-
1887
- <?php
1888
- break;
1889
-
1890
- case '_range':
1891
- ?>
1892
-
1893
- <p><label for="_range"><?php _e( 'Set Date Range', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Whether to show a specific number of years or specify a date range to be available for the date picker.', 'ultimate-member' ) ); ?></label>
1894
- <select name="_range" id="_range" class="um-adm-conditional" data-cond1='years' data-cond1-show='_years' data-cond2="date_range" data-cond2-show="_date_range" style="width: 100%">
1895
- <option value="years" <?php selected( 'years', $this->edit_mode_value ); ?>><?php _e( 'Fixed Number of Years', 'ultimate-member' ) ?></option>
1896
- <option value="date_range" <?php selected( 'date_range', $this->edit_mode_value ); ?>><?php _e( 'Specific Date Range', 'ultimate-member' ) ?></option>
1897
- </select>
1898
- </p>
1899
-
1900
- <?php
1901
- break;
1902
-
1903
- case '_content':
1904
-
1905
- if ( $this->set_field_type == 'shortcode' ) {
1906
-
1907
- ?>
1908
-
1909
- <p><label for="_content"><?php _e( 'Enter Shortcode', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Enter the shortcode in the following textarea and it will be displayed on the fields', 'ultimate-member' ) ); ?></label>
1910
- <textarea name="_content" id="_content" placeholder="<?php esc_attr_e( 'e.g. [my_custom_shortcode]', 'ultimate-member' ) ?>"><?php echo $this->edit_mode_value; ?></textarea>
1911
- </p>
1912
-
1913
- <?php
1914
-
1915
- } else {
1916
-
1917
- ?>
1918
-
1919
- <div class="um-admin-editor-h"><label><?php _e( 'Content Editor', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Edit the content of this field here', 'ultimate-member' ) ); ?></label></div>
1920
-
1921
- <div class="um-admin-editor"><!-- editor dynamically loaded here --></div>
1922
-
1923
- <?php
1924
-
1925
- }
1926
-
1927
- break;
1928
-
1929
- case '_crop':
1930
- ?>
1931
-
1932
- <p><label for="_crop"><?php _e( 'Crop Feature', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Enable/disable crop feature for this image upload and define ratio', 'ultimate-member' ) ); ?></label>
1933
- <select name="_crop" id="_crop" style="width: 100%">
1934
- <option value="0" <?php selected( '0', $this->edit_mode_value ); ?>><?php _e( 'Turn Off (Default)', 'ultimate-member' ) ?></option>
1935
- <option value="1" <?php selected( '1', $this->edit_mode_value ); ?>><?php _e( 'Crop and force 1:1 ratio', 'ultimate-member' ) ?></option>
1936
- <option value="3" <?php selected( '3', $this->edit_mode_value ); ?>><?php _e( 'Crop and force user-defined ratio', 'ultimate-member' ) ?></option>
1937
- </select>
1938
- </p>
1939
-
1940
- <?php
1941
- break;
1942
-
1943
- case '_allowed_types':
1944
-
1945
- if ( $this->set_field_type == 'image' ) {
1946
-
1947
- if ( isset( $this->edit_mode_value ) && is_array( $this->edit_mode_value ) ) {
1948
- $values = $this->edit_mode_value;
1949
- } else {
1950
- $values = array( 'png','jpeg','jpg','gif' );
1951
- } ?>
1952
-
1953
- <p><label for="_allowed_types"><?php _e( 'Allowed Image Types', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Select the image types that you want to allow to be uploaded via this field.', 'ultimate-member' ) ); ?></label>
1954
- <select name="_allowed_types[]" id="_allowed_types" multiple="multiple" style="width: 100%">
1955
- <?php foreach( UM()->files()->allowed_image_types() as $e => $n ) { ?>
1956
- <option value="<?php echo $e; ?>" <?php if ( in_array( $e, $values ) ) { echo 'selected'; } ?>><?php echo $n; ?></option>
1957
- <?php } ?>
1958
- </select>
1959
- </p>
1960
-
1961
- <?php
1962
-
1963
- } else {
1964
-
1965
- if ( isset( $this->edit_mode_value ) && is_array( $this->edit_mode_value ) ) {
1966
- $values = $this->edit_mode_value;
1967
- } else {
1968
- $values = array( 'pdf', 'txt' );
1969
- } ?>
1970
-
1971
- <p><label for="_allowed_types"><?php _e( 'Allowed File Types', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Select the image types that you want to allow to be uploaded via this field.', 'ultimate-member' ) ); ?></label>
1972
- <select name="_allowed_types[]" id="_allowed_types" multiple="multiple" style="width: 100%">
1973
- <?php foreach( UM()->files()->allowed_file_types() as $e => $n ) { ?>
1974
- <option value="<?php echo $e; ?>" <?php if ( in_array( $e, $values ) ) { echo 'selected'; } ?>><?php echo $n; ?></option>
1975
- <?php } ?>
1976
- </select>
1977
- </p>
1978
-
1979
- <?php
1980
-
1981
- }
1982
-
1983
- break;
1984
-
1985
- case '_upload_text':
1986
-
1987
- if ( $this->set_field_type == 'image' ) {
1988
- $value = __( 'Drag &amp; Drop Photo', 'ultimate-member' );
1989
- }
1990
- if ( $this->set_field_type == 'file' ) {
1991
- $value = __( 'Drag &amp; Drop File', 'ultimate-member' );
1992
- }
1993
-
1994
- ?>
1995
-
1996
- <p><label for="_upload_text"><?php _e( 'Upload Box Text', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'This is the headline that appears in the upload box for this field', 'ultimate-member' ) ); ?></label>
1997
- <input type="text" name="_upload_text" id="_upload_text" value="<?php echo ( $this->edit_mode_value ) ? $this->edit_mode_value : $value; ?>" />
1998
- </p>
1999
-
2000
- <?php
2001
- break;
2002
-
2003
- case '_upload_help_text':
2004
- ?>
2005
-
2006
- <p><label for="_upload_help_text"><?php _e( 'Additional Instructions Text', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'If you need to add information or secondary line below the headline of upload box, enter it here', 'ultimate-member' ) ); ?></label>
2007
- <input type="text" name="_upload_help_text" id="_upload_help_text" value="<?php echo $this->edit_mode_value; ?>" />
2008
- </p>
2009
-
2010
- <?php
2011
- break;
2012
-
2013
- case '_button_text':
2014
- ?>
2015
-
2016
- <p><label for="_button_text"><?php _e( 'Upload Box Text', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'The text that appears on the button. e.g. Upload', 'ultimate-member' ) ); ?></label>
2017
- <input type="text" name="_button_text" id="_button_text" value="<?php echo ( $this->edit_mode_value ) ? $this->edit_mode_value : __( 'Upload', 'ultimate-member' ); ?>" />
2018
- </p>
2019
-
2020
- <?php
2021
- break;
2022
-
2023
- case '_max_size':
2024
- ?>
2025
-
2026
- <p><label for="_max_size"><?php _e( 'Maximum Size in bytes', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'The maximum size for image that can be uploaded through this field. Leave empty for unlimited size.', 'ultimate-member' ) ); ?></label>
2027
- <input type="text" name="_max_size" id="_max_size" value="<?php echo $this->edit_mode_value; ?>" />
2028
- </p>
2029
-
2030
- <?php
2031
- break;
2032
-
2033
- case '_height':
2034
- ?>
2035
-
2036
- <p><label for="_height"><?php _e( 'Textarea Height', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'The height of textarea in pixels. Default is 100 pixels', 'ultimate-member' ) ); ?></label>
2037
- <input type="text" name="_height" id="_height" value="<?php echo ( $this->edit_mode_value ) ? $this->edit_mode_value : '100px'; ?>" />
2038
- </p>
2039
-
2040
- <?php
2041
- break;
2042
-
2043
- case '_spacing':
2044
- ?>
2045
-
2046
- <p><label for="_spacing"><?php _e( 'Spacing', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'This is the required spacing in pixels. e.g. 20px', 'ultimate-member' ) ); ?></label>
2047
- <input type="text" name="_spacing" id="_spacing" value="<?php echo ( $this->edit_mode_value ) ? $this->edit_mode_value : '20px'; ?>" />
2048
- </p>
2049
-
2050
- <?php
2051
- break;
2052
-
2053
- case '_is_multi':
2054
- ?>
2055
-
2056
- <p><label for="_is_multi"><?php _e( 'Allow multiple selections', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Enable/disable multiple selections for this field', 'ultimate-member' ) ); ?></label>
2057
- <input type="checkbox" name="_is_multi" id="_is_multi" value="1" <?php checked( isset( $this->edit_mode_value ) ? $this->edit_mode_value : 0 ) ?> class="um-adm-conditional" data-cond1="1" data-cond1-show="_max_selections" data-cond1-hide="xxx" />
2058
- </p>
2059
-
2060
- <?php
2061
- break;
2062
-
2063
- case '_max_selections':
2064
- ?>
2065
-
2066
- <p class="_max_selections"><label for="_max_selections"><?php _e( 'Maximum number of selections', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Enter a number here to force a maximum number of selections by user for this field', 'ultimate-member' ) ); ?></label>
2067
- <input type="text" name="_max_selections" id="_max_selections" value="<?php echo $this->edit_mode_value; ?>" />
2068
- </p>
2069
-
2070
- <?php
2071
- break;
2072
-
2073
- case '_min_selections':
2074
- ?>
2075
-
2076
- <p class="_min_selections"><label for="_min_selections"><?php _e( 'Minimum number of selections', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Enter a number here to force a minimum number of selections by user for this field', 'ultimate-member' ) ); ?></label>
2077
- <input type="text" name="_min_selections" id="_min_selections" value="<?php echo $this->edit_mode_value; ?>" />
2078
- </p>
2079
-
2080
- <?php
2081
- break;
2082
-
2083
- case '_max_entries':
2084
- ?>
2085
-
2086
- <p class="_max_entries"><label for="_max_selections"><?php _e( 'Maximum number of entries', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'This is the max number of entries the user can add via field group.', 'ultimate-member' ) ); ?></label>
2087
- <input type="text" name="_max_entries" id="_max_entries" value="<?php echo ( $this->edit_mode_value ) ? $this->edit_mode_value : 10; ?>" />
2088
- </p>
2089
-
2090
- <?php
2091
- break;
2092
-
2093
- case '_max_words':
2094
- ?>
2095
-
2096
- <p><label for="_max_words"><?php _e( 'Maximum allowed words', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'If you want to enable a maximum number of words to be input in this textarea. Leave empty to disable this setting', 'ultimate-member' ) ); ?></label>
2097
- <input type="text" name="_max_words" id="_max_words" value="<?php echo $this->edit_mode_value; ?>" />
2098
- </p>
2099
-
2100
- <?php
2101
- break;
2102
-
2103
- case '_min':
2104
- ?>
2105
-
2106
- <p><label for="_min"><?php _e( 'Minimum Number', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Minimum number that can be entered in this field', 'ultimate-member' ) ); ?></label>
2107
- <input type="text" name="_min" id="_min" value="<?php echo $this->edit_mode_value; ?>" />
2108
- </p>
2109
-
2110
- <?php
2111
- break;
2112
-
2113
- case '_max':
2114
- ?>
2115
-
2116
- <p><label for="_max"><?php _e( 'Maximum Number', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Maximum number that can be entered in this field', 'ultimate-member' ) ); ?></label>
2117
- <input type="text" name="_max" id="_max" value="<?php echo $this->edit_mode_value; ?>" />
2118
- </p>
2119
-
2120
- <?php
2121
- break;
2122
-
2123
- case '_min_chars':
2124
- ?>
2125
-
2126
- <p><label for="_min_chars"><?php _e( 'Minimum length', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'If you want to enable a minimum number of characters to be input in this field. Leave empty to disable this setting', 'ultimate-member' ) ); ?></label>
2127
- <input type="text" name="_min_chars" id="_min_chars" value="<?php echo $this->edit_mode_value; ?>" />
2128
- </p>
2129
-
2130
- <?php
2131
- break;
2132
-
2133
- case '_max_chars':
2134
- ?>
2135
-
2136
- <p><label for="_max_chars"><?php _e( 'Maximum length', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'If you want to enable a maximum number of characters to be input in this field. Leave empty to disable this setting', 'ultimate-member' ) ); ?></label>
2137
- <input type="text" name="_max_chars" id="_max_chars" value="<?php echo $this->edit_mode_value; ?>" />
2138
- </p>
2139
-
2140
- <?php
2141
- break;
2142
-
2143
- case '_html':
2144
- ?>
2145
-
2146
- <p><label for="_html"><?php _e( 'Does this textarea accept HTML?', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Turn on/off HTML tags for this textarea', 'ultimate-member' ) ); ?></label>
2147
- <input type="checkbox" name="_html" id="_html" value="1" <?php checked( isset( $this->edit_mode_value ) ? $this->edit_mode_value : 0 ) ?> />
2148
- </p>
2149
-
2150
- <?php
2151
- break;
2152
-
2153
- case '_options':
2154
-
2155
- if ( isset( $this->edit_mode_value ) && is_array( $this->edit_mode_value ) ) {
2156
- $values = implode("\n", $this->edit_mode_value);
2157
- } else if ( $this->edit_mode_value ) {
2158
- $values = $this->edit_mode_value;
2159
- } else {
2160
- $values = '';
2161
- } ?>
2162
-
2163
- <p><label for="_options"><?php _e( 'Edit Choices', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Enter one choice per line. This will represent the available choices or selections available for user.', 'ultimate-member' ) ); ?></label>
2164
- <textarea name="_options" id="_options"><?php echo $values; ?></textarea>
2165
- </p>
2166
-
2167
- <?php
2168
- break;
2169
-
2170
- case '_title':
2171
- ?>
2172
-
2173
- <p><label for="_title"><?php _e( 'Title', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'This is the title of the field for your reference in the backend. The title will not appear on the front-end of your website.', 'ultimate-member' ) ); ?></label>
2174
- <input type="text" name="_title" id="_title" value="<?php echo htmlspecialchars( $this->edit_mode_value, ENT_QUOTES ); ?>" />
2175
- </p>
2176
-
2177
- <?php
2178
- break;
2179
-
2180
- case '_id':
2181
-
2182
- ?>
2183
-
2184
- <p style="display:none"><label for="_id"><?php _e( 'Unique ID', 'ultimate-member' ) ?></label>
2185
- <input type="text" name="_id" id="_id" value="<?php echo $this->edit_mode_value; ?>" />
2186
- </p>
2187
-
2188
- <?php
2189
-
2190
- break;
2191
-
2192
- case '_metakey':
2193
-
2194
- if ( $this->in_edit ) {
2195
-
2196
- ?>
2197
-
2198
- <p><label for="_metakey"><?php _e( 'Meta Key', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'The meta key cannot be changed for duplicated fields or when editing an existing field. If you require a different meta key please create a new field.', 'ultimate-member' ) ); ?></label>
2199
- <input type="text" name="_metakey_locked" id="_metakey_locked" value="<?php echo $this->edit_mode_value; ?>" disabled />
2200
- </p>
2201
-
2202
- <?php } else { ?>
2203
-
2204
- <p><label for="_metakey"><?php _e( 'Meta Key', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'A meta key is required to store the entered info in this field in the database. The meta key should be unique to this field and be written in lowercase with an underscore ( _ ) separating words e.g country_list or job_title', 'ultimate-member' ) ); ?></label>
2205
- <input type="text" name="_metakey" id="_metakey" value="" />
2206
- </p>
2207
-
2208
- <?php
2209
-
2210
- }
2211
-
2212
- break;
2213
-
2214
- case '_help':
2215
- ?>
2216
-
2217
- <p><label for="_help"><?php _e( 'Help Text', 'ultimate-member' ) ?> <?php UM()->tooltip( __('This is the text that appears in a tooltip when a user hovers over the info icon. Help text is useful for providing users with more information about what they should enter in the field. Leave blank if no help text is needed for field.', 'ultimate-member' ) ); ?></label>
2218
- <input type="text" name="_help" id="_help" value="<?php echo $this->edit_mode_value; ?>" />
2219
- </p>
2220
-
2221
- <?php
2222
- break;
2223
-
2224
- case '_default':
2225
- ?>
2226
-
2227
- <?php if ( $this->set_field_type == 'textarea' ) { ?>
2228
-
2229
- <p><label for="_default"><?php _e( 'Default Text', 'ultimate-member' ); ?> <?php UM()->tooltip( __( 'Text to display by default in this field', 'ultimate-member' ) ); ?></label>
2230
- <textarea name="_default" id="_default"><?php echo $this->edit_mode_value; ?></textarea>
2231
- </p>
2232
-
2233
- <?php } elseif ( $this->set_field_type == 'date' ) { ?>
2234
-
2235
- <p class="um"><label for="_default"><?php _e( 'Default Date', 'ultimate-member' ); ?> <?php UM()->tooltip( __( 'You may use all PHP compatible date formats such as: 2020-02-02, 02/02/2020, yesterday, today, tomorrow, next monday, first day of next month, +3 day', 'ultimate-member' ) ); ?></label>
2236
- <input type="text" name="_default" id="_default" value="<?php echo $this->edit_mode_value; ?>" class="um-datepicker" data-format="yyyy/mm/dd" />
2237
- </p>
2238
-
2239
- <?php } elseif ( $this->set_field_type == 'time' ) { ?>
2240
-
2241
- <p class="um"><label for="_default"><?php _e( 'Default Time', 'ultimate-member' ); ?> <?php UM()->tooltip( __( 'You may use all PHP compatible date formats such as: 2020-02-02, 02/02/2020, yesterday, today, tomorrow, next monday, first day of next month, +3 day', 'ultimate-member' ) ); ?></label>
2242
- <input type="text" name="_default" id="_default" value="<?php echo $this->edit_mode_value; ?>" class="um-timepicker" data-format="HH:i" />
2243
- </p>
2244
-
2245
- <?php } elseif ( $this->set_field_type == 'rating' ) { ?>
2246
-
2247
- <p><label for="_default"><?php _e( 'Default Rating', 'ultimate-member' ); ?> <?php UM()->tooltip( __( 'If you wish the rating field to be prefilled with a number of stars, enter it here.', 'ultimate-member' ) ); ?></label>
2248
- <input type="text" name="_default" id="_default" value="<?php echo $this->edit_mode_value; ?>" />
2249
- </p>
2250
-
2251
- <?php } else { ?>
2252
-
2253
- <p><label for="_default"><?php _e( 'Default Value', 'ultimate-member' ); ?> <?php UM()->tooltip( __( 'This option allows you to pre-fill the field with a default value prior to the user entering a value in the field. Leave blank to have no default value', 'ultimate-member' ) ); ?></label>
2254
- <input type="text" name="_default" id="_default" value="<?php echo $this->edit_mode_value; ?>" />
2255
- </p>
2256
-
2257
- <?php } ?>
2258
-
2259
- <?php
2260
- break;
2261
-
2262
- case '_label':
2263
- ?>
2264
-
2265
- <p><label for="_label"><?php _e( 'Label', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'The field label is the text that appears above the field on your front-end form. Leave blank to not show a label above field.', 'ultimate-member' ) ); ?></label>
2266
- <input type="text" name="_label" id="_label" value="<?php echo htmlspecialchars( $this->edit_mode_value, ENT_QUOTES ); ?>" />
2267
- </p>
2268
-
2269
- <?php
2270
- break;
2271
-
2272
- case '_label_confirm_pass':
2273
- ?>
2274
-
2275
- <p><label for="_label_confirm_pass"><?php _e( 'Confirm password field label', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'This label is the text that appears above the confirm password field. Leave blank to show default label.', 'ultimate-member' ) ); ?></label>
2276
- <input type="text" name="_label_confirm_pass" id="_label_confirm_pass" value="<?php echo htmlspecialchars( $this->edit_mode_value, ENT_QUOTES ); ?>" />
2277
- </p>
2278
-
2279
- <?php
2280
- break;
2281
-
2282
- case '_placeholder':
2283
- ?>
2284
-
2285
- <p><label for="_placeholder"><?php _e( 'Placeholder', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'This is the text that appears within the field e.g please enter your email address. Leave blank to not show any placeholder text.', 'ultimate-member' ) ); ?></label>
2286
- <input type="text" name="_placeholder" id="_placeholder" value="<?php echo htmlspecialchars( $this->edit_mode_value, ENT_QUOTES ); ?>" />
2287
- </p>
2288
-
2289
- <?php
2290
- break;
2291
-
2292
- case '_public':
2293
- $privacy_options = array(
2294
- '1' => __( 'Everyone', 'ultimate-member' ),
2295
- '2' => __( 'Members', 'ultimate-member' ),
2296
- '-1' => __( 'Only visible to profile owner and users who can edit other member accounts', 'ultimate-member' ),
2297
- '-3' => __( 'Only visible to profile owner and specific roles', 'ultimate-member' ),
2298
- '-2' => __( 'Only specific member roles', 'ultimate-member' ),
2299
- );
2300
-
2301
- $privacy_options = apply_filters( 'um_field_privacy_options', $privacy_options ); ?>
2302
-
2303
- <p>
2304
- <label for="_public"><?php _e( 'Privacy', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Field privacy allows you to select who can view this field on the front-end. The site admin can view all fields regardless of the option set here.', 'ultimate-member' ) ); ?></label>
2305
- <select name="_public" id="_public" class="um-adm-conditional" data-cond1="-2" data-cond1-show="_roles" data-cond2="-3" data-cond2-show="_roles" style="width: 100%">
2306
- <?php foreach ( $privacy_options as $value => $title ) { ?>
2307
- <option value="<?php echo esc_attr( $value ) ?>" <?php selected( $value, $this->edit_mode_value ); ?>>
2308
- <?php echo $title ?>
2309
- </option>
2310
- <?php } ?>
2311
- </select>
2312
- </p>
2313
-
2314
- <?php
2315
- break;
2316
-
2317
- case '_roles':
2318
-
2319
- if ( isset( $this->edit_mode_value ) && is_array( $this->edit_mode_value ) ) {
2320
- $values = $this->edit_mode_value;
2321
- } else {
2322
- $values = array('');
2323
- }
2324
-
2325
- ?>
2326
-
2327
- <p class="_roles"><label for="_roles"><?php _e( 'Select member roles', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Select the member roles that can view this field on the front-end.', 'ultimate-member' ) ); ?></label>
2328
- <select name="_roles[]" id="_roles" style="width: 100%" multiple="multiple">
2329
-
2330
- <?php foreach ( UM()->roles()->get_roles() as $key => $value) { ?>
2331
-
2332
- <option value="<?php echo $key; ?>" <?php if ( in_array( $key, $values ) ) { echo 'selected'; } ?>><?php echo $value; ?></option>
2333
-
2334
- <?php } ?>
2335
-
2336
- </select>
2337
- </p>
2338
-
2339
- <?php
2340
- break;
2341
-
2342
- case '_required':
2343
-
2344
- if ( $this->set_field_type == 'password' )
2345
- $def_required = 1;
2346
- else
2347
- $def_required = 0;
2348
-
2349
- ?>
2350
-
2351
- <div class="um-admin-tri">
2352
-
2353
- <p><label for="_required"><?php _e( 'Is this field required?', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'This option allows you to set whether the field must be filled in before the form can be processed.', 'ultimate-member' ) ); ?></label>
2354
- <input type="checkbox" name="_required" id="_required" value="1" <?php checked( isset( $this->edit_mode_value ) ? $this->edit_mode_value : $def_required ) ?> />
2355
- </p>
2356
-
2357
- </div>
2358
-
2359
- <?php
2360
- break;
2361
-
2362
- case '_editable':
2363
- ?>
2364
-
2365
- <div class="um-admin-tri">
2366
-
2367
- <p><label for="_editable"><?php _e( 'Can user edit this field?', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'This option allows you to set whether or not the user can edit the information in this field. The site admin can edit all fields regardless of the option set here.', 'ultimate-member' ) ); ?></label>
2368
- <input type="hidden" name="_editable" id="_editable_hidden" value="0" />
2369
- <input type="checkbox" name="_editable" id="_editable" value="1" <?php checked( null === $this->edit_mode_value || $this->edit_mode_value ) ?> />
2370
- </p>
2371
-
2372
- </div>
2373
-
2374
- <?php
2375
- break;
2376
-
2377
- case '_number':
2378
- ?>
2379
-
2380
- <p><label for="_number"><?php _e( 'Rating System', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Choose whether you want a 5-stars or 10-stars ratings based here.', 'ultimate-member' ) ); ?></label>
2381
- <select name="_number" id="_number" style="width: 100%">
2382
- <option value="5" <?php selected( 5, $this->edit_mode_value ); ?>><?php _e( '5 stars rating system', 'ultimate-member' ) ?></option>
2383
- <option value="10" <?php selected( 10, $this->edit_mode_value ); ?>><?php _e( '10 stars rating system', 'ultimate-member' ) ?></option>
2384
- </select>
2385
- </p>
2386
-
2387
- <?php
2388
- break;
2389
-
2390
- case '_custom_dropdown_options_source':
2391
- ?>
2392
-
2393
- <p><label for="_custom_dropdown_options_source"><?php _e( 'Choices Callback', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Add a callback source to retrieve choices.', 'ultimate-member' ) ); ?></label>
2394
- <input type="text" name="_custom_dropdown_options_source" id="_custom_dropdown_options_source" value="<?php echo htmlspecialchars($this->edit_mode_value, ENT_QUOTES); ?>" />
2395
- </p>
2396
-
2397
- <?php
2398
- break;
2399
-
2400
-
2401
- case '_parent_dropdown_relationship':
2402
- ?>
2403
-
2404
- <p><label for="_parent_dropdown_relationship"><?php _e( 'Parent Option', 'ultimate-member' ) ?><?php UM()->tooltip( __( 'Dynamically populates the option based from selected parent option.', 'ultimate-member' ) ); ?></label>
2405
- <select name="_parent_dropdown_relationship" id="_parent_dropdown_relationship" style="width: 100%">
2406
- <option value=""><?php _e( 'No Selected', 'ultimate-member' ) ?></option>
2407
-
2408
- <?php if ( UM()->builtin()->custom_fields ) {
2409
- foreach ( UM()->builtin()->custom_fields as $field_key => $array ) {
2410
- if ( in_array( $array['type'], array( 'select' ) ) && ( ! isset( $field_args['metakey'] ) || $field_args['metakey'] != $array['metakey'] ) && isset( $array['title'] ) ) { ?>
2411
- <option value="<?php echo esc_attr( $array['metakey'] ) ?>" <?php selected( $array['metakey'], $this->edit_mode_value ) ?>><?php echo $array['title'] ?></option>
2412
- <?php }
2413
- }
2414
- } ?>
2415
- </select>
2416
- </p>
2417
-
2418
- <?php
2419
- break;
2420
-
2421
-
2422
- }
2423
-
2424
- }
2425
-
2426
- }
2427
- }
1
+ <?php
2
+ namespace um\admin\core;
3
+
4
+
5
+ if ( ! defined( 'ABSPATH' ) ) exit;
6
+
7
+
8
+ if ( ! class_exists( 'um\admin\core\Admin_Metabox' ) ) {
9
+
10
+
11
+ /**
12
+ * Class Admin_Metabox
13
+ *
14
+ * @package um\admin\core
15
+ */
16
+ class Admin_Metabox {
17
+
18
+
19
+ /**
20
+ * @var bool
21
+ */
22
+ private $form_nonce_added = false;
23
+
24
+
25
+ /**
26
+ * @var bool
27
+ */
28
+ private $directory_nonce_added = false;
29
+
30
+
31
+ /**
32
+ * @var bool
33
+ */
34
+ private $custom_nonce_added = false;
35
+
36
+
37
+ var $init_icon = false;
38
+
39
+
40
+ /**
41
+ * Admin_Metabox constructor.
42
+ */
43
+ function __construct() {
44
+ $this->in_edit = false;
45
+ $this->edit_mode_value = null;
46
+ $this->edit_array = [];
47
+
48
+ add_action( 'admin_head', array( &$this, 'admin_head' ), 9);
49
+ add_action( 'admin_footer', array( &$this, 'load_modal_content' ), 9 );
50
+
51
+ add_action( 'load-post.php', array( &$this, 'add_metabox' ), 9 );
52
+ add_action( 'load-post-new.php', array( &$this, 'add_metabox' ), 9 );
53
+
54
+ add_action( 'admin_init', array( &$this, 'add_taxonomy_metabox' ), 9 );
55
+
56
+ //roles metaboxes
57
+ add_action( 'um_roles_add_meta_boxes', array( &$this, 'add_metabox_role' ) );
58
+
59
+ add_filter( 'um_builtin_validation_types_continue_loop', array( &$this, 'validation_types_continue_loop' ), 1, 4 );
60
+ add_filter( 'um_restrict_content_hide_metabox', array( &$this, 'hide_metabox_restrict_content_shop' ), 10, 1 );
61
+
62
+ add_filter( 'um_member_directory_meta_value_before_save', array( UM()->member_directory(), 'before_save_data' ), 10, 3 );
63
+ }
64
+
65
+
66
+ /**
67
+ * Hide Woocommerce Shop page restrict content metabox
68
+ * @param $hide
69
+ *
70
+ * @return bool
71
+ */
72
+ function hide_metabox_restrict_content_shop( $hide ) {
73
+ if ( function_exists( 'wc_get_page_id' ) && ! empty( $_GET['post'] ) &&
74
+ absint( $_GET['post'] ) == wc_get_page_id( 'shop' ) ) {
75
+ return true;
76
+ }
77
+
78
+ return $hide;
79
+ }
80
+
81
+
82
+ /**
83
+ * Filter validation types on loop
84
+ *
85
+ * @param $break
86
+ * @param $key
87
+ * @param $form_id
88
+ * @param $field_array
89
+ *
90
+ * @return bool
91
+ */
92
+ function validation_types_continue_loop( $break, $key, $form_id, $field_array ) {
93
+
94
+ // show unique username validation only for user_login field
95
+ if ( isset( $field_array['metakey'] ) && $field_array['metakey'] == 'user_login' && $key !== 'unique_username' ) {
96
+ return false;
97
+ }
98
+
99
+ return $break;
100
+ }
101
+
102
+
103
+ /**
104
+ * Gets the role meta
105
+ *
106
+ * @param $id
107
+ *
108
+ * @return mixed
109
+ */
110
+ function get_custom_post_meta( $id ) {
111
+ $all_meta = get_post_custom( $id );
112
+ foreach ( $all_meta as $k => $v ) {
113
+ if ( strstr( $k, '_um_' ) ) {
114
+ $um_meta[ $k ] = $v;
115
+ }
116
+ }
117
+ if ( isset( $um_meta ) ) {
118
+ return $um_meta;
119
+ }
120
+
121
+ return false;
122
+ }
123
+
124
+
125
+ /**
126
+ * Runs on admin head
127
+ */
128
+ function admin_head(){
129
+ global $post;
130
+ if ( UM()->admin()->is_plugin_post_type() && isset($post->ID) ){
131
+ $this->postmeta = $this->get_custom_post_meta($post->ID);
132
+ }
133
+ }
134
+
135
+
136
+ /**
137
+ * Init the metaboxes
138
+ */
139
+ function add_metabox() {
140
+ global $current_screen;
141
+
142
+ if ( $current_screen->id == 'um_form' ) {
143
+ add_action( 'add_meta_boxes', array(&$this, 'add_metabox_form'), 1 );
144
+ add_action( 'save_post', array(&$this, 'save_metabox_form'), 10, 2 );
145
+ }
146
+
147
+ if ( $current_screen->id == 'um_directory' ) {
148
+ add_action( 'add_meta_boxes', array(&$this, 'add_metabox_directory'), 1 );
149
+ add_action( 'save_post', array(&$this, 'save_metabox_directory'), 10, 2 );
150
+ }
151
+
152
+ //restrict content metabox
153
+ $post_types = UM()->options()->get( 'restricted_access_post_metabox' );
154
+ if ( ! empty( $post_types[ $current_screen->id ] ) ) {
155
+
156
+ /**
157
+ * UM hook
158
+ *
159
+ * @type filter
160
+ * @title um_restrict_content_hide_metabox
161
+ * @description Show/Hide Restrict content metabox
162
+ * @input_vars
163
+ * [{"var":"$show","type":"bool","desc":"Show Metabox"}]
164
+ * @change_log
165
+ * ["Since: 2.0"]
166
+ * @usage add_filter( 'um_restrict_content_hide_metabox', 'function_name', 10, 1 );
167
+ * @example
168
+ * <?php
169
+ * add_filter( 'um_restrict_content_hide_metabox', 'my_restrict_content_hide_metabox', 10, 1 );
170
+ * function my_restrict_content_hide_metabox( $show ) {
171
+ * // your code here
172
+ * return $show;
173
+ * }
174
+ * ?>
175
+ */
176
+ $hide_metabox = apply_filters( 'um_restrict_content_hide_metabox', false );
177
+
178
+ if ( ! $hide_metabox ) {
179
+ add_action( 'add_meta_boxes', array(&$this, 'add_metabox_restrict_content'), 1 );
180
+ add_action( 'save_post', array( &$this, 'save_metabox_restrict_content' ), 10, 2 );
181
+ }
182
+
183
+ if ( $current_screen->id == 'attachment' ) {
184
+ add_action( 'add_attachment', array( &$this, 'save_attachment_metabox_restrict_content' ), 10, 2 );
185
+ add_action( 'edit_attachment', array( &$this, 'save_attachment_metabox_restrict_content' ), 10, 2 );
186
+ }
187
+ }
188
+
189
+
190
+ add_action( 'save_post', array( &$this, 'save_metabox_custom' ), 10, 2 );
191
+ }
192
+
193
+
194
+ /**
195
+ * @param $post_id
196
+ * @param $post
197
+ */
198
+ public function save_metabox_custom( $post_id, $post ) {
199
+ // validate nonce
200
+ if ( ! isset( $_POST['um_admin_save_metabox_custom_nonce'] ) ||
201
+ ! wp_verify_nonce( $_POST['um_admin_save_metabox_custom_nonce'], basename( __FILE__ ) ) ) {
202
+ return;
203
+ }
204
+
205
+ /**
206
+ * UM hook
207
+ *
208
+ * @type action
209
+ * @title um_admin_custom_restrict_content_metaboxes
210
+ * @description Save metabox custom with restrict content
211
+ * @input_vars
212
+ * [{"var":"$post_id","type":"int","desc":"Post ID"},
213
+ * {"var":"$post","type":"array","desc":"Post data"}]
214
+ * @change_log
215
+ * ["Since: 2.0"]
216
+ * @usage add_action( 'um_admin_custom_restrict_content_metaboxes', 'function_name', 10, 2 );
217
+ * @example
218
+ * <?php
219
+ * add_action( 'um_admin_custom_restrict_content_metaboxes', 'my_admin_custom_restrict_content', 10, 2 );
220
+ * function my_admin_custom_restrict_content( $post_id, $post ) {
221
+ * // your code here
222
+ * }
223
+ * ?>
224
+ */
225
+ do_action( 'um_admin_custom_restrict_content_metaboxes', $post_id, $post );
226
+ }
227
+
228
+
229
+ /**
230
+ *
231
+ */
232
+ function add_metabox_restrict_content() {
233
+ global $current_screen;
234
+
235
+ add_meta_box(
236
+ 'um-admin-restrict-content',
237
+ __( 'Ultimate Member: Content Restriction', 'ultimate-member' ),
238
+ array( &$this, 'restrict_content_cb' ),
239
+ $current_screen->id,
240
+ 'normal',
241
+ 'default'
242
+ );
243
+
244
+ /**
245
+ * UM hook
246
+ *
247
+ * @type action
248
+ * @title um_admin_custom_restrict_content_metaboxes
249
+ * @description Add restrict content custom metabox
250
+ * @change_log
251
+ * ["Since: 2.0"]
252
+ * @usage add_action( 'um_admin_custom_restrict_content_metaboxes', 'function_name', 10 );
253
+ * @example
254
+ * <?php
255
+ * add_action( 'um_admin_custom_restrict_content_metaboxes', 'my_admin_custom_restrict_content', 10 );
256
+ * function my_admin_custom_restrict_content() {
257
+ * // your code here
258
+ * }
259
+ * ?>
260
+ */
261
+ do_action( 'um_admin_custom_restrict_content_metaboxes' );
262
+ }
263
+
264
+
265
+ /**
266
+ * Content restriction metabox
267
+ *
268
+ * @param $object
269
+ * @param $box
270
+ */
271
+ function restrict_content_cb( $object, $box ) {
272
+ include_once UM()->admin()->templates_path . 'access/restrict_content.php';
273
+ wp_nonce_field( basename( __FILE__ ), 'um_admin_save_metabox_restrict_content_nonce' );
274
+ }
275
+
276
+
277
+ /**
278
+ * Init the metaboxes
279
+ */
280
+ function add_taxonomy_metabox() {
281
+ //restrict content metabox
282
+ $all_taxonomies = get_taxonomies( array( 'public' => true ) );
283
+ $tax_types = UM()->options()->get( 'restricted_access_taxonomy_metabox' );
284
+ $exclude_taxonomies = UM()->excluded_taxonomies();
285
+
286
+ foreach ( $all_taxonomies as $key => $taxonomy ) {
287
+ if ( in_array( $key, $exclude_taxonomies ) || empty( $tax_types[$key] ) )
288
+ continue;
289
+
290
+ add_action( $taxonomy . '_add_form_fields', array( &$this, 'um_category_access_fields_create' ) );
291
+ add_action( $taxonomy . '_edit_form_fields', array( &$this, 'um_category_access_fields_edit' ) );
292
+ add_action( 'create_' . $taxonomy, array( &$this, 'um_category_access_fields_save' ) );
293
+ add_action( 'edited_' . $taxonomy, array( &$this, 'um_category_access_fields_save' ) );
294
+ }
295
+ }
296
+
297
+
298
+ /**
299
+ * @param $post_id
300
+ * @param $post
301
+ */
302
+ function save_metabox_restrict_content( $post_id, $post ) {
303
+ // validate nonce
304
+ if ( ! isset( $_POST['um_admin_save_metabox_restrict_content_nonce'] ) ||
305
+ ! wp_verify_nonce( $_POST['um_admin_save_metabox_restrict_content_nonce'], basename( __FILE__ ) ) ) {
306
+ return;
307
+ }
308
+
309
+ // validate user
310
+ $post_type = get_post_type_object( $post->post_type );
311
+ if ( ! current_user_can( $post_type->cap->edit_post, $post_id ) ) {
312
+ return;
313
+ }
314
+
315
+ if ( ! empty( $_POST['um_content_restriction'] ) && is_array( $_POST['um_content_restriction'] ) ) {
316
+ $restriction_meta = UM()->admin()->sanitize_post_restriction_meta( $_POST['um_content_restriction'] );
317
+
318
+ update_post_meta( $post_id, 'um_content_restriction', $restriction_meta );
319
+ } else {
320
+ delete_post_meta( $post_id, 'um_content_restriction' );
321
+ }
322
+ }
323
+
324
+
325
+ /**
326
+ * @param $post_id
327
+ *
328
+ */
329
+ function save_attachment_metabox_restrict_content( $post_id ) {
330
+ // validate nonce
331
+ if ( ! isset( $_POST['um_admin_save_metabox_restrict_content_nonce'] )
332
+ || ! wp_verify_nonce( $_POST['um_admin_save_metabox_restrict_content_nonce'], basename( __FILE__ ) ) ) {
333
+ return;
334
+ }
335
+
336
+ $post = get_post( $post_id );
337
+
338
+ // validate user
339
+ $post_type = get_post_type_object( $post->post_type );
340
+ if ( ! current_user_can( $post_type->cap->edit_post, $post_id ) ) {
341
+ return;
342
+ }
343
+
344
+ if ( ! empty( $_POST['um_content_restriction'] ) && is_array( $_POST['um_content_restriction'] ) ) {
345
+ $restriction_meta = UM()->admin()->sanitize_post_restriction_meta( $_POST['um_content_restriction'] );
346
+
347
+ update_post_meta( $post_id, 'um_content_restriction', $restriction_meta );
348
+ } else {
349
+ delete_post_meta( $post_id, 'um_content_restriction' );
350
+ }
351
+ }
352
+
353
+
354
+ /**
355
+ *
356
+ */
357
+ function um_category_access_fields_create() {
358
+ /**
359
+ * UM hook
360
+ *
361
+ * @type filter
362
+ * @title um_admin_category_access_settings_fields
363
+ * @description Settings fields for terms
364
+ * @input_vars
365
+ * [{"var":"$access_settings_fields","type":"array","desc":"Settings Fields"},
366
+ * {"var":"$data","type":"array","desc":"Settings Data"},
367
+ * {"var":"$screen","type":"string","desc":"Category Screen"}]
368
+ * @change_log
369
+ * ["Since: 2.0"]
370
+ * @usage add_filter( 'um_admin_category_access_settings_fields', 'function_name', 10, 3 );
371
+ * @example
372
+ * <?php
373
+ * add_filter( 'um_admin_category_access_settings_fields', 'my_admin_category_access_settings_fields', 10, 3 );
374
+ * function my_admin_category_access_settings_fields( $access_settings_fields, $data, $screen ) {
375
+ * // your code here
376
+ * $access_settings_fields[] = array(
377
+ * 'id' => 'my-field-key',
378
+ * 'type' => 'my-field-type',
379
+ * 'label' => __( 'My field Label', 'ultimate-member' ),
380
+ * 'description' => __( 'My Field Description', 'ultimate-member' ),
381
+ * 'value' => ! empty( $data['_um_custom_access_settings'] ) ? $data['_um_custom_access_settings'] : 0,
382
+ * );
383
+ * return $access_settings_fields;
384
+ * }
385
+ * ?>
386
+ */
387
+ $fields = apply_filters( 'um_admin_category_access_settings_fields', array(
388
+ array(
389
+ 'id' => '_um_custom_access_settings',
390
+ 'type' => 'checkbox',
391
+ 'label' => __( 'Restrict access to this term and its posts?', 'ultimate-member' ),
392
+ 'description' => __( 'Activate content restriction for this term and its posts. Affects only posts that do not have individual Restriction Content settings', 'ultimate-member' ),
393
+ 'value' => 0,
394
+ ),
395
+ array(
396
+ 'id' => '_um_accessible',
397
+ 'type' => 'select',
398
+ 'label' => __( 'Who can access this term and its posts?', 'ultimate-member' ),
399
+ 'value' => '0',
400
+ 'options' => array(
401
+ '0' => __( 'Everyone', 'ultimate-member' ),
402
+ '1' => __( 'Logged out users', 'ultimate-member' ),
403
+ '2' => __( 'Logged in users', 'ultimate-member' ),
404
+ ),
405
+ 'conditional' => array( '_um_custom_access_settings', '=', '1' ),
406
+ ),
407
+ array(
408
+ 'id' => '_um_access_roles',
409
+ 'type' => 'multi_checkbox',
410
+ 'label' => __( 'Select which roles can access this term and its posts', 'ultimate-member' ),
411
+ 'description' => __( 'Leave empty if you want to display a term for all logged in users', 'ultimate-member' ),
412
+ 'options' => UM()->roles()->get_roles( false ),
413
+ 'columns' => 3,
414
+ 'conditional' => array( '_um_accessible', '=', '2' ),
415
+ ),
416
+ array(
417
+ 'id' => '_um_access_hide_from_queries',
418
+ 'type' => 'checkbox',
419
+ 'label' => UM()->options()->get( 'disable_restriction_pre_queries' ) ? __( 'Hide from queries', 'ultimate-member' ) : __( 'Would you like to display 404 error on the term\'s archive page and terms\' posts single pages when users haven\'t access?', 'ultimate-member' ),
420
+ 'description' => UM()->options()->get( 'disable_restriction_pre_queries' ) ? __( 'Exclude only from WP queries results', 'ultimate-member' ) : __( 'Recommended to be enabled. Restricted term\'s archive page and all terms\' posts will be hidden by exclusion from WP Query. The safest and most effective method that hides post and its comments from all requests, RSS feeds, etc. on your site', 'ultimate-member' ),
421
+ 'value' => 1,
422
+ 'conditional' => array( '_um_accessible', '!=', '0' ),
423
+ ),
424
+ array(
425
+ 'id' => '_um_noaccess_action',
426
+ 'type' => 'select',
427
+ 'label' => __( 'What happens when users without access try to view the term\'s post?', 'ultimate-member' ),
428
+ 'description' => __( 'Action when users without access tries to view the term\'s post', 'ultimate-member' ),
429
+ 'value' => '0',
430
+ 'options' => array(
431
+ '0' => __( 'Show access restricted message', 'ultimate-member' ),
432
+ '1' => __( 'Redirect user', 'ultimate-member' ),
433
+ ),
434
+ 'conditional' => UM()->options()->get( 'disable_restriction_pre_queries' ) ? array( '_um_accessible', '!=', '0' ) : array( '_um_access_hide_from_queries', '=', '0' ),
435
+ ),
436
+ array(
437
+ 'id' => '_um_restrict_by_custom_message',
438
+ 'type' => 'select',
439
+ 'label' => __( 'Restricted access message type', 'ultimate-member' ),
440
+ 'description' => __( 'Would you like to use the global default message or apply a custom message to this term\'s post?', 'ultimate-member' ),
441
+ 'value' => '0',
442
+ 'options' => array(
443
+ '0' => __( 'Global default message', 'ultimate-member' ),
444
+ '1' => __( 'Custom message', 'ultimate-member' ),
445
+ ),
446
+ 'conditional' => array( '_um_noaccess_action', '=', '0' ),
447
+ ),
448
+ array(
449
+ 'id' => '_um_restrict_custom_message',
450
+ 'type' => 'wp_editor',
451
+ 'label' => __( 'Custom restricted access message', 'ultimate-member' ),
452
+ 'description' => __( 'You may replace global restricted access message here', 'ultimate-member' ),
453
+ 'value' => '',
454
+ 'conditional' => array( '_um_restrict_by_custom_message', '=', '1' ),
455
+ ),
456
+ array(
457
+ 'id' => '_um_access_redirect',
458
+ 'type' => 'select',
459
+ 'label' => __( 'Where should users be redirected to?', 'ultimate-member' ),
460
+ 'description' => __( 'Select redirect to page when user hasn\'t access to the term\'s post', 'ultimate-member' ),
461
+ 'value' => '0',
462
+ 'conditional' => array( '_um_noaccess_action', '=', '1' ),
463
+ 'options' => array(
464
+ '0' => __( 'Login page', 'ultimate-member' ),
465
+ '1' => __( 'Custom URL', 'ultimate-member' ),
466
+ ),
467
+ ),
468
+ array(
469
+ 'id' => '_um_access_redirect_url',
470
+ 'type' => 'text',
471
+ 'label' => __( 'Redirect URL', 'ultimate-member' ),
472
+ 'description' => __( 'Set full URL where do you want to redirect the user', 'ultimate-member' ),
473
+ 'value' => '',
474
+ 'conditional' => array( '_um_access_redirect', '=', '1' ),
475
+ ),
476
+ ), array(), 'create' );
477
+
478
+ UM()->admin_forms(
479
+ array(
480
+ 'class' => 'um-restrict-content um-third-column',
481
+ 'prefix_id' => 'um_content_restriction',
482
+ 'without_wrapper' => true,
483
+ 'div_line' => true,
484
+ 'fields' => $fields,
485
+ )
486
+ )->render_form();
487
+
488
+ wp_nonce_field( basename( __FILE__ ), 'um_admin_save_taxonomy_restrict_content_nonce' );
489
+ }
490
+
491
+
492
+ /**
493
+ * @param $term
494
+ */
495
+ function um_category_access_fields_edit( $term ) {
496
+ $termID = $term->term_id;
497
+
498
+ $data = get_term_meta( $termID, 'um_content_restriction', true );
499
+
500
+ $_um_access_roles_value = array();
501
+ if ( ! empty( $data['_um_access_roles'] ) ) {
502
+ foreach ( $data['_um_access_roles'] as $key => $value ) {
503
+ if ( $value ) {
504
+ $_um_access_roles_value[] = $key;
505
+ }
506
+ }
507
+ }
508
+
509
+ /**
510
+ * UM hook
511
+ *
512
+ * @type filter
513
+ * @title um_admin_category_access_settings_fields
514
+ * @description Settings fields for terms
515
+ * @input_vars
516
+ * [{"var":"$access_settings_fields","type":"array","desc":"Settings Fields"},
517
+ * {"var":"$data","type":"array","desc":"Settings Data"},
518
+ * {"var":"$screen","type":"string","desc":"Category Screen"}]
519
+ * @change_log
520
+ * ["Since: 2.0"]
521
+ * @usage add_filter( 'um_admin_category_access_settings_fields', 'function_name', 10, 3 );
522
+ * @example
523
+ * <?php
524
+ * add_filter( 'um_admin_category_access_settings_fields', 'my_admin_category_access_settings_fields', 10, 3 );
525
+ * function my_admin_category_access_settings_fields( $access_settings_fields, $data, $screen ) {
526
+ * // your code here
527
+ * $access_settings_fields[] = array(
528
+ * 'id' => 'my-field-key',
529
+ * 'type' => 'my-field-type',
530
+ * 'label' => __( 'My field Label', 'ultimate-member' ),
531
+ * 'description' => __( 'My Field Description', 'ultimate-member' ),
532
+ * 'value' => ! empty( $data['_um_custom_access_settings'] ) ? $data['_um_custom_access_settings'] : 0,
533
+ * );
534
+ * return $access_settings_fields;
535
+ * }
536
+ * ?>
537
+ */
538
+ $fields = apply_filters( 'um_admin_category_access_settings_fields', array(
539
+ array(
540
+ 'id' => '_um_custom_access_settings',
541
+ 'type' => 'checkbox',
542
+ 'label' => __( 'Restrict access to this term and its posts?', 'ultimate-member' ),
543
+ 'description' => __( 'Activate content restriction for this term and its posts. Affects only posts that do not have individual Restriction Content settings', 'ultimate-member' ),
544
+ 'value' => ! empty( $data['_um_custom_access_settings'] ) ? $data['_um_custom_access_settings'] : 0,
545
+ ),
546
+ array(
547
+ 'id' => '_um_accessible',
548
+ 'type' => 'select',
549
+ 'label' => __( 'Who can access this term and its posts?', 'ultimate-member' ),
550
+ 'value' => ! empty( $data['_um_accessible'] ) ? $data['_um_accessible'] : '0',
551
+ 'options' => array(
552
+ '0' => __( 'Everyone', 'ultimate-member' ),
553
+ '1' => __( 'Logged out users', 'ultimate-member' ),
554
+ '2' => __( 'Logged in users', 'ultimate-member' ),
555
+ ),
556
+ 'conditional' => array( '_um_custom_access_settings', '=', '1' ),
557
+ ),
558
+ array(
559
+ 'id' => '_um_access_roles',
560
+ 'type' => 'multi_checkbox',
561
+ 'label' => __( 'Select which roles can access this term and its posts', 'ultimate-member' ),
562
+ 'description' => __( 'Leave empty if you want to display a term for all logged in users', 'ultimate-member' ),
563
+ 'value' => $_um_access_roles_value,
564
+ 'options' => UM()->roles()->get_roles( false ),
565
+ 'columns' => 3,
566
+ 'conditional' => array( '_um_accessible', '=', '2' ),
567
+ ),
568
+ array(
569
+ 'id' => '_um_access_hide_from_queries',
570
+ 'type' => 'checkbox',
571
+ 'label' => UM()->options()->get( 'disable_restriction_pre_queries' ) ? __( 'Hide from queries', 'ultimate-member' ) : __( 'Would you like to display 404 error on the term\'s archive page and terms\' posts single pages when users haven\'t access?', 'ultimate-member' ),
572
+ 'description' => UM()->options()->get( 'disable_restriction_pre_queries' ) ? __( 'Exclude only from WP queries results', 'ultimate-member' ) : __( 'Recommended to be enabled. Restricted term\'s archive page and all terms\' posts will be hidden by exclusion from WP Query. The safest and most effective method that hides post and its comments from all requests, RSS feeds, etc. on your site', 'ultimate-member' ),
573
+ 'value' => ! empty( $data['_um_access_hide_from_queries'] ) ? $data['_um_access_hide_from_queries'] : '',
574
+ 'conditional' => array( '_um_accessible', '!=', '0' ),
575
+ ),
576
+ array(
577
+ 'id' => '_um_noaccess_action',
578
+ 'type' => 'select',
579
+ 'label' => __( 'What happens when users without access try to view the term\'s post?', 'ultimate-member' ),
580
+ 'description' => __( 'Action when users without access tries to view the term\'s post', 'ultimate-member' ),
581
+ 'value' => ! empty( $data['_um_noaccess_action'] ) ? $data['_um_noaccess_action'] : '0',
582
+ 'options' => array(
583
+ '0' => __( 'Show access restricted message', 'ultimate-member' ),
584
+ '1' => __( 'Redirect user', 'ultimate-member' ),
585
+ ),
586
+ 'conditional' => UM()->options()->get( 'disable_restriction_pre_queries' ) ? array( '_um_accessible', '!=', '0' ) : array( '_um_access_hide_from_queries', '=', '0' ),
587
+ ),
588
+ array(
589
+ 'id' => '_um_restrict_by_custom_message',
590
+ 'type' => 'select',
591
+ 'label' => __( 'Restricted access message type', 'ultimate-member' ),
592
+ 'description' => __( 'Would you like to use the global default message or apply a custom message to this term\'s post?', 'ultimate-member' ),
593
+ 'value' => ! empty( $data['_um_restrict_by_custom_message'] ) ? $data['_um_restrict_by_custom_message'] : '0',
594
+ 'options' => array(
595
+ '0' => __( 'Global default message', 'ultimate-member' ),
596
+ '1' => __( 'Custom message', 'ultimate-member' ),
597
+ ),
598
+ 'conditional' => array( '_um_noaccess_action', '=', '0' ),
599
+ ),
600
+ array(
601
+ 'id' => '_um_restrict_custom_message',
602
+ 'type' => 'wp_editor',
603
+ 'label' => __( 'Custom restricted access message', 'ultimate-member' ),
604
+ 'description' => __( 'You may replace global restricted access message here', 'ultimate-member' ),
605
+ 'value' => ! empty( $data['_um_restrict_custom_message'] ) ? $data['_um_restrict_custom_message'] : '',
606
+ 'conditional' => array( '_um_restrict_by_custom_message', '=', '1' ),
607
+ ),
608
+ array(
609
+ 'id' => '_um_access_redirect',
610
+ 'type' => 'select',
611
+ 'label' => __( 'Where should users be redirected to?', 'ultimate-member' ),
612
+ 'description' => __( 'Select redirect to page when user hasn\'t access to the term\'s post', 'ultimate-member' ),
613
+ 'value' => ! empty( $data['_um_access_redirect'] ) ? $data['_um_access_redirect'] : '0',
614
+ 'options' => array(
615
+ '0' => __( 'Login page', 'ultimate-member' ),
616
+ '1' => __( 'Custom URL', 'ultimate-member' ),
617
+ ),
618
+ 'conditional' => array( '_um_noaccess_action', '=', '1' ),
619
+ ),
620
+ array(
621
+ 'id' => '_um_access_redirect_url',
622
+ 'type' => 'text',
623
+ 'label' => __( 'Redirect URL', 'ultimate-member' ),
624
+ 'description' => __( 'Set full URL where do you want to redirect the user', 'ultimate-member' ),
625
+ 'value' => ! empty( $data['_um_access_redirect_url'] ) ? $data['_um_access_redirect_url'] : '',
626
+ 'conditional' => array( '_um_access_redirect', '=', '1' ),
627
+ ),
628
+ ), $data, 'edit' );
629
+
630
+ UM()->admin_forms(
631
+ array(
632
+ 'class' => 'um-restrict-content um-third-column',
633
+ 'prefix_id' => 'um_content_restriction',
634
+ 'without_wrapper' => true,
635
+ 'fields' => $fields,
636
+ )
637
+ )->render_form();
638
+
639
+ wp_nonce_field( basename( __FILE__ ), 'um_admin_save_taxonomy_restrict_content_nonce' );
640
+ }
641
+
642
+
643
+ /**
644
+ * @param $termID
645
+ *
646
+ * @return mixed
647
+ */
648
+ function um_category_access_fields_save( $termID ) {
649
+
650
+ // validate nonce
651
+ if ( ! isset( $_REQUEST['um_admin_save_taxonomy_restrict_content_nonce'] ) || ! wp_verify_nonce( $_REQUEST['um_admin_save_taxonomy_restrict_content_nonce'], basename( __FILE__ ) ) ) {
652
+ return $termID;
653
+ }
654
+
655
+ // validate user
656
+ $term = get_term( $termID );
657
+ $taxonomy = get_taxonomy( $term->taxonomy );
658
+
659
+ if ( ! current_user_can( $taxonomy->cap->edit_terms, $termID ) ) {
660
+ return $termID;
661
+ }
662
+
663
+ if ( ! empty( $_REQUEST['um_content_restriction'] ) && is_array( $_REQUEST['um_content_restriction'] ) ) {
664
+ $restriction_meta = UM()->admin()->sanitize_term_restriction_meta( $_REQUEST['um_content_restriction'] );
665
+
666
+ update_term_meta( $termID, 'um_content_restriction', $restriction_meta );
667
+ } else {
668
+ delete_term_meta( $termID, 'um_content_restriction' );
669
+ }
670
+
671
+ return $termID;
672
+ }
673
+
674
+
675
+ /**
676
+ * Load a directory metabox
677
+ *
678
+ * @param $object
679
+ * @param $box
680
+ */
681
+ function load_metabox_directory( $object, $box ) {
682
+ $box['id'] = str_replace( 'um-admin-form-', '', $box['id'] );
683
+
684
+ preg_match('#\{.*?\}#s', $box['id'], $matches );
685
+
686
+ if ( isset( $matches[0] ) ) {
687
+ $path = $matches[0];
688
+ $box['id'] = preg_replace('~(\\{[^}]+\\})~','', $box['id'] );
689
+ } else {
690
+ $path = um_path;
691
+ }
692
+
693
+ $path = str_replace('{','', $path );
694
+ $path = str_replace('}','', $path );
695
+
696
+
697
+ include_once $path . 'includes/admin/templates/directory/'. $box['id'] . '.php';
698
+ if ( ! $this->directory_nonce_added ) {
699
+ $this->directory_nonce_added = true;
700
+ wp_nonce_field( basename( __FILE__ ), 'um_admin_save_metabox_directory_nonce' );
701
+ }
702
+ }
703
+
704
+
705
+ /**
706
+ * Load a role metabox
707
+ *
708
+ * @param $object
709
+ * @param $box
710
+ */
711
+ function load_metabox_role( $object, $box ) {
712
+ global $post;
713
+
714
+ $box['id'] = str_replace( 'um-admin-form-', '', $box['id'] );
715
+
716
+ if ( $box['id'] == 'builder' ) {
717
+ UM()->builder()->form_id = get_the_ID();
718
+ }
719
+
720
+ preg_match('#\{.*?\}#s', $box['id'], $matches);
721
+
722
+ if ( isset($matches[0]) ){
723
+ $path = $matches[0];
724
+ $box['id'] = preg_replace('~(\\{[^}]+\\})~','', $box['id'] );
725
+ } else {
726
+ $path = um_path;
727
+ }
728
+
729
+ $path = str_replace('{','', $path );
730
+ $path = str_replace('}','', $path );
731
+
732
+ include_once $path . 'includes/admin/templates/role/'. $box['id'] . '.php';
733
+ //wp_nonce_field( basename( __FILE__ ), 'um_admin_save_metabox_role_nonce' );
734
+ }
735
+
736
+
737
+ /**
738
+ * Load a form metabox
739
+ *
740
+ * @param $object
741
+ * @param $box
742
+ */
743
+ function load_metabox_form( $object, $box ) {
744
+ global $post;
745
+
746
+ $box['id'] = str_replace( 'um-admin-form-','', $box['id'] );
747
+
748
+ if ( $box['id'] == 'builder' ) {
749
+ UM()->builder()->form_id = get_the_ID();
750
+ }
751
+
752
+ preg_match('#\{.*?\}#s', $box['id'], $matches);
753
+
754
+ if ( isset( $matches[0] ) ) {
755
+ $path = $matches[0];
756
+ $box['id'] = preg_replace('~(\\{[^}]+\\})~','', $box['id'] );
757
+ } else {
758
+ $path = um_path;
759
+ }
760
+
761
+ $path = str_replace('{','', $path );
762
+ $path = str_replace('}','', $path );
763
+
764
+ include_once $path . 'includes/admin/templates/form/'. $box['id'] . '.php';
765
+
766
+ if ( ! $this->form_nonce_added ) {
767
+ $this->form_nonce_added = true;
768
+ wp_nonce_field( basename( __FILE__ ), 'um_admin_save_metabox_form_nonce' );
769
+ }
770
+ }
771
+
772
+
773
+ /**
774
+ * Load admin custom metabox
775
+ *
776
+ * @param $object
777
+ * @param $box
778
+ */
779
+ function load_metabox_custom( $object, $box ) {
780
+ global $post;
781
+
782
+ $box['id'] = str_replace('um-admin-custom-','', $box['id']);
783
+
784
+ preg_match('#\{.*?\}#s', $box['id'], $matches);
785
+
786
+ if ( isset($matches[0]) ){
787
+ $path = $matches[0];
788
+ $box['id'] = preg_replace('~(\\{[^}]+\\})~','', $box['id'] );
789
+ } else {
790
+ $path = um_path;
791
+ }
792
+
793
+ $path = str_replace('{','', $path );
794
+ $path = str_replace('}','', $path );
795
+
796
+ include_once $path . 'includes/admin/templates/'. $box['id'] . '.php';
797
+ if ( ! $this->custom_nonce_added ) {
798
+ $this->custom_nonce_added = true;
799
+ wp_nonce_field( basename( __FILE__ ), 'um_admin_save_metabox_custom_nonce' );
800
+ }
801
+ }
802
+
803
+
804
+ /**
805
+ * Add directory metabox
806
+ */
807
+ function add_metabox_directory() {
808
+ add_meta_box( 'um-admin-form-general', __( 'General Options', 'ultimate-member' ), array( &$this, 'load_metabox_directory' ), 'um_directory', 'normal', 'default' );
809
+ add_meta_box( 'um-admin-form-sorting', __( 'Sorting', 'ultimate-member' ), array( &$this, 'load_metabox_directory' ), 'um_directory', 'normal', 'default' );
810
+ add_meta_box( 'um-admin-form-profile', __( 'Profile Card', 'ultimate-member' ), array( &$this, 'load_metabox_directory' ), 'um_directory', 'normal', 'default' );
811
+ add_meta_box( 'um-admin-form-search', __( 'Search Options', 'ultimate-member' ), array( &$this, 'load_metabox_directory' ), 'um_directory', 'normal', 'default' );
812
+ add_meta_box( 'um-admin-form-pagination', __( 'Results &amp; Pagination', 'ultimate-member' ), array( &$this, 'load_metabox_directory' ), 'um_directory', 'normal', 'default' );
813
+ add_meta_box( 'um-admin-form-shortcode', __( 'Shortcode', 'ultimate-member' ), array( &$this, 'load_metabox_directory' ), 'um_directory', 'side', 'default' );
814
+ add_meta_box( 'um-admin-form-appearance', __( 'Styling: General', 'ultimate-member' ), array( &$this, 'load_metabox_directory'), 'um_directory', 'side', 'default' );
815
+ }
816
+
817
+
818
+ /**
819
+ * Add role metabox
820
+ */
821
+ function add_metabox_role() {
822
+ $callback = array( &$this, 'load_metabox_role' );
823
+
824
+ $roles_metaboxes = array(
825
+ array(
826
+ 'id' => 'um-admin-form-admin-permissions',
827
+ 'title' => __( 'Administrative Permissions', 'ultimate-member' ),
828
+ 'callback' => $callback,
829
+ 'screen' => 'um_role_meta',
830
+ 'context' => 'normal',
831
+ 'priority' => 'default'
832
+ ),
833
+ array(
834
+ 'id' => 'um-admin-form-general',
835
+ 'title' => __( 'General Permissions', 'ultimate-member' ),
836
+ 'callback' => $callback,
837
+ 'screen' => 'um_role_meta',
838
+ 'context' => 'normal',
839
+ 'priority' => 'default'
840
+ ),
841
+ array(
842
+ 'id' => 'um-admin-form-profile',
843
+ 'title' => __( 'Profile Access', 'ultimate-member' ),
844
+ 'callback' => $callback,
845
+ 'screen' => 'um_role_meta',
846
+ 'context' => 'normal',
847
+ 'priority' => 'default'
848
+ )
849
+ );
850
+
851
+ if ( ! isset( $_GET['id'] ) || 'administrator' !== sanitize_key( $_GET['id'] ) ) {
852
+ $roles_metaboxes[] = array(
853
+ 'id' => 'um-admin-form-home',
854
+ 'title' => __( 'Homepage Options', 'ultimate-member' ),
855
+ 'callback' => $callback,
856
+ 'screen' => 'um_role_meta',
857
+ 'context' => 'normal',
858
+ 'priority' => 'default'
859
+ );
860
+ }
861
+
862
+ $roles_metaboxes = array_merge( $roles_metaboxes, array(
863
+ array(
864
+ 'id' => 'um-admin-form-register',
865
+ 'title' => __( 'Registration Options', 'ultimate-member' ),
866
+ 'callback' => $callback,
867
+ 'screen' => 'um_role_meta',
868
+ 'context' => 'normal',
869
+ 'priority' => 'default'
870
+ ),
871
+ array(
872
+ 'id' => 'um-admin-form-login',
873
+ 'title' => __( 'Login Options', 'ultimate-member' ),
874
+ 'callback' => $callback,
875
+ 'screen' => 'um_role_meta',
876
+ 'context' => 'normal',
877
+ 'priority' => 'default'
878
+ ),
879
+ array(
880
+ 'id' => 'um-admin-form-logout',
881
+ 'title' => __( 'Logout Options', 'ultimate-member' ),
882
+ 'callback' => $callback,
883
+ 'screen' => 'um_role_meta',
884
+ 'context' => 'normal',
885
+ 'priority' => 'default'
886
+ ),
887
+ array(
888
+ 'id' => 'um-admin-form-delete',
889
+ 'title' => __( 'Delete Options', 'ultimate-member' ),
890
+ 'callback' => $callback,
891
+ 'screen' => 'um_role_meta',
892
+ 'context' => 'normal',
893
+ 'priority' => 'default'
894
+ ),
895
+ array(
896
+ 'id' => 'um-admin-form-publish',
897
+ 'title' => __( 'Publish', 'ultimate-member' ),
898
+ 'callback' => $callback,
899
+ 'screen' => 'um_role_meta',
900
+ 'context' => 'side',
901
+ 'priority' => 'default'
902
+ )
903
+ ) );
904
+
905
+ /**
906
+ * UM hook
907
+ *
908
+ * @type filter
909
+ * @title um_admin_role_metaboxes
910
+ * @description Extend metaboxes at Add/Edit User Role
911
+ * @input_vars
912
+ * [{"var":"$roles_metaboxes","type":"array","desc":"Metaboxes at Add/Edit UM Role"}]
913
+ * @change_log
914
+ * ["Since: 2.0"]
915
+ * @usage add_filter( 'um_admin_role_metaboxes', 'function_name', 10, 1 );
916
+ * @example
917
+ * <?php
918
+ * add_filter( 'um_admin_role_metaboxes', 'my_admin_role_metaboxes', 10, 1 );
919
+ * function my_admin_role_metaboxes( $roles_metaboxes ) {
920
+ * // your code here
921
+ * $roles_metaboxes[] = array(
922
+ * 'id' => 'um-admin-form-your-custom',
923
+ * 'title' => __( 'My Roles Metabox', 'ultimate-member' ),
924
+ * 'callback' => 'my-metabox-callback',
925
+ * 'screen' => 'um_role_meta',
926
+ * 'context' => 'side',
927
+ * 'priority' => 'default'
928
+ * );
929
+ *
930
+ * return $roles_metaboxes;
931
+ * }
932
+ * ?>
933
+ */
934
+ $roles_metaboxes = apply_filters( 'um_admin_role_metaboxes', $roles_metaboxes );
935
+
936
+ $wp_caps_metabox = false;
937
+ if ( ! empty( $_GET['id'] ) ) {
938
+ $data = get_option( 'um_role_' . sanitize_key( $_GET['id'] ) . '_meta' );
939
+ if ( ! empty( $data['_um_is_custom'] ) ) {
940
+ $wp_caps_metabox = true;
941
+ }
942
+ }
943
+ if ( 'add' == sanitize_key( $_GET['tab'] ) || $wp_caps_metabox ) {
944
+ $roles_metaboxes[] = array(
945
+ 'id' => 'um-admin-form-wp-capabilities',
946
+ 'title' => __( 'WP Capabilities', 'ultimate-member' ),
947
+ 'callback' => $callback,
948
+ 'screen' => 'um_role_meta',
949
+ 'context' => 'normal',
950
+ 'priority' => 'default'
951
+ );
952
+ }
953
+
954
+
955
+ foreach ( $roles_metaboxes as $metabox ) {
956
+ add_meta_box(
957
+ $metabox['id'],
958
+ $metabox['title'],
959
+ $metabox['callback'],
960
+ $metabox['screen'],
961
+ $metabox['context'],
962
+ $metabox['priority']
963
+ );
964
+ }
965
+ }
966
+
967
+
968
+ /**
969
+ * Add form metabox
970
+ */
971
+ function add_metabox_form() {
972
+
973
+ add_meta_box( 'um-admin-form-mode', __( 'Select Form Type', 'ultimate-member' ), array( &$this, 'load_metabox_form' ), 'um_form', 'normal', 'default' );
974
+ add_meta_box( 'um-admin-form-builder', __( 'Form Builder', 'ultimate-member' ), array( &$this, 'load_metabox_form' ), 'um_form', 'normal', 'default' );
975
+ add_meta_box( 'um-admin-form-shortcode', __( 'Shortcode', 'ultimate-member' ), array( &$this, 'load_metabox_form' ), 'um_form', 'side', 'default' );
976
+
977
+ add_meta_box( 'um-admin-form-register_customize', __( 'Customize this form', 'ultimate-member' ), array( &$this, 'load_metabox_form' ), 'um_form', 'side', 'default' );
978
+
979
+ /**
980
+ * UM hook
981
+ *
982
+ * @type action
983
+ * @title um_admin_custom_register_metaboxes
984
+ * @description Add custom metaboxes for register form
985
+ * @change_log
986
+ * ["Since: 2.0"]
987
+ * @usage add_action( 'um_admin_custom_register_metaboxes', 'function_name', 10 );
988
+ * @example
989
+ * <?php
990
+ * add_action( 'um_admin_custom_register_metaboxes', 'my_admin_custom_register_metaboxes', 10 );
991
+ * function my_admin_custom_register_metaboxes() {
992
+ * // your code here
993
+ * }
994
+ * ?>
995
+ */
996
+ do_action( 'um_admin_custom_register_metaboxes' );
997
+
998
+ add_meta_box( 'um-admin-form-profile_customize', __( 'Customize this form', 'ultimate-member' ), array( &$this, 'load_metabox_form' ), 'um_form', 'side', 'default' );
999
+ add_meta_box( 'um-admin-form-profile_settings', __( 'User Meta', 'ultimate-member' ), array( &$this, 'load_metabox_form' ), 'um_form', 'side', 'default' );
1000
+
1001
+ /**
1002
+ * UM hook
1003
+ *
1004
+ * @type action
1005
+ * @title um_admin_custom_profile_metaboxes
1006
+ * @description Add custom metaboxes for profile form
1007
+ * @change_log
1008
+ * ["Since: 2.0"]
1009
+ * @usage add_action( 'um_admin_custom_profile_metaboxes', 'function_name', 10 );
1010
+ * @example
1011
+ * <?php
1012
+ * add_action( 'um_admin_custom_profile_metaboxes', 'my_admin_custom_profile_metaboxes', 10 );
1013
+ * function my_admin_custom_profile_metaboxes() {
1014
+ * // your code here
1015
+ * }
1016
+ * ?>
1017
+ */
1018
+ do_action( 'um_admin_custom_profile_metaboxes' );
1019
+
1020
+ add_meta_box( 'um-admin-form-login_customize', __( 'Customize this form', 'ultimate-member' ), array( &$this, 'load_metabox_form' ), 'um_form', 'side', 'default' );
1021
+ add_meta_box( 'um-admin-form-login_settings', __( 'Options', 'ultimate-member' ), array( &$this, 'load_metabox_form' ), 'um_form', 'side', 'default' );
1022
+
1023
+ /**
1024
+ * UM hook
1025
+ *
1026
+ * @type action
1027
+ * @title um_admin_custom_login_metaboxes
1028
+ * @description Add custom metaboxes for login form
1029
+ * @change_log
1030
+ * ["Since: 2.0"]
1031
+ * @usage add_action( 'um_admin_custom_login_metaboxes', 'function_name', 10 );
1032
+ * @example
1033
+ * <?php
1034
+ * add_action( 'um_admin_custom_login_metaboxes', 'my_admin_custom_login_metaboxes', 10 );
1035
+ * function my_admin_custom_login_metaboxes() {
1036
+ * // your code here
1037
+ * }
1038
+ * ?>
1039
+ */
1040
+ do_action( 'um_admin_custom_login_metaboxes' );
1041
+ }
1042
+
1043
+
1044
+ /**
1045
+ * Save directory metabox
1046
+ *
1047
+ * @param $post_id
1048
+ * @param $post
1049
+ */
1050
+ function save_metabox_directory( $post_id, $post ) {
1051
+ global $wpdb;
1052
+
1053
+ // validate nonce
1054
+ if ( ! isset( $_POST['um_admin_save_metabox_directory_nonce'] ) ||
1055
+ ! wp_verify_nonce( $_POST['um_admin_save_metabox_directory_nonce'], basename( __FILE__ ) ) ) {
1056
+ return;
1057
+ }
1058
+
1059
+ // validate post type
1060
+ if ( $post->post_type != 'um_directory' ) {
1061
+ return;
1062
+ }
1063
+
1064
+ // validate user
1065
+ $post_type = get_post_type_object( $post->post_type );
1066
+ if ( ! current_user_can( $post_type->cap->edit_post, $post_id ) ) {
1067
+ return;
1068
+ }
1069
+
1070
+ $where = array( 'ID' => $post_id );
1071
+
1072
+ if ( empty( $_POST['post_title'] ) ) {
1073
+ $_POST['post_title'] = sprintf( __( 'Directory #%s', 'ultimate-member' ), $post_id );
1074
+ }
1075
+
1076
+ $wpdb->update( $wpdb->posts, array( 'post_title' => sanitize_text_field( $_POST['post_title'] ) ), $where );
1077
+
1078
+ do_action( 'um_before_member_directory_save', $post_id );
1079
+
1080
+ // save
1081
+ delete_post_meta( $post_id, '_um_roles' );
1082
+ delete_post_meta( $post_id, '_um_tagline_fields' );
1083
+ delete_post_meta( $post_id, '_um_reveal_fields' );
1084
+ delete_post_meta( $post_id, '_um_search_fields' );
1085
+ delete_post_meta( $post_id, '_um_roles_can_search' );
1086
+ delete_post_meta( $post_id, '_um_roles_can_filter' );
1087
+ delete_post_meta( $post_id, '_um_show_these_users' );
1088
+ delete_post_meta( $post_id, '_um_exclude_these_users' );
1089
+
1090
+ delete_post_meta( $post_id, '_um_search_filters' );
1091
+ delete_post_meta( $post_id, '_um_search_filters_gmt' );
1092
+
1093
+ delete_post_meta( $post_id, '_um_sorting_fields' );
1094
+
1095
+ //save metadata
1096
+ $metadata = UM()->admin()->sanitize_member_directory_meta( $_POST['um_metadata'] );
1097
+ foreach ( $metadata as $k => $v ) {
1098
+
1099
+ if ( $k == '_um_show_these_users' && trim( $v ) ) {
1100
+ $v = preg_split( '/[\r\n]+/', $v, -1, PREG_SPLIT_NO_EMPTY );
1101
+ }
1102
+
1103
+ if ( $k == '_um_exclude_these_users' && trim( $v ) ) {
1104
+ $v = preg_split( '/[\r\n]+/', $v, -1, PREG_SPLIT_NO_EMPTY );
1105
+ }
1106
+
1107
+ if ( strstr( $k, '_um_' ) ) {
1108
+
1109
+ if ( $k === '_um_is_default' ) {
1110
+
1111
+ $mode = UM()->query()->get_attr( 'mode', $post_id );
1112
+
1113
+ if ( ! empty( $mode ) ) {
1114
+
1115
+ $posts = $wpdb->get_col(
1116
+ "SELECT post_id
1117
+ FROM {$wpdb->postmeta}
1118
+ WHERE meta_key = '_um_mode' AND
1119
+ meta_value = 'directory'"
1120
+ );
1121
+
1122
+ foreach ( $posts as $p_id ) {
1123
+ delete_post_meta( $p_id, '_um_is_default' );
1124
+ }
1125
+
1126
+ }
1127
+
1128
+ }
1129
+
1130
+ $v = apply_filters( 'um_member_directory_meta_value_before_save', $v, $k, $post_id );
1131
+
1132
+ update_post_meta( $post_id, $k, $v );
1133
+
1134
+ }
1135
+ }
1136
+
1137
+ update_post_meta( $post_id, '_um_search_filters_gmt', (int) $_POST['um-gmt-offset'] );
1138
+ }
1139
+
1140
+
1141
+ /**
1142
+ * Save form metabox
1143
+ *
1144
+ * @param $post_id
1145
+ * @param $post
1146
+ */
1147
+ function save_metabox_form( $post_id, $post ) {
1148
+ global $wpdb;
1149
+
1150
+ // validate nonce
1151
+ if ( ! isset( $_POST['um_admin_save_metabox_form_nonce'] ) ||
1152
+ ! wp_verify_nonce( $_POST['um_admin_save_metabox_form_nonce'], basename( __FILE__ ) ) ) {
1153
+ return;
1154
+ }
1155
+
1156
+ // validate post type
1157
+ if ( $post->post_type != 'um_form' ) {
1158
+ return;
1159
+ }
1160
+
1161
+ // validate user
1162
+ $post_type = get_post_type_object( $post->post_type );
1163
+ if ( ! current_user_can( $post_type->cap->edit_post, $post_id ) ) {
1164
+ return;
1165
+ }
1166
+
1167
+ $where = array( 'ID' => $post_id );
1168
+ if ( empty( $_POST['post_title'] ) ) {
1169
+ $_POST['post_title'] = sprintf( __( 'Form #%s', 'ultimate-member' ), $post_id );
1170
+ }
1171
+ $wpdb->update( $wpdb->posts, array( 'post_title' => sanitize_text_field( $_POST['post_title'] ) ), $where );
1172
+
1173
+ // save
1174
+ delete_post_meta( $post_id, '_um_profile_metafields' );
1175
+
1176
+ $form_meta = UM()->admin()->sanitize_form_meta( $_POST['form'] );
1177
+
1178
+ foreach ( $form_meta as $k => $v ) {
1179
+ if ( strstr( $k, '_um_' ) ) {
1180
+ if ( $k === '_um_is_default' ) {
1181
+ $mode = UM()->query()->get_attr( 'mode', $post_id );
1182
+ if ( ! empty( $mode ) ) {
1183
+ $posts = $wpdb->get_col( $wpdb->prepare(
1184
+ "SELECT post_id
1185
+ FROM {$wpdb->postmeta}
1186
+ WHERE meta_key = '_um_mode' AND
1187
+ meta_value = %s",
1188
+ $mode
1189
+ ) );
1190
+ foreach ( $posts as $p_id ) {
1191
+ delete_post_meta( $p_id, '_um_is_default' );
1192
+ }
1193
+ }
1194
+ }
1195
+
1196
+ update_post_meta( $post_id, $k, $v );
1197
+ }
1198
+ }
1199
+
1200
+ }
1201
+
1202
+
1203
+ /**
1204
+ * Load modal content
1205
+ */
1206
+ function load_modal_content() {
1207
+ $screen = get_current_screen();
1208
+
1209
+ if ( isset( $screen->id ) && strstr( $screen->id, 'um_form' ) ) {
1210
+ foreach ( glob( um_path . 'includes/admin/templates/modal/forms/*.php' ) as $modal_content ) {
1211
+ include_once $modal_content;
1212
+ }
1213
+ }
1214
+
1215
+ if ( $this->init_icon ) {
1216
+ include_once um_path . 'includes/admin/templates/modal/forms/fonticons.php';
1217
+ }
1218
+
1219
+ if ( $screen->id == 'users' ) {
1220
+ include_once um_path . 'includes/admin/templates/modal/dynamic_registration_preview.php';
1221
+ }
1222
+
1223
+ // needed on forms only
1224
+ if ( ! isset( $this->is_loaded ) && isset( $screen->id ) && strstr( $screen->id, 'um_form' ) ) {
1225
+ $settings['textarea_rows'] = 8;
1226
+
1227
+ echo '<div class="um-hidden-editor-edit" style="display:none;">';
1228
+ wp_editor( '', 'um_editor_edit', $settings );
1229
+ echo '</div>';
1230
+
1231
+ echo '<div class="um-hidden-editor-new" style="display:none;">';
1232
+ wp_editor( '', 'um_editor_new', $settings );
1233
+ echo '</div>';
1234
+
1235
+ $this->is_loaded = true;
1236
+ }
1237
+ }
1238
+
1239
+
1240
+ /**
1241
+ * Show field input for edit at modal field
1242
+ *
1243
+ * @param $attribute
1244
+ * @param null $form_id
1245
+ * @param array $field_args
1246
+ */
1247
+ function field_input( $attribute, $form_id = null, $field_args = array() ) {
1248
+
1249
+ if ( $this->in_edit == true ) { // we're editing a field
1250
+ $real_attr = substr( $attribute, 1 );
1251
+ $this->edit_mode_value = isset( $this->edit_array[ $real_attr ] ) ? $this->edit_array[ $real_attr ] : null;
1252
+ }
1253
+
1254
+ switch ( $attribute ) {
1255
+
1256
+ default:
1257
+
1258
+ /**
1259
+ * UM hook
1260
+ *
1261
+ * @type action
1262
+ * @title um_admin_field_edit_hook{$attribute}
1263
+ * @description Integration for 3-d party fields at wp-admin
1264
+ * @input_vars
1265
+ * [{"var":"$edit_mode_value","type":"string","desc":"Post ID"}]
1266
+ * @change_log
1267
+ * ["Since: 2.0"]
1268
+ * @usage add_action( 'um_admin_field_edit_hook{$attribute}', 'function_name', 10, 1 );
1269
+ * @example
1270
+ * <?php
1271
+ * add_action( 'um_admin_field_edit_hook{$attribute}', 'my_admin_field_edit', 10, 1 );
1272
+ * function my_admin_field_edit( $edit_mode_value ) {
1273
+ * // your code here
1274
+ * }
1275
+ * ?>
1276
+ */
1277
+ do_action( "um_admin_field_edit_hook{$attribute}", $this->edit_mode_value, $form_id, $this->edit_array );
1278
+
1279
+ break;
1280
+
1281
+ case '_visibility':
1282
+ ?>
1283
+
1284
+ <p><label for="_visibility"><?php _e( 'Visibility', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Select where this field should appear. This option should only be changed on the profile form and allows you to show a field in one mode only (edit or view) or in both modes.','ultimate-member' ) ); ?></label>
1285
+ <select name="_visibility" id="_visibility" style="width: 100%">
1286
+ <option value="all" <?php selected( 'all', $this->edit_mode_value ); ?>><?php _e( 'View everywhere', 'ultimate-member' ) ?></option>
1287
+ <option value="edit" <?php selected( 'edit', $this->edit_mode_value ); ?>><?php _e( 'Edit mode only', 'ultimate-member' ) ?></option>
1288
+ <option value="view" <?php selected( 'view', $this->edit_mode_value ); ?>><?php _e( 'View mode only', 'ultimate-member' ) ?></option>
1289
+ </select>
1290
+ </p>
1291
+
1292
+ <?php
1293
+ break;
1294
+
1295
+ case '_conditional_action':
1296
+ case '_conditional_action1':
1297
+ case '_conditional_action2':
1298
+ case '_conditional_action3':
1299
+ case '_conditional_action4':
1300
+ ?>
1301
+
1302
+ <p>
1303
+ <select name="<?php echo esc_attr( $attribute ); ?>" id="<?php echo esc_attr( $attribute ); ?>" style="width: 90px">
1304
+
1305
+ <option></option>
1306
+
1307
+ <?php $actions = array( 'show', 'hide' );
1308
+ foreach ( $actions as $action ) { ?>
1309
+
1310
+ <option value="<?php echo esc_attr( $action ); ?>" <?php selected( $action, $this->edit_mode_value ); ?>><?php echo $action; ?></option>
1311
+
1312
+ <?php } ?>
1313
+
1314
+ </select>
1315
+
1316
+ &nbsp;&nbsp;<?php _e( 'If' ); ?>
1317
+ </p>
1318
+
1319
+ <?php
1320
+ break;
1321
+
1322
+ case '_conditional_field':
1323
+ case '_conditional_field1':
1324
+ case '_conditional_field2':
1325
+ case '_conditional_field3':
1326
+ case '_conditional_field4':
1327
+ ?>
1328
+
1329
+ <p>
1330
+ <select name="<?php echo esc_attr( $attribute ); ?>" id="<?php echo esc_attr( $attribute ); ?>" style="width: 150px">
1331
+
1332
+ <option></option>
1333
+
1334
+ <?php $fields = UM()->query()->get_attr( 'custom_fields', $form_id );
1335
+
1336
+ foreach ( $fields as $key => $array ) {
1337
+ if ( isset( $array['title'] ) &&
1338
+ ( ! isset( $this->edit_array['metakey'] ) || $key != $this->edit_array['metakey'] ) ) { ?>
1339
+
1340
+ <option value="<?php echo esc_attr( $key ) ?>" <?php selected( $key, $this->edit_mode_value ) ?>><?php echo $array['title'] ?></option>
1341
+
1342
+ <?php }
1343
+ } ?>
1344
+
1345
+ </select>
1346
+ </p>
1347
+
1348
+ <?php
1349
+ break;
1350
+
1351
+ case '_conditional_operator':
1352
+ case '_conditional_operator1':
1353
+ case '_conditional_operator2':
1354
+ case '_conditional_operator3':
1355
+ case '_conditional_operator4':
1356
+ ?>
1357
+
1358
+ <p>
1359
+ <select name="<?php echo esc_attr( $attribute ); ?>" id="<?php echo esc_attr( $attribute ); ?>" style="width: 150px">
1360
+
1361
+ <option></option>
1362
+
1363
+ <?php $operators = array(
1364
+ 'empty',
1365
+ 'not empty',
1366
+ 'equals to',
1367
+ 'not equals',
1368
+ 'greater than',
1369
+ 'less than',
1370
+ 'contains'
1371
+ );
1372
+
1373
+ foreach ( $operators as $operator ) { ?>
1374
+
1375
+ <option value="<?php echo esc_attr( $operator ); ?>" <?php selected( $operator, $this->edit_mode_value ); ?>><?php echo $operator; ?></option>
1376
+
1377
+ <?php } ?>
1378
+
1379
+ </select>
1380
+ </p>
1381
+
1382
+ <?php
1383
+ break;
1384
+
1385
+ case '_conditional_value':
1386
+ case '_conditional_value1':
1387
+ case '_conditional_value2':
1388
+ case '_conditional_value3':
1389
+ case '_conditional_value4':
1390
+ ?>
1391
+
1392
+ <p>
1393
+ <input type="text" name="<?php echo esc_attr( $attribute ); ?>" id="<?php echo esc_attr( $attribute ); ?>" value="<?php echo isset( $this->edit_mode_value ) ? $this->edit_mode_value : ''; ?>" placeholder="<?php esc_attr_e( 'Value', 'ultimate-member' ); ?>" style="width: 150px!important;position: relative;top: -1px;" />
1394
+ </p>
1395
+
1396
+ <?php
1397
+ break;
1398
+
1399
+ case '_validate':
1400
+ ?>
1401
+
1402
+ <p><label for="_validate"><?php _e( 'Validate', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Does this field require a special validation', 'ultimate-member' ) ); ?></label>
1403
+ <select name="_validate" id="_validate" data-placeholder="<?php esc_attr_e( 'Select a validation type...', 'ultimate-member' ) ?>" class="um-adm-conditional" data-cond1="custom" data-cond1-show="_custom_validate" style="width: 100%">
1404
+
1405
+ <option value="" <?php selected( '', $this->edit_mode_value ); ?>></option>
1406
+
1407
+ <?php foreach( UM()->builtin()->validation_types() as $key => $name ) { ?>
1408
+ <?php
1409
+ /**
1410
+ * UM hook
1411
+ *
1412
+ * @type filter
1413
+ * @title um_builtin_validation_types_continue_loop
1414
+ * @description Builtin Validation Types
1415
+ * @input_vars
1416
+ * [{"var":"$continue","type":"bool","desc":"Validate?"},
1417
+ * {"var":"$key","type":"string","desc":"Field Key"},
1418
+ * {"var":"$form_id","type":"int","desc":"Form ID"},
1419
+ * {"var":"$field_args","type":"array","desc":"Field Settings"}]
1420
+ * @change_log
1421
+ * ["Since: 2.0"]
1422
+ * @usage add_filter( 'um_builtin_validation_types_continue_loop', 'function_name', 10, 4 );
1423
+ * @example
1424
+ * <?php
1425
+ * add_filter( 'um_builtin_validation_types_continue_loop', 'my_builtin_validation_types', 10, 4 );
1426
+ * function my_builtin_validation_types( $continue, $key, $form_id, $field_args ) {
1427
+ * // your code here
1428
+ * return $continue;
1429
+ * }
1430
+ * ?>
1431
+ */
1432
+ $continue = apply_filters( "um_builtin_validation_types_continue_loop", true, $key, $form_id, $field_args );
1433
+ if ( $continue ) { ?>
1434
+ <option value="<?php echo esc_attr( $key ); ?>" <?php selected( $key, $this->edit_mode_value ); ?>><?php echo $name; ?></option>
1435
+ <?php } ?>
1436
+ <?php } ?>
1437
+
1438
+ </select>
1439
+ </p>
1440
+
1441
+ <?php
1442
+ break;
1443
+
1444
+ case '_custom_validate':
1445
+ ?>
1446
+
1447
+ <p class="_custom_validate"><label for="_custom_validate"><?php _e( 'Custom Action', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'If you want to apply your custom validation, you can use action hooks to add custom validation. Please refer to documentation for further details.', 'ultimate-member' ) ); ?></label>
1448
+ <input type="text" name="_custom_validate" id="_custom_validate" value="<?php echo ( $this->edit_mode_value ) ? $this->edit_mode_value : ''; ?>" />
1449
+ </p>
1450
+
1451
+ <?php
1452
+ break;
1453
+
1454
+ case '_icon':
1455
+
1456
+ if ( $this->set_field_type == 'row' ) {
1457
+ $back = 'UM_edit_row';
1458
+
1459
+ ?>
1460
+
1461
+ <p class="_heading_text"><label for="_icon"><?php _e( 'Icon', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Select an icon to appear in the field. Leave blank if you do not want an icon to show in the field.', 'ultimate-member' ) ); ?></label>
1462
+
1463
+ <a href="javascript:void(0);" class="button" data-modal="UM_fonticons" data-modal-size="normal" data-dynamic-content="um_admin_fonticon_selector" data-arg1="" data-arg2="" data-back="<?php echo esc_attr( $back ); ?>"><?php _e( 'Choose Icon', 'ultimate-member' ) ?></a>
1464
+
1465
+ <span class="um-admin-icon-value"><?php if ( $this->edit_mode_value ) { ?><i class="<?php echo $this->edit_mode_value; ?>"></i><?php } else { ?><?php _e( 'No Icon', 'ultimate-member' ) ?><?php } ?></span>
1466
+
1467
+ <input type="hidden" name="_icon" id="_icon" value="<?php echo (isset( $this->edit_mode_value ) ) ? $this->edit_mode_value : ''; ?>" />
1468
+
1469
+ <?php if ( $this->edit_mode_value ) { ?>
1470
+ <span class="um-admin-icon-clear show"><i class="um-icon-android-cancel"></i></span>
1471
+ <?php } else { ?>
1472
+ <span class="um-admin-icon-clear"><i class="um-icon-android-cancel"></i></span>
1473
+ <?php } ?>
1474
+
1475
+ </p>
1476
+
1477
+ <?php } else {
1478
+
1479
+ if ( $this->in_edit ) {
1480
+ $back = 'UM_edit_field';
1481
+ } else {
1482
+ $back = 'UM_add_field';
1483
+ }
1484
+
1485
+ ?>
1486
+
1487
+ <div class="um-admin-tri">
1488
+
1489
+ <p><label for="_icon"><?php _e( 'Icon', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Select an icon to appear in the field. Leave blank if you do not want an icon to show in the field.', 'ultimate-member' ) ); ?></label>
1490
+
1491
+ <a href="javascript:void(0);" class="button" data-modal="UM_fonticons" data-modal-size="normal" data-dynamic-content="um_admin_fonticon_selector" data-arg1="" data-arg2="" data-back="<?php echo esc_attr( $back ); ?>"><?php _e( 'Choose Icon', 'ultimate-member' ) ?></a>
1492
+
1493
+ <span class="um-admin-icon-value"><?php if ( $this->edit_mode_value ) { ?><i class="<?php echo $this->edit_mode_value; ?>"></i><?php } else { ?><?php _e( 'No Icon', 'ultimate-member' ) ?><?php } ?></span>
1494
+
1495
+ <input type="hidden" name="_icon" id="_icon" value="<?php echo (isset( $this->edit_mode_value ) ) ? $this->edit_mode_value : ''; ?>" />
1496
+
1497
+ <?php if ( $this->edit_mode_value ) { ?>
1498
+ <span class="um-admin-icon-clear show"><i class="um-icon-android-cancel"></i></span>
1499
+ <?php } else { ?>
1500
+ <span class="um-admin-icon-clear"><i class="um-icon-android-cancel"></i></span>
1501
+ <?php } ?>
1502
+
1503
+ </p>
1504
+
1505
+ </div>
1506
+
1507
+ <?php
1508
+
1509
+ }
1510
+
1511
+ break;
1512
+
1513
+ case '_css_class':
1514
+ ?>
1515
+
1516
+ <p><label for="_css_class"><?php _e( 'CSS Class', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Specify a custom CSS class to be applied to this element', 'ultimate-member' ) ); ?></label>
1517
+ <input type="text" name="_css_class" id="_css_class" value="<?php echo ( $this->edit_mode_value ) ? $this->edit_mode_value : ''; ?>" />
1518
+ </p>
1519
+
1520
+ <?php
1521
+ break;
1522
+
1523
+ case '_width':
1524
+ ?>
1525
+
1526
+ <p><label for="_width"><?php _e( 'Thickness (in pixels)', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'This is the width in pixels, e.g. 4 or 2, etc', 'ultimate-member' ) ); ?></label>
1527
+ <input type="text" name="_width" id="_width" value="<?php echo ( $this->edit_mode_value ) ? $this->edit_mode_value : 4; ?>" />
1528
+ </p>
1529
+
1530
+ <?php
1531
+ break;
1532
+
1533
+ case '_divider_text':
1534
+ ?>
1535
+
1536
+ <p><label for="_divider_text"><?php _e( 'Optional Text', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Optional text to include with the divider', 'ultimate-member' ) ); ?></label>
1537
+ <input type="text" name="_divider_text" id="_divider_text" value="<?php echo ( $this->edit_mode_value ) ? $this->edit_mode_value : ''; ?>" />
1538
+ </p>
1539
+
1540
+ <?php
1541
+ break;
1542
+
1543
+ case '_padding':
1544
+ ?>
1545
+
1546
+ <p><label for="_padding"><?php _e( 'Padding', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Set padding for this section', 'ultimate-member' ) ); ?></label>
1547
+ <input type="text" name="_padding" id="_padding" value="<?php echo ( $this->edit_mode_value ) ? $this->edit_mode_value : '0px 0px 0px 0px'; ?>" />
1548
+ </p>
1549
+
1550
+ <?php
1551
+ break;
1552
+
1553
+ case '_margin':
1554
+ ?>
1555
+
1556
+ <p><label for="_margin"><?php _e( 'Margin', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Set margin for this section', 'ultimate-member' ) ); ?></label>
1557
+ <input type="text" name="_margin" id="_margin" value="<?php echo ( $this->edit_mode_value ) ? $this->edit_mode_value : '0px 0px 30px 0px'; ?>" />
1558
+ </p>
1559
+
1560
+ <?php
1561
+ break;
1562
+
1563
+ case '_border':
1564
+ ?>
1565
+
1566
+ <p><label for="_border"><?php _e( 'Border', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Set border for this section', 'ultimate-member' ) ); ?></label>
1567
+ <input type="text" name="_border" id="_border" value="<?php echo ( $this->edit_mode_value ) ? $this->edit_mode_value : '0px 0px 0px 0px'; ?>" />
1568
+ </p>
1569
+
1570
+ <?php
1571
+ break;
1572
+
1573
+ case '_borderstyle':
1574
+ ?>
1575
+
1576
+ <p><label for="_borderstyle"><?php _e( 'Style', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Choose the border style', 'ultimate-member' ) ); ?></label>
1577
+ <select name="_borderstyle" id="_borderstyle" style="width: 100%">
1578
+ <option value="solid" <?php selected( 'solid', $this->edit_mode_value ); ?>><?php _e( 'Solid', 'ultimate-member' ) ?></option>
1579
+ <option value="dotted" <?php selected( 'dotted', $this->edit_mode_value ); ?>><?php _e( 'Dotted', 'ultimate-member' ) ?></option>
1580
+ <option value="dashed" <?php selected( 'dashed', $this->edit_mode_value ); ?>><?php _e( 'Dashed', 'ultimate-member' ) ?></option>
1581
+ <option value="double" <?php selected( 'double', $this->edit_mode_value ); ?>><?php _e( 'Double', 'ultimate-member' ) ?></option>
1582
+ </select>
1583
+ </p>
1584
+
1585
+ <?php
1586
+ break;
1587
+
1588
+ case '_borderradius':
1589
+ ?>
1590
+
1591
+ <p><label for="_borderradius"><?php _e( 'Border Radius', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Rounded corners can be applied by setting a pixels value here. e.g. 5px', 'ultimate-member' ) ); ?></label>
1592
+ <input type="text" name="_borderradius" id="_borderradius" value="<?php echo ( $this->edit_mode_value ) ? $this->edit_mode_value : '0px'; ?>" />
1593
+ </p>
1594
+
1595
+ <?php
1596
+ break;
1597
+
1598
+ case '_bordercolor':
1599
+ ?>
1600
+
1601
+ <p><label for="_bordercolor"><?php _e( 'Border Color', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Give a color to this border', 'ultimate-member' ) ); ?></label>
1602
+ <input type="text" name="_bordercolor" id="_bordercolor" class="um-admin-colorpicker" data-default-color="" value="<?php echo ( $this->edit_mode_value ) ? $this->edit_mode_value : ''; ?>" />
1603
+ </p>
1604
+
1605
+ <?php
1606
+ break;
1607
+
1608
+ case '_heading':
1609
+ ?>
1610
+
1611
+ <p><label for="_heading"><?php _e( 'Enable Row Heading', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Whether to enable a heading for this row', 'ultimate-member' ) ); ?></label>
1612
+ <input type="checkbox" name="_heading" id="_heading" value="1" <?php checked( isset( $this->edit_mode_value ) ? $this->edit_mode_value : 0 ) ?> class="um-adm-conditional" data-cond1="1" data-cond1-show="_heading_text" data-cond1-hide="xxx" />
1613
+ </p>
1614
+
1615
+ <?php
1616
+ break;
1617
+
1618
+ case '_heading_text':
1619
+ ?>
1620
+
1621
+ <p class="_heading_text"><label for="_heading_text"><?php _e( 'Heading Text', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Enter the row heading text here', 'ultimate-member' ) ); ?></label>
1622
+ <input type="text" name="_heading_text" id="_heading_text" value="<?php echo ( $this->edit_mode_value ) ? $this->edit_mode_value : ''; ?>" />
1623
+ </p>
1624
+
1625
+ <?php
1626
+ break;
1627
+
1628
+ case '_background':
1629
+ ?>
1630
+
1631
+ <p><label for="_background"><?php _e( 'Background Color', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'This will be the background of entire section', 'ultimate-member' ) ); ?></label>
1632
+ <input type="text" name="_background" id="_background" class="um-admin-colorpicker" data-default-color="" value="<?php echo ( $this->edit_mode_value ) ? $this->edit_mode_value : ''; ?>" />
1633
+ </p>
1634
+
1635
+ <?php
1636
+ break;
1637
+
1638
+ case '_heading_background_color':
1639
+ ?>
1640
+
1641
+ <p class="_heading_text"><label for="_heading_background_color"><?php _e( 'Heading Background Color', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'This will be the background of the heading section', 'ultimate-member' ) ); ?></label>
1642
+ <input type="text" name="_heading_background_color" id="_heading_background_color" class="um-admin-colorpicker" data-default-color="" value="<?php echo ( $this->edit_mode_value ) ? $this->edit_mode_value : ''; ?>" />
1643
+ </p>
1644
+
1645
+ <?php
1646
+ break;
1647
+
1648
+ case '_heading_text_color':
1649
+ ?>
1650
+
1651
+ <p class="_heading_text"><label for="_heading_text_color"><?php _e( 'Heading Text Color', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'This will be the text color of heading part only', 'ultimate-member' ) ); ?></label>
1652
+ <input type="text" name="_heading_text_color" id="_heading_text_color" class="um-admin-colorpicker" data-default-color="" value="<?php echo ( $this->edit_mode_value ) ? $this->edit_mode_value : ''; ?>" />
1653
+ </p>
1654
+
1655
+ <?php
1656
+ break;
1657
+
1658
+ case '_text_color':
1659
+ ?>
1660
+
1661
+ <p><label for="_text_color"><?php _e( 'Text Color', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'This will be the text color of entire section', 'ultimate-member' ) ); ?></label>
1662
+ <input type="text" name="_text_color" id="_text_color" class="um-admin-colorpicker" data-default-color="" value="<?php echo ( $this->edit_mode_value ) ? $this->edit_mode_value : ''; ?>" />
1663
+ </p>
1664
+
1665
+ <?php
1666
+ break;
1667
+
1668
+ case '_icon_color':
1669
+ ?>
1670
+
1671
+ <p class="_heading_text"><label for="_icon_color"><?php _e( 'Icon Color', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'This will be the color of selected icon. By default It will be the same color as heading text color', 'ultimate-member' ) ); ?></label>
1672
+ <input type="text" name="_icon_color" id="_icon_color" class="um-admin-colorpicker" data-default-color="" value="<?php echo ( $this->edit_mode_value ) ? $this->edit_mode_value : ''; ?>" />
1673
+ </p>
1674
+
1675
+ <?php
1676
+ break;
1677
+
1678
+ case '_color':
1679
+ ?>
1680
+
1681
+ <p><label for="_color"><?php _e( 'Color', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Select a color for this divider', 'ultimate-member' ) ); ?></label>
1682
+ <input type="text" name="_color" id="_color" class="um-admin-colorpicker" data-default-color="#eeeeee" value="<?php echo ( $this->edit_mode_value ) ? $this->edit_mode_value : '#eeeeee'; ?>" />
1683
+ </p>
1684
+
1685
+ <?php
1686
+ break;
1687
+
1688
+ case '_url_text':
1689
+ ?>
1690
+
1691
+ <p><label for="_url_text"><?php _e( 'URL Alt Text', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Entering custom text here will replace the url with a text link', 'ultimate-member' ) ); ?></label>
1692
+ <input type="text" name="_url_text" id="_url_text" value="<?php echo ( $this->edit_mode_value ) ? $this->edit_mode_value : ''; ?>" />
1693
+ </p>
1694
+
1695
+ <?php
1696
+ break;
1697
+
1698
+ case '_url_target':
1699
+ ?>
1700
+
1701
+ <p><label for="_url_target"><?php _e( 'Link Target', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Choose whether to open this link in same window or in a new window', 'ultimate-member' ) ); ?></label>
1702
+ <select name="_url_target" id="_url_target" style="width: 100%">
1703
+ <option value="_blank" <?php selected( '_blank', $this->edit_mode_value ); ?>><?php _e( 'Open in new window', 'ultimate-member' ) ?></option>
1704
+ <option value="_self" <?php selected( '_self', $this->edit_mode_value ); ?>><?php _e( 'Same window', 'ultimate-member' ) ?></option>
1705
+ </select>
1706
+ </p>
1707
+
1708
+ <?php
1709
+ break;
1710
+
1711
+ case '_url_rel':
1712
+ ?>
1713
+
1714
+ <p><label for="_url_rel"><?php _e( 'SEO Follow', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Whether to follow or nofollow this link by search engines', 'ultimate-member' ) ); ?></label>
1715
+ <select name="_url_rel" id="_url_rel" style="width: 100%">
1716
+ <option value="follow" <?php selected( 'follow', $this->edit_mode_value ); ?>><?php _e( 'Follow', 'ultimate-member' ) ?></option>
1717
+ <option value="nofollow" <?php selected( 'nofollow', $this->edit_mode_value ); ?>><?php _e( 'No-Follow', 'ultimate-member' ) ?></option>
1718
+ </select>
1719
+ </p>
1720
+
1721
+ <?php
1722
+ break;
1723
+
1724
+ case '_force_good_pass':
1725
+ ?>
1726
+
1727
+ <p><label for="_force_good_pass"><?php _e( 'Force strong password?', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Turn on to force users to create a strong password (A combination of one lowercase letter, one uppercase letter, and one number). If turned on this option is only applied to register forms and not to login forms.', 'ultimate-member' ) ); ?></label>
1728
+ <input type="checkbox" name="_force_good_pass" id="_force_good_pass" value="1" <?php checked( isset( $this->edit_mode_value ) ? $this->edit_mode_value : UM()->options()->get( 'require_strongpass' ) ) ?> />
1729
+ </p>
1730
+
1731
+ <?php
1732
+ break;
1733
+
1734
+ case '_force_confirm_pass':
1735
+ ?>
1736
+
1737
+ <p><label for="_force_confirm_pass"><?php _e( 'Automatically add a confirm password field?', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Turn on to add a confirm password field. If turned on the confirm password field will only show on register forms and not on login forms.', 'ultimate-member' ) ); ?></label>
1738
+ <input type="checkbox" name="_force_confirm_pass" id="_force_confirm_pass" value="1" <?php checked( isset( $this->edit_mode_value ) ? $this->edit_mode_value : 0 ) ?> class="um-adm-conditional" data-cond1="1" data-cond1-show="_label_confirm_pass" data-cond1-hide="xxx" />
1739
+ </p>
1740
+
1741
+ <?php
1742
+ break;
1743
+
1744
+ case '_style':
1745
+ ?>
1746
+
1747
+ <p><label for="_style"><?php _e( 'Style', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'This is the line-style of divider', 'ultimate-member' ) ); ?></label>
1748
+ <select name="_style" id="_style" style="width: 100%">
1749
+ <option value="solid" <?php selected( 'solid', $this->edit_mode_value ); ?>><?php _e( 'Solid', 'ultimate-member' ) ?></option>
1750
+ <option value="dotted" <?php selected( 'dotted', $this->edit_mode_value ); ?>><?php _e( 'Dotted', 'ultimate-member' ) ?></option>
1751
+ <option value="dashed" <?php selected( 'dashed', $this->edit_mode_value ); ?>><?php _e( 'Dashed', 'ultimate-member' ) ?></option>
1752
+ <option value="double" <?php selected( 'double', $this->edit_mode_value ); ?>><?php _e( 'Double', 'ultimate-member' ) ?></option>
1753
+ </select>
1754
+ </p>
1755
+
1756
+ <?php
1757
+ break;
1758
+
1759
+ case '_intervals':
1760
+
1761
+ ?>
1762
+
1763
+ <p><label for="_intervals"><?php _e( 'Time Intervals (in minutes)', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Choose the minutes interval between each time in the time picker.', 'ultimate-member' ) ); ?></label>
1764
+ <input type="text" name="_intervals" id="_intervals" value="<?php echo ( $this->edit_mode_value ) ? $this->edit_mode_value : 60; ?>" placeholder="<?php esc_attr_e( 'e.g. 30, 60, 120', 'ultimate-member' ) ?>" />
1765
+ </p>
1766
+
1767
+ <?php
1768
+ break;
1769
+
1770
+
1771
+ case '_format':
1772
+
1773
+ if ( $this->set_field_type == 'date' ) {
1774
+ ?>
1775
+
1776
+ <p><label for="_format"><?php _e( 'Date User-Friendly Format', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'The display format of the date which is visible to user.', 'ultimate-member' ) ); ?></label>
1777
+ <select name="_format" id="_format" style="width: 100%">
1778
+ <option value="j M Y" <?php selected( 'j M Y', $this->edit_mode_value ); ?>><?php echo UM()->datetime()->get_time('j M Y'); ?></option>
1779
+ <option value="M j Y" <?php selected( 'M j Y', $this->edit_mode_value ); ?>><?php echo UM()->datetime()->get_time('M j Y'); ?></option>
1780
+ <option value="j F Y" <?php selected( 'j F Y', $this->edit_mode_value ); ?>><?php echo UM()->datetime()->get_time('j F Y'); ?></option>
1781
+ <option value="F j Y" <?php selected( 'F j Y', $this->edit_mode_value ); ?>><?php echo UM()->datetime()->get_time('F j Y'); ?></option>
1782
+ </select>
1783
+ </p>
1784
+
1785
+ <?php } else { ?>
1786
+
1787
+ <p><label for="_format"><?php _e( 'Time Format', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Choose the displayed time-format for this field', 'ultimate-member' ) ); ?></label>
1788
+ <select name="_format" id="_format" style="width: 100%">
1789
+ <option value="g:i a" <?php selected( 'g:i a', $this->edit_mode_value ); ?>><?php echo UM()->datetime()->get_time('g:i a'); ?><?php _e( '( 12-hr format )', 'ultimate-member' ) ?></option>
1790
+ <option value="g:i A" <?php selected( 'g:i A', $this->edit_mode_value ); ?>><?php echo UM()->datetime()->get_time('g:i A'); ?><?php _e( '( 12-hr format )', 'ultimate-member' ) ?></option>
1791
+ <option value="H:i" <?php selected( 'H:i', $this->edit_mode_value ); ?>><?php echo UM()->datetime()->get_time('H:i'); ?><?php _e( '( 24-hr format )', 'ultimate-member' ) ?></option>
1792
+ </select>
1793
+ </p>
1794
+
1795
+ <?php
1796
+ }
1797
+ break;
1798
+
1799
+ case '_format_custom':
1800
+ ?>
1801
+
1802
+ <p><label for="_format_custom"><?php _e( 'Use custom Date format', 'ultimate-member' ); ?> <?php UM()->tooltip( __( 'This option overrides "Date User-Friendly Format" option. See https://www.php.net/manual/en/function.date.php', 'ultimate-member' ) ); ?></label>
1803
+ <input type="text" name="_format_custom" id="_format_custom" value="<?php echo htmlspecialchars( $this->edit_mode_value, ENT_QUOTES ); ?>" placeholder="j M Y" />
1804
+ </p>
1805
+
1806
+ <?php
1807
+ break;
1808
+
1809
+ case '_pretty_format':
1810
+ ?>
1811
+
1812
+ <p><label for="_pretty_format"><?php _e( 'Displayed Date Format', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Whether you wish to show the date in full or only show the years e.g. 25 Years', 'ultimate-member' ) ); ?></label>
1813
+ <select name="_pretty_format" id="_pretty_format" style="width: 100%">
1814
+ <option value="0" <?php selected( 0, $this->edit_mode_value ); ?>><?php _e( 'Show full date', 'ultimate-member' ) ?></option>
1815
+ <option value="1" <?php selected( 1, $this->edit_mode_value ); ?>><?php _e( 'Show years only', 'ultimate-member' ) ?></option>
1816
+ </select>
1817
+ </p>
1818
+
1819
+ <?php
1820
+ break;
1821
+
1822
+ case '_disabled_weekdays':
1823
+
1824
+ if ( isset( $this->edit_mode_value ) && is_array( $this->edit_mode_value ) ) {
1825
+ $values = $this->edit_mode_value;
1826
+ } else {
1827
+ $values = array('');
1828
+ }
1829
+ ?>
1830
+
1831
+ <p><label for="_disabled_weekdays"><?php _e( 'Disable specific weekdays', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Disable specific week days from being available for selection in this date picker', 'ultimate-member' ) ); ?></label>
1832
+ <select name="_disabled_weekdays[]" id="_disabled_weekdays" multiple="multiple" style="width: 100%">
1833
+ <option value="1" <?php if ( in_array( 1, $values ) ) { echo 'selected'; } ?>><?php _e( 'Sunday', 'ultimate-member' ) ?></option>
1834
+ <option value="2" <?php if ( in_array( 2, $values ) ) { echo 'selected'; } ?>><?php _e( 'Monday', 'ultimate-member' ) ?></option>
1835
+ <option value="3" <?php if ( in_array( 3, $values ) ) { echo 'selected'; } ?>><?php _e( 'Tuesday', 'ultimate-member' ) ?></option>
1836
+ <option value="4" <?php if ( in_array( 4, $values ) ) { echo 'selected'; } ?>><?php _e( 'Wednesday', 'ultimate-member' ) ?></option>
1837
+ <option value="5" <?php if ( in_array( 5, $values ) ) { echo 'selected'; } ?>><?php _e( 'Thursday', 'ultimate-member' ) ?></option>
1838
+ <option value="6" <?php if ( in_array( 6, $values ) ) { echo 'selected'; } ?>><?php _e( 'Friday', 'ultimate-member' ) ?></option>
1839
+ <option value="7" <?php if ( in_array( 7, $values ) ) { echo 'selected'; } ?>><?php _e( 'Saturday', 'ultimate-member' ) ?></option>
1840
+ </select>
1841
+ </p>
1842
+
1843
+ <?php
1844
+ break;
1845
+
1846
+ case '_years':
1847
+ ?>
1848
+
1849
+ <p class="_years"><label for="_years"><?php _e( 'Number of Years to pick from', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Number of years available for the date selection. Default to last 50 years', 'ultimate-member' ) ); ?></label>
1850
+ <input type="text" name="_years" id="_years" value="<?php echo ( $this->edit_mode_value ) ? $this->edit_mode_value : 50; ?>" />
1851
+ </p>
1852
+
1853
+ <?php
1854
+ break;
1855
+
1856
+ case '_years_x':
1857
+ ?>
1858
+
1859
+ <p class="_years"><label for="_years_x"><?php _e( 'Years Selection', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'This decides which years should be shown relative to today date', 'ultimate-member' ) ); ?></label>
1860
+ <select name="_years_x" id="_years_x" style="width: 100%">
1861
+ <option value="equal" <?php selected( 'equal', $this->edit_mode_value ); ?>><?php _e( 'Equal years before / after today', 'ultimate-member' ) ?></option>
1862
+ <option value="past" <?php selected( 'past', $this->edit_mode_value ); ?>><?php _e( 'Past years only', 'ultimate-member' ) ?></option>
1863
+ <option value="future" <?php selected( 'future', $this->edit_mode_value ); ?>><?php _e( 'Future years only', 'ultimate-member' ) ?></option>
1864
+ </select>
1865
+ </p>
1866
+
1867
+ <?php
1868
+ break;
1869
+
1870
+ case '_range_start':
1871
+ ?>
1872
+
1873
+ <p class="_date_range"><label for="_range_start"><?php _e( 'Date Range Start', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Set the minimum date/day in range in the format YYYY/MM/DD', 'ultimate-member' ) ); ?></label>
1874
+ <input type="text" name="_range_start" id="_range_start" value="<?php echo $this->edit_mode_value; ?>" placeholder="<?php esc_attr_e( 'YYYY/MM/DD', 'ultimate-member' ) ?>" />
1875
+ </p>
1876
+
1877
+ <?php
1878
+ break;
1879
+
1880
+ case '_range_end':
1881
+ ?>
1882
+
1883
+ <p class="_date_range"><label for="_range_end"><?php _e( 'Date Range End', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Set the maximum date/day in range in the format YYYY/MM/DD', 'ultimate-member' ) ); ?></label>
1884
+ <input type="text" name="_range_end" id="_range_end" value="<?php echo $this->edit_mode_value; ?>" placeholder="<?php esc_attr_e( 'YYYY/MM/DD', 'ultimate-member' ) ?>" />
1885
+ </p>
1886
+
1887
+ <?php
1888
+ break;
1889
+
1890
+ case '_range':
1891
+ ?>
1892
+
1893
+ <p><label for="_range"><?php _e( 'Set Date Range', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Whether to show a specific number of years or specify a date range to be available for the date picker.', 'ultimate-member' ) ); ?></label>
1894
+ <select name="_range" id="_range" class="um-adm-conditional" data-cond1='years' data-cond1-show='_years' data-cond2="date_range" data-cond2-show="_date_range" style="width: 100%">
1895
+ <option value="years" <?php selected( 'years', $this->edit_mode_value ); ?>><?php _e( 'Fixed Number of Years', 'ultimate-member' ) ?></option>
1896
+ <option value="date_range" <?php selected( 'date_range', $this->edit_mode_value ); ?>><?php _e( 'Specific Date Range', 'ultimate-member' ) ?></option>
1897
+ </select>
1898
+ </p>
1899
+
1900
+ <?php
1901
+ break;
1902
+
1903
+ case '_content':
1904
+
1905
+ if ( $this->set_field_type == 'shortcode' ) {
1906
+
1907
+ ?>
1908
+
1909
+ <p><label for="_content"><?php _e( 'Enter Shortcode', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Enter the shortcode in the following textarea and it will be displayed on the fields', 'ultimate-member' ) ); ?></label>
1910
+ <textarea name="_content" id="_content" placeholder="<?php esc_attr_e( 'e.g. [my_custom_shortcode]', 'ultimate-member' ) ?>"><?php echo $this->edit_mode_value; ?></textarea>
1911
+ </p>
1912
+
1913
+ <?php
1914
+
1915
+ } else {
1916
+
1917
+ ?>
1918
+
1919
+ <div class="um-admin-editor-h"><label><?php _e( 'Content Editor', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Edit the content of this field here', 'ultimate-member' ) ); ?></label></div>
1920
+
1921
+ <div class="um-admin-editor"><!-- editor dynamically loaded here --></div>
1922
+
1923
+ <?php
1924
+
1925
+ }
1926
+
1927
+ break;
1928
+
1929
+ case '_crop':
1930
+ ?>
1931
+
1932
+ <p><label for="_crop"><?php _e( 'Crop Feature', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Enable/disable crop feature for this image upload and define ratio', 'ultimate-member' ) ); ?></label>
1933
+ <select name="_crop" id="_crop" style="width: 100%">
1934
+ <option value="0" <?php selected( '0', $this->edit_mode_value ); ?>><?php _e( 'Turn Off (Default)', 'ultimate-member' ) ?></option>
1935
+ <option value="1" <?php selected( '1', $this->edit_mode_value ); ?>><?php _e( 'Crop and force 1:1 ratio', 'ultimate-member' ) ?></option>
1936
+ <option value="3" <?php selected( '3', $this->edit_mode_value ); ?>><?php _e( 'Crop and force user-defined ratio', 'ultimate-member' ) ?></option>
1937
+ </select>
1938
+ </p>
1939
+
1940
+ <?php
1941
+ break;
1942
+
1943
+ case '_allowed_types':
1944
+
1945
+ if ( $this->set_field_type == 'image' ) {
1946
+
1947
+ if ( isset( $this->edit_mode_value ) && is_array( $this->edit_mode_value ) ) {
1948
+ $values = $this->edit_mode_value;
1949
+ } else {
1950
+ $values = array( 'png','jpeg','jpg','gif' );
1951
+ } ?>
1952
+
1953
+ <p><label for="_allowed_types"><?php _e( 'Allowed Image Types', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Select the image types that you want to allow to be uploaded via this field.', 'ultimate-member' ) ); ?></label>
1954
+ <select name="_allowed_types[]" id="_allowed_types" multiple="multiple" style="width: 100%">
1955
+ <?php foreach( UM()->files()->allowed_image_types() as $e => $n ) { ?>
1956
+ <option value="<?php echo $e; ?>" <?php if ( in_array( $e, $values ) ) { echo 'selected'; } ?>><?php echo $n; ?></option>
1957
+ <?php } ?>
1958
+ </select>
1959
+ </p>
1960
+
1961
+ <?php
1962
+
1963
+ } else {
1964
+
1965
+ if ( isset( $this->edit_mode_value ) && is_array( $this->edit_mode_value ) ) {
1966
+ $values = $this->edit_mode_value;
1967
+ } else {
1968
+ $values = array( 'pdf', 'txt' );
1969
+ } ?>
1970
+
1971
+ <p><label for="_allowed_types"><?php _e( 'Allowed File Types', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Select the image types that you want to allow to be uploaded via this field.', 'ultimate-member' ) ); ?></label>
1972
+ <select name="_allowed_types[]" id="_allowed_types" multiple="multiple" style="width: 100%">
1973
+ <?php foreach( UM()->files()->allowed_file_types() as $e => $n ) { ?>
1974
+ <option value="<?php echo $e; ?>" <?php if ( in_array( $e, $values ) ) { echo 'selected'; } ?>><?php echo $n; ?></option>
1975
+ <?php } ?>
1976
+ </select>
1977
+ </p>
1978
+
1979
+ <?php
1980
+
1981
+ }
1982
+
1983
+ break;
1984
+
1985
+ case '_upload_text':
1986
+
1987
+ if ( $this->set_field_type == 'image' ) {
1988
+ $value = __( 'Drag &amp; Drop Photo', 'ultimate-member' );
1989
+ }
1990
+ if ( $this->set_field_type == 'file' ) {
1991
+ $value = __( 'Drag &amp; Drop File', 'ultimate-member' );
1992
+ }
1993
+
1994
+ ?>
1995
+
1996
+ <p><label for="_upload_text"><?php _e( 'Upload Box Text', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'This is the headline that appears in the upload box for this field', 'ultimate-member' ) ); ?></label>
1997
+ <input type="text" name="_upload_text" id="_upload_text" value="<?php echo ( $this->edit_mode_value ) ? $this->edit_mode_value : $value; ?>" />
1998
+ </p>
1999
+
2000
+ <?php
2001
+ break;
2002
+
2003
+ case '_upload_help_text':
2004
+ ?>
2005
+
2006
+ <p><label for="_upload_help_text"><?php _e( 'Additional Instructions Text', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'If you need to add information or secondary line below the headline of upload box, enter it here', 'ultimate-member' ) ); ?></label>
2007
+ <input type="text" name="_upload_help_text" id="_upload_help_text" value="<?php echo $this->edit_mode_value; ?>" />
2008
+ </p>
2009
+
2010
+ <?php
2011
+ break;
2012
+
2013
+ case '_button_text':
2014
+ ?>
2015
+
2016
+ <p><label for="_button_text"><?php _e( 'Upload Box Text', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'The text that appears on the button. e.g. Upload', 'ultimate-member' ) ); ?></label>
2017
+ <input type="text" name="_button_text" id="_button_text" value="<?php echo ( $this->edit_mode_value ) ? $this->edit_mode_value : __( 'Upload', 'ultimate-member' ); ?>" />
2018
+ </p>
2019
+
2020
+ <?php
2021
+ break;
2022
+
2023
+ case '_max_size':
2024
+ ?>
2025
+
2026
+ <p><label for="_max_size"><?php _e( 'Maximum Size in bytes', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'The maximum size for image that can be uploaded through this field. Leave empty for unlimited size.', 'ultimate-member' ) ); ?></label>
2027
+ <input type="text" name="_max_size" id="_max_size" value="<?php echo $this->edit_mode_value; ?>" />
2028
+ </p>
2029
+
2030
+ <?php
2031
+ break;
2032
+
2033
+ case '_height':
2034
+ ?>
2035
+
2036
+ <p><label for="_height"><?php _e( 'Textarea Height', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'The height of textarea in pixels. Default is 100 pixels', 'ultimate-member' ) ); ?></label>
2037
+ <input type="text" name="_height" id="_height" value="<?php echo ( $this->edit_mode_value ) ? $this->edit_mode_value : '100px'; ?>" />
2038
+ </p>
2039
+
2040
+ <?php
2041
+ break;
2042
+
2043
+ case '_spacing':
2044
+ ?>
2045
+
2046
+ <p><label for="_spacing"><?php _e( 'Spacing', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'This is the required spacing in pixels. e.g. 20px', 'ultimate-member' ) ); ?></label>
2047
+ <input type="text" name="_spacing" id="_spacing" value="<?php echo ( $this->edit_mode_value ) ? $this->edit_mode_value : '20px'; ?>" />
2048
+ </p>
2049
+
2050
+ <?php
2051
+ break;
2052
+
2053
+ case '_is_multi':
2054
+ ?>
2055
+
2056
+ <p><label for="_is_multi"><?php _e( 'Allow multiple selections', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Enable/disable multiple selections for this field', 'ultimate-member' ) ); ?></label>
2057
+ <input type="checkbox" name="_is_multi" id="_is_multi" value="1" <?php checked( isset( $this->edit_mode_value ) ? $this->edit_mode_value : 0 ) ?> class="um-adm-conditional" data-cond1="1" data-cond1-show="_max_selections" data-cond1-hide="xxx" />
2058
+ </p>
2059
+
2060
+ <?php
2061
+ break;
2062
+
2063
+ case '_max_selections':
2064
+ ?>
2065
+
2066
+ <p class="_max_selections"><label for="_max_selections"><?php _e( 'Maximum number of selections', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Enter a number here to force a maximum number of selections by user for this field', 'ultimate-member' ) ); ?></label>
2067
+ <input type="text" name="_max_selections" id="_max_selections" value="<?php echo $this->edit_mode_value; ?>" />
2068
+ </p>
2069
+
2070
+ <?php
2071
+ break;
2072
+
2073
+ case '_min_selections':
2074
+ ?>
2075
+
2076
+ <p class="_min_selections"><label for="_min_selections"><?php _e( 'Minimum number of selections', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Enter a number here to force a minimum number of selections by user for this field', 'ultimate-member' ) ); ?></label>
2077
+ <input type="text" name="_min_selections" id="_min_selections" value="<?php echo $this->edit_mode_value; ?>" />
2078
+ </p>
2079
+
2080
+ <?php
2081
+ break;
2082
+
2083
+ case '_max_entries':
2084
+ ?>
2085
+
2086
+ <p class="_max_entries"><label for="_max_selections"><?php _e( 'Maximum number of entries', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'This is the max number of entries the user can add via field group.', 'ultimate-member' ) ); ?></label>
2087
+ <input type="text" name="_max_entries" id="_max_entries" value="<?php echo ( $this->edit_mode_value ) ? $this->edit_mode_value : 10; ?>" />
2088
+ </p>
2089
+
2090
+ <?php
2091
+ break;
2092
+
2093
+ case '_max_words':
2094
+ ?>
2095
+
2096
+ <p><label for="_max_words"><?php _e( 'Maximum allowed words', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'If you want to enable a maximum number of words to be input in this textarea. Leave empty to disable this setting', 'ultimate-member' ) ); ?></label>
2097
+ <input type="text" name="_max_words" id="_max_words" value="<?php echo $this->edit_mode_value; ?>" />
2098
+ </p>
2099
+
2100
+ <?php
2101
+ break;
2102
+
2103
+ case '_min':
2104
+ ?>
2105
+
2106
+ <p><label for="_min"><?php _e( 'Minimum Number', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Minimum number that can be entered in this field', 'ultimate-member' ) ); ?></label>
2107
+ <input type="text" name="_min" id="_min" value="<?php echo $this->edit_mode_value; ?>" />
2108
+ </p>
2109
+
2110
+ <?php
2111
+ break;
2112
+
2113
+ case '_max':
2114
+ ?>
2115
+
2116
+ <p><label for="_max"><?php _e( 'Maximum Number', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Maximum number that can be entered in this field', 'ultimate-member' ) ); ?></label>
2117
+ <input type="text" name="_max" id="_max" value="<?php echo $this->edit_mode_value; ?>" />
2118
+ </p>
2119
+
2120
+ <?php
2121
+ break;
2122
+
2123
+ case '_min_chars':
2124
+ ?>
2125
+
2126
+ <p><label for="_min_chars"><?php _e( 'Minimum length', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'If you want to enable a minimum number of characters to be input in this field. Leave empty to disable this setting', 'ultimate-member' ) ); ?></label>
2127
+ <input type="text" name="_min_chars" id="_min_chars" value="<?php echo $this->edit_mode_value; ?>" />
2128
+ </p>
2129
+
2130
+ <?php
2131
+ break;
2132
+
2133
+ case '_max_chars':
2134
+ ?>
2135
+
2136
+ <p><label for="_max_chars"><?php _e( 'Maximum length', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'If you want to enable a maximum number of characters to be input in this field. Leave empty to disable this setting', 'ultimate-member' ) ); ?></label>
2137
+ <input type="text" name="_max_chars" id="_max_chars" value="<?php echo $this->edit_mode_value; ?>" />
2138
+ </p>
2139
+
2140
+ <?php
2141
+ break;
2142
+
2143
+ case '_html':
2144
+ ?>
2145
+
2146
+ <p><label for="_html"><?php _e( 'Does this textarea accept HTML?', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Turn on/off HTML tags for this textarea', 'ultimate-member' ) ); ?></label>
2147
+ <input type="checkbox" name="_html" id="_html" value="1" <?php checked( isset( $this->edit_mode_value ) ? $this->edit_mode_value : 0 ) ?> />
2148
+ </p>
2149
+
2150
+ <?php
2151
+ break;
2152
+
2153
+ case '_options':
2154
+
2155
+ if ( isset( $this->edit_mode_value ) && is_array( $this->edit_mode_value ) ) {
2156
+ $values = implode("\n", $this->edit_mode_value);
2157
+ } else if ( $this->edit_mode_value ) {
2158
+ $values = $this->edit_mode_value;
2159
+ } else {
2160
+ $values = '';
2161
+ } ?>
2162
+
2163
+ <p><label for="_options"><?php _e( 'Edit Choices', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Enter one choice per line. This will represent the available choices or selections available for user.', 'ultimate-member' ) ); ?></label>
2164
+ <textarea name="_options" id="_options"><?php echo $values; ?></textarea>
2165
+ </p>
2166
+
2167
+ <?php
2168
+ break;
2169
+
2170
+ case '_title':
2171
+ ?>
2172
+
2173
+ <p><label for="_title"><?php _e( 'Title', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'This is the title of the field for your reference in the backend. The title will not appear on the front-end of your website.', 'ultimate-member' ) ); ?></label>
2174
+ <input type="text" name="_title" id="_title" value="<?php echo htmlspecialchars( $this->edit_mode_value, ENT_QUOTES ); ?>" />
2175
+ </p>
2176
+
2177
+ <?php
2178
+ break;
2179
+
2180
+ case '_id':
2181
+
2182
+ ?>
2183
+
2184
+ <p style="display:none"><label for="_id"><?php _e( 'Unique ID', 'ultimate-member' ) ?></label>
2185
+ <input type="text" name="_id" id="_id" value="<?php echo $this->edit_mode_value; ?>" />
2186
+ </p>
2187
+
2188
+ <?php
2189
+
2190
+ break;
2191
+
2192
+ case '_metakey':
2193
+
2194
+ if ( $this->in_edit ) {
2195
+
2196
+ ?>
2197
+
2198
+ <p><label for="_metakey"><?php _e( 'Meta Key', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'The meta key cannot be changed for duplicated fields or when editing an existing field. If you require a different meta key please create a new field.', 'ultimate-member' ) ); ?></label>
2199
+ <input type="text" name="_metakey_locked" id="_metakey_locked" value="<?php echo $this->edit_mode_value; ?>" disabled />
2200
+ </p>
2201
+
2202
+ <?php } else { ?>
2203
+
2204
+ <p><label for="_metakey"><?php _e( 'Meta Key', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'A meta key is required to store the entered info in this field in the database. The meta key should be unique to this field and be written in lowercase with an underscore ( _ ) separating words e.g country_list or job_title', 'ultimate-member' ) ); ?></label>
2205
+ <input type="text" name="_metakey" id="_metakey" value="" />
2206
+ </p>
2207
+
2208
+ <?php
2209
+
2210
+ }
2211
+
2212
+ break;
2213
+
2214
+ case '_help':
2215
+ ?>
2216
+
2217
+ <p><label for="_help"><?php _e( 'Help Text', 'ultimate-member' ) ?> <?php UM()->tooltip( __('This is the text that appears in a tooltip when a user hovers over the info icon. Help text is useful for providing users with more information about what they should enter in the field. Leave blank if no help text is needed for field.', 'ultimate-member' ) ); ?></label>
2218
+ <input type="text" name="_help" id="_help" value="<?php echo $this->edit_mode_value; ?>" />
2219
+ </p>
2220
+
2221
+ <?php
2222
+ break;
2223
+
2224
+ case '_default':
2225
+ ?>
2226
+
2227
+ <?php if ( $this->set_field_type == 'textarea' ) { ?>
2228
+
2229
+ <p><label for="_default"><?php _e( 'Default Text', 'ultimate-member' ); ?> <?php UM()->tooltip( __( 'Text to display by default in this field', 'ultimate-member' ) ); ?></label>
2230
+ <textarea name="_default" id="_default"><?php echo $this->edit_mode_value; ?></textarea>
2231
+ </p>
2232
+
2233
+ <?php } elseif ( $this->set_field_type == 'date' ) { ?>
2234
+
2235
+ <p class="um"><label for="_default"><?php _e( 'Default Date', 'ultimate-member' ); ?> <?php UM()->tooltip( __( 'You may use all PHP compatible date formats such as: 2020-02-02, 02/02/2020, yesterday, today, tomorrow, next monday, first day of next month, +3 day', 'ultimate-member' ) ); ?></label>
2236
+ <input type="text" name="_default" id="_default" value="<?php echo $this->edit_mode_value; ?>" class="um-datepicker" data-format="yyyy/mm/dd" />
2237
+ </p>
2238
+
2239
+ <?php } elseif ( $this->set_field_type == 'time' ) { ?>
2240
+
2241
+ <p class="um"><label for="_default"><?php _e( 'Default Time', 'ultimate-member' ); ?> <?php UM()->tooltip( __( 'You may use all PHP compatible date formats such as: 2020-02-02, 02/02/2020, yesterday, today, tomorrow, next monday, first day of next month, +3 day', 'ultimate-member' ) ); ?></label>
2242
+ <input type="text" name="_default" id="_default" value="<?php echo $this->edit_mode_value; ?>" class="um-timepicker" data-format="HH:i" />
2243
+ </p>
2244
+
2245
+ <?php } elseif ( $this->set_field_type == 'rating' ) { ?>
2246
+
2247
+ <p><label for="_default"><?php _e( 'Default Rating', 'ultimate-member' ); ?> <?php UM()->tooltip( __( 'If you wish the rating field to be prefilled with a number of stars, enter it here.', 'ultimate-member' ) ); ?></label>
2248
+ <input type="text" name="_default" id="_default" value="<?php echo $this->edit_mode_value; ?>" />
2249
+ </p>
2250
+
2251
+ <?php } else { ?>
2252
+
2253
+ <p><label for="_default"><?php _e( 'Default Value', 'ultimate-member' ); ?> <?php UM()->tooltip( __( 'This option allows you to pre-fill the field with a default value prior to the user entering a value in the field. Leave blank to have no default value', 'ultimate-member' ) ); ?></label>
2254
+ <input type="text" name="_default" id="_default" value="<?php echo $this->edit_mode_value; ?>" />
2255
+ </p>
2256
+
2257
+ <?php } ?>
2258
+
2259
+ <?php
2260
+ break;
2261
+
2262
+ case '_label':
2263
+ ?>
2264
+
2265
+ <p><label for="_label"><?php _e( 'Label', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'The field label is the text that appears above the field on your front-end form. Leave blank to not show a label above field.', 'ultimate-member' ) ); ?></label>
2266
+ <input type="text" name="_label" id="_label" value="<?php echo htmlspecialchars( $this->edit_mode_value, ENT_QUOTES ); ?>" />
2267
+ </p>
2268
+
2269
+ <?php
2270
+ break;
2271
+
2272
+ case '_label_confirm_pass':
2273
+ ?>
2274
+
2275
+ <p><label for="_label_confirm_pass"><?php _e( 'Confirm password field label', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'This label is the text that appears above the confirm password field. Leave blank to show default label.', 'ultimate-member' ) ); ?></label>
2276
+ <input type="text" name="_label_confirm_pass" id="_label_confirm_pass" value="<?php echo htmlspecialchars( $this->edit_mode_value, ENT_QUOTES ); ?>" />
2277
+ </p>
2278
+
2279
+ <?php
2280
+ break;
2281
+
2282
+ case '_placeholder':
2283
+ ?>
2284
+
2285
+ <p><label for="_placeholder"><?php _e( 'Placeholder', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'This is the text that appears within the field e.g please enter your email address. Leave blank to not show any placeholder text.', 'ultimate-member' ) ); ?></label>
2286
+ <input type="text" name="_placeholder" id="_placeholder" value="<?php echo htmlspecialchars( $this->edit_mode_value, ENT_QUOTES ); ?>" />
2287
+ </p>
2288
+
2289
+ <?php
2290
+ break;
2291
+
2292
+ case '_public':
2293
+ $privacy_options = array(
2294
+ '1' => __( 'Everyone', 'ultimate-member' ),
2295
+ '2' => __( 'Members', 'ultimate-member' ),
2296
+ '-1' => __( 'Only visible to profile owner and users who can edit other member accounts', 'ultimate-member' ),
2297
+ '-3' => __( 'Only visible to profile owner and specific roles', 'ultimate-member' ),
2298
+ '-2' => __( 'Only specific member roles', 'ultimate-member' ),
2299
+ );
2300
+
2301
+ $privacy_options = apply_filters( 'um_field_privacy_options', $privacy_options ); ?>
2302
+
2303
+ <p>
2304
+ <label for="_public"><?php _e( 'Privacy', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Field privacy allows you to select who can view this field on the front-end. The site admin can view all fields regardless of the option set here.', 'ultimate-member' ) ); ?></label>
2305
+ <select name="_public" id="_public" class="um-adm-conditional" data-cond1="-2" data-cond1-show="_roles" data-cond2="-3" data-cond2-show="_roles" style="width: 100%">
2306
+ <?php foreach ( $privacy_options as $value => $title ) { ?>
2307
+ <option value="<?php echo esc_attr( $value ) ?>" <?php selected( $value, $this->edit_mode_value ); ?>>
2308
+ <?php echo $title ?>
2309
+ </option>
2310
+ <?php } ?>
2311
+ </select>
2312
+ </p>
2313
+
2314
+ <?php
2315
+ break;
2316
+
2317
+ case '_roles':
2318
+
2319
+ if ( isset( $this->edit_mode_value ) && is_array( $this->edit_mode_value ) ) {
2320
+ $values = $this->edit_mode_value;
2321
+ } else {
2322
+ $values = array('');
2323
+ }
2324
+
2325
+ ?>
2326
+
2327
+ <p class="_roles"><label for="_roles"><?php _e( 'Select member roles', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Select the member roles that can view this field on the front-end.', 'ultimate-member' ) ); ?></label>
2328
+ <select name="_roles[]" id="_roles" style="width: 100%" multiple="multiple">
2329
+
2330
+ <?php foreach ( UM()->roles()->get_roles() as $key => $value) { ?>
2331
+
2332
+ <option value="<?php echo $key; ?>" <?php if ( in_array( $key, $values ) ) { echo 'selected'; } ?>><?php echo $value; ?></option>
2333
+
2334
+ <?php } ?>
2335
+
2336
+ </select>
2337
+ </p>
2338
+
2339
+ <?php
2340
+ break;
2341
+
2342
+ case '_required':
2343
+
2344
+ if ( $this->set_field_type == 'password' )
2345
+ $def_required = 1;
2346
+ else
2347
+ $def_required = 0;
2348
+
2349
+ ?>
2350
+
2351
+ <div class="um-admin-tri">
2352
+
2353
+ <p><label for="_required"><?php _e( 'Is this field required?', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'This option allows you to set whether the field must be filled in before the form can be processed.', 'ultimate-member' ) ); ?></label>
2354
+ <input type="checkbox" name="_required" id="_required" value="1" <?php checked( isset( $this->edit_mode_value ) ? $this->edit_mode_value : $def_required ) ?> />
2355
+ </p>
2356
+
2357
+ </div>
2358
+
2359
+ <?php
2360
+ break;
2361
+
2362
+ case '_editable':
2363
+ ?>
2364
+
2365
+ <div class="um-admin-tri">
2366
+
2367
+ <p><label for="_editable"><?php _e( 'Can user edit this field?', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'This option allows you to set whether or not the user can edit the information in this field. The site admin can edit all fields regardless of the option set here.', 'ultimate-member' ) ); ?></label>
2368
+ <input type="hidden" name="_editable" id="_editable_hidden" value="0" />
2369
+ <input type="checkbox" name="_editable" id="_editable" value="1" <?php checked( null === $this->edit_mode_value || $this->edit_mode_value ) ?> />
2370
+ </p>
2371
+
2372
+ </div>
2373
+
2374
+ <?php
2375
+ break;
2376
+
2377
+ case '_number':
2378
+ ?>
2379
+
2380
+ <p><label for="_number"><?php _e( 'Rating System', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Choose whether you want a 5-stars or 10-stars ratings based here.', 'ultimate-member' ) ); ?></label>
2381
+ <select name="_number" id="_number" style="width: 100%">
2382
+ <option value="5" <?php selected( 5, $this->edit_mode_value ); ?>><?php _e( '5 stars rating system', 'ultimate-member' ) ?></option>
2383
+ <option value="10" <?php selected( 10, $this->edit_mode_value ); ?>><?php _e( '10 stars rating system', 'ultimate-member' ) ?></option>
2384
+ </select>
2385
+ </p>
2386
+
2387
+ <?php
2388
+ break;
2389
+
2390
+ case '_custom_dropdown_options_source':
2391
+ ?>
2392
+
2393
+ <p><label for="_custom_dropdown_options_source"><?php _e( 'Choices Callback', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'Add a callback source to retrieve choices.', 'ultimate-member' ) ); ?></label>
2394
+ <input type="text" name="_custom_dropdown_options_source" id="_custom_dropdown_options_source" value="<?php echo esc_attr( $this->edit_mode_value ); ?>" />
2395
+ </p>
2396
+
2397
+ <?php
2398
+ break;
2399
+
2400
+ case '_parent_dropdown_relationship':
2401
+ ?>
2402
+
2403
+ <p><label for="_parent_dropdown_relationship"><?php _e( 'Parent Option', 'ultimate-member' ) ?><?php UM()->tooltip( __( 'Dynamically populates the option based from selected parent option.', 'ultimate-member' ) ); ?></label>
2404
+ <select name="_parent_dropdown_relationship" id="_parent_dropdown_relationship" style="width: 100%">
2405
+ <option value=""><?php _e( 'No Selected', 'ultimate-member' ) ?></option>
2406
+
2407
+ <?php if ( UM()->builtin()->custom_fields ) {
2408
+ foreach ( UM()->builtin()->custom_fields as $field_key => $array ) {
2409
+ if ( in_array( $array['type'], array( 'select' ) ) && ( ! isset( $field_args['metakey'] ) || $field_args['metakey'] != $array['metakey'] ) && isset( $array['title'] ) ) { ?>
2410
+ <option value="<?php echo esc_attr( $array['metakey'] ) ?>" <?php selected( $array['metakey'], $this->edit_mode_value ) ?>><?php echo $array['title'] ?></option>
2411
+ <?php }
2412
+ }
2413
+ } ?>
2414
+ </select>
2415
+ </p>
2416
+
2417
+ <?php
2418
+ break;
2419
+
2420
+
2421
+ }
2422
+
2423
+ }
2424
+
2425
+ }
2426
+ }
 
includes/admin/core/packages/2.4.0/functions.php CHANGED
@@ -1,50 +1,50 @@
1
- <?php if ( ! defined( 'ABSPATH' ) ) exit;
2
-
3
-
4
- function um_upgrade_choice_callbacks240() {
5
- UM()->admin()->check_ajax_nonce();
6
-
7
- um_maybe_unset_time_limit();
8
-
9
- $functions = array();
10
- // hardcoded for UM:Woocommerce function
11
- if ( function_exists( 'um_woo_directory_get_states' ) ) {
12
- $functions[] = 'um_woo_directory_get_states';
13
- }
14
-
15
- $custom_fields = get_option( 'um_fields', array() );
16
- foreach ( $custom_fields as $custom_field ) {
17
- if ( array_key_exists( 'custom_dropdown_options_source', $custom_field ) && function_exists( $custom_field['custom_dropdown_options_source'] ) ) {
18
- $functions[] = $custom_field['custom_dropdown_options_source'];
19
- }
20
- }
21
-
22
- $forms_query = new WP_Query;
23
- $forms = $forms_query->query( array(
24
- 'post_type' => 'um_form',
25
- 'posts_per_page' => -1,
26
- 'fields' => 'ids',
27
- ) );
28
-
29
- foreach ( $forms as $form_id ) {
30
- $forms_fields = get_post_meta( $form_id, '_um_custom_fields', true );
31
- if ( ! is_array( $forms_fields ) ) {
32
- continue;
33
- }
34
-
35
- foreach ( $forms_fields as $key => $field ) {
36
- if ( array_key_exists( 'custom_dropdown_options_source', $field ) && function_exists( $field['custom_dropdown_options_source'] ) ) {
37
- $functions[] = $field['custom_dropdown_options_source'];
38
- }
39
- }
40
- }
41
-
42
- $functions = array_unique( $functions );
43
- $functions = implode( "\r\n", $functions );
44
- UM()->options()->update( 'allowed_choice_callbacks', $functions );
45
-
46
- // delete temporarily option for fields upgrade
47
- update_option( 'um_last_version_upgrade', '2.4.0' );
48
-
49
- wp_send_json_success( array( 'message' => __( 'Custom callback functions whitelisted for 2.4.0 version.', 'ultimate-member' ) ) );
50
- }
1
+ <?php if ( ! defined( 'ABSPATH' ) ) exit;
2
+
3
+
4
+ function um_upgrade_choice_callbacks240() {
5
+ UM()->admin()->check_ajax_nonce();
6
+
7
+ um_maybe_unset_time_limit();
8
+
9
+ $functions = array();
10
+ // hardcoded for UM:Woocommerce function
11
+ if ( function_exists( 'um_woo_directory_get_states' ) ) {
12
+ $functions[] = 'um_woo_directory_get_states';
13
+ }
14
+
15
+ $custom_fields = get_option( 'um_fields', array() );
16
+ foreach ( $custom_fields as $custom_field ) {
17
+ if ( array_key_exists( 'custom_dropdown_options_source', $custom_field ) && function_exists( $custom_field['custom_dropdown_options_source'] ) ) {
18
+ $functions[] = $custom_field['custom_dropdown_options_source'];
19
+ }
20
+ }
21
+
22
+ $forms_query = new WP_Query;
23
+ $forms = $forms_query->query( array(
24
+ 'post_type' => 'um_form',
25
+ 'posts_per_page' => -1,
26
+ 'fields' => 'ids',
27
+ ) );
28
+
29
+ foreach ( $forms as $form_id ) {
30
+ $forms_fields = get_post_meta( $form_id, '_um_custom_fields', true );
31
+ if ( ! is_array( $forms_fields ) ) {
32
+ continue;
33
+ }
34
+
35
+ foreach ( $forms_fields as $key => $field ) {
36
+ if ( array_key_exists( 'custom_dropdown_options_source', $field ) && function_exists( $field['custom_dropdown_options_source'] ) ) {
37
+ $functions[] = $field['custom_dropdown_options_source'];
38
+ }
39
+ }
40
+ }
41
+
42
+ $functions = array_unique( $functions );
43
+ $functions = implode( "\r\n", $functions );
44
+ UM()->options()->update( 'allowed_choice_callbacks', $functions );
45
+
46
+ // delete temporarily option for fields upgrade
47
+ update_option( 'um_last_version_upgrade', '2.4.0' );
48
+
49
+ wp_send_json_success( array( 'message' => __( 'Custom callback functions whitelisted for 2.4.0 version.', 'ultimate-member' ) ) );
50
+ }
includes/admin/templates/form/builder.php CHANGED
@@ -1,35 +1,35 @@
1
- <?php if ( ! defined( 'ABSPATH' ) ) {
2
- exit;
3
- }
4
-
5
- if ( empty( UM()->builder()->form_id ) ) {
6
- UM()->builder()->form_id = $this->form_id;
7
- } ?>
8
-
9
- <div class="um-admin-builder" data-form_id="<?php echo esc_attr( UM()->builder()->form_id ); ?>">
10
-
11
- <div class="um-admin-drag-ctrls-demo um-admin-drag-ctrls">
12
-
13
- <a href="javascript:void(0);" class="active" data-modal="UM_preview_form" data-modal-size="smaller"
14
- data-dynamic-content="um_admin_preview_form" data-arg1="<?php echo esc_attr( get_the_ID() ); ?>" data-arg2="">
15
- <?php esc_html_e( 'Live Preview', 'ultimate-member' ); ?>
16
- </a>
17
-
18
- </div>
19
-
20
- <div class="um-admin-clear"></div>
21
-
22
- <div class="um-admin-drag">
23
-
24
- <div class="um-admin-drag-ajax" data-form_id="<?php echo esc_attr( UM()->builder()->form_id ); ?>">
25
- <?php UM()->builder()->show_builder(); ?>
26
- </div>
27
-
28
- <div class="um-admin-drag-addrow um-admin-tipsy-n" title="<?php esc_attr_e( 'Add Master Row', 'ultimate-member' ); ?>"
29
- data-row_action="add_row">
30
- <i class="um-icon-plus"></i>
31
- </div>
32
-
33
- </div>
34
-
35
- </div>
1
+ <?php if ( ! defined( 'ABSPATH' ) ) {
2
+ exit;
3
+ }
4
+
5
+ if ( empty( UM()->builder()->form_id ) ) {
6
+ UM()->builder()->form_id = $this->form_id;
7
+ } ?>
8
+
9
+ <div class="um-admin-builder" data-form_id="<?php echo esc_attr( UM()->builder()->form_id ); ?>">
10
+
11
+ <div class="um-admin-drag-ctrls-demo um-admin-drag-ctrls">
12
+
13
+ <a href="javascript:void(0);" class="active" data-modal="UM_preview_form" data-modal-size="smaller"
14
+ data-dynamic-content="um_admin_preview_form" data-arg1="<?php echo esc_attr( get_the_ID() ); ?>" data-arg2="">
15
+ <?php esc_html_e( 'Live Preview', 'ultimate-member' ); ?>
16
+ </a>
17
+
18
+ </div>
19
+
20
+ <div class="um-admin-clear"></div>
21
+
22
+ <div class="um-admin-drag">
23
+
24
+ <div class="um-admin-drag-ajax" data-form_id="<?php echo esc_attr( UM()->builder()->form_id ); ?>">
25
+ <?php UM()->builder()->show_builder(); ?>
26
+ </div>
27
+
28
+ <div class="um-admin-drag-addrow um-admin-tipsy-n" title="<?php esc_attr_e( 'Add Master Row', 'ultimate-member' ); ?>"
29
+ data-row_action="add_row">
30
+ <i class="um-icon-plus"></i>
31
+ </div>
32
+
33
+ </div>
34
+
35
+ </div>
includes/core/class-access.php CHANGED
@@ -1,2133 +1,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
-
52
- // callbacks for changing terms query
53
- add_action( 'pre_get_terms', array( &$this, 'exclude_hidden_terms_query' ), 99, 1 );
54
-
55
- // Change recent posts widget query
56
- add_filter( 'widget_posts_args', array( &$this, 'exclude_restricted_posts_widget' ), 99, 1 );
57
- // Exclude pages displayed by wp_list_pages function
58
- add_filter( 'wp_list_pages_excludes', array( &$this, 'exclude_restricted_pages' ), 10, 1 );
59
- // Archives list change where based on restricted posts
60
- add_filter( 'getarchives_where', array( &$this, 'exclude_restricted_posts_archives_widget' ), 99, 2 );
61
-
62
- // Navigation line below the post content, change query to exclude restricted
63
- add_filter( 'get_next_post_where', array( &$this, 'exclude_navigation_posts' ), 99, 5 );
64
- add_filter( 'get_previous_post_where', array( &$this, 'exclude_navigation_posts' ), 99, 5 );
65
-
66
- // callbacks for changing posts query
67
- add_action( 'pre_get_posts', array( &$this, 'exclude_posts' ), 99, 1 );
68
- add_filter( 'posts_where', array( &$this, 'exclude_posts_where' ), 10, 2 );
69
- add_filter( 'wp_count_posts', array( &$this, 'custom_count_posts_handler' ), 99, 3 );
70
-
71
- // change the title of the post
72
- add_filter( 'the_title', array( &$this, 'filter_restricted_post_title' ), 10, 2 );
73
- // change the content of the restricted post
74
- add_filter( 'the_content', array( &$this, 'filter_restricted_post_content' ), 999999, 1 );
75
- // change the excerpt of the restricted post
76
- add_filter( 'get_the_excerpt', array( &$this, 'filter_restricted_post_excerpt' ), 999999, 2 );
77
-
78
- // filter attachment
79
- add_filter( 'wp_get_attachment_url', array( &$this, 'filter_attachment' ), 99, 2 );
80
- add_filter( 'has_post_thumbnail', array( &$this, 'filter_post_thumbnail' ), 99, 3 );
81
-
82
- // comments queries
83
- add_action( 'pre_get_comments', array( &$this, 'exclude_posts_comments' ), 99, 1 );
84
- add_filter( 'wp_count_comments', array( &$this, 'custom_comments_count_handler' ), 99, 2 );
85
- // comments RSS
86
- add_filter( 'comment_feed_where', array( &$this, 'exclude_posts_comments_feed' ), 99, 2 );
87
- // Disable comments if user has not permission to access current post
88
- add_filter( 'comments_open', array( $this, 'disable_comments_open' ), 99, 2 );
89
- add_filter( 'get_comments_number', array( $this, 'disable_comments_open_number' ), 99, 2 );
90
-
91
- // filter menu items
92
- add_filter( 'wp_nav_menu_objects', array( &$this, 'filter_menu' ), 99, 2 );
93
-
94
- // Gutenberg blocks restrictions
95
- add_filter( 'render_block', array( $this, 'restrict_blocks' ), 10, 2 );
96
-
97
- // there is posts (Posts/Page/CPT) filtration if site is accessible
98
- // there also will be redirects if they need
99
- // protect posts types
100
- add_filter( 'the_posts', array( &$this, 'filter_protected_posts' ), 99, 2 );
101
- // protect pages for wp_list_pages func
102
- add_filter( 'get_pages', array( &$this, 'filter_protected_posts' ), 99, 2 );
103
-
104
- // check the site's accessible more priority have Individual Post/Term Restriction settings
105
- add_action( 'template_redirect', array( &$this, 'template_redirect' ), 1000 );
106
- add_action( 'um_access_check_individual_term_settings', array( &$this, 'um_access_check_individual_term_settings' ) );
107
- add_action( 'um_access_check_global_settings', array( &$this, 'um_access_check_global_settings' ) );
108
-
109
- add_action( 'plugins_loaded', array( &$this, 'disable_restriction_pre_queries' ), 1 );
110
- }
111
-
112
-
113
- /**
114
- * Rollback function for old business logic to avoid security enhancements with 404 errors
115
- */
116
- function disable_restriction_pre_queries() {
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
-
733
- return $content;
734
- }
735
-
736
-
737
- /**
738
- * Replace excerpt of restricted posts
739
- *
740
- * @param string $post_excerpt
741
- * @param \WP_Post $post
742
- *
743
- * @return string
744
- */
745
- function filter_restricted_post_excerpt( $post_excerpt = '', $post = null ) {
746
- if ( empty( $post ) ) {
747
- return $post_excerpt;
748
- }
749
-
750
- if ( current_user_can( 'administrator' ) || is_admin() ) {
751
- return $post_excerpt;
752
- }
753
-
754
- $ignore = apply_filters( 'um_ignore_restricted_excerpt', false, $post->ID );
755
- if ( $ignore ) {
756
- return $post_excerpt;
757
- }
758
-
759
- if ( $this->is_restricted( $post->ID ) ) {
760
- $post_excerpt = '';
761
- }
762
-
763
- return $post_excerpt;
764
- }
765
-
766
-
767
- /**
768
- * Hide attachment if the post is restricted
769
- *
770
- * @param string $url
771
- * @param int $attachment_id
772
- *
773
- * @return boolean|string
774
- */
775
- function filter_attachment( $url, $attachment_id ) {
776
- if ( current_user_can( 'administrator' ) ) {
777
- return $url;
778
- }
779
-
780
- return ( $attachment_id && $this->is_restricted( $attachment_id ) ) ? false : $url;
781
- }
782
-
783
-
784
- /**
785
- * Hide attachment if the post is restricted
786
- *
787
- * @param $has_thumbnail
788
- * @param $post
789
- * @param $thumbnail_id
790
- *
791
- * @return bool
792
- */
793
- function filter_post_thumbnail( $has_thumbnail, $post = null, $thumbnail_id = false ) {
794
- if ( empty( $thumbnail_id ) ) {
795
- return $has_thumbnail;
796
- }
797
-
798
- if ( current_user_can( 'administrator' ) ) {
799
- return $has_thumbnail;
800
- }
801
-
802
- if ( $this->is_restricted( $thumbnail_id ) ) {
803
- $has_thumbnail = false;
804
- } elseif ( ! empty( $post ) && ! empty( $post->ID ) ) {
805
- if ( $this->is_restricted( $post->ID ) ) {
806
- $has_thumbnail = false;
807
- }
808
- } else {
809
- $post_id = get_the_ID();
810
- if ( false !== $post_id && $this->is_restricted( $post_id ) ) {
811
- $has_thumbnail = false;
812
- }
813
- }
814
-
815
- $has_thumbnail = apply_filters( 'um_restrict_post_thumbnail', $has_thumbnail, $post, $thumbnail_id );
816
-
817
- return $has_thumbnail;
818
- }
819
-
820
-
821
-
822
- /**
823
- * Exclude comments from restricted posts in widgets
824
- *
825
- * @param \WP_Comment_Query $query
826
- */
827
- function exclude_posts_comments( $query ) {
828
- if ( current_user_can( 'administrator' ) ) {
829
- return;
830
- }
831
-
832
- if ( ! empty( $query->query_vars['post_id'] ) ) {
833
- $exclude_posts = array();
834
- if ( $this->is_restricted( $query->query_vars['post_id'] ) ) {
835
- $exclude_posts[] = $query->query_vars['post_id'];
836
- }
837
- } else {
838
- $q_values = ! empty( $query->query_vars['post_type'] ) ? $query->query_vars['post_type'] : array();
839
- if ( ! is_array( $q_values ) ) {
840
- $q_values = explode( ',', $query->query_vars['post_type'] );
841
- }
842
-
843
- // 'any' will cause the query var to be ignored.
844
- if ( in_array( 'any', $q_values, true ) || empty( $q_values ) ) {
845
- $exclude_posts = $this->exclude_posts_array( true, $this->get_available_comments_post_types() );
846
- } else {
847
- $exclude_posts = $this->exclude_posts_array( true, $q_values );
848
- }
849
- }
850
-
851
- if ( ! empty( $exclude_posts ) ) {
852
- $post__not_in = ! empty( $query->query_vars['post__not_in'] ) ? $query->query_vars['post__not_in'] : array();
853
- $query->query_vars['post__not_in'] = array_merge( wp_parse_id_list( $post__not_in ), $exclude_posts );
854
- }
855
- }
856
-
857
-
858
- /**
859
- * @return array
860
- */
861
- function get_available_comments_post_types() {
862
- global $wp_taxonomies, $wpdb;
863
-
864
- $restricted_posts = UM()->options()->get( 'restricted_access_post_metabox' );
865
- if ( empty( $restricted_posts ) ) {
866
- $restricted_posts = array();
867
- }
868
- $restricted_posts = array_keys( $restricted_posts );
869
-
870
- $restricted_taxonomies = UM()->options()->get( 'restricted_access_taxonomy_metabox' );
871
- if ( ! empty( $restricted_taxonomies ) ) {
872
- $restricted_taxonomies = array_keys( $restricted_taxonomies );
873
- foreach ( $restricted_taxonomies as $k => $taxonomy ) {
874
- if ( taxonomy_exists( $taxonomy ) ) {
875
- $restricted_posts = array_merge( $restricted_posts, $wp_taxonomies[ $taxonomy ]->object_type );
876
- }
877
- }
878
- }
879
-
880
- $restricted_posts = array_unique( $restricted_posts );
881
- foreach ( $restricted_posts as $k => $post_type ) {
882
- if ( 'closed' === get_default_comment_status( $post_type ) ) {
883
- $open_comments = $wpdb->get_var( $wpdb->prepare(
884
- "SELECT ID
885
- FROM {$wpdb->posts}
886
- WHERE post_type = %s AND
887
- comment_status != 'closed'",
888
- $post_type
889
- ) );
890
-
891
- if ( empty( $open_comments ) ) {
892
- unset( $restricted_posts[ $k ] );
893
- }
894
- }
895
- }
896
-
897
- $restricted_posts = array_values( $restricted_posts );
898
-
899
- return $restricted_posts;
900
- }
901
-
902
-
903
- /**
904
- * Exclude comments from comments feed
905
- *
906
- * @param string $where
907
- * @param \WP_Query $query
908
- *
909
- * @return string
910
- */
911
- function exclude_posts_comments_feed( $where, $query ) {
912
- if ( current_user_can( 'administrator' ) ) {
913
- return $where;
914
- }
915
-
916
- $exclude_posts = $this->exclude_posts_array( true, $this->get_available_comments_post_types() );
917
- if ( ! empty( $exclude_posts ) ) {
918
- $exclude_string = implode( ',', $exclude_posts );
919
- $where .= ' AND comment_post_ID NOT IN ( ' . $exclude_string . ' )';
920
- }
921
-
922
- return $where;
923
- }
924
-
925
-
926
- /**
927
- * @param array|object $stats
928
- * @param int $post_id Post ID. Can be 0 for the whole website
929
- *
930
- * @return object
931
- */
932
- function custom_comments_count_handler( $stats = array(), $post_id = 0 ) {
933
- if ( ! empty( $stats ) || current_user_can( 'administrator' ) ) {
934
- return $stats;
935
- }
936
-
937
- if ( $post_id === 0 ) {
938
- $exclude_posts = $this->exclude_posts_array( true, $this->get_available_comments_post_types() );
939
- if ( empty( $exclude_posts ) ) {
940
- return $stats;
941
- }
942
- } else {
943
- $exclude_posts = array();
944
- if ( $this->is_restricted( $post_id ) ) {
945
- $exclude_posts[] = $post_id;
946
- }
947
- }
948
-
949
- $stats = $this->get_comment_count( $post_id, $exclude_posts );
950
- $stats['moderated'] = $stats['awaiting_moderation'];
951
- unset( $stats['awaiting_moderation'] );
952
-
953
- $stats_object = (object) $stats;
954
-
955
- return $stats_object;
956
- }
957
-
958
-
959
- /**
960
- * @param int $post_id
961
- * @param array $exclude_posts
962
- *
963
- * @return array
964
- */
965
- function get_comment_count( $post_id = 0, $exclude_posts = array() ) {
966
- static $cache = array();
967
-
968
- if ( isset( $cache[ $post_id ] ) ) {
969
- return $cache[ $post_id ];
970
- }
971
-
972
- global $wpdb;
973
-
974
- $post_id = (int) $post_id;
975
-
976
- $where = 'WHERE 1=1';
977
- if ( $post_id > 0 ) {
978
- $where .= $wpdb->prepare( ' AND comment_post_ID = %d', $post_id );
979
- }
980
-
981
- if ( ! empty( $exclude_posts ) ) {
982
- $exclude_string = implode( ',', $exclude_posts );
983
- $where .= ' AND comment_post_ID NOT IN ( ' . $exclude_string . ' )';
984
- }
985
-
986
- $totals = (array) $wpdb->get_results(
987
- "
988
- SELECT comment_approved, COUNT( * ) AS total
989
- FROM {$wpdb->comments}
990
- {$where}
991
- GROUP BY comment_approved
992
- ",
993
- ARRAY_A
994
- );
995
-
996
- $comment_count = array(
997
- 'approved' => 0,
998
- 'awaiting_moderation' => 0,
999
- 'spam' => 0,
1000
- 'trash' => 0,
1001
- 'post-trashed' => 0,
1002
- 'total_comments' => 0,
1003
- 'all' => 0,
1004
- );
1005
-
1006
- foreach ( $totals as $row ) {
1007
- switch ( $row['comment_approved'] ) {
1008
- case 'trash':
1009
- $comment_count['trash'] = $row['total'];
1010
- break;
1011
- case 'post-trashed':
1012
- $comment_count['post-trashed'] = $row['total'];
1013
- break;
1014
- case 'spam':
1015
- $comment_count['spam'] = $row['total'];
1016
- $comment_count['total_comments'] += $row['total'];
1017
- break;
1018
- case '1':
1019
- $comment_count['approved'] = $row['total'];
1020
- $comment_count['total_comments'] += $row['total'];
1021
- $comment_count['all'] += $row['total'];
1022
- break;
1023
- case '0':
1024
- $comment_count['awaiting_moderation'] = $row['total'];
1025
- $comment_count['total_comments'] += $row['total'];
1026
- $comment_count['all'] += $row['total'];
1027
- break;
1028
- default:
1029
- break;
1030
- }
1031
- }
1032
-
1033
- $comment_count = array_map( 'intval', $comment_count );
1034
- $cache[ $post_id ] = $comment_count;
1035
-
1036
- return $comment_count;
1037
- }
1038
-
1039
-
1040
- /**
1041
- * Disable comments if user has not permission to access this post
1042
- *
1043
- * @param mixed $open
1044
- * @param int $post_id
1045
- * @return boolean
1046
- */
1047
- function disable_comments_open( $open, $post_id ) {
1048
- if ( current_user_can( 'administrator' ) ) {
1049
- return $open;
1050
- }
1051
-
1052
- static $cache = array();
1053
-
1054
- if ( isset( $cache[ $post_id ] ) ) {
1055
- return $cache[ $post_id ] ? $open : false;
1056
- }
1057
-
1058
- if ( ! $this->is_restricted( $post_id ) ) {
1059
- $cache[ $post_id ] = $open;
1060
- return $open;
1061
- }
1062
-
1063
- $open = false;
1064
-
1065
- $cache[ $post_id ] = $open;
1066
- return $open;
1067
- }
1068
-
1069
-
1070
- /**
1071
- * Disable comments if user has not permission to access this post
1072
- *
1073
- * @param int $count
1074
- * @param int $post_id
1075
- * @return boolean
1076
- */
1077
- function disable_comments_open_number( $count, $post_id = 0 ) {
1078
- if ( current_user_can( 'administrator' ) ) {
1079
- return $count;
1080
- }
1081
-
1082
- static $cache_number = array();
1083
-
1084
- if ( isset( $cache_number[ $post_id ] ) ) {
1085
- return $cache_number[ $post_id ];
1086
- }
1087
-
1088
- if ( ! $this->is_restricted( $post_id ) ) {
1089
- $cache_number[ $post_id ] = $count;
1090
- return $count;
1091
- }
1092
-
1093
- $count = 0;
1094
-
1095
- $cache_number[ $post_id ] = $count;
1096
- return $count;
1097
- }
1098
-
1099
-
1100
- /**
1101
- * Protect Post Types in menu query
1102
- * Restrict content new logic
1103
- * @param array $menu_items
1104
- * @param array $args
1105
- * @return array
1106
- */
1107
- function filter_menu( $menu_items, $args = array() ) {
1108
- //if empty
1109
- if ( empty( $menu_items ) ) {
1110
- return $menu_items;
1111
- }
1112
-
1113
- if ( current_user_can( 'administrator' ) ) {
1114
- return $menu_items;
1115
- }
1116
-
1117
- $filtered_items = array();
1118
-
1119
- //other filter
1120
- foreach ( $menu_items as $menu_item ) {
1121
- if ( ! empty( $menu_item->object_id ) && ! empty( $menu_item->object ) ) {
1122
- if ( isset( $menu_item->type ) && 'taxonomy' === $menu_item->type ) {
1123
- if ( ! $this->is_restricted_term( $menu_item->object_id ) ) {
1124
- $filtered_items[] = $menu_item;
1125
- continue;
1126
- }
1127
- } elseif ( isset( $menu_item->type ) && 'post_type' === $menu_item->type ) {
1128
- if ( ! $this->is_restricted( $menu_item->object_id ) ) {
1129
- $filtered_items[] = $menu_item;
1130
- continue;
1131
- } else {
1132
- $restriction_settings = $this->get_post_privacy_settings( $menu_item->object_id );
1133
- if ( empty( $restriction_settings['_um_access_hide_from_queries'] ) || ! UM()->options()->get( 'disable_restriction_pre_queries' ) ) {
1134
- $filtered_items[] = $this->maybe_replace_nav_menu_title( $menu_item );
1135
- continue;
1136
- }
1137
- }
1138
- } elseif ( isset( $menu_item->type ) && 'custom' === $menu_item->type ) {
1139
- $filtered_items[] = $menu_item;
1140
- continue;
1141
- } else {
1142
- $filtered_items[] = $menu_item;
1143
- continue;
1144
- }
1145
- } else {
1146
- //add all other posts
1147
- $filtered_items[] = $menu_item;
1148
- }
1149
- }
1150
-
1151
- return $filtered_items;
1152
- }
1153
-
1154
-
1155
- /**
1156
- * @param $block_content
1157
- * @param $block
1158
- *
1159
- * @return string
1160
- */
1161
- function restrict_blocks( $block_content, $block ) {
1162
- if ( is_admin() ) {
1163
- return $block_content;
1164
- }
1165
-
1166
- $restricted_blocks = UM()->options()->get( 'restricted_blocks' );
1167
- if ( empty( $restricted_blocks ) ) {
1168
- return $block_content;
1169
- }
1170
-
1171
- if ( is_user_logged_in() && current_user_can( 'administrator' ) ) {
1172
- return $block_content;
1173
- }
1174
-
1175
- if ( ! isset( $block['attrs']['um_is_restrict'] ) || $block['attrs']['um_is_restrict'] !== true ) {
1176
- return $block_content;
1177
- }
1178
-
1179
- if ( empty( $block['attrs']['um_who_access'] ) ) {
1180
- return $block_content;
1181
- }
1182
-
1183
- $default_message = UM()->options()->get( 'restricted_block_message' );
1184
- switch ( $block['attrs']['um_who_access'] ) {
1185
- case '1': {
1186
- if ( ! is_user_logged_in() ) {
1187
- $block_content = '';
1188
- if ( isset( $block['attrs']['um_message_type'] ) ) {
1189
- if ( $block['attrs']['um_message_type'] == '1' ) {
1190
- $block_content = $default_message;
1191
- } elseif ( $block['attrs']['um_message_type'] == '2' ) {
1192
- $block_content = $block['attrs']['um_message_content'];
1193
- }
1194
- }
1195
- } else {
1196
- $display = true;
1197
-
1198
- // What roles can access this content?
1199
- if ( ! empty( $block['attrs']['um_roles_access'] ) ) {
1200
- $display = false;
1201
- foreach ( $block['attrs']['um_roles_access'] as $role ) {
1202
- if ( current_user_can( $role ) ) {
1203
- $display = true;
1204
- }
1205
- }
1206
- }
1207
-
1208
- $display = apply_filters( 'um_loggedin_block_restriction', $display, $block );
1209
-
1210
- if ( ! $display ) {
1211
- $block_content = '';
1212
- if ( isset( $block['attrs']['um_message_type'] ) ) {
1213
- if ( $block['attrs']['um_message_type'] == '1' ) {
1214
- $block_content = $default_message;
1215
- } elseif ( $block['attrs']['um_message_type'] == '2' ) {
1216
- $block_content = $block['attrs']['um_message_content'];
1217
- }
1218
- }
1219
- }
1220
- }
1221
- break;
1222
- }
1223
- case '2': {
1224
- if ( is_user_logged_in() ) {
1225
- $block_content = '';
1226
- if ( isset( $block['attrs']['um_message_type'] ) ) {
1227
- if ( $block['attrs']['um_message_type'] == '1' ) {
1228
- $block_content = $default_message;
1229
- } elseif ( $block['attrs']['um_message_type'] == '2' ) {
1230
- $block_content = $block['attrs']['um_message_content'];
1231
- }
1232
- }
1233
- }
1234
- break;
1235
- }
1236
- }
1237
-
1238
- return $block_content;
1239
- }
1240
-
1241
-
1242
- /**
1243
- * @param \WP_Post $post
1244
- *
1245
- * @return \WP_Post
1246
- */
1247
- function maybe_replace_title( $post ) {
1248
- if ( ! UM()->options()->get( 'restricted_post_title_replace' ) ) {
1249
- return $post;
1250
- }
1251
-
1252
- if ( current_user_can( 'administrator' ) ) {
1253
- return $post;
1254
- }
1255
-
1256
- if ( ! is_a( $post, '\WP_Post' ) ) {
1257
- return $post;
1258
- }
1259
-
1260
- $ignore = apply_filters( 'um_ignore_restricted_title', false, $post->ID );
1261
- if ( $ignore ) {
1262
- return $post;
1263
- }
1264
-
1265
- $restricted_global_title = UM()->options()->get( 'restricted_access_post_title' );
1266
- $post->post_title = stripslashes( $restricted_global_title );
1267
-
1268
- return $post;
1269
- }
1270
-
1271
-
1272
- /**
1273
- * @param \WP_Post $nav_item
1274
- *
1275
- * @return \WP_Post
1276
- */
1277
- function maybe_replace_nav_menu_title( $nav_item ) {
1278
- if ( ! UM()->options()->get( 'restricted_post_title_replace' ) ) {
1279
- return $nav_item;
1280
- }
1281
-
1282
- if ( current_user_can( 'administrator' ) ) {
1283
- return $nav_item;
1284
- }
1285
-
1286
- if ( ! is_a( $nav_item, '\WP_Post' ) ) {
1287
- return $nav_item;
1288
- }
1289
-
1290
- $ignore = apply_filters( 'um_ignore_restricted_title', false, $nav_item->ID );
1291
- if ( $ignore ) {
1292
- return $nav_item;
1293
- }
1294
-
1295
- $restricted_global_title = UM()->options()->get( 'restricted_access_post_title' );
1296
- $nav_item->title = stripslashes( $restricted_global_title );
1297
-
1298
- return $nav_item;
1299
- }
1300
-
1301
-
1302
- /**
1303
- * Protect Post Types in query
1304
- * Restrict content new logic
1305
- *
1306
- * @param array $posts
1307
- * @param array|\WP_Query $query
1308
- * @return array
1309
- */
1310
- function filter_protected_posts( $posts, $query ) {
1311
- if ( current_user_can( 'administrator' ) ) {
1312
- return $posts;
1313
- }
1314
-
1315
- //Woocommerce AJAX fixes....remove filtration on wc-ajax which goes to Front Page
1316
- if ( ! empty( $_GET['wc-ajax'] ) && defined( 'WC_DOING_AJAX' ) && WC_DOING_AJAX ) {
1317
- return $posts;
1318
- }
1319
-
1320
- //if empty
1321
- if ( empty( $posts ) || is_admin() ) {
1322
- return $posts;
1323
- }
1324
-
1325
- if ( is_object( $query ) ) {
1326
- $is_singular = $query->is_singular();
1327
- } else {
1328
- $is_singular = ! empty( $query->is_singular ) ? true : false;
1329
- }
1330
-
1331
- if ( is_object( $query ) && is_a( $query, '\WP_Query' ) &&
1332
- ( $query->is_main_query() || ! empty( $query->query_vars['um_main_query'] ) ) ) {
1333
- if ( $is_singular ) {
1334
- if ( ! UM()->options()->get( 'disable_restriction_pre_queries' ) && $this->is_restricted( $posts[0]->ID ) ) {
1335
- $content_restriction = $this->get_post_privacy_settings( $posts[0]->ID );
1336
- if ( ! empty( $content_restriction['_um_access_hide_from_queries'] ) ) {
1337
- unset( $posts[0] );
1338
- return $posts;
1339
- }
1340
- }
1341
- }
1342
- }
1343
-
1344
- $filtered_posts = array();
1345
-
1346
- //other filter
1347
- foreach ( $posts as $post ) {
1348
- if ( is_user_logged_in() && isset( $post->post_author ) && $post->post_author == get_current_user_id() ) {
1349
- $filtered_posts[] = $post;
1350
- continue;
1351
- }
1352
-
1353
- $restriction = $this->get_post_privacy_settings( $post );
1354
- if ( ! $restriction ) {
1355
- $filtered_posts[] = $post;
1356
- continue;
1357
- }
1358
-
1359
- if ( $is_singular ) {
1360
- $this->singular_page = true;
1361
- }
1362
-
1363
- if ( ! $this->is_restricted( $post->ID ) ) {
1364
- $filtered_posts[] = $post;
1365
- continue;
1366
- } else {
1367
- if ( $is_singular ) {
1368
- if ( ! isset( $restriction['_um_noaccess_action'] ) || '0' == $restriction['_um_noaccess_action'] ) {
1369
- if ( UM()->options()->get( 'disable_restriction_pre_queries' ) || empty( $restriction['_um_access_hide_from_queries'] ) ) {
1370
- /**
1371
- * UM hook
1372
- *
1373
- * @type action
1374
- * @title um_access_fix_external_post_content
1375
- * @description Hook for 3-d party content filtration
1376
- * @change_log
1377
- * ["Since: 2.0"]
1378
- * @usage add_action( 'um_access_fix_external_post_content', 'function_name', 10 );
1379
- * @example
1380
- * <?php
1381
- * add_action( 'um_access_fix_external_post_content', 'my_access_fix_external_post_content', 10 );
1382
- * function my_access_fix_external_post_content() {
1383
- * // your code here
1384
- * }
1385
- * ?>
1386
- */
1387
- do_action( 'um_access_fix_external_post_content' );
1388
-
1389
- $filtered_posts[] = $this->maybe_replace_title( $post );
1390
- continue;
1391
- }
1392
- } elseif ( '1' == $restriction['_um_noaccess_action'] ) {
1393
- $curr = UM()->permalinks()->get_current_url();
1394
-
1395
- if ( ! isset( $restriction['_um_access_redirect'] ) || '0' == $restriction['_um_access_redirect'] ) {
1396
-
1397
- exit( wp_redirect( esc_url( add_query_arg( 'redirect_to', urlencode_deep( $curr ), um_get_core_page( 'login' ) ) ) ) );
1398
-
1399
- } elseif ( '1' == $restriction['_um_access_redirect'] ) {
1400
-
1401
- if ( ! empty( $restriction['_um_access_redirect_url'] ) ) {
1402
- $redirect = $restriction['_um_access_redirect_url'];
1403
- } else {
1404
- $redirect = esc_url( add_query_arg( 'redirect_to', urlencode_deep( $curr ), um_get_core_page( 'login' ) ) );
1405
- }
1406
-
1407
- exit( wp_redirect( $redirect ) );
1408
- }
1409
- }
1410
- } else {
1411
- if ( empty( $restriction['_um_access_hide_from_queries'] ) || ! UM()->options()->get( 'disable_restriction_pre_queries' ) ) {
1412
- $filtered_posts[] = $this->maybe_replace_title( $post );
1413
- continue;
1414
- }
1415
- }
1416
- }
1417
- }
1418
-
1419
- return $filtered_posts;
1420
- }
1421
-
1422
-
1423
- /**
1424
- * Set custom access actions and redirection
1425
- *
1426
- * Old global restrict content logic
1427
- */
1428
- function template_redirect() {
1429
- global $post, $wp_query;
1430
-
1431
- //if we logged by administrator it can access to all content
1432
- if ( current_user_can( 'administrator' ) ) {
1433
- return;
1434
- }
1435
-
1436
- if ( is_object( $wp_query ) ) {
1437
- $is_singular = $wp_query->is_singular();
1438
- } else {
1439
- $is_singular = ! empty( $wp_query->is_singular ) ? true : false;
1440
- }
1441
-
1442
- //if we use individual restrict content options skip this function
1443
- if ( $is_singular && $this->singular_page ) {
1444
- return;
1445
- }
1446
-
1447
- //also skip if we currently at wp-admin or 404 page
1448
- if ( is_admin() || is_404() ) {
1449
- return;
1450
- }
1451
-
1452
- //also skip if we currently at UM Register|Login|Reset Password pages
1453
- if ( um_is_core_post( $post, 'register' ) ||
1454
- um_is_core_post( $post, 'password-reset' ) ||
1455
- um_is_core_post( $post, 'login' ) ) {
1456
- return;
1457
- }
1458
-
1459
- /**
1460
- * UM hook
1461
- *
1462
- * @type action
1463
- * @title um_roles_add_meta_boxes_um_role_meta
1464
- * @description Check terms individual restrict options
1465
- * @change_log
1466
- * ["Since: 2.0"]
1467
- * @usage add_action( 'um_access_check_individual_term_settings', 'function_name', 10 );
1468
- * @example
1469
- * <?php
1470
- * add_action( 'um_access_check_individual_term_settings', 'my_access_check_individual_term_settings', 10 );
1471
- * function my_access_check_individual_term_settings() {
1472
- * // your code here
1473
- * }
1474
- * ?>
1475
- */
1476
- do_action( 'um_access_check_individual_term_settings' );
1477
- //exit from function if term page is accessible
1478
- if ( $this->check_access() ) {
1479
- return;
1480
- }
1481
-
1482
- /**
1483
- * UM hook
1484
- *
1485
- * @type action
1486
- * @title um_access_check_global_settings
1487
- * @description Check global restrict content options
1488
- * @change_log
1489
- * ["Since: 2.0"]
1490
- * @usage add_action( 'um_access_check_global_settings', 'function_name', 10 );
1491
- * @example
1492
- * <?php
1493
- * add_action( 'um_access_check_global_settings', 'my_access_check_global_settings', 10 );
1494
- * function my_access_check_global_settings() {
1495
- * // your code here
1496
- * }
1497
- * ?>
1498
- */
1499
- do_action( 'um_access_check_global_settings' );
1500
-
1501
- $this->check_access();
1502
- }
1503
-
1504
-
1505
- /**
1506
- * Check individual term Content Restriction settings
1507
- */
1508
- function um_access_check_individual_term_settings() {
1509
- //check only tax|tags|categories - skip archive, author, and date lists
1510
- if ( ! ( is_tax() || is_tag() || is_category() ) ) {
1511
- return;
1512
- }
1513
-
1514
- $term_id = null;
1515
- if ( is_tag() ) {
1516
- $term_id = get_query_var( 'tag_id' );
1517
- } elseif ( is_category() ) {
1518
- $term_id = get_query_var( 'cat' );
1519
- } elseif ( is_tax() ) {
1520
- $tax_name = get_query_var( 'taxonomy' );
1521
-
1522
- $term_name = get_query_var( 'term' );
1523
- $term = get_term_by( 'slug', $term_name, $tax_name );
1524
-
1525
- $term_id = ! empty( $term->term_id ) ? $term->term_id : $term_id;
1526
- }
1527
-
1528
- if ( ! isset( $term_id ) ) {
1529
- return;
1530
- }
1531
-
1532
- if ( $this->is_restricted_term( $term_id, true ) ) {
1533
- $restriction = get_term_meta( $term_id, 'um_content_restriction', true );
1534
- if ( '1' == $restriction['_um_noaccess_action'] ) {
1535
- $curr = UM()->permalinks()->get_current_url();
1536
-
1537
- if ( ! isset( $restriction['_um_access_redirect'] ) || '0' == $restriction['_um_access_redirect'] ) {
1538
-
1539
- $this->redirect_handler = $this->set_referer( esc_url( add_query_arg( 'redirect_to', urlencode_deep( $curr ), um_get_core_page( 'login' ) ) ), 'individual_term' );
1540
-
1541
- } elseif ( '1' == $restriction['_um_access_redirect'] ) {
1542
-
1543
- if ( ! empty( $restriction['_um_access_redirect_url'] ) ) {
1544
- $redirect = $restriction['_um_access_redirect_url'];
1545
- } else {
1546
- $redirect = esc_url( add_query_arg( 'redirect_to', urlencode_deep( $curr ), um_get_core_page( 'login' ) ) );
1547
- }
1548
-
1549
- $this->redirect_handler = $this->set_referer( $redirect, 'individual_term' );
1550
-
1551
- }
1552
- } else {
1553
- add_filter( 'tag_template', array( &$this, 'taxonomy_message' ), 10, 3 );
1554
- add_filter( 'archive_template', array( &$this, 'taxonomy_message' ), 10, 3 );
1555
- add_filter( 'category_template', array( &$this, 'taxonomy_message' ), 10, 3 );
1556
- add_filter( 'taxonomy_template', array( &$this, 'taxonomy_message' ), 10, 3 );
1557
- }
1558
- }
1559
- }
1560
-
1561
-
1562
- /**
1563
- * @param $template
1564
- * @param $type
1565
- * @param $templates
1566
- *
1567
- * @return string
1568
- */
1569
- function taxonomy_message( $template, $type, $templates ) {
1570
- return UM()->locate_template( 'restricted-taxonomy.php' );
1571
- }
1572
-
1573
-
1574
- /**
1575
- * Check global accessible settings
1576
- */
1577
- function um_access_check_global_settings() {
1578
- global $post;
1579
-
1580
- $curr = UM()->permalinks()->get_current_url();
1581
- $ms_empty_role_access = is_multisite() && is_user_logged_in() && ! UM()->roles()->get_priority_user_role( um_user( 'ID' ) );
1582
-
1583
- if ( is_front_page() ) {
1584
- if ( is_user_logged_in() && ! $ms_empty_role_access ) {
1585
-
1586
- $user_default_homepage = um_user( 'default_homepage' );
1587
- if ( ! empty( $user_default_homepage ) ) {
1588
- return;
1589
- }
1590
-
1591
- $redirect_homepage = um_user( 'redirect_homepage' );
1592
- /**
1593
- * UM hook
1594
- *
1595
- * @type filter
1596
- * @title um_custom_homepage_redirect_url
1597
- * @description Change custom homepage redirect
1598
- * @input_vars
1599
- * [{"var":"$url","type":"string","desc":"Redirect URL"},
1600
- * {"var":"$id","type":"int","desc":"User ID"}]
1601
- * @change_log
1602
- * ["Since: 2.0"]
1603
- * @usage
1604
- * <?php add_filter( 'um_custom_homepage_redirect_url', 'function_name', 10, 2 ); ?>
1605
- * @example
1606
- * <?php
1607
- * add_filter( 'um_custom_homepage_redirect_url', 'my_custom_homepage_redirect_url', 10, 2 );
1608
- * function my_custom_homepage_redirect_url( $url, $id ) {
1609
- * // your code here
1610
- * return $url;
1611
- * }
1612
- * ?>
1613
- */
1614
- $redirect_homepage = apply_filters( 'um_custom_homepage_redirect_url', $redirect_homepage, um_user( 'ID' ) );
1615
- $redirect_to = ! empty( $redirect_homepage ) ? $redirect_homepage : um_get_core_page( 'user' );
1616
- $this->redirect_handler = $this->set_referer( esc_url( add_query_arg( 'redirect_to', urlencode_deep( $curr ), $redirect_to ) ), 'custom_homepage' );
1617
-
1618
- } else {
1619
- $access = UM()->options()->get( 'accessible' );
1620
-
1621
- if ( $access == 2 ) {
1622
- //global settings for accessible home page
1623
- $home_page_accessible = UM()->options()->get( 'home_page_accessible' );
1624
-
1625
- if ( $home_page_accessible == 0 ) {
1626
- //get redirect URL if not set get login page by default
1627
- $redirect = UM()->options()->get( 'access_redirect' );
1628
- if ( ! $redirect ) {
1629
- $redirect = um_get_core_page( 'login' );
1630
- }
1631
-
1632
- $this->redirect_handler = $this->set_referer( esc_url( add_query_arg( 'redirect_to', urlencode_deep( $curr ), $redirect ) ), 'global' );
1633
- } else {
1634
- $this->allow_access = true;
1635
- return;
1636
- }
1637
- }
1638
- }
1639
- } elseif ( is_category() ) {
1640
- if ( ! is_user_logged_in() || $ms_empty_role_access ) {
1641
-
1642
- $access = UM()->options()->get( 'accessible' );
1643
-
1644
- if ( $access == 2 ) {
1645
- //global settings for accessible home page
1646
- $category_page_accessible = UM()->options()->get( 'category_page_accessible' );
1647
- if ( $category_page_accessible == 0 ) {
1648
- //get redirect URL if not set get login page by default
1649
- $redirect = UM()->options()->get( 'access_redirect' );
1650
- if ( ! $redirect ) {
1651
- $redirect = um_get_core_page( 'login' );
1652
- }
1653
-
1654
- $this->redirect_handler = $this->set_referer( esc_url( add_query_arg( 'redirect_to', urlencode_deep( $curr ), $redirect ) ), 'global' );
1655
- } else {
1656
- $this->allow_access = true;
1657
- return;
1658
- }
1659
- }
1660
- }
1661
- }
1662
-
1663
- $access = UM()->options()->get( 'accessible' );
1664
-
1665
- if ( $access == 2 && ( ! is_user_logged_in() || $ms_empty_role_access ) ) {
1666
-
1667
- //build exclude URLs pages
1668
- $redirects = array();
1669
- $redirects[] = trim( untrailingslashit( UM()->options()->get( 'access_redirect' ) ) );
1670
-
1671
- $exclude_uris = UM()->options()->get( 'access_exclude_uris' );
1672
- if ( ! empty( $exclude_uris ) ) {
1673
- $exclude_uris = array_map( 'trim', $exclude_uris );
1674
- $redirects = array_merge( $redirects, $exclude_uris );
1675
- }
1676
-
1677
- $redirects = array_unique( $redirects );
1678
-
1679
- $current_url = UM()->permalinks()->get_current_url( get_option( 'permalink_structure' ) );
1680
- $current_url = untrailingslashit( $current_url );
1681
- $current_url_slash = trailingslashit( $current_url );
1682
-
1683
- if ( ! ( isset( $post->ID ) && ( in_array( $current_url, $redirects ) || in_array( $current_url_slash, $redirects ) ) ) ) {
1684
- //if current page not in exclude URLs
1685
- //get redirect URL if not set get login page by default
1686
- $redirect = UM()->options()->get( 'access_redirect' );
1687
- if ( ! $redirect ) {
1688
- $redirect = um_get_core_page( 'login' );
1689
- }
1690
-
1691
- $this->redirect_handler = $this->set_referer( esc_url( add_query_arg( 'redirect_to', urlencode_deep( $curr ), $redirect ) ), 'global' );
1692
- } else {
1693
- $this->redirect_handler = false;
1694
- $this->allow_access = true;
1695
- }
1696
- }
1697
- }
1698
-
1699
-
1700
- /**
1701
- * Check access
1702
- *
1703
- * @return bool
1704
- */
1705
- function check_access() {
1706
- if ( $this->allow_access === true ) {
1707
- return true;
1708
- }
1709
-
1710
- if ( $this->redirect_handler ) {
1711
- wp_redirect( $this->redirect_handler );
1712
- exit;
1713
- }
1714
-
1715
- return false;
1716
- }
1717
-
1718
-
1719
- /**
1720
- * Sets a custom access referer in a redirect URL
1721
- *
1722
- * @param string $url
1723
- * @param string $referer
1724
- *
1725
- * @return string
1726
- */
1727
- function set_referer( $url, $referer ) {
1728
-
1729
- /**
1730
- * UM hook
1731
- *
1732
- * @type filter
1733
- * @title um_access_enable_referer
1734
- * @description Access Referrer Enable/Disable
1735
- * @input_vars
1736
- * [{"var":"$referrer","type":"bool","desc":"Access referrer"}]
1737
- * @change_log
1738
- * ["Since: 2.0"]
1739
- * @usage add_filter( 'um_access_enable_referer', 'function_name', 10, 1 );
1740
- * @example
1741
- * <?php
1742
- * add_filter( 'um_access_enable_referer', 'my_access_enable_referer', 10, 1 );
1743
- * function my_access_enable_referer( $referrer ) {
1744
- * // your code here
1745
- * return $referrer;
1746
- * }
1747
- * ?>
1748
- */
1749
- $enable_referer = apply_filters( 'um_access_enable_referer', false );
1750
- if ( ! $enable_referer ) {
1751
- return $url;
1752
- }
1753
-
1754
- $url = add_query_arg( 'um_ref', $referer, $url );
1755
- return $url;
1756
- }
1757
-
1758
-
1759
- /**
1760
- * Get privacy settings for post
1761
- * return false if post is not private
1762
- * Restrict content new logic
1763
- *
1764
- * @param \WP_Post|int $post Post ID or object
1765
- * @return bool|array
1766
- */
1767
- function get_post_privacy_settings( $post ) {
1768
- // break for incorrect post
1769
- if ( empty( $post ) ) {
1770
- return false;
1771
- }
1772
-
1773
- static $cache = array();
1774
-
1775
- $cache_key = is_numeric( $post ) ? $post : $post->ID;
1776
-
1777
- if ( isset( $cache[ $cache_key ] ) ) {
1778
- return $cache[ $cache_key ];
1779
- }
1780
-
1781
- if ( is_numeric( $post ) ) {
1782
- $post = get_post( $post );
1783
- }
1784
-
1785
- //if logged in administrator all pages are visible
1786
- if ( current_user_can( 'administrator' ) ) {
1787
- $cache[ $cache_key ] = false;
1788
- return false;
1789
- }
1790
-
1791
- $exclude = false;
1792
- //exclude from privacy UM default pages (except Members list and User(Profile) page)
1793
- if ( ! empty( $post->post_type ) && $post->post_type === 'page' ) {
1794
-
1795
- if ( um_is_core_post( $post, 'login' ) || um_is_core_post( $post, 'register' ) ||
1796
- um_is_core_post( $post, 'account' ) || um_is_core_post( $post, 'logout' ) ||
1797
- um_is_core_post( $post, 'password-reset' ) || ( is_user_logged_in() && um_is_core_post( $post, 'user' ) ) )
1798
- $exclude = true;
1799
- }
1800
-
1801
- $exclude = apply_filters( 'um_exclude_posts_from_privacy', $exclude, $post );
1802
- if ( $exclude ) {
1803
- $cache[ $cache_key ] = false;
1804
- return false;
1805
- }
1806
-
1807
- $restricted_posts = UM()->options()->get( 'restricted_access_post_metabox' );
1808
-
1809
- if ( ! empty( $post->post_type ) && ! empty( $restricted_posts[ $post->post_type ] ) ) {
1810
- $restriction = get_post_meta( $post->ID, 'um_content_restriction', true );
1811
-
1812
- if ( ! empty( $restriction['_um_custom_access_settings'] ) ) {
1813
- if ( ! isset( $restriction['_um_accessible'] ) ) {
1814
- $restricted_taxonomies = UM()->options()->get( 'restricted_access_taxonomy_metabox' );
1815
-
1816
- //get all taxonomies for current post type
1817
- $taxonomies = get_object_taxonomies( $post );
1818
-
1819
- //get all post terms
1820
- $terms = array();
1821
- if ( ! empty( $taxonomies ) ) {
1822
- foreach ( $taxonomies as $taxonomy ) {
1823
- if ( empty( $restricted_taxonomies[ $taxonomy ] ) ) {
1824
- continue;
1825
- }
1826
-
1827
- $terms = array_merge( $terms, wp_get_post_terms( $post->ID, $taxonomy, array( 'fields' => 'ids', 'um_ignore_exclude' => true, ) ) );
1828
- }
1829
- }
1830
-
1831
- //get restriction options for first term with privacy settigns
1832
- foreach ( $terms as $term_id ) {
1833
- $restriction = get_term_meta( $term_id, 'um_content_restriction', true );
1834
-
1835
- if ( ! empty( $restriction['_um_custom_access_settings'] ) ) {
1836
- if ( ! isset( $restriction['_um_accessible'] ) ) {
1837
- continue;
1838
- } else {
1839
- $cache[ $cache_key ] = $restriction;
1840
- return $restriction;
1841
- }
1842
- }
1843
- }
1844
-
1845
- $cache[ $cache_key ] = false;
1846
- return false;
1847
- } else {
1848
-
1849
- // set default redirect if Profile page is restricted for not-logged in users and showing message instead of redirect
1850
- // this snippet was added to make the same action for {site_url}/user and {site_url}/user/{user_slug} URLs
1851
- // 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
1852
- if ( ! is_user_logged_in() && um_is_core_post( $post, 'user' ) && $restriction['_um_accessible'] == '2' && $restriction['_um_noaccess_action'] == '0' ) {
1853
- if ( isset( $restriction['_um_access_roles'] ) ) {
1854
- $restriction = array(
1855
- '_um_accessible' => '2',
1856
- '_um_access_roles' => $restriction['_um_access_roles'],
1857
- '_um_noaccess_action' => '1',
1858
- '_um_access_redirect' => '1',
1859
- '_um_access_redirect_url' => get_home_url( get_current_blog_id() )
1860
- );
1861
- } else {
1862
- $restriction = array(
1863
- '_um_accessible' => '2',
1864
- '_um_noaccess_action' => '1',
1865
- '_um_access_redirect' => '1',
1866
- '_um_access_redirect_url' => get_home_url( get_current_blog_id() )
1867
- );
1868
- }
1869
- }
1870
-
1871
- $restriction = apply_filters( 'um_post_content_restriction_settings', $restriction, $post );
1872
-
1873
- $cache[ $cache_key ] = $restriction;
1874
- return $restriction;
1875
- }
1876
- }
1877
- }
1878
-
1879
- //post hasn't privacy settings....check all terms of this post
1880
- $restricted_taxonomies = UM()->options()->get( 'restricted_access_taxonomy_metabox' );
1881
-
1882
- //get all taxonomies for current post type
1883
- $taxonomies = get_object_taxonomies( $post );
1884
-
1885
- //get all post terms
1886
- $terms = array();
1887
- if ( ! empty( $taxonomies ) ) {
1888
- foreach ( $taxonomies as $taxonomy ) {
1889
- if ( empty( $restricted_taxonomies[ $taxonomy ] ) ) {
1890
- continue;
1891
- }
1892
-
1893
- $terms = array_merge( $terms, wp_get_post_terms( $post->ID, $taxonomy, array( 'fields' => 'ids', 'um_ignore_exclude' => true, ) ) );
1894
- }
1895
- }
1896
-
1897
- //get restriction options for first term with privacy settings
1898
- foreach ( $terms as $term_id ) {
1899
- $restriction = get_term_meta( $term_id, 'um_content_restriction', true );
1900
-
1901
- if ( ! empty( $restriction['_um_custom_access_settings'] ) ) {
1902
- if ( ! isset( $restriction['_um_accessible'] ) ) {
1903
- continue;
1904
- } else {
1905
- $cache[ $cache_key ] = $restriction;
1906
- return $restriction;
1907
- }
1908
- }
1909
- }
1910
-
1911
- $cache[ $cache_key ] = false;
1912
- //post is public
1913
- return false;
1914
- }
1915
-
1916
-
1917
- /**
1918
- * Helper for checking if the user can some of the roles array
1919
- *
1920
- * @param $user_id
1921
- * @param $roles
1922
- * @return bool
1923
- */
1924
- function user_can( $user_id, $roles ) {
1925
- $user_can = false;
1926
-
1927
- if ( ! empty( $roles ) ) {
1928
- foreach ( $roles as $key => $value ) {
1929
- if ( ! empty( $value ) && user_can( $user_id, $key ) ) {
1930
- $user_can = true;
1931
- break;
1932
- }
1933
- }
1934
- }
1935
-
1936
- return $user_can;
1937
- }
1938
-
1939
-
1940
- /**
1941
- * Helper for 3rd-party integrations with content restriction settings
1942
- *
1943
- * @param array $restriction
1944
- *
1945
- * @return bool
1946
- */
1947
- function um_custom_restriction( $restriction ) {
1948
- /**
1949
- * UM hook
1950
- *
1951
- * @type filter
1952
- * @title um_custom_restriction
1953
- * @description Extend Sort Types for Member Directory
1954
- * @input_vars
1955
- * [{"var":"$custom_restriction","type":"bool","desc":"Custom Restriction"},
1956
- * {"var":"$restriction","type":"array","desc":"Restriction settings"}]
1957
- * @change_log
1958
- * ["Since: 2.0"]
1959
- * @usage add_filter( 'um_custom_restriction', 'function_name', 10, 2 );
1960
- * @example
1961
- * <?php
1962
- * add_filter( 'um_custom_restriction', 'my_custom_restriction', 10, 2 );
1963
- * function my_directory_sort_users_select( $custom_restriction, $restriction ) {
1964
- * // your code here
1965
- * return $custom_restriction;
1966
- * }
1967
- * ?>
1968
- */
1969
- return apply_filters( 'um_custom_restriction', true, $restriction );
1970
- }
1971
-
1972
-
1973
- /**
1974
- * Is post restricted?
1975
- *
1976
- * @param int $post_id
1977
- * @return bool
1978
- */
1979
- function is_restricted( $post_id ) {
1980
- // break for incorrect post
1981
- if ( empty( $post_id ) ) {
1982
- return false;
1983
- }
1984
-
1985
- static $cache = array();
1986
-
1987
- if ( isset( $cache[ $post_id ] ) ) {
1988
- return $cache[ $post_id ];
1989
- }
1990
-
1991
- if ( current_user_can( 'administrator' ) ) {
1992
- $cache[ $post_id ] = false;
1993
- return false;
1994
- }
1995
-
1996
- $post = get_post( $post_id );
1997
- if ( is_user_logged_in() && isset( $post->post_author ) && $post->post_author == get_current_user_id() ) {
1998
- $cache[ $post_id ] = false;
1999
- return false;
2000
- }
2001
-
2002
- $restricted = true;
2003
-
2004
- $restriction = $this->get_post_privacy_settings( $post_id );
2005
- if ( ! $restriction ) {
2006
- $restricted = false;
2007
- } else {
2008
- if ( '0' == $restriction['_um_accessible'] ) {
2009
- //post is private
2010
- $restricted = false;
2011
- } elseif ( '1' == $restriction['_um_accessible'] ) {
2012
- //if post for not logged in users and user is not logged in
2013
- if ( ! is_user_logged_in() ) {
2014
- $restricted = false;
2015
- }
2016
- } elseif ( '2' == $restriction['_um_accessible'] ) {
2017
- //if post for logged in users and user is not logged in
2018
- if ( is_user_logged_in() ) {
2019
- $custom_restrict = $this->um_custom_restriction( $restriction );
2020
-
2021
- if ( empty( $restriction['_um_access_roles'] ) || false === array_search( '1', $restriction['_um_access_roles'] ) ) {
2022
- if ( $custom_restrict ) {
2023
- $restricted = false;
2024
- }
2025
- } else {
2026
- $user_can = $this->user_can( get_current_user_id(), $restriction['_um_access_roles'] );
2027
-
2028
- if ( $user_can && $custom_restrict ) {
2029
- $restricted = false;
2030
- }
2031
- }
2032
- }
2033
- }
2034
- }
2035
-
2036
- $restricted = apply_filters( 'um_is_restricted_post', $restricted, $post_id );
2037
-
2038
- $cache[ $post_id ] = $restricted;
2039
-
2040
- return $restricted;
2041
- }
2042
-
2043
-
2044
- /**
2045
- * Is term restricted?
2046
- *
2047
- * @param int $term_id
2048
- * @param bool $on_term_page
2049
- * @return bool
2050
- */
2051
- function is_restricted_term( $term_id, $on_term_page = false ) {
2052
- static $cache = array();
2053
-
2054
- if ( isset( $cache[ $term_id ] ) ) {
2055
- return $cache[ $term_id ];
2056
- }
2057
-
2058
- if ( current_user_can( 'administrator' ) ) {
2059
- $cache[ $term_id ] = false;
2060
- return false;
2061
- }
2062
-
2063
- $restricted_taxonomies = UM()->options()->get( 'restricted_access_taxonomy_metabox' );
2064
- if ( empty( $restricted_taxonomies ) ) {
2065
- $cache[ $term_id ] = false;
2066
- return false;
2067
- }
2068
-
2069
- $term = get_term( $term_id );
2070
- if ( empty( $term->taxonomy ) || empty( $restricted_taxonomies[ $term->taxonomy ] ) ) {
2071
- $cache[ $term_id ] = false;
2072
- return false;
2073
- }
2074
-
2075
- $restricted = true;
2076
-
2077
- // $this->allow_access = true only in case if the
2078
-
2079
- $restriction = get_term_meta( $term_id, 'um_content_restriction', true );
2080
- if ( empty( $restriction ) ) {
2081
- $restricted = false;
2082
- } else {
2083
- if ( empty( $restriction['_um_custom_access_settings'] ) ) {
2084
- $restricted = false;
2085
- } else {
2086
- if ( '0' == $restriction['_um_accessible'] ) {
2087
- //term is private
2088
- $restricted = false;
2089
- if ( $on_term_page ) {
2090
- $this->allow_access = true;
2091
- }
2092
- } elseif ( '1' == $restriction['_um_accessible'] ) {
2093
- //if term for not logged in users and user is not logged in
2094
- if ( ! is_user_logged_in() ) {
2095
- $restricted = false;
2096
- if ( $on_term_page ) {
2097
- $this->allow_access = true;
2098
- }
2099
- }
2100
- } elseif ( '2' == $restriction['_um_accessible'] ) {
2101
- //if term for logged in users and user is not logged in
2102
- if ( is_user_logged_in() ) {
2103
- $custom_restrict = $this->um_custom_restriction( $restriction );
2104
-
2105
- if ( empty( $restriction['_um_access_roles'] ) || false === array_search( '1', $restriction['_um_access_roles'] ) ) {
2106
- if ( $custom_restrict ) {
2107
- $restricted = false;
2108
- if ( $on_term_page ) {
2109
- $this->allow_access = true;
2110
- }
2111
- }
2112
- } else {
2113
- $user_can = $this->user_can( get_current_user_id(), $restriction['_um_access_roles'] );
2114
-
2115
- if ( $user_can && $custom_restrict ) {
2116
- $restricted = false;
2117
- if ( $on_term_page ) {
2118
- $this->allow_access = true;
2119
- }
2120
- }
2121
- }
2122
- }
2123
- }
2124
- }
2125
- }
2126
-
2127
- $restricted = apply_filters( 'um_is_restricted_term', $restricted, $term_id, $on_term_page );
2128
-
2129
- $cache[ $term_id ] = $restricted;
2130
- return $restricted;
2131
- }
2132
- }
2133
- }
 
 
 
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
+ }
includes/core/class-builtin.php CHANGED
@@ -1,1976 +1,1976 @@
1
- <?php
2
- namespace um\core;
3
-
4
- // Exit if accessed directly
5
- if ( ! defined( 'ABSPATH' ) ) exit;
6
-
7
- if ( ! class_exists( 'um\core\Builtin' ) ) {
8
-
9
-
10
- /**
11
- * Class Builtin
12
- * @package um\core
13
- */
14
- class Builtin {
15
-
16
-
17
- /**
18
- * @var array
19
- */
20
- public $predefined_fields = array();
21
-
22
-
23
- /**
24
- * @var array
25
- */
26
- var $all_user_fields = array();
27
-
28
-
29
- /**
30
- * @var array
31
- */
32
- var $core_fields = array();
33
-
34
-
35
- /**
36
- * Builtin constructor.
37
- */
38
- function __construct() {
39
- add_action( 'init', array( &$this, 'set_core_fields' ), 1 );
40
- add_action( 'init', array( &$this, 'set_predefined_fields' ), 1 );
41
- add_action( 'init', array( &$this, 'set_custom_fields' ), 1 );
42
- $this->saved_fields = get_option( 'um_fields' );
43
- }
44
-
45
-
46
- /**
47
- * @return array
48
- */
49
- function get_all_user_fields() {
50
- return apply_filters( 'um_builtin_all_user_fields', $this->all_user_fields );
51
- }
52
-
53
-
54
- /**
55
- * Regular or multi-select/options
56
- *
57
- * @param $field
58
- * @param $attrs
59
- *
60
- * @return bool
61
- */
62
- function is_dropdown_field( $field, $attrs ) {
63
-
64
- if ( isset( $attrs['options'] ) ) {
65
- return true;
66
- }
67
-
68
- $fields = $this->all_user_fields;
69
-
70
- if ( isset( $fields[$field]['options'] ) || ! empty( $fields[$field]['custom_dropdown_options_source'] ) ) {
71
- return true;
72
- }
73
-
74
- return false;
75
- }
76
-
77
-
78
- /**
79
- * Get a field
80
- *
81
- * @param $field
82
- *
83
- * @return mixed|string
84
- */
85
- function get_a_field( $field ) {
86
- $fields = $this->all_user_fields;
87
- if ( isset( $fields[ $field ] ) ) {
88
- return $fields[ $field ];
89
- }
90
- return '';
91
- }
92
-
93
-
94
- /**
95
- * Get specific fields
96
- *
97
- * @param $fields
98
- *
99
- * @return array
100
- */
101
- function get_specific_fields( $fields ) {
102
- $fields = explode( ',', $fields );
103
- $array = array();
104
- foreach ( $fields as $field ) {
105
- if ( isset( $this->predefined_fields[ $field ] ) ) {
106
- $array[ $field ] = $this->predefined_fields[ $field ];
107
- }
108
- }
109
- return $array;
110
- }
111
-
112
-
113
- /**
114
- * Get specific field
115
- *
116
- * @param $fields
117
- *
118
- * @return array|mixed
119
- */
120
- function get_specific_field( $fields ) {
121
- $fields = explode( ',', $fields );
122
- $array = array();
123
- foreach ( $fields as $field ) {
124
- if ( isset( $this->predefined_fields[ $field ] ) ) {
125
- $array = $this->predefined_fields[ $field ];
126
- } elseif ( isset( $this->saved_fields[ $field ] ) ) {
127
- $array = $this->saved_fields[ $field ];
128
- }
129
- }
130
- return $array;
131
- }
132
-
133
-
134
- /**
135
- * Checks for a unique field error
136
- *
137
- * @param $key
138
- *
139
- * @return int|string
140
- */
141
- function unique_field_err( $key ) {
142
- if ( empty( $key ) ) {
143
- return __( 'Please provide a meta key', 'ultimate-member' );
144
- }
145
- if ( isset( $this->core_fields[ $key ] ) ) {
146
- return __( 'Your meta key is a reserved core field and cannot be used', 'ultimate-member' );
147
- }
148
- if ( isset( $this->predefined_fields[ $key ] ) ) {
149
- return __( 'Your meta key is a predefined reserved key and cannot be used', 'ultimate-member' );
150
- }
151
- if ( isset( $this->saved_fields[ $key ] ) ) {
152
- return __( 'Your meta key already exists in your fields list', 'ultimate-member' );
153
- }
154
- if ( ! UM()->validation()->safe_string( $key ) ) {
155
- return __( 'Your meta key contains illegal characters. Please correct it.', 'ultimate-member' );
156
- }
157
-
158
- return 0;
159
- }
160
-
161
-
162
- /**
163
- * Check date range errors (start date)
164
- *
165
- * @param $date
166
- *
167
- * @return int|string
168
- */
169
- function date_range_start_err( $date ) {
170
- if ( empty( $date ) ) {
171
- return __( 'Please provide a date range beginning', 'ultimate-member' );
172
- }
173
- if ( ! UM()->validation()->validate_date( $date ) ) {
174
- return __( 'Please enter a valid start date in the date range', 'ultimate-member' );
175
- }
176
-
177
- return 0;
178
- }
179
-
180
-
181
- /**
182
- * Check date range errors (end date)
183
- *
184
- * @param $date
185
- * @param $start_date
186
- *
187
- * @return int|string
188
- */
189
- function date_range_end_err( $date, $start_date ) {
190
- if ( empty( $date ) ) {
191
- return __( 'Please provide a date range end', 'ultimate-member' );
192
- }
193
- if ( ! UM()->validation()->validate_date( $date ) ) {
194
- return __( 'Please enter a valid end date in the date range', 'ultimate-member' );
195
- }
196
- if ( strtotime( $date ) <= strtotime( $start_date ) ) {
197
- return __( 'The end of date range must be greater than the start of date range', 'ultimate-member' );
198
- }
199
- return 0;
200
- }
201
-
202
-
203
- /**
204
- * Get a core field attrs
205
- *
206
- * @param $type
207
- *
208
- * @return array|mixed
209
- */
210
- function get_core_field_attrs( $type ) {
211
- return ( isset( $this->core_fields[ $type ] ) ) ? $this->core_fields[ $type ] : array('');
212
- }
213
-
214
-
215
- /**
216
- * Core Fields
217
- */
218
- function set_core_fields() {
219
-
220
- $this->core_fields = array(
221
-
222
- 'row' => array(
223
- 'name' => 'Row',
224
- 'in_fields' => false,
225
- 'form_only' => true,
226
- 'conditional_support' => 0,
227
- 'icon' => 'um-faicon-pencil',
228
- 'col1' => array('_id','_background','_text_color','_padding','_margin','_border','_borderradius','_borderstyle','_bordercolor'),
229
- 'col2' => array('_heading','_heading_text','_heading_background_color','_heading_text_color','_icon','_icon_color','_css_class'),
230
- ),
231
-
232
- 'text' => array(
233
- 'name' => 'Text Box',
234
- 'col1' => array('_title','_metakey','_help','_default','_min_chars','_visibility'),
235
- 'col2' => array('_label','_placeholder','_public','_roles','_validate','_custom_validate','_max_chars'),
236
- 'col3' => array('_required','_editable','_icon'),
237
- 'validate' => array(
238
- '_title' => array(
239
- 'mode' => 'required',
240
- 'error' => __('You must provide a title','ultimate-member')
241
- ),
242
- '_metakey' => array(
243
- 'mode' => 'unique',
244
- ),
245
- )
246
- ),
247
-
248
- 'number' => array(
249
- 'name' => __('Number','ultimate-member'),
250
- 'col1' => array('_title','_metakey','_help','_default','_min','_visibility'),
251
- 'col2' => array('_label','_placeholder','_public','_roles','_validate','_custom_validate','_max'),
252
- 'col3' => array('_required','_editable','_icon'),
253
- 'validate' => array(
254
- '_title' => array(
255
- 'mode' => 'required',
256
- 'error' => __('You must provide a title','ultimate-member')
257
- ),
258
- '_metakey' => array(
259
- 'mode' => 'unique',
260
- ),
261
- )
262
- ),
263
-
264
- 'textarea' => array(
265
- 'name' => 'Textarea',
266
- 'col1' => array('_title','_metakey','_help','_height','_max_chars','_max_words','_visibility'),
267
- 'col2' => array('_label','_placeholder','_public','_roles','_default','_html'),
268
- 'col3' => array('_required','_editable','_icon'),
269
- 'validate' => array(
270
- '_title' => array(
271
- 'mode' => 'required',
272
- 'error' => __('You must provide a title','ultimate-member')
273
- ),
274
- '_metakey' => array(
275
- 'mode' => 'unique',
276
- ),
277
- )
278
- ),
279
-
280
- 'select' => array(
281
- 'name' => 'Dropdown',
282
- 'col1' => array('_title','_metakey','_help','_default','_options','_visibility'),
283
- 'col2' => array('_label','_placeholder','_public','_roles','_custom_dropdown_options_source','_parent_dropdown_relationship'),
284
- 'col3' => array('_required','_editable','_icon'),
285
- 'validate' => array(
286
- '_title' => array(
287
- 'mode' => 'required',
288
- 'error' => __('You must provide a title','ultimate-member')
289
- ),
290
- '_metakey' => array(
291
- 'mode' => 'unique',
292
- ),
293
- '_options' => array(
294
- 'mode' => 'required',
295
- 'error' => __('You have not added any choices yet.','ultimate-member')
296
- ),
297
- )
298
- ),
299
-
300
- 'multiselect' => array(
301
- 'name' => 'Multi-Select',
302
- 'col1' => array('_title','_metakey','_help','_default','_options','_visibility'),
303
- 'col2' => array('_label','_placeholder','_public','_roles','_min_selections','_max_selections','_custom_dropdown_options_source'),
304
- 'col3' => array('_required','_editable','_icon'),
305
- 'validate' => array(
306
- '_title' => array(
307
- 'mode' => 'required',
308
- 'error' => __('You must provide a title','ultimate-member')
309
- ),
310
- '_metakey' => array(
311
- 'mode' => 'unique',
312
- ),
313
- '_options' => array(
314
- 'mode' => 'required',
315
- 'error' => __('You have not added any choices yet.','ultimate-member')
316
- ),
317
- )
318
- ),
319
-
320
- 'radio' => array(
321
- 'name' => 'Radio',
322
- 'col1' => array('_title','_metakey','_help','_default','_options','_visibility'),
323
- 'col2' => array('_label','_public','_roles'),
324
- 'col3' => array('_required','_editable','_icon'),
325
- 'validate' => array(
326
- '_title' => array(
327
- 'mode' => 'required',
328
- 'error' => __('You must provide a title','ultimate-member')
329
- ),
330
- '_metakey' => array(
331
- 'mode' => 'unique',
332
- ),
333
- '_options' => array(
334
- 'mode' => 'required',
335
- 'error' => __('You have not added any choices yet.','ultimate-member')
336
- ),
337
- )
338
- ),
339
-
340
- 'checkbox' => array(
341
- 'name' => 'Checkbox',
342
- 'col1' => array('_title','_metakey','_help','_default','_options','_visibility'),
343
- 'col2' => array('_label','_public','_roles','_max_selections'),
344
- 'col3' => array('_required','_editable','_icon'),
345
- 'validate' => array(
346
- '_title' => array(
347
- 'mode' => 'required',
348
- 'error' => __('You must provide a title','ultimate-member')
349
- ),
350
- '_metakey' => array(
351
- 'mode' => 'unique',
352
- ),
353
- '_options' => array(
354
- 'mode' => 'required',
355
- 'error' => __('You have not added any choices yet.','ultimate-member')
356
- ),
357
- )
358
- ),
359
-
360
- 'url' => array(
361
- 'name' => 'URL',
362
- 'col1' => array('_title','_metakey','_help','_default','_url_text','_visibility'),
363
- 'col2' => array('_label','_placeholder','_url_target','_url_rel','_public','_roles','_validate','_custom_validate'),
364
- 'col3' => array('_required','_editable','_icon'),
365
- 'validate' => array(
366
- '_title' => array(
367
- 'mode' => 'required',
368
- 'error' => __('You must provide a title','ultimate-member')
369
- ),
370
- '_metakey' => array(
371
- 'mode' => 'unique',
372
- ),
373
- )
374
- ),
375
-
376
- 'password' => array(
377
- 'name' => 'Password',
378
- 'col1' => array('_title','_metakey','_help','_min_chars','_max_chars','_visibility'),
379
- 'col2' => array('_label','_placeholder','_public','_roles','_force_good_pass','_force_confirm_pass','_label_confirm_pass'),
380
- 'col3' => array('_required','_editable','_icon'),
381
- 'validate' => array(
382
- '_title' => array(
383
- 'mode' => 'required',
384
- 'error' => __('You must provide a title','ultimate-member')
385
- ),
386
- '_metakey' => array(
387
- 'mode' => 'unique',
388
- ),
389
- )
390
- ),
391
-
392
- 'image' => array(
393
- 'name' => 'Image Upload',
394
- 'col1' => array('_title','_metakey','_help','_allowed_types','_max_size','_crop','_visibility'),
395
- 'col2' => array('_label','_public','_roles','_upload_text','_upload_help_text','_button_text'),
396
- 'col3' => array('_required','_editable','_icon'),
397
- 'validate' => array(
398
- '_title' => array(
399
- 'mode' => 'required',
400
- 'error' => __('You must provide a title','ultimate-member')
401
- ),
402
- '_metakey' => array(
403
- 'mode' => 'unique',
404
- ),
405
- '_max_size' => array(
406
- 'mode' => 'numeric',
407
- 'error' => __('Please enter a valid size','ultimate-member')
408
- ),
409
- )
410
- ),
411
-
412
- 'file' => array(
413
- 'name' => 'File Upload',
414
- 'col1' => array('_title','_metakey','_help','_allowed_types','_max_size','_visibility'),
415
- 'col2' => array('_label','_public','_roles','_upload_text','_upload_help_text','_button_text'),
416
- 'col3' => array('_required','_editable','_icon'),
417
- 'validate' => array(
418
- '_title' => array(
419
- 'mode' => 'required',
420
- 'error' => __('You must provide a title','ultimate-member')
421
- ),
422
- '_metakey' => array(
423
- 'mode' => 'unique',
424
- ),
425
- '_max_size' => array(
426
- 'mode' => 'numeric',
427
- 'error' => __( 'Please enter a valid size', 'ultimate-member' )
428
- ),
429
- )
430
- ),
431
-
432
- 'date' => array(
433
- 'name' => 'Date Picker',
434
- 'col1' => array( '_title', '_metakey', '_help', '_default', '_range', '_years', '_years_x', '_range_start', '_range_end', '_visibility' ),
435
- 'col2' => array( '_label', '_placeholder', '_public', '_roles', '_format', '_format_custom', '_pretty_format', '_disabled_weekdays' ),
436
- 'col3' => array( '_required', '_editable', '_icon' ),
437
- 'validate' => array(
438
- '_title' => array(
439
- 'mode' => 'required',
440
- 'error' => __( 'You must provide a title', 'ultimate-member' )
441
- ),
442
- '_metakey' => array(
443
- 'mode' => 'unique',
444
- ),
445
- '_years' => array(
446
- 'mode' => 'numeric',
447
- 'error' => __( 'Number of years is not valid', 'ultimate-member' )
448
- ),
449
- '_range_start' => array(
450
- 'mode' => 'range-start',
451
- ),
452
- '_range_end' => array(
453
- 'mode' => 'range-end',
454
- ),
455
- )
456
- ),
457
-
458
- 'time' => array(
459
- 'name' => 'Time Picker',
460
- 'col1' => array('_title','_metakey','_help','_format','_visibility'),
461
- 'col2' => array('_label','_placeholder','_default','_public','_roles','_intervals'),
462
- 'col3' => array('_required','_editable','_icon'),
463
- 'validate' => array(
464
- '_title' => array(
465
- 'mode' => 'required',
466
- 'error' => __( 'You must provide a title', 'ultimate-member' )
467
- ),
468
- '_metakey' => array(
469
- 'mode' => 'unique',
470
- ),
471
- )
472
- ),
473
-
474
- 'rating' => array(
475
- 'name' => 'Rating',
476
- 'col1' => array('_title','_metakey','_help','_visibility'),
477
- 'col2' => array('_label','_public','_roles','_number','_default'),
478
- 'col3' => array('_required','_editable','_icon'),
479
- 'validate' => array(
480
- '_title' => array(
481
- 'mode' => 'required',
482
- 'error' => __('You must provide a title','ultimate-member')
483
- ),
484
- '_metakey' => array(
485
- 'mode' => 'unique',
486
- ),
487
- )
488
- ),
489
-
490
- 'block' => array(
491
- 'name' => 'Content Block',
492
- 'col1' => array('_title','_visibility'),
493
- 'col2' => array('_public','_roles'),
494
- 'col_full' => array('_content'),
495
- 'mce_content' => true,
496
- 'validate' => array(
497
- '_title' => array(
498
- 'mode' => 'required',
499
- 'error' => __('You must provide a title','ultimate-member')
500
- ),
501
- )
502
- ),
503
-
504
- 'shortcode' => array(
505
- 'name' => 'Shortcode',
506
- 'col1' => array('_title','_visibility'),
507
- 'col2' => array('_public','_roles'),
508
- 'col_full' => array('_content'),
509
- 'validate' => array(
510
- '_title' => array(
511
- 'mode' => 'required',
512
- 'error' => __('You must provide a title','ultimate-member')
513
- ),
514
- '_content' => array(
515
- 'mode' => 'required',
516
- 'error' => __('You must add a shortcode to the content area','ultimate-member')
517
- ),
518
- )
519
- ),
520
-
521
- 'spacing' => array(
522
- 'name' => 'Spacing',
523
- 'col1' => array('_title','_visibility'),
524
- 'col2' => array('_spacing'),
525
- 'form_only' => true,
526
- 'validate' => array(
527
- '_title' => array(
528
- 'mode' => 'required',
529
- 'error' => __('You must provide a title','ultimate-member')
530
- ),
531
- )
532
- ),
533
-
534
- 'divider' => array(
535
- 'name' => 'Divider',
536
- 'col1' => array('_title','_width','_divider_text','_visibility'),
537
- 'col2' => array('_style','_color','_public','_roles'),
538
- 'form_only' => true,
539
- 'validate' => array(
540
- '_title' => array(
541
- 'mode' => 'required',
542
- 'error' => __('You must provide a title','ultimate-member')
543
- ),
544
- )
545
- ),
546
-
547
- 'googlemap' => array(
548
- 'name' => 'Google Map',
549
- 'col1' => array('_title','_metakey','_help','_visibility'),
550
- 'col2' => array('_label','_placeholder','_public','_roles','_validate','_custom_validate'),
551
- 'col3' => array('_required','_editable','_icon'),
552
- 'validate' => array(
553
- '_title' => array(
554
- 'mode' => 'required',
555
- 'error' => __('You must provide a title','ultimate-member')
556
- ),
557
- '_metakey' => array(
558
- 'mode' => 'unique',
559
- ),
560
- )
561
- ),
562
-
563
- 'youtube_video' => array(
564
- 'name' => 'YouTube Video',
565
- 'col1' => array('_title','_metakey','_help','_visibility'),
566
- 'col2' => array('_label','_placeholder','_public','_roles','_validate','_custom_validate'),
567
- 'col3' => array('_required','_editable','_icon'),
568
- 'validate' => array(
569
- '_title' => array(
570
- 'mode' => 'required',
571
- 'error' => __('You must provide a title','ultimate-member')
572
- ),
573
- '_metakey' => array(
574
- 'mode' => 'unique',
575
- ),
576
- )
577
- ),
578
-
579
- 'vimeo_video' => array(
580
- 'name' => 'Vimeo Video',
581
- 'col1' => array('_title','_metakey','_help','_visibility'),
582
- 'col2' => array('_label','_placeholder','_public','_roles','_validate','_custom_validate'),
583
- 'col3' => array('_required','_editable','_icon'),
584
- 'validate' => array(
585
- '_title' => array(
586
- 'mode' => 'required',
587
- 'error' => __('You must provide a title','ultimate-member')
588
- ),
589
- '_metakey' => array(
590
- 'mode' => 'unique',
591
- ),
592
- )
593
- ),
594
-
595
- 'soundcloud_track' => array(
596
- 'name' => 'SoundCloud Track',
597
- 'col1' => array('_title','_metakey','_help','_visibility'),
598
- 'col2' => array('_label','_placeholder','_public','_roles','_validate','_custom_validate'),
599
- 'col3' => array('_required','_editable','_icon'),
600
- 'validate' => array(
601
- '_title' => array(
602
- 'mode' => 'required',
603
- 'error' => __('You must provide a title','ultimate-member')
604
- ),
605
- '_metakey' => array(
606
- 'mode' => 'unique',
607
- ),
608
- )
609
- ),
610
-
611
- /*'group' => array(
612
- 'name' => 'Field Group',
613
- 'col1' => array('_title','_max_entries'),
614
- 'col2' => array('_label','_public','_roles'),
615
- 'form_only' => true,
616
- 'validate' => array(
617
- '_title' => array(
618
- 'mode' => 'required',
619
- 'error' => 'You must provide a title'
620
- ),
621
- '_label' => array(
622
- 'mode' => 'required',
623
- 'error' => 'You must provide a label'
624
- ),
625
- )
626
- ),*/
627
-
628
- );
629
-
630
- /**
631
- * UM hook
632
- *
633
- * @type filter
634
- * @title um_core_fields_hook
635
- * @description UM Core Fields
636
- * @input_vars
637
- * [{"var":"$core_fields","type":"array","desc":"Core Fields"}]
638
- * @change_log
639
- * ["Since: 2.0"]
640
- * @usage add_filter( 'um_core_fields_hook', 'function_name', 10, 1 );
641
- * @example
642
- * <?php
643
- * add_filter( 'um_core_fields_hook', 'my_core_fields', 10, 1 );
644
- * function my_core_fields( $core_fields ) {
645
- * // your code here
646
- * return $core_fields;
647
- * }
648
- * ?>
649
- */
650
- $this->core_fields = apply_filters( 'um_core_fields_hook', $this->core_fields );
651
- }
652
-
653
-
654
- /**
655
- * Predefined Fields
656
- */
657
- function set_predefined_fields() {
658
- global $wp_roles;
659
-
660
- $um_roles = array();
661
- if ( ! empty( $wp_roles->roles ) ) {
662
- $role_keys = get_option( 'um_roles', array() );
663
- if ( ! empty( $role_keys ) && is_array( $role_keys ) ) {
664
- $role_keys = array_map( function( $item ) {
665
- return 'um_' . $item;
666
- }, $role_keys );
667
- } else {
668
- $role_keys = array();
669
- }
670
-
671
- $exclude_roles = array_diff( array_keys( $wp_roles->roles ), array_merge( $role_keys, array( 'subscriber' ) ) );
672
- $um_roles = UM()->roles()->get_roles( false, $exclude_roles );
673
- }
674
-
675
- /**
676
- * UM hook
677
- *
678
- * @type filter
679
- * @title um_profile_privacy_options
680
- * @description Profile Privacy Options
681
- * @input_vars
682
- * [{"var":"$privacy_options","type":"array","desc":"Privacy Options"}]
683
- * @change_log
684
- * ["Since: 2.0"]
685
- * @usage add_filter( 'um_profile_privacy_options', 'function_name', 10, 1 );
686
- * @example
687
- * <?php
688
- * add_filter( 'um_profile_privacy_options', 'my_profile_privacy_options', 10, 1 );
689
- * function my_profile_privacy_options( $privacy_options ) {
690
- * // your code here
691
- * return $privacy_options;
692
- * }
693
- * ?>
694
- */
695
- $profile_privacy = apply_filters( 'um_profile_privacy_options', array(
696
- 'Everyone' => __( 'Everyone', 'ultimate-member' ),
697
- 'Only me' => __( 'Only me', 'ultimate-member' )
698
- ) );
699
-
700
- /*
701
- * it's important create key for array equals value of 'metakey'.
702
- *
703
- */
704
-
705
- $this->predefined_fields = array(
706
-
707
- 'user_login' => array(
708
- 'title' => __('Username','ultimate-member'),
709
- 'metakey' => 'user_login',
710
- 'type' => 'text',
711
- 'label' => __('Username','ultimate-member'),
712
- 'required' => 1,
713
- 'public' => 1,
714
- 'editable' => 0,
715
- 'validate' => 'unique_username',
716
- 'min_chars' => 3,
717
- 'max_chars' => 24
718
- ),
719
-
720
- 'username' => array(
721
- 'title' => __('Username or E-mail','ultimate-member'),
722
- 'metakey' => 'username',
723
- 'type' => 'text',
724
- 'label' => __('Username or E-mail','ultimate-member'),
725
- 'required' => 1,
726
- 'public' => 1,
727
- 'editable' => 0,
728
- 'validate' => 'unique_username_or_email',
729
- ),
730
-
731
- 'user_password' => array(
732
- 'title' => __('Password','ultimate-member'),
733
- 'metakey' => 'user_password',
734
- 'type' => 'password',
735
- 'label' => __('Password','ultimate-member'),
736
- 'required' => 1,
737
- 'public' => 1,
738
- 'editable' => 1,
739
- 'min_chars' => 8,
740
- 'max_chars' => 30,
741
- 'force_good_pass' => 1,
742
- 'force_confirm_pass' => 1,
743
- 'label_confirm_pass' => __('Confirm Password','ultimate-member')
744
- ),
745
-
746
- 'first_name' => array(
747
- 'title' => __('First Name','ultimate-member'),
748
- 'metakey' => 'first_name',
749
- 'type' => 'text',
750
- 'label' => __('First Name','ultimate-member'),
751
- 'required' => 0,
752
- 'public' => 1,
753
- 'editable' => 1,
754
- ),
755
-
756
- 'last_name' => array(
757
- 'title' => __('Last Name','ultimate-member'),
758
- 'metakey' => 'last_name',
759
- 'type' => 'text',
760
- 'label' => __('Last Name','ultimate-member'),
761
- 'required' => 0,
762
- 'public' => 1,
763
- 'editable' => 1,
764
- ),
765
-
766
- 'nickname' => array(
767
- 'title' => __('Nickname','ultimate-member'),
768
- 'metakey' => 'nickname',
769
- 'type' => 'text',
770
- 'label' => __('Nickname','ultimate-member'),
771
- 'required' => 0,
772
- 'public' => 1,
773
- 'editable' => 1,
774
- ),
775
-
776
- 'user_url' => array(
777
- 'title' => __('Website URL','ultimate-member'),
778
- 'metakey' => 'user_url',
779
- 'type' => 'url',
780
- 'label' => __('Website URL','ultimate-member'),
781
- 'required' => 1,
782
- 'public' => 1,
783
- 'editable' => 1,
784
- 'validate' => 'url'
785
- ),
786
-
787
- 'user_registered' => array(
788
- 'title' => __('Registration Date','ultimate-member'),
789
- 'metakey' => 'user_registered',
790
- 'type' => 'text',
791
- 'label' => __('Registration Date','ultimate-member'),
792
- 'required' => 0,
793
- 'public' => 1,
794
- 'editable' => 1,
795
- 'edit_forbidden' => 1,
796
- ),
797
-
798
- '_um_last_login' => array(
799
- 'title' => __('Last Login','ultimate-member'),
800
- 'metakey' => '_um_last_login',
801
- 'type' => 'text',
802
- 'label' => __('Last Login','ultimate-member'),
803
- 'required' => 0,
804
- 'public' => 1,
805
- 'editable' => 1,
806
- 'edit_forbidden' => 1,
807
- ),
808
-
809
- 'user_email' => array(
810
- 'title' => __('E-mail Address','ultimate-member'),
811
- 'metakey' => 'user_email',
812
- 'type' => 'text',
813
- 'label' => __('E-mail Address','ultimate-member'),
814
- 'required' => 0,
815
- 'public' => 1,
816
- 'validate' => 'unique_email',
817
- 'autocomplete' => 'off'
818
- ),
819
-
820
- 'secondary_user_email' => array(
821
- 'title' => __('Secondary E-mail Address','ultimate-member'),
822
- 'metakey' => 'secondary_user_email',
823
- 'type' => 'text',
824
- 'label' => __('Secondary E-mail Address','ultimate-member'),
825
- 'required' => 0,
826
- 'public' => 1,
827
- 'editable' => 1,
828
- 'validate' => 'unique_email',
829
- 'autocomplete' => 'off'
830
- ),
831
-
832
- 'description' => array(
833
- 'title' => __('Biography','ultimate-member'),
834
- 'metakey' => 'description',
835
- 'type' => 'textarea',
836
- 'label' => __('Biography','ultimate-member'),
837
- 'html' => 0,
838
- 'required' => 0,
839
- 'public' => 1,
840
- 'editable' => 1,
841
- 'max_words' => 40,
842
- 'placeholder' => __('Enter a bit about yourself...','ultimate-member'),
843
- ),
844
-
845
- 'birth_date' => array(
846
- 'title' => __('Birth Date','ultimate-member'),
847
- 'metakey' => 'birth_date',
848
- 'type' => 'date',
849
- 'label' => __('Birth Date','ultimate-member'),
850
- 'required' => 0,
851
- 'public' => 1,
852
- 'editable' => 1,
853
- 'pretty_format' => 1,
854
- 'years' => 115,
855
- 'years_x' => 'past',
856
- 'icon' => 'um-faicon-calendar'
857
- ),
858
-
859
- 'gender' => array(
860
- 'title' => __('Gender','ultimate-member'),
861
- 'metakey' => 'gender',
862
- 'type' => 'radio',
863
- 'label' => __('Gender','ultimate-member'),
864
- 'required' => 0,
865
- 'public' => 1,
866
- 'editable' => 1,
867
- 'options' => array( __('Male','ultimate-member'), __('Female','ultimate-member') )
868
- ),
869
-
870
- 'country' => array(
871
- 'title' => __('Country','ultimate-member'),
872
- 'metakey' => 'country',
873
- 'type' => 'select',
874
- 'label' => __('Country','ultimate-member'),
875
- 'placeholder' => __('Choose a Country','ultimate-member'),
876
- 'required' => 0,
877
- 'public' => 1,
878
- 'editable' => 1,
879
- 'options' => $this->get('countries')
880
- ),
881
-
882
- 'facebook' => array(
883
- 'title' => __('Facebook','ultimate-member'),
884
- 'metakey' => 'facebook',
885
- 'type' => 'url',
886
- 'label' => __('Facebook','ultimate-member'),
887
- 'required' => 0,
888
- 'public' => 1,
889
- 'editable' => 1,
890
- 'url_target' => '_blank',
891
- 'url_rel' => 'nofollow',
892
- 'icon' => 'um-faicon-facebook',
893
- 'validate' => 'facebook_url',
894
- 'url_text' => 'Facebook',
895
- 'advanced' => 'social',
896
- 'color' => '#3B5999',
897
- 'match' => 'https://facebook.com/',
898
- ),
899
-
900
- 'twitter' => array(
901
- 'title' => __('Twitter','ultimate-member'),
902
- 'metakey' => 'twitter',
903
- 'type' => 'url',
904
- 'label' => __('Twitter','ultimate-member'),
905
- 'required' => 0,
906
- 'public' => 1,
907
- 'editable' => 1,
908
- 'url_target' => '_blank',
909
- 'url_rel' => 'nofollow',
910
- 'icon' => 'um-faicon-twitter',
911
- 'validate' => 'twitter_url',
912
- 'url_text' => 'Twitter',
913
- 'advanced' => 'social',
914
- 'color' => '#4099FF',
915
- 'match' => 'https://twitter.com/',
916
- ),
917
-
918
- 'linkedin' => array(
919
- 'title' => __('LinkedIn','ultimate-member'),
920
- 'metakey' => 'linkedin',
921
- 'type' => 'url',
922
- 'label' => __('LinkedIn','ultimate-member'),
923
- 'required' => 0,
924
- 'public' => 1,
925
- 'editable' => 1,
926
- 'url_target' => '_blank',
927
- 'url_rel' => 'nofollow',
928
- 'icon' => 'um-faicon-linkedin',
929
- 'validate' => 'linkedin_url',
930
- 'url_text' => 'LinkedIn',
931
- 'advanced' => 'social',
932
- 'color' => '#0976b4',
933
- 'match' => 'https://linkedin.com/',
934
- ),
935
-
936
- 'googleplus' => array(
937
- 'title' => __('Google+','ultimate-member'),
938
- 'metakey' => 'googleplus',
939
- 'type' => 'url',
940
- 'label' => __('Google+','ultimate-member'),
941
- 'required' => 0,
942
- 'public' => 1,
943
- 'editable' => 1,
944
- 'url_target' => '_blank',
945
- 'url_rel' => 'nofollow',
946
- 'icon' => 'um-faicon-google-plus',
947
- 'validate' => 'google_url',
948
- 'url_text' => 'Google+',
949
- 'advanced' => 'social',
950
- 'color' => '#dd4b39',
951
- 'match' => 'https://google.com/+',
952
- ),
953
-
954
- 'instagram' => array(
955
- 'title' => __('Instagram','ultimate-member'),
956
- 'metakey' => 'instagram',
957
- 'type' => 'url',
958
- 'label' => __('Instagram','ultimate-member'),
959
- 'required' => 0,
960
- 'public' => 1,
961
- 'editable' => 1,
962
- 'url_target' => '_blank',
963
- 'url_rel' => 'nofollow',
964
- 'icon' => 'um-faicon-instagram',
965
- 'validate' => 'instagram_url',
966
- 'url_text' => 'Instagram',
967
- 'advanced' => 'social',
968
- 'color' => 'radial-gradient(circle at 30% 107%, #fdf497 0%, #fdf497 5%, #fd5949 45%,#d6249f 60%,#285AEB 90%)',
969
- 'match' => 'https://instagram.com/',
970
- ),
971
-
972
- 'skype' => array(
973
- 'title' => __('Skype ID','ultimate-member'),
974
- 'metakey' => 'skype',
975
- 'type' => 'text',
976
- 'label' => __('Skype ID','ultimate-member'),
977
- 'required' => 0,
978
- 'public' => 1,
979
- 'editable' => 1,
980
- 'url_target' => '_blank',
981
- 'url_rel' => 'nofollow',
982
- 'icon' => 'um-faicon-skype',
983
- 'validate' => 'skype',
984
- 'url_text' => __( 'Join chat', 'ultimate-member' ),
985
- ),
986
-
987
- 'viber' => array(
988
- 'title' => __('Viber number','ultimate-member'),
989
- 'metakey' => 'viber',
990
- 'type' => 'text',
991
- 'label' => __('Viber number','ultimate-member'),
992
- 'required' => 0,
993
- 'public' => 1,
994
- 'editable' => 1,
995
- 'url_target' => '_blank',
996
- 'url_rel' => 'nofollow',
997
- 'icon' => 'um-icon-ios-telephone',
998
- 'validate' => 'phone_number',
999
- ),
1000
-
1001
- 'whatsapp' => array(
1002
- 'title' => __('WhatsApp number','ultimate-member'),
1003
- 'metakey' => 'whatsapp',
1004
- 'type' => 'text',
1005
- 'label' => __('WhatsApp number','ultimate-member'),
1006
- 'required' => 0,
1007
- 'public' => 1,
1008
- 'editable' => 1,
1009
- 'url_target' => '_blank',
1010
- 'url_rel' => 'nofollow',
1011
- 'icon' => 'um-icon-social-whatsapp',
1012
- 'validate' => 'phone_number',
1013
- ),
1014
-
1015
- 'telegram' => array(
1016
- 'title' => __('Telegram','ultimate-member'),
1017
- 'metakey' => 'telegram',
1018
- 'type' => 'url',
1019
- 'label' => __('Telegram','ultimate-member'),
1020
- 'required' => 0,
1021
- 'public' => 1,
1022
- 'editable' => 1,
1023
- 'url_target' => '_blank',
1024
- 'url_rel' => 'nofollow',
1025
- 'icon' => 'um-faicon-paper-plane',
1026
- 'validate' => 'telegram_url',
1027
- 'url_text' => 'Telegram',
1028
- 'match' => 'https://t.me/',
1029
- ),
1030
-
1031
- 'discord' => array(
1032
- 'title' => __('Discord','ultimate-member'),
1033
- 'metakey' => 'discord',
1034
- 'type' => 'text',
1035
- 'label' => __('Discord ID','ultimate-member'),
1036
- 'required' => 0,
1037
- 'public' => 1,
1038
- 'editable' => 1,
1039
- 'url_target' => '_blank',
1040
- 'url_rel' => 'nofollow',
1041
- 'validate' => 'discord',
1042
- ),
1043
-
1044
- 'youtube' => array(
1045
- 'title' => __('YouTube','ultimate-member'),
1046
- 'metakey' => 'youtube',
1047
- 'type' => 'url',
1048
- 'label' => __('YouTube','ultimate-member'),
1049
- 'required' => 0,
1050
- 'public' => 1,
1051
- 'editable' => 1,
1052
- 'url_target' => '_blank',
1053
- 'url_rel' => 'nofollow',
1054
- 'icon' => 'um-faicon-youtube',
1055
- 'validate' => 'youtube_url',
1056
- 'url_text' => 'YouTube',
1057
- 'advanced' => 'social',
1058
- 'color' => '#e52d27',
1059
- 'match' => 'https://youtube.com/',
1060
- ),
1061
-
1062
- 'soundcloud' => array(
1063
- 'title' => __( 'SoundCloud', 'ultimate-member' ),
1064
- 'metakey' => 'soundcloud',
1065
- 'type' => 'url',
1066
- 'label' => __( 'SoundCloud', 'ultimate-member' ),
1067
- 'required' => 0,
1068
- 'public' => 1,
1069
- 'editable' => 1,
1070
- 'url_target' => '_blank',
1071
- 'url_rel' => 'nofollow',
1072
- 'icon' => 'um-faicon-soundcloud',
1073
- 'validate' => 'soundcloud_url',
1074
- 'url_text' => 'SoundCloud',
1075
- 'advanced' => 'social',
1076
- 'color' => '#f50',
1077
- 'match' => 'https://soundcloud.com/',
1078
- ),
1079
-
1080
- 'vkontakte' => array(
1081
- 'title' => __('VKontakte','ultimate-member'),
1082
- 'metakey' => 'vkontakte',
1083
- 'type' => 'url',
1084
- 'label' => __('VKontakte','ultimate-member'),
1085
- 'required' => 0,
1086
- 'public' => 1,
1087
- 'editable' => 1,
1088
- 'url_target' => '_blank',
1089
- 'url_rel' => 'nofollow',
1090
- 'icon' => 'um-faicon-vk',
1091
- 'validate' => 'vk_url',
1092
- 'url_text' => 'VKontakte',
1093
- 'advanced' => 'social',
1094
- 'color' => '#2B587A',
1095
- 'match' => 'https://vk.com/',
1096
- ),
1097
-
1098
- 'role_select' => array(
1099
- 'title' => __('Roles (Dropdown)','ultimate-member'),
1100
- 'metakey' => 'role_select',
1101
- 'type' => 'select',
1102
- 'label' => __('Account Type','ultimate-member'),
1103
- 'placeholder' => 'Choose account type',
1104
- 'required' => 0,
1105
- 'public' => 1,
1106
- 'editable' => 1,
1107
- 'options' => $um_roles,
1108
- ),
1109
-
1110
- 'role_radio' => array(
1111
- 'title' => __('Roles (Radio)','ultimate-member'),
1112
- 'metakey' => 'role_radio',
1113
- 'type' => 'radio',
1114
- 'label' => __('Account Type','ultimate-member'),
1115
- 'required' => 0,
1116
- 'public' => 1,
1117
- 'editable' => 1,
1118
- 'options' => $um_roles,
1119
- ),
1120
-
1121
- 'languages' => array(
1122
- 'title' => __('Languages','ultimate-member'),
1123
- 'metakey' => 'languages',
1124
- 'type' => 'multiselect',
1125
- 'label' => __('Languages Spoken','ultimate-member'),
1126
- 'placeholder' => __('Select languages','ultimate-member'),
1127
- 'required' => 0,
1128
- 'public' => 1,
1129
- 'editable' => 1,
1130
- 'options' => $this->get('languages'),
1131
- ),
1132
-
1133
- 'phone_number' => array(
1134
- 'title' => __('Phone Number','ultimate-member'),
1135
- 'metakey' => 'phone_number',
1136
- 'type' => 'text',
1137
- 'label' => __('Phone Number','ultimate-member'),
1138
- 'required' => 0,
1139
- 'public' => 1,
1140
- 'editable' => 1,
1141
- 'validate' => 'phone_number',
1142
- 'icon' => 'um-faicon-phone',
1143
- ),
1144
-
1145
- 'mobile_number' => array(
1146
- 'title' => __('Mobile Number','ultimate-member'),
1147
- 'metakey' => 'mobile_number',
1148
- 'type' => 'text',
1149
- 'label' => __('Mobile Number','ultimate-member'),
1150
- 'required' => 0,
1151
- 'public' => 1,
1152
- 'editable' => 1,
1153
- 'validate' => 'phone_number',
1154
- 'icon' => 'um-faicon-mobile',
1155
- ),
1156
-
1157
- // private use ( not public list )
1158
-
1159
- 'profile_photo' => array(
1160
- 'title' => __('Profile Photo','ultimate-member'),
1161
- 'metakey' => 'profile_photo',
1162
- 'type' => 'image',
1163
- 'label' => __('Change your profile photo','ultimate-member'),
1164
- 'upload_text' => __('Upload your photo here','ultimate-member'),
1165
- 'icon' => 'um-faicon-camera',
1166
- 'crop' => 1,
1167
- 'max_size' => ( UM()->options()->get('profile_photo_max_size') ) ? UM()->options()->get('profile_photo_max_size') : 999999999,
1168
- 'min_width' => str_replace('px','',UM()->options()->get('profile_photosize')),
1169
- 'min_height' => str_replace('px','',UM()->options()->get('profile_photosize')),
1170
- 'private_use' => true,
1171
- ),
1172
-
1173
- 'cover_photo' => array(
1174
- 'title' => __('Cover Photo','ultimate-member'),
1175
- 'metakey' => 'cover_photo',
1176
- 'type' => 'image',
1177
- 'label' => __('Change your cover photo','ultimate-member'),
1178
- 'upload_text' => __('Upload profile cover here','ultimate-member'),
1179
- 'icon' => 'um-faicon-picture-o',
1180
- 'crop' => 2,
1181
- 'max_size' => ( UM()->options()->get('cover_photo_max_size') ) ? UM()->options()->get('cover_photo_max_size') : 999999999,
1182
- 'modal_size' => 'large',
1183
- 'ratio' => str_replace(':1','',UM()->options()->get('profile_cover_ratio')),
1184
- 'min_width' => UM()->options()->get('cover_min_width'),
1185
- 'private_use' => true,
1186
- ),
1187
-
1188
- 'username_b' => array(
1189
- 'title' => __('Username or E-mail','ultimate-member'),
1190
- 'metakey' => 'username_b',
1191
- 'type' => 'text',
1192
- 'placeholder' => __('Enter your username or email','ultimate-member'),
1193
- 'required' => 1,
1194
- 'public' => 1,
1195
- 'editable' => 0,
1196
- 'private_use' => true,
1197
- ),
1198
-
1199
- // account page use ( not public )
1200
-
1201
- 'profile_privacy' => array(
1202
- 'title' => __( 'Profile Privacy', 'ultimate-member' ),
1203
- 'metakey' => 'profile_privacy',
1204
- 'type' => 'select',
1205
- 'label' => __( 'Profile Privacy', 'ultimate-member' ),
1206
- 'help' => __( 'Who can see your public profile?', 'ultimate-member' ),
1207
- 'required' => 0,
1208
- 'public' => 1,
1209
- 'editable' => 1,
1210
- 'default' => 'Everyone',
1211
- 'options' => $profile_privacy,
1212
- 'allowclear' => 0,
1213
- 'account_only' => true,
1214
- 'required_perm' => 'can_make_private_profile',
1215
- ),
1216
-
1217
- 'profile_noindex' => array(
1218
- 'title' => __( 'Avoid indexing my profile by search engines', 'ultimate-member' ),
1219
- 'metakey' => 'profile_noindex',
1220
- 'type' => 'select',
1221
- 'label' => __( 'Avoid indexing my profile by search engines', 'ultimate-member' ),
1222
- 'help' => __( 'Hide my profile for robots?', 'ultimate-member' ),
1223
- 'required' => 0,
1224
- 'public' => 1,
1225
- 'editable' => 1,
1226
- 'default' => UM()->roles()->um_user_can( 'profile_noindex' ) ? '1' : '0',
1227
- 'options' => array(
1228
- '0' => __( 'No', 'ultimate-member' ),
1229
- '1' => __( 'Yes', 'ultimate-member' ),
1230
- ),
1231
- 'allowclear' => 0,
1232
- 'account_only' => true,
1233
- 'required_perm' => 'can_make_private_profile',
1234
- ),
1235
-
1236
- 'hide_in_members' => array(
1237
- 'title' => __( 'Hide my profile from directory', 'ultimate-member' ),
1238
- 'metakey' => 'hide_in_members',
1239
- 'type' => 'radio',
1240
- 'label' => __( 'Hide my profile from directory', 'ultimate-member' ),
1241
- 'help' => __( 'Here you can hide yourself from appearing in public directory', 'ultimate-member' ),
1242
- 'required' => 0,
1243
- 'public' => 1,
1244
- 'editable' => 1,
1245
- 'default' => UM()->member_directory()->get_hide_in_members_default() ? 'Yes' : 'No',
1246
- 'options' => array(
1247
- 'No' => __( 'No', 'ultimate-member' ),
1248
- 'Yes' => __( 'Yes', 'ultimate-member' ),
1249
- ),
1250
- 'account_only' => true,
1251
- 'required_opt' => array( 'members_page', 1 ),
1252
- ),
1253
-
1254
- 'delete_account' => array(
1255
- 'title' => __( 'Delete Account', 'ultimate-member' ),
1256
- 'metakey' => 'delete_account',
1257
- 'type' => 'radio',
1258
- 'label' => __( 'Delete Account', 'ultimate-member'),
1259
- 'help' => __( 'If you confirm, everything related to your profile will be deleted permanently from the site', 'ultimate-member' ),
1260
- 'required' => 0,
1261
- 'public' => 1,
1262
- 'editable' => 1,
1263
- 'default' => __( 'No', 'ultimate-member' ),
1264
- 'options' => array(
1265
- __( 'Yes', 'ultimate-member' ),
1266
- __( 'No', 'ultimate-member' )
1267
- ),
1268
- 'account_only' => true,
1269
- ),
1270
-
1271
- 'single_user_password' => array(
1272
- 'title' => __( 'Password', 'ultimate-member' ),
1273
- 'metakey' => 'single_user_password',
1274
- 'type' => 'password',
1275
- 'label' => __( 'Password', 'ultimate-member' ),
1276
- 'required' => 1,
1277
- 'public' => 1,
1278
- 'editable' => 1,
1279
- 'account_only' => true,
1280
- ),
1281
-
1282
- );
1283
-
1284
- /**
1285
- * UM hook
1286
- *
1287
- * @type filter
1288
- * @title um_predefined_fields_hook
1289
- * @description Extend Predefined Fields
1290
- * @input_vars
1291
- * [{"var":"$predefined_fields","type":"array","desc":"Predefined Fields"}]
1292
- * @change_log
1293
- * ["Since: 2.0"]
1294
- * @usage add_filter( 'um_predefined_fields_hook', 'function_name', 10, 1 );
1295
- * @example
1296
- * <?php
1297
- * add_filter( 'um_predefined_fields_hook', 'my_predefined_fields', 10, 1 );
1298
- * function my_predefined_fields( $predefined_fields ) {
1299
- * // your code here
1300
- * return $predefined_fields;
1301
- * }
1302
- * ?>
1303
- */
1304
- $this->predefined_fields = apply_filters( 'um_predefined_fields_hook', $this->predefined_fields );
1305
- }
1306
-
1307
-
1308
- /**
1309
- * Custom Fields
1310
- */
1311
- function set_custom_fields() {
1312
-
1313
- if ( is_array( $this->saved_fields ) ) {
1314
-
1315
- $this->custom_fields = $this->saved_fields;
1316
-
1317
- } else {
1318
-
1319
- $this->custom_fields = '';
1320
-
1321
- }
1322
-
1323
- $custom = $this->custom_fields;
1324
- $predefined = $this->predefined_fields;
1325
-
1326
- if ( is_array( $custom ) ){
1327
- $this->all_user_fields = array_merge( $predefined, $custom );
1328
- } else {
1329
- $this->all_user_fields = $predefined;
1330
- }
1331
-
1332
- }
1333
-
1334
-
1335
- /**
1336
- * Get all fields without metakeys
1337
- *
1338
- * @since 2.0.56
1339
- *
1340
- * @return array
1341
- */
1342
- function get_fields_without_metakey() {
1343
- $fields_without_metakey = array(
1344
- 'block',
1345
- 'shortcode',
1346
- 'spacing',
1347
- 'divider',
1348
- 'group'
1349
- );
1350
-
1351
-
1352
- /**
1353
- * UM hook
1354
- *
1355
- * @type filter
1356
- * @title um_fields_without_metakey
1357
- * @description Field Types without meta key
1358
- * @input_vars
1359
- * [{"var":"$types","type":"array","desc":"Field Types"}]
1360
- * @change_log
1361
- * ["Since: 2.0"]
1362
- * @usage add_filter( 'um_fields_without_metakey', 'function_name', 10, 1 );
1363
- * @example
1364
- * <?php
1365
- * add_filter( 'um_fields_without_metakey', 'my_fields_without_metakey', 10, 1 );
1366
- * function my_fields_without_metakey( $types ) {
1367
- * // your code here
1368
- * return $types;
1369
- * }
1370
- * ?>
1371
- */
1372
- return apply_filters( 'um_fields_without_metakey', $fields_without_metakey );
1373
- }
1374
-
1375
-
1376
- /**
1377
- * May be used to show a dropdown, or source for user meta
1378
- *
1379
- * @param null $exclude_types
1380
- * @param bool $show_all
1381
- *
1382
- * @return array
1383
- */
1384
- function all_user_fields( $exclude_types = null, $show_all = false ) {
1385
-
1386
- $fields_without_metakey = $this->get_fields_without_metakey();
1387
- $fields_without_metakey = apply_filters( 'um_all_user_fields_without_metakey', $fields_without_metakey );
1388
-
1389
- if ( ! $show_all ) {
1390
- $this->fields_dropdown = array( 'image', 'file', 'password', 'rating' );
1391
- $this->fields_dropdown = array_merge( $this->fields_dropdown, $fields_without_metakey );
1392
- } else {
1393
- $this->fields_dropdown = $fields_without_metakey;
1394
- }
1395
-
1396
- $custom = $this->custom_fields;
1397
- $predefined = $this->predefined_fields;
1398
-
1399
- if ( $exclude_types ) {
1400
- $exclude_types = explode( ',', $exclude_types );
1401
- }
1402
-
1403
- $all = array( 0 => '' );
1404
-
1405
- if ( is_array( $custom ) ) {
1406
- $all = $all + array_merge( $predefined, $custom );
1407
- } else {
1408
- $all = $all + $predefined;
1409
- }
1410
-
1411
- foreach ( $all as $k => $arr ) {
1412
-
1413
- if ( $k == 0 ) {
1414
- unset( $all[ $k ] );
1415
- }
1416
-
1417
- if ( isset( $arr['title'] ) ) {
1418
- $all[ $k ]['title'] = stripslashes( $arr['title'] );
1419
- }
1420
-
1421
- if ( $exclude_types && isset( $arr['type'] ) && in_array( $arr['type'], $exclude_types ) ) {
1422
- unset( $all[ $k ] );
1423
- }
1424
- if ( isset( $arr['account_only'] ) || isset( $arr['private_use'] ) ) {
1425
- if ( ! $show_all ) {
1426
- unset( $all[ $k ] );
1427
- }
1428
- }
1429
- if ( isset( $arr['type'] ) && in_array( $arr['type'], $this->fields_dropdown ) ) {
1430
- unset( $all[ $k ] );
1431
- }
1432
- }
1433
-
1434
- $all = UM()->fields()->array_sort_by_column( $all, 'title' );
1435
-
1436
- return $all;
1437
- }
1438
-
1439
-
1440
- /**
1441
- * Possible validation types for fields
1442
- *
1443
- * @return mixed
1444
- */
1445
- function validation_types() {
1446
-
1447
- $array[0] = __('None','ultimate-member');
1448
- $array['alphabetic'] = __('Alphabetic value only','ultimate-member');
1449
- $array['alpha_numeric'] = __('Alpha-numeric value','ultimate-member');
1450
- $array['english'] = __('English letters only','ultimate-member');
1451
- $array['facebook_url'] = __('Facebook URL','ultimate-member');
1452
- $array['google_url'] = __('Google+ URL','ultimate-member');
1453
- $array['instagram_url'] = __('Instagram URL','ultimate-member');
1454
- $array['linkedin_url'] = __('LinkedIn URL','ultimate-member');
1455
- $array['vk_url'] = __('VKontakte URL','ultimate-member');
1456
- $array['lowercase'] = __('Lowercase only','ultimate-member');
1457
- $array['numeric'] = __('Numeric value only','ultimate-member');
1458
- $array['phone_number'] = __('Phone Number','ultimate-member');
1459
- $array['skype'] = __('Skype ID','ultimate-member');
1460
- $array['soundcloud'] = __( 'SoundCloud Profile', 'ultimate-member' );
1461
- $array['twitter_url'] = __('Twitter URL','ultimate-member');
1462
- $array['is_email'] = __('E-mail( Not Unique )','ultimate-member');
1463
- $array['unique_email'] = __('Unique E-mail','ultimate-member');
1464
- $array['unique_value'] = __('Unique Metakey value','ultimate-member');
1465
- $array['unique_username'] = __('Unique Username','ultimate-member');
1466
- $array['unique_username_or_email'] = __('Unique Username/E-mail','ultimate-member');
1467
- $array['url'] = __('Website URL','ultimate-member');
1468
- $array['youtube_url'] = __('YouTube Profile','ultimate-member');
1469
- $array['telegram_url'] = __('Telegram URL','ultimate-member');
1470
- $array['discord'] = __('Discord ID','ultimate-member');
1471
- $array['custom'] = __('Custom Validation','ultimate-member');
1472
-
1473
- /**
1474
- * UM hook
1475
- *
1476
- * @type filter
1477
- * @title um_admin_field_validation_hook
1478
- * @description Extend validation types
1479
- * @input_vars
1480
- * [{"var":"$types","type":"array","desc":"Validation Types"}]
1481
- * @change_log
1482
- * ["Since: 2.0"]
1483
- * @usage add_filter( 'um_admin_field_validation_hook', 'function_name', 10, 1 );
1484
- * @example
1485
- * <?php
1486
- * add_filter( 'um_admin_field_validation_hook', 'my_admin_field_validation', 10, 1 );
1487
- * function my_admin_field_validation( $types ) {
1488
- * // your code here
1489
- * return $types;
1490
- * }
1491
- * ?>
1492
- */
1493
- $array = apply_filters( 'um_admin_field_validation_hook', $array );
1494
- return $array;
1495
- }
1496
-
1497
-
1498
- /**
1499
- * Get predefined options
1500
- *
1501
- * @param $data
1502
- *
1503
- * @return array|mixed|void
1504
- */
1505
- function get( $data ) {
1506
- switch ( $data ) {
1507
-
1508
- case 'languages':
1509
- $array = array(
1510
- "aa" => __("Afar",'ultimate-member'),
1511
- "ab" => __("Abkhazian",'ultimate-member'),
1512
- "ae" => __("Avestan",'ultimate-member'),
1513
- "af" => __("Afrikaans",'ultimate-member'),
1514
- "ak" => __("Akan",'ultimate-member'),
1515
- "am" => __("Amharic",'ultimate-member'),
1516
- "an" => __("Aragonese",'ultimate-member'),
1517
- "ar" => __("Arabic",'ultimate-member'),
1518
- "as" => __("Assamese",'ultimate-member'),
1519
- "av" => __("Avaric",'ultimate-member'),
1520
- "ay" => __("Aymara",'ultimate-member'),
1521
- "az" => __("Azerbaijani",'ultimate-member'),
1522
- "ba" => __("Bashkir",'ultimate-member'),
1523
- "be" => __("Belarusian",'ultimate-member'),
1524
- "bg" => __("Bulgarian",'ultimate-member'),
1525
- "bh" => __("Bihari",'ultimate-member'),
1526
- "bi" => __("Bislama",'ultimate-member'),
1527
- "bm" => __("Bambara",'ultimate-member'),
1528
- "bn" => __("Bengali",'ultimate-member'),
1529
- "bo" => __("Tibetan",'ultimate-member'),
1530
- "br" => __("Breton",'ultimate-member'),
1531
- "bs" => __("Bosnian",'ultimate-member'),
1532
- "ca" => __("Catalan",'ultimate-member'),
1533
- "ce" => __("Chechen",'ultimate-member'),
1534
- "ch" => __("Chamorro",'ultimate-member'),
1535
- "co" => __("Corsican",'ultimate-member'),
1536
- "cr" => __("Cree",'ultimate-member'),
1537
- "cs" => __("Czech",'ultimate-member'),
1538
- "cu" => __("Church Slavic",'ultimate-member'),
1539
- "cv" => __("Chuvash",'ultimate-member'),
1540
- "cy" => __("Welsh",'ultimate-member'),
1541
- "da" => __("Danish",'ultimate-member'),
1542
- "de" => __("German",'ultimate-member'),
1543
- "dv" => __("Divehi",'ultimate-member'),
1544
- "dz" => __("Dzongkha",'ultimate-member'),
1545
- "ee" => __("Ewe",'ultimate-member'),
1546
- "el" => __("Greek",'ultimate-member'),
1547
- "en" => __("English",'ultimate-member'),
1548
- "eo" => __("Esperanto",'ultimate-member'),
1549
- "es" => __("Spanish",'ultimate-member'),
1550
- "et" => __("Estonian",'ultimate-member'),
1551
- "eu" => __("Basque",'ultimate-member'),
1552
- "fa" => __("Persian",'ultimate-member'),
1553
- "ff" => __("Fulah",'ultimate-member'),
1554
- "fi" => __("Finnish",'ultimate-member'),
1555
- "fj" => __("Fijian",'ultimate-member'),
1556
- "fo" => __("Faroese",'ultimate-member'),
1557
- "fr" => __("French",'ultimate-member'),
1558
- "fy" => __("Western Frisian",'ultimate-member'),
1559
- "ga" => __("Irish",'ultimate-member'),
1560
- "gd" => __("Scottish Gaelic",'ultimate-member'),
1561
- "gl" => __("Galician",'ultimate-member'),
1562
- "gn" => __("Guarani",'ultimate-member'),
1563
- "gu" => __("Gujarati",'ultimate-member'),
1564
- "gv" => __("Manx",'ultimate-member'),
1565
- "ha" => __("Hausa",'ultimate-member'),
1566
- "he" => __("Hebrew",'ultimate-member'),
1567
- "hi" => __("Hindi",'ultimate-member'),
1568
- "ho" => __("Hiri Motu",'ultimate-member'),
1569
- "hr" => __("Croatian",'ultimate-member'),
1570
- "ht" => __("Haitian",'ultimate-member'),
1571
- "hu" => __("Hungarian",'ultimate-member'),
1572
- "hy" => __("Armenian",'ultimate-member'),
1573
- "hz" => __("Herero",'ultimate-member'),
1574
- "ia" => __("Interlingua (International Auxiliary Language Association)",'ultimate-member'),
1575
- "id" => __("Indonesian",'ultimate-member'),
1576
- "ie" => __("Interlingue",'ultimate-member'),
1577
- "ig" => __("Igbo",'ultimate-member'),
1578
- "ii" => __("Sichuan Yi",'ultimate-member'),
1579
- "ik" => __("Inupiaq",'ultimate-member'),
1580
- "io" => __("Ido",'ultimate-member'),
1581
- "is" => __("Icelandic",'ultimate-member'),
1582
- "it" => __("Italian",'ultimate-member'),
1583
- "iu" => __("Inuktitut",'ultimate-member'),
1584
- "ja" => __("Japanese",'ultimate-member'),
1585
- "jv" => __("Javanese",'ultimate-member'),
1586
- "ka" => __("Kartuli",'ultimate-member'),
1587
- "kg" => __("Kongo",'ultimate-member'),
1588
- "ki" => __("Kikuyu",'ultimate-member'),
1589
- "kj" => __("Kwanyama",'ultimate-member'),
1590
- "kk" => __("Kazakh",'ultimate-member'),
1591
- "kl" => __("Kalaallisut",'ultimate-member'),
1592
- "km" => __("Khmer",'ultimate-member'),
1593
- "kn" => __("Kannada",'ultimate-member'),
1594
- "ko" => __("Korean",'ultimate-member'),
1595
- "kr" => __("Kanuri",'ultimate-member'),
1596
- "ks" => __("Kashmiri",'ultimate-member'),
1597
- "ku" => __("Kurdish",'ultimate-member'),
1598
- "kv" => __("Komi",'ultimate-member'),
1599
- "kw" => __("Cornish",'ultimate-member'),
1600
- "ky" => __("Kirghiz",'ultimate-member'),
1601
- "la" => __("Latin",'ultimate-member'),
1602
- "lb" => __("Luxembourgish",'ultimate-member'),
1603
- "lg" => __("Ganda",'ultimate-member'),
1604
- "li" => __("Limburgish",'ultimate-member'),
1605
- "ln" => __("Lingala",'ultimate-member'),
1606
- "lo" => __("Lao",'ultimate-member'),
1607
- "lt" => __("Lithuanian",'ultimate-member'),
1608
- "lu" => __("Luba-Katanga",'ultimate-member'),
1609
- "lv" => __("Latvian",'ultimate-member'),
1610
- "mg" => __("Malagasy",'ultimate-member'),
1611
- "mh" => __("Marshallese",'ultimate-member'),
1612
- "mi" => __("Maori",'ultimate-member'),
1613
- "mk" => __("Macedonian",'ultimate-member'),
1614
- "ml" => __("Malayalam",'ultimate-member'),
1615
- "mn" => __("Mongolian",'ultimate-member'),
1616
- "mr" => __("Marathi",'ultimate-member'),
1617
- "ms" => __("Malay",'ultimate-member'),
1618
- "mt" => __("Maltese",'ultimate-member'),
1619
- "my" => __("Burmese",'ultimate-member'),
1620
- "na" => __("Nauru",'ultimate-member'),
1621
- "nb" => __("Norwegian Bokmal",'ultimate-member'),
1622
- "nd" => __("North Ndebele",'ultimate-member'),
1623
- "ne" => __("Nepali",'ultimate-member'),
1624
- "ng" => __("Ndonga",'ultimate-member'),
1625
- "nl" => __("Dutch",'ultimate-member'),
1626
- "nn" => __("Norwegian Nynorsk",'ultimate-member'),
1627
- "no" => __("Norwegian",'ultimate-member'),
1628
- "nr" => __("South Ndebele",'ultimate-member'),
1629
- "nv" => __("Navajo",'ultimate-member'),
1630
- "ny" => __("Chichewa",'ultimate-member'),
1631
- "oc" => __("Occitan",'ultimate-member'),
1632
- "oj" => __("Ojibwa",'ultimate-member'),
1633
- "om" => __("Oromo",'ultimate-member'),
1634
- "or" => __("Oriya",'ultimate-member'),
1635
- "os" => __("Ossetian",'ultimate-member'),
1636
- "pa" => __("Panjabi",'ultimate-member'),
1637
- "pi" => __("Pali",'ultimate-member'),
1638
- "pl" => __("Polish",'ultimate-member'),
1639
- "ps" => __("Pashto",'ultimate-member'),
1640
- "pt" => __("Portuguese",'ultimate-member'),
1641
- "qu" => __("Quechua",'ultimate-member'),
1642
- "rm" => __("Raeto-Romance",'ultimate-member'),
1643
- "rn" => __("Kirundi",'ultimate-member'),
1644
- "ro" => __("Romanian",'ultimate-member'),
1645
- "ru" => __("Russian",'ultimate-member'),
1646
- "rw" => __("Kinyarwanda",'ultimate-member'),
1647
- "sa" => __("Sanskrit",'ultimate-member'),
1648
- "sc" => __("Sardinian",'ultimate-member'),
1649
- "sd" => __("Sindhi",'ultimate-member'),
1650
- "se" => __("Northern Sami",'ultimate-member'),
1651
- "sg" => __("Sango",'ultimate-member'),
1652
- "si" => __("Sinhala",'ultimate-member'),
1653
- "sk" => __("Slovak",'ultimate-member'),
1654
- "sl" => __("Slovenian",'ultimate-member'),
1655
- "sm" => __("Samoan",'ultimate-member'),
1656
- "sn" => __("Shona",'ultimate-member'),
1657
- "so" => __("Somali",'ultimate-member'),
1658
- "sq" => __("Albanian",'ultimate-member'),
1659
- "sr" => __("Serbian",'ultimate-member'),
1660
- "ss" => __("Swati",'ultimate-member'),
1661
- "st" => __("Southern Sotho",'ultimate-member'),
1662
- "su" => __("Sundanese",'ultimate-member'),
1663
- "sv" => __("Swedish",'ultimate-member'),
1664
- "sw" => __("Swahili",'ultimate-member'),
1665
- "ta" => __("Tamil",'ultimate-member'),
1666
- "te" => __("Telugu",'ultimate-member'),
1667
- "tg" => __("Tajik",'ultimate-member'),
1668
- "th" => __("Thai",'ultimate-member'),
1669
- "ti" => __("Tigrinya",'ultimate-member'),
1670
- "tk" => __("Turkmen",'ultimate-member'),
1671
- "tl" => __("Tagalog",'ultimate-member'),
1672
- "tn" => __("Tswana",'ultimate-member'),
1673
- "to" => __("Tonga",'ultimate-member'),
1674
- "tr" => __("Turkish",'ultimate-member'),
1675
- "ts" => __("Tsonga",'ultimate-member'),
1676
- "tt" => __("Tatar",'ultimate-member'),
1677
- "tw" => __("Twi",'ultimate-member'),
1678
- "ty" => __("Tahitian",'ultimate-member'),
1679
- "ug" => __("Uighur",'ultimate-member'),
1680
- "uk" => __("Ukrainian",'ultimate-member'),
1681
- "ur" => __("Urdu",'ultimate-member'),
1682
- "uz" => __("Uzbek",'ultimate-member'),
1683
- "ve" => __("Venda",'ultimate-member'),
1684
- "vi" => __("Vietnamese",'ultimate-member'),
1685
- "vo" => __("Volapuk",'ultimate-member'),
1686
- "wa" => __("Walloon",'ultimate-member'),
1687
- "wo" => __("Wolof",'ultimate-member'),
1688
- "xh" => __("Xhosa",'ultimate-member'),
1689
- "yi" => __("Yiddish",'ultimate-member'),
1690
- "yo" => __("Yoruba",'ultimate-member'),
1691
- "za" => __("Zhuang",'ultimate-member'),
1692
- "zh" => __("Chinese",'ultimate-member'),
1693
- "zu" => __("Zulu",'ultimate-member')
1694
- );
1695
- break;
1696
-
1697
- case 'countries':
1698
- $array = array (
1699
- 'AF' => __('Afghanistan','ultimate-member'),
1700
- 'AX' => __('Åland Islands','ultimate-member'),
1701
- 'AL' => __('Albania','ultimate-member'),
1702
- 'DZ' => __('Algeria','ultimate-member'),
1703
- 'AS' => __('American Samoa','ultimate-member'),
1704
- 'AD' => __('Andorra','ultimate-member'),
1705
- 'AO' => __('Angola','ultimate-member'),
1706
- 'AI' => __('Anguilla','ultimate-member'),
1707
- 'AQ' => __('Antarctica','ultimate-member'),
1708
- 'AG' => __('Antigua and Barbuda','ultimate-member'),
1709
- 'AR' => __('Argentina','ultimate-member'),
1710
- 'AM' => __('Armenia','ultimate-member'),
1711
- 'AW' => __('Aruba','ultimate-member'),
1712
- 'AU' => __('Australia','ultimate-member'),
1713
- 'AT' => __('Austria','ultimate-member'),
1714
- 'AZ' => __('Azerbaijan','ultimate-member'),
1715
- 'BS' => __('Bahamas','ultimate-member'),
1716
- 'BH' => __('Bahrain','ultimate-member'),
1717
- 'BD' => __('Bangladesh','ultimate-member'),
1718
- 'BB' => __('Barbados','ultimate-member'),
1719
- 'BY' => __('Belarus','ultimate-member'),
1720
- 'BE' => __('Belgium','ultimate-member'),
1721
- 'BZ' => __('Belize','ultimate-member'),
1722
- 'BJ' => __('Benin','ultimate-member'),
1723
- 'BM' => __('Bermuda','ultimate-member'),
1724
- 'BT' => __('Bhutan','ultimate-member'),
1725
- 'BO' => __('Bolivia, Plurinational State of','ultimate-member'),
1726
- 'BA' => __('Bosnia and Herzegovina','ultimate-member'),
1727
- 'BW' => __('Botswana','ultimate-member'),
1728
- 'BV' => __('Bouvet Island','ultimate-member'),
1729
- 'BR' => __('Brazil','ultimate-member'),
1730
- 'IO' => __('British Indian Ocean Territory','ultimate-member'),
1731
- 'BN' => __('Brunei Darussalam','ultimate-member'),
1732
- 'BG' => __('Bulgaria','ultimate-member'),
1733
- 'BF' => __('Burkina Faso','ultimate-member'),
1734
- 'BI' => __('Burundi','ultimate-member'),
1735
- 'KH' => __('Cambodia','ultimate-member'),
1736
- 'CM' => __('Cameroon','ultimate-member'),
1737
- 'CA' => __('Canada','ultimate-member'),
1738
- 'CV' => __('Cape Verde','ultimate-member'),
1739
- 'KY' => __('Cayman Islands','ultimate-member'),
1740
- 'CF' => __('Central African Republic','ultimate-member'),
1741
- 'TD' => __('Chad','ultimate-member'),
1742
- 'CL' => __('Chile','ultimate-member'),
1743
- 'CN' => __('China','ultimate-member'),
1744
- 'CX' => __('Christmas Island','ultimate-member'),
1745
- 'CC' => __('Cocos (Keeling) Islands','ultimate-member'),
1746
- 'CO' => __('Colombia','ultimate-member'),
1747
- 'KM' => __('Comoros','ultimate-member'),
1748
- 'CG' => __('Congo','ultimate-member'),
1749
- 'CD' => __('Congo, the Democratic Republic of the','ultimate-member'),
1750
- 'CK' => __('Cook Islands','ultimate-member'),
1751
- 'CR' => __('Costa Rica','ultimate-member'),
1752
- 'CI' => __("Côte d'Ivoire",'ultimate-member'),
1753
- 'HR' => __('Croatia','ultimate-member'),
1754
- 'CU' => __('Cuba','ultimate-member'),
1755
- 'CY' => __('Cyprus','ultimate-member'),
1756
- 'CZ' => __('Czech Republic','ultimate-member'),
1757
- 'DK' => __('Denmark','ultimate-member'),
1758
- 'DJ' => __('Djibouti','ultimate-member'),
1759
- 'DM' => __('Dominica','ultimate-member'),
1760
- 'DO' => __('Dominican Republic','ultimate-member'),
1761
- 'EC' => __('Ecuador','ultimate-member'),
1762
- 'EG' => __('Egypt','ultimate-member'),
1763
- 'SV' => __('El Salvador','ultimate-member'),
1764
- 'GQ' => __('Equatorial Guinea','ultimate-member'),
1765
- 'ER' => __('Eritrea','ultimate-member'),
1766
- 'EE' => __('Estonia','ultimate-member'),
1767
- 'ET' => __('Ethiopia','ultimate-member'),
1768
- 'FK' => __('Falkland Islands (Malvinas)','ultimate-member'),
1769
- 'FO' => __('Faroe Islands','ultimate-member'),
1770
- 'FJ' => __('Fiji','ultimate-member'),
1771
- 'FI' => __('Finland','ultimate-member'),
1772
- 'FR' => __('France','ultimate-member'),
1773
- 'GF' => __('French Guiana','ultimate-member'),
1774
- 'PF' => __('French Polynesia','ultimate-member'),
1775
- 'TF' => __('French Southern Territories','ultimate-member'),
1776
- 'GA' => __('Gabon','ultimate-member'),
1777
- 'GM' => __('Gambia','ultimate-member'),
1778
- 'GE' => __('Sakartvelo','ultimate-member'),
1779
- 'DE' => __('Germany','ultimate-member'),
1780
- 'GH' => __('Ghana','ultimate-member'),
1781
- 'GI' => __('Gibraltar','ultimate-member'),
1782
- 'GR' => __('Greece','ultimate-member'),
1783
- 'GL' => __('Greenland','ultimate-member'),
1784
- 'GD' => __('Grenada','ultimate-member'),
1785
- 'GP' => __('Guadeloupe','ultimate-member'),
1786
- 'GU' => __('Guam','ultimate-member'),
1787
- 'GT' => __('Guatemala','ultimate-member'),
1788
- 'GG' => __('Guernsey','ultimate-member'),
1789
- 'GN' => __('Guinea','ultimate-member'),
1790
- 'GW' => __('Guinea-Bissau','ultimate-member'),
1791
- 'GY' => __('Guyana','ultimate-member'),
1792
- 'HT' => __('Haiti','ultimate-member'),
1793
- 'HM' => __('Heard Island and McDonald Islands','ultimate-member'),
1794
- 'VA' => __('Holy See (Vatican City State)','ultimate-member'),
1795
- 'HN' => __('Honduras','ultimate-member'),
1796
- 'HK' => __('Hong Kong','ultimate-member'),
1797
- 'HU' => __('Hungary','ultimate-member'),
1798
- 'IS' => __('Iceland','ultimate-member'),
1799
- 'IN' => __('India','ultimate-member'),
1800
- 'ID' => __('Indonesia','ultimate-member'),
1801
- 'IR' => __('Iran, Islamic Republic of','ultimate-member'),
1802
- 'IQ' => __('Iraq','ultimate-member'),
1803
- 'IE' => __('Ireland','ultimate-member'),
1804
- 'IM' => __('Isle of Man','ultimate-member'),
1805
- 'IL' => __('Israel','ultimate-member'),
1806
- 'IT' => __('Italy','ultimate-member'),
1807
- 'JM' => __('Jamaica','ultimate-member'),
1808
- 'JP' => __('Japan','ultimate-member'),
1809
- 'JE' => __('Jersey','ultimate-member'),
1810
- 'JO' => __('Jordan','ultimate-member'),
1811
- 'KZ' => __('Kazakhstan','ultimate-member'),
1812
- 'KE' => __('Kenya','ultimate-member'),
1813
- 'KI' => __('Kiribati','ultimate-member'),
1814
- 'KP' => __("Korea, Democratic People's Republic of",'ultimate-member'),
1815
- 'KR' => __('Korea, Republic of','ultimate-member'),
1816
- 'KW' => __('Kuwait','ultimate-member'),
1817
- 'KG' => __('Kyrgyzstan','ultimate-member'),
1818
- 'LA' => __("Lao People's Democratic Republic",'ultimate-member'),
1819
- 'LV' => __('Latvia','ultimate-member'),
1820
- 'LB' => __('Lebanon','ultimate-member'),
1821
- 'LS' => __('Lesotho','ultimate-member'),
1822
- 'LR' => __('Liberia','ultimate-member'),
1823
- 'LY' => __('Libyan Arab Jamahiriya','ultimate-member'),
1824
- 'LI' => __('Liechtenstein','ultimate-member'),
1825
- 'LT' => __('Lithuania','ultimate-member'),
1826
- 'LU' => __('Luxembourg','ultimate-member'),
1827
- 'MO' => __('Macao','ultimate-member'),
1828
- 'MK' => __('Macedonia, the former Yugoslav Republic of','ultimate-member'),
1829
- 'MG' => __('Madagascar','ultimate-member'),
1830
- 'MW' => __('Malawi','ultimate-member'),
1831
- 'MY' => __('Malaysia','ultimate-member'),
1832
- 'MV' => __('Maldives','ultimate-member'),
1833
- 'ML' => __('Mali','ultimate-member'),
1834
- 'MT' => __('Malta','ultimate-member'),
1835
- 'MH' => __('Marshall Islands','ultimate-member'),
1836
- 'MQ' => __('Martinique','ultimate-member'),
1837
- 'MR' => __('Mauritania','ultimate-member'),
1838
- 'MU' => __('Mauritius','ultimate-member'),
1839
- 'YT' => __('Mayotte','ultimate-member'),
1840
- 'MX' => __('Mexico','ultimate-member'),
1841
- 'FM' => __('Micronesia, Federated States of','ultimate-member'),
1842
- 'MD' => __('Moldova, Republic of','ultimate-member'),
1843
- 'MC' => __('Monaco','ultimate-member'),
1844
- 'MN' => __('Mongolia','ultimate-member'),
1845
- 'ME' => __('Montenegro','ultimate-member'),
1846
- 'MS' => __('Montserrat','ultimate-member'),
1847
- 'MA' => __('Morocco','ultimate-member'),
1848
- 'MZ' => __('Mozambique','ultimate-member'),
1849
- 'MM' => __('Myanmar','ultimate-member'),
1850
- 'NA' => __('Namibia','ultimate-member'),
1851
- 'NR' => __('Nauru','ultimate-member'),
1852
- 'NP' => __('Nepal','ultimate-member'),
1853
- 'NL' => __('Netherlands','ultimate-member'),
1854
- 'AN' => __('Netherlands Antilles','ultimate-member'),
1855
- 'NC' => __('New Caledonia','ultimate-member'),
1856
- 'NZ' => __('New Zealand','ultimate-member'),
1857
- 'NI' => __('Nicaragua','ultimate-member'),
1858
- 'NE' => __('Niger','ultimate-member'),
1859
- 'NG' => __('Nigeria','ultimate-member'),
1860
- 'NU' => __('Niue','ultimate-member'),
1861
- 'NF' => __('Norfolk Island','ultimate-member'),
1862
- 'MP' => __('Northern Mariana Islands','ultimate-member'),
1863
- 'NO' => __('Norway','ultimate-member'),
1864
- 'OM' => __('Oman','ultimate-member'),
1865
- 'PK' => __('Pakistan','ultimate-member'),
1866
- 'PW' => __('Palau','ultimate-member'),
1867
- 'PS' => __('Palestine','ultimate-member'),
1868
- 'PA' => __('Panama','ultimate-member'),
1869
- 'PG' => __('Papua New Guinea','ultimate-member'),
1870
- 'PY' => __('Paraguay','ultimate-member'),
1871
- 'PE' => __('Peru','ultimate-member'),
1872
- 'PH' => __('Philippines','ultimate-member'),
1873
- 'PN' => __('Pitcairn','ultimate-member'),
1874
- 'PL' => __('Poland','ultimate-member'),
1875
- 'PT' => __('Portugal','ultimate-member'),
1876
- 'PR' => __('Puerto Rico','ultimate-member'),
1877
- 'QA' => __('Qatar','ultimate-member'),
1878
- 'RE' => __('Réunion','ultimate-member'),
1879
- 'RO' => __('Romania','ultimate-member'),
1880
- 'RU' => __('Russian Federation','ultimate-member'),
1881
- 'RW' => __('Rwanda','ultimate-member'),
1882
- 'BL' => __('Saint Barthélemy','ultimate-member'),
1883
- 'SH' => __('Saint Helena','ultimate-member'),
1884
- 'KN' => __('Saint Kitts and Nevis','ultimate-member'),
1885
- 'LC' => __('Saint Lucia','ultimate-member'),
1886
- 'MF' => __('Saint Martin (French part)','ultimate-member'),
1887
- 'PM' => __('Saint Pierre and Miquelon','ultimate-member'),
1888
- 'VC' => __('Saint Vincent and the Grenadines','ultimate-member'),
1889
- 'WS' => __('Samoa','ultimate-member'),
1890
- 'SM' => __('San Marino','ultimate-member'),
1891
- 'ST' => __('Sao Tome and Principe','ultimate-member'),
1892
- 'SA' => __('Saudi Arabia','ultimate-member'),
1893
- 'SN' => __('Senegal','ultimate-member'),
1894
- 'RS' => __('Serbia','ultimate-member'),
1895
- 'SC' => __('Seychelles','ultimate-member'),
1896
- 'SL' => __('Sierra Leone','ultimate-member'),
1897
- 'SG' => __('Singapore','ultimate-member'),
1898
- 'SK' => __('Slovakia','ultimate-member'),
1899
- 'SI' => __('Slovenia','ultimate-member'),
1900
- 'SB' => __('Solomon Islands','ultimate-member'),
1901
- 'SO' => __('Somalia','ultimate-member'),
1902
- 'ZA' => __('South Africa','ultimate-member'),
1903
- 'GS' => __('South Georgia and the South Sandwich Islands','ultimate-member'),
1904
- 'SS' => __('South Sudan','ultimate-member'),
1905
- 'ES' => __('Spain','ultimate-member'),
1906
- 'LK' => __('Sri Lanka','ultimate-member'),
1907
- 'SD' => __('Sudan','ultimate-member'),
1908
- 'SR' => __('Suriname','ultimate-member'),
1909
- 'SJ' => __('Svalbard and Jan Mayen','ultimate-member'),
1910
- 'SZ' => __('Swaziland','ultimate-member'),
1911
- 'SE' => __('Sweden','ultimate-member'),
1912
- 'CH' => __('Switzerland','ultimate-member'),
1913
- 'SY' => __('Syrian Arab Republic','ultimate-member'),
1914
- 'TW' => __('Taiwan, Province of China','ultimate-member'),
1915
- 'TJ' => __('Tajikistan','ultimate-member'),
1916
- 'TZ' => __('Tanzania, United Republic of','ultimate-member'),
1917
- 'TH' => __('Thailand','ultimate-member'),
1918
- 'TL' => __('Timor-Leste','ultimate-member'),
1919
- 'TG' => __('Togo','ultimate-member'),
1920
- 'TK' => __('Tokelau','ultimate-member'),
1921
- 'TO' => __('Tonga','ultimate-member'),
1922
- 'TT' => __('Trinidad and Tobago','ultimate-member'),
1923
- 'TN' => __('Tunisia','ultimate-member'),
1924
- 'TR' => __('Turkey','ultimate-member'),
1925
- 'TM' => __('Turkmenistan','ultimate-member'),
1926
- 'TC' => __('Turks and Caicos Islands','ultimate-member'),
1927
- 'TV' => __('Tuvalu','ultimate-member'),
1928
- 'UG' => __('Uganda','ultimate-member'),
1929
- 'UA' => __('Ukraine','ultimate-member'),
1930
- 'AE' => __('United Arab Emirates','ultimate-member'),
1931
- 'GB' => __('United Kingdom','ultimate-member'),
1932
- 'US' => __('United States','ultimate-member'),
1933
- 'UM' => __('United States Minor Outlying Islands','ultimate-member'),
1934
- 'UY' => __('Uruguay','ultimate-member'),
1935
- 'UZ' => __('Uzbekistan','ultimate-member'),
1936
- 'VU' => __('Vanuatu','ultimate-member'),
1937
- 'VE' => __('Venezuela, Bolivarian Republic of','ultimate-member'),
1938
- 'VN' => __('Viet Nam','ultimate-member'),
1939
- 'VG' => __('Virgin Islands, British','ultimate-member'),
1940
- 'VI' => __('Virgin Islands, U.S.','ultimate-member'),
1941
- 'WF' => __('Wallis and Futuna','ultimate-member'),
1942
- 'EH' => __('Western Sahara','ultimate-member'),
1943
- 'YE' => __('Yemen','ultimate-member'),
1944
- 'ZM' => __('Zambia','ultimate-member'),
1945
- 'ZW' => __('Zimbabwe','ultimate-member'),
1946
- );
1947
- break;
1948
-
1949
- }
1950
-
1951
- /**
1952
- * UM hook
1953
- *
1954
- * @type filter
1955
- * @title um_{$data}_predefined_field_options
1956
- * @description Extend Predefined Fields options. Where $data - field key.
1957
- * @input_vars
1958
- * [{"var":"$options","type":"array","desc":"Field's Options"}]
1959
- * @change_log
1960
- * ["Since: 2.0"]
1961
- * @usage add_filter( 'um_{$data}_predefined_field_options', 'function_name', 10, 1 );
1962
- * @example
1963
- * <?php
1964
- * add_filter( 'um_{$data}_predefined_field_options', 'my_predefined_field', 10, 1 );
1965
- * function my_predefined_field( $options ) {
1966
- * // your code here
1967
- * return $options;
1968
- * }
1969
- * ?>
1970
- */
1971
- $array = apply_filters( "um_{$data}_predefined_field_options", $array );
1972
- return $array;
1973
- }
1974
-
1975
- }
1976
- }
1
+ <?php
2
+ namespace um\core;
3
+
4
+ // Exit if accessed directly
5
+ if ( ! defined( 'ABSPATH' ) ) exit;
6
+
7
+ if ( ! class_exists( 'um\core\Builtin' ) ) {
8
+
9
+
10
+ /**
11
+ * Class Builtin
12
+ * @package um\core
13
+ */
14
+ class Builtin {
15
+
16
+
17
+ /**
18
+ * @var array
19
+ */
20
+ public $predefined_fields = array();
21
+
22
+
23
+ /**
24
+ * @var array
25
+ */
26
+ var $all_user_fields = array();
27
+
28
+
29
+ /**
30
+ * @var array
31
+ */
32
+ var $core_fields = array();
33
+
34
+
35
+ /**
36
+ * Builtin constructor.
37
+ */
38
+ function __construct() {
39
+ add_action( 'init', array( &$this, 'set_core_fields' ), 1 );
40
+ add_action( 'init', array( &$this, 'set_predefined_fields' ), 1 );
41
+ add_action( 'init', array( &$this, 'set_custom_fields' ), 1 );
42
+ $this->saved_fields = get_option( 'um_fields' );
43
+ }
44
+
45
+
46
+ /**
47
+ * @return array
48
+ */
49
+ function get_all_user_fields() {
50
+ return apply_filters( 'um_builtin_all_user_fields', $this->all_user_fields );
51
+ }
52
+
53
+
54
+ /**
55
+ * Regular or multi-select/options
56
+ *
57
+ * @param $field
58
+ * @param $attrs
59
+ *
60
+ * @return bool
61
+ */
62
+ function is_dropdown_field( $field, $attrs ) {
63
+
64
+ if ( isset( $attrs['options'] ) ) {
65
+ return true;
66
+ }
67
+
68
+ $fields = $this->all_user_fields;
69
+
70
+ if ( isset( $fields[ $field ]['options'] ) || ! empty( $fields[ $field ]['custom_dropdown_options_source'] ) ) {
71
+ return true;
72
+ }
73
+
74
+ return false;
75
+ }
76
+
77
+
78
+ /**
79
+ * Get a field
80
+ *
81
+ * @param $field
82
+ *
83
+ * @return mixed|string
84
+ */
85
+ function get_a_field( $field ) {
86
+ $fields = $this->all_user_fields;
87
+ if ( isset( $fields[ $field ] ) ) {
88
+ return $fields[ $field ];
89
+ }
90
+ return '';
91
+ }
92
+
93
+
94
+ /**
95
+ * Get specific fields
96
+ *
97
+ * @param $fields
98
+ *
99
+ * @return array
100
+ */
101
+ function get_specific_fields( $fields ) {
102
+ $fields = explode( ',', $fields );
103
+ $array = array();
104
+ foreach ( $fields as $field ) {
105
+ if ( isset( $this->predefined_fields[ $field ] ) ) {
106
+ $array[ $field ] = $this->predefined_fields[ $field ];
107
+ }
108
+ }
109
+ return $array;
110
+ }
111
+
112
+
113
+ /**
114
+ * Get specific field
115
+ *
116
+ * @param $fields
117
+ *
118
+ * @return array|mixed
119
+ */
120
+ function get_specific_field( $fields ) {
121
+ $fields = explode( ',', $fields );
122
+ $array = array();
123
+ foreach ( $fields as $field ) {
124
+ if ( isset( $this->predefined_fields[ $field ] ) ) {
125
+ $array = $this->predefined_fields[ $field ];
126
+ } elseif ( isset( $this->saved_fields[ $field ] ) ) {
127
+ $array = $this->saved_fields[ $field ];
128
+ }
129
+ }
130
+ return $array;
131
+ }
132
+
133
+
134
+ /**
135
+ * Checks for a unique field error
136
+ *
137
+ * @param $key
138
+ *
139
+ * @return int|string
140
+ */
141
+ function unique_field_err( $key ) {
142
+ if ( empty( $key ) ) {
143
+ return __( 'Please provide a meta key', 'ultimate-member' );
144
+ }
145
+ if ( isset( $this->core_fields[ $key ] ) ) {
146
+ return __( 'Your meta key is a reserved core field and cannot be used', 'ultimate-member' );
147
+ }
148
+ if ( isset( $this->predefined_fields[ $key ] ) ) {
149
+ return __( 'Your meta key is a predefined reserved key and cannot be used', 'ultimate-member' );
150
+ }
151
+ if ( isset( $this->saved_fields[ $key ] ) ) {
152
+ return __( 'Your meta key already exists in your fields list', 'ultimate-member' );
153
+ }
154
+ if ( ! UM()->validation()->safe_string( $key ) ) {
155
+ return __( 'Your meta key contains illegal characters. Please correct it.', 'ultimate-member' );
156
+ }
157
+
158
+ return 0;
159
+ }
160
+
161
+
162
+ /**
163
+ * Check date range errors (start date)
164
+ *
165
+ * @param $date
166
+ *
167
+ * @return int|string
168
+ */
169
+ function date_range_start_err( $date ) {
170
+ if ( empty( $date ) ) {
171
+ return __( 'Please provide a date range beginning', 'ultimate-member' );
172
+ }
173
+ if ( ! UM()->validation()->validate_date( $date ) ) {
174
+ return __( 'Please enter a valid start date in the date range', 'ultimate-member' );
175
+ }
176
+
177
+ return 0;
178
+ }
179
+
180
+
181
+ /**
182
+ * Check date range errors (end date)
183
+ *
184
+ * @param $date
185
+ * @param $start_date
186
+ *
187
+ * @return int|string
188
+ */
189
+ function date_range_end_err( $date, $start_date ) {
190
+ if ( empty( $date ) ) {
191
+ return __( 'Please provide a date range end', 'ultimate-member' );
192
+ }
193
+ if ( ! UM()->validation()->validate_date( $date ) ) {
194
+ return __( 'Please enter a valid end date in the date range', 'ultimate-member' );
195
+ }
196
+ if ( strtotime( $date ) <= strtotime( $start_date ) ) {
197
+ return __( 'The end of date range must be greater than the start of date range', 'ultimate-member' );
198
+ }
199
+ return 0;
200
+ }
201
+
202
+
203
+ /**
204
+ * Get a core field attrs
205
+ *
206
+ * @param $type
207
+ *
208
+ * @return array|mixed
209
+ */
210
+ function get_core_field_attrs( $type ) {
211
+ return ( isset( $this->core_fields[ $type ] ) ) ? $this->core_fields[ $type ] : array('');
212
+ }
213
+
214
+
215
+ /**
216
+ * Core Fields
217
+ */
218
+ function set_core_fields() {
219
+
220
+ $this->core_fields = array(
221
+
222
+ 'row' => array(
223
+ 'name' => 'Row',
224
+ 'in_fields' => false,
225
+ 'form_only' => true,
226
+ 'conditional_support' => 0,
227
+ 'icon' => 'um-faicon-pencil',
228
+ 'col1' => array('_id','_background','_text_color','_padding','_margin','_border','_borderradius','_borderstyle','_bordercolor'),
229
+ 'col2' => array('_heading','_heading_text','_heading_background_color','_heading_text_color','_icon','_icon_color','_css_class'),
230
+ ),
231
+
232
+ 'text' => array(
233
+ 'name' => 'Text Box',
234
+ 'col1' => array('_title','_metakey','_help','_default','_min_chars','_visibility'),
235
+ 'col2' => array('_label','_placeholder','_public','_roles','_validate','_custom_validate','_max_chars'),
236
+ 'col3' => array('_required','_editable','_icon'),
237
+ 'validate' => array(
238
+ '_title' => array(
239
+ 'mode' => 'required',
240
+ 'error' => __('You must provide a title','ultimate-member')
241
+ ),
242
+ '_metakey' => array(
243
+ 'mode' => 'unique',
244
+ ),
245
+ )
246
+ ),
247
+
248
+ 'number' => array(
249
+ 'name' => __('Number','ultimate-member'),
250
+ 'col1' => array('_title','_metakey','_help','_default','_min','_visibility'),
251
+ 'col2' => array('_label','_placeholder','_public','_roles','_validate','_custom_validate','_max'),
252
+ 'col3' => array('_required','_editable','_icon'),
253
+ 'validate' => array(
254
+ '_title' => array(
255
+ 'mode' => 'required',
256
+ 'error' => __('You must provide a title','ultimate-member')
257
+ ),
258
+ '_metakey' => array(
259
+ 'mode' => 'unique',
260
+ ),
261
+ )
262
+ ),
263
+
264
+ 'textarea' => array(
265
+ 'name' => 'Textarea',
266
+ 'col1' => array('_title','_metakey','_help','_height','_max_chars','_max_words','_visibility'),
267
+ 'col2' => array('_label','_placeholder','_public','_roles','_default','_html'),
268
+ 'col3' => array('_required','_editable','_icon'),
269
+ 'validate' => array(
270
+ '_title' => array(
271
+ 'mode' => 'required',
272
+ 'error' => __('You must provide a title','ultimate-member')
273
+ ),
274
+ '_metakey' => array(
275
+ 'mode' => 'unique',
276
+ ),
277
+ )
278
+ ),
279
+
280
+ 'select' => array(
281
+ 'name' => 'Dropdown',
282
+ 'col1' => array('_title','_metakey','_help','_default','_options','_visibility'),
283
+ 'col2' => array('_label','_placeholder','_public','_roles','_custom_dropdown_options_source','_parent_dropdown_relationship'),
284
+ 'col3' => array('_required','_editable','_icon'),
285
+ 'validate' => array(
286
+ '_title' => array(
287
+ 'mode' => 'required',
288
+ 'error' => __('You must provide a title','ultimate-member')
289
+ ),
290
+ '_metakey' => array(
291
+ 'mode' => 'unique',
292
+ ),
293
+ '_options' => array(
294
+ 'mode' => 'required',
295
+ 'error' => __('You have not added any choices yet.','ultimate-member')
296
+ ),
297
+ )
298
+ ),
299
+
300
+ 'multiselect' => array(
301
+ 'name' => 'Multi-Select',
302
+ 'col1' => array('_title','_metakey','_help','_default','_options','_visibility'),
303
+ 'col2' => array('_label','_placeholder','_public','_roles','_min_selections','_max_selections','_custom_dropdown_options_source'),
304
+ 'col3' => array('_required','_editable','_icon'),
305
+ 'validate' => array(
306
+ '_title' => array(
307
+ 'mode' => 'required',
308
+ 'error' => __('You must provide a title','ultimate-member')
309
+ ),
310
+ '_metakey' => array(
311
+ 'mode' => 'unique',
312
+ ),
313
+ '_options' => array(
314
+ 'mode' => 'required',
315
+ 'error' => __('You have not added any choices yet.','ultimate-member')
316
+ ),
317
+ )
318
+ ),
319
+
320
+ 'radio' => array(
321
+ 'name' => 'Radio',
322
+ 'col1' => array('_title','_metakey','_help','_default','_options','_visibility'),
323
+ 'col2' => array('_label','_public','_roles'),
324
+ 'col3' => array('_required','_editable','_icon'),
325
+ 'validate' => array(
326
+ '_title' => array(
327
+ 'mode' => 'required',
328
+ 'error' => __('You must provide a title','ultimate-member')
329
+ ),
330
+ '_metakey' => array(
331
+ 'mode' => 'unique',
332
+ ),
333
+ '_options' => array(
334
+ 'mode' => 'required',
335
+ 'error' => __('You have not added any choices yet.','ultimate-member')
336
+ ),
337
+ )
338
+ ),
339
+
340
+ 'checkbox' => array(
341
+ 'name' => 'Checkbox',
342
+ 'col1' => array('_title','_metakey','_help','_default','_options','_visibility'),
343
+ 'col2' => array('_label','_public','_roles','_max_selections'),
344
+ 'col3' => array('_required','_editable','_icon'),
345
+ 'validate' => array(
346
+ '_title' => array(
347
+ 'mode' => 'required',
348
+ 'error' => __('You must provide a title','ultimate-member')
349
+ ),
350
+ '_metakey' => array(
351
+ 'mode' => 'unique',
352
+ ),
353
+ '_options' => array(
354
+ 'mode' => 'required',
355
+ 'error' => __('You have not added any choices yet.','ultimate-member')
356
+ ),
357
+ )
358
+ ),
359
+
360
+ 'url' => array(
361
+ 'name' => 'URL',
362
+ 'col1' => array('_title','_metakey','_help','_default','_url_text','_visibility'),
363
+ 'col2' => array('_label','_placeholder','_url_target','_url_rel','_public','_roles','_validate','_custom_validate'),
364
+ 'col3' => array('_required','_editable','_icon'),
365
+ 'validate' => array(
366
+ '_title' => array(
367
+ 'mode' => 'required',
368
+ 'error' => __('You must provide a title','ultimate-member')
369
+ ),
370
+ '_metakey' => array(
371
+ 'mode' => 'unique',
372
+ ),
373
+ )
374
+ ),
375
+
376
+ 'password' => array(
377
+ 'name' => 'Password',
378
+ 'col1' => array('_title','_metakey','_help','_min_chars','_max_chars','_visibility'),
379
+ 'col2' => array('_label','_placeholder','_public','_roles','_force_good_pass','_force_confirm_pass','_label_confirm_pass'),
380
+ 'col3' => array('_required','_editable','_icon'),
381
+ 'validate' => array(
382
+ '_title' => array(
383
+ 'mode' => 'required',
384
+ 'error' => __('You must provide a title','ultimate-member')
385
+ ),
386
+ '_metakey' => array(
387
+ 'mode' => 'unique',
388
+ ),
389
+ )
390
+ ),
391
+
392
+ 'image' => array(
393
+ 'name' => 'Image Upload',
394
+ 'col1' => array('_title','_metakey','_help','_allowed_types','_max_size','_crop','_visibility'),
395
+ 'col2' => array('_label','_public','_roles','_upload_text','_upload_help_text','_button_text'),
396
+ 'col3' => array('_required','_editable','_icon'),
397
+ 'validate' => array(
398
+ '_title' => array(
399
+ 'mode' => 'required',
400
+ 'error' => __('You must provide a title','ultimate-member')
401
+ ),
402
+ '_metakey' => array(
403
+ 'mode' => 'unique',
404
+ ),
405
+ '_max_size' => array(
406
+ 'mode' => 'numeric',
407
+ 'error' => __('Please enter a valid size','ultimate-member')
408
+ ),
409
+ )
410
+ ),
411
+
412
+ 'file' => array(
413
+ 'name' => 'File Upload',
414
+ 'col1' => array('_title','_metakey','_help','_allowed_types','_max_size','_visibility'),
415
+ 'col2' => array('_label','_public','_roles','_upload_text','_upload_help_text','_button_text'),
416
+ 'col3' => array('_required','_editable','_icon'),
417
+ 'validate' => array(
418
+ '_title' => array(
419
+ 'mode' => 'required',
420
+ 'error' => __('You must provide a title','ultimate-member')
421
+ ),
422
+ '_metakey' => array(
423
+ 'mode' => 'unique',
424
+ ),
425
+ '_max_size' => array(
426
+ 'mode' => 'numeric',
427
+ 'error' => __( 'Please enter a valid size', 'ultimate-member' )
428
+ ),
429
+ )
430
+ ),
431
+
432
+ 'date' => array(
433
+ 'name' => 'Date Picker',
434
+ 'col1' => array( '_title', '_metakey', '_help', '_default', '_range', '_years', '_years_x', '_range_start', '_range_end', '_visibility' ),
435
+ 'col2' => array( '_label', '_placeholder', '_public', '_roles', '_format', '_format_custom', '_pretty_format', '_disabled_weekdays' ),
436
+ 'col3' => array( '_required', '_editable', '_icon' ),
437
+ 'validate' => array(
438
+ '_title' => array(
439
+ 'mode' => 'required',
440
+ 'error' => __( 'You must provide a title', 'ultimate-member' )
441
+ ),
442
+ '_metakey' => array(
443
+ 'mode' => 'unique',
444
+ ),
445
+ '_years' => array(
446
+ 'mode' => 'numeric',
447
+ 'error' => __( 'Number of years is not valid', 'ultimate-member' )
448
+ ),
449
+ '_range_start' => array(
450
+ 'mode' => 'range-start',
451
+ ),
452
+ '_range_end' => array(
453
+ 'mode' => 'range-end',
454
+ ),
455
+ )
456
+ ),
457
+
458
+ 'time' => array(
459
+ 'name' => 'Time Picker',
460
+ 'col1' => array('_title','_metakey','_help','_format','_visibility'),
461
+ 'col2' => array('_label','_placeholder','_default','_public','_roles','_intervals'),
462
+ 'col3' => array('_required','_editable','_icon'),
463
+ 'validate' => array(
464
+ '_title' => array(
465
+ 'mode' => 'required',
466
+ 'error' => __( 'You must provide a title', 'ultimate-member' )
467
+ ),
468
+ '_metakey' => array(
469
+ 'mode' => 'unique',
470
+ ),
471
+ )
472
+ ),
473
+
474
+ 'rating' => array(
475
+ 'name' => 'Rating',
476
+ 'col1' => array('_title','_metakey','_help','_visibility'),
477
+ 'col2' => array('_label','_public','_roles','_number','_default'),
478
+ 'col3' => array('_required','_editable','_icon'),
479
+ 'validate' => array(
480
+ '_title' => array(
481
+ 'mode' => 'required',
482
+ 'error' => __('You must provide a title','ultimate-member')
483
+ ),
484
+ '_metakey' => array(
485
+ 'mode' => 'unique',
486
+ ),
487
+ )
488
+ ),
489
+
490
+ 'block' => array(
491
+ 'name' => 'Content Block',
492
+ 'col1' => array('_title','_visibility'),
493
+ 'col2' => array('_public','_roles'),
494
+ 'col_full' => array('_content'),
495
+ 'mce_content' => true,
496
+ 'validate' => array(
497
+ '_title' => array(
498
+ 'mode' => 'required',
499
+ 'error' => __('You must provide a title','ultimate-member')
500
+ ),
501
+ )
502
+ ),
503
+
504
+ 'shortcode' => array(
505
+ 'name' => 'Shortcode',
506
+ 'col1' => array('_title','_visibility'),
507
+ 'col2' => array('_public','_roles'),
508
+ 'col_full' => array('_content'),
509
+ 'validate' => array(
510
+ '_title' => array(
511
+ 'mode' => 'required',
512
+ 'error' => __('You must provide a title','ultimate-member')
513
+ ),
514
+ '_content' => array(
515
+ 'mode' => 'required',
516
+ 'error' => __('You must add a shortcode to the content area','ultimate-member')
517
+ ),
518
+ )
519
+ ),
520
+
521
+ 'spacing' => array(
522
+ 'name' => 'Spacing',
523
+ 'col1' => array('_title','_visibility'),
524
+ 'col2' => array('_spacing'),
525
+ 'form_only' => true,
526
+ 'validate' => array(
527
+ '_title' => array(
528
+ 'mode' => 'required',
529
+ 'error' => __('You must provide a title','ultimate-member')
530
+ ),
531
+ )
532
+ ),
533
+
534
+ 'divider' => array(
535
+ 'name' => 'Divider',
536
+ 'col1' => array('_title','_width','_divider_text','_visibility'),
537
+ 'col2' => array('_style','_color','_public','_roles'),
538
+ 'form_only' => true,
539
+ 'validate' => array(
540
+ '_title' => array(
541
+ 'mode' => 'required',
542
+ 'error' => __('You must provide a title','ultimate-member')
543
+ ),
544
+ )
545
+ ),
546
+
547
+ 'googlemap' => array(
548
+ 'name' => 'Google Map',
549
+ 'col1' => array('_title','_metakey','_help','_visibility'),
550
+ 'col2' => array('_label','_placeholder','_public','_roles','_validate','_custom_validate'),
551
+ 'col3' => array('_required','_editable','_icon'),
552
+ 'validate' => array(
553
+ '_title' => array(
554
+ 'mode' => 'required',
555
+ 'error' => __('You must provide a title','ultimate-member')
556
+ ),
557
+ '_metakey' => array(
558
+ 'mode' => 'unique',
559
+ ),
560
+ )
561
+ ),
562
+
563
+ 'youtube_video' => array(
564
+ 'name' => 'YouTube Video',
565
+ 'col1' => array('_title','_metakey','_help','_visibility'),
566
+ 'col2' => array('_label','_placeholder','_public','_roles','_validate','_custom_validate'),
567
+ 'col3' => array('_required','_editable','_icon'),
568
+ 'validate' => array(
569
+ '_title' => array(
570
+ 'mode' => 'required',
571
+ 'error' => __('You must provide a title','ultimate-member')
572
+ ),
573
+ '_metakey' => array(
574
+ 'mode' => 'unique',
575
+ ),
576
+ )
577
+ ),
578
+
579
+ 'vimeo_video' => array(
580
+ 'name' => 'Vimeo Video',
581
+ 'col1' => array('_title','_metakey','_help','_visibility'),
582
+ 'col2' => array('_label','_placeholder','_public','_roles','_validate','_custom_validate'),
583
+ 'col3' => array('_required','_editable','_icon'),
584
+ 'validate' => array(
585
+ '_title' => array(
586
+ 'mode' => 'required',
587
+ 'error' => __('You must provide a title','ultimate-member')
588
+ ),
589
+ '_metakey' => array(
590
+ 'mode' => 'unique',
591
+ ),
592
+ )
593
+ ),
594
+
595
+ 'soundcloud_track' => array(
596
+ 'name' => 'SoundCloud Track',
597
+ 'col1' => array('_title','_metakey','_help','_visibility'),
598
+ 'col2' => array('_label','_placeholder','_public','_roles','_validate','_custom_validate'),
599
+ 'col3' => array('_required','_editable','_icon'),
600
+ 'validate' => array(
601
+ '_title' => array(
602
+ 'mode' => 'required',
603
+ 'error' => __('You must provide a title','ultimate-member')
604
+ ),
605
+ '_metakey' => array(
606
+ 'mode' => 'unique',
607
+ ),
608
+ )
609
+ ),
610
+
611
+ /*'group' => array(
612
+ 'name' => 'Field Group',
613
+ 'col1' => array('_title','_max_entries'),
614
+ 'col2' => array('_label','_public','_roles'),
615
+ 'form_only' => true,
616
+ 'validate' => array(
617
+ '_title' => array(
618
+ 'mode' => 'required',
619
+ 'error' => 'You must provide a title'
620
+ ),
621
+ '_label' => array(
622
+ 'mode' => 'required',
623
+ 'error' => 'You must provide a label'
624
+ ),
625
+ )
626
+ ),*/
627
+
628
+ );
629
+
630
+ /**
631
+ * UM hook
632
+ *
633
+ * @type filter
634
+ * @title um_core_fields_hook
635
+ * @description UM Core Fields
636
+ * @input_vars
637
+ * [{"var":"$core_fields","type":"array","desc":"Core Fields"}]
638
+ * @change_log
639
+ * ["Since: 2.0"]
640
+ * @usage add_filter( 'um_core_fields_hook', 'function_name', 10, 1 );
641
+ * @example
642
+ * <?php
643
+ * add_filter( 'um_core_fields_hook', 'my_core_fields', 10, 1 );
644
+ * function my_core_fields( $core_fields ) {
645
+ * // your code here
646
+ * return $core_fields;
647
+ * }
648
+ * ?>
649
+ */
650
+ $this->core_fields = apply_filters( 'um_core_fields_hook', $this->core_fields );
651
+ }
652
+
653
+
654
+ /**
655
+ * Predefined Fields
656
+ */
657
+ function set_predefined_fields() {
658
+ global $wp_roles;
659
+
660
+ $um_roles = array();
661
+ if ( ! empty( $wp_roles->roles ) ) {
662
+ $role_keys = get_option( 'um_roles', array() );
663
+ if ( ! empty( $role_keys ) && is_array( $role_keys ) ) {
664
+ $role_keys = array_map( function( $item ) {
665
+ return 'um_' . $item;
666
+ }, $role_keys );
667
+ } else {
668
+ $role_keys = array();
669
+ }
670
+
671
+ $exclude_roles = array_diff( array_keys( $wp_roles->roles ), array_merge( $role_keys, array( 'subscriber' ) ) );
672
+ $um_roles = UM()->roles()->get_roles( false, $exclude_roles );
673
+ }
674
+
675
+ /**
676
+ * UM hook
677
+ *
678
+ * @type filter
679
+ * @title um_profile_privacy_options
680
+ * @description Profile Privacy Options
681
+ * @input_vars
682
+ * [{"var":"$privacy_options","type":"array","desc":"Privacy Options"}]
683
+ * @change_log
684
+ * ["Since: 2.0"]
685
+ * @usage add_filter( 'um_profile_privacy_options', 'function_name', 10, 1 );
686
+ * @example
687
+ * <?php
688
+ * add_filter( 'um_profile_privacy_options', 'my_profile_privacy_options', 10, 1 );
689
+ * function my_profile_privacy_options( $privacy_options ) {
690
+ * // your code here
691
+ * return $privacy_options;
692
+ * }
693
+ * ?>
694
+ */
695
+ $profile_privacy = apply_filters( 'um_profile_privacy_options', array(
696
+ 'Everyone' => __( 'Everyone', 'ultimate-member' ),
697
+ 'Only me' => __( 'Only me', 'ultimate-member' )
698
+ ) );
699
+
700
+ /*
701
+ * it's important create key for array equals value of 'metakey'.
702
+ *
703
+ */
704
+
705
+ $this->predefined_fields = array(
706
+
707
+ 'user_login' => array(
708
+ 'title' => __('Username','ultimate-member'),
709
+ 'metakey' => 'user_login',
710
+ 'type' => 'text',
711
+ 'label' => __('Username','ultimate-member'),
712
+ 'required' => 1,
713
+ 'public' => 1,
714
+ 'editable' => 0,
715
+ 'validate' => 'unique_username',
716
+ 'min_chars' => 3,
717
+ 'max_chars' => 24
718
+ ),
719
+
720
+ 'username' => array(
721
+ 'title' => __('Username or E-mail','ultimate-member'),
722
+ 'metakey' => 'username',
723
+ 'type' => 'text',
724
+ 'label' => __('Username or E-mail','ultimate-member'),
725
+ 'required' => 1,
726
+ 'public' => 1,
727
+ 'editable' => 0,
728
+ 'validate' => 'unique_username_or_email',
729
+ ),
730
+
731
+ 'user_password' => array(
732
+ 'title' => __('Password','ultimate-member'),
733
+ 'metakey' => 'user_password',
734
+ 'type' => 'password',
735
+ 'label' => __('Password','ultimate-member'),
736
+ 'required' => 1,
737
+ 'public' => 1,
738
+ 'editable' => 1,
739
+ 'min_chars' => 8,
740
+ 'max_chars' => 30,
741
+ 'force_good_pass' => 1,
742
+ 'force_confirm_pass' => 1,
743
+ 'label_confirm_pass' => __('Confirm Password','ultimate-member')
744
+ ),
745
+
746
+ 'first_name' => array(
747
+ 'title' => __('First Name','ultimate-member'),
748
+ 'metakey' => 'first_name',
749
+ 'type' => 'text',
750
+ 'label' => __('First Name','ultimate-member'),
751
+ 'required' => 0,
752
+ 'public' => 1,
753
+ 'editable' => 1,
754
+ ),
755
+
756
+ 'last_name' => array(
757
+ 'title' => __('Last Name','ultimate-member'),
758
+ 'metakey' => 'last_name',
759
+ 'type' => 'text',
760
+ 'label' => __('Last Name','ultimate-member'),
761
+ 'required' => 0,
762
+ 'public' => 1,
763
+ 'editable' => 1,
764
+ ),
765
+
766
+ 'nickname' => array(
767
+ 'title' => __('Nickname','ultimate-member'),
768
+ 'metakey' => 'nickname',
769
+ 'type' => 'text',
770
+ 'label' => __('Nickname','ultimate-member'),
771
+ 'required' => 0,
772
+ 'public' => 1,
773
+ 'editable' => 1,
774
+ ),
775
+
776
+ 'user_url' => array(
777
+ 'title' => __('Website URL','ultimate-member'),
778
+ 'metakey' => 'user_url',
779
+ 'type' => 'url',
780
+ 'label' => __('Website URL','ultimate-member'),
781
+ 'required' => 1,
782
+ 'public' => 1,
783
+ 'editable' => 1,
784
+ 'validate' => 'url'
785
+ ),
786
+
787
+ 'user_registered' => array(
788
+ 'title' => __('Registration Date','ultimate-member'),
789
+ 'metakey' => 'user_registered',
790
+ 'type' => 'text',
791
+ 'label' => __('Registration Date','ultimate-member'),
792
+ 'required' => 0,
793
+ 'public' => 1,
794
+ 'editable' => 1,
795
+ 'edit_forbidden' => 1,
796
+ ),
797
+
798
+ '_um_last_login' => array(
799
+ 'title' => __('Last Login','ultimate-member'),
800
+ 'metakey' => '_um_last_login',
801
+ 'type' => 'text',
802
+ 'label' => __('Last Login','ultimate-member'),
803
+ 'required' => 0,
804
+ 'public' => 1,
805
+ 'editable' => 1,
806
+ 'edit_forbidden' => 1,
807
+ ),
808
+
809
+ 'user_email' => array(
810
+ 'title' => __('E-mail Address','ultimate-member'),
811
+ 'metakey' => 'user_email',
812
+ 'type' => 'text',
813
+ 'label' => __('E-mail Address','ultimate-member'),
814
+ 'required' => 0,
815
+ 'public' => 1,
816
+ 'validate' => 'unique_email',
817
+ 'autocomplete' => 'off'
818
+ ),
819
+
820
+ 'secondary_user_email' => array(
821
+ 'title' => __('Secondary E-mail Address','ultimate-member'),
822
+ 'metakey' => 'secondary_user_email',
823
+ 'type' => 'text',
824
+ 'label' => __('Secondary E-mail Address','ultimate-member'),
825
+ 'required' => 0,
826
+ 'public' => 1,
827
+ 'editable' => 1,
828
+ 'validate' => 'unique_email',
829
+ 'autocomplete' => 'off'
830
+ ),
831
+
832
+ 'description' => array(
833
+ 'title' => __('Biography','ultimate-member'),
834
+ 'metakey' => 'description',
835
+ 'type' => 'textarea',
836
+ 'label' => __('Biography','ultimate-member'),
837
+ 'html' => 0,
838
+ 'required' => 0,
839
+ 'public' => 1,
840
+ 'editable' => 1,
841
+ 'max_words' => 40,
842
+ 'placeholder' => __('Enter a bit about yourself...','ultimate-member'),
843
+ ),
844
+
845
+ 'birth_date' => array(
846
+ 'title' => __('Birth Date','ultimate-member'),
847
+ 'metakey' => 'birth_date',
848
+ 'type' => 'date',
849
+ 'label' => __('Birth Date','ultimate-member'),
850
+ 'required' => 0,
851
+ 'public' => 1,
852
+ 'editable' => 1,
853
+ 'pretty_format' => 1,
854
+ 'years' => 115,
855
+ 'years_x' => 'past',
856
+ 'icon' => 'um-faicon-calendar'
857
+ ),
858
+
859
+ 'gender' => array(
860
+ 'title' => __('Gender','ultimate-member'),
861
+ 'metakey' => 'gender',
862
+ 'type' => 'radio',
863
+ 'label' => __('Gender','ultimate-member'),
864
+ 'required' => 0,
865
+ 'public' => 1,
866
+ 'editable' => 1,
867
+ 'options' => array( __('Male','ultimate-member'), __('Female','ultimate-member') )
868
+ ),
869
+
870
+ 'country' => array(
871
+ 'title' => __('Country','ultimate-member'),
872
+ 'metakey' => 'country',
873
+ 'type' => 'select',
874
+ 'label' => __('Country','ultimate-member'),
875
+ 'placeholder' => __('Choose a Country','ultimate-member'),
876
+ 'required' => 0,
877
+ 'public' => 1,
878
+ 'editable' => 1,
879
+ 'options' => $this->get('countries')
880
+ ),
881
+
882
+ 'facebook' => array(
883
+ 'title' => __('Facebook','ultimate-member'),
884
+ 'metakey' => 'facebook',
885
+ 'type' => 'url',
886
+ 'label' => __('Facebook','ultimate-member'),
887
+ 'required' => 0,
888
+ 'public' => 1,
889
+ 'editable' => 1,
890
+ 'url_target' => '_blank',
891
+ 'url_rel' => 'nofollow',
892
+ 'icon' => 'um-faicon-facebook',
893
+ 'validate' => 'facebook_url',
894
+ 'url_text' => 'Facebook',
895
+ 'advanced' => 'social',
896
+ 'color' => '#3B5999',
897
+ 'match' => 'https://facebook.com/',
898
+ ),
899
+
900
+ 'twitter' => array(
901
+ 'title' => __('Twitter','ultimate-member'),
902
+ 'metakey' => 'twitter',
903
+ 'type' => 'url',
904
+ 'label' => __('Twitter','ultimate-member'),
905
+ 'required' => 0,
906
+ 'public' => 1,
907
+ 'editable' => 1,
908
+ 'url_target' => '_blank',
909
+ 'url_rel' => 'nofollow',
910
+ 'icon' => 'um-faicon-twitter',
911
+ 'validate' => 'twitter_url',
912
+ 'url_text' => 'Twitter',
913
+ 'advanced' => 'social',
914
+ 'color' => '#4099FF',
915
+ 'match' => 'https://twitter.com/',
916
+ ),
917
+
918
+ 'linkedin' => array(
919
+ 'title' => __('LinkedIn','ultimate-member'),
920
+ 'metakey' => 'linkedin',
921
+ 'type' => 'url',
922
+ 'label' => __('LinkedIn','ultimate-member'),
923
+ 'required' => 0,
924
+ 'public' => 1,
925
+ 'editable' => 1,
926
+ 'url_target' => '_blank',
927
+ 'url_rel' => 'nofollow',
928
+ 'icon' => 'um-faicon-linkedin',
929
+ 'validate' => 'linkedin_url',
930
+ 'url_text' => 'LinkedIn',
931
+ 'advanced' => 'social',
932
+ 'color' => '#0976b4',
933
+ 'match' => 'https://linkedin.com/',
934
+ ),
935
+
936
+ 'googleplus' => array(
937
+ 'title' => __('Google+','ultimate-member'),
938
+ 'metakey' => 'googleplus',
939
+ 'type' => 'url',
940
+ 'label' => __('Google+','ultimate-member'),
941
+ 'required' => 0,
942
+ 'public' => 1,
943
+ 'editable' => 1,
944
+ 'url_target' => '_blank',
945
+ 'url_rel' => 'nofollow',
946
+ 'icon' => 'um-faicon-google-plus',
947
+ 'validate' => 'google_url',
948
+ 'url_text' => 'Google+',
949
+ 'advanced' => 'social',
950
+ 'color' => '#dd4b39',
951
+ 'match' => 'https://google.com/+',
952
+ ),
953
+
954
+ 'instagram' => array(
955
+ 'title' => __('Instagram','ultimate-member'),
956
+ 'metakey' => 'instagram',
957
+ 'type' => 'url',
958
+ 'label' => __('Instagram','ultimate-member'),
959
+ 'required' => 0,
960
+ 'public' => 1,
961
+ 'editable' => 1,
962
+ 'url_target' => '_blank',
963
+ 'url_rel' => 'nofollow',
964
+ 'icon' => 'um-faicon-instagram',
965
+ 'validate' => 'instagram_url',
966
+ 'url_text' => 'Instagram',
967
+ 'advanced' => 'social',
968
+ 'color' => 'radial-gradient(circle at 30% 107%, #fdf497 0%, #fdf497 5%, #fd5949 45%,#d6249f 60%,#285AEB 90%)',
969
+ 'match' => 'https://instagram.com/',
970
+ ),
971
+
972
+ 'skype' => array(
973
+ 'title' => __('Skype ID','ultimate-member'),
974
+ 'metakey' => 'skype',
975
+ 'type' => 'text',
976
+ 'label' => __('Skype ID','ultimate-member'),
977
+ 'required' => 0,
978
+ 'public' => 1,
979
+ 'editable' => 1,
980
+ 'url_target' => '_blank',
981
+ 'url_rel' => 'nofollow',
982
+ 'icon' => 'um-faicon-skype',
983
+ 'validate' => 'skype',
984
+ 'url_text' => __( 'Join chat', 'ultimate-member' ),
985
+ ),
986
+
987
+ 'viber' => array(
988
+ 'title' => __('Viber number','ultimate-member'),
989
+ 'metakey' => 'viber',
990
+ 'type' => 'text',
991
+ 'label' => __('Viber number','ultimate-member'),
992
+ 'required' => 0,
993
+ 'public' => 1,
994
+ 'editable' => 1,
995
+ 'url_target' => '_blank',
996
+ 'url_rel' => 'nofollow',
997
+ 'icon' => 'um-icon-ios-telephone',
998
+ 'validate' => 'phone_number',
999
+ ),
1000
+
1001
+ 'whatsapp' => array(
1002
+ 'title' => __('WhatsApp number','ultimate-member'),
1003
+ 'metakey' => 'whatsapp',
1004
+ 'type' => 'text',
1005
+ 'label' => __('WhatsApp number','ultimate-member'),
1006
+ 'required' => 0,
1007
+ 'public' => 1,
1008
+ 'editable' => 1,
1009
+ 'url_target' => '_blank',
1010
+ 'url_rel' => 'nofollow',
1011
+ 'icon' => 'um-icon-social-whatsapp',
1012
+ 'validate' => 'phone_number',
1013
+ ),
1014
+
1015
+ 'telegram' => array(
1016
+ 'title' => __('Telegram','ultimate-member'),
1017
+ 'metakey' => 'telegram',
1018
+ 'type' => 'url',
1019
+ 'label' => __('Telegram','ultimate-member'),
1020
+ 'required' => 0,
1021
+ 'public' => 1,
1022
+ 'editable' => 1,
1023
+ 'url_target' => '_blank',
1024
+ 'url_rel' => 'nofollow',
1025
+ 'icon' => 'um-faicon-paper-plane',
1026
+ 'validate' => 'telegram_url',
1027
+ 'url_text' => 'Telegram',
1028
+ 'match' => 'https://t.me/',
1029
+ ),
1030
+
1031
+ 'discord' => array(
1032
+ 'title' => __('Discord','ultimate-member'),
1033
+ 'metakey' => 'discord',
1034
+ 'type' => 'text',
1035
+ 'label' => __('Discord ID','ultimate-member'),
1036
+ 'required' => 0,
1037
+ 'public' => 1,
1038
+ 'editable' => 1,
1039
+ 'url_target' => '_blank',
1040
+ 'url_rel' => 'nofollow',
1041
+ 'validate' => 'discord',
1042
+ ),
1043
+
1044
+ 'youtube' => array(
1045
+ 'title' => __('YouTube','ultimate-member'),
1046
+ 'metakey' => 'youtube',
1047
+ 'type' => 'url',
1048
+ 'label' => __('YouTube','ultimate-member'),
1049
+ 'required' => 0,
1050
+ 'public' => 1,
1051
+ 'editable' => 1,
1052
+ 'url_target' => '_blank',
1053
+ 'url_rel' => 'nofollow',
1054
+ 'icon' => 'um-faicon-youtube',
1055
+ 'validate' => 'youtube_url',
1056
+ 'url_text' => 'YouTube',
1057
+ 'advanced' => 'social',
1058
+ 'color' => '#e52d27',
1059
+ 'match' => 'https://youtube.com/',
1060
+ ),
1061
+
1062
+ 'soundcloud' => array(
1063
+ 'title' => __( 'SoundCloud', 'ultimate-member' ),
1064
+ 'metakey' => 'soundcloud',
1065
+ 'type' => 'url',
1066
+ 'label' => __( 'SoundCloud', 'ultimate-member' ),
1067
+ 'required' => 0,
1068
+ 'public' => 1,
1069
+ 'editable' => 1,
1070
+ 'url_target' => '_blank',
1071
+ 'url_rel' => 'nofollow',
1072
+ 'icon' => 'um-faicon-soundcloud',
1073
+ 'validate' => 'soundcloud_url',
1074
+ 'url_text' => 'SoundCloud',
1075
+ 'advanced' => 'social',
1076
+ 'color' => '#f50',
1077
+ 'match' => 'https://soundcloud.com/',
1078
+ ),
1079
+
1080
+ 'vkontakte' => array(
1081
+ 'title' => __('VKontakte','ultimate-member'),
1082
+ 'metakey' => 'vkontakte',
1083
+ 'type' => 'url',
1084
+ 'label' => __('VKontakte','ultimate-member'),
1085
+ 'required' => 0,
1086
+ 'public' => 1,
1087
+ 'editable' => 1,
1088
+ 'url_target' => '_blank',
1089
+ 'url_rel' => 'nofollow',
1090
+ 'icon' => 'um-faicon-vk',
1091
+ 'validate' => 'vk_url',
1092
+ 'url_text' => 'VKontakte',
1093
+ 'advanced' => 'social',
1094
+ 'color' => '#2B587A',
1095
+ 'match' => 'https://vk.com/',
1096
+ ),
1097
+
1098
+ 'role_select' => array(
1099
+ 'title' => __('Roles (Dropdown)','ultimate-member'),
1100
+ 'metakey' => 'role_select',
1101
+ 'type' => 'select',
1102
+ 'label' => __('Account Type','ultimate-member'),
1103
+ 'placeholder' => 'Choose account type',
1104
+ 'required' => 0,
1105
+ 'public' => 1,
1106
+ 'editable' => 1,
1107
+ 'options' => $um_roles,
1108
+ ),
1109
+
1110
+ 'role_radio' => array(
1111
+ 'title' => __('Roles (Radio)','ultimate-member'),
1112
+ 'metakey' => 'role_radio',
1113
+ 'type' => 'radio',
1114
+ 'label' => __('Account Type','ultimate-member'),
1115
+ 'required' => 0,
1116
+ 'public' => 1,
1117
+ 'editable' => 1,
1118
+ 'options' => $um_roles,
1119
+ ),
1120
+
1121
+ 'languages' => array(
1122
+ 'title' => __('Languages','ultimate-member'),
1123
+ 'metakey' => 'languages',
1124
+ 'type' => 'multiselect',
1125
+ 'label' => __('Languages Spoken','ultimate-member'),
1126
+ 'placeholder' => __('Select languages','ultimate-member'),
1127
+ 'required' => 0,
1128
+ 'public' => 1,
1129
+ 'editable' => 1,
1130
+ 'options' => $this->get('languages'),
1131
+ ),
1132
+
1133
+ 'phone_number' => array(
1134
+ 'title' => __('Phone Number','ultimate-member'),
1135
+ 'metakey' => 'phone_number',
1136
+ 'type' => 'text',
1137
+ 'label' => __('Phone Number','ultimate-member'),
1138
+ 'required' => 0,
1139
+ 'public' => 1,
1140
+ 'editable' => 1,
1141
+ 'validate' => 'phone_number',
1142
+ 'icon' => 'um-faicon-phone',
1143
+ ),
1144
+
1145
+ 'mobile_number' => array(
1146
+ 'title' => __('Mobile Number','ultimate-member'),
1147
+ 'metakey' => 'mobile_number',
1148
+ 'type' => 'text',
1149
+ 'label' => __('Mobile Number','ultimate-member'),
1150
+ 'required' => 0,
1151
+ 'public' => 1,
1152
+ 'editable' => 1,
1153
+ 'validate' => 'phone_number',
1154
+ 'icon' => 'um-faicon-mobile',
1155
+ ),
1156
+
1157
+ // private use ( not public list )
1158
+
1159
+ 'profile_photo' => array(
1160
+ 'title' => __('Profile Photo','ultimate-member'),
1161
+ 'metakey' => 'profile_photo',
1162
+ 'type' => 'image',
1163
+ 'label' => __('Change your profile photo','ultimate-member'),
1164
+ 'upload_text' => __('Upload your photo here','ultimate-member'),
1165
+ 'icon' => 'um-faicon-camera',
1166
+ 'crop' => 1,
1167
+ 'max_size' => ( UM()->options()->get('profile_photo_max_size') ) ? UM()->options()->get('profile_photo_max_size') : 999999999,
1168
+ 'min_width' => str_replace('px','',UM()->options()->get('profile_photosize')),
1169
+ 'min_height' => str_replace('px','',UM()->options()->get('profile_photosize')),
1170
+ 'private_use' => true,
1171
+ ),
1172
+
1173
+ 'cover_photo' => array(
1174
+ 'title' => __('Cover Photo','ultimate-member'),
1175
+ 'metakey' => 'cover_photo',
1176
+ 'type' => 'image',
1177
+ 'label' => __('Change your cover photo','ultimate-member'),
1178
+ 'upload_text' => __('Upload profile cover here','ultimate-member'),
1179
+ 'icon' => 'um-faicon-picture-o',
1180
+ 'crop' => 2,
1181
+ 'max_size' => ( UM()->options()->get('cover_photo_max_size') ) ? UM()->options()->get('cover_photo_max_size') : 999999999,
1182
+ 'modal_size' => 'large',
1183
+ 'ratio' => str_replace(':1','',UM()->options()->get('profile_cover_ratio')),
1184
+ 'min_width' => UM()->options()->get('cover_min_width'),
1185
+ 'private_use' => true,
1186
+ ),
1187
+
1188
+ 'username_b' => array(
1189
+ 'title' => __('Username or E-mail','ultimate-member'),
1190
+ 'metakey' => 'username_b',
1191
+ 'type' => 'text',
1192
+ 'placeholder' => __('Enter your username or email','ultimate-member'),
1193
+ 'required' => 1,
1194
+ 'public' => 1,
1195
+ 'editable' => 0,
1196
+ 'private_use' => true,
1197
+ ),
1198
+
1199
+ // account page use ( not public )
1200
+
1201
+ 'profile_privacy' => array(
1202
+ 'title' => __( 'Profile Privacy', 'ultimate-member' ),
1203
+ 'metakey' => 'profile_privacy',
1204
+ 'type' => 'select',
1205
+ 'label' => __( 'Profile Privacy', 'ultimate-member' ),
1206
+ 'help' => __( 'Who can see your public profile?', 'ultimate-member' ),
1207
+ 'required' => 0,
1208
+ 'public' => 1,
1209
+ 'editable' => 1,
1210
+ 'default' => 'Everyone',
1211
+ 'options' => $profile_privacy,
1212
+ 'allowclear' => 0,
1213
+ 'account_only' => true,
1214
+ 'required_perm' => 'can_make_private_profile',
1215
+ ),
1216
+
1217
+ 'profile_noindex' => array(
1218
+ 'title' => __( 'Avoid indexing my profile by search engines', 'ultimate-member' ),
1219
+ 'metakey' => 'profile_noindex',
1220
+ 'type' => 'select',
1221
+ 'label' => __( 'Avoid indexing my profile by search engines', 'ultimate-member' ),
1222
+ 'help' => __( 'Hide my profile for robots?', 'ultimate-member' ),
1223
+ 'required' => 0,
1224
+ 'public' => 1,
1225
+ 'editable' => 1,
1226
+ 'default' => UM()->roles()->um_user_can( 'profile_noindex' ) ? '1' : '0',
1227
+ 'options' => array(
1228
+ '0' => __( 'No', 'ultimate-member' ),
1229
+ '1' => __( 'Yes', 'ultimate-member' ),
1230
+ ),
1231
+ 'allowclear' => 0,
1232
+ 'account_only' => true,
1233
+ 'required_perm' => 'can_make_private_profile',
1234
+ ),
1235
+
1236
+ 'hide_in_members' => array(
1237
+ 'title' => __( 'Hide my profile from directory', 'ultimate-member' ),
1238
+ 'metakey' => 'hide_in_members',
1239
+ 'type' => 'radio',
1240
+ 'label' => __( 'Hide my profile from directory', 'ultimate-member' ),
1241
+ 'help' => __( 'Here you can hide yourself from appearing in public directory', 'ultimate-member' ),
1242
+ 'required' => 0,
1243
+ 'public' => 1,
1244
+ 'editable' => 1,
1245
+ 'default' => UM()->member_directory()->get_hide_in_members_default() ? 'Yes' : 'No',
1246
+ 'options' => array(
1247
+ 'No' => __( 'No', 'ultimate-member' ),
1248
+ 'Yes' => __( 'Yes', 'ultimate-member' ),
1249
+ ),
1250
+ 'account_only' => true,
1251
+ 'required_opt' => array( 'members_page', 1 ),
1252
+ ),
1253
+
1254
+ 'delete_account' => array(
1255
+ 'title' => __( 'Delete Account', 'ultimate-member' ),
1256
+ 'metakey' => 'delete_account',
1257
+ 'type' => 'radio',
1258
+ 'label' => __( 'Delete Account', 'ultimate-member'),
1259
+ 'help' => __( 'If you confirm, everything related to your profile will be deleted permanently from the site', 'ultimate-member' ),
1260
+ 'required' => 0,
1261
+ 'public' => 1,
1262
+ 'editable' => 1,
1263
+ 'default' => __( 'No', 'ultimate-member' ),
1264
+ 'options' => array(
1265
+ __( 'Yes', 'ultimate-member' ),
1266
+ __( 'No', 'ultimate-member' )
1267
+ ),
1268
+ 'account_only' => true,
1269
+ ),
1270
+
1271
+ 'single_user_password' => array(
1272
+ 'title' => __( 'Password', 'ultimate-member' ),
1273
+ 'metakey' => 'single_user_password',
1274
+ 'type' => 'password',
1275
+ 'label' => __( 'Password', 'ultimate-member' ),
1276
+ 'required' => 1,
1277
+ 'public' => 1,
1278
+ 'editable' => 1,
1279
+ 'account_only' => true,
1280
+ ),
1281
+
1282
+ );
1283
+
1284
+ /**
1285
+ * UM hook
1286
+ *
1287
+ * @type filter
1288
+ * @title um_predefined_fields_hook
1289
+ * @description Extend Predefined Fields
1290
+ * @input_vars
1291
+ * [{"var":"$predefined_fields","type":"array","desc":"Predefined Fields"}]
1292
+ * @change_log
1293
+ * ["Since: 2.0"]
1294
+ * @usage add_filter( 'um_predefined_fields_hook', 'function_name', 10, 1 );
1295
+ * @example
1296
+ * <?php
1297
+ * add_filter( 'um_predefined_fields_hook', 'my_predefined_fields', 10, 1 );
1298
+ * function my_predefined_fields( $predefined_fields ) {
1299
+ * // your code here
1300
+ * return $predefined_fields;
1301
+ * }
1302
+ * ?>
1303
+ */
1304
+ $this->predefined_fields = apply_filters( 'um_predefined_fields_hook', $this->predefined_fields );
1305
+ }
1306
+
1307
+
1308
+ /**
1309
+ * Custom Fields
1310
+ */
1311
+ function set_custom_fields() {
1312
+
1313
+ if ( is_array( $this->saved_fields ) ) {
1314
+
1315
+ $this->custom_fields = $this->saved_fields;
1316
+
1317
+ } else {
1318
+
1319
+ $this->custom_fields = '';
1320
+
1321
+ }
1322
+
1323
+ $custom = $this->custom_fields;
1324
+ $predefined = $this->predefined_fields;
1325
+
1326
+ if ( is_array( $custom ) ){
1327
+ $this->all_user_fields = array_merge( $predefined, $custom );
1328
+ } else {
1329
+ $this->all_user_fields = $predefined;
1330
+ }
1331
+
1332
+ }
1333
+
1334
+
1335
+ /**
1336
+ * Get all fields without metakeys
1337
+ *
1338
+ * @since 2.0.56
1339
+ *
1340
+ * @return array
1341
+ */
1342
+ function get_fields_without_metakey() {
1343
+ $fields_without_metakey = array(
1344
+ 'block',
1345
+ 'shortcode',
1346
+ 'spacing',
1347
+ 'divider',
1348
+ 'group'
1349
+ );
1350
+
1351
+
1352
+ /**
1353
+ * UM hook
1354
+ *
1355
+ * @type filter
1356
+ * @title um_fields_without_metakey
1357
+ * @description Field Types without meta key
1358
+ * @input_vars
1359
+ * [{"var":"$types","type":"array","desc":"Field Types"}]
1360
+ * @change_log
1361
+ * ["Since: 2.0"]
1362
+ * @usage add_filter( 'um_fields_without_metakey', 'function_name', 10, 1 );
1363
+ * @example
1364
+ * <?php
1365
+ * add_filter( 'um_fields_without_metakey', 'my_fields_without_metakey', 10, 1 );
1366
+ * function my_fields_without_metakey( $types ) {
1367
+ * // your code here
1368
+ * return $types;
1369
+ * }
1370
+ * ?>
1371
+ */
1372
+ return apply_filters( 'um_fields_without_metakey', $fields_without_metakey );
1373
+ }
1374
+
1375
+
1376
+ /**
1377
+ * May be used to show a dropdown, or source for user meta
1378
+ *
1379
+ * @param null $exclude_types
1380
+ * @param bool $show_all
1381
+ *
1382
+ * @return array
1383
+ */
1384
+ function all_user_fields( $exclude_types = null, $show_all = false ) {
1385
+
1386
+ $fields_without_metakey = $this->get_fields_without_metakey();
1387
+ $fields_without_metakey = apply_filters( 'um_all_user_fields_without_metakey', $fields_without_metakey );
1388
+
1389
+ if ( ! $show_all ) {
1390
+ $this->fields_dropdown = array( 'image', 'file', 'password', 'rating' );
1391
+ $this->fields_dropdown = array_merge( $this->fields_dropdown, $fields_without_metakey );
1392
+ } else {
1393
+ $this->fields_dropdown = $fields_without_metakey;
1394
+ }
1395
+
1396
+ $custom = $this->custom_fields;
1397
+ $predefined = $this->predefined_fields;
1398
+
1399
+ if ( $exclude_types ) {
1400
+ $exclude_types = explode( ',', $exclude_types );
1401
+ }
1402
+
1403
+ $all = array( 0 => '' );
1404
+
1405
+ if ( is_array( $custom ) ) {
1406
+ $all = $all + array_merge( $predefined, $custom );
1407
+ } else {
1408
+ $all = $all + $predefined;
1409
+ }
1410
+
1411
+ foreach ( $all as $k => $arr ) {
1412
+
1413
+ if ( $k == 0 ) {
1414
+ unset( $all[ $k ] );
1415
+ }
1416
+
1417
+ if ( isset( $arr['title'] ) ) {
1418
+ $all[ $k ]['title'] = stripslashes( $arr['title'] );
1419
+ }
1420
+
1421
+ if ( $exclude_types && isset( $arr['type'] ) && in_array( $arr['type'], $exclude_types ) ) {
1422
+ unset( $all[ $k ] );
1423
+ }
1424
+ if ( isset( $arr['account_only'] ) || isset( $arr['private_use'] ) ) {
1425
+ if ( ! $show_all ) {
1426
+ unset( $all[ $k ] );
1427
+ }
1428
+ }
1429
+ if ( isset( $arr['type'] ) && in_array( $arr['type'], $this->fields_dropdown ) ) {
1430
+ unset( $all[ $k ] );
1431
+ }
1432
+ }
1433
+
1434
+ $all = UM()->fields()->array_sort_by_column( $all, 'title' );
1435
+
1436
+ return $all;
1437
+ }
1438
+
1439
+
1440
+ /**
1441
+ * Possible validation types for fields
1442
+ *
1443
+ * @return mixed
1444
+ */
1445
+ function validation_types() {
1446
+
1447
+ $array[0] = __('None','ultimate-member');
1448
+ $array['alphabetic'] = __('Alphabetic value only','ultimate-member');
1449
+ $array['alpha_numeric'] = __('Alpha-numeric value','ultimate-member');
1450
+ $array['english'] = __('English letters only','ultimate-member');
1451
+ $array['facebook_url'] = __('Facebook URL','ultimate-member');
1452
+ $array['google_url'] = __('Google+ URL','ultimate-member');
1453
+ $array['instagram_url'] = __('Instagram URL','ultimate-member');
1454
+ $array['linkedin_url'] = __('LinkedIn URL','ultimate-member');
1455
+ $array['vk_url'] = __('VKontakte URL','ultimate-member');
1456
+ $array['lowercase'] = __('Lowercase only','ultimate-member');
1457
+ $array['numeric'] = __('Numeric value only','ultimate-member');
1458
+ $array['phone_number'] = __('Phone Number','ultimate-member');
1459
+ $array['skype'] = __('Skype ID','ultimate-member');
1460
+ $array['soundcloud'] = __( 'SoundCloud Profile', 'ultimate-member' );
1461
+ $array['twitter_url'] = __('Twitter URL','ultimate-member');
1462
+ $array['is_email'] = __('E-mail( Not Unique )','ultimate-member');
1463
+ $array['unique_email'] = __('Unique E-mail','ultimate-member');
1464
+ $array['unique_value'] = __('Unique Metakey value','ultimate-member');
1465
+ $array['unique_username'] = __('Unique Username','ultimate-member');
1466
+ $array['unique_username_or_email'] = __('Unique Username/E-mail','ultimate-member');
1467
+ $array['url'] = __('Website URL','ultimate-member');
1468
+ $array['youtube_url'] = __('YouTube Profile','ultimate-member');
1469
+ $array['telegram_url'] = __('Telegram URL','ultimate-member');
1470
+ $array['discord'] = __('Discord ID','ultimate-member');
1471
+ $array['custom'] = __('Custom Validation','ultimate-member');
1472
+
1473
+ /**
1474
+ * UM hook
1475
+ *
1476
+ * @type filter
1477
+ * @title um_admin_field_validation_hook
1478
+ * @description Extend validation types
1479
+ * @input_vars
1480
+ * [{"var":"$types","type":"array","desc":"Validation Types"}]
1481
+ * @change_log
1482
+ * ["Since: 2.0"]
1483
+ * @usage add_filter( 'um_admin_field_validation_hook', 'function_name', 10, 1 );
1484
+ * @example
1485
+ * <?php
1486
+ * add_filter( 'um_admin_field_validation_hook', 'my_admin_field_validation', 10, 1 );
1487
+ * function my_admin_field_validation( $types ) {
1488
+ * // your code here
1489
+ * return $types;
1490
+ * }
1491
+ * ?>
1492
+ */
1493
+ $array = apply_filters( 'um_admin_field_validation_hook', $array );
1494
+ return $array;
1495
+ }
1496
+
1497
+
1498
+ /**
1499
+ * Get predefined options
1500
+ *
1501
+ * @param $data
1502
+ *
1503
+ * @return array|mixed|void
1504
+ */
1505
+ function get( $data ) {
1506
+ switch ( $data ) {
1507
+
1508
+ case 'languages':
1509
+ $array = array(
1510
+ "aa" => __("Afar",'ultimate-member'),
1511
+ "ab" => __("Abkhazian",'ultimate-member'),
1512
+ "ae" => __("Avestan",'ultimate-member'),
1513
+ "af" => __("Afrikaans",'ultimate-member'),
1514
+ "ak" => __("Akan",'ultimate-member'),
1515
+ "am" => __("Amharic",'ultimate-member'),
1516
+ "an" => __("Aragonese",'ultimate-member'),
1517
+ "ar" => __("Arabic",'ultimate-member'),
1518
+ "as" => __("Assamese",'ultimate-member'),
1519
+ "av" => __("Avaric",'ultimate-member'),
1520
+ "ay" => __("Aymara",'ultimate-member'),
1521
+ "az" => __("Azerbaijani",'ultimate-member'),
1522
+ "ba" => __("Bashkir",'ultimate-member'),
1523
+ "be" => __("Belarusian",'ultimate-member'),
1524
+ "bg" => __("Bulgarian",'ultimate-member'),
1525
+ "bh" => __("Bihari",'ultimate-member'),
1526
+ "bi" => __("Bislama",'ultimate-member'),
1527
+ "bm" => __("Bambara",'ultimate-member'),
1528
+ "bn" => __("Bengali",'ultimate-member'),
1529
+ "bo" => __("Tibetan",'ultimate-member'),
1530
+ "br" => __("Breton",'ultimate-member'),
1531
+ "bs" => __("Bosnian",'ultimate-member'),
1532
+ "ca" => __("Catalan",'ultimate-member'),
1533
+ "ce" => __("Chechen",'ultimate-member'),
1534
+ "ch" => __("Chamorro",'ultimate-member'),
1535
+ "co" => __("Corsican",'ultimate-member'),
1536
+ "cr" => __("Cree",'ultimate-member'),
1537
+ "cs" => __("Czech",'ultimate-member'),
1538
+ "cu" => __("Church Slavic",'ultimate-member'),
1539
+ "cv" => __("Chuvash",'ultimate-member'),
1540
+ "cy" => __("Welsh",'ultimate-member'),
1541
+ "da" => __("Danish",'ultimate-member'),
1542
+ "de" => __("German",'ultimate-member'),
1543
+ "dv" => __("Divehi",'ultimate-member'),
1544
+ "dz" => __("Dzongkha",'ultimate-member'),
1545
+ "ee" => __("Ewe",'ultimate-member'),
1546
+ "el" => __("Greek",'ultimate-member'),
1547
+ "en" => __("English",'ultimate-member'),
1548
+ "eo" => __("Esperanto",'ultimate-member'),
1549
+ "es" => __("Spanish",'ultimate-member'),
1550
+ "et" => __("Estonian",'ultimate-member'),
1551
+ "eu" => __("Basque",'ultimate-member'),
1552
+ "fa" => __("Persian",'ultimate-member'),
1553
+ "ff" => __("Fulah",'ultimate-member'),
1554
+ "fi" => __("Finnish",'ultimate-member'),
1555
+ "fj" => __("Fijian",'ultimate-member'),
1556
+ "fo" => __("Faroese",'ultimate-member'),
1557
+ "fr" => __("French",'ultimate-member'),
1558
+ "fy" => __("Western Frisian",'ultimate-member'),
1559
+ "ga" => __("Irish",'ultimate-member'),
1560
+ "gd" => __("Scottish Gaelic",'ultimate-member'),
1561
+ "gl" => __("Galician",'ultimate-member'),
1562
+ "gn" => __("Guarani",'ultimate-member'),
1563
+ "gu" => __("Gujarati",'ultimate-member'),
1564
+ "gv" => __("Manx",'ultimate-member'),
1565
+ "ha" => __("Hausa",'ultimate-member'),
1566
+ "he" => __("Hebrew",'ultimate-member'),
1567
+ "hi" => __("Hindi",'ultimate-member'),
1568
+ "ho" => __("Hiri Motu",'ultimate-member'),
1569
+ "hr" => __("Croatian",'ultimate-member'),
1570
+ "ht" => __("Haitian",'ultimate-member'),
1571
+ "hu" => __("Hungarian",'ultimate-member'),
1572
+ "hy" => __("Armenian",'ultimate-member'),
1573
+ "hz" => __("Herero",'ultimate-member'),
1574
+ "ia" => __("Interlingua (International Auxiliary Language Association)",'ultimate-member'),
1575
+ "id" => __("Indonesian",'ultimate-member'),
1576
+ "ie" => __("Interlingue",'ultimate-member'),
1577
+ "ig" => __("Igbo",'ultimate-member'),
1578
+ "ii" => __("Sichuan Yi",'ultimate-member'),
1579
+ "ik" => __("Inupiaq",'ultimate-member'),
1580
+ "io" => __("Ido",'ultimate-member'),
1581
+ "is" => __("Icelandic",'ultimate-member'),
1582
+ "it" => __("Italian",'ultimate-member'),
1583
+ "iu" => __("Inuktitut",'ultimate-member'),
1584
+ "ja" => __("Japanese",'ultimate-member'),
1585
+ "jv" => __("Javanese",'ultimate-member'),
1586
+ "ka" => __("Kartuli",'ultimate-member'),
1587
+ "kg" => __("Kongo",'ultimate-member'),
1588
+ "ki" => __("Kikuyu",'ultimate-member'),
1589
+ "kj" => __("Kwanyama",'ultimate-member'),
1590
+ "kk" => __("Kazakh",'ultimate-member'),
1591
+ "kl" => __("Kalaallisut",'ultimate-member'),
1592
+ "km" => __("Khmer",'ultimate-member'),
1593
+ "kn" => __("Kannada",'ultimate-member'),
1594
+ "ko" => __("Korean",'ultimate-member'),
1595
+ "kr" => __("Kanuri",'ultimate-member'),
1596
+ "ks" => __("Kashmiri",'ultimate-member'),
1597
+ "ku" => __("Kurdish",'ultimate-member'),
1598
+ "kv" => __("Komi",'ultimate-member'),
1599
+ "kw" => __("Cornish",'ultimate-member'),
1600
+ "ky" => __("Kirghiz",'ultimate-member'),
1601
+ "la" => __("Latin",'ultimate-member'),
1602
+ "lb" => __("Luxembourgish",'ultimate-member'),
1603
+ "lg" => __("Ganda",'ultimate-member'),
1604
+ "li" => __("Limburgish",'ultimate-member'),
1605
+ "ln" => __("Lingala",'ultimate-member'),
1606
+ "lo" => __("Lao",'ultimate-member'),
1607
+ "lt" => __("Lithuanian",'ultimate-member'),
1608
+ "lu" => __("Luba-Katanga",'ultimate-member'),
1609
+ "lv" => __("Latvian",'ultimate-member'),
1610
+ "mg" => __("Malagasy",'ultimate-member'),
1611
+ "mh" => __("Marshallese",'ultimate-member'),
1612
+ "mi" => __("Maori",'ultimate-member'),
1613
+ "mk" => __("Macedonian",'ultimate-member'),
1614
+ "ml" => __("Malayalam",'ultimate-member'),
1615
+ "mn" => __("Mongolian",'ultimate-member'),
1616
+ "mr" => __("Marathi",'ultimate-member'),
1617
+ "ms" => __("Malay",'ultimate-member'),
1618
+ "mt" => __("Maltese",'ultimate-member'),
1619
+ "my" => __("Burmese",'ultimate-member'),
1620
+ "na" => __("Nauru",'ultimate-member'),
1621
+ "nb" => __("Norwegian Bokmal",'ultimate-member'),
1622
+ "nd" => __("North Ndebele",'ultimate-member'),
1623
+ "ne" => __("Nepali",'ultimate-member'),
1624
+ "ng" => __("Ndonga",'ultimate-member'),
1625
+ "nl" => __("Dutch",'ultimate-member'),
1626
+ "nn" => __("Norwegian Nynorsk",'ultimate-member'),
1627
+ "no" => __("Norwegian",'ultimate-member'),
1628
+ "nr" => __("South Ndebele",'ultimate-member'),
1629
+ "nv" => __("Navajo",'ultimate-member'),
1630
+ "ny" => __("Chichewa",'ultimate-member'),
1631
+ "oc" => __("Occitan",'ultimate-member'),
1632
+ "oj" => __("Ojibwa",'ultimate-member'),
1633
+ "om" => __("Oromo",'ultimate-member'),
1634
+ "or" => __("Oriya",'ultimate-member'),
1635
+ "os" => __("Ossetian",'ultimate-member'),
1636
+ "pa" => __("Panjabi",'ultimate-member'),
1637
+ "pi" => __("Pali",'ultimate-member'),
1638
+ "pl" => __("Polish",'ultimate-member'),
1639
+ "ps" => __("Pashto",'ultimate-member'),
1640
+ "pt" => __("Portuguese",'ultimate-member'),
1641
+ "qu" => __("Quechua",'ultimate-member'),
1642
+ "rm" => __("Raeto-Romance",'ultimate-member'),
1643
+ "rn" => __("Kirundi",'ultimate-member'),
1644
+ "ro" => __("Romanian",'ultimate-member'),
1645
+ "ru" => __("Russian",'ultimate-member'),
1646
+ "rw" => __("Kinyarwanda",'ultimate-member'),
1647
+ "sa" => __("Sanskrit",'ultimate-member'),
1648
+ "sc" => __("Sardinian",'ultimate-member'),
1649
+ "sd" => __("Sindhi",'ultimate-member'),
1650
+ "se" => __("Northern Sami",'ultimate-member'),
1651
+ "sg" => __("Sango",'ultimate-member'),
1652
+ "si" => __("Sinhala",'ultimate-member'),
1653
+ "sk" => __("Slovak",'ultimate-member'),
1654
+ "sl" => __("Slovenian",'ultimate-member'),
1655
+ "sm" => __("Samoan",'ultimate-member'),
1656
+ "sn" => __("Shona",'ultimate-member'),
1657
+ "so" => __("Somali",'ultimate-member'),
1658
+ "sq" => __("Albanian",'ultimate-member'),
1659
+ "sr" => __("Serbian",'ultimate-member'),
1660
+ "ss" => __("Swati",'ultimate-member'),
1661
+ "st" => __("Southern Sotho",'ultimate-member'),
1662
+ "su" => __("Sundanese",'ultimate-member'),
1663
+ "sv" => __("Swedish",'ultimate-member'),
1664
+ "sw" => __("Swahili",'ultimate-member'),
1665
+ "ta" => __("Tamil",'ultimate-member'),
1666
+ "te" => __("Telugu",'ultimate-member'),
1667
+ "tg" => __("Tajik",'ultimate-member'),
1668
+ "th" => __("Thai",'ultimate-member'),
1669
+ "ti" => __("Tigrinya",'ultimate-member'),
1670
+ "tk" => __("Turkmen",'ultimate-member'),
1671
+ "tl" => __("Tagalog",'ultimate-member'),
1672
+ "tn" => __("Tswana",'ultimate-member'),
1673
+ "to" => __("Tonga",'ultimate-member'),
1674
+ "tr" => __("Turkish",'ultimate-member'),
1675
+ "ts" => __("Tsonga",'ultimate-member'),
1676
+ "tt" => __("Tatar",'ultimate-member'),
1677
+ "tw" => __("Twi",'ultimate-member'),
1678
+ "ty" => __("Tahitian",'ultimate-member'),
1679
+ "ug" => __("Uighur",'ultimate-member'),
1680
+ "uk" => __("Ukrainian",'ultimate-member'),
1681
+ "ur" => __("Urdu",'ultimate-member'),
1682
+ "uz" => __("Uzbek",'ultimate-member'),
1683
+ "ve" => __("Venda",'ultimate-member'),
1684
+ "vi" => __("Vietnamese",'ultimate-member'),
1685
+ "vo" => __("Volapuk",'ultimate-member'),
1686
+ "wa" => __("Walloon",'ultimate-member'),
1687
+ "wo" => __("Wolof",'ultimate-member'),
1688
+ "xh" => __("Xhosa",'ultimate-member'),
1689
+ "yi" => __("Yiddish",'ultimate-member'),
1690
+ "yo" => __("Yoruba",'ultimate-member'),
1691
+ "za" => __("Zhuang",'ultimate-member'),
1692
+ "zh" => __("Chinese",'ultimate-member'),
1693
+ "zu" => __("Zulu",'ultimate-member')
1694
+ );
1695
+ break;
1696
+
1697
+ case 'countries':
1698
+ $array = array (
1699
+ 'AF' => __('Afghanistan','ultimate-member'),
1700
+ 'AX' => __('Åland Islands','ultimate-member'),
1701
+ 'AL' => __('Albania','ultimate-member'),
1702
+ 'DZ' => __('Algeria','ultimate-member'),
1703
+ 'AS' => __('American Samoa','ultimate-member'),
1704
+ 'AD' => __('Andorra','ultimate-member'),
1705
+ 'AO' => __('Angola','ultimate-member'),
1706
+ 'AI' => __('Anguilla','ultimate-member'),
1707
+ 'AQ' => __('Antarctica','ultimate-member'),
1708
+ 'AG' => __('Antigua and Barbuda','ultimate-member'),
1709
+ 'AR' => __('Argentina','ultimate-member'),
1710
+ 'AM' => __('Armenia','ultimate-member'),
1711
+ 'AW' => __('Aruba','ultimate-member'),
1712
+ 'AU' => __('Australia','ultimate-member'),
1713
+ 'AT' => __('Austria','ultimate-member'),
1714
+ 'AZ' => __('Azerbaijan','ultimate-member'),
1715
+ 'BS' => __('Bahamas','ultimate-member'),
1716
+ 'BH' => __('Bahrain','ultimate-member'),
1717
+ 'BD' => __('Bangladesh','ultimate-member'),
1718
+ 'BB' => __('Barbados','ultimate-member'),
1719
+ 'BY' => __('Belarus','ultimate-member'),
1720
+ 'BE' => __('Belgium','ultimate-member'),
1721
+ 'BZ' => __('Belize','ultimate-member'),
1722
+ 'BJ' => __('Benin','ultimate-member'),
1723
+ 'BM' => __('Bermuda','ultimate-member'),
1724
+ 'BT' => __('Bhutan','ultimate-member'),
1725
+ 'BO' => __('Bolivia, Plurinational State of','ultimate-member'),
1726
+ 'BA' => __('Bosnia and Herzegovina','ultimate-member'),
1727
+ 'BW' => __('Botswana','ultimate-member'),
1728
+ 'BV' => __('Bouvet Island','ultimate-member'),
1729
+ 'BR' => __('Brazil','ultimate-member'),
1730
+ 'IO' => __('British Indian Ocean Territory','ultimate-member'),
1731
+ 'BN' => __('Brunei Darussalam','ultimate-member'),
1732
+ 'BG' => __('Bulgaria','ultimate-member'),
1733
+ 'BF' => __('Burkina Faso','ultimate-member'),
1734
+ 'BI' => __('Burundi','ultimate-member'),
1735
+ 'KH' => __('Cambodia','ultimate-member'),
1736
+ 'CM' => __('Cameroon','ultimate-member'),
1737
+ 'CA' => __('Canada','ultimate-member'),
1738
+ 'CV' => __('Cape Verde','ultimate-member'),
1739
+ 'KY' => __('Cayman Islands','ultimate-member'),
1740
+ 'CF' => __('Central African Republic','ultimate-member'),
1741
+ 'TD' => __('Chad','ultimate-member'),
1742
+ 'CL' => __('Chile','ultimate-member'),
1743
+ 'CN' => __('China','ultimate-member'),
1744
+ 'CX' => __('Christmas Island','ultimate-member'),
1745
+ 'CC' => __('Cocos (Keeling) Islands','ultimate-member'),
1746
+ 'CO' => __('Colombia','ultimate-member'),
1747
+ 'KM' => __('Comoros','ultimate-member'),
1748
+ 'CG' => __('Congo','ultimate-member'),
1749
+ 'CD' => __('Congo, the Democratic Republic of the','ultimate-member'),
1750
+ 'CK' => __('Cook Islands','ultimate-member'),
1751
+ 'CR' => __('Costa Rica','ultimate-member'),
1752
+ 'CI' => __("Côte d'Ivoire",'ultimate-member'),
1753
+ 'HR' => __('Croatia','ultimate-member'),
1754
+ 'CU' => __('Cuba','ultimate-member'),
1755
+ 'CY' => __('Cyprus','ultimate-member'),
1756
+ 'CZ' => __('Czech Republic','ultimate-member'),
1757
+ 'DK' => __('Denmark','ultimate-member'),
1758
+ 'DJ' => __('Djibouti','ultimate-member'),
1759
+ 'DM' => __('Dominica','ultimate-member'),
1760
+ 'DO' => __('Dominican Republic','ultimate-member'),
1761
+ 'EC' => __('Ecuador','ultimate-member'),
1762
+ 'EG' => __('Egypt','ultimate-member'),
1763
+ 'SV' => __('El Salvador','ultimate-member'),
1764
+ 'GQ' => __('Equatorial Guinea','ultimate-member'),
1765
+ 'ER' => __('Eritrea','ultimate-member'),
1766
+ 'EE' => __('Estonia','ultimate-member'),
1767
+ 'ET' => __('Ethiopia','ultimate-member'),
1768
+ 'FK' => __('Falkland Islands (Malvinas)','ultimate-member'),
1769
+ 'FO' => __('Faroe Islands','ultimate-member'),
1770
+ 'FJ' => __('Fiji','ultimate-member'),
1771
+ 'FI' => __('Finland','ultimate-member'),
1772
+ 'FR' => __('France','ultimate-member'),
1773
+ 'GF' => __('French Guiana','ultimate-member'),
1774
+ 'PF' => __('French Polynesia','ultimate-member'),
1775
+ 'TF' => __('French Southern Territories','ultimate-member'),
1776
+ 'GA' => __('Gabon','ultimate-member'),
1777
+ 'GM' => __('Gambia','ultimate-member'),
1778
+ 'GE' => __('Sakartvelo','ultimate-member'),
1779
+ 'DE' => __('Germany','ultimate-member'),
1780
+ 'GH' => __('Ghana','ultimate-member'),
1781
+ 'GI' => __('Gibraltar','ultimate-member'),
1782
+ 'GR' => __('Greece','ultimate-member'),
1783
+ 'GL' => __('Greenland','ultimate-member'),
1784
+ 'GD' => __('Grenada','ultimate-member'),
1785
+ 'GP' => __('Guadeloupe','ultimate-member'),
1786
+ 'GU' => __('Guam','ultimate-member'),
1787
+ 'GT' => __('Guatemala','ultimate-member'),
1788
+ 'GG' => __('Guernsey','ultimate-member'),
1789
+ 'GN' => __('Guinea','ultimate-member'),
1790
+ 'GW' => __('Guinea-Bissau','ultimate-member'),
1791
+ 'GY' => __('Guyana','ultimate-member'),
1792
+ 'HT' => __('Haiti','ultimate-member'),
1793
+ 'HM' => __('Heard Island and McDonald Islands','ultimate-member'),
1794
+ 'VA' => __('Holy See (Vatican City State)','ultimate-member'),
1795
+ 'HN' => __('Honduras','ultimate-member'),
1796
+ 'HK' => __('Hong Kong','ultimate-member'),
1797
+ 'HU' => __('Hungary','ultimate-member'),
1798
+ 'IS' => __('Iceland','ultimate-member'),
1799
+ 'IN' => __('India','ultimate-member'),
1800
+ 'ID' => __('Indonesia','ultimate-member'),
1801
+ 'IR' => __('Iran, Islamic Republic of','ultimate-member'),
1802
+ 'IQ' => __('Iraq','ultimate-member'),
1803
+ 'IE' => __('Ireland','ultimate-member'),
1804
+ 'IM' => __('Isle of Man','ultimate-member'),
1805
+ 'IL' => __('Israel','ultimate-member'),
1806
+ 'IT' => __('Italy','ultimate-member'),
1807
+ 'JM' => __('Jamaica','ultimate-member'),
1808
+ 'JP' => __('Japan','ultimate-member'),
1809
+ 'JE' => __('Jersey','ultimate-member'),
1810
+ 'JO' => __('Jordan','ultimate-member'),
1811
+ 'KZ' => __('Kazakhstan','ultimate-member'),
1812
+ 'KE' => __('Kenya','ultimate-member'),
1813
+ 'KI' => __('Kiribati','ultimate-member'),
1814
+ 'KP' => __("Korea, Democratic People's Republic of",'ultimate-member'),
1815
+ 'KR' => __('Korea, Republic of','ultimate-member'),
1816
+ 'KW' => __('Kuwait','ultimate-member'),
1817
+ 'KG' => __('Kyrgyzstan','ultimate-member'),
1818
+ 'LA' => __("Lao People's Democratic Republic",'ultimate-member'),
1819
+ 'LV' => __('Latvia','ultimate-member'),
1820
+ 'LB' => __('Lebanon','ultimate-member'),
1821
+ 'LS' => __('Lesotho','ultimate-member'),
1822
+ 'LR' => __('Liberia','ultimate-member'),
1823
+ 'LY' => __('Libyan Arab Jamahiriya','ultimate-member'),
1824
+ 'LI' => __('Liechtenstein','ultimate-member'),
1825
+ 'LT' => __('Lithuania','ultimate-member'),
1826
+ 'LU' => __('Luxembourg','ultimate-member'),
1827
+ 'MO' => __('Macao','ultimate-member'),
1828
+ 'MK' => __('Macedonia, the former Yugoslav Republic of','ultimate-member'),
1829
+ 'MG' => __('Madagascar','ultimate-member'),
1830
+ 'MW' => __('Malawi','ultimate-member'),
1831
+ 'MY' => __('Malaysia','ultimate-member'),
1832
+ 'MV' => __('Maldives','ultimate-member'),
1833
+ 'ML' => __('Mali','ultimate-member'),
1834
+ 'MT' => __('Malta','ultimate-member'),
1835
+ 'MH' => __('Marshall Islands','ultimate-member'),
1836
+ 'MQ' => __('Martinique','ultimate-member'),
1837
+ 'MR' => __('Mauritania','ultimate-member'),
1838
+ 'MU' => __('Mauritius','ultimate-member'),
1839
+ 'YT' => __('Mayotte','ultimate-member'),
1840
+ 'MX' => __('Mexico','ultimate-member'),
1841
+ 'FM' => __('Micronesia, Federated States of','ultimate-member'),
1842
+ 'MD' => __('Moldova, Republic of','ultimate-member'),
1843
+ 'MC' => __('Monaco','ultimate-member'),
1844
+ 'MN' => __('Mongolia','ultimate-member'),
1845
+ 'ME' => __('Montenegro','ultimate-member'),
1846
+ 'MS' => __('Montserrat','ultimate-member'),
1847
+ 'MA' => __('Morocco','ultimate-member'),
1848
+ 'MZ' => __('Mozambique','ultimate-member'),
1849
+ 'MM' => __('Myanmar','ultimate-member'),
1850
+ 'NA' => __('Namibia','ultimate-member'),
1851
+ 'NR' => __('Nauru','ultimate-member'),
1852
+ 'NP' => __('Nepal','ultimate-member'),
1853
+ 'NL' => __('Netherlands','ultimate-member'),
1854
+ 'AN' => __('Netherlands Antilles','ultimate-member'),
1855
+ 'NC' => __('New Caledonia','ultimate-member'),
1856
+ 'NZ' => __('New Zealand','ultimate-member'),
1857
+ 'NI' => __('Nicaragua','ultimate-member'),
1858
+ 'NE' => __('Niger','ultimate-member'),
1859
+ 'NG' => __('Nigeria','ultimate-member'),
1860
+ 'NU' => __('Niue','ultimate-member'),
1861
+ 'NF' => __('Norfolk Island','ultimate-member'),
1862
+ 'MP' => __('Northern Mariana Islands','ultimate-member'),
1863
+ 'NO' => __('Norway','ultimate-member'),
1864
+ 'OM' => __('Oman','ultimate-member'),
1865
+ 'PK' => __('Pakistan','ultimate-member'),
1866
+ 'PW' => __('Palau','ultimate-member'),
1867
+ 'PS' => __('Palestine','ultimate-member'),
1868
+ 'PA' => __('Panama','ultimate-member'),
1869
+ 'PG' => __('Papua New Guinea','ultimate-member'),
1870
+ 'PY' => __('Paraguay','ultimate-member'),
1871
+ 'PE' => __('Peru','ultimate-member'),
1872
+ 'PH' => __('Philippines','ultimate-member'),
1873
+ 'PN' => __('Pitcairn','ultimate-member'),
1874
+ 'PL' => __('Poland','ultimate-member'),
1875
+ 'PT' => __('Portugal','ultimate-member'),
1876
+ 'PR' => __('Puerto Rico','ultimate-member'),
1877
+ 'QA' => __('Qatar','ultimate-member'),
1878
+ 'RE' => __('Réunion','ultimate-member'),
1879
+ 'RO' => __('Romania','ultimate-member'),
1880
+ 'RU' => __('Russian Federation','ultimate-member'),
1881
+ 'RW' => __('Rwanda','ultimate-member'),
1882
+ 'BL' => __('Saint Barthélemy','ultimate-member'),
1883
+ 'SH' => __('Saint Helena','ultimate-member'),
1884
+ 'KN' => __('Saint Kitts and Nevis','ultimate-member'),
1885
+ 'LC' => __('Saint Lucia','ultimate-member'),
1886
+ 'MF' => __('Saint Martin (French part)','ultimate-member'),
1887
+ 'PM' => __('Saint Pierre and Miquelon','ultimate-member'),
1888
+ 'VC' => __('Saint Vincent and the Grenadines','ultimate-member'),
1889
+ 'WS' => __('Samoa','ultimate-member'),
1890
+ 'SM' => __('San Marino','ultimate-member'),
1891
+ 'ST' => __('Sao Tome and Principe','ultimate-member'),
1892
+ 'SA' => __('Saudi Arabia','ultimate-member'),
1893
+ 'SN' => __('Senegal','ultimate-member'),
1894
+ 'RS' => __('Serbia','ultimate-member'),
1895
+ 'SC' => __('Seychelles','ultimate-member'),
1896
+ 'SL' => __('Sierra Leone','ultimate-member'),
1897
+ 'SG' => __('Singapore','ultimate-member'),
1898
+ 'SK' => __('Slovakia','ultimate-member'),
1899
+ 'SI' => __('Slovenia','ultimate-member'),
1900
+ 'SB' => __('Solomon Islands','ultimate-member'),
1901
+ 'SO' => __('Somalia','ultimate-member'),
1902
+ 'ZA' => __('South Africa','ultimate-member'),
1903
+ 'GS' => __('South Georgia and the South Sandwich Islands','ultimate-member'),
1904
+ 'SS' => __('South Sudan','ultimate-member'),
1905
+ 'ES' => __('Spain','ultimate-member'),
1906
+ 'LK' => __('Sri Lanka','ultimate-member'),
1907
+ 'SD' => __('Sudan','ultimate-member'),
1908
+ 'SR' => __('Suriname','ultimate-member'),
1909
+ 'SJ' => __('Svalbard and Jan Mayen','ultimate-member'),
1910
+ 'SZ' => __('Swaziland','ultimate-member'),
1911
+ 'SE' => __('Sweden','ultimate-member'),
1912
+ 'CH' => __('Switzerland','ultimate-member'),
1913
+ 'SY' => __('Syrian Arab Republic','ultimate-member'),
1914
+ 'TW' => __('Taiwan, Province of China','ultimate-member'),
1915
+ 'TJ' => __('Tajikistan','ultimate-member'),
1916
+ 'TZ' => __('Tanzania, United Republic of','ultimate-member'),
1917
+ 'TH' => __('Thailand','ultimate-member'),
1918
+ 'TL' => __('Timor-Leste','ultimate-member'),
1919
+ 'TG' => __('Togo','ultimate-member'),
1920
+ 'TK' => __('Tokelau','ultimate-member'),
1921
+ 'TO' => __('Tonga','ultimate-member'),
1922
+ 'TT' => __('Trinidad and Tobago','ultimate-member'),
1923
+ 'TN' => __('Tunisia','ultimate-member'),
1924
+ 'TR' => __('Turkey','ultimate-member'),
1925
+ 'TM' => __('Turkmenistan','ultimate-member'),
1926
+ 'TC' => __('Turks and Caicos Islands','ultimate-member'),
1927
+ 'TV' => __('Tuvalu','ultimate-member'),
1928
+ 'UG' => __('Uganda','ultimate-member'),
1929
+ 'UA' => __('Ukraine','ultimate-member'),
1930
+ 'AE' => __('United Arab Emirates','ultimate-member'),
1931
+ 'GB' => __('United Kingdom','ultimate-member'),
1932
+ 'US' => __('United States','ultimate-member'),
1933
+ 'UM' => __('United States Minor Outlying Islands','ultimate-member'),
1934
+ 'UY' => __('Uruguay','ultimate-member'),
1935
+ 'UZ' => __('Uzbekistan','ultimate-member'),
1936
+ 'VU' => __('Vanuatu','ultimate-member'),
1937
+ 'VE' => __('Venezuela, Bolivarian Republic of','ultimate-member'),
1938
+ 'VN' => __('Viet Nam','ultimate-member'),
1939
+ 'VG' => __('Virgin Islands, British','ultimate-member'),
1940
+ 'VI' => __('Virgin Islands, U.S.','ultimate-member'),
1941
+ 'WF' => __('Wallis and Futuna','ultimate-member'),
1942
+ 'EH' => __('Western Sahara','ultimate-member'),
1943
+ 'YE' => __('Yemen','ultimate-member'),
1944
+ 'ZM' => __('Zambia','ultimate-member'),
1945
+ 'ZW' => __('Zimbabwe','ultimate-member'),
1946
+ );
1947
+ break;
1948
+
1949
+ }
1950
+
1951
+ /**
1952
+ * UM hook
1953
+ *
1954
+ * @type filter
1955
+ * @title um_{$data}_predefined_field_options
1956
+ * @description Extend Predefined Fields options. Where $data - field key.
1957
+ * @input_vars
1958
+ * [{"var":"$options","type":"array","desc":"Field's Options"}]
1959
+ * @change_log
1960
+ * ["Since: 2.0"]
1961
+ * @usage add_filter( 'um_{$data}_predefined_field_options', 'function_name', 10, 1 );
1962
+ * @example
1963
+ * <?php
1964
+ * add_filter( 'um_{$data}_predefined_field_options', 'my_predefined_field', 10, 1 );
1965
+ * function my_predefined_field( $options ) {
1966
+ * // your code here
1967
+ * return $options;
1968
+ * }
1969
+ * ?>
1970
+ */
1971
+ $array = apply_filters( "um_{$data}_predefined_field_options", $array );
1972
+ return $array;
1973
+ }
1974
+
1975
+ }
1976
+ }
includes/core/class-fields.php CHANGED
@@ -1,4896 +1,4902 @@
1
- <?php
2
- namespace um\core;
3
-
4
-
5
- if ( ! defined( 'ABSPATH' ) ) exit;
6
-
7
-
8
- if ( ! class_exists( 'um\core\Fields' ) ) {
9
-
10
-
11
- /**
12
- * Class Fields
13
- * @package um\core
14
- */
15
- class Fields {
16
-
17
-
18
- /**
19
- * @var string
20
- */
21
- var $set_mode = '';
22
-
23
-
24
- /**
25
- * @var int form_id
26
- */
27
- public $set_id = null;
28
-
29
-
30
- /**
31
- * Fields constructor.
32
- */
33
- function __construct() {
34
- $this->editing = false;
35
- $this->viewing = false;
36
- $this->timestamp = current_time( 'timestamp' );
37
- }
38
-
39
-
40
- /**
41
- * Standard checkbox field
42
- *
43
- * @param integer $id
44
- * @param string $title
45
- * @param bool $checked
46
- */
47
- function checkbox( $id, $title, $checked = true ) {
48
-
49
- /**
50
- * Set value on form submission
51
- */
52
- if ( isset( $_REQUEST[ $id ] ) ) {
53
- $checked = (bool) $_REQUEST[ $id ];
54
- }
55
-
56
- $class = $checked ? 'um-icon-android-checkbox-outline' : 'um-icon-android-checkbox-outline-blank';
57
-
58
- ?>
59
-
60
-
61
- <div class="um-field um-field-c">
62
- <div class="um-field-area">
63
- <label class="um-field-checkbox<?php echo $checked ? ' active' : '' ?>">
64
- <input type="checkbox" name="<?php echo esc_attr( $id ); ?>" value="1" <?php checked( $checked ) ?> />
65
- <span class="um-field-checkbox-state"><i class="<?php echo esc_attr( $class ) ?>"></i></span>
66
- <span class="um-field-checkbox-option"> <?php echo esc_html( $title ); ?></span>
67
- </label>
68
- </div>
69
- </div>
70
-
71
- <?php
72
- }
73
-
74
-
75
- /**
76
- * Shows social links
77
- */
78
- function show_social_urls() {
79
- $social = array();
80
-
81
- $fields = UM()->builtin()->get_all_user_fields();
82
- foreach ( $fields as $field => $args ) {
83
- if ( isset( $args['advanced'] ) && $args['advanced'] == 'social' ) {
84
- $social[ $field ] = $args;
85
- }
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
-
95
- <?php
96
- }
97
- }
98
- }
99
-
100
-
101
- /**
102
- * Hidden field inside a shortcode
103
- *
104
- * @param string $field
105
- */
106
- function add_hidden_field( $field ) {
107
- echo '<div style="display: none !important;">';
108
-
109
- $fields = UM()->builtin()->get_specific_fields( $field );
110
-
111
- $output = null;
112
-
113
- foreach ( $fields as $key => $data ) {
114
- $output .= UM()->fields()->edit_field( $key, $data );
115
- }
116
-
117
- echo $output;
118
-
119
- echo '</div>';
120
- }
121
-
122
-
123
- /**
124
- * Get hidden field
125
- *
126
- * @param string $key
127
- * @param string $value
128
- *
129
- * @return string
130
- */
131
- function disabled_hidden_field( $key, $value ) {
132
- return '<input type="hidden" name="' . esc_attr( $key ) . '" value="' . esc_attr( $value ) . '"/>';
133
- }
134
-
135
-
136
- /**
137
- * Updates a field globally
138
- *
139
- * @param integer $id
140
- * @param array $args
141
- */
142
- function globally_update_field( $id, $args ) {
143
- $fields = UM()->builtin()->saved_fields;
144
-
145
- $fields[ $id ] = $args;
146
-
147
- if ( array_key_exists( 'custom_dropdown_options_source', $args ) && function_exists( $args['custom_dropdown_options_source'] ) ) {
148
- $allowed_callbacks = UM()->options()->get( 'allowed_choice_callbacks' );
149
- if ( ! empty( $allowed_callbacks ) ) {
150
- $allowed_callbacks = array_map( 'rtrim', explode( "\n", $allowed_callbacks ) );
151
- $allowed_callbacks[] = $args['custom_dropdown_options_source'];
152
- } else {
153
- $allowed_callbacks = array( $args['custom_dropdown_options_source'] );
154
- }
155
- $allowed_callbacks = array_unique( $allowed_callbacks );
156
- $allowed_callbacks = implode( "\r\n", $allowed_callbacks );
157
-
158
- UM()->options()->update( 'allowed_choice_callbacks', $allowed_callbacks );
159
- }
160
-
161
- unset( $fields[ $id ]['in_row'] );
162
- unset( $fields[ $id ]['in_sub_row'] );
163
- unset( $fields[ $id ]['in_column'] );
164
- unset( $fields[ $id ]['in_group'] );
165
- unset( $fields[ $id ]['position'] );
166
-
167
- do_action( 'um_add_new_field', $id, $args );
168
-
169
- update_option( 'um_fields', $fields );
170
- }
171
-
172
-
173
- /**
174
- * Updates a field in form only
175
- *
176
- * @param integer $id
177
- * @param array $args
178
- * @param integer $form_id
179
- */
180
- function update_field( $id, $args, $form_id ) {
181
- $fields = UM()->query()->get_attr( 'custom_fields', $form_id );
182
-
183
- if ( $args['type'] == 'row' ) {
184
- if ( isset( $fields[ $id ] ) ) {
185
- $old_args = $fields[ $id ];
186
- foreach ( $old_args as $k => $v ) {
187
- if ( ! in_array( $k, array( 'sub_rows', 'cols' ) ) ) {
188
- unset( $old_args[ $k ] );
189
- }
190
- }
191
- $args = array_merge( $old_args, $args );
192
- }
193
- }
194
-
195
- // custom fields support
196
- if ( isset( UM()->builtin()->predefined_fields[ $id ] ) && isset( UM()->builtin()->predefined_fields[ $id ]['custom'] ) ) {
197
- $args = array_merge( UM()->builtin()->predefined_fields[ $id ], $args );
198
- }
199
-
200
- $fields[ $id ] = $args;
201
-
202
- if ( array_key_exists( 'custom_dropdown_options_source', $args ) && function_exists( $args['custom_dropdown_options_source'] ) ) {
203
- $allowed_callbacks = UM()->options()->get( 'allowed_choice_callbacks' );
204
- if ( ! empty( $allowed_callbacks ) ) {
205
- $allowed_callbacks = array_map( 'rtrim', explode( "\n", $allowed_callbacks ) );
206
- $allowed_callbacks[] = $args['custom_dropdown_options_source'];
207
- } else {
208
- $allowed_callbacks = array( $args['custom_dropdown_options_source'] );
209
- }
210
- $allowed_callbacks = array_unique( $allowed_callbacks );
211
- $allowed_callbacks = implode( "\r\n", $allowed_callbacks );
212
-
213
- UM()->options()->update( 'allowed_choice_callbacks', $allowed_callbacks );
214
- }
215
-
216
- // for group field only
217
- if ( $args['type'] == 'group' ) {
218
- $fields[ $id ]['in_group'] = '';
219
- }
220
-
221
- UM()->query()->update_attr( 'custom_fields', $form_id, $fields );
222
- }
223
-
224
-
225
- /**
226
- * Deletes a field in form only
227
- *
228
- * @param integer $id
229
- * @param integer $form_id
230
- */
231
- function delete_field_from_form( $id, $form_id ) {
232
- $fields = UM()->query()->get_attr( 'custom_fields', $form_id );
233
-
234
- if ( isset( $fields[ $id ] ) ) {
235
- $condition_fields = get_option( 'um_fields' );
236
-
237
- if( ! is_array( $condition_fields ) ) $condition_fields = array();
238
-
239
- foreach ( $condition_fields as $key => $value ) {
240
- $deleted_field = array_search( $id, $value );
241
-
242
- if ( $key != $id && $deleted_field != false ) {
243
- $deleted_field_id = str_replace( 'conditional_field', '', $deleted_field );
244
-
245
- if ( $deleted_field_id == '' ) {
246
- $arr_id = 0;
247
- } else {
248
- $arr_id = $deleted_field_id;
249
- }
250
-
251
- unset( $condition_fields[ $key ][ 'conditional_action' . $deleted_field_id ] );
252
- unset( $condition_fields[ $key ][ $deleted_field ] );
253
- unset( $condition_fields[ $key ][ 'conditional_operator' . $deleted_field_id ] );
254
- unset( $condition_fields[ $key ][ 'conditional_value' . $deleted_field_id ] );
255
- unset( $condition_fields[ $key ]['conditions'][ $arr_id ] );
256
-
257
- unset( $fields[ $key ][ 'conditional_action' . $deleted_field_id ] );
258
- unset( $fields[ $key ][ $deleted_field ] );
259
- unset( $fields[ $key ][ 'conditional_operator' . $deleted_field_id ] );
260
- unset( $fields[ $key ][ 'conditional_value' . $deleted_field_id ] );
261
- unset( $fields[ $key ]['conditions'][ $arr_id ] );
262
- }
263
- }
264
-
265
- update_option( 'um_fields' , $condition_fields );
266
- unset( $fields[ $id ] );
267
- UM()->query()->update_attr( 'custom_fields', $form_id, $fields );
268
- }
269
- }
270
-
271
-
272
- /**
273
- * Deletes a field from custom fields
274
- *
275
- * @param integer $id
276
- */
277
- function delete_field_from_db( $id ) {
278
- $fields = UM()->builtin()->saved_fields;
279
- if ( isset( $fields[ $id ] ) ) {
280
- $args = $fields[ $id ];
281
-
282
- unset( $fields[ $id ] );
283
-
284
- do_action( 'um_delete_custom_field', $id, $args );
285
-
286
- update_option( 'um_fields', $fields );
287
-
288
- global $wpdb;
289
- $forms = $wpdb->get_col( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'um_form'" );
290
- foreach ( $forms as $form_id ) {
291
- $form_fields = get_post_meta( $form_id, '_um_custom_fields', true );
292
- unset( $form_fields[ $id ] );
293
- update_post_meta( $form_id, '_um_custom_fields', $form_fields );
294
- }
295
-
296
- $directories = $wpdb->get_col( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'um_directory'" );
297
- foreach ( $directories as $directory_id ) {
298
- // Frontend filters
299
- $directory_search_fields = get_post_meta( $directory_id, '_um_search_fields', true );
300
- $directory_search_fields = array_values( array_diff( $directory_search_fields, array( $id ) ) );
301
- update_post_meta( $directory_id, '_um_search_fields', $directory_search_fields );
302
-
303
- // Admin filtering
304
- $directory_search_filters = get_post_meta( $directory_id, '_um_search_filters', true );
305
- unset( $directory_search_filters[ $id ] );
306
- update_post_meta( $directory_id, '_um_search_filters', $directory_search_filters );
307
-
308
- // display in tagline
309
- $directory_reveal_fields = get_post_meta( $directory_id, '_um_reveal_fields', true );
310
- $directory_reveal_fields = array_values( array_diff( $directory_reveal_fields, array( $id ) ) );
311
- update_post_meta( $directory_id, '_um_reveal_fields', $directory_reveal_fields );
312
-
313
- // extra user information section
314
- $directory_tagline_fields = get_post_meta( $directory_id, '_um_tagline_fields', true );
315
- $directory_tagline_fields = array_values( array_diff( $directory_tagline_fields, array( $id ) ) );
316
- update_post_meta( $directory_id, '_um_tagline_fields', $directory_tagline_fields );
317
-
318
- // Custom fields selected in "Choose field(s) to enable in sorting"
319
- $directory_sorting_fields = get_post_meta( $directory_id, '_um_sorting_fields', true );
320
- foreach ( $directory_sorting_fields as $key => $sorting_data ) {
321
- if ( is_array( $sorting_data ) && array_key_exists( $id, $sorting_data ) ) {
322
- unset( $directory_sorting_fields[ $key ] );
323
- }
324
- }
325
- $directory_sorting_fields = array_values( $directory_sorting_fields );
326
- update_post_meta( $directory_id, '_um_sorting_fields', $directory_sorting_fields );
327
-
328
- // If "Default sort users by" = "Other (Custom Field)" is selected when delete this custom field and set default sorting
329
- $directory_sortby_custom = get_post_meta( $directory_id, '_um_sortby_custom', true );
330
- if ( $directory_sortby_custom === $id ) {
331
- $directory_sortby = get_post_meta( $directory_id, '_um_sortby', true );
332
- if ( 'other' === $directory_sortby ) {
333
- update_post_meta( $directory_id, '_um_sortby', 'user_registered_desc' );
334
- }
335
- update_post_meta( $directory_id, '_um_sortby_custom', '' );
336
- update_post_meta( $directory_id, '_um_sortby_custom_label', '' );
337
- }
338
- }
339
-
340
- }
341
- }
342
-
343
-
344
- /**
345
- * Quickly adds a field from custom fields
346
- *
347
- * @param integer $global_id
348
- * @param integer $form_id
349
- * @param array $position
350
- */
351
- function add_field_from_list( $global_id, $form_id, $position = array() ) {
352
- $fields = UM()->query()->get_attr( 'custom_fields', $form_id );
353
- $field_scope = UM()->builtin()->saved_fields;
354
-
355
- if ( ! isset( $fields[ $global_id ] ) ) {
356
-
357
- $count = 1;
358
- if ( ! empty( $fields ) ) {
359
- $count = count( $fields ) + 1;
360
- }
361
-
362
- $fields[ $global_id ] = $field_scope[ $global_id ];
363
- $fields[ $global_id ]['position'] = $count;
364
-
365
- // set position
366
- if ( $position ) {
367
- foreach ( $position as $key => $val) {
368
- $fields[ $global_id ][ $key ] = $val;
369
- }
370
- }
371
-
372
- // add field to form
373
- UM()->query()->update_attr( 'custom_fields', $form_id, $fields );
374
-
375
- }
376
- }
377
-
378
-
379
- /**
380
- * Quickly adds a field from pre-defined fields
381
- *
382
- * @param integer $global_id
383
- * @param integer $form_id
384
- * @param array $position
385
- */
386
- function add_field_from_predefined( $global_id, $form_id, $position = array() ) {
387
- $fields = UM()->query()->get_attr( 'custom_fields', $form_id );
388
- $field_scope = UM()->builtin()->predefined_fields;
389
-
390
- if ( ! isset( $fields[ $global_id ] ) ) {
391
-
392
- $count = 1;
393
- if ( ! empty( $fields ) ) {
394
- $count = count( $fields ) + 1;
395
- }
396
-
397
- $fields[ $global_id ] = $field_scope[ $global_id ];
398
- $fields[ $global_id ]['position'] = $count;
399
-
400
- // set position
401
- if ( $position ) {
402
- foreach ( $position as $key => $val ) {
403
- $fields[ $global_id ][ $key ] = $val;
404
- }
405
- }
406
-
407
- // add field to form
408
- UM()->query()->update_attr( 'custom_fields', $form_id, $fields );
409
- }
410
- }
411
-
412
-
413
- /**
414
- * Duplicates a frield by meta key
415
- *
416
- * @param integer $id
417
- * @param integer $form_id
418
- */
419
- function duplicate_field( $id, $form_id ) {
420
- $fields = UM()->query()->get_attr( 'custom_fields', $form_id );
421
- $all_fields = UM()->builtin()->saved_fields;
422
-
423
- $inc = count( $fields ) + 1;
424
-
425
- $duplicate = $fields[ $id ];
426
-
427
- $new_metakey = $id . "_" . $inc;
428
- $new_title = $fields[ $id ]['title'] . " #" . $inc;
429
- $new_position = $inc;
430
-
431
- $duplicate['title'] = $new_title;
432
- $duplicate['metakey'] = $new_metakey;
433
- $duplicate['position'] = $new_position;
434
-
435
- $fields[ $new_metakey ] = $duplicate;
436
- $all_fields[ $new_metakey ] = $duplicate;
437
-
438
- // not global attributes
439
- unset( $all_fields[ $new_metakey ]['in_row'] );
440
- unset( $all_fields[ $new_metakey ]['in_sub_row'] );
441
- unset( $all_fields[ $new_metakey ]['in_column'] );
442
- unset( $all_fields[ $new_metakey ]['in_group'] );
443
- unset( $all_fields[ $new_metakey ]['position'] );
444
-
445
-
446
- do_action( 'um_add_new_field', $new_metakey, $duplicate );
447
-
448
- UM()->query()->update_attr( 'custom_fields', $form_id, $fields );
449
- update_option( 'um_fields', $all_fields );
450
- }
451
-
452
-
453
- /**
454
- * Print field error
455
- *
456
- * @param string $text
457
- * @param bool $force_show
458
- *
459
- * @return string
460
- */
461
- function field_error( $text, $force_show = false ) {
462
-
463
- if ( empty( $text ) ) {
464
- return '';
465
- }
466
-
467
- if ( $force_show ) {
468
- $output = '<div class="um-field-error"><span class="um-field-arrow"><i class="um-faicon-caret-up"></i></span>' . esc_attr( $text ) . '</div>';
469
- return $output;
470
- }
471
-
472
-
473
- if ( isset( $this->set_id ) && UM()->form()->processing == $this->set_id ) {
474
- $output = '<div class="um-field-error"><span class="um-field-arrow"><i class="um-faicon-caret-up"></i></span>' . esc_attr( $text ) . '</div>';
475
- } else {
476
- $output = '';
477
- }
478
-
479
- if ( ! UM()->form()->processing ) {
480
- $output = '<div class="um-field-error"><span class="um-field-arrow"><i class="um-faicon-caret-up"></i></span>' . esc_attr( $text ) . '</div>';
481
- }
482
-
483
- return $output;
484
- }
485
-
486
-
487
- /**
488
- * Print field notice
489
- *
490
- * @param string $text
491
- * @param bool $force_show
492
- *
493
- * @return string
494
- */
495
- function field_notice( $text, $force_show = false ) {
496
-
497
- if ( empty( $text ) ) {
498
- return '';
499
- }
500
-
501
- if ( $force_show ) {
502
- $output = '<div class="um-field-notice"><span class="um-field-arrow"><i class="um-faicon-caret-up"></i></span>' . esc_attr( $text ) . '</div>';
503
- return $output;
504
- }
505
-
506
-
507
- if ( isset( $this->set_id ) && UM()->form()->processing == $this->set_id ) {
508
- $output = '<div class="um-field-notice"><span class="um-field-arrow"><i class="um-faicon-caret-up"></i></span>' . esc_attr( $text ) . '</div>';
509
- } else {
510
- $output = '';
511
- }
512
-
513
- if ( ! UM()->form()->processing ) {
514
- $output = '<div class="um-field-notice"><span class="um-field-arrow"><i class="um-faicon-caret-up"></i></span>' . esc_attr( $text ) . '</div>';
515
- }
516
-
517
- return $output;
518
- }
519
-
520
-
521
- /**
522
- * Checks if field has a server-side error
523
- *
524
- * @param string $key
525
- *
526
- * @return boolean
527
- */
528
- function is_error( $key ) {
529
- return UM()->form()->has_error( $key );
530
- }
531
-
532
- /**
533
- * Checks if field has a notice
534
- *
535
- * @param string $key
536
- *
537
- * @return boolean
538
- */
539
- function is_notice( $key ) {
540
- return UM()->form()->has_notice( $key );
541
- }
542
-
543
-
544
- /**
545
- * Returns field error
546
- *
547
- * @param string $key
548
- *
549
- * @return string
550
- */
551
- function show_error( $key ) {
552
- return UM()->form()->errors[ $key ];
553
- }
554
-
555
- /**
556
- * Returns field notices
557
- *
558
- * @param string $key
559
- *
560
- * @return string
561
- */
562
- function show_notice( $key ) {
563
- return UM()->form()->notices[ $key ];
564
- }
565
-
566
-
567
- /**
568
- * Display field label
569
- *
570
- * @param string $label
571
- * @param string $key
572
- * @param array $data
573
- *
574
- * @return string
575
- */
576
- function field_label( $label, $key, $data ) {
577
- $output = null;
578
- $output .= '<div class="um-field-label">';
579
-
580
- if ( isset( $data['icon'] ) && $data['icon'] != '' && isset( $this->field_icons ) && $this->field_icons != 'off' && ( $this->field_icons == 'label' || $this->viewing == true ) ) {
581
- $output .= '<div class="um-field-label-icon"><i class="' . esc_attr( $data['icon'] ) . '" aria-label="' . esc_attr( $label ) . '"></i></div>';
582
- }
583
-
584
- if ( $this->viewing == true ) {
585
- /**
586
- * UM hook
587
- *
588
- * @type filter
589
- * @title um_view_label_{$key}
590
- * @description Change field label on view by field $key
591
- * @input_vars
592
- * [{"var":"$label","type":"string","desc":"Field Label"}]
593
- * @change_log
594
- * ["Since: 2.0"]
595
- * @usage add_filter( 'um_view_label_{$key}', 'function_name', 10, 1 );
596
- * @example
597
- * <?php
598
- * add_filter( 'um_view_label_{$key}', 'my_view_label', 10, 1 );
599
- * function my_view_label( $label ) {
600
- * // your code here
601
- * return $label;
602
- * }
603
- * ?>
604
- */
605
- $label = apply_filters( "um_view_label_{$key}", $label );
606
- } else {
607
- /**
608
- * UM hook
609
- *
610
- * @type filter
611
- * @title um_edit_label_{$key}
612
- * @description Change field label on edit by field $key
613
- * @input_vars
614
- * [{"var":"$label","type":"string","desc":"Field Label"}]
615
- * @change_log
616
- * ["Since: 2.0"]
617
- * @usage add_filter( 'um_edit_label_{$key}', 'function_name', 10, 1 );
618
- * @example
619
- * <?php
620
- * add_filter( 'um_edit_label_{$key}', 'my_edit_label', 10, 1 );
621
- * function my_edit_label( $label ) {
622
- * // your code here
623
- * return $label;
624
- * }
625
- * ?>
626
- */
627
- $label = apply_filters( "um_edit_label_{$key}", $label );
628
- /**
629
- * UM hook
630
- *
631
- * @type filter
632
- * @title um_edit_label_all_fields
633
- * @description Change field label on view by field $key
634
- * @input_vars
635
- * [{"var":"$label","type":"string","desc":"Field Label"},
636
- * {"var":"$data","type":"array","desc":"Field Data"}]
637
- * @change_log
638
- * ["Since: 2.0"]
639
- * @usage add_filter( 'um_edit_label_all_fields', 'function_name', 10, 2 );
640
- * @example
641
- * <?php
642
- * add_filter( 'um_edit_label_all_fields', 'my_edit_label_all_fields', 10, 2 );
643
- * function my_edit_label_all_fields( $label, $data ) {
644
- * // your code here
645
- * return $label;
646
- * }
647
- * ?>
648
- */
649
- $label = apply_filters( 'um_edit_label_all_fields', $label, $data );
650
- }
651
-
652
- $fields_without_metakey = UM()->builtin()->get_fields_without_metakey();
653
- $for_attr = '';
654
- if ( ! in_array( $data['type'], $fields_without_metakey ) ) {
655
- $for_attr = ' for="' . esc_attr( $key . UM()->form()->form_suffix ) . '"';
656
- }
657
-
658
- $output .= '<label' . $for_attr . '>' . __( $label, 'ultimate-member' ) . '</label>';
659
-
660
- if ( ! empty( $data['help'] ) && $this->viewing == false && ! strstr( $key, 'confirm_user_pass' ) ) {
661
-
662
- if ( ! UM()->mobile()->isMobile() ) {
663
- if ( ! isset( $this->disable_tooltips ) ) {
664
- $output .= '<span class="um-tip um-tip-' . ( is_rtl() ? 'e' : 'w' ) . '" title="' . esc_attr__( $data['help'], 'ultimate-member' ) . '"><i class="um-icon-help-circled"></i></span>';
665
- }
666
- }
667
-
668
- if ( UM()->mobile()->isMobile() || isset( $this->disable_tooltips ) ) {
669
- $output .= '<span class="um-tip-text">' . __( $data['help'], 'ultimate-member' ) . '</span>';
670
- }
671
-
672
- }
673
-
674
- $output .= '<div class="um-clear"></div></div>';
675
-
676
- return $output;
677
- }
678
-
679
-
680
- /**
681
- * Output field classes
682
- *
683
- * @param string $key
684
- * @param array $data
685
- * @param string $add
686
- *
687
- * @return string
688
- */
689
- function get_class( $key, $data, $add = null ) {
690
- $classes = null;
691
-
692
- $classes .= 'um-form-field ';
693
-
694
- if ( $this->is_error( $key ) ) {
695
- $classes .= 'um-error ';
696
- } else {
697
- $classes .= 'valid ';
698
- }
699
-
700
- if ( ! isset( $data['required'] ) ) {
701
- $classes .= 'not-required ';
702
- }
703
-
704
- if ( $data['type'] == 'date' ) {
705
- $classes .= 'um-datepicker ';
706
- }
707
-
708
- if ( $data['type'] == 'time' ) {
709
- $classes .= 'um-timepicker ';
710
- }
711
-
712
- if ( ! empty( $data['icon'] ) && isset( $this->field_icons ) && $this->field_icons == 'field' ) {
713
- $classes .= 'um-iconed ';
714
- }
715
-
716
- if ( $add ) {
717
- $classes .= $add . ' ';
718
- }
719
-
720
- /**
721
- * UM hook
722
- *
723
- * @type filter
724
- * @title um_extend_field_classes
725
- * @description Change field classes
726
- * @input_vars
727
- * [{"var":"$classes","type":"string","desc":"Field Classes"},
728
- * {"var":"$key","type":"string","desc":"Field Key"},
729
- * {"var":"$data","type":"array","desc":"Field Data"}]
730
- * @change_log
731
- * ["Since: 2.0"]
732
- * @usage add_filter( 'um_extend_field_classes', 'function_name', 10, 3 );
733
- * @example
734
- * <?php
735
- * add_filter( 'um_extend_field_classes', 'my_extend_field_classes', 10, 3 );
736
- * function my_extend_field_classes( $classes, $key, $data ) {
737
- * // your code here
738
- * return $classes;
739
- * }
740
- * ?>
741
- */
742
- $classes = apply_filters( 'um_extend_field_classes', $classes, $key, $data );
743
-
744
- return $classes;
745
- }
746
-
747
-
748
- /**
749
- * Gets field value
750
- *
751
- * @param string $key
752
- * @param boolean $default
753
- * @param array $data
754
- *
755
- * @return mixed
756
- */
757
- function field_value( $key, $default = false, $data = null ) {
758
- // preview in backend
759
- if ( isset( UM()->user()->preview ) && UM()->user()->preview ) {
760
- if ( $this->set_mode == 'login' || $this->set_mode == 'register' ) {
761
- return '';
762
- } else {
763
- $val = um_user( $key );
764
- if ( ! empty( $val ) ) {
765
- return $val;
766
- } else {
767
- return '';
768
- }
769
- }
770
- }
771
-
772
- if ( isset( $_SESSION ) && isset( $_SESSION['um_social_profile'][ $key ] ) && isset( $this->set_mode ) && $this->set_mode == 'register' ) {
773
- return $_SESSION['um_social_profile'][ $key ];
774
- }
775
-
776
- $type = ( isset( $data['type'] ) ) ? $data['type'] : '';
777
-
778
- // normal state
779
- if ( isset( UM()->form()->post_form[ $key ] ) ) {
780
- //show empty value for password fields
781
- if ( strstr( $key, 'user_pass' ) && $this->set_mode != 'password' ) {
782
- return '';
783
- }
784
-
785
- if ( 'profile' === $this->set_mode ) {
786
- if ( ! isset( UM()->form()->post_form['profile_nonce'] ) || false === wp_verify_nonce( UM()->form()->post_form['profile_nonce'], 'um-profile-nonce' . UM()->user()->target_id ) ) {
787
- return '';
788
- }
789
- }
790
-
791
- return stripslashes_deep( UM()->form()->post_form[ $key ] );
792
-
793
- } elseif ( um_user( $key ) && $this->editing == true ) {
794
-
795
- //show empty value for password fields
796
- if ( strstr( $key, 'user_pass' ) || $type == 'password' ) {
797
- return '';
798
- }
799
-
800
- $value = um_user( $key );
801
- /**
802
- * UM hook
803
- *
804
- * @type filter
805
- * @title um_edit_{$key}_field_value
806
- * @description Change field value on edit by field $key
807
- * @input_vars
808
- * [{"var":"$value","type":"string","desc":"Field Value"},
809
- * {"var":"$key","type":"string","desc":"Field Key"}]
810
- * @change_log
811
- * ["Since: 2.0"]
812
- * @usage add_filter( 'um_edit_{$key}_field_value', 'function_name', 10, 2 );
813
- * @example
814
- * <?php
815
- * add_filter( 'um_edit_{$key}_field_value', 'my_edit_field_value', 10, 2 );
816
- * function my_edit_field_value( $value, $key ) {
817
- * // your code here
818
- * return $value;
819
- * }
820
- * ?>
821
- */
822
- $value = apply_filters( "um_edit_{$key}_field_value", $value, $key );
823
- /**
824
- * UM hook
825
- *
826
- * @type filter
827
- * @title um_edit_{$type}_field_value
828
- * @description Change field value on edit by field $type
829
- * @input_vars
830
- * [{"var":"$value","type":"string","desc":"Field Value"},
831
- * {"var":"$key","type":"string","desc":"Field Key"}]
832
- * @change_log
833
- * ["Since: 2.0"]
834
- * @usage add_filter( 'um_edit_{$type}_field_value', 'function_name', 10, 2 );
835
- * @example
836
- * <?php
837
- * add_filter( 'um_edit_{$type}_field_value', 'my_edit_field_value', 10, 2 );
838
- * function my_edit_field_value( $value, $key ) {
839
- * // your code here
840
- * return $value;
841
- * }
842
- * ?>
843
- */
844
- $value = apply_filters( "um_edit_{$type}_field_value", $value, $key );
845
-
846
- } elseif ( ( um_user( $key ) || isset( $data['show_anyway'] ) ) && $this->viewing == true ) {
847
-
848
- return um_filtered_value( $key, $data );
849
-
850
- } elseif ( isset( UM()->user()->profile[ $key ] ) ) {
851
-
852
- $value = UM()->user()->profile[ $key ];
853
- /**
854
- * UM hook
855
- *
856
- * @type filter
857
- * @title um_edit_{$key}_field_value
858
- * @description Change field value on edit by field $key
859
- * @input_vars
860
- * [{"var":"$value","type":"string","desc":"Field Value"},
861
- * {"var":"$key","type":"string","desc":"Field Key"}]
862
- * @change_log
863
- * ["Since: 2.0"]
864
- * @usage add_filter( 'um_edit_{$key}_field_value', 'function_name', 10, 2 );
865
- * @example
866
- * <?php
867
- * add_filter( 'um_edit_{$key}_field_value', 'my_edit_field_value', 10, 2 );
868
- * function my_edit_field_value( $value, $key ) {
869
- * // your code here
870
- * return $value;
871
- * }
872
- * ?>
873
- */
874
- $value = apply_filters( "um_edit_{$key}_field_value", $value, $key );
875
- $value = maybe_unserialize( $value );
876
-
877
- } elseif ( $default ) {
878
-
879
- /**
880
- * UM hook
881
- *
882
- * @type filter
883
- * @title um_field_default_value
884
- * @description Change field default value
885
- * @input_vars
886
- * [{"var":"$default","type":"string","desc":"Field Default Value"},
887
- * {"var":"$data","type":"array","desc":"Field Data"},
888
- * {"var":"$type","type":"string","desc":"Field Type"}]
889
- * @change_log
890
- * ["Since: 2.0"]
891
- * @usage add_filter( 'um_field_default_value', 'function_name', 10, 2 );
892
- * @example
893
- * <?php
894
- * add_filter( 'um_field_default_value', 'my_field_default_value', 10, 2 );
895
- * function my_field_default_value( $default, $data, $type ) {
896
- * // your code here
897
- * return $default;
898
- * }
899
- * ?>
900
- */
901
- $default = apply_filters( 'um_field_default_value', $default, $data, $type );
902
- /**
903
- * UM hook
904
- *
905
- * @type filter
906
- * @title um_field_{$key}_default_value
907
- * @description Change field default value by $key
908
- * @input_vars
909
- * [{"var":"$default","type":"string","desc":"Field Default Value"},
910
- * {"var":"$data","type":"array","desc":"Field Data"}]
911
- * @change_log
912
- * ["Since: 2.0"]
913
- * @usage add_filter( 'um_field_{$key}_default_value', 'function_name', 10, 2 );
914
- * @example
915
- * <?php
916
- * add_filter( 'um_field_{$key}_default_value', 'my_field_default_value', 10, 2 );
917
- * function my_field_default_value( $default, $data ) {
918
- * // your code here
919
- * return $default;
920
- * }
921
- * ?>
922
- */
923
- $default = apply_filters( "um_field_{$key}_default_value", $default, $data );
924
- /**
925
- * UM hook
926
- *
927
- * @type filter
928
- * @title um_field_{$type}_default_value
929
- * @description Change field default value by $type
930
- * @input_vars
931
- * [{"var":"$default","type":"string","desc":"Field Default Value"},
932
- * {"var":"$data","type":"array","desc":"Field Data"}]
933
- * @change_log
934
- * ["Since: 2.0"]
935
- * @usage add_filter( 'um_field_{$type}_default_value', 'function_name', 10, 2 );
936
- * @example
937
- * <?php
938
- * add_filter( 'um_field_{$type}_default_value', 'my_field_default_value', 10, 2 );
939
- * function my_field_default_value( $default, $data ) {
940
- * // your code here
941
- * return $default;
942
- * }
943
- * ?>
944
- */
945
- $default = apply_filters( "um_field_{$type}_default_value", $default, $data );
946
-
947
- }
948
-
949
- // Default Value for Registration Form and Profile Form editing
950
- if ( ! isset( $value ) && ( $this->set_mode == 'register' || $this->editing == true ) ) {
951
-
952
- /**
953
- * UM hook
954
- *
955
- * @type filter
956
- * @title um_edit_{$key}_field_value
957
- * @description Change field value on edit by field $key
958
- * @input_vars
959
- * [{"var":"$value","type":"string","desc":"Field Value"},
960
- * {"var":"$key","type":"string","desc":"Field Key"}]
961
- * @change_log
962
- * ["Since: 2.0"]
963
- * @usage add_filter( 'um_edit_{$key}_field_value', 'function_name', 10, 2 );
964
- * @example
965
- * <?php
966
- * add_filter( 'um_edit_{$key}_field_value', 'my_edit_field_value', 10, 2 );
967
- * function my_edit_field_value( $value, $key ) {
968
- * // your code here
969
- * return $value;
970
- * }
971
- * ?>
972
- */
973
- $value = apply_filters( "um_edit_{$key}_field_value", $default, $key );
974
-
975
- } elseif ( isset( $value ) && is_array( $value ) && ! count( $value ) ) {
976
- $value = '';
977
- } elseif ( ! isset( $value ) ) {
978
- $value = '';
979
- }
980
-
981
-
982
- /**
983
- * UM hook
984
- *
985
- * @type filter
986
- * @title um_field_value
987
- * @description Change field value
988
- * @input_vars
989
- * [{"var":"$value","type":"string","desc":"Field Value"},
990
- * {"var":"$key","type":"string","desc":"Field Key"},,
991
- * {"var":"$type","type":"string","desc":"Field Type"}
992
- * {"var":"$default","type":"string","desc":"Field Default Value"},
993
- * {"var":"$data","type":"array","desc":"Field Data"}]
994
- * @usage add_filter( 'um_field_value', 'function_name', 10, 5 );
995
- */
996
- return apply_filters( 'um_field_value', $value, $default, $key, $type, $data );
997
- }
998
-
999
-
1000
- /**
1001
- * Checks if an option is selected
1002
- *
1003
- * is used by Select, Multiselect and Checkbox fields
1004
- *
1005
- * @param string $key
1006
- * @param string $value
1007
- * @param array $data
1008
- *
1009
- * @return boolean
1010
- */
1011
- function is_selected( $key, $value, $data ) {
1012
- global $wpdb;
1013
-
1014
- /**
1015
- * UM hook
1016
- *
1017
- * @type filter
1018
- * @title um_is_selected_filter_key
1019
- * @description Change is selected filter key
1020
- * @input_vars
1021
- * [{"var":"$key","type":"string","desc":"Selected filter key"}]
1022
- * @change_log
1023
- * ["Since: 2.0"]
1024
- * @usage add_filter( 'um_is_selected_filter_key', 'function_name', 10, 1 );
1025
- * @example
1026
- * <?php
1027
- * add_filter( 'um_is_selected_filter_key', 'my_selected_filter_key', 10, 1 );
1028
- * function my_selected_filter_key( $key ) {
1029
- * // your code here
1030
- * return $key;
1031
- * }
1032
- * ?>
1033
- */
1034
- $key = apply_filters( 'um_is_selected_filter_key', $key );
1035
-
1036
- if ( isset( UM()->form()->post_form[ $key ] ) ) {
1037
-
1038
- if ( is_array( UM()->form()->post_form[ $key ] ) ) {
1039
-
1040
- if ( in_array( $value, UM()->form()->post_form[ $key ] ) ) {
1041
- return true;
1042
- }
1043
-
1044
- $stripslashed = array_map( 'stripslashes', UM()->form()->post_form[ $key ] );
1045
- if ( in_array( $value, $stripslashed ) ) {
1046
- return true;
1047
- }
1048
-
1049
- if ( in_array( html_entity_decode( $value ), UM()->form()->post_form[ $key ] ) ) {
1050
- return true;
1051
- }
1052
- } else {
1053
-
1054
- if ( $value == UM()->form()->post_form[ $key ] ) {
1055
- return true;
1056
- }
1057
-
1058
- }
1059
-
1060
- } else {
1061
-
1062
- $field_value = um_user( $key );
1063
- if ( ! $field_value ) {
1064
- $field_value = 0;
1065
- }
1066
-
1067
- if ( $field_value == 0 && $value == '0' ) {
1068
- $value = (int) $value;
1069
- }
1070
-
1071
- if ( strstr( $key, 'role_' ) || $key == 'role' ) {
1072
- $field_value = strtolower( UM()->roles()->get_editable_priority_user_role( um_user( 'ID' ) ) );
1073
-
1074
- $role_keys = get_option( 'um_roles', array() );
1075
-
1076
- if ( ! empty( $role_keys ) ) {
1077
- if ( in_array( $field_value, $role_keys ) ) {
1078
- $field_value = 'um_' . $field_value;
1079
- }
1080
- }
1081
- }
1082
-
1083
-
1084
- /**
1085
- * UM hook
1086
- *
1087
- * @type filter
1088
- * @title um_is_selected_filter_value
1089
- * @description Change is selected filter value
1090
- * @input_vars
1091
- * [{"var":"$value","type":"string","desc":"Selected filter value"},
1092
- * {"var":"$key","type":"string","desc":"Selected filter key"},
1093
- * {"var":"$value","type":"string","desc":"Selected filter value"}]
1094
- * @change_log
1095
- * ["Since: 2.0"]
1096
- * @usage add_filter( 'um_is_selected_filter_value', 'function_name', 10, 2 );
1097
- * @example
1098
- * <?php
1099
- * add_filter( 'um_is_selected_filter_value', 'my_selected_filter_value', 10, 2 );
1100
- * function my_selected_filter_value( $value, $key ) {
1101
- * // your code here
1102
- * return $field_value;
1103
- * }
1104
- * ?>
1105
- */
1106
- $field_value = apply_filters( 'um_is_selected_filter_value', $field_value, $key, $value );
1107
-
1108
- /**
1109
- * UM hook
1110
- *
1111
- * @type filter
1112
- * @title um_is_selected_filter_data
1113
- * @description Change is selected filter data
1114
- * @input_vars
1115
- * [{"var":"$data","type":"array","desc":"Selected filter value"},
1116
- * {"var":"$key","type":"string","desc":"Selected filter key"},
1117
- * {"var":"$value","type":"string","desc":"Selected filter value"}]
1118
- * @change_log
1119
- * ["Since: 2.0"]
1120
- * @usage add_filter( 'um_is_selected_filter_data', 'function_name', 10, 3 );
1121
- * @example
1122
- * <?php
1123
- * add_filter( 'um_is_selected_filter_data', 'my_selected_filter_data', 10, 3 );
1124
- * function my_selected_filter_data( $data, $key, $value ) {
1125
- * // your code here
1126
- * return $data;
1127
- * }
1128
- * ?>
1129
- */
1130
- $data = apply_filters( 'um_is_selected_filter_data', $data, $key, $field_value );
1131
-
1132
- if ( ! $this->editing || 'custom' == $this->set_mode ) {
1133
- // show default on register screen if there is default
1134
- if ( isset( $data['default'] ) ) {
1135
-
1136
- if ( ! is_array( $data['default'] ) && $data['default'] === $value ) {
1137
- return true;
1138
- }
1139
-
1140
- if ( is_array( $data['default'] ) && in_array( $value, $data['default'] ) ) {
1141
- return true;
1142
- }
1143
-
1144
- if ( is_array( $data['default'] ) && array_intersect( $data['options'], $data['default'] ) ) {
1145
- return true;
1146
- }
1147
-
1148
- // default value with comma
1149
- if ( is_string( $data['default'] ) && strstr( $data['default'], ',' ) ) {
1150
- $choices = array_map( 'trim', explode( ',', $data['default'] ) );
1151
- if ( in_array( $value, $choices ) ) {
1152
- return true;
1153
- }
1154
- }
1155
-
1156
- }
1157
- } else {
1158
-
1159
- if ( $field_value && is_array( $field_value ) && ( in_array( $value, $field_value ) || in_array( html_entity_decode( $value ), $field_value ) ) ) {
1160
- return true;
1161
- }
1162
-
1163
- if ( $field_value == 0 && ! is_array( $field_value ) && $field_value === $value ) {
1164
- return true;
1165
- }
1166
-
1167
- if ( $field_value && ! is_array( $field_value ) && $field_value == $value ) {
1168
- return true;
1169
- }
1170
-
1171
- if ( $field_value && ! is_array( $field_value ) && html_entity_decode( $field_value ) == html_entity_decode( $value ) ) {
1172
- return true;
1173
- }
1174
-
1175
- // show default on edit screen if there isn't meta row in usermeta table
1176
- $direct_db_value = $wpdb->get_var( $wpdb->prepare( "SELECT ISNULL( meta_value ) FROM {$wpdb->usermeta} WHERE user_id = %d AND meta_key = %s", um_user( 'ID' ), $key ) );
1177
- if ( ! isset( $direct_db_value ) && isset( $data['default'] ) ) {
1178
- if ( ! is_array( $data['default'] ) && strstr( $data['default'], ', ' ) ) {
1179
- $data['default'] = explode( ', ', $data['default'] );
1180
- }
1181
-
1182
- if ( ! is_array( $data['default'] ) && $data['default'] === $value ) {
1183
- return true;
1184
- }
1185
-
1186
- if ( is_array( $data['default'] ) && in_array( $value, $data['default'] ) ) {
1187
- return true;
1188
- }
1189
- }
1190
- }
1191
-
1192
- }
1193
-
1194
- return false;
1195
- }
1196
-
1197
-
1198
- /**
1199
- * Checks if a radio button is selected
1200
- *
1201
- * @param string $key
1202
- * @param string $value
1203
- * @param array $data
1204
- *
1205
- * @return boolean
1206
- */
1207
- function is_radio_checked( $key, $value, $data ) {
1208
- global $wpdb;
1209
-
1210
- if ( isset( UM()->form()->post_form[ $key ] ) ) {
1211
- if ( is_array( UM()->form()->post_form[ $key ] ) && in_array( $value, UM()->form()->post_form[ $key ] ) ) {
1212
- return true;
1213
- } elseif ( $value == UM()->form()->post_form[ $key ] ) {
1214
- return true;
1215
- }
1216
- } else {
1217
-
1218
- if ( $this->editing && 'custom' !== $this->set_mode ) {
1219
- if ( um_user( $key ) ) {
1220
-
1221
- $um_user_value = um_user( $key );
1222
-
1223
- if ( strstr( $key, 'role_' ) || $key == 'role' ) {
1224
- $um_user_value = strtolower( UM()->roles()->get_editable_priority_user_role( um_user( 'ID' ) ) );
1225
-
1226
- $role_keys = get_option( 'um_roles', array() );
1227
-
1228
- if ( ! empty( $role_keys ) ) {
1229
- if ( in_array( $um_user_value, $role_keys ) ) {
1230
- $um_user_value = 'um_' . $um_user_value;
1231
- }
1232
- }
1233
- }
1234
-
1235
- if ( $um_user_value == $value ) {
1236
- return true;
1237
- }
1238
-
1239
- if ( is_array( $um_user_value ) && in_array( $value, $um_user_value ) ) {
1240
- return true;
1241
- }
1242
-
1243
- if ( is_array( $um_user_value ) ) {
1244
- foreach ( $um_user_value as $u ) {
1245
- if ( $u == html_entity_decode( $value ) ) {
1246
- return true;
1247
- }
1248
- }
1249
- }
1250
- } else {
1251
-
1252
- // show default on edit screen if there isn't meta row in usermeta table
1253
- $direct_db_value = $wpdb->get_var( $wpdb->prepare( "SELECT ISNULL( meta_value ) FROM {$wpdb->usermeta} WHERE user_id = %d AND meta_key = %s", um_user( 'ID' ), $key ) );
1254
- if ( ! isset( $direct_db_value ) && isset( $data['default'] ) && $data['default'] == $value ) {
1255
- return true;
1256
- }
1257
-
1258
- }
1259
- } else {
1260
- if ( isset( $data['default'] ) && $data['default'] == $value ) {
1261
- return true;
1262
- }
1263
- }
1264
- }
1265
-
1266
- return false;
1267
- }
1268
-
1269
-
1270
- /**
1271
- * Get field icon
1272
- *
1273
- * @param string $key
1274
- *
1275
- * @return string
1276
- */
1277
- function get_field_icon( $key ) {
1278
- $fields = UM()->builtin()->all_user_fields;
1279
- if ( isset( $fields[ $key ]['icon'] ) ) {
1280
- return $fields[ $key ]['icon'];
1281
- }
1282
-
1283
- return '';
1284
- }
1285
-
1286
-
1287
- /**
1288
- * Gets selected option value from a callback function
1289
- *
1290
- * @param string $value
1291
- * @param array $data
1292
- * @param string $type
1293
- *
1294
- * @return string
1295
- */
1296
- function get_option_value_from_callback( $value, $data, $type ) {
1297
-
1298
- if ( in_array( $type, array( 'select', 'multiselect' ) ) && ! empty( $data['custom_dropdown_options_source'] ) ) {
1299
-
1300
- $has_custom_source = apply_filters( "um_has_dropdown_options_source__{$data['metakey']}", false );
1301
-
1302
- if ( $has_custom_source ) {
1303
-
1304
- $opts = apply_filters( "um_get_field__{$data['metakey']}", array() );
1305
- $arr_options = $opts['options'];
1306
-
1307
- } elseif ( function_exists( $data['custom_dropdown_options_source'] ) ) {
1308
- if ( isset( $data['parent_dropdown_relationship'] ) ) {
1309
- $_POST['parent_option_name'] = $data['parent_dropdown_relationship'];
1310
- $_POST['parent_option'] = um_user( $data['parent_dropdown_relationship'] );
1311
-
1312
- $arr_options = call_user_func( $data['custom_dropdown_options_source'], $data['parent_dropdown_relationship'] );
1313
- } else {
1314
- $arr_options = call_user_func( $data['custom_dropdown_options_source'] );
1315
- }
1316
- }
1317
-
1318
- if ( $has_custom_source || function_exists( $data['custom_dropdown_options_source'] ) ) {
1319
- if ( $type == 'select' ) {
1320
- if ( ! empty( $arr_options[ $value ] ) ) {
1321
- return $arr_options[ $value ];
1322
- } elseif ( ! empty( $data['default'] ) && empty( $arr_options[ $value ] ) ) {
1323
- return $arr_options[ $data['default'] ];
1324
- } else {
1325
- return '';
1326
- }
1327
- } elseif ( $type == 'multiselect' ) {
1328
-
1329
- if ( is_array( $value ) ) {
1330
- $values = $value;
1331
- } else {
1332
- $values = explode( ', ', $value );
1333
- }
1334
-
1335
- $arr_paired_options = array();
1336
-
1337
- foreach ( $values as $option ) {
1338
- if ( isset( $arr_options[ $option ] ) ) {
1339
- $arr_paired_options[] = $arr_options[ $option ];
1340
- }
1341
- }
1342
-
1343
- return implode( ', ', $arr_paired_options );
1344
- }
1345
- }
1346
-
1347
-
1348
- }
1349
-
1350
- return $value;
1351
- }
1352
-
1353
-
1354
- /**
1355
- * Get select options from a callback function
1356
- *
1357
- * @param array $data
1358
- * @param string $type
1359
- *
1360
- * @return array $arr_options
1361
- */
1362
- function get_options_from_callback( $data, $type ) {
1363
- $arr_options = array();
1364
-
1365
- if ( in_array( $type, array( 'select', 'multiselect' ) ) && ! empty( $data['custom_dropdown_options_source'] ) ) {
1366
-
1367
- if ( function_exists( $data['custom_dropdown_options_source'] ) ) {
1368
- if ( isset( $data['parent_dropdown_relationship'] ) ) {
1369
- $arr_options = call_user_func( $data['custom_dropdown_options_source'], $data['parent_dropdown_relationship'] );
1370
- } else {
1371
- $arr_options = call_user_func( $data['custom_dropdown_options_source'] );
1372
- }
1373
- }
1374
-
1375
- }
1376
-
1377
- return $arr_options;
1378
- }
1379
-
1380
-
1381
- /**
1382
- * Get field type
1383
- *
1384
- * @param string $key
1385
- *
1386
- * @return string
1387
- */
1388
- function get_field_type( $key ) {
1389
- $fields = UM()->builtin()->all_user_fields;
1390
- if ( isset( $fields[ $key ]['type'] ) ) {
1391
- return $fields[ $key ]['type'];
1392
- }
1393
-
1394
- return '';
1395
- }
1396
-
1397
-
1398
- /**
1399
- * Get field label
1400
- *
1401
- * @param string $key
1402
- *
1403
- * @return string
1404
- */
1405
- function get_label( $key ) {
1406
- $label = '';
1407
-
1408
- $fields = UM()->builtin()->all_user_fields;
1409
- if ( isset( $fields[ $key ]['label'] ) ) {
1410
- $label = stripslashes( $fields[ $key ]['label'] );
1411
- }
1412
-
1413
- if ( empty( $label ) && isset( $fields[ $key ]['title'] ) ) {
1414
- $label = stripslashes( $fields[ $key ]['title'] );
1415
- }
1416
-
1417
- /**
1418
- * UM hook
1419
- *
1420
- * @type filter
1421
- * @title um_change_field_label
1422
- * @description Change Field Label
1423
- * @input_vars
1424
- * [{"var":"$label","type":"string","desc":"Field Label"},
1425
- * {"var":"$key","type":"string","desc":"Field Key"}]
1426
- * @change_log
1427
- * ["Since: 2.0.30"]
1428
- * @usage add_filter( 'um_change_field_label', 'function_name', 10, 2 );
1429
- * @example
1430
- * <?php
1431
- * add_filter( 'um_change_field_label', 'my_change_field_label', 10, 2 );
1432
- * function my_form_fields( $label, $key ) {
1433
- * // your code here
1434
- * return $label;
1435
- * }
1436
- * ?>
1437
- */
1438
- $label = apply_filters( 'um_change_field_label', $label, $key );
1439
-
1440
- $label = sprintf( __( '%s', 'ultimate-member' ), $label );
1441
- return $label;
1442
- }
1443
-
1444
-
1445
- /**
1446
- * Get field title
1447
- *
1448
- * @param string $key
1449
- *
1450
- * @return string
1451
- */
1452
- function get_field_title( $key ) {
1453
- $fields = UM()->builtin()->all_user_fields;
1454
- if ( isset( $fields[ $key ]['title'] ) ) {
1455
- return $fields[ $key ]['title'];
1456
- }
1457
- if ( isset( $fields[ $key ]['label'] ) ) {
1458
- return $fields[ $key ]['label'];
1459
- }
1460
-
1461
- return __( 'Custom Field', 'ultimate-member' );
1462
- }
1463
-
1464
-
1465
- /**
1466
- * Get form fields
1467
- *
1468
- * @return array
1469
- */
1470
- function get_fields() {
1471
- /**
1472
- * UM hook
1473
- *
1474
- * @type filter
1475
- * @title um_get_form_fields
1476
- * @description Extend form fields
1477
- * @input_vars
1478
- * [{"var":"$fields","type":"array","desc":"Selected filter value"}]
1479
- * @change_log
1480
- * ["Since: 2.0"]
1481
- * @usage add_filter( 'um_get_form_fields', 'function_name', 10, 1 );
1482
- * @example
1483
- * <?php
1484
- * add_filter( 'um_get_form_fields', 'my_form_fields', 10, 1 );
1485
- * function my_form_fields( $fields ) {
1486
- * // your code here
1487
- * return $fields;
1488
- * }
1489
- * ?>
1490
- */
1491
- $this->fields = apply_filters( 'um_get_form_fields', array() );
1492
- return $this->fields;
1493
- }
1494
-
1495
-
1496
- /**
1497
- * Get specific field
1498
- *
1499
- * @param $key
1500
- *
1501
- * @return mixed
1502
- * @throws \Exception
1503
- */
1504
- function get_field( $key ) {
1505
- $fields = $this->get_fields();
1506
-
1507
- if ( isset( $fields ) && is_array( $fields ) && isset( $fields[ $key ] ) ) {
1508
- $array = $fields[ $key ];
1509
- } else {
1510
- if ( ! isset( UM()->builtin()->predefined_fields[ $key ] ) && ! isset( UM()->builtin()->all_user_fields[ $key ] ) ) {
1511
- return '';
1512
- }
1513
- $array = ( isset( UM()->builtin()->predefined_fields[ $key ] ) ) ? UM()->builtin()->predefined_fields[ $key ] : UM()->builtin()->all_user_fields[ $key ];
1514
- }
1515
-
1516
- $array['classes'] = null;
1517
-
1518
- if ( ! isset( $array['placeholder'] ) ) {
1519
- $array['placeholder'] = null;
1520
- }
1521
- if ( ! isset( $array['required'] ) ) {
1522
- $array['required'] = null;
1523
- }
1524
- if ( ! isset( $array['validate'] ) ) {
1525
- $array['validate'] = null;
1526
- }
1527
- if ( ! isset( $array['default'] ) ) {
1528
- $array['default'] = null;
1529
- }
1530
-
1531
- if ( isset( $array['conditions'] ) && is_array( $array['conditions'] ) && ! $this->viewing ) {
1532
- $array['conditional'] = '';
1533
-
1534
- foreach ( $array['conditions'] as $cond_id => $cond ) {
1535
- $array['conditional'] .= ' data-cond-' . $cond_id . '-action="' . esc_attr( $cond[0] ) . '" data-cond-' . $cond_id . '-field="' . esc_attr( $cond[1] ) . '" data-cond-' . $cond_id . '-operator="' . esc_attr( $cond[2] ) . '" data-cond-' . $cond_id . '-value="' . esc_attr( $cond[3] ) . '"';
1536
- }
1537
-
1538
- $array['classes'] .= ' um-is-conditional';
1539
-
1540
- } else {
1541
- $array['conditional'] = null;
1542
- }
1543
-
1544
- $fields_without_metakey = UM()->builtin()->get_fields_without_metakey();
1545
-
1546
- if ( ! in_array( $array['type'], $fields_without_metakey ) ) {
1547
- $array['classes'] .= ' um-field-' . esc_attr( $key );
1548
- }
1549
- $array['classes'] .= ' um-field-' . esc_attr( $array['type'] );
1550
- $array['classes'] .= ' um-field-type_' . esc_attr( $array['type'] );
1551
-
1552
- switch ( $array['type'] ) {
1553
-
1554
- case 'googlemap':
1555
- case 'youtube_video':
1556
- case 'vimeo_video':
1557
- case 'soundcloud_track':
1558
- $array['disabled'] = '';
1559
- $array['input'] = 'text';
1560
- break;
1561
-
1562
- case 'text':
1563
-
1564
- $array['disabled'] = '';
1565
-
1566
- if ( $key == 'user_login' && isset( $this->set_mode ) && $this->set_mode == 'account' ) {
1567
- $array['disabled'] = 'disabled="disabled"';
1568
- }
1569
-
1570
- $array['input'] = 'text';
1571
-
1572
- break;
1573
-
1574
- case 'password':
1575
-
1576
- $array['input'] = 'password';
1577
-
1578
- break;
1579
-
1580
- case 'number':
1581
-
1582
- $array['disabled'] = '';
1583
-
1584
- break;
1585
-
1586
- case 'url':
1587
-
1588
- $array['input'] = 'text';
1589
-
1590
- break;
1591
-
1592
- case 'date':
1593
-
1594
- $array['input'] = 'text';
1595
-
1596
- if ( ! isset( $array['format'] ) ) {
1597
- $array['format'] = 'j M Y';
1598
- }
1599
-
1600
- switch ( $array['format'] ) {
1601
- case 'j M Y':
1602
- $js_format = 'd mmm yyyy';
1603
- break;
1604
- case 'j F Y':
1605
- $js_format = 'd mmmm yyyy';
1606
- break;
1607
- case 'M j Y':
1608
- $js_format = 'mmm d yyyy';
1609
- break;
1610
- case 'F j Y':
1611
- $js_format = 'mmmm d yyyy';
1612
- break;
1613
- }
1614
-
1615
- $array['js_format'] = $js_format;
1616
-
1617
- if ( ! isset( $array['range'] ) ) {
1618
- $array['range'] = 'years';
1619
- }
1620
- if ( ! isset( $array['years'] ) ) {
1621
- $array['years'] = 100;
1622
- }
1623
- if ( ! isset( $array['years_x'] ) ) {
1624
- $array['years_x'] = 'past';
1625
- }
1626
- if ( ! isset( $array['disabled_weekdays'] ) ) {
1627
- $array['disabled_weekdays'] = '';
1628
- }
1629
-
1630
- if ( ! empty( $array['disabled_weekdays'] ) ) {
1631
- $array['disabled_weekdays'] = '[' . implode( ',', $array['disabled_weekdays'] ) . ']';
1632
- }
1633
-
1634
- // When date range is strictly defined
1635
- if ( $array['range'] == 'date_range' ) {
1636
-
1637
- $array['date_min'] = str_replace( '/', ',', $array['range_start'] );
1638
- $array['date_max'] = str_replace( '/', ',', $array['range_end'] );
1639
-
1640
- } else {
1641
-
1642
- if ( $array['years_x'] == 'past' ) {
1643
-
1644
- $date = new \DateTime( date( 'Y-n-d' ) );
1645
- $past = $date->modify( '-' . $array['years'] . ' years' );
1646
- $past = $date->format( 'Y,n,d' );
1647
-
1648
- $array['date_min'] = $past;
1649
- $array['date_max'] = date( 'Y,n,d' );
1650
-
1651
- } elseif ( $array['years_x'] == 'future' ) {
1652
-
1653
- $date = new \DateTime( date( 'Y-n-d' ) );
1654
- $future = $date->modify( '+' . $array['years'] . ' years' );
1655
- $future = $date->format( 'Y,n,d' );
1656
-
1657
- $array['date_min'] = date( 'Y,n,d' );
1658
- $array['date_max'] = $future;
1659
-
1660
- } else {
1661
-
1662
- $date = new \DateTime( date( 'Y-n-d' ) );
1663
- $date_f = new \DateTime( date( 'Y-n-d' ) );
1664
- $past = $date->modify( '-' . ( $array['years'] / 2 ) . ' years' );
1665
- $past = $date->format( 'Y,n,d' );
1666
- $future = $date_f->modify( '+' . ( $array['years'] / 2 ) . ' years' );
1667
- $future = $date_f->format( 'Y,n,d' );
1668
-
1669
- $array['date_min'] = $past;
1670
- $array['date_max'] = $future;
1671
-
1672
- }
1673
-
1674
- }
1675
-
1676
- break;
1677
-
1678
- case 'time':
1679
-
1680
- $array['input'] = 'text';
1681
-
1682
- if ( ! isset( $array['format'] ) ) {
1683
- $array['format'] = 'g:i a';
1684
- }
1685
-
1686
- switch ( $array['format'] ) {
1687
- case 'g:i a':
1688
- $js_format = 'h:i a';
1689
- break;
1690
- case 'g:i A':
1691
- $js_format = 'h:i A';
1692
- break;
1693
- case 'H:i':
1694
- $js_format = 'HH:i';
1695
- break;
1696
- }
1697
-
1698
- $array['js_format'] = $js_format;
1699
-
1700
- if ( ! isset( $array['intervals'] ) ) {
1701
- $array['intervals'] = 60;
1702
- }
1703
-
1704
- break;
1705
-
1706
- case 'textarea':
1707
-
1708
- if ( ! isset( $array['height'] ) ) {
1709
- $array['height'] = '100px';
1710
- }
1711
-
1712
- break;
1713
-
1714
- case 'rating':
1715
-
1716
- if ( ! isset( $array['number'] ) ) {
1717
- $array['number'] = 5;
1718
- }
1719
-
1720
- break;
1721
-
1722
- case 'spacing':
1723
-
1724
- if ( ! isset( $array['spacing'] ) ) {
1725
- $array['spacing'] = '20px';
1726
- }
1727
-
1728
- break;
1729
-
1730
- case 'divider':
1731
-
1732
- if ( isset( $array['width'] ) ) {
1733
- $array['borderwidth'] = $array['width'];
1734
- } else {
1735
- $array['borderwidth'] = 4;
1736
- }
1737
-
1738
- if ( isset( $array['color'] ) ) {
1739
- $array['bordercolor'] = $array['color'];
1740
- } else {
1741
- $array['bordercolor'] = '#eee';
1742
- }
1743
-
1744
- if ( isset( $array['style'] ) ) {
1745
- $array['borderstyle'] = $array['style'];
1746
- } else {
1747
- $array['borderstyle'] = 'solid';
1748
- }
1749
-
1750
- if ( ! isset( $array['divider_text'] ) ) {
1751
- $array['divider_text'] = '';
1752
- }
1753
-
1754
- break;
1755
-
1756
- case 'image':
1757
-
1758
- if ( ! isset( $array['crop'] ) ) {
1759
- $array['crop'] = 0;
1760
- }
1761
-
1762
- if ( $array['crop'] == 0 ) {
1763
- $array['crop_data'] = 0;
1764
- } elseif ( $array['crop'] == 1 ) {
1765
- $array['crop_data'] = 'square';
1766
- } elseif ( $array['crop'] == 2 ) {
1767
- $array['crop_data'] = 'cover';
1768
- } else {
1769
- $array['crop_data'] = 'user';
1770
- }
1771
-
1772
- if ( ! isset( $array['modal_size'] ) ) {
1773
- $array['modal_size'] = 'normal';
1774
- }
1775
-
1776
- if ( $array['crop'] > 0 ) {
1777
- $array['crop_class'] = 'crop';
1778
- } else {
1779
- $array['crop_class'] = '';
1780
- }
1781
-
1782
- if ( ! isset( $array['ratio'] ) ) {
1783
- $array['ratio'] = 1.0;
1784
- }
1785
-
1786
- if ( ! isset( $array['min_width'] ) ) {
1787
- $array['min_width'] = '';
1788
- }
1789
- if ( ! isset( $array['min_height'] ) ) {
1790
- $array['min_height'] = '';
1791
- }
1792
-
1793
- if ( $array['min_width'] == '' && $array['crop'] == 1 ) {
1794
- $array['min_width'] = 600;
1795
- }
1796
- if ( $array['min_height'] == '' && $array['crop'] == 1 ) {
1797
- $array['min_height'] = 600;
1798
- }
1799
-
1800
- if ( $array['min_width'] == '' && $array['crop'] == 3 ) {
1801
- $array['min_width'] = 600;
1802
- }
1803
- if ( $array['min_height'] == '' && $array['crop'] == 3 ) {
1804
- $array['min_height'] = 600;
1805
- }
1806
-
1807
- if ( ! isset( $array['invalid_image'] ) ) {
1808
- $array['invalid_image'] = __( 'Please upload a valid image!', 'ultimate-member' );
1809
- }
1810
- if ( ! isset( $array['allowed_types'] ) ) {
1811
- $array['allowed_types'] = 'gif,jpg,jpeg,png';
1812
- } else {
1813
- $array['allowed_types'] = implode( ',', $array['allowed_types'] );
1814
- }
1815
- if ( ! isset( $array['upload_text'] ) ) {
1816
- $array['upload_text'] = '';
1817
- }
1818
- if ( ! isset( $array['button_text'] ) ) {
1819
- $array['button_text'] = __( 'Upload', 'ultimate-member' );
1820
- }
1821
- if ( ! isset( $array['extension_error'] ) ) {
1822
- $array['extension_error'] = __( 'Sorry this is not a valid image.', 'ultimate-member' );
1823
- }
1824
- if ( ! isset( $array['max_size_error'] ) ) {
1825
- $array['max_size_error'] = __( 'This image is too large!', 'ultimate-member' );
1826
- }
1827
- if ( ! isset( $array['min_size_error'] ) ) {
1828
- $array['min_size_error'] = __( 'This image is too small!', 'ultimate-member' );
1829
- }
1830
- if ( ! isset( $array['max_files_error'] ) ) {
1831
- $array['max_files_error'] = __( 'You can only upload one image', 'ultimate-member' );
1832
- }
1833
- if ( empty( $array['max_size'] ) ) {
1834
- $array['max_size'] = 999999999;
1835
- }
1836
- if ( ! isset( $array['upload_help_text'] ) ) {
1837
- $array['upload_help_text'] = '';
1838
- }
1839
- if ( ! isset( $array['icon'] ) ) {
1840
- $array['icon'] = '';
1841
- }
1842
-
1843
- break;
1844
-
1845
- case 'file':
1846
-
1847
- if ( ! isset( $array['modal_size'] ) ) {
1848
- $array['modal_size'] = 'normal';
1849
- }
1850
-
1851
- if ( ! isset( $array['allowed_types'] ) ) {
1852
- $array['allowed_types'] = 'pdf,txt';
1853
- } else {
1854
- $array['allowed_types'] = implode( ',', $array['allowed_types'] );
1855
- }
1856
- if ( ! isset( $array['upload_text'] ) ) {
1857
- $array['upload_text'] = '';
1858
- }
1859
- if ( ! isset( $array['button_text'] ) ) {
1860
- $array['button_text'] = __( 'Upload', 'ultimate-member' );
1861
- }
1862
- if ( ! isset( $array['extension_error'] ) ) {
1863
- $array['extension_error'] = __( 'Sorry this is not a valid file.', 'ultimate-member' );
1864
- }
1865
- if ( ! isset( $array['max_size_error'] ) ) {
1866
- $array['max_size_error'] = __( 'This file is too large!', 'ultimate-member' );
1867
- }
1868
- if ( ! isset( $array['min_size_error'] ) ) {
1869
- $array['min_size_error'] = __( 'This file is too small!', 'ultimate-member' );
1870
- }
1871
- if ( ! isset( $array['max_files_error'] ) ) {
1872
- $array['max_files_error'] = __( 'You can only upload one file', 'ultimate-member' );
1873
- }
1874
- if ( empty( $array['max_size'] ) ) {
1875
- $array['max_size'] = 999999999;
1876
- }
1877
- if ( ! isset( $array['upload_help_text'] ) ) {
1878
- $array['upload_help_text'] = '';
1879
- }
1880
- if ( ! isset( $array['icon'] ) ) {
1881
- $array['icon'] = '';
1882
- }
1883
-
1884
- break;
1885
-
1886
- case 'select':
1887
-
1888
- break;
1889
-
1890
- case 'multiselect':
1891
-
1892
- break;
1893
-
1894
- case 'group':
1895
-
1896
- if ( ! isset( $array['max_entries'] ) ) {
1897
- $array['max_entries'] = 0;
1898
- }
1899
-
1900
- break;
1901
-
1902
- }
1903
-
1904
- if ( ! isset( $array['visibility'] ) ) {
1905
- $array['visibility'] = 'all';
1906
- }
1907
-
1908
- /**
1909
- * UM hook
1910
- *
1911
- * @type filter
1912
- * @title um_get_field__{$key}
1913
- * @description Extend field data by field $key
1914
- * @input_vars
1915
- * [{"var":"$data","type":"array","desc":"Field Data"}]
1916
- * @change_log
1917
- * ["Since: 2.0"]
1918
- * @usage add_filter( 'um_get_field__{$key}', 'function_name', 10, 1 );
1919
- * @example
1920
- * <?php
1921
- * add_filter( 'um_get_field__{$key}', 'my_get_field', 10, 1 );
1922
- * function my_get_field( $data ) {
1923
- * // your code here
1924
- * return $data;
1925
- * }
1926
- * ?>
1927
- */
1928
- $array = apply_filters( "um_get_field__{$key}", $array );
1929
-
1930
- return $array;
1931
- }
1932
-
1933
-
1934
- /**
1935
- * @param $option_value
1936
- *
1937
- * @return mixed|void
1938
- */
1939
- function filter_field_non_utf8_value( $option_value ) {
1940
- /**
1941
- * UM hook
1942
- *
1943
- * @type filter
1944
- * @title um_field_non_utf8_value
1945
- * @description Change dropdown option text
1946
- * @input_vars
1947
- * [{"var":"$value","type":"string","desc":"Option Value"}]
1948
- * @change_log
1949
- * ["Since: 2.0"]
1950
- * @usage add_filter( 'um_field_non_utf8_value', 'function_name', 10, 1 );
1951
- * @example
1952
- * <?php
1953
- * add_filter( 'um_field_non_utf8_value', 'my_field_non_utf8_value', 10, 1 );
1954
- * function my_field_non_utf8_value( $value ) {
1955
- * // your code here
1956
- * return $value;
1957
- * }
1958
- * ?>
1959
- */
1960
- return apply_filters( 'um_field_non_utf8_value', $option_value );
1961
- }
1962
-
1963
-
1964
- /**
1965
- * Getting the fields that need to be disabled in edit mode (profile)
1966
- *
1967
- * @param bool $_um_profile_id
1968
- *
1969
- * @return array
1970
- */
1971
- function get_restricted_fields_for_edit( $_um_profile_id = false ) {
1972
- // fields that need to be disabled in edit mode (profile)
1973
- $arr_restricted_fields = array( 'user_email', 'username', 'user_login', 'user_password', '_um_last_login' );
1974
- $arr_restricted_fields = apply_filters( 'um_user_profile_restricted_edit_fields', $arr_restricted_fields, $_um_profile_id );
1975
-
1976
- return $arr_restricted_fields;
1977
- }
1978
-
1979
-
1980
- /**
1981
- * Gets a field in 'input mode'
1982
- *
1983
- * @param string $key
1984
- * @param array $data
1985
- * @param bool $rule
1986
- * @param array $args
1987
- *
1988
- * @return string|null
1989
- * @throws \Exception
1990
- */
1991
- function edit_field( $key, $data, $rule = false, $args = array() ) {
1992
- global $_um_profile_id;
1993
-
1994
- $output = '';
1995
- $disabled = '';
1996
- if ( empty( $_um_profile_id ) ) {
1997
- $_um_profile_id = um_user( 'ID' );
1998
- }
1999
-
2000
- // get whole field data
2001
- if ( isset( $data ) && is_array( $data ) ) {
2002
- $data = $this->get_field( $key );
2003
- if ( is_array( $data ) ) {
2004
- /**
2005
- * @var string $in_row
2006
- * @var boolean $in_sub_row
2007
- * @var boolean $in_column
2008
- * @var string $type
2009
- * @var string $metakey
2010
- * @var int $position
2011
- * @var string $title
2012
- * @var string $help
2013
- * @var array $options
2014
- * @var string $visibility
2015
- * @var string $label
2016
- * @var string $placeholder
2017
- * @var boolean $public
2018
- * @var boolean $editable
2019
- * @var string $icon
2020
- * @var boolean $in_group
2021
- * @var boolean $required
2022
- * @var string $validate
2023
- * @var string $default
2024
- * @var string $conditional
2025
- * @var string $input
2026
- * @var string $js_format
2027
- * @var string $date_max
2028
- * @var string $date_min
2029
- * @var string $disabled_weekdays
2030
- * @var string $years_x
2031
- * @var string $years
2032
- * @var string $range
2033
- * @var string $intervals
2034
- * @var string $height
2035
- * @var string $spacing
2036
- * @var string $borderwidth
2037
- * @var string $borderstyle
2038
- * @var string $bordercolor
2039
- * @var string $divider_text
2040
- * @var string $crop_class
2041
- * @var string $crop_data
2042
- * @var string $modal_size
2043
- * @var string $ratio
2044
- * @var string $min_width
2045
- * @var string $min_height
2046
- * @var string $button_text
2047
- * @var string $max_size
2048
- * @var string $max_size_error
2049
- * @var string $extension_error
2050
- * @var string $allowed_types
2051
- * @var string $upload_text
2052
- * @var string $max_files_error
2053
- * @var string $upload_help_text
2054
- * @var string $min_size_error
2055
- * @var string $filter
2056
- * @var string $content
2057
- * @var string $max_entries
2058
- */
2059
- extract( $data );
2060
- }
2061
- }
2062
-
2063
- if ( ! isset( $data['type'] ) ) {
2064
- return '';
2065
- }
2066
-
2067
- if ( isset( $data['in_group'] ) && $data['in_group'] != '' && $rule != 'group' ) {
2068
- return '';
2069
- }
2070
-
2071
- // forbidden in edit mode? 'edit_forbidden' - it's field attribute predefined in the field data in code
2072
- if ( isset( $data['edit_forbidden'] ) ) {
2073
- return '';
2074
- }
2075
-
2076
- // required option? 'required_opt' - it's field attribute predefined in the field data in code
2077
- if ( isset( $data['required_opt'] ) ) {
2078
- $opt = $data['required_opt'];
2079
- if ( UM()->options()->get( $opt[0] ) != $opt[1] ) {
2080
- return '';
2081
- }
2082
- }
2083
-
2084
- // required user permission 'required_perm' - it's field attribute predefined in the field data in code
2085
- if ( isset( $data['required_perm'] ) ) {
2086
- if ( ! UM()->roles()->um_user_can( $data['required_perm'] ) ) {
2087
- return '';
2088
- }
2089
- }
2090
-
2091
- // fields that need to be disabled in edit mode (profile) (email, username, etc.)
2092
- $arr_restricted_fields = $this->get_restricted_fields_for_edit( $_um_profile_id );
2093
- if ( in_array( $key, $arr_restricted_fields ) && $this->editing == true && $this->set_mode == 'profile' ) {
2094
- return '';
2095
- }
2096
-
2097
-
2098
- if ( $visibility == 'view' && $this->set_mode != 'register' ) {
2099
- return '';
2100
- }
2101
-
2102
- if ( ! um_can_view_field( $data ) ) {
2103
- return '';
2104
- }
2105
-
2106
- um_fetch_user( $_um_profile_id );
2107
-
2108
- // Stop return empty values build field attributes:
2109
-
2110
- if ( $visibility == 'view' && $this->set_mode == 'register' ) {
2111
-
2112
- um_fetch_user( get_current_user_id() );
2113
- if ( ! um_user( 'can_edit_everyone' ) ) {
2114
- $disabled = ' disabled="disabled" ';
2115
- }
2116
-
2117
- um_fetch_user( $_um_profile_id );
2118
- if ( isset( $data['public'] ) && $data['public'] == '-2' && $data['roles'] ) {
2119
- $current_user_roles = um_user( 'roles' );
2120
- if ( ! empty( $current_user_roles ) && count( array_intersect( $current_user_roles, $data['roles'] ) ) > 0 ) {
2121
- $disabled = '';
2122
- }
2123
- }
2124
- }
2125
-
2126
- if ( ! empty( $this->editing ) && $this->set_mode == 'profile' ) {
2127
- if ( ! UM()->roles()->um_user_can( 'can_edit_everyone' ) ) {
2128
- if ( isset( $data['editable'] ) && $data['editable'] == 0 ) {
2129
- $disabled = ' disabled="disabled" ';
2130
- }
2131
- }
2132
- }
2133
-
2134
- $disabled = apply_filters( 'um_is_field_disabled', $disabled, $data );
2135
-
2136
- if ( ! isset( $data['autocomplete'] ) ) {
2137
- $autocomplete = 'off';
2138
- }
2139
-
2140
- if ( isset( $data['classes'] ) ) {
2141
- $classes = explode( " ", $data['classes'] );
2142
- }
2143
-
2144
- um_fetch_user( $_um_profile_id );
2145
-
2146
- /**
2147
- * UM hook
2148
- *
2149
- * @type filter
2150
- * @title um_hook_for_field_{$type}
2151
- * @description Change field type
2152
- * @input_vars
2153
- * [{"var":"$type","type":"string","desc":"Field Type"}]
2154
- * @change_log
2155
- * ["Since: 2.0"]
2156
- * @usage add_filter( 'um_hook_for_field_{$type}', 'function_name', 10, 1 );
2157
- * @example
2158
- * <?php
2159
- * add_filter( 'um_hook_for_field_{$type}', 'my_field_type', 10, 1 );
2160
- * function my_get_field( $type ) {
2161
- * // your code here
2162
- * return $type;
2163
- * }
2164
- * ?>
2165
- */
2166
- $type = apply_filters( "um_hook_for_field_{$type}", $type );
2167
- switch ( $type ) {
2168
-
2169
- case 'textarea':
2170
- case 'multiselect':
2171
- $field_id = $field_name = $key;
2172
- $field_value = $this->field_value( $key, $default, $data );
2173
- break;
2174
-
2175
- case 'select':
2176
- case 'radio':
2177
- $form_key = str_replace( array( 'role_select', 'role_radio' ), 'role', $key );
2178
- $field_id = $form_key;
2179
- break;
2180
- default:
2181
- $field_id = '';
2182
- break;
2183
- }
2184
-
2185
- /**
2186
- * UM hook
2187
- *
2188
- * @type filter
2189
- * @title um_completeness_field_id
2190
- * @description use for change core id not allowed duplicate
2191
- * @input_vars
2192
- * [{"var":"$field_id","type":"string","desc":"Field id"},
2193
- * {"var":"$data","type":"array","desc":"Field Data"}]
2194
- * {"var":"$args","type":"array","desc":"Optional field arguments"}]
2195
- * @change_log
2196
- * ["Since: 2.0.13"]
2197
- * @usage add_filter( 'um_completeness_field_id', 'function_name', 10, 3 );
2198
- * @example
2199
- * <?php
2200
- * add_filter( 'um_completeness_field_id', 'function_name', 10, 3 );
2201
- * function function_name( $field_id, $data, $args ) {
2202
- * // your code here
2203
- * return $field_id;
2204
- * }
2205
- * ?>
2206
- */
2207
- $field_id = apply_filters( 'um_completeness_field_id', $field_id, $data, $args );
2208
-
2209
-
2210
- /* Begin by field type */
2211
- switch ( $type ) {
2212
-
2213
- /* Default: Integration */
2214
- default:
2215
- $mode = ( isset( $this->set_mode ) ) ? $this->set_mode : 'no_mode';
2216
-
2217
- /**
2218
- * UM hook
2219
- *
2220
- * @type filter
2221
- * @title um_edit_field_{$mode}_{$type}
2222
- * @description Change field html by $mode and field $type
2223
- * @input_vars
2224
- * [{"var":"$output","type":"string","desc":"Field HTML"},
2225
- * {"var":"$data","type":"array","desc":"Field Data"}]
2226
- * @change_log
2227
- * ["Since: 2.0"]
2228
- * @usage add_filter( 'um_edit_field_{$mode}_{$type}', 'function_name', 10, 2 );
2229
- * @example
2230
- * <?php
2231
- * add_filter( 'um_edit_field_{$mode}_{$type}', 'my_edit_field_html', 10, 2 );
2232
- * function my_edit_field_html( $output, $data ) {
2233
- * // your code here
2234
- * return $output;
2235
- * }
2236
- * ?>
2237
- */
2238
-
2239
- $output .= apply_filters( "um_edit_field_{$mode}_{$type}", $output, $data );
2240
- break;
2241
-
2242
- /* Other fields */
2243
- case 'googlemap':
2244
- case 'youtube_video':
2245
- case 'vimeo_video':
2246
- case 'soundcloud_track':
2247
-
2248
- $output .= '<div ' . $this->get_atts( $key, $classes, $conditional, $data ) . '>';
2249
-
2250
- if ( isset( $data['label'] ) ) {
2251
- $output .= $this->field_label( $label, $key, $data );
2252
- }
2253
-
2254
- $output .= '<div class="um-field-area">';
2255
-
2256
- if ( ! empty( $icon ) && isset( $this->field_icons ) && $this->field_icons == 'field' ) {
2257
-
2258
- $output .= '<div class="um-field-icon"><i class="' . $icon . '"></i></div>';
2259
-
2260
- }
2261
-
2262
- $field_name = $key . UM()->form()->form_suffix;
2263
- $field_value = htmlspecialchars( $this->field_value( $key, $default, $data ) );
2264
-
2265
- $output .= '<input ' . $disabled . ' class="' . $this->get_class( $key, $data ) . '" type="' . esc_attr( $input ) . '" name="' . esc_attr( $field_name ) . '" id="' . esc_attr( $field_name ) . '" value="' . esc_attr( $field_value ) . '" placeholder="' . esc_attr( $placeholder ) . '" data-validate="' . esc_attr( $validate ) . '" data-key="' . esc_attr( $key ) . '" />
2266
-
2267
- </div>';
2268
-
2269
- if ( ! empty( $disabled ) ) {
2270
- $output .= $this->disabled_hidden_field( $field_name, $field_value );
2271
- }
2272
-
2273
- if ( $this->is_error( $key ) ) {
2274
- $output .= $this->field_error( $this->show_error( $key ) );
2275
- }else if ( $this->is_notice( $key ) ) {
2276
- $output .= $this->field_notice( $this->show_notice( $key ) );
2277
- }
2278
-
2279
- $output .= '</div>';
2280
- break;
2281
-
2282
- /* Text */
2283
- case 'text':
2284
-
2285
- $output .= '<div ' . $this->get_atts( $key, $classes, $conditional, $data ) . '>';
2286
-
2287
- if ( isset( $data['label'] ) ) {
2288
- $output .= $this->field_label( $label, $key, $data );
2289
- }
2290
-
2291
- $output .= '<div class="um-field-area">';
2292
-
2293
- if ( ! empty( $icon ) && isset( $this->field_icons ) && $this->field_icons == 'field' ) {
2294
-
2295
- $output .= '<div class="um-field-icon"><i class="' . esc_attr( $icon ) . '"></i></div>';
2296
-
2297
- }
2298
-
2299
- $field_name = $key . UM()->form()->form_suffix;
2300
- $field_value = htmlspecialchars( $this->field_value( $key, $default, $data ) );
2301
-
2302
- $output .= '<input ' . $disabled . ' autocomplete="' . esc_attr( $autocomplete ) . '" class="' . $this->get_class( $key, $data ) . '" type="' . esc_attr( $input ) . '" name="' . esc_attr( $field_name ) . '" id="' . esc_attr( $field_name ) . '" value="' . esc_attr( $field_value ) . '" placeholder="' . esc_attr( $placeholder ) . '" data-validate="' . esc_attr( $validate ) . '" data-key="' . esc_attr( $key ) . '" />
2303
-
2304
- </div>';
2305
-
2306
- if ( ! empty( $disabled ) ) {
2307
- $output .= $this->disabled_hidden_field( $field_name, $field_value );
2308
- }
2309
-
2310
- if ( $this->is_error( $key ) ) {
2311
- $output .= $this->field_error( $this->show_error( $key ) );
2312
- }else if ( $this->is_notice( $key ) ) {
2313
- $output .= $this->field_notice( $this->show_notice( $key ) );
2314
- }
2315
-
2316
- $output .= '</div>';
2317
- break;
2318
-
2319
- /* Number */
2320
- case 'number':
2321
-
2322
- $output .= '<div ' . $this->get_atts( $key, $classes, $conditional, $data ) . '>';
2323
-
2324
- if ( isset( $data['label'] ) ) {
2325
- $output .= $this->field_label( $label, $key, $data );
2326
- }
2327
-
2328
- $output .= '<div class="um-field-area">';
2329
-
2330
- if ( ! empty( $icon ) && isset( $this->field_icons ) && $this->field_icons == 'field' ) {
2331
-
2332
- $output .= '<div class="um-field-icon"><i class="' . esc_attr( $icon ) . '"></i></div>';
2333
-
2334
- }
2335
-
2336
- $number_limit = '';
2337
- if ( isset( $min ) ) {
2338
- $number_limit .= ' min="' . esc_attr( $min ) . '" ';
2339
- }
2340
- if ( isset( $max ) ) {
2341
- $number_limit .= ' max="' . esc_attr( $max ) . '" ';
2342
- }
2343
-
2344
- $output .= '<input ' . $disabled . ' class="' . $this->get_class( $key, $data ) . '" type="number" name="' . esc_attr( $key . UM()->form()->form_suffix ) . '" id="' . esc_attr( $key . UM()->form()->form_suffix ) . '" value="' . esc_attr( htmlspecialchars( $this->field_value( $key, $default, $data ) ) ) . '" placeholder="' . esc_attr( $placeholder ) . '" data-validate="' . esc_attr( $validate ) . '" data-key="' . esc_attr( $key ) . '" ' . $number_limit . ' />
2345
-
2346
- </div>';
2347
-
2348
- if ( $this->is_error( $key ) ) {
2349
- $output .= $this->field_error( $this->show_error( $key ) );
2350
- }else if ( $this->is_notice( $key ) ) {
2351
- $output .= $this->field_notice( $this->show_notice( $key ) );
2352
- }
2353
-
2354
- $output .= '</div>';
2355
- break;
2356
-
2357
- /* Password */
2358
- case 'password':
2359
-
2360
- $original_key = $key;
2361
-
2362
- if ( $key == 'single_user_password' ) {
2363
-
2364
- $key = $original_key;
2365
-
2366
- $output .= '<div ' . $this->get_atts( $key, $classes, $conditional, $data ) . '>';
2367
-
2368
- if ( isset( $data['label'] ) ) {
2369
- $output .= $this->field_label( $label, $key, $data );
2370
- }
2371
-
2372
- $output .= '<div class="um-field-area">';
2373
-
2374
- if ( ! empty( $icon ) && isset( $this->field_icons ) && $this->field_icons == 'field' ) {
2375
-
2376
- $output .= '<div class="um-field-icon"><i class="' . esc_attr( $icon ) . '"></i></div>';
2377
-
2378
- }
2379
-
2380
- $output .= '<input class="' . $this->get_class( $key, $data ) . '" type="' . esc_attr( $input ) . '" name="' . esc_attr( $key . UM()->form()->form_suffix ) . '" id="' . esc_attr( $key . UM()->form()->form_suffix ) . '" value="' . $this->field_value( $key, $default, $data ) . '" placeholder="' . esc_attr( $placeholder ) . '" data-validate="' . esc_attr( $validate ) . '" data-key="' . esc_attr( $key ) . '" />
2381
-
2382
- </div>';
2383
-
2384
- if ( $this->is_error( $key ) ) {
2385
- $output .= $this->field_error( $this->show_error( $key ) );
2386
- }else if ( $this->is_notice( $key ) ) {
2387
- $output .= $this->field_notice( $this->show_notice( $key ) );
2388
- }
2389
-
2390
- $output .= '</div>';
2391
-
2392
- } else {
2393
-
2394
- if ( UM()->account()->current_password_is_required( 'password' ) &&
2395
- ( $this->set_mode == 'account' || um_is_core_page( 'account' ) ) ) {
2396
-
2397
- $key = 'current_' . $original_key;
2398
- $output .= '<div ' . $this->get_atts( $key, $classes, $conditional, $data ) . '>';
2399
-
2400
- if ( isset( $data['label'] ) ) {
2401
- $output .= $this->field_label( __( 'Current Password', 'ultimate-member' ), $key, $data );
2402
- }
2403
-
2404
- $output .= '<div class="um-field-area">';
2405
-
2406
- if ( ! empty( $icon ) && isset( $this->field_icons ) && $this->field_icons == 'field') {
2407
-
2408
- $output .= '<div class="um-field-icon"><i class="' . esc_attr( $icon ) . '"></i></div>';
2409
-
2410
- }
2411
-
2412
- $output .= '<input class="' . $this->get_class( $key, $data ) . '" type="' . esc_attr( $input ) . '" name="' . esc_attr( $key . UM()->form()->form_suffix ) . '" id="' . esc_attr( $key . UM()->form()->form_suffix ) . '" value="' . $this->field_value( $key, $default, $data ) . '" placeholder="' . esc_attr( $placeholder ) . '" data-validate="' . esc_attr( $validate ) . '" data-key="' . esc_attr( $key ) . '" />
2413
-
2414
- </div>';
2415
-
2416
- if ( $this->is_error( $key ) ) {
2417
- $output .= $this->field_error( $this->show_error( $key ) );
2418
- } elseif ( $this->is_notice( $key ) ) {
2419
- $output .= $this->field_notice( $this->show_notice( $key ) );
2420
- }
2421
-
2422
- $output .= '</div>';
2423
-
2424
- }
2425
-
2426
- $key = $original_key;
2427
-
2428
- $output .= '<div ' . $this->get_atts( $key, $classes, $conditional, $data ) . '>';
2429
-
2430
- if ( $this->set_mode == 'account' && um_is_core_page( 'account' ) || $this->set_mode == 'password' && um_is_core_page( 'password-reset' ) ) {
2431
-
2432
- $output .= $this->field_label( __( 'New Password', 'ultimate-member' ), $key, $data );
2433
-
2434
- } elseif ( isset( $data['label'] ) ) {
2435
-
2436
- $output .= $this->field_label( $label, $key, $data );
2437
-
2438
- }
2439
-
2440
- $output .= '<div class="um-field-area">';
2441
-
2442
- if ( ! empty( $icon ) && isset( $this->field_icons ) && $this->field_icons == 'field') {
2443
-
2444
- $output .= '<div class="um-field-icon"><i class="' . esc_attr( $icon ) . '"></i></div>';
2445
-
2446
- }
2447
-
2448
- $name = $key . UM()->form()->form_suffix;
2449
- if ( $this->set_mode == 'password' && um_is_core_page( 'password-reset' ) ) {
2450
- $name = $key;
2451
- }
2452
-
2453
- $output .= '<input class="' . $this->get_class( $key, $data ) . '" type="' . esc_attr( $input ) . '" name="' . esc_attr( $name ) . '" id="' . esc_attr( $key . UM()->form()->form_suffix ) . '" value="' . $this->field_value( $key, $default, $data ) . '" placeholder="' . esc_attr( $placeholder ) . '" data-validate="' . esc_attr( $validate ) . '" data-key="' . esc_attr( $key ) . '" />
2454
-
2455
- </div>';
2456
-
2457
- if ( $this->is_error( $key ) ) {
2458
- $output .= $this->field_error( $this->show_error( $key ) );
2459
- } elseif ( $this->is_notice( $key ) ) {
2460
- $output .= $this->field_notice( $this->show_notice( $key ) );
2461
- }
2462
-
2463
- $output .= '</div>';
2464
-
2465
- if ( $this->set_mode != 'login' && isset( $data['force_confirm_pass'] ) && $data['force_confirm_pass'] == 1 ) {
2466
-
2467
- $key = 'confirm_' . $original_key;
2468
- $output .= '<div ' . $this->get_atts( $key, $classes, $conditional, $data ) . '>';
2469
-
2470
- if ( ! empty( $data['label_confirm_pass'] ) ) {
2471
- $label_confirm_pass = __( $data['label_confirm_pass'], 'ultimate-member' );
2472
- $output .= $this->field_label( $label_confirm_pass, $key, $data );
2473
- } elseif ( isset( $data['label'] ) ) {
2474
- $data['label'] = __( $data['label'], 'ultimate-member' );
2475
- $output .= $this->field_label( sprintf( __( 'Confirm %s', 'ultimate-member' ), $data['label'] ), $key, $data );
2476
- }
2477
-
2478
- $output .= '<div class="um-field-area">';
2479
-
2480
- if ( ! empty( $icon ) && isset( $this->field_icons ) && $this->field_icons == 'field' ) {
2481
-
2482
- $output .= '<div class="um-field-icon"><i class="' . esc_attr( $icon ) . '"></i></div>';
2483
-
2484
- }
2485
-
2486
- $name = $key . UM()->form()->form_suffix;
2487
- if ( $this->set_mode == 'password' && um_is_core_page( 'password-reset' ) ) {
2488
- $name = $key;
2489
- }
2490
-
2491
- if ( ! empty( $label_confirm_pass ) ) {
2492
- $placeholder = $label_confirm_pass;
2493
- } elseif( ! empty( $placeholder ) && ! isset( $data['label'] ) ) {
2494
- $placeholder = sprintf( __( 'Confirm %s', 'ultimate-member' ), $placeholder );
2495
- } elseif( isset( $data['label'] ) ) {
2496
- $placeholder = sprintf( __( 'Confirm %s', 'ultimate-member' ), $data['label'] );
2497
- }
2498
-
2499
-
2500
- $output .= '<input class="' . $this->get_class( $key, $data ) . '" type="' . esc_attr( $input ) . '" name="' . esc_attr( $name ) . '" id="' . esc_attr( $key . UM()->form()->form_suffix ) . '" value="' . $this->field_value( $key, $default, $data ) . '" placeholder="' . esc_attr( $placeholder ) . '" data-validate="' . esc_attr( $validate ) . '" data-key="' . esc_attr( $key ) . '" />';
2501
-
2502
-
2503
- $output .= '</div>';
2504
-
2505
- if ( $this->is_error( $key ) ) {
2506
- $output .= $this->field_error( $this->show_error( $key ) );
2507
- }else if ( $this->is_notice( $key ) ) {
2508
- $output .= $this->field_notice( $this->show_notice( $key ) );
2509
- }
2510
-
2511
- $output .= '</div>';
2512
-
2513
- }
2514
-
2515
- }
2516
-
2517
- break;
2518
-
2519
- /* URL */
2520
- case 'url':
2521
-
2522
- $output .= '<div ' . $this->get_atts( $key, $classes, $conditional, $data ) . '>';
2523
-
2524
- if ( isset( $data['label'] ) ) {
2525
- $output .= $this->field_label( $label, $key, $data );
2526
- }
2527
-
2528
- $output .= '<div class="um-field-area">';
2529
-
2530
- if ( ! empty( $icon ) && isset( $this->field_icons ) && $this->field_icons == 'field' ) {
2531
-
2532
- $output .= '<div class="um-field-icon"><i class="' . esc_attr( $icon ) . '"></i></div>';
2533
-
2534
- }
2535
-
2536
- $output .= '<input ' . $disabled . ' class="' . $this->get_class( $key, $data ) . '" type="' . esc_attr( $input ) . '" name="' . esc_attr( $key . UM()->form()->form_suffix ) . '" id="' . esc_attr( $key . UM()->form()->form_suffix ) . '" value="' . esc_attr( $this->field_value( $key, $default, $data ) ) . '" placeholder="' . esc_attr( $placeholder ) . '" data-validate="' . esc_attr( $validate ) . '" data-key="' . esc_attr( $key ) . '" />
2537
-
2538
- </div>';
2539
-
2540
- if ( $this->is_error( $key ) ) {
2541
- $output .= $this->field_error( $this->show_error( $key ) );
2542
- }else if ( $this->is_notice( $key ) ) {
2543
- $output .= $this->field_notice( $this->show_notice( $key ) );
2544
- }
2545
-
2546
- $output .= '</div>';
2547
- break;
2548
-
2549
- /* Date */
2550
- case 'date':
2551
-
2552
- $output .= '<div ' . $this->get_atts( $key, $classes, $conditional, $data ) . '>';
2553
-
2554
- if (isset( $data['label'] )) {
2555
- $output .= $this->field_label( $label, $key, $data );
2556
- }
2557
-
2558
- $output .= '<div class="um-field-area">';
2559
-
2560
- if ( ! empty( $icon ) && isset( $this->field_icons ) && $this->field_icons == 'field' ) {
2561
-
2562
- $output .= '<div class="um-field-icon"><i class="' . esc_attr( $icon ) . '"></i></div>';
2563
-
2564
- }
2565
-
2566
- $output .= '<input ' . $disabled . ' class="' . $this->get_class( $key, $data ) . '" type="' . esc_attr( $input ) . '" name="' . esc_attr( $key . UM()->form()->form_suffix ) . '" id="' . esc_attr( $key . UM()->form()->form_suffix ) . '" value="' . $this->field_value( $key, $default, $data ) . '" placeholder="' . esc_attr( $placeholder ) . '" data-validate="' . esc_attr( $validate ) . '" data-key="' . esc_attr( $key ) . '" data-range="' . esc_attr( $range ) . '" data-years="' . esc_attr( $years ) . '" data-years_x="' . esc_attr( $years_x ) . '" data-disabled_weekdays="' . esc_attr( $disabled_weekdays ) . '" data-date_min="' . esc_attr( $date_min ) . '" data-date_max="' . esc_attr( $date_max ) . '" data-format="' . esc_attr( $js_format ) . '" data-value="' . $this->field_value( $key, $default, $data ) . '" />
2567
-
2568
- </div>';
2569
-
2570
- if ( $this->is_error( $key ) ) {
2571
- $output .= $this->field_error( $this->show_error( $key ) );
2572
- }else if ( $this->is_notice( $key ) ) {
2573
- $output .= $this->field_notice( $this->show_notice( $key ) );
2574
- }
2575
-
2576
- $output .= '</div>';
2577
- break;
2578
-
2579
- /* Time */
2580
- case 'time':
2581
-
2582
- $output .= '<div ' . $this->get_atts( $key, $classes, $conditional, $data ) . '>';
2583
-
2584
- if (isset( $data['label'] )) {
2585
- $output .= $this->field_label( $label, $key, $data );
2586
- }
2587
-
2588
- $output .= '<div class="um-field-area">';
2589
-
2590
- if ( ! empty( $icon ) && isset( $this->field_icons ) && $this->field_icons == 'field' ) {
2591
-
2592
- $output .= '<div class="um-field-icon"><i class="' . esc_attr( $icon ) . '"></i></div>';
2593
-
2594
- }
2595
-
2596
- $output .= '<input ' . $disabled . ' class="' . $this->get_class( $key, $data ) . '" type="' . esc_attr( $input ) . '" name="' . esc_attr( $key . UM()->form()->form_suffix ) . '" id="' . esc_attr( $key . UM()->form()->form_suffix ) . '" value="' . $this->field_value( $key, $default, $data ) . '" placeholder="' . esc_attr( $placeholder ) . '" data-validate="' . esc_attr( $validate ) . '" data-key="' . esc_attr( $key ) . '" data-format="' . esc_attr( $js_format ) . '" data-intervals="' . esc_attr( $intervals ) . '" data-value="' . $this->field_value( $key, $default, $data ) . '" />
2597
-
2598
- </div>';
2599
-
2600
- if ( $this->is_error( $key ) ) {
2601
- $output .= $this->field_error( $this->show_error( $key ) );
2602
- }else if ( $this->is_notice( $key ) ) {
2603
- $output .= $this->field_notice( $this->show_notice( $key ) );
2604
- }
2605
-
2606
- $output .= '</div>';
2607
- break;
2608
-
2609
- /* Row */
2610
- case 'row':
2611
- $output .= '';
2612
- break;
2613
-
2614
- /* Textarea */
2615
- case 'textarea':
2616
- $output .= '<div ' . $this->get_atts( $key, $classes, $conditional, $data ) . '>';
2617
-
2618
- if ( isset( $data['label'] ) ) {
2619
- $output .= $this->field_label( $label, $key, $data );
2620
- }
2621
-
2622
- $output .= '<div class="um-field-area">';
2623
-
2624
- if ( isset( $data['html'] ) && $data['html'] != 0 && $key != "description" ) {
2625
-
2626
- $textarea_settings = array(
2627
- 'media_buttons' => false,
2628
- 'wpautop' => false,
2629
- 'editor_class' => $this->get_class( $key, $data ),
2630
- 'editor_height' => $height,
2631
- 'tinymce' => array(
2632
- 'toolbar1' => 'formatselect,bullist,numlist,bold,italic,underline,forecolor,blockquote,hr,removeformat,link,unlink,undo,redo',
2633
- 'toolbar2' => '',
2634
- )
2635
- );
2636
-
2637
- if ( ! empty( $disabled ) ) {
2638
- $textarea_settings['tinymce']['readonly'] = true;
2639
- }
2640
-
2641
- /**
2642
- * UM hook
2643
- *
2644
- * @type filter
2645
- * @title um_form_fields_textarea_settings
2646
- * @description Change WP Editor options for textarea init
2647
- * @input_vars
2648
- * [{"var":"$textarea_settings","type":"array","desc":"WP Editor settings"}]
2649
- * @change_log
2650
- * ["Since: 2.0"]
2651
- * @usage add_filter( 'um_form_fields_textarea_settings', 'function_name', 10, 1 );
2652
- * @example
2653
- * <?php
2654
- * add_filter( 'um_form_fields_textarea_settings', 'my_textarea_settings', 10, 1 );
2655
- * function my_edit_field_html( $textarea_settings ) {
2656
- * // your code here
2657
- * return $textarea_settings;
2658
- * }
2659
- * ?>
2660
- */
2661
- $textarea_settings = apply_filters( 'um_form_fields_textarea_settings', $textarea_settings );
2662
-
2663
- // turn on the output buffer
2664
- ob_start();
2665
-
2666
- // echo the editor to the buffer
2667
- wp_editor( $field_value, $key, $textarea_settings );
2668
-
2669
- // add the contents of the buffer to the output variable
2670
- $output .= ob_get_clean();
2671
- $output .= '<br /><span class="description">' . $placeholder . '</span>';
2672
- } else {
2673
- $textarea_field_value = ! empty( $data['html'] ) ? $field_value : strip_tags( $field_value );
2674
- $output .= '<textarea ' . $disabled . ' style="height: ' . esc_attr( $height ) . ';" class="' . $this->get_class( $key, $data ) . '" name="' . esc_attr( $field_name ) . '" id="' . esc_attr( $field_id ) . '" placeholder="' . esc_attr( $placeholder ) . '">' . esc_textarea( $textarea_field_value ) . '</textarea>';
2675
- }
2676
-
2677
- $output .= '</div>';
2678
-
2679
- if ( ! empty( $disabled ) ) {
2680
- $output .= $this->disabled_hidden_field( $field_name, $field_value );
2681
- }
2682
-
2683
- if ( $this->is_error( $key ) ) {
2684
- $output .= $this->field_error( $this->show_error( $key ) );
2685
- }else if ( $this->is_notice( $key ) ) {
2686
- $output .= $this->field_notice( $this->show_notice( $key ) );
2687
- }
2688
-
2689
- $output .= '</div>';
2690
- break;
2691
-
2692
- /* Rating */
2693
- case 'rating':
2694
- $output .= '<div ' . $this->get_atts( $key, $classes, $conditional, $data ) . '>';
2695
-
2696
- if ( isset( $data['label'] ) ) {
2697
- $output .= $this->field_label( $label, $key, $data );
2698
- }
2699
-
2700
- $output .= '<div class="um-field-area">';
2701
-
2702
- $output .= '<div class="um-rating um-raty" id="' . esc_attr( $key ) . '" data-key="' . esc_attr( $key ) . '" data-number="' . esc_attr( $data['number'] ) . '" data-score="' . $this->field_value( $key, $default, $data ) . '"></div>';
2703
- $output .= '</div>';
2704
-
2705
- if ( $this->is_error( $key ) ) {
2706
- $output .= $this->field_error( $this->show_error( $key ) );
2707
- } elseif ( $this->is_notice( $key ) ) {
2708
- $output .= $this->field_notice( $this->show_notice( $key ) );
2709
- }
2710
-
2711
- $output .= '</div>';
2712
-
2713
- break;
2714
-
2715
- /* Gap/Space */
2716
- case 'spacing':
2717
- $output .= '<div ' . $this->get_atts( $key, $classes, $conditional, $data, array( 'height' => $spacing ) ) . '></div>';
2718
- break;
2719
-
2720
- /* A line divider */
2721
- case 'divider':
2722
- $output .= '<div ' . $this->get_atts( $key, $classes, $conditional, $data, array( 'border-bottom' => $borderwidth . 'px ' . $borderstyle . ' ' . $bordercolor ) ) . '>';
2723
- if ( $divider_text ) {
2724
- $output .= '<div class="um-field-divider-text"><span>' . esc_html( $divider_text ) . '</span></div>';
2725
- }
2726
- $output .= '</div>';
2727
- break;
2728
-
2729
- /* Single Image Upload */
2730
- case 'image':
2731
- $output .= '<div ' . $this->get_atts( $key, $classes, $conditional, $data ) . ' data-mode="' . esc_attr( $this->set_mode ) . '" data-upload-label="' . ( ! empty( $data['button_text'] ) ? esc_attr( $data['button_text'] ) : esc_attr__( 'Upload', 'ultimate-member' ) ) . '">';
2732
- if ( in_array( $key, array( 'profile_photo', 'cover_photo' ) ) ) {
2733
- $field_value = '';
2734
- } else {
2735
- $field_value = $this->field_value( $key, $default, $data );
2736
- }
2737
- $output .= '<input type="hidden" name="' . esc_attr( $key . UM()->form()->form_suffix ) . '" id="' . esc_attr( $key . UM()->form()->form_suffix ) . '" value="' . $field_value . '" />';
2738
- if ( isset( $data['label'] ) ) {
2739
- $output .= $this->field_label( $label, $key, $data );
2740
- }
2741
- $modal_label = ( isset( $data['label'] ) ) ? $data['label'] : __( 'Upload Photo', 'ultimate-member' );
2742
- $output .= '<div class="um-field-area" style="text-align: center;">';
2743
-
2744
- if ( ! empty( $field_value ) && $field_value != 'empty_file' ) {
2745
- if ( ! in_array( $key, array( 'profile_photo', 'cover_photo' ) ) ) {
2746
- if ( isset( $this->set_mode ) && 'register' == $this->set_mode ) {
2747
- $image_info = get_transient("um_{$field_value}");
2748
- } else {
2749
- $image_info = um_user( $data['metakey']."_metadata" );
2750
- }
2751
-
2752
- if ( ( isset( $this->set_mode ) && $this->set_mode == 'register' ) || file_exists( UM()->uploader()->get_core_temp_dir() . DIRECTORY_SEPARATOR . $field_value ) ) {
2753
- $imgValue = UM()->uploader()->get_core_temp_url() . "/" . $this->field_value( $key, $default, $data );
2754
- } else {
2755
- $imgValue = UM()->files()->get_download_link( $this->set_id, $key, um_user( 'ID' ) );
2756
- }
2757
- $img = '<img src="' . $imgValue . '" alt="" />';
2758
- } else {
2759
- $img = '';
2760
- }
2761
- $output .= '<div class="um-single-image-preview show ' . $crop_class . '" data-crop="' . $crop_data . '" data-key="' . $key . '">';
2762
- if ( empty( $disabled ) ) {
2763
- $output .= '<a href="javascript:void(0);" class="cancel"><i class="um-icon-close"></i></a>';
2764
- }
2765
- $output .= $img;
2766
- $output .= '</div>';
2767
- if ( empty( $disabled ) ) {
2768
- $output .= '<a href="javascript:void(0);" data-modal="um_upload_single" data-modal-size="' . $modal_size . '" data-modal-copy="1" class="um-button um-btn-auto-width">' . __( 'Change photo', 'ultimate-member' ) . '</a>';
2769
- }
2770
-
2771
-
2772
- } else {
2773
- $output .= '<div class="um-single-image-preview ' . $crop_class . '" data-crop="' . $crop_data . '" data-key="' . $key . '">';
2774
- if ( empty( $disabled ) ) {
2775
- $output .= '<a href="javascript:void(0);" class="cancel"><i class="um-icon-close"></i></a>';
2776
- }
2777
- $output .= '<img src="" alt="" /><div class="um-clear"></div></div>';
2778
- if ( empty( $disabled ) ) {
2779
- $output .= '<a href="javascript:void(0);" data-modal="um_upload_single" data-modal-size="' . $modal_size . '" data-modal-copy="1" class="um-button um-btn-auto-width">' . $button_text . '</a>';
2780
- }
2781
-
2782
- }
2783
- $output .= '</div>';
2784
- /* modal hidden */
2785
- if ( empty( $disabled ) ) {
2786
- $output .= '<div class="um-modal-hidden-content">';
2787
- $output .= '<div class="um-modal-header"> ' . $modal_label . '</div>';
2788
- $output .= '<div class="um-modal-body">';
2789
- if ( isset( $this->set_id ) ) {
2790
- $set_id = $this->set_id;
2791
- $set_mode = $this->set_mode;
2792
- } else {
2793
- $set_id = 0;
2794
- $set_mode = '';
2795
- }
2796
- $nonce = wp_create_nonce( 'um_upload_nonce-' . $this->timestamp );
2797
- $output .= '<div class="um-single-image-preview ' . $crop_class . '" data-crop="' . $crop_data . '" data-ratio="' . $ratio . '" data-min_width="' . $min_width . '" data-min_height="' . $min_height . '" data-coord=""><a href="javascript:void(0);" class="cancel"><i class="um-icon-close"></i></a><img src="" alt="" /><div class="um-clear"></div></div><div class="um-clear"></div>';
2798
- $output .= '<div class="um-single-image-upload" data-user_id="' . esc_attr( $_um_profile_id ) . '" data-nonce="' . $nonce . '" data-timestamp="' . esc_attr( $this->timestamp ) . '" data-icon="' . esc_attr( $icon ) . '" data-set_id="' . esc_attr( $set_id ) . '" data-set_mode="' . esc_attr( $set_mode ) . '" data-type="' . esc_attr( $type ) . '" data-key="' . esc_attr( $key ) . '" data-max_size="' . esc_attr( $max_size ) . '" data-max_size_error="' . esc_attr( $max_size_error ) . '" data-min_size_error="' . esc_attr( $min_size_error ) . '" data-extension_error="' . esc_attr( $extension_error ) . '" data-allowed_types="' . esc_attr( $allowed_types ) . '" data-upload_text="' . esc_attr( $upload_text ) . '" data-max_files_error="' . esc_attr( $max_files_error ) . '" data-upload_help_text="' . esc_attr( $upload_help_text ) . '">' . $button_text . '</div>';
2799
- $output .= '<div class="um-modal-footer">
2800
- <div class="um-modal-right">
2801
- <a href="javascript:void(0);" class="um-modal-btn um-finish-upload image disabled" data-key="' . $key . '" data-change="' . __( 'Change photo', 'ultimate-member' ) . '" data-processing="' . __( 'Processing...', 'ultimate-member' ) . '"> ' . __( 'Apply', 'ultimate-member' ) . '</a>
2802
- <a href="javascript:void(0);" class="um-modal-btn alt" data-action="um_remove_modal"> ' . __( 'Cancel', 'ultimate-member' ) . '</a>
2803
- </div>
2804
- <div class="um-clear"></div>
2805
- </div>';
2806
- $output .= '</div>';
2807
- $output .= '</div>';
2808
- }
2809
- /* end */
2810
- if ( $this->is_error( $key ) ) {
2811
- $output .= $this->field_error( $this->show_error( $key ) );
2812
- }else if ( $this->is_notice( $key ) ) {
2813
- $output .= $this->field_notice( $this->show_notice( $key ) );
2814
- }
2815
- $output .= '</div>';
2816
-
2817
- break;
2818
-
2819
- /* Single File Upload */
2820
- case 'file':
2821
- $output .= '<div ' . $this->get_atts( $key, $classes, $conditional, $data ) . ' data-mode="' . esc_attr( $this->set_mode ) . '" data-upload-label="' . ( ! empty( $data['button_text'] ) ? esc_attr( $data['button_text'] ) : esc_attr__( 'Upload', 'ultimate-member' ) ) . '">';
2822
- $output .= '<input type="hidden" name="' . esc_attr( $key . UM()->form()->form_suffix ) . '" id="' . esc_attr( $key . UM()->form()->form_suffix ) . '" value="' . $this->field_value( $key, $default, $data ) . '" />';
2823
- if ( isset( $data['label'] ) ) {
2824
- $output .= $this->field_label( $label, $key, $data );
2825
- }
2826
- $modal_label = ( isset( $data['label'] ) ) ? $data['label'] : __( 'Upload File', 'ultimate-member' );
2827
- $output .= '<div class="um-field-area" style="text-align: center;">';
2828
-
2829
- $file_field_value = $this->field_value( $key, $default, $data );
2830
-
2831
- if ( ! empty( $file_field_value ) && 'empty_file' !== $file_field_value ) {
2832
- $file_type = wp_check_filetype( $file_field_value );
2833
-
2834
- if ( um_is_temp_file( $file_field_value ) ) {
2835
- $file_info = get_transient( "um_{$file_field_value}" );
2836
- } else {
2837
- $file_info = um_user( $data['metakey'] . "_metadata" );
2838
- }
2839
-
2840
- $file_field_name = $file_field_value;
2841
- if ( ! empty( $file_info['original_name'] ) ) {
2842
- $file_field_name = $file_info['original_name'];
2843
- }
2844
-
2845
- if ( ( isset( $this->set_mode ) && 'register' == $this->set_mode ) || file_exists( UM()->uploader()->get_core_temp_dir() . DIRECTORY_SEPARATOR . $file_field_value ) ) {
2846
- $file_url = UM()->uploader()->get_core_temp_url() . DIRECTORY_SEPARATOR . $file_field_value;
2847
- $file_dir = UM()->uploader()->get_core_temp_dir() . DIRECTORY_SEPARATOR . $file_field_value;
2848
- } else {
2849
- $file_url = UM()->files()->get_download_link( $this->set_id, $key, um_user( 'ID' ) );
2850
- $file_dir = UM()->uploader()->get_upload_base_dir() . um_user( 'ID' ) . DIRECTORY_SEPARATOR . $this->field_value( $key, $default, $data );
2851
- }
2852
-
2853
- //multisite fix for old customers
2854
- if ( ! file_exists( $file_dir ) && is_multisite() ) {
2855
- $file_dir = str_replace( DIRECTORY_SEPARATOR . 'sites' . DIRECTORY_SEPARATOR . get_current_blog_id() . DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, $file_dir );
2856
- }
2857
-
2858
- if ( file_exists( $file_dir ) ) {
2859
- $output .= "<div class=\"um-single-file-preview show\" data-key=\"{$key}\">";
2860
- if ( empty( $disabled ) ) {
2861
- $output .= "<a href=\"#\" class=\"cancel\"><i class=\"um-icon-close\"></i></a>";
2862
- }
2863
- $output .= "<div class=\"um-single-fileinfo\">
2864
- <a href=\"{$file_url}\" target=\"_blank\">
2865
- <span class=\"icon\" style=\"background:" . UM()->files()->get_fonticon_bg_by_ext( $file_type['ext'] ) . "\"><i class=\"" . UM()->files()->get_fonticon_by_ext( $file_type['ext'] ) . "\"></i></span>
2866
- <span class=\"filename\">{$file_field_name}</span>
2867
- </a>
2868
- </div></div>";
2869
- } else {
2870
- $output .= "<div class=\"um-single-file-preview show\" data-key=\"{$key}\">" . __('This file has been removed.','ultimate-member') . "</div>";
2871
- }
2872
-
2873
- if ( empty( $disabled ) ) {
2874
- $output .= "<a href=\"#\" data-modal=\"um_upload_single\" data-modal-size=\"{$modal_size}\" data-modal-copy=\"1\" class=\"um-button um-btn-auto-width\">" . __( 'Change file', 'ultimate-member' ) . "</a>";
2875
- }
2876
- } else {
2877
- $output .= "<div class=\"um-single-file-preview\" data-key=\"{$key}\"></div>";
2878
- if ( empty( $disabled ) ) {
2879
- $output .= "<a href=\"#\" data-modal=\"um_upload_single\" data-modal-size=\"{$modal_size}\" data-modal-copy=\"1\" class=\"um-button um-btn-auto-width\">{$button_text}</a>";
2880
- }
2881
- }
2882
- $output .= '</div>';
2883
- /* modal hidden */
2884
- if ( empty( $disabled ) ) {
2885
- $output .= '<div class="um-modal-hidden-content">';
2886
- $output .= '<div class="um-modal-header"> ' . $modal_label . '</div>';
2887
- $output .= '<div class="um-modal-body">';
2888
- if ( isset( $this->set_id ) ) {
2889
- $set_id = $this->set_id;
2890
- $set_mode = $this->set_mode;
2891
- } else {
2892
- $set_id = 0;
2893
- $set_mode = '';
2894
- }
2895
- $output .= '<div class="um-single-file-preview">
2896
- <a href="javascript:void(0);" class="cancel"><i class="um-icon-close"></i></a>
2897
- <div class="um-single-fileinfo">
2898
- <a href="" target="_blank">
2899
- <span class="icon"><i></i></span>
2900
- <span class="filename"></span>
2901
- </a>
2902
- </div>
2903
- </div>';
2904
- $nonce = wp_create_nonce( 'um_upload_nonce-' . $this->timestamp );
2905
- $output .= '<div class="um-single-file-upload" data-user_id="' . esc_attr( $_um_profile_id ) . '" data-timestamp="' . esc_attr( $this->timestamp ) . '" data-nonce="' . $nonce . '" data-icon="' . esc_attr( $icon ) . '" data-set_id="' . esc_attr( $set_id ) . '" data-set_mode="' . esc_attr( $set_mode ) . '" data-type="' . esc_attr( $type ) . '" data-key="' . esc_attr( $key ) . '" data-max_size="' . esc_attr( $max_size ) . '" data-max_size_error="' . esc_attr( $max_size_error ) . '" data-min_size_error="' . esc_attr( $min_size_error ) . '" data-extension_error="' . esc_attr( $extension_error ) . '" data-allowed_types="' . esc_attr( $allowed_types ) . '" data-upload_text="' . esc_attr( $upload_text ) . '" data-max_files_error="' . esc_attr( $max_files_error ) . '" data-upload_help_text="' . esc_attr( $upload_help_text ) . '">' . $button_text . '</div>';
2906
- $output .= '<div class="um-modal-footer">
2907
- <div class="um-modal-right">
2908
- <a href="javascript:void(0);" class="um-modal-btn um-finish-upload file disabled" data-key="' . esc_attr( $key ) . '" data-change="' . esc_attr__( 'Change file' ) . '" data-processing="' . esc_attr__( 'Processing...', 'ultimate-member' ) . '"> ' . __( 'Save', 'ultimate-member' ) . '</a>
2909
- <a href="javascript:void(0);" class="um-modal-btn alt" data-action="um_remove_modal"> ' . __( 'Cancel', 'ultimate-member' ) . '</a>
2910
- </div>
2911
- <div class="um-clear"></div>
2912
- </div>';
2913
- $output .= '</div>';
2914
- $output .= '</div>';
2915
- }
2916
- /* end */
2917
- if ( $this->is_error( $key ) ) {
2918
- $output .= $this->field_error( $this->show_error( $key ) );
2919
- }else if ( $this->is_notice( $key ) ) {
2920
- $output .= $this->field_notice( $this->show_notice( $key ) );
2921
- }
2922
- $output .= '</div>';
2923
-
2924
- break;
2925
-
2926
- /* Select dropdown */
2927
- case 'select':
2928
-
2929
- $output .= '<div ' . $this->get_atts( $key, $classes, $conditional, $data ) . '>';
2930
-
2931
- if ( isset( $data['allowclear'] ) && $data['allowclear'] == 0 ) {
2932
- $class = 'um-s2';
2933
- } else {
2934
- $class = 'um-s1';
2935
- }
2936
-
2937
- if ( isset( $data['label'] ) ) {
2938
- $output .= $this->field_label( $label, $key, $data );
2939
- }
2940
-
2941
- $output .= '<div class="um-field-area ' . ( ! empty( $icon ) && isset( $this->field_icons ) && $this->field_icons == 'field' ? 'um-field-area-has-icon' : '' ) . ' ">';
2942
- if ( ! empty( $icon ) && isset( $this->field_icons ) && $this->field_icons == 'field' ) {
2943
- $output .= '<div class="um-field-icon"><i class="' . esc_attr( $icon ) . '"></i></div>';
2944
- }
2945
-
2946
- $options = array();
2947
- $has_parent_option = false;
2948
- $disabled_by_parent_option = '';
2949
- $atts_ajax = '';
2950
- $select_original_option_value = '';
2951
-
2952
- if ( isset( $data[ 'options' ] ) && is_array( $data[ 'options' ] ) ) {
2953
- $options = $data[ 'options' ];
2954
- }
2955
-
2956
- if ( ! empty( $data['parent_dropdown_relationship'] ) && ! UM()->user()->preview ) {
2957
-
2958
- $disabled_by_parent_option = 'disabled = disabled';
2959
-
2960
- $has_parent_option = true;
2961
-
2962
- /**
2963
- * UM hook
2964
- *
2965
- * @type filter
2966
- * @title um_custom_dropdown_options_parent__{$form_key}
2967
- * @description Change parent dropdown relationship by $form_key
2968
- * @input_vars
2969
- * [{"var":"$parent","type":"string","desc":"Parent dropdown relationship"},
2970
- * {"var":"$data","type":"array","desc":"Field Data"}]
2971
- * @change_log
2972
- * ["Since: 2.0"]
2973
- * @usage add_filter( 'um_custom_dropdown_options_parent__{$form_key}', 'function_name', 10, 2 );
2974
- * @example
2975
- * <?php
2976
- * add_filter( 'um_custom_dropdown_options_parent__{$form_key}', 'my_custom_dropdown_options_parent', 10, 2 );
2977
- * function my_custom_dropdown_options_parent( $parent, $data ) {
2978
- * // your code here
2979
- * return $parent;
2980
- * }
2981
- * ?>
2982
- */
2983
- $parent_dropdown_relationship = apply_filters( "um_custom_dropdown_options_parent__{$form_key}", $data['parent_dropdown_relationship'], $data );
2984
- $atts_ajax .= " data-um-parent='{$parent_dropdown_relationship}' ";
2985
-
2986
- if ( ! empty( $data['custom_dropdown_options_source'] ) && $has_parent_option && function_exists( $data['custom_dropdown_options_source'] ) &&
2987
- um_user( $data['parent_dropdown_relationship'] )
2988
- ) {
2989
- $options = call_user_func( $data['custom_dropdown_options_source'], $data['parent_dropdown_relationship'] );
2990
-
2991
- $disabled_by_parent_option = '';
2992
- if ( um_user( $form_key ) ) {
2993
- $select_original_option_value = " data-um-original-value='" . um_user( $form_key ) . "' ";
2994
- }
2995
- }
2996
- }
2997
-
2998
- // Child dropdown option selected
2999
- if ( isset( UM()->form()->post_form[ $form_key ] ) ) {
3000
- $select_original_option_value = " data-um-original-value='" . esc_attr( UM()->form()->post_form[ $form_key ] ) . "' ";
3001
- }
3002
-
3003
- // Child dropdown
3004
- if ( $has_parent_option ) {
3005
-
3006
- if ( ! empty( $data['custom_dropdown_options_source'] ) && $has_parent_option &&
3007
- function_exists( $data['custom_dropdown_options_source'] ) && isset( UM()->form()->post_form[ $form_key ] ) ) {
3008
- $options = call_user_func( $data['custom_dropdown_options_source'], $data['parent_dropdown_relationship'] );
3009
- }
3010
- }
3011
-
3012
- if ( ! empty( $data['custom_dropdown_options_source'] ) ) {
3013
-
3014
- /**
3015
- * UM hook
3016
- *
3017
- * @type filter
3018
- * @title um_custom_dropdown_options_source__{$form_key}
3019
- * @description Change custom dropdown options source by $form_key
3020
- * @input_vars
3021
- * [{"var":"$source","type":"string","desc":"Dropdown options source"},
3022
- * {"var":"$data","type":"array","desc":"Field Data"}]
3023
- * @change_log
3024
- * ["Since: 2.0"]
3025
- * @usage add_filter( 'um_custom_dropdown_options_source__{$form_key}', 'function_name', 10, 2 );
3026
- * @example
3027
- * <?php
3028
- * add_filter( 'um_custom_dropdown_options_source__{$form_key}', 'my_custom_dropdown_options_source', 10, 2 );
3029
- * function my_custom_dropdown_options_source( $source, $data ) {
3030
- * // your code here
3031
- * return $source;
3032
- * }
3033
- * ?>
3034
- */
3035
- $ajax_source = apply_filters( "um_custom_dropdown_options_source__{$form_key}", $data['custom_dropdown_options_source'], $data );
3036
- $atts_ajax .= ' data-um-ajax-source="' . esc_attr( $ajax_source ) . '" ';
3037
-
3038
- /**
3039
- * UM hook
3040
- *
3041
- * @type filter
3042
- * @title um_custom_dropdown_options_source_url__{$form_key}
3043
- * @description Change custom dropdown options source URL by $form_key
3044
- * @input_vars
3045
- * [{"var":"$url","type":"string","desc":"Dropdown options source URL"},
3046
- * {"var":"$data","type":"array","desc":"Field Data"}]
3047
- * @change_log
3048
- * ["Since: 2.0"]
3049
- * @usage add_filter( 'um_custom_dropdown_options_source_url__{$form_key}', 'function_name', 10, 2 );
3050
- * @example
3051
- * <?php
3052
- * add_filter( 'um_custom_dropdown_options_source_url__{$form_key}', 'my_custom_dropdown_options_source_url', 10, 2 );
3053
- * function my_custom_dropdown_options_source( $url, $data ) {
3054
- * // your code here
3055
- * return $url;
3056
- * }
3057
- * ?>
3058
- */
3059
- // todo maybe deprecate
3060
- // $ajax_source_url = apply_filters( "um_custom_dropdown_options_source_url__{$form_key}", admin_url( 'admin-ajax.php' ), $data );
3061
- // $atts_ajax .= ' data-um-ajax-url="' . esc_url( $ajax_source_url ) . '" ';
3062
-
3063
- }
3064
-
3065
- /**
3066
- * UM hook
3067
- *
3068
- * @type filter
3069
- * @title um_fields_options_enable_pairs__{$key}
3070
- * @description Enable options pairs by field $key
3071
- * @input_vars
3072
- * [{"var":"$options_pairs","type":"string","desc":"Enable pairs"}]
3073
- * @change_log
3074
- * ["Since: 2.0"]
3075
- * @usage add_filter( 'um_fields_options_enable_pairs__{$key}', 'function_name', 10, 1 );
3076
- * @example
3077
- * <?php
3078
- * add_filter( 'um_fields_options_enable_pairs__{$key}', 'my_fields_options_enable_pairs', 10, 1 );
3079
- * function my_fields_options_enable_pairs( $options_pairs ) {
3080
- * // your code here
3081
- * return $options_pairs;
3082
- * }
3083
- * ?>
3084
- */
3085
- $enable_options_pair = apply_filters( "um_fields_options_enable_pairs__{$key}", false );
3086
-
3087
- if ( ! $has_parent_option ) {
3088
- if ( isset( $options ) && $options == 'builtin' ) {
3089
- $options = UM()->builtin()->get ( $filter );
3090
- }
3091
-
3092
- // 'country'
3093
- if ( $key === 'country' && empty( $options ) ) {
3094
- $options = UM()->builtin()->get( 'countries' );
3095
- } else if ( empty( $options ) && isset( $data['options'] ) ) {
3096
- $options = $data['options'];
3097
- }
3098
-
3099
- $options = apply_filters( 'um_selectbox_options', $options, $key );
3100
-
3101
- if ( isset( $options ) ) {
3102
- /**
3103
- * UM hook
3104
- *
3105
- * @type filter
3106
- * @title um_select_dropdown_dynamic_options
3107
- * @description Extend dropdown dynamic options
3108
- * @input_vars
3109
- * [{"var":"$options","type":"array","desc":"Dynamic options"},
3110
- * {"var":"$data","type":"array","desc":"Field Data"}]
3111
- * @change_log
3112
- * ["Since: 2.0"]
3113
- * @usage add_filter( 'um_select_dropdown_dynamic_options', 'function_name', 10, 2 );
3114
- * @example
3115
- * <?php
3116
- * add_filter( 'um_select_dropdown_dynamic_options', 'my_select_dropdown_dynamic_options', 10, 2 );
3117
- * function my_select_dropdown_dynamic_options( $options, $data ) {
3118
- * // your code here
3119
- * return $options;
3120
- * }
3121
- * ?>
3122
- */
3123
- $options = apply_filters( 'um_select_dropdown_dynamic_options', $options, $data );
3124
- /**
3125
- * UM hook
3126
- *
3127
- * @type filter
3128
- * @title um_select_dropdown_dynamic_options_{$key}
3129
- * @description Extend dropdown dynamic options by field $key
3130
- * @input_vars
3131
- * [{"var":"$options","type":"array","desc":"Dynamic options"}]
3132
- * @change_log
3133
- * ["Since: 2.0"]
3134
- * @usage add_filter( 'um_select_dropdown_dynamic_options_{$key}', 'function_name', 10, 1 );
3135
- * @example
3136
- * <?php
3137
- * add_filter( 'um_select_dropdown_dynamic_options_{$key}', 'my_select_dropdown_dynamic_options', 10, 1 );
3138
- * function my_select_dropdown_dynamic_options( $options ) {
3139
- * // your code here
3140
- * return $options;
3141
- * }
3142
- * ?>
3143
- */
3144
- $options = apply_filters( "um_select_dropdown_dynamic_options_{$key}", $options );
3145
- }
3146
- }
3147
-
3148
- if ( $form_key === 'role' ) {
3149
- $options = $this->get_available_roles( $form_key, $options );
3150
- }
3151
-
3152
- /**
3153
- * UM hook
3154
- *
3155
- * @type filter
3156
- * @title um_select_option_value
3157
- * @description Enable options pair by field $data
3158
- * @input_vars
3159
- * [{"var":"$options_pair","type":"null","desc":"Enable pairs"},
3160
- * {"var":"$data","type":"array","desc":"Field Data"}]
3161
- */
3162
- $options_pair = apply_filters( 'um_select_options_pair', null, $data );
3163
-
3164
- // switch options pair for custom options from a callback function
3165
- if ( ! empty( $data['custom_dropdown_options_source'] ) ) {
3166
- $options_pair = true;
3167
- }
3168
-
3169
- $field_value = '';
3170
-
3171
- if ( ! empty( $placeholder ) && is_string( $placeholder ) ) {
3172
- $placeholder = strip_tags( $placeholder );
3173
- }
3174
-
3175
- $output .= '<select data-default="' . $data['default'] . '" ' . $disabled . ' ' . $select_original_option_value . ' ' . $disabled_by_parent_option . ' name="' . esc_attr( $form_key ) . '" id="' . esc_attr( $field_id ) . '" data-validate="' . esc_attr( $validate ) . '" data-key="' . esc_attr( $key ) . '" class="' . $this->get_class( $key, $data, $class ) . '" style="width: 100%" data-placeholder="' . esc_attr( $placeholder ) . '" ' . $atts_ajax . '>';
3176
-
3177
- $output .= '<option value=""></option>';
3178
-
3179
- // add options
3180
- if ( ! empty( $options ) ) {
3181
- foreach ( $options as $k => $v ) {
3182
-
3183
- $v = rtrim( $v );
3184
-
3185
- $option_value = $v;
3186
- $um_field_checkbox_item_title = $v;
3187
-
3188
-
3189
- if ( ! is_numeric( $k ) && in_array( $form_key, array( 'role' ) ) ||
3190
- ( $this->set_mode == 'account' || um_is_core_page( 'account' ) ) ) {
3191
- $option_value = $k;
3192
- $um_field_checkbox_item_title = $v;
3193
- }
3194
-
3195
- if ( isset( $options_pair ) ) {
3196
- $option_value = $k;
3197
- $um_field_checkbox_item_title = $v;
3198
- }
3199
-
3200
- $option_value = $this->filter_field_non_utf8_value( $option_value );
3201
-
3202
- $output .= '<option value="' . $option_value . '" ';
3203
-
3204
- if ( $this->is_selected( $form_key, $option_value, $data ) ) {
3205
- $output .= 'selected';
3206
- $field_value = $option_value;
3207
- } elseif ( ! isset( $options_pair ) && $this->is_selected( $form_key, $v, $data ) ) {
3208
- $output .= 'selected';
3209
- $field_value = $v;
3210
- }
3211
-
3212
- $output .= '>' . __( $um_field_checkbox_item_title, 'ultimate-member' ) . '</option>';
3213
- }
3214
- }
3215
-
3216
- if ( ! empty( $disabled ) ) {
3217
- $output .= $this->disabled_hidden_field( $form_key, $field_value );
3218
- }
3219
-
3220
- $output .= '</select>';
3221
-
3222
- $output .= '</div>';
3223
-
3224
-
3225
- if ( $this->is_error( $form_key ) ) {
3226
- $output .= $this->field_error( $this->show_error( $form_key ) );
3227
- } elseif ( $this->is_notice( $form_key ) ) {
3228
- $output .= $this->field_notice( $this->show_notice( $form_key ) );
3229
- }
3230
-
3231
-
3232
- $output .= '</div>';
3233
- break;
3234
-
3235
- /* Multi-Select dropdown */
3236
- case 'multiselect':
3237
-
3238
- $max_selections = ( isset( $max_selections ) ) ? absint( $max_selections ) : 0;
3239
-
3240
- $output .= '<div ' . $this->get_atts( $key, $classes, $conditional, $data ) . '>';
3241
-
3242
- if ( isset( $data['allowclear'] ) && $data['allowclear'] == 0 ) {
3243
- $class = 'um-s2';
3244
- } else {
3245
- $class = 'um-s1';
3246
- }
3247
-
3248
- if ( isset( $data['label'] ) ) {
3249
- $output .= $this->field_label( $label, $key, $data );
3250
- }
3251
-
3252
- $field_icon = false;
3253
- $field_icon_output = '';
3254
-
3255
- /**
3256
- * UM hook
3257
- *
3258
- * @type filter
3259
- * @title um_multiselect_option_value
3260
- * @description Change multiselect keyword data
3261
- * @input_vars
3262
- * [{"var":"$keyword","type":"int","desc":"Option Value"},
3263
- * {"var":"$type","type":"string","desc":"Field Type"}]
3264
- * @change_log
3265
- * ["Since: 2.0"]
3266
- * @usage add_filter( 'um_multiselect_option_value', 'function_name', 10, 2 );
3267
- * @example
3268
- * <?php
3269
- * add_filter( 'um_multiselect_option_value', 'my_multiselect_option_value', 10, 2 );
3270
- * function my_multiselect_option_value( $keyword, $type ) {
3271
- * // your code here
3272
- * return $keyword;
3273
- * }
3274
- * ?>
3275
- */
3276
- $use_keyword = apply_filters( 'um_multiselect_option_value', 0, $data['type'] );
3277
-
3278
- $output .= '<div class="um-field-area ' . (! empty( $icon ) && isset( $this->field_icons ) && $this->field_icons == 'field' ? 'um-field-area-has-icon' : '' ) . ' ">';
3279
- if ( ! empty( $icon ) && isset( $this->field_icons ) && $this->field_icons == 'field') {
3280
- $output .= '<div class="um-field-icon"><i class="' . esc_attr( $icon ) . '"></i></div>';
3281
- }
3282
-
3283
- $output .= '<select ' . $disabled . ' multiple="multiple" name="' . esc_attr( $field_name ) . '[]" id="' . esc_attr( $field_id ) . '" data-maxsize="' . esc_attr( $max_selections ) . '" data-validate="' . esc_attr( $validate ) . '" data-key="' . esc_attr( $key ) . '" class="' . $this->get_class( $key, $data, $class ) . ' um-user-keyword_' . $use_keyword . '" style="width: 100%" data-placeholder="' . esc_attr( $placeholder ) . '">';
3284
-
3285
-
3286
- if ( isset( $options ) && $options == 'builtin' ) {
3287
- $options = UM()->builtin()->get( $filter );
3288
- }
3289
-
3290
- if ( ! isset( $options ) ) {
3291
- $options = UM()->builtin()->get( 'countries' );
3292
- }
3293
-
3294
- if ( isset( $options ) ) {
3295
- /**
3296
- * UM hook
3297
- *
3298
- * @type filter
3299
- * @title um_multiselect_options
3300
- * @description Extend multiselect options
3301
- * @input_vars
3302
- * [{"var":"$options","type":"array","desc":"Multiselect Options"},
3303
- * {"var":"$data","type":"array","desc":"Field Data"}]
3304
- * @change_log
3305
- * ["Since: 2.0"]
3306
- * @usage add_filter( 'um_multiselect_options', 'function_name', 10, 2 );
3307
- * @example
3308
- * <?php
3309
- * add_filter( 'um_multiselect_options', 'my_multiselect_options', 10, 2 );
3310
- * function my_multiselect_options( $options, $data ) {
3311
- * // your code here
3312
- * return $options;
3313
- * }
3314
- * ?>
3315
- */
3316
- $options = apply_filters( 'um_multiselect_options', $options, $data );
3317
- /**
3318
- * UM hook
3319
- *
3320
- * @type filter
3321
- * @title um_multiselect_options_{$key}
3322
- * @description Extend multiselect options by field $key
3323
- * @input_vars
3324
- * [{"var":"$options","type":"array","desc":"Multiselect Options"}]
3325
- * @change_log
3326
- * ["Since: 2.0"]
3327
- * @usage add_filter( 'um_multiselect_options_{$key}', 'function_name', 10, 1 );
3328
- * @example
3329
- * <?php
3330
- * add_filter( 'um_multiselect_options_{$key}', 'my_multiselect_options', 10, 1 );
3331
- * function my_multiselect_options( $options ) {
3332
- * // your code here
3333
- * return $options;
3334
- * }
3335
- * ?>
3336
- */
3337
- $options = apply_filters( "um_multiselect_options_{$key}", $options );
3338
- /**
3339
- * UM hook
3340
- *
3341
- * @type filter
3342
- * @title um_multiselect_options_{$type}
3343
- * @description Extend multiselect options by field $type
3344
- * @input_vars
3345
- * [{"var":"$options","type":"array","desc":"Multiselect Options"},
3346
- * {"var":"$data","type":"array","desc":"Field Data"}]
3347
- * @change_log
3348
- * ["Since: 2.0"]
3349
- * @usage add_filter( 'um_multiselect_options_{$type}', 'function_name', 10, 2 );
3350
- * @example
3351
- * <?php
3352
- * add_filter( 'um_multiselect_options_{$type}', 'my_multiselect_options', 10, 2 );
3353
- * function my_multiselect_option_value( $options, $data ) {
3354
- * // your code here
3355
- * return $options;
3356
- * }
3357
- * ?>
3358
- */
3359
- $options = apply_filters( "um_multiselect_options_{$data['type']}", $options, $data );
3360
- }
3361
-
3362
- /**
3363
- * UM hook
3364
- *
3365
- * @type filter
3366
- * @title um_select_option_value
3367
- * @description Enable options pair by field $data
3368
- * @input_vars
3369
- * [{"var":"$options_pair","type":"null","desc":"Enable pairs"},
3370
- * {"var":"$data","type":"array","desc":"Field Data"}]
3371
- */
3372
- $use_keyword = apply_filters( 'um_select_options_pair', null, $data );
3373
-
3374
- // switch options pair for custom options from a callback function
3375
- if ( ! empty( $data['custom_dropdown_options_source'] ) ) {
3376
- $use_keyword = true;
3377
- }
3378
-
3379
- // add an empty option!
3380
- $output .= '<option value=""></option>';
3381
-
3382
- $arr_selected = array();
3383
- // add options
3384
- if ( ! empty( $options ) && is_array( $options ) ) {
3385
- foreach ( $options as $k => $v ) {
3386
-
3387
- $v = rtrim( $v );
3388
-
3389
- $um_field_checkbox_item_title = $v;
3390
- $opt_value = $v;
3391
-
3392
- if ( $use_keyword ) {
3393
- $um_field_checkbox_item_title = $v;
3394
- $opt_value = $k;
3395
- }
3396
-
3397
- $opt_value = $this->filter_field_non_utf8_value( $opt_value );
3398
-
3399
- $output .= '<option value="' . $opt_value . '" ';
3400
- if ( $this->is_selected( $key, $opt_value, $data ) ) {
3401
-
3402
- $output .= 'selected';
3403
- $arr_selected[ $opt_value ] = $opt_value;
3404
- }
3405
-
3406
- $output .= '>' . __( $um_field_checkbox_item_title, 'ultimate-member' ) . '</option>';
3407
-
3408
- }
3409
- }
3410
-
3411
- $output .= '</select>';
3412
-
3413
- if ( ! empty( $disabled ) && ! empty( $arr_selected ) ) {
3414
- foreach ( $arr_selected as $item ) {
3415
- $output .= $this->disabled_hidden_field( $key . '[]', $item );
3416
- }
3417
- }
3418
-
3419
- $output .= '</div>';
3420
-
3421
-
3422
- if ( $this->is_error( $key ) ) {
3423
- $output .= $this->field_error( $this->show_error( $key ) );
3424
- }else if ( $this->is_notice( $key ) ) {
3425
- $output .= $this->field_notice( $this->show_notice( $key ) );
3426
- }
3427
-
3428
- $output .= '</div>';
3429
- break;
3430
-
3431
- /* Radio */
3432
- case 'radio':
3433
-
3434
- if ( isset( $options ) ) {
3435
- /**
3436
- * UM hook
3437
- *
3438
- * @type filter
3439
- * @title um_radio_field_options
3440
- * @description Extend radio field options
3441
- * @input_vars
3442
- * [{"var":"$options","type":"array","desc":"Radio Field Options"},
3443
- * {"var":"$data","type":"array","desc":"Field Data"}]
3444
- * @change_log
3445
- * ["Since: 2.0"]
3446
- * @usage add_filter( 'um_radio_field_options', 'function_name', 10, 2 );
3447
- * @example
3448
- * <?php
3449
- * add_filter( 'um_radio_field_options', 'my_radio_field_options', 10, 2 );
3450
- * function my_radio_field_options( $options, $data ) {
3451
- * // your code here
3452
- * return $options;
3453
- * }
3454
- * ?>
3455
- */
3456
- $options = apply_filters( 'um_radio_field_options', $options, $data );
3457
- /**
3458
- * UM hook
3459
- *
3460
- * @type filter
3461
- * @title um_radio_field_options_{$key}
3462
- * @description Extend radio field options by field $key
3463
- * @input_vars
3464
- * [{"var":"$options","type":"array","desc":"Radio field Options"}]
3465
- * @change_log
3466
- * ["Since: 2.0"]
3467
- * @usage add_filter( 'um_radio_field_options_{$key}', 'function_name', 10, 1 );
3468
- * @example
3469
- * <?php
3470
- * add_filter( 'um_radio_field_options_{$key}', 'my_radio_field_options', 10, 1 );
3471
- * function my_radio_field_options( $options ) {
3472
- * // your code here
3473
- * return $options;
3474
- * }
3475
- * ?>
3476
- */
3477
- $options = apply_filters( "um_radio_field_options_{$key}", $options );
3478
- }
3479
-
3480
- $output .= '<div ' . $this->get_atts( $key, $classes, $conditional, $data ) . '>';
3481
-
3482
- if ( isset( $data['label'] ) ) {
3483
- $output .= $this->field_label( $label, $key, $data );
3484
- }
3485
-
3486
- $output .= '<div class="um-field-area">';
3487
-
3488
- $options = $this->get_available_roles( $form_key, $options );
3489
-
3490
- // add options
3491
- $i = 0;
3492
- $field_value = array();
3493
-
3494
- /**
3495
- * UM hook
3496
- *
3497
- * @type filter
3498
- * @title um_radio_option_value
3499
- * @description Enable options pair by field $data
3500
- * @input_vars
3501
- * [{"var":"$options_pair","type":"null","desc":"Enable pairs"},
3502
- * {"var":"$data","type":"array","desc":"Field Data"}]
3503
- */
3504
- $options_pair = apply_filters( "um_radio_options_pair__{$key}", false, $data );
3505
-
3506
-
3507
- if ( ! empty( $options ) ) {
3508
- foreach ( $options as $k => $v ) {
3509
-
3510
- $v = rtrim( $v );
3511
-
3512
- $um_field_checkbox_item_title = $v;
3513
- $option_value = $v;
3514
-
3515
- if ( ! is_numeric( $k ) && in_array( $form_key, array( 'role' ) ) ||
3516
- ( $this->set_mode == 'account' || um_is_core_page( 'account' ) ) ) {
3517
- $um_field_checkbox_item_title = $v;
3518
- $option_value = $k;
3519
- }
3520
-
3521
- if( $options_pair ){
3522
- $um_field_checkbox_item_title = $v;
3523
- $option_value = $k;
3524
- }
3525
-
3526
- $i++;
3527
- if ($i % 2 == 0) {
3528
- $col_class = 'right';
3529
- } else {
3530
- $col_class = '';
3531
- }
3532
-
3533
- if ( $this->is_radio_checked( $key, $option_value, $data ) ) {
3534
- $active = 'active';
3535
- $class = "um-icon-android-radio-button-on";
3536
- } else {
3537
- $active = '';
3538
- $class = "um-icon-android-radio-button-off";
3539
- }
3540
-
3541
-
3542
- if ( isset( $data['editable'] ) && $data['editable'] == 0 ) {
3543
- $col_class .= " um-field-radio-state-disabled";
3544
- }
3545
-
3546
- $output .= '<label class="um-field-radio ' . esc_attr( $active ) . ' um-field-half ' . esc_attr( $col_class ) . '">';
3547
-
3548
- $option_value = $this->filter_field_non_utf8_value( $option_value );
3549
-
3550
- $output .= '<input ' . $disabled . ' type="radio" name="' . ( ( $form_key == 'role' ) ? esc_attr( $form_key ) : esc_attr( $form_key ) . '[]' ) . '" value="' . $option_value . '" ';
3551
-
3552
- if ( $this->is_radio_checked( $key, $option_value, $data ) ) {
3553
- $output .= 'checked';
3554
- $field_value[ $key ] = $option_value;
3555
- }
3556
-
3557
- $output .= ' />';
3558
-
3559
- $output .= '<span class="um-field-radio-state"><i class="' . esc_attr( $class ) . '"></i></span>';
3560
- $output .= '<span class="um-field-radio-option">' . esc_html__( $um_field_checkbox_item_title, 'ultimate-member' ) . '</span>';
3561
- $output .= '</label>';
3562
-
3563
- if ( $i % 2 == 0 ) {
3564
- $output .= '<div class="um-clear"></div>';
3565
- }
3566
-
3567
- }
3568
- }
3569
-
3570
- if ( ! empty( $disabled ) ) {
3571
- foreach ( $field_value as $item ) {
3572
- $output .= $this->disabled_hidden_field( $form_key, $item );
3573
- }
3574
- }
3575
-
3576
- $output .= '<div class="um-clear"></div>';
3577
-
3578
- $output .= '</div>';
3579
-
3580
- if ( $this->is_error( $key ) ) {
3581
- $output .= $this->field_error( $this->show_error( $key ) );
3582
- }else if ( $this->is_notice( $key ) ) {
3583
- $output .= $this->field_notice( $this->show_notice( $key ) );
3584
- }
3585
-
3586
- $output .= '</div>';
3587
- break;
3588
-
3589
- /* Checkbox */
3590
- case 'checkbox':
3591
-
3592
- if ( isset( $options ) ) {
3593
- /**
3594
- * UM hook
3595
- *
3596
- * @type filter
3597
- * @title um_checkbox_field_options
3598
- * @description Extend checkbox options
3599
- * @input_vars
3600
- * [{"var":"$options","type":"array","desc":"Checkbox Options"},
3601
- * {"var":"$data","type":"array","desc":"Field Data"}]
3602
- * @change_log
3603
- * ["Since: 2.0"]
3604
- * @usage add_filter( 'um_checkbox_field_options', 'function_name', 10, 2 );
3605
- * @example
3606
- * <?php
3607
- * add_filter( 'um_checkbox_field_options', 'my_checkbox_options', 10, 2 );
3608
- * function my_checkbox_options( $options, $data ) {
3609
- * // your code here
3610
- * return $options;
3611
- * }
3612
- * ?>
3613
- */
3614
- $options = apply_filters( 'um_checkbox_field_options', $options, $data );
3615
- /**
3616
- * UM hook
3617
- *
3618
- * @type filter
3619
- * @title um_checkbox_field_options_{$key}
3620
- * @description Extend checkbox options by field $key
3621
- * @input_vars
3622
- * [{"var":"$options","type":"array","desc":"Checkbox Options"}]
3623
- * @change_log
3624
- * ["Since: 2.0"]
3625
- * @usage add_filter( 'um_checkbox_field_options_{$key}', 'function_name', 10, 1 );
3626
- * @example
3627
- * <?php
3628
- * add_filter( 'um_checkbox_field_options_{$key}', 'my_checkbox_options', 10, 1 );
3629
- * function my_checkbox_options( $options ) {
3630
- * // your code here
3631
- * return $options;
3632
- * }
3633
- * ?>
3634
- */
3635
- $options = apply_filters( "um_checkbox_field_options_{$key}", $options );
3636
- }
3637
-
3638
- $output .= '<div ' . $this->get_atts( $key, $classes, $conditional, $data ) . '>';
3639
-
3640
- if ( isset( $data['label'] ) ) {
3641
- $output .= $this->field_label( $label, $key, $data );
3642
- }
3643
-
3644
- $output .= '<div class="um-field-area">';
3645
-
3646
- // add options
3647
- $i = 0;
3648
-
3649
- foreach ( $options as $k => $v ) {
3650
-
3651
- $v = rtrim( $v );
3652
-
3653
- $i++;
3654
- if ( $i % 2 == 0 ) {
3655
- $col_class = 'right';
3656
- } else {
3657
- $col_class = '';
3658
- }
3659
-
3660
- if ( $this->is_selected( $key, $v, $data ) ) {
3661
- $active = 'active';
3662
- $class = "um-icon-android-checkbox-outline";
3663
- } else {
3664
- $active = '';
3665
- $class = "um-icon-android-checkbox-outline-blank";
3666
- }
3667
-
3668
- if ( isset( $data['editable'] ) && $data['editable'] == 0 ) {
3669
- $col_class .= " um-field-radio-state-disabled";
3670
- }
3671
-
3672
- $output .= '<label class="um-field-checkbox ' . esc_attr( $active ) . ' um-field-half ' . esc_attr( $col_class ) . '">';
3673
-
3674
- $um_field_checkbox_item_title = $v;
3675
-
3676
- $v = $this->filter_field_non_utf8_value( $v );
3677
-
3678
- $output .= '<input ' . $disabled . ' type="checkbox" name="' . esc_attr( $key ) . '[]" value="' . strip_tags( $v ) . '" ';
3679
-
3680
- if ( $this->is_selected( $key, $v, $data ) ) {
3681
- $output .= 'checked';
3682
- }
3683
-
3684
- $output .= ' />';
3685
-
3686
- if ( ! empty( $disabled ) && $this->is_selected( $key, $v, $data ) ) {
3687
- $output .= $this->disabled_hidden_field( $key . '[]', strip_tags( $v ) );
3688
- }
3689
-
3690
-
3691
- $output .= '<span class="um-field-checkbox-state"><i class="' . esc_attr( $class ) . '"></i></span>';
3692
- /**
3693
- * UM hook
3694
- *
3695
- * @type filter
3696
- * @title um_field_checkbox_item_title
3697
- * @description Change Checkbox item title
3698
- * @input_vars
3699
- * [{"var":"$checkbox_item_title","type":"array","desc":"Item Title"},
3700
- * {"var":"$key","type":"string","desc":"Field Key"},
3701
- * {"var":"$value","type":"string","desc":"Field Value"},
3702
- * {"var":"$data","type":"array","desc":"Field Data"}]
3703
- * @change_log
3704
- * ["Since: 2.0"]
3705
- * @usage add_filter( 'um_field_checkbox_item_title', 'function_name', 10, 4 );
3706
- * @example
3707
- * <?php
3708
- * add_filter( 'um_field_checkbox_item_title', 'my_checkbox_item_title', 10, 4 );
3709
- * function my_checkbox_item_title( $checkbox_item_title, $key, $value, $data ) {
3710
- * // your code here
3711
- * return $checkbox_item_title;
3712
- * }
3713
- * ?>
3714
- */
3715
- $um_field_checkbox_item_title = apply_filters( 'um_field_checkbox_item_title', $um_field_checkbox_item_title, $key, $v, $data );
3716
- $output .= '<span class="um-field-checkbox-option">' . __( $um_field_checkbox_item_title, 'ultimate-member' ) . '</span>';
3717
- $output .= '</label>';
3718
-
3719
- if ( $i % 2 == 0 ) {
3720
- $output .= '<div class="um-clear"></div>';
3721
- }
3722
-
3723
- }
3724
-
3725
- $output .= '<div class="um-clear"></div>';
3726
-
3727
- $output .= '</div>';
3728
-
3729
-
3730
- if ( $this->is_error( $key ) ) {
3731
- $output .= $this->field_error( $this->show_error( $key ) );
3732
- }else if ( $this->is_notice( $key ) ) {
3733
- $output .= $this->field_notice( $this->show_notice( $key ) );
3734
- }
3735
-
3736
- $output .= '</div>';
3737
- break;
3738
-
3739
- /* HTML */
3740
- case 'block':
3741
- $output .= '<div ' . $this->get_atts( $key, $classes, $conditional, $data ) . '>' . $content . '</div>';
3742
- break;
3743
-
3744
- /* Shortcode */
3745
- case 'shortcode':
3746
-
3747
- $content = str_replace( '{profile_id}', um_profile_id(), $content );
3748
- if ( version_compare( get_bloginfo('version'),'5.4', '<' ) ) {
3749
- $content = do_shortcode( $content );
3750
- } else {
3751
- $content = apply_shortcodes( $content );
3752
- }
3753
-
3754
- $output .= '<div ' . $this->get_atts( $key, $classes, $conditional, $data ) . '>' . $content . '</div>';
3755
- break;
3756
-
3757
- /* Unlimited Group */
3758
- case 'group':
3759
-
3760
- $fields = $this->get_fields_in_group( $key );
3761
- if ( ! empty( $fields ) ) {
3762
-
3763
- $output .= '<div class="um-field-group" data-max_entries="' . $max_entries . '">
3764
- <div class="um-field-group-head"><i class="um-icon-plus"></i>' . esc_html__( $label, 'ultimate-member' ) . '</div>';
3765
- $output .= '<div class="um-field-group-body"><a href="javascript:void(0);" class="um-field-group-cancel"><i class="um-icon-close"></i></a>';
3766
-
3767
- foreach ( $fields as $subkey => $subdata ) {
3768
- $output .= $this->edit_field( $subkey, $subdata, 'group' );
3769
- }
3770
-
3771
- $output .= '</div>';
3772
- $output .= '</div>';
3773
-
3774
- }
3775
-
3776
- break;
3777
-
3778
- }
3779
-
3780
- // Custom filter for field output
3781
- if ( isset( $this->set_mode ) ) {
3782
- /**
3783
- * UM hook
3784
- *
3785
- * @type filter
3786
- * @title um_{$key}_form_edit_field
3787
- * @description Change field HTML on edit mode by field $key
3788
- * @input_vars
3789
- * [{"var":"$output","type":"string","desc":"Field HTML"},
3790
- * {"var":"$mode","type":"string","desc":"Fields Mode"}]
3791
- * @change_log
3792
- * ["Since: 2.0"]
3793
- * @usage add_filter( 'um_{$key}_form_edit_field', 'function_name', 10, 2 );
3794
- * @example
3795
- * <?php
3796
- * add_filter( 'um_{$key}_form_edit_field', 'my_form_edit_field', 10, 2 );
3797
- * function my_form_edit_field( $output, $mode ) {
3798
- * // your code here
3799
- * return $output;
3800
- * }
3801
- * ?>
3802
- */
3803
- $output = apply_filters( "um_{$key}_form_edit_field", $output, $this->set_mode );
3804
- }
3805
-
3806
- return $output;
3807
- }
3808
-
3809
-
3810
- /**
3811
- * Filter for user roles
3812
- *
3813
- * @param $form_key
3814
- * @param array $options
3815
- * @return array
3816
- */
3817
- function get_available_roles( $form_key, $options = array() ) {
3818
- if ( $form_key != 'role' ) {
3819
- return $options;
3820
- }
3821
-
3822
- // role field
3823
- global $wp_roles;
3824
- $role_keys = array_map( function( $item ) {
3825
- return 'um_' . $item;
3826
- }, get_option( 'um_roles', array() ) );
3827
- $exclude_roles = array_diff( array_keys( $wp_roles->roles ), array_merge( $role_keys, array( 'subscriber' ) ) );
3828
-
3829
- $roles = UM()->roles()->get_roles( false, $exclude_roles );
3830
-
3831
- if ( ! empty( $options ) ) {
3832
-
3833
- $roles = array_map( function( $item ) {
3834
- return html_entity_decode( $item, ENT_QUOTES );
3835
- }, $roles );
3836
-
3837
- //fix when customers change options for role (radio/dropdown) fields
3838
- $intersected_options = array();
3839
- foreach ( $options as $key => $title ) {
3840
- if ( false !== $search_key = array_search( $title, $roles ) ) {
3841
- $intersected_options[ $search_key ] = $title;
3842
- } elseif ( isset( $roles[ $key ] ) ) {
3843
- $intersected_options[ $key ] = $title;
3844
- }
3845
- }
3846
-
3847
- $options = $intersected_options;
3848
- } else {
3849
- $options = $roles;
3850
- }
3851
-
3852
- return $options;
3853
- }
3854
-
3855
-
3856
- /**
3857
- * Sorts columns array
3858
- *
3859
- * @param array $arr
3860
- * @param string $col
3861
- * @param string $dir
3862
- *
3863
- * @return array $arr
3864
- */
3865
- function array_sort_by_column( $arr, $col, $dir = SORT_ASC ) {
3866
- $sort_col = array();
3867
- foreach ( $arr as $key => $row ) {
3868
- if ( $key == 'form_id' ) {
3869
- unset( $arr['form_id'] );
3870
- continue;
3871
- }
3872
-
3873
- if ( isset( $row[ $col ] ) ) {
3874
- $sort_col[ $key ] = $row[ $col ];
3875
- } else {
3876
- unset( $arr[ $key ] );
3877
- }
3878
- }
3879
-
3880
- array_multisort( $sort_col, $dir, $arr );
3881
-
3882
- return $arr;
3883
- }
3884
-
3885
-
3886
- /**
3887
- * Get fields in row
3888
- *
3889
- * @param int $row_id
3890
- *
3891
- * @return string
3892
- */
3893
- function get_fields_by_row( $row_id ) {
3894
- if ( ! isset( $this->get_fields ) ) {
3895
- return '';
3896
- }
3897
-
3898
- foreach ( $this->get_fields as $key => $array ) {
3899
- if ( ! isset( $array['in_row'] ) || ( isset( $array['in_row'] ) && $array['in_row'] == $row_id ) ) {
3900
- $results[ $key ] = $array;
3901
- }
3902
- }
3903
-
3904
- return ( isset ( $results ) ) ? $results : '';
3905
- }
3906
-
3907
-
3908
- /**
3909
- * Get fields by sub row
3910
- *
3911
- * @param string $row_fields
3912
- * @param integer $subrow_id
3913
- *
3914
- * @return mixed
3915
- */
3916
- function get_fields_in_subrow( $row_fields, $subrow_id ) {
3917
- if ( ! is_array( $row_fields ) ) {
3918
- return '';
3919
- }
3920
- foreach ( $row_fields as $key => $array ) {
3921
- if ( ! isset( $array['in_sub_row'] ) || ( isset( $array['in_sub_row'] ) && $array['in_sub_row'] == $subrow_id ) ) {
3922
- $results[ $key ] = $array;
3923
- }
3924
- }
3925
-
3926
- return ( isset ( $results ) ) ? $results : '';
3927
- }
3928
-
3929
-
3930
- /**
3931
- * Get fields in group
3932
- *
3933
- * @param integer $group_id
3934
- *
3935
- * @return mixed
3936
- */
3937
- function get_fields_in_group( $group_id ) {
3938
- foreach ( $this->get_fields as $key => $array ) {
3939
- if ( isset( $array['in_group'] ) && $array['in_group'] == $group_id ) {
3940
- $results[ $key ] = $array;
3941
- }
3942
- }
3943
-
3944
- return ( isset ( $results ) ) ? $results : '';
3945
- }
3946
-
3947
-
3948
- /**
3949
- * Get fields in column
3950
- *
3951
- * @param array $fields
3952
- * @param integer $col_number
3953
- *
3954
- * @return mixed
3955
- */
3956
- function get_fields_in_column( $fields, $col_number ) {
3957
- foreach ( $fields as $key => $array ) {
3958
- if ( isset( $array['in_column'] ) && $array['in_column'] == $col_number ) {
3959
- $results[ $key ] = $array;
3960
- }
3961
- }
3962
-
3963
- return ( isset ( $results ) ) ? $results : '';
3964
- }
3965
-
3966
-
3967
- /**
3968
- * Display fields
3969
- *
3970
- * @param string $mode
3971
- * @param array $args
3972
- *
3973
- * @return string|null
3974
- * @throws \Exception
3975
- */
3976
- function display( $mode, $args ) {
3977
- $output = null;
3978
-
3979
- $this->global_args = $args;
3980
-
3981
- UM()->form()->form_suffix = '-' . $this->global_args['form_id'];
3982
-
3983
- $this->set_mode = $mode;
3984
-
3985
- if ( 'profile' === $mode ) {
3986
- UM()->form()->nonce = wp_create_nonce( 'um-profile-nonce' . UM()->user()->target_id );
3987
- }
3988
-
3989
- $this->set_id = $this->global_args['form_id'];
3990
-
3991
- $this->field_icons = ( isset( $this->global_args['icons'] ) ) ? $this->global_args['icons'] : 'label';
3992
-
3993
- // start output here
3994
- $this->get_fields = $this->get_fields();
3995
-
3996
- if ( ! empty( $this->get_fields ) ) {
3997
-
3998
- // find rows
3999
- foreach ( $this->get_fields as $key => $array ) {
4000
- if ( $array['type'] == 'row' ) {
4001
- $this->rows[ $key ] = $array;
4002
- unset( $this->get_fields[ $key ] ); // not needed anymore
4003
- }
4004
- }
4005
-
4006
- // rows fallback
4007
- if ( ! isset( $this->rows ) ) {
4008
- $this->rows = array(
4009
- '_um_row_1' => array(
4010
- 'type' => 'row',
4011
- 'id' => '_um_row_1',
4012
- 'sub_rows' => 1,
4013
- 'cols' => 1,
4014
- ),
4015
- );
4016
- }
4017
-
4018
- // master rows
4019
- foreach ( $this->rows as $row_id => $row_array ) {
4020
-
4021
- $row_fields = $this->get_fields_by_row( $row_id );
4022
- if ( $row_fields ) {
4023
-
4024
- $output .= $this->new_row_output( $row_id, $row_array );
4025
-
4026
- $sub_rows = ( isset( $row_array['sub_rows'] ) ) ? $row_array['sub_rows'] : 1;
4027
- for ( $c = 0; $c < $sub_rows; $c++ ) {
4028
-
4029
- // cols
4030
- $cols = isset( $row_array['cols'] ) ? $row_array['cols'] : 1;
4031
- if ( is_numeric( $cols ) ) {
4032
- $cols_num = (int) $cols;
4033
- } else {
4034
- if ( strstr( $cols, ':' ) ) {
4035
- $col_split = explode( ':', $cols );
4036
- } else {
4037
- $col_split = array( $cols );
4038
- }
4039
- $cols_num = $col_split[ $c ];
4040
- }
4041
-
4042
- // sub row fields
4043
- $subrow_fields = null;
4044
- $subrow_fields = $this->get_fields_in_subrow( $row_fields, $c );
4045
-
4046
- if ( is_array( $subrow_fields ) ) {
4047
-
4048
- $subrow_fields = $this->array_sort_by_column( $subrow_fields, 'position' );
4049
-
4050
- if ( $cols_num == 1 ) {
4051
-
4052
- $output .= '<div class="um-col-1">';
4053
- $col1_fields = $this->get_fields_in_column( $subrow_fields, 1 );
4054
- if ( $col1_fields ) {
4055
- foreach ( $col1_fields as $key => $data ) {
4056
- $output .= $this->edit_field( $key, $data );
4057
- }
4058
- }
4059
- $output .= '</div>';
4060
-
4061
- } else if ($cols_num == 2) {
4062
-
4063
- $output .= '<div class="um-col-121">';
4064
- $col1_fields = $this->get_fields_in_column( $subrow_fields, 1 );
4065
- if ( $col1_fields ) {
4066
- foreach ( $col1_fields as $key => $data ) {
4067
- $output .= $this->edit_field( $key, $data );
4068
- }
4069
- }
4070
- $output .= '</div>';
4071
-
4072
- $output .= '<div class="um-col-122">';
4073
- $col2_fields = $this->get_fields_in_column( $subrow_fields, 2 );
4074
- if ( $col2_fields ) {
4075
- foreach ( $col2_fields as $key => $data ) {
4076
- $output .= $this->edit_field( $key, $data );
4077
- }
4078
- }
4079
- $output .= '</div><div class="um-clear"></div>';
4080
-
4081
- } else {
4082
-
4083
- $output .= '<div class="um-col-131">';
4084
- $col1_fields = $this->get_fields_in_column( $subrow_fields, 1 );
4085
- if ( $col1_fields ) {
4086
- foreach ( $col1_fields as $key => $data ) {
4087
- $output .= $this->edit_field( $key, $data );
4088
- }
4089
- }
4090
- $output .= '</div>';
4091
-
4092
- $output .= '<div class="um-col-132">';
4093
- $col2_fields = $this->get_fields_in_column( $subrow_fields, 2 );
4094
- if ( $col2_fields ) {
4095
- foreach ( $col2_fields as $key => $data ) {
4096
- $output .= $this->edit_field( $key, $data );
4097
- }
4098
- }
4099
- $output .= '</div>';
4100
-
4101
- $output .= '<div class="um-col-133">';
4102
- $col3_fields = $this->get_fields_in_column( $subrow_fields, 3 );
4103
- if ( $col3_fields ) {
4104
- foreach ( $col3_fields as $key => $data ) {
4105
- $output .= $this->edit_field( $key, $data );
4106
- }
4107
- }
4108
- $output .= '</div><div class="um-clear"></div>';
4109
-
4110
- }
4111
-
4112
- }
4113
-
4114
- }
4115
-
4116
- $output .= '</div>';
4117
-
4118
- }
4119
-
4120
- }
4121
-
4122
- }
4123
-
4124
- return $output;
4125
- }
4126
-
4127
-
4128
- /**
4129
- * Gets a field in `view mode`
4130
- *
4131
- * @param string $key
4132
- * @param array $data
4133
- * @param bool $rule
4134
- *
4135
- * @return string|null
4136
- * @throws \Exception
4137
- */
4138
- function view_field( $key, $data, $rule = false ) {
4139
- $output = '';
4140
-
4141
- // get whole field data
4142
- if ( is_array( $data ) ) {
4143
- $data = $this->get_field( $key );
4144
-
4145
- if ( is_array( $data ) ) {
4146
- /**
4147
- * @var $visibility
4148
- * @var $type
4149
- * @var $default
4150
- * @var $classes
4151
- * @var $conditional
4152
- * @var $content
4153
- * @var $divider_text
4154
- * @var $spacing
4155
- * @var $borderwidth
4156
- * @var $borderstyle
4157
- * @var $bordercolor
4158
- * @var $label
4159
- */
4160
- extract( $data );
4161
- }
4162
- }
4163
-
4164
- //hide if empty type
4165
- if ( ! isset( $data['type'] ) ) {
4166
- return '';
4167
- }
4168
-
4169
- if ( isset( $data['in_group'] ) && $data['in_group'] != '' && $rule != 'group' ) {
4170
- return '';
4171
- }
4172
-
4173
- //invisible on profile page
4174
- if ( $visibility == 'edit' || $type == 'password' ) {
4175
- return '';
4176
- }
4177
-
4178
- //hide if empty
4179
- $fields_without_metakey = UM()->builtin()->get_fields_without_metakey();
4180
- if ( ! in_array( $type, $fields_without_metakey ) ) {
4181
- $_field_value = $this->field_value( $key, $default, $data );
4182
-
4183
- if ( ! isset( $_field_value ) || $_field_value == '' ) {
4184
- return '';
4185
- }
4186
- }
4187
-
4188
- if ( ! um_can_view_field( $data ) ) {
4189
- return '';
4190
- }
4191
-
4192
- // disable these fields in profile view only
4193
- if ( in_array( $key, array( 'user_password' ) ) && $this->set_mode == 'profile' ) {
4194
- return '';
4195
- }
4196
-
4197
- if ( ! um_field_conditions_are_met( $data ) ) {
4198
- return '';
4199
- }
4200
-
4201
-
4202
- if ( isset( $data['classes'] ) ) {
4203
- $classes = explode( " ", $data['classes'] );
4204
- }
4205
-
4206
- switch ( $type ) {
4207
-
4208
- /* Default */
4209
- default:
4210
-
4211
- $_field_value = $this->field_value( $key, $default, $data );
4212
-
4213
- if ( ! in_array( $type, $fields_without_metakey ) && ( ! isset( $_field_value ) || $_field_value == '' ) ) {
4214
- $output = '';
4215
- } else {
4216
-
4217
- $output .= '<div ' . $this->get_atts( $key, $classes, $conditional, $data ) . '>';
4218
-
4219
- if ( isset( $data['label'] ) || ! empty( $data['icon'] ) ) {
4220
-
4221
- if ( ! isset( $data['label'] ) ) {
4222
- $data['label'] = '';
4223
- }
4224
-
4225
- $output .= $this->field_label( $data['label'], $key, $data );
4226
- }
4227
-
4228
- $res = $this->field_value( $key, $default, $data );
4229
-
4230
- if ( ! empty( $res ) ) {
4231
- $res = stripslashes( $res );
4232
- }
4233
- if ( 'description' === $data['metakey'] ) {
4234
- if ( UM()->options()->get( 'profile_show_html_bio' ) ) {
4235
- $res = make_clickable( wpautop( wp_kses_post( $res ) ) );
4236
- } else {
4237
- $res = esc_html( $res );
4238
- }
4239
-
4240
- $res = nl2br( $res );
4241
- }
4242
-
4243
- $data['is_view_field'] = true;
4244
- /**
4245
- * UM hook
4246
- *
4247
- * @type filter
4248
- * @title um_view_field
4249
- * @description Change field HTML on view mode
4250
- * @input_vars
4251
- * [{"var":"$output","type":"string","desc":"Field HTML"},
4252
- * {"var":"$data","type":"string","desc":"Field Data"},
4253
- * {"var":"$type","type":"string","desc":"Field Type"}]
4254
- * @change_log
4255
- * ["Since: 2.0"]
4256
- * @usage add_filter( 'um_view_field', 'function_name', 10, 3 );
4257
- * @example
4258
- * <?php
4259
- * add_filter( 'um_view_field', 'my_view_field', 10, 3 );
4260
- * function my_form_edit_field( $output, $data, $type ) {
4261
- * // your code here
4262
- * return $output;
4263
- * }
4264
- * ?>
4265
- */
4266
- $res = apply_filters( 'um_view_field', $res, $data, $type );
4267
- /**
4268
- * UM hook
4269
- *
4270
- * @type filter
4271
- * @title um_view_field_value_{$type}
4272
- * @description Change field HTML on view mode by field type
4273
- * @input_vars
4274
- * [{"var":"$output","type":"string","desc":"Field HTML"},
4275
- * {"var":"$data","type":"string","desc":"Field Data"}]
4276
- * @change_log
4277
- * ["Since: 2.0"]
4278
- * @usage add_filter( 'um_view_field_value_{$type}', 'function_name', 10, 2 );
4279
- * @example
4280
- * <?php
4281
- * add_filter( 'um_view_field_value_{$type}', 'my_view_field', 10, 2 );
4282
- * function my_form_edit_field( $output, $data ) {
4283
- * // your code here
4284
- * return $output;
4285
- * }
4286
- * ?>
4287
- */
4288
- $res = apply_filters( "um_view_field_value_{$type}", $res, $data );
4289
-
4290
- $id_attr = '';
4291
- if ( ! in_array( $type, $fields_without_metakey ) ) {
4292
- $id_attr = ' id="' . esc_attr( $key . UM()->form()->form_suffix ) . '"';
4293
- }
4294
-
4295
- if ( empty( $res ) ) {
4296
- $output = '';
4297
- } else {
4298
- $output .= '<div class="um-field-area">';
4299
- $output .= '<div class="um-field-value"' . $id_attr . '>' . $res . '</div>';
4300
- $output .= '</div>';
4301
-
4302
- $output .= '</div>';
4303
- }
4304
- }
4305
-
4306
- break;
4307
-
4308
- /* HTML */
4309
- case 'block':
4310
- $output .= '<div ' . $this->get_atts( $key, $classes, $conditional, $data ) . '>' . $content . '</div>';
4311
- break;
4312
-
4313
- /* Shortcode */
4314
- case 'shortcode':
4315
-
4316
- $content = str_replace( '{profile_id}', um_profile_id(), $content );
4317
- if ( version_compare( get_bloginfo('version'),'5.4', '<' ) ) {
4318
- $content = do_shortcode( $content );
4319
- } else {
4320
- $content = apply_shortcodes( $content );
4321
- }
4322
-
4323
- $output .= '<div ' . $this->get_atts( $key, $classes, $conditional, $data ) . '>' . $content . '</div>';
4324
- break;
4325
-
4326
- /* Gap/Space */
4327
- case 'spacing':
4328
- $output .= '<div ' . $this->get_atts( $key, $classes, $conditional, $data, array( 'height' => $spacing ) ) . '></div>';
4329
- break;
4330
-
4331
- /* A line divider */
4332
- case 'divider':
4333
- $output .= '<div ' . $this->get_atts( $key, $classes, $conditional, $data, array( 'border-bottom' => $borderwidth . 'px ' . $borderstyle . ' ' . $bordercolor ) ) . '>';
4334
- if ( $divider_text ) {
4335
- $output .= '<div class="um-field-divider-text"><span>' . $divider_text . '</span></div>';
4336
- }
4337
- $output .= '</div>';
4338
- break;
4339
-
4340
- /* Rating */
4341
- case 'rating':
4342
-
4343
- $output .= '<div ' . $this->get_atts( $key, $classes, $conditional, $data ) . '>';
4344
-
4345
- if ( isset( $data['label'] ) || ! empty( $data['icon'] ) ) {
4346
- $output .= $this->field_label( $label, $key, $data );
4347
- }
4348
-
4349
- ob_start(); ?>
4350
-
4351
- <div class="um-field-area">
4352
- <div class="um-field-value">
4353
- <div class="um-rating-readonly um-raty" id="<?php echo esc_attr( $key ) ?>"
4354
- data-key="<?php echo esc_attr( $key ) ?>" data-number="<?php echo esc_attr( $data['number'] ) ?>"
4355
- data-score="<?php echo $this->field_value( $key, $default, $data ) ?>"></div>
4356
- </div>
4357
- </div>
4358
-
4359
- <?php $output .= ob_get_clean();
4360
- $output .= '</div>';
4361
-
4362
- break;
4363
-
4364
- }
4365
-
4366
- // Custom filter for field output
4367
- if ( isset( $this->set_mode ) ) {
4368
- /**
4369
- * UM hook
4370
- *
4371
- * @type filter
4372
- * @title um_{$key}_form_show_field
4373
- * @description Change field HTML by field $key
4374
- * @input_vars
4375
- * [{"var":"$output","type":"string","desc":"Field HTML"},
4376
- * {"var":"$mode","type":"string","desc":"Form Mode"}]
4377
- * @change_log
4378
- * ["Since: 2.0"]
4379
- * @usage add_filter( 'um_{$key}_form_show_field', 'function_name', 10, 2 );
4380
- * @example
4381
- * <?php
4382
- * add_filter( 'um_{$key}_form_show_field', 'my_form_show_field', 10, 2 );
4383
- * function my_form_show_field( $output, $mode ) {
4384
- * // your code here
4385
- * return $output;
4386
- * }
4387
- * ?>
4388
- */
4389
- $output = apply_filters( "um_{$key}_form_show_field", $output, $this->set_mode );
4390
- /**
4391
- * UM hook
4392
- *
4393
- * @type filter
4394
- * @title um_{$type}_form_show_field
4395
- * @description Change field HTML by field $type
4396
- * @input_vars
4397
- * [{"var":"$output","type":"string","desc":"Field HTML"},
4398
- * {"var":"$mode","type":"string","desc":"Form Mode"}]
4399
- * @change_log
4400
- * ["Since: 2.0"]
4401
- * @usage add_filter( 'um_{$type}_form_show_field', 'function_name', 10, 2 );
4402
- * @example
4403
- * <?php
4404
- * add_filter( 'um_{$type}_form_show_field', 'my_form_show_field', 10, 2 );
4405
- * function my_form_show_field( $output, $mode ) {
4406
- * // your code here
4407
- * return $output;
4408
- * }
4409
- * ?>
4410
- */
4411
- $output = apply_filters( "um_{$type}_form_show_field", $output, $this->set_mode );
4412
- }
4413
-
4414
- return $output;
4415
- }
4416
-
4417
-
4418
- /**
4419
- * Filter field data
4420
- *
4421
- * @param array $data
4422
- *
4423
- * @return array
4424
- */
4425
- function view_field_output( $data ) {
4426
- /**
4427
- * UM hook
4428
- *
4429
- * @type filter
4430
- * @title um_view_field_output_{$type}
4431
- * @description Change field data output by $type
4432
- * @input_vars
4433
- * [{"var":"$data","type":"array","desc":"Field Data"}]
4434
- * @change_log
4435
- * ["Since: 2.0"]
4436
- * @usage add_filter( 'um_view_field_output_{$type}', 'function_name', 10, 1 );
4437
- * @example
4438
- * <?php
4439
- * add_filter( 'um_view_field_output_{$type}', 'my_view_field_output', 10, 1 );
4440
- * function my_view_field_output( $data ) {
4441
- * // your code here
4442
- * return $data;
4443
- * }
4444
- * ?>
4445
- */
4446
- return apply_filters( "um_view_field_output_" . $data['type'], $data );
4447
- }
4448
-
4449
-
4450
- /**
4451
- * Display fields ( view mode )
4452
- *
4453
- * @param string $mode
4454
- * @param array $args
4455
- *
4456
- * @return string|null
4457
- * @throws \Exception
4458
- */
4459
- function display_view( $mode, $args ) {
4460
- $output = null;
4461
-
4462
- $this->global_args = $args;
4463
-
4464
- UM()->form()->form_suffix = '-' . $this->global_args['form_id'];
4465
-
4466
- $this->set_mode = $mode;
4467
- $this->set_id = $this->global_args['form_id'];
4468
-
4469
- $this->field_icons = ( isset( $this->global_args['icons'] ) ) ? $this->global_args['icons'] : 'label';
4470
-
4471
- // start output here
4472
- $this->get_fields = $this->get_fields();
4473
-
4474
- if ( UM()->options()->get( 'profile_empty_text' ) ) {
4475
-
4476
- $emo = UM()->options()->get( 'profile_empty_text_emo' );
4477
- if ( $emo ) {
4478
- $emo = '<i class="um-faicon-frown-o"></i>';
4479
- } else {
4480
- $emo = false;
4481
- }
4482
-
4483
- if ( um_is_myprofile() ) {
4484
- $output .= '<p class="um-profile-note">' . $emo . '<span>' . sprintf( __( 'Your profile is looking a little empty. Why not <a href="%s">add</a> some information!', 'ultimate-member' ), esc_url( um_edit_profile_url() ) ) . '</span></p>';
4485
- } else {
4486
- $output .= '<p class="um-profile-note">' . $emo . '<span>' . __( 'This user has not added any information to their profile yet.', 'ultimate-member' ) . '</span></p>';
4487
- }
4488
- }
4489
-
4490
- if ( ! empty( $this->get_fields ) ) {
4491
-
4492
- // find rows
4493
- foreach ( $this->get_fields as $key => $array ) {
4494
- if ( $array['type'] == 'row' ) {
4495
- $this->rows[ $key ] = $array;
4496
- unset( $this->get_fields[ $key ] ); // not needed anymore
4497
- }
4498
- }
4499
-
4500
- // rows fallback
4501
- if ( ! isset( $this->rows ) ) {
4502
- $this->rows = array(
4503
- '_um_row_1' => array(
4504
- 'type' => 'row',
4505
- 'id' => '_um_row_1',
4506
- 'sub_rows' => 1,
4507
- 'cols' => 1,
4508
- ),
4509
- );
4510
- }
4511
-
4512
- // master rows
4513
- foreach ( $this->rows as $row_id => $row_array ) {
4514
-
4515
- $row_fields = $this->get_fields_by_row( $row_id );
4516
-
4517
- if ( $row_fields ) {
4518
-
4519
- $output .= $this->new_row_output( $row_id, $row_array );
4520
-
4521
- $sub_rows = ( isset( $row_array['sub_rows'] ) ) ? $row_array['sub_rows'] : 1;
4522
- for ( $c = 0; $c < $sub_rows; $c++ ) {
4523
-
4524
- // cols
4525
- $cols = isset( $row_array['cols'] ) ? $row_array['cols'] : 1;
4526
- if ( is_numeric( $cols ) ) {
4527
- $cols_num = (int) $cols;
4528
- } else {
4529
- if ( strstr( $cols, ':' ) ) {
4530
- $col_split = explode( ':', $cols );
4531
- } else {
4532
- $col_split = array( $cols );
4533
- }
4534
- $cols_num = $col_split[ $c ];
4535
- }
4536
-
4537
- // sub row fields
4538
- $subrow_fields = null;
4539
- $subrow_fields = $this->get_fields_in_subrow( $row_fields, $c );
4540
-
4541
- if ( is_array( $subrow_fields ) ) {
4542
-
4543
- $subrow_fields = $this->array_sort_by_column( $subrow_fields, 'position' );
4544
-
4545
- if ( $cols_num == 1 ) {
4546
-
4547
- $output .= '<div class="um-col-1">';
4548
- $col1_fields = $this->get_fields_in_column( $subrow_fields, 1 );
4549
- if ( $col1_fields ) {
4550
- foreach ( $col1_fields as $key => $data ) {
4551
-
4552
- $data = $this->view_field_output( $data );
4553
- $output .= $this->view_field( $key, $data );
4554
-
4555
- }
4556
- }
4557
- $output .= '</div>';
4558
-
4559
- } elseif ( $cols_num == 2 ) {
4560
-
4561
- $output .= '<div class="um-col-121">';
4562
- $col1_fields = $this->get_fields_in_column( $subrow_fields, 1 );
4563
- if ( $col1_fields ) {
4564
- foreach ( $col1_fields as $key => $data ) {
4565
-
4566
- $data = $this->view_field_output( $data );
4567
- $output .= $this->view_field( $key, $data );
4568
-
4569
- }
4570
- }
4571
- $output .= '</div>';
4572
-
4573
- $output .= '<div class="um-col-122">';
4574
- $col2_fields = $this->get_fields_in_column( $subrow_fields, 2 );
4575
- if ( $col2_fields ) {
4576
- foreach ( $col2_fields as $key => $data ) {
4577
-
4578
- $data = $this->view_field_output( $data );
4579
- $output .= $this->view_field( $key, $data );
4580
-
4581
- }
4582
- }
4583
- $output .= '</div><div class="um-clear"></div>';
4584
-
4585
- } else {
4586
-
4587
- $output .= '<div class="um-col-131">';
4588
- $col1_fields = $this->get_fields_in_column( $subrow_fields, 1 );
4589
- if ( $col1_fields ) {
4590
- foreach ( $col1_fields as $key => $data ) {
4591
-
4592
- $data = $this->view_field_output( $data );
4593
- $output .= $this->view_field( $key, $data );
4594
-
4595
- }
4596
- }
4597
- $output .= '</div>';
4598
-
4599
- $output .= '<div class="um-col-132">';
4600
- $col2_fields = $this->get_fields_in_column( $subrow_fields, 2 );
4601
- if ( $col2_fields ) {
4602
- foreach ( $col2_fields as $key => $data ) {
4603
-
4604
- $data = $this->view_field_output( $data );
4605
- $output .= $this->view_field( $key, $data );
4606
-
4607
- }
4608
- }
4609
- $output .= '</div>';
4610
-
4611
- $output .= '<div class="um-col-133">';
4612
- $col3_fields = $this->get_fields_in_column( $subrow_fields, 3 );
4613
- if ( $col3_fields ) {
4614
- foreach ( $col3_fields as $key => $data ) {
4615
-
4616
- $data = $this->view_field_output( $data );
4617
- $output .= $this->view_field( $key, $data );
4618
-
4619
- }
4620
- }
4621
- $output .= '</div><div class="um-clear"></div>';
4622
-
4623
- }
4624
-
4625
- }
4626
-
4627
- }
4628
-
4629
- $output .= '</div>';
4630
-
4631
- }
4632
-
4633
- }
4634
-
4635
- }
4636
-
4637
- return $output;
4638
- }
4639
-
4640
-
4641
- /**
4642
- * Get new row in form
4643
- *
4644
- * @param string $row_id
4645
- * @param array $row_array
4646
- *
4647
- * @return string
4648
- */
4649
- function new_row_output( $row_id, $row_array ) {
4650
- $output = null;
4651
- extract( $row_array );
4652
-
4653
- $padding = ( isset( $padding ) ) ? $padding : '';
4654
- $margin = ( isset( $margin ) ) ? $margin : '';
4655
- $background = ( isset( $background ) ) ? $background : '';
4656
- $text_color = ( isset( $text_color ) ) ? $text_color : '';
4657
- $borderradius = ( isset( $borderradius ) ) ? $borderradius : '';
4658
- $border = ( isset( $border ) ) ? $border : '';
4659
- $bordercolor = ( isset( $bordercolor ) ) ? $bordercolor : '';
4660
- $borderstyle = ( isset( $borderstyle ) ) ? $borderstyle : '';
4661
- $heading = ( isset( $heading ) ) ? $heading : '';
4662
- $css_class = ( isset( $css_class ) ) ? $css_class : '';
4663
-
4664
- $css_padding = '';
4665
- $css_margin = '';
4666
- $css_background = '';
4667
- $css_borderradius = '';
4668
- $css_border = '';
4669
- $css_bordercolor = '';
4670
- $css_borderstyle = '';
4671
- $css_heading_background_color = '';
4672
- $css_heading_padding = '';
4673
- $css_heading_text_color = '';
4674
- $css_heading_borderradius = '';
4675
- $css_text_color = '';
4676
-
4677
- // row css rules
4678
- if ( $padding ) {
4679
- $css_padding = 'padding: ' . $padding . ';';
4680
- }
4681
- if ( $margin ) {
4682
- $css_margin = 'margin: ' . $margin . ';';
4683
- } else {
4684
- $css_margin = 'margin: 0 0 30px 0;';
4685
- }
4686
-
4687
- if ( $background ) {
4688
- $css_background = 'background-color: ' . $background . ';';
4689
- }
4690
- if ( $borderradius ) {
4691
- $css_borderradius = 'border-radius: 0px 0px ' . $borderradius . ' ' . $borderradius . ';';
4692
- }
4693
- if ( $border ) {
4694
- $css_border = 'border-width: ' . $border . ';';
4695
- }
4696
- if ( $bordercolor ) {
4697
- $css_bordercolor = 'border-color: ' . $bordercolor . ';';
4698
- }
4699
- if ( $borderstyle ) {
4700
- $css_borderstyle = 'border-style: ' . $borderstyle . ';';
4701
- }
4702
- if ( $text_color ) {
4703
- $css_text_color = 'color: ' . $text_color . ' !important;';
4704
- $css_class .= ' um-customized-row';
4705
- }
4706
-
4707
- // show the heading
4708
- if ( $heading ) {
4709
-
4710
- if ( ! empty( $heading_background_color ) ) {
4711
- $css_heading_background_color = "background-color: $heading_background_color;";
4712
- $css_heading_padding = 'padding: 10px 15px;';
4713
- }
4714
-
4715
- $css_heading_borderradius = empty( $borderradius ) ? '' : "border-radius: $borderradius $borderradius 0px 0px;";
4716
- $css_heading_border = $css_border . $css_borderstyle . $css_bordercolor . $css_heading_borderradius . 'border-bottom-width: 0px;';
4717
- $css_heading_margin = $css_margin . 'margin-bottom: 0px;';
4718
- $css_heading_text_color = empty( $heading_text_color ) ? '' : "color: $heading_text_color;";
4719
- $css_icon_color = empty( $icon_color ) ? '' : "color: $icon_color;";
4720
-
4721
- $output .= '<div class="um-row-heading" style="' . $css_heading_margin . $css_heading_padding . $css_heading_border . $css_heading_background_color . $css_heading_text_color . '">';
4722
-
4723
- if ( ! empty( $icon ) ) {
4724
- $output .= '<span class="um-row-heading-icon" style="' . $css_icon_color . '"><i class="' . $icon . '"></i></span>';
4725
- }
4726
- if ( ! empty( $heading_text ) ) {
4727
- $output .= htmlspecialchars( $heading_text );
4728
- }
4729
-
4730
- $output .= '</div>';
4731
-
4732
- $css_border .= 'border-top-width: 0px;';
4733
- $css_margin .= 'margin-top: 0px;';
4734
-
4735
- } else {
4736
-
4737
- // no heading
4738
- $css_borderradius = empty( $borderradius ) ? '' : "border-radius: $borderradius;";
4739
-
4740
- }
4741
-
4742
- $output .= '<div class="um-row ' . $row_id . ' ' . $css_class . '" style="' . $css_padding . $css_background . $css_margin . $css_border . $css_borderstyle . $css_bordercolor . $css_borderradius . $css_text_color . '">';
4743
-
4744
- return $output;
4745
- }
4746
-
4747
-
4748
- /**
4749
- *
4750
- */
4751
- function do_ajax_action() {
4752
- UM()->admin()->check_ajax_nonce();
4753
-
4754
- if ( ! is_user_logged_in() || ! current_user_can( 'manage_options' ) ) {
4755
- wp_send_json_error( __( 'Please login as administrator', 'ultimate-member' ) );
4756
- }
4757
-
4758
- /**
4759
- * @var $in_row
4760
- * @var $in_sub_row
4761
- * @var $in_column
4762
- * @var $in_group
4763
- * @var $act_id
4764
- * @var $arg1
4765
- * @var $arg2
4766
- */
4767
- extract( $_POST );
4768
-
4769
- $output = null;
4770
-
4771
- $position = array();
4772
- if ( ! empty( $in_column ) ) {
4773
- $position['in_row'] = '_um_row_' . ( (int) $in_row + 1 );
4774
- $position['in_sub_row'] = $in_sub_row;
4775
- $position['in_column'] = $in_column;
4776
- $position['in_group'] = $in_group;
4777
- }
4778
-
4779
- switch ( $act_id ) {
4780
-
4781
- case 'um_admin_duplicate_field':
4782
- $this->duplicate_field( $arg1, $arg2 );
4783
- break;
4784
-
4785
- case 'um_admin_remove_field_global':
4786
- $this->delete_field_from_db( $arg1 );
4787
- break;
4788
-
4789
- case 'um_admin_remove_field':
4790
- $this->delete_field_from_form( $arg1, $arg2 );
4791
- break;
4792
-
4793
- case 'um_admin_add_field_from_predefined':
4794
- $this->add_field_from_predefined( $arg1, $arg2, $position );
4795
- break;
4796
-
4797
- case 'um_admin_add_field_from_list':
4798
- $this->add_field_from_list( $arg1, $arg2, $position );
4799
- break;
4800
-
4801
- }
4802
-
4803
- if ( is_array( $output ) ) {
4804
- print_r( $output );
4805
- } else {
4806
- echo $output;
4807
- }
4808
- die;
4809
-
4810
- }
4811
-
4812
-
4813
-
4814
- /**
4815
- * Get rendered field attributes
4816
- *
4817
- * @since 2.1.2
4818
- *
4819
- * @param string $key
4820
- * @param array $classes
4821
- * @param string $conditional
4822
- * @param array $data
4823
- * @param array $field_style
4824
- *
4825
- * @return string/html
4826
- */
4827
- function get_atts( $key, $classes, $conditional, $data, $field_style = array() ) {
4828
-
4829
- array_unshift( $classes, 'um-field-' . $data['type'] );
4830
- array_unshift( $classes, 'um-field' );
4831
-
4832
- $field_atts = array(
4833
- 'id' => array(
4834
- "um_field_{$this->set_id}_{$key}",
4835
- ),
4836
- 'class' => $classes,
4837
- 'data-key' => array(
4838
- esc_attr( $key )
4839
- )
4840
- );
4841
-
4842
- $fields_without_metakey = UM()->builtin()->get_fields_without_metakey();
4843
-
4844
- if ( in_array( $data['type'], $fields_without_metakey ) ) {
4845
- unset( $field_atts['id'] );
4846
-
4847
- if ( empty( $field_atts['data-key'] ) ) {
4848
- unset( $field_atts['data-key'] );
4849
- }
4850
- }
4851
-
4852
- if ( ! empty( $field_style ) && is_array( $field_style ) ) {
4853
-
4854
- $arr_inline_style = '';
4855
- foreach ( $field_style as $style_attr => $style_value ) {
4856
- $arr_inline_style .= esc_attr( $style_attr ) . ':' . esc_attr( $style_value ) . ';';
4857
- }
4858
- $field_atts['style'] = array( $arr_inline_style );
4859
- }
4860
-
4861
- /**
4862
- * UM hook
4863
- *
4864
- * @type filter
4865
- * @title um_field_extra_atts
4866
- * @description user for adding extra field attributes
4867
- * @input_vars
4868
- * [{"var":"$field_atts","type":"array","desc":"Field attributes"},
4869
- * [{"var":"$key","type":"string","desc":"Field id"},
4870
- * {"var":"$data","type":"array","desc":"Field Data"}]
4871
- * @change_log
4872
- * ["Since: 2.0.57"]
4873
- * @usage add_filter( 'um_field_extra_atts', 'function_name', 10, 3 );
4874
- * @example
4875
- * <?php
4876
- * add_filter( 'um_field_extra_atts', 'function_name', 10, 3 );
4877
- * function function_name( $field_atts, $key, $data ) {
4878
- * // your code here
4879
- * return $array_extra_atts;
4880
- * }
4881
- * ?>
4882
- */
4883
- $field_atts = apply_filters( 'um_field_extra_atts', $field_atts, $key, $data );
4884
-
4885
- $html_atts = '';
4886
- foreach ( $field_atts as $att_name => $att_values ) {
4887
- $att_values = implode( " ", $att_values );
4888
- $html_atts .= " {$att_name}=\"" . esc_attr( $att_values ) . "\"";
4889
- }
4890
-
4891
- $html_atts .= $conditional;
4892
-
4893
- return $html_atts;
4894
- }
4895
- }
4896
- }
 
 
 
 
 
 
1
+ <?php
2
+ namespace um\core;
3
+
4
+
5
+ if ( ! defined( 'ABSPATH' ) ) exit;
6
+
7
+
8
+ if ( ! class_exists( 'um\core\Fields' ) ) {
9
+
10
+
11
+ /**
12
+ * Class Fields
13
+ * @package um\core
14
+ */
15
+ class Fields {
16
+
17
+
18
+ /**
19
+ * @var string
20
+ */
21
+ var $set_mode = '';
22
+
23
+
24
+ /**
25
+ * @var int form_id
26
+ */
27
+ public $set_id = null;
28
+
29
+
30
+ /**
31
+ * Fields constructor.
32
+ */
33
+ function __construct() {
34
+ $this->editing = false;
35
+ $this->viewing = false;
36
+ $this->timestamp = current_time( 'timestamp' );
37
+ }
38
+
39
+
40
+ /**
41
+ * Standard checkbox field
42
+ *
43
+ * @param integer $id
44
+ * @param string $title
45
+ * @param bool $checked
46
+ */
47
+ function checkbox( $id, $title, $checked = true ) {
48
+
49
+ /**
50
+ * Set value on form submission
51
+ */
52
+ if ( isset( $_REQUEST[ $id ] ) ) {
53
+ $checked = (bool) $_REQUEST[ $id ];
54
+ }
55
+
56
+ $class = $checked ? 'um-icon-android-checkbox-outline' : 'um-icon-android-checkbox-outline-blank';
57
+
58
+ ?>
59
+
60
+
61
+ <div class="um-field um-field-c">
62
+ <div class="um-field-area">
63
+ <label class="um-field-checkbox<?php echo $checked ? ' active' : '' ?>">
64
+ <input type="checkbox" name="<?php echo esc_attr( $id ); ?>" value="1" <?php checked( $checked ) ?> />
65
+ <span class="um-field-checkbox-state"><i class="<?php echo esc_attr( $class ) ?>"></i></span>
66
+ <span class="um-field-checkbox-option"> <?php echo esc_html( $title ); ?></span>
67
+ </label>
68
+ </div>
69
+ </div>
70
+
71
+ <?php
72
+ }
73
+
74
+
75
+ /**
76
+ * Shows social links
77
+ */
78
+ function show_social_urls() {
79
+ $social = array();
80
+
81
+ $fields = UM()->builtin()->get_all_user_fields();
82
+ foreach ( $fields as $field => $args ) {
83
+ if ( isset( $args['advanced'] ) && $args['advanced'] == 'social' ) {
84
+ $social[ $field ] = $args;
85
+ }
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
+
95
+ <?php
96
+ }
97
+ }
98
+ }
99
+
100
+
101
+ /**
102
+ * Hidden field inside a shortcode
103
+ *
104
+ * @param string $field
105
+ */
106
+ function add_hidden_field( $field ) {
107
+ echo '<div style="display: none !important;">';
108
+
109
+ $fields = UM()->builtin()->get_specific_fields( $field );
110
+
111
+ $output = null;
112
+
113
+ foreach ( $fields as $key => $data ) {
114
+ $output .= UM()->fields()->edit_field( $key, $data );
115
+ }
116
+
117
+ echo $output;
118
+
119
+ echo '</div>';
120
+ }
121
+
122
+
123
+ /**
124
+ * Get hidden field
125
+ *
126
+ * @param string $key
127
+ * @param string $value
128
+ *
129
+ * @return string
130
+ */
131
+ function disabled_hidden_field( $key, $value ) {
132
+ return '<input type="hidden" name="' . esc_attr( $key ) . '" value="' . esc_attr( $value ) . '"/>';
133
+ }
134
+
135
+
136
+ /**
137
+ * Updates a field globally
138
+ *
139
+ * @param integer $id
140
+ * @param array $args
141
+ */
142
+ function globally_update_field( $id, $args ) {
143
+ $fields = UM()->builtin()->saved_fields;
144
+
145
+ $fields[ $id ] = $args;
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
+
163
+ unset( $fields[ $id ]['in_row'] );
164
+ unset( $fields[ $id ]['in_sub_row'] );
165
+ unset( $fields[ $id ]['in_column'] );
166
+ unset( $fields[ $id ]['in_group'] );
167
+ unset( $fields[ $id ]['position'] );
168
+
169
+ do_action( 'um_add_new_field', $id, $args );
170
+
171
+ update_option( 'um_fields', $fields );
172
+ }
173
+
174
+
175
+ /**
176
+ * Updates a field in form only
177
+ *
178
+ * @param integer $id
179
+ * @param array $args
180
+ * @param integer $form_id
181
+ */
182
+ function update_field( $id, $args, $form_id ) {
183
+ $fields = UM()->query()->get_attr( 'custom_fields', $form_id );
184
+
185
+ if ( $args['type'] == 'row' ) {
186
+ if ( isset( $fields[ $id ] ) ) {
187
+ $old_args = $fields[ $id ];
188
+ foreach ( $old_args as $k => $v ) {
189
+ if ( ! in_array( $k, array( 'sub_rows', 'cols' ) ) ) {
190
+ unset( $old_args[ $k ] );
191
+ }
192
+ }
193
+ $args = array_merge( $old_args, $args );
194
+ }
195
+ }
196
+
197
+ // custom fields support
198
+ if ( isset( UM()->builtin()->predefined_fields[ $id ] ) && isset( UM()->builtin()->predefined_fields[ $id ]['custom'] ) ) {
199
+ $args = array_merge( UM()->builtin()->predefined_fields[ $id ], $args );
200
+ }
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
+
220
+ $fields[ $id ] = $args;
221
+
222
+ // for group field only
223
+ if ( $args['type'] == 'group' ) {
224
+ $fields[ $id ]['in_group'] = '';
225
+ }
226
+
227
+ UM()->query()->update_attr( 'custom_fields', $form_id, $fields );
228
+ }
229
+
230
+
231
+ /**
232
+ * Deletes a field in form only
233
+ *
234
+ * @param integer $id
235
+ * @param integer $form_id
236
+ */
237
+ function delete_field_from_form( $id, $form_id ) {
238
+ $fields = UM()->query()->get_attr( 'custom_fields', $form_id );
239
+
240
+ if ( isset( $fields[ $id ] ) ) {
241
+ $condition_fields = get_option( 'um_fields' );
242
+
243
+ if( ! is_array( $condition_fields ) ) $condition_fields = array();
244
+
245
+ foreach ( $condition_fields as $key => $value ) {
246
+ $deleted_field = array_search( $id, $value );
247
+
248
+ if ( $key != $id && $deleted_field != false ) {
249
+ $deleted_field_id = str_replace( 'conditional_field', '', $deleted_field );
250
+
251
+ if ( $deleted_field_id == '' ) {
252
+ $arr_id = 0;
253
+ } else {
254
+ $arr_id = $deleted_field_id;
255
+ }
256
+
257
+ unset( $condition_fields[ $key ][ 'conditional_action' . $deleted_field_id ] );
258
+ unset( $condition_fields[ $key ][ $deleted_field ] );
259
+ unset( $condition_fields[ $key ][ 'conditional_operator' . $deleted_field_id ] );
260
+ unset( $condition_fields[ $key ][ 'conditional_value' . $deleted_field_id ] );
261
+ unset( $condition_fields[ $key ]['conditions'][ $arr_id ] );
262
+
263
+ unset( $fields[ $key ][ 'conditional_action' . $deleted_field_id ] );
264
+ unset( $fields[ $key ][ $deleted_field ] );
265
+ unset( $fields[ $key ][ 'conditional_operator' . $deleted_field_id ] );
266
+ unset( $fields[ $key ][ 'conditional_value' . $deleted_field_id ] );
267
+ unset( $fields[ $key ]['conditions'][ $arr_id ] );
268
+ }
269
+ }
270
+
271
+ update_option( 'um_fields' , $condition_fields );
272
+ unset( $fields[ $id ] );
273
+ UM()->query()->update_attr( 'custom_fields', $form_id, $fields );
274
+ }
275
+ }
276
+
277
+
278
+ /**
279
+ * Deletes a field from custom fields
280
+ *
281
+ * @param integer $id
282
+ */
283
+ function delete_field_from_db( $id ) {
284
+ $fields = UM()->builtin()->saved_fields;
285
+ if ( isset( $fields[ $id ] ) ) {
286
+ $args = $fields[ $id ];
287
+
288
+ unset( $fields[ $id ] );
289
+
290
+ do_action( 'um_delete_custom_field', $id, $args );
291
+
292
+ update_option( 'um_fields', $fields );
293
+
294
+ global $wpdb;
295
+ $forms = $wpdb->get_col( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'um_form'" );
296
+ foreach ( $forms as $form_id ) {
297
+ $form_fields = get_post_meta( $form_id, '_um_custom_fields', true );
298
+ unset( $form_fields[ $id ] );
299
+ update_post_meta( $form_id, '_um_custom_fields', $form_fields );
300
+ }
301
+
302
+ $directories = $wpdb->get_col( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'um_directory'" );
303
+ foreach ( $directories as $directory_id ) {
304
+ // Frontend filters
305
+ $directory_search_fields = get_post_meta( $directory_id, '_um_search_fields', true );
306
+ $directory_search_fields = array_values( array_diff( $directory_search_fields, array( $id ) ) );
307
+ update_post_meta( $directory_id, '_um_search_fields', $directory_search_fields );
308
+
309
+ // Admin filtering
310
+ $directory_search_filters = get_post_meta( $directory_id, '_um_search_filters', true );
311
+ unset( $directory_search_filters[ $id ] );
312
+ update_post_meta( $directory_id, '_um_search_filters', $directory_search_filters );
313
+
314
+ // display in tagline
315
+ $directory_reveal_fields = get_post_meta( $directory_id, '_um_reveal_fields', true );
316
+ $directory_reveal_fields = array_values( array_diff( $directory_reveal_fields, array( $id ) ) );
317
+ update_post_meta( $directory_id, '_um_reveal_fields', $directory_reveal_fields );
318
+
319
+ // extra user information section
320
+ $directory_tagline_fields = get_post_meta( $directory_id, '_um_tagline_fields', true );
321
+ $directory_tagline_fields = array_values( array_diff( $directory_tagline_fields, array( $id ) ) );
322
+ update_post_meta( $directory_id, '_um_tagline_fields', $directory_tagline_fields );
323
+
324
+ // Custom fields selected in "Choose field(s) to enable in sorting"
325
+ $directory_sorting_fields = get_post_meta( $directory_id, '_um_sorting_fields', true );
326
+ foreach ( $directory_sorting_fields as $key => $sorting_data ) {
327
+ if ( is_array( $sorting_data ) && array_key_exists( $id, $sorting_data ) ) {
328
+ unset( $directory_sorting_fields[ $key ] );
329
+ }
330
+ }
331
+ $directory_sorting_fields = array_values( $directory_sorting_fields );
332
+ update_post_meta( $directory_id, '_um_sorting_fields', $directory_sorting_fields );
333
+
334
+ // If "Default sort users by" = "Other (Custom Field)" is selected when delete this custom field and set default sorting
335
+ $directory_sortby_custom = get_post_meta( $directory_id, '_um_sortby_custom', true );
336
+ if ( $directory_sortby_custom === $id ) {
337
+ $directory_sortby = get_post_meta( $directory_id, '_um_sortby', true );
338
+ if ( 'other' === $directory_sortby ) {
339
+ update_post_meta( $directory_id, '_um_sortby', 'user_registered_desc' );
340
+ }
341
+ update_post_meta( $directory_id, '_um_sortby_custom', '' );
342
+ update_post_meta( $directory_id, '_um_sortby_custom_label', '' );
343
+ }
344
+ }
345
+
346
+ }
347
+ }
348
+
349
+
350
+ /**
351
+ * Quickly adds a field from custom fields
352
+ *
353
+ * @param integer $global_id
354
+ * @param integer $form_id
355
+ * @param array $position
356
+ */
357
+ function add_field_from_list( $global_id, $form_id, $position = array() ) {
358
+ $fields = UM()->query()->get_attr( 'custom_fields', $form_id );
359
+ $field_scope = UM()->builtin()->saved_fields;
360
+
361
+ if ( ! isset( $fields[ $global_id ] ) ) {
362
+
363
+ $count = 1;
364
+ if ( ! empty( $fields ) ) {
365
+ $count = count( $fields ) + 1;
366
+ }
367
+
368
+ $fields[ $global_id ] = $field_scope[ $global_id ];
369
+ $fields[ $global_id ]['position'] = $count;
370
+
371
+ // set position
372
+ if ( $position ) {
373
+ foreach ( $position as $key => $val) {
374
+ $fields[ $global_id ][ $key ] = $val;
375
+ }
376
+ }
377
+
378
+ // add field to form
379
+ UM()->query()->update_attr( 'custom_fields', $form_id, $fields );
380
+
381
+ }
382
+ }
383
+
384
+
385
+ /**
386
+ * Quickly adds a field from pre-defined fields
387
+ *
388
+ * @param integer $global_id
389
+ * @param integer $form_id
390
+ * @param array $position
391
+ */
392
+ function add_field_from_predefined( $global_id, $form_id, $position = array() ) {
393
+ $fields = UM()->query()->get_attr( 'custom_fields', $form_id );
394
+ $field_scope = UM()->builtin()->predefined_fields;
395
+
396
+ if ( ! isset( $fields[ $global_id ] ) ) {
397
+
398
+ $count = 1;
399
+ if ( ! empty( $fields ) ) {
400
+ $count = count( $fields ) + 1;
401
+ }
402
+
403
+ $fields[ $global_id ] = $field_scope[ $global_id ];
404
+ $fields[ $global_id ]['position'] = $count;
405
+
406
+ // set position
407
+ if ( $position ) {
408
+ foreach ( $position as $key => $val ) {
409
+ $fields[ $global_id ][ $key ] = $val;
410
+ }
411
+ }
412
+
413
+ // add field to form
414
+ UM()->query()->update_attr( 'custom_fields', $form_id, $fields );
415
+ }
416
+ }
417
+
418
+
419
+ /**
420
+ * Duplicates a frield by meta key
421
+ *
422
+ * @param integer $id
423
+ * @param integer $form_id
424
+ */
425
+ function duplicate_field( $id, $form_id ) {
426
+ $fields = UM()->query()->get_attr( 'custom_fields', $form_id );
427
+ $all_fields = UM()->builtin()->saved_fields;
428
+
429
+ $inc = count( $fields ) + 1;
430
+
431
+ $duplicate = $fields[ $id ];
432
+
433
+ $new_metakey = $id . "_" . $inc;
434
+ $new_title = $fields[ $id ]['title'] . " #" . $inc;
435
+ $new_position = $inc;
436
+
437
+ $duplicate['title'] = $new_title;
438
+ $duplicate['metakey'] = $new_metakey;
439
+ $duplicate['position'] = $new_position;
440
+
441
+ $fields[ $new_metakey ] = $duplicate;
442
+ $all_fields[ $new_metakey ] = $duplicate;
443
+
444
+ // not global attributes
445
+ unset( $all_fields[ $new_metakey ]['in_row'] );
446
+ unset( $all_fields[ $new_metakey ]['in_sub_row'] );
447
+ unset( $all_fields[ $new_metakey ]['in_column'] );
448
+ unset( $all_fields[ $new_metakey ]['in_group'] );
449
+ unset( $all_fields[ $new_metakey ]['position'] );
450
+
451
+
452
+ do_action( 'um_add_new_field', $new_metakey, $duplicate );
453
+
454
+ UM()->query()->update_attr( 'custom_fields', $form_id, $fields );
455
+ update_option( 'um_fields', $all_fields );
456
+ }
457
+
458
+
459
+ /**
460
+ * Print field error
461
+ *
462
+ * @param string $text
463
+ * @param bool $force_show
464
+ *
465
+ * @return string
466
+ */
467
+ function field_error( $text, $force_show = false ) {
468
+
469
+ if ( empty( $text ) ) {
470
+ return '';
471
+ }
472
+
473
+ if ( $force_show ) {
474
+ $output = '<div class="um-field-error"><span class="um-field-arrow"><i class="um-faicon-caret-up"></i></span>' . esc_attr( $text ) . '</div>';
475
+ return $output;
476
+ }
477
+
478
+
479
+ if ( isset( $this->set_id ) && UM()->form()->processing == $this->set_id ) {
480
+ $output = '<div class="um-field-error"><span class="um-field-arrow"><i class="um-faicon-caret-up"></i></span>' . esc_attr( $text ) . '</div>';
481
+ } else {
482
+ $output = '';
483
+ }
484
+
485
+ if ( ! UM()->form()->processing ) {
486
+ $output = '<div class="um-field-error"><span class="um-field-arrow"><i class="um-faicon-caret-up"></i></span>' . esc_attr( $text ) . '</div>';
487
+ }
488
+
489
+ return $output;
490
+ }
491
+
492
+
493
+ /**
494
+ * Print field notice
495
+ *
496
+ * @param string $text
497
+ * @param bool $force_show
498
+ *
499
+ * @return string
500
+ */
501
+ function field_notice( $text, $force_show = false ) {
502
+
503
+ if ( empty( $text ) ) {
504
+ return '';
505
+ }
506
+
507
+ if ( $force_show ) {
508
+ $output = '<div class="um-field-notice"><span class="um-field-arrow"><i class="um-faicon-caret-up"></i></span>' . esc_attr( $text ) . '</div>';
509
+ return $output;
510
+ }
511
+
512
+
513
+ if ( isset( $this->set_id ) && UM()->form()->processing == $this->set_id ) {
514
+ $output = '<div class="um-field-notice"><span class="um-field-arrow"><i class="um-faicon-caret-up"></i></span>' . esc_attr( $text ) . '</div>';
515
+ } else {
516
+ $output = '';
517
+ }
518
+
519
+ if ( ! UM()->form()->processing ) {
520
+ $output = '<div class="um-field-notice"><span class="um-field-arrow"><i class="um-faicon-caret-up"></i></span>' . esc_attr( $text ) . '</div>';
521
+ }
522
+
523
+ return $output;
524
+ }
525
+
526
+
527
+ /**
528
+ * Checks if field has a server-side error
529
+ *
530
+ * @param string $key
531
+ *
532
+ * @return boolean
533
+ */
534
+ function is_error( $key ) {
535
+ return UM()->form()->has_error( $key );
536
+ }
537
+
538
+ /**
539
+ * Checks if field has a notice
540
+ *
541
+ * @param string $key
542
+ *
543
+ * @return boolean
544
+ */
545
+ function is_notice( $key ) {
546
+ return UM()->form()->has_notice( $key );
547
+ }
548
+
549
+
550
+ /**
551
+ * Returns field error
552
+ *
553
+ * @param string $key
554
+ *
555
+ * @return string
556
+ */
557
+ function show_error( $key ) {
558
+ return UM()->form()->errors[ $key ];
559
+ }
560
+
561
+ /**
562
+ * Returns field notices
563
+ *
564
+ * @param string $key
565
+ *
566
+ * @return string
567
+ */
568
+ function show_notice( $key ) {
569
+ return UM()->form()->notices[ $key ];
570
+ }
571
+
572
+
573
+ /**
574
+ * Display field label
575
+ *
576
+ * @param string $label
577
+ * @param string $key
578
+ * @param array $data
579
+ *
580
+ * @return string
581
+ */
582
+ function field_label( $label, $key, $data ) {
583
+ $output = null;
584
+ $output .= '<div class="um-field-label">';
585
+
586
+ if ( isset( $data['icon'] ) && $data['icon'] != '' && isset( $this->field_icons ) && $this->field_icons != 'off' && ( $this->field_icons == 'label' || $this->viewing == true ) ) {
587
+ $output .= '<div class="um-field-label-icon"><i class="' . esc_attr( $data['icon'] ) . '" aria-label="' . esc_attr( $label ) . '"></i></div>';
588
+ }
589
+
590
+ if ( $this->viewing == true ) {
591
+ /**
592
+ * UM hook
593
+ *
594
+ * @type filter
595
+ * @title um_view_label_{$key}
596
+ * @description Change field label on view by field $key
597
+ * @input_vars
598
+ * [{"var":"$label","type":"string","desc":"Field Label"}]
599
+ * @change_log
600
+ * ["Since: 2.0"]
601
+ * @usage add_filter( 'um_view_label_{$key}', 'function_name', 10, 1 );
602
+ * @example
603
+ * <?php
604
+ * add_filter( 'um_view_label_{$key}', 'my_view_label', 10, 1 );
605
+ * function my_view_label( $label ) {
606
+ * // your code here
607
+ * return $label;
608
+ * }
609
+ * ?>
610
+ */
611
+ $label = apply_filters( "um_view_label_{$key}", $label );
612
+ } else {
613
+ /**
614
+ * UM hook
615
+ *
616
+ * @type filter
617
+ * @title um_edit_label_{$key}
618
+ * @description Change field label on edit by field $key
619
+ * @input_vars
620
+ * [{"var":"$label","type":"string","desc":"Field Label"}]
621
+ * @change_log
622
+ * ["Since: 2.0"]
623
+ * @usage add_filter( 'um_edit_label_{$key}', 'function_name', 10, 1 );
624
+ * @example
625
+ * <?php
626
+ * add_filter( 'um_edit_label_{$key}', 'my_edit_label', 10, 1 );
627
+ * function my_edit_label( $label ) {
628
+ * // your code here
629
+ * return $label;
630
+ * }
631
+ * ?>
632
+ */
633
+ $label = apply_filters( "um_edit_label_{$key}", $label );
634
+ /**
635
+ * UM hook
636
+ *
637
+ * @type filter
638
+ * @title um_edit_label_all_fields
639
+ * @description Change field label on view by field $key
640
+ * @input_vars
641
+ * [{"var":"$label","type":"string","desc":"Field Label"},
642
+ * {"var":"$data","type":"array","desc":"Field Data"}]
643
+ * @change_log
644
+ * ["Since: 2.0"]
645
+ * @usage add_filter( 'um_edit_label_all_fields', 'function_name', 10, 2 );
646
+ * @example
647
+ * <?php
648
+ * add_filter( 'um_edit_label_all_fields', 'my_edit_label_all_fields', 10, 2 );
649
+ * function my_edit_label_all_fields( $label, $data ) {
650
+ * // your code here
651
+ * return $label;
652
+ * }
653
+ * ?>
654
+ */
655
+ $label = apply_filters( 'um_edit_label_all_fields', $label, $data );
656
+ }
657
+
658
+ $fields_without_metakey = UM()->builtin()->get_fields_without_metakey();
659
+ $for_attr = '';
660
+ if ( ! in_array( $data['type'], $fields_without_metakey ) ) {
661
+ $for_attr = ' for="' . esc_attr( $key . UM()->form()->form_suffix ) . '"';
662
+ }
663
+
664
+ $output .= '<label' . $for_attr . '>' . __( $label, 'ultimate-member' ) . '</label>';
665
+
666
+ if ( ! empty( $data['help'] ) && $this->viewing == false && ! strstr( $key, 'confirm_user_pass' ) ) {
667
+
668
+ if ( ! UM()->mobile()->isMobile() ) {
669
+ if ( ! isset( $this->disable_tooltips ) ) {
670
+ $output .= '<span class="um-tip um-tip-' . ( is_rtl() ? 'e' : 'w' ) . '" title="' . esc_attr__( $data['help'], 'ultimate-member' ) . '"><i class="um-icon-help-circled"></i></span>';
671
+ }
672
+ }
673
+
674
+ if ( UM()->mobile()->isMobile() || isset( $this->disable_tooltips ) ) {
675
+ $output .= '<span class="um-tip-text">' . __( $data['help'], 'ultimate-member' ) . '</span>';
676
+ }
677
+
678
+ }
679
+
680
+ $output .= '<div class="um-clear"></div></div>';
681
+
682
+ return $output;
683
+ }
684
+
685
+
686
+ /**
687
+ * Output field classes
688
+ *
689
+ * @param string $key
690
+ * @param array $data
691
+ * @param string $add
692
+ *
693
+ * @return string
694
+ */
695
+ function get_class( $key, $data, $add = null ) {
696
+ $classes = null;
697
+
698
+ $classes .= 'um-form-field ';
699
+
700
+ if ( $this->is_error( $key ) ) {
701
+ $classes .= 'um-error ';
702
+ } else {
703
+ $classes .= 'valid ';
704
+ }
705
+
706
+ if ( ! isset( $data['required'] ) ) {
707
+ $classes .= 'not-required ';
708
+ }
709
+
710
+ if ( $data['type'] == 'date' ) {
711
+ $classes .= 'um-datepicker ';
712
+ }
713
+
714
+ if ( $data['type'] == 'time' ) {
715
+ $classes .= 'um-timepicker ';
716
+ }
717
+
718
+ if ( ! empty( $data['icon'] ) && isset( $this->field_icons ) && $this->field_icons == 'field' ) {
719
+ $classes .= 'um-iconed ';
720
+ }
721
+
722
+ if ( $add ) {
723
+ $classes .= $add . ' ';
724
+ }
725
+
726
+ /**
727
+ * UM hook
728
+ *
729
+ * @type filter
730
+ * @title um_extend_field_classes
731
+ * @description Change field classes
732
+ * @input_vars
733
+ * [{"var":"$classes","type":"string","desc":"Field Classes"},
734
+ * {"var":"$key","type":"string","desc":"Field Key"},
735
+ * {"var":"$data","type":"array","desc":"Field Data"}]
736
+ * @change_log
737
+ * ["Since: 2.0"]
738
+ * @usage add_filter( 'um_extend_field_classes', 'function_name', 10, 3 );
739
+ * @example
740
+ * <?php
741
+ * add_filter( 'um_extend_field_classes', 'my_extend_field_classes', 10, 3 );
742
+ * function my_extend_field_classes( $classes, $key, $data ) {
743
+ * // your code here
744
+ * return $classes;
745
+ * }
746
+ * ?>
747
+ */
748
+ $classes = apply_filters( 'um_extend_field_classes', $classes, $key, $data );
749
+
750
+ return $classes;
751
+ }
752
+
753
+
754
+ /**
755
+ * Gets field value
756
+ *
757
+ * @param string $key
758
+ * @param boolean $default
759
+ * @param array $data
760
+ *
761
+ * @return mixed
762
+ */
763
+ function field_value( $key, $default = false, $data = null ) {
764
+ // preview in backend
765
+ if ( isset( UM()->user()->preview ) && UM()->user()->preview ) {
766
+ if ( $this->set_mode == 'login' || $this->set_mode == 'register' ) {
767
+ return '';
768
+ } else {
769
+ $val = um_user( $key );
770
+ if ( ! empty( $val ) ) {
771
+ return $val;
772
+ } else {
773
+ return '';
774
+ }
775
+ }
776
+ }
777
+
778
+ if ( isset( $_SESSION ) && isset( $_SESSION['um_social_profile'][ $key ] ) && isset( $this->set_mode ) && $this->set_mode == 'register' ) {
779
+ return $_SESSION['um_social_profile'][ $key ];
780
+ }
781
+
782
+ $type = ( isset( $data['type'] ) ) ? $data['type'] : '';
783
+
784
+ // normal state
785
+ if ( isset( UM()->form()->post_form[ $key ] ) ) {
786
+ //show empty value for password fields
787
+ if ( strstr( $key, 'user_pass' ) && $this->set_mode != 'password' ) {
788
+ return '';
789
+ }
790
+
791
+ if ( 'profile' === $this->set_mode ) {
792
+ if ( ! isset( UM()->form()->post_form['profile_nonce'] ) || false === wp_verify_nonce( UM()->form()->post_form['profile_nonce'], 'um-profile-nonce' . UM()->user()->target_id ) ) {
793
+ return '';
794
+ }
795
+ }
796
+
797
+ return stripslashes_deep( UM()->form()->post_form[ $key ] );
798
+
799
+ } elseif ( um_user( $key ) && $this->editing == true ) {
800
+
801
+ //show empty value for password fields
802
+ if ( strstr( $key, 'user_pass' ) || $type == 'password' ) {
803
+ return '';
804
+ }
805
+
806
+ $value = um_user( $key );
807
+ /**
808
+ * UM hook
809
+ *
810
+ * @type filter
811
+ * @title um_edit_{$key}_field_value
812
+ * @description Change field value on edit by field $key
813
+ * @input_vars
814
+ * [{"var":"$value","type":"string","desc":"Field Value"},
815
+ * {"var":"$key","type":"string","desc":"Field Key"}]
816
+ * @change_log
817
+ * ["Since: 2.0"]
818
+ * @usage add_filter( 'um_edit_{$key}_field_value', 'function_name', 10, 2 );
819
+ * @example
820
+ * <?php
821
+ * add_filter( 'um_edit_{$key}_field_value', 'my_edit_field_value', 10, 2 );
822
+ * function my_edit_field_value( $value, $key ) {
823
+ * // your code here
824
+ * return $value;
825
+ * }
826
+ * ?>
827
+ */
828
+ $value = apply_filters( "um_edit_{$key}_field_value", $value, $key );
829
+ /**
830
+ * UM hook
831
+ *
832
+ * @type filter
833
+ * @title um_edit_{$type}_field_value
834
+ * @description Change field value on edit by field $type
835
+ * @input_vars
836
+ * [{"var":"$value","type":"string","desc":"Field Value"},
837
+ * {"var":"$key","type":"string","desc":"Field Key"}]
838
+ * @change_log
839
+ * ["Since: 2.0"]
840
+ * @usage add_filter( 'um_edit_{$type}_field_value', 'function_name', 10, 2 );
841
+ * @example
842
+ * <?php
843
+ * add_filter( 'um_edit_{$type}_field_value', 'my_edit_field_value', 10, 2 );
844
+ * function my_edit_field_value( $value, $key ) {
845
+ * // your code here
846
+ * return $value;
847
+ * }
848
+ * ?>
849
+ */
850
+ $value = apply_filters( "um_edit_{$type}_field_value", $value, $key );
851
+
852
+ } elseif ( ( um_user( $key ) || isset( $data['show_anyway'] ) ) && $this->viewing == true ) {
853
+
854
+ return um_filtered_value( $key, $data );
855
+
856
+ } elseif ( isset( UM()->user()->profile[ $key ] ) ) {
857
+
858
+ $value = UM()->user()->profile[ $key ];
859
+ /**
860
+ * UM hook
861
+ *
862
+ * @type filter
863
+ * @title um_edit_{$key}_field_value
864
+ * @description Change field value on edit by field $key
865
+ * @input_vars
866
+ * [{"var":"$value","type":"string","desc":"Field Value"},
867
+ * {"var":"$key","type":"string","desc":"Field Key"}]
868
+ * @change_log
869
+ * ["Since: 2.0"]
870
+ * @usage add_filter( 'um_edit_{$key}_field_value', 'function_name', 10, 2 );
871
+ * @example
872
+ * <?php
873
+ * add_filter( 'um_edit_{$key}_field_value', 'my_edit_field_value', 10, 2 );
874
+ * function my_edit_field_value( $value, $key ) {
875
+ * // your code here
876
+ * return $value;
877
+ * }
878
+ * ?>
879
+ */
880
+ $value = apply_filters( "um_edit_{$key}_field_value", $value, $key );
881
+ $value = maybe_unserialize( $value );
882
+
883
+ } elseif ( $default ) {
884
+
885
+ /**
886
+ * UM hook
887
+ *
888
+ * @type filter
889
+ * @title um_field_default_value
890
+ * @description Change field default value
891
+ * @input_vars
892
+ * [{"var":"$default","type":"string","desc":"Field Default Value"},
893
+ * {"var":"$data","type":"array","desc":"Field Data"},
894
+ * {"var":"$type","type":"string","desc":"Field Type"}]
895
+ * @change_log
896
+ * ["Since: 2.0"]
897
+ * @usage add_filter( 'um_field_default_value', 'function_name', 10, 2 );
898
+ * @example
899
+ * <?php
900
+ * add_filter( 'um_field_default_value', 'my_field_default_value', 10, 2 );
901
+ * function my_field_default_value( $default, $data, $type ) {
902
+ * // your code here
903
+ * return $default;
904
+ * }
905
+ * ?>
906
+ */
907
+ $default = apply_filters( 'um_field_default_value', $default, $data, $type );
908
+ /**
909
+ * UM hook
910
+ *
911
+ * @type filter
912
+ * @title um_field_{$key}_default_value
913
+ * @description Change field default value by $key
914
+ * @input_vars
915
+ * [{"var":"$default","type":"string","desc":"Field Default Value"},
916
+ * {"var":"$data","type":"array","desc":"Field Data"}]
917
+ * @change_log
918
+ * ["Since: 2.0"]
919
+ * @usage add_filter( 'um_field_{$key}_default_value', 'function_name', 10, 2 );
920
+ * @example
921
+ * <?php
922
+ * add_filter( 'um_field_{$key}_default_value', 'my_field_default_value', 10, 2 );
923
+ * function my_field_default_value( $default, $data ) {
924
+ * // your code here
925
+ * return $default;
926
+ * }
927
+ * ?>
928
+ */
929
+ $default = apply_filters( "um_field_{$key}_default_value", $default, $data );
930
+ /**
931
+ * UM hook
932
+ *
933
+ * @type filter
934
+ * @title um_field_{$type}_default_value
935
+ * @description Change field default value by $type
936
+ * @input_vars
937
+ * [{"var":"$default","type":"string","desc":"Field Default Value"},
938
+ * {"var":"$data","type":"array","desc":"Field Data"}]
939
+ * @change_log
940
+ * ["Since: 2.0"]
941
+ * @usage add_filter( 'um_field_{$type}_default_value', 'function_name', 10, 2 );
942
+ * @example
943
+ * <?php
944
+ * add_filter( 'um_field_{$type}_default_value', 'my_field_default_value', 10, 2 );
945
+ * function my_field_default_value( $default, $data ) {
946
+ * // your code here
947
+ * return $default;
948
+ * }
949
+ * ?>
950
+ */
951
+ $default = apply_filters( "um_field_{$type}_default_value", $default, $data );
952
+
953
+ }
954
+
955
+ // Default Value for Registration Form and Profile Form editing
956
+ if ( ! isset( $value ) && ( $this->set_mode == 'register' || $this->editing == true ) ) {
957
+
958
+ /**
959
+ * UM hook
960
+ *
961
+ * @type filter
962
+ * @title um_edit_{$key}_field_value
963
+ * @description Change field value on edit by field $key
964
+ * @input_vars
965
+ * [{"var":"$value","type":"string","desc":"Field Value"},
966
+ * {"var":"$key","type":"string","desc":"Field Key"}]
967
+ * @change_log
968
+ * ["Since: 2.0"]
969
+ * @usage add_filter( 'um_edit_{$key}_field_value', 'function_name', 10, 2 );
970
+ * @example
971
+ * <?php
972
+ * add_filter( 'um_edit_{$key}_field_value', 'my_edit_field_value', 10, 2 );
973
+ * function my_edit_field_value( $value, $key ) {
974
+ * // your code here
975
+ * return $value;
976
+ * }
977
+ * ?>
978
+ */
979
+ $value = apply_filters( "um_edit_{$key}_field_value", $default, $key );
980
+
981
+ } elseif ( isset( $value ) && is_array( $value ) && ! count( $value ) ) {
982
+ $value = '';
983
+ } elseif ( ! isset( $value ) ) {
984
+ $value = '';
985
+ }
986
+
987
+
988
+ /**
989
+ * UM hook
990
+ *
991
+ * @type filter
992
+ * @title um_field_value
993
+ * @description Change field value
994
+ * @input_vars
995
+ * [{"var":"$value","type":"string","desc":"Field Value"},
996
+ * {"var":"$key","type":"string","desc":"Field Key"},,
997
+ * {"var":"$type","type":"string","desc":"Field Type"}
998
+ * {"var":"$default","type":"string","desc":"Field Default Value"},
999
+ * {"var":"$data","type":"array","desc":"Field Data"}]
1000
+ * @usage add_filter( 'um_field_value', 'function_name', 10, 5 );
1001
+ */
1002
+ return apply_filters( 'um_field_value', $value, $default, $key, $type, $data );
1003
+ }
1004
+
1005
+
1006
+ /**
1007
+ * Checks if an option is selected
1008
+ *
1009
+ * is used by Select, Multiselect and Checkbox fields
1010
+ *
1011
+ * @param string $key
1012
+ * @param string $value
1013
+ * @param array $data
1014
+ *
1015
+ * @return boolean
1016
+ */
1017
+ function is_selected( $key, $value, $data ) {
1018
+ global $wpdb;
1019
+
1020
+ /**
1021
+ * UM hook
1022
+ *
1023
+ * @type filter
1024
+ * @title um_is_selected_filter_key
1025
+ * @description Change is selected filter key
1026
+ * @input_vars
1027
+ * [{"var":"$key","type":"string","desc":"Selected filter key"}]
1028
+ * @change_log
1029
+ * ["Since: 2.0"]
1030
+ * @usage add_filter( 'um_is_selected_filter_key', 'function_name', 10, 1 );
1031
+ * @example
1032
+ * <?php
1033
+ * add_filter( 'um_is_selected_filter_key', 'my_selected_filter_key', 10, 1 );
1034
+ * function my_selected_filter_key( $key ) {
1035
+ * // your code here
1036
+ * return $key;
1037
+ * }
1038
+ * ?>
1039
+ */
1040
+ $key = apply_filters( 'um_is_selected_filter_key', $key );
1041
+
1042
+ if ( isset( UM()->form()->post_form[ $key ] ) ) {
1043
+
1044
+ if ( is_array( UM()->form()->post_form[ $key ] ) ) {
1045
+
1046
+ if ( in_array( $value, UM()->form()->post_form[ $key ] ) ) {
1047
+ return true;
1048
+ }
1049
+
1050
+ $stripslashed = array_map( 'stripslashes', UM()->form()->post_form[ $key ] );
1051
+ if ( in_array( $value, $stripslashed ) ) {
1052
+ return true;
1053
+ }
1054
+
1055
+ if ( in_array( html_entity_decode( $value ), UM()->form()->post_form[ $key ] ) ) {
1056
+ return true;
1057
+ }
1058
+ } else {
1059
+
1060
+ if ( $value == UM()->form()->post_form[ $key ] ) {
1061
+ return true;
1062
+ }
1063
+
1064
+ }
1065
+
1066
+ } else {
1067
+
1068
+ $field_value = um_user( $key );
1069
+ if ( ! $field_value ) {
1070
+ $field_value = 0;
1071
+ }
1072
+
1073
+ if ( $field_value == 0 && $value == '0' ) {
1074
+ $value = (int) $value;
1075
+ }
1076
+
1077
+ if ( strstr( $key, 'role_' ) || $key == 'role' ) {
1078
+ $field_value = strtolower( UM()->roles()->get_editable_priority_user_role( um_user( 'ID' ) ) );
1079
+
1080
+ $role_keys = get_option( 'um_roles', array() );
1081
+
1082
+ if ( ! empty( $role_keys ) ) {
1083
+ if ( in_array( $field_value, $role_keys ) ) {
1084
+ $field_value = 'um_' . $field_value;
1085
+ }
1086
+ }
1087
+ }
1088
+
1089
+
1090
+ /**
1091
+ * UM hook
1092
+ *
1093
+ * @type filter
1094
+ * @title um_is_selected_filter_value
1095
+ * @description Change is selected filter value
1096
+ * @input_vars
1097
+ * [{"var":"$value","type":"string","desc":"Selected filter value"},
1098
+ * {"var":"$key","type":"string","desc":"Selected filter key"},
1099
+ * {"var":"$value","type":"string","desc":"Selected filter value"}]
1100
+ * @change_log
1101
+ * ["Since: 2.0"]
1102
+ * @usage add_filter( 'um_is_selected_filter_value', 'function_name', 10, 2 );
1103
+ * @example
1104
+ * <?php
1105
+ * add_filter( 'um_is_selected_filter_value', 'my_selected_filter_value', 10, 2 );
1106
+ * function my_selected_filter_value( $value, $key ) {
1107
+ * // your code here
1108
+ * return $field_value;
1109
+ * }
1110
+ * ?>
1111
+ */
1112
+ $field_value = apply_filters( 'um_is_selected_filter_value', $field_value, $key, $value );
1113
+
1114
+ /**
1115
+ * UM hook
1116
+ *
1117
+ * @type filter
1118
+ * @title um_is_selected_filter_data
1119
+ * @description Change is selected filter data
1120
+ * @input_vars
1121
+ * [{"var":"$data","type":"array","desc":"Selected filter value"},
1122
+ * {"var":"$key","type":"string","desc":"Selected filter key"},
1123
+ * {"var":"$value","type":"string","desc":"Selected filter value"}]
1124
+ * @change_log
1125
+ * ["Since: 2.0"]
1126
+ * @usage add_filter( 'um_is_selected_filter_data', 'function_name', 10, 3 );
1127
+ * @example
1128
+ * <?php
1129
+ * add_filter( 'um_is_selected_filter_data', 'my_selected_filter_data', 10, 3 );
1130
+ * function my_selected_filter_data( $data, $key, $value ) {
1131
+ * // your code here
1132
+ * return $data;
1133
+ * }
1134
+ * ?>
1135
+ */
1136
+ $data = apply_filters( 'um_is_selected_filter_data', $data, $key, $field_value );
1137
+
1138
+ if ( ! $this->editing || 'custom' == $this->set_mode ) {
1139
+ // show default on register screen if there is default
1140
+ if ( isset( $data['default'] ) ) {
1141
+
1142
+ if ( ! is_array( $data['default'] ) && $data['default'] === $value ) {
1143
+ return true;
1144
+ }
1145
+
1146
+ if ( is_array( $data['default'] ) && in_array( $value, $data['default'] ) ) {
1147
+ return true;
1148
+ }
1149
+
1150
+ if ( is_array( $data['default'] ) && array_intersect( $data['options'], $data['default'] ) ) {
1151
+ return true;
1152
+ }
1153
+
1154
+ // default value with comma
1155
+ if ( is_string( $data['default'] ) && strstr( $data['default'], ',' ) ) {
1156
+ $choices = array_map( 'trim', explode( ',', $data['default'] ) );
1157
+ if ( in_array( $value, $choices ) ) {
1158
+ return true;
1159
+ }
1160
+ }
1161
+
1162
+ }
1163
+ } else {
1164
+
1165
+ if ( $field_value && is_array( $field_value ) && ( in_array( $value, $field_value ) || in_array( html_entity_decode( $value ), $field_value ) ) ) {
1166
+ return true;
1167
+ }
1168
+
1169
+ if ( $field_value == 0 && ! is_array( $field_value ) && $field_value === $value ) {
1170
+ return true;
1171
+ }
1172
+
1173
+ if ( $field_value && ! is_array( $field_value ) && $field_value == $value ) {
1174
+ return true;
1175
+ }
1176
+
1177
+ if ( $field_value && ! is_array( $field_value ) && html_entity_decode( $field_value ) == html_entity_decode( $value ) ) {
1178
+ return true;
1179
+ }
1180
+
1181
+ // show default on edit screen if there isn't meta row in usermeta table
1182
+ $direct_db_value = $wpdb->get_var( $wpdb->prepare( "SELECT ISNULL( meta_value ) FROM {$wpdb->usermeta} WHERE user_id = %d AND meta_key = %s", um_user( 'ID' ), $key ) );
1183
+ if ( ! isset( $direct_db_value ) && isset( $data['default'] ) ) {
1184
+ if ( ! is_array( $data['default'] ) && strstr( $data['default'], ', ' ) ) {
1185
+ $data['default'] = explode( ', ', $data['default'] );
1186
+ }
1187
+
1188
+ if ( ! is_array( $data['default'] ) && $data['default'] === $value ) {
1189
+ return true;
1190
+ }
1191
+
1192
+ if ( is_array( $data['default'] ) && in_array( $value, $data['default'] ) ) {
1193
+ return true;
1194
+ }
1195
+ }
1196
+ }
1197
+
1198
+ }
1199
+
1200
+ return false;
1201
+ }
1202
+
1203
+
1204
+ /**
1205
+ * Checks if a radio button is selected
1206
+ *
1207
+ * @param string $key
1208
+ * @param string $value
1209
+ * @param array $data
1210
+ *
1211
+ * @return boolean
1212
+ */
1213
+ function is_radio_checked( $key, $value, $data ) {
1214
+ global $wpdb;
1215
+
1216
+ if ( isset( UM()->form()->post_form[ $key ] ) ) {
1217
+ if ( is_array( UM()->form()->post_form[ $key ] ) && in_array( $value, UM()->form()->post_form[ $key ] ) ) {
1218
+ return true;
1219
+ } elseif ( $value == UM()->form()->post_form[ $key ] ) {
1220
+ return true;
1221
+ }
1222
+ } else {
1223
+
1224
+ if ( $this->editing && 'custom' !== $this->set_mode ) {
1225
+ if ( um_user( $key ) ) {
1226
+
1227
+ $um_user_value = um_user( $key );
1228
+
1229
+ if ( strstr( $key, 'role_' ) || $key == 'role' ) {
1230
+ $um_user_value = strtolower( UM()->roles()->get_editable_priority_user_role( um_user( 'ID' ) ) );
1231
+
1232
+ $role_keys = get_option( 'um_roles', array() );
1233
+
1234
+ if ( ! empty( $role_keys ) ) {
1235
+ if ( in_array( $um_user_value, $role_keys ) ) {
1236
+ $um_user_value = 'um_' . $um_user_value;
1237
+ }
1238
+ }
1239
+ }
1240
+
1241
+ if ( $um_user_value == $value ) {
1242
+ return true;
1243
+ }
1244
+
1245
+ if ( is_array( $um_user_value ) && in_array( $value, $um_user_value ) ) {
1246
+ return true;
1247
+ }
1248
+
1249
+ if ( is_array( $um_user_value ) ) {
1250
+ foreach ( $um_user_value as $u ) {
1251
+ if ( $u == html_entity_decode( $value ) ) {
1252
+ return true;
1253
+ }
1254
+ }
1255
+ }
1256
+ } else {
1257
+
1258
+ // show default on edit screen if there isn't meta row in usermeta table
1259
+ $direct_db_value = $wpdb->get_var( $wpdb->prepare( "SELECT ISNULL( meta_value ) FROM {$wpdb->usermeta} WHERE user_id = %d AND meta_key = %s", um_user( 'ID' ), $key ) );
1260
+ if ( ! isset( $direct_db_value ) && isset( $data['default'] ) && $data['default'] == $value ) {
1261
+ return true;
1262
+ }
1263
+
1264
+ }
1265
+ } else {
1266
+ if ( isset( $data['default'] ) && $data['default'] == $value ) {
1267
+ return true;
1268
+ }
1269
+ }
1270
+ }
1271
+
1272
+ return false;
1273
+ }
1274
+
1275
+
1276
+ /**
1277
+ * Get field icon
1278
+ *
1279
+ * @param string $key
1280
+ *
1281
+ * @return string
1282
+ */
1283
+ function get_field_icon( $key ) {
1284
+ $fields = UM()->builtin()->all_user_fields;
1285
+ if ( isset( $fields[ $key ]['icon'] ) ) {
1286
+ return $fields[ $key ]['icon'];
1287
+ }
1288
+
1289
+ return '';
1290
+ }
1291
+
1292
+
1293
+ /**
1294
+ * Gets selected option value from a callback function
1295
+ *
1296
+ * @param string $value
1297
+ * @param array $data
1298
+ * @param string $type
1299
+ *
1300
+ * @return string
1301
+ */
1302
+ function get_option_value_from_callback( $value, $data, $type ) {
1303
+
1304
+ if ( in_array( $type, array( 'select', 'multiselect' ) ) && ! empty( $data['custom_dropdown_options_source'] ) ) {
1305
+
1306
+ $has_custom_source = apply_filters( "um_has_dropdown_options_source__{$data['metakey']}", false );
1307
+
1308
+ if ( $has_custom_source ) {
1309
+
1310
+ $opts = apply_filters( "um_get_field__{$data['metakey']}", array() );
1311
+ $arr_options = $opts['options'];
1312
+
1313
+ } elseif ( function_exists( $data['custom_dropdown_options_source'] ) ) {
1314
+ if ( isset( $data['parent_dropdown_relationship'] ) ) {
1315
+ $_POST['parent_option_name'] = $data['parent_dropdown_relationship'];
1316
+ $_POST['parent_option'] = um_user( $data['parent_dropdown_relationship'] );
1317
+
1318
+ $arr_options = call_user_func( $data['custom_dropdown_options_source'], $data['parent_dropdown_relationship'] );
1319
+ } else {
1320
+ $arr_options = call_user_func( $data['custom_dropdown_options_source'] );
1321
+ }
1322
+ }
1323
+
1324
+ if ( $has_custom_source || function_exists( $data['custom_dropdown_options_source'] ) ) {
1325
+ if ( $type == 'select' ) {
1326
+ if ( ! empty( $arr_options[ $value ] ) ) {
1327
+ return $arr_options[ $value ];
1328
+ } elseif ( ! empty( $data['default'] ) && empty( $arr_options[ $value ] ) ) {
1329
+ return $arr_options[ $data['default'] ];
1330
+ } else {
1331
+ return '';
1332
+ }
1333
+ } elseif ( $type == 'multiselect' ) {
1334
+
1335
+ if ( is_array( $value ) ) {
1336
+ $values = $value;
1337
+ } else {
1338
+ $values = explode( ', ', $value );
1339
+ }
1340
+
1341
+ $arr_paired_options = array();
1342
+
1343
+ foreach ( $values as $option ) {
1344
+ if ( isset( $arr_options[ $option ] ) ) {
1345
+ $arr_paired_options[] = $arr_options[ $option ];
1346
+ }
1347
+ }
1348
+
1349
+ return implode( ', ', $arr_paired_options );
1350
+ }
1351
+ }
1352
+
1353
+
1354
+ }
1355
+
1356
+ return $value;
1357
+ }
1358
+
1359
+
1360
+ /**
1361
+ * Get select options from a callback function
1362
+ *
1363
+ * @param array $data
1364
+ * @param string $type
1365
+ *
1366
+ * @return array $arr_options
1367
+ */
1368
+ function get_options_from_callback( $data, $type ) {
1369
+ $arr_options = array();
1370
+
1371
+ if ( in_array( $type, array( 'select', 'multiselect' ) ) && ! empty( $data['custom_dropdown_options_source'] ) ) {
1372
+
1373
+ if ( function_exists( $data['custom_dropdown_options_source'] ) ) {
1374
+ if ( isset( $data['parent_dropdown_relationship'] ) ) {
1375
+ $arr_options = call_user_func( $data['custom_dropdown_options_source'], $data['parent_dropdown_relationship'] );
1376
+ } else {
1377
+ $arr_options = call_user_func( $data['custom_dropdown_options_source'] );
1378
+ }
1379
+ }
1380
+
1381
+ }
1382
+
1383
+ return $arr_options;
1384
+ }
1385
+
1386
+
1387
+ /**
1388
+ * Get field type
1389
+ *
1390
+ * @param string $key
1391
+ *
1392
+ * @return string
1393
+ */
1394
+ function get_field_type( $key ) {
1395
+ $fields = UM()->builtin()->all_user_fields;
1396
+ if ( isset( $fields[ $key ]['type'] ) ) {
1397
+ return $fields[ $key ]['type'];
1398
+ }
1399
+
1400
+ return '';
1401
+ }
1402
+
1403
+
1404
+ /**
1405
+ * Get field label
1406
+ *
1407
+ * @param string $key
1408
+ *
1409
+ * @return string
1410
+ */
1411
+ function get_label( $key ) {
1412
+ $label = '';
1413
+
1414
+ $fields = UM()->builtin()->all_user_fields;
1415
+ if ( isset( $fields[ $key ]['label'] ) ) {
1416
+ $label = stripslashes( $fields[ $key ]['label'] );
1417
+ }
1418
+
1419
+ if ( empty( $label ) && isset( $fields[ $key ]['title'] ) ) {
1420
+ $label = stripslashes( $fields[ $key ]['title'] );
1421
+ }
1422
+
1423
+ /**
1424
+ * UM hook
1425
+ *
1426
+ * @type filter
1427
+ * @title um_change_field_label
1428
+ * @description Change Field Label
1429
+ * @input_vars
1430
+ * [{"var":"$label","type":"string","desc":"Field Label"},
1431
+ * {"var":"$key","type":"string","desc":"Field Key"}]
1432
+ * @change_log
1433
+ * ["Since: 2.0.30"]
1434
+ * @usage add_filter( 'um_change_field_label', 'function_name', 10, 2 );
1435
+ * @example
1436
+ * <?php
1437
+ * add_filter( 'um_change_field_label', 'my_change_field_label', 10, 2 );
1438
+ * function my_form_fields( $label, $key ) {
1439
+ * // your code here
1440
+ * return $label;
1441
+ * }
1442
+ * ?>
1443
+ */
1444
+ $label = apply_filters( 'um_change_field_label', $label, $key );
1445
+
1446
+ $label = sprintf( __( '%s', 'ultimate-member' ), $label );
1447
+ return $label;
1448
+ }
1449
+
1450
+
1451
+ /**
1452
+ * Get field title
1453
+ *
1454
+ * @param string $key
1455
+ *
1456
+ * @return string
1457
+ */
1458
+ function get_field_title( $key ) {
1459
+ $fields = UM()->builtin()->all_user_fields;
1460
+ if ( isset( $fields[ $key ]['title'] ) ) {
1461
+ return $fields[ $key ]['title'];
1462
+ }
1463
+ if ( isset( $fields[ $key ]['label'] ) ) {
1464
+ return $fields[ $key ]['label'];
1465
+ }
1466
+
1467
+ return __( 'Custom Field', 'ultimate-member' );
1468
+ }
1469
+
1470
+
1471
+ /**
1472
+ * Get form fields
1473
+ *
1474
+ * @return array
1475
+ */
1476
+ function get_fields() {
1477
+ /**
1478
+ * UM hook
1479
+ *
1480
+ * @type filter
1481
+ * @title um_get_form_fields
1482
+ * @description Extend form fields
1483
+ * @input_vars
1484
+ * [{"var":"$fields","type":"array","desc":"Selected filter value"}]
1485
+ * @change_log
1486
+ * ["Since: 2.0"]
1487
+ * @usage add_filter( 'um_get_form_fields', 'function_name', 10, 1 );
1488
+ * @example
1489
+ * <?php
1490
+ * add_filter( 'um_get_form_fields', 'my_form_fields', 10, 1 );
1491
+ * function my_form_fields( $fields ) {
1492
+ * // your code here
1493
+ * return $fields;
1494
+ * }
1495
+ * ?>
1496
+ */
1497
+ $this->fields = apply_filters( 'um_get_form_fields', array() );
1498
+ return $this->fields;
1499
+ }
1500
+
1501
+
1502
+ /**
1503
+ * Get specific field
1504
+ *
1505
+ * @param $key
1506
+ *
1507
+ * @return mixed
1508
+ * @throws \Exception
1509
+ */
1510
+ function get_field( $key ) {
1511
+ $fields = $this->get_fields();
1512
+
1513
+ if ( isset( $fields ) && is_array( $fields ) && isset( $fields[ $key ] ) ) {
1514
+ $array = $fields[ $key ];
1515
+ } else {
1516
+ if ( ! isset( UM()->builtin()->predefined_fields[ $key ] ) && ! isset( UM()->builtin()->all_user_fields[ $key ] ) ) {
1517
+ return '';
1518
+ }
1519
+ $array = ( isset( UM()->builtin()->predefined_fields[ $key ] ) ) ? UM()->builtin()->predefined_fields[ $key ] : UM()->builtin()->all_user_fields[ $key ];
1520
+ }
1521
+
1522
+ $array['classes'] = null;
1523
+
1524
+ if ( ! isset( $array['placeholder'] ) ) {
1525
+ $array['placeholder'] = null;
1526
+ }
1527
+ if ( ! isset( $array['required'] ) ) {
1528
+ $array['required'] = null;
1529
+ }
1530
+ if ( ! isset( $array['validate'] ) ) {
1531
+ $array['validate'] = null;
1532
+ }
1533
+ if ( ! isset( $array['default'] ) ) {
1534
+ $array['default'] = null;
1535
+ }
1536
+
1537
+ if ( isset( $array['conditions'] ) && is_array( $array['conditions'] ) && ! $this->viewing ) {
1538
+ $array['conditional'] = '';
1539
+
1540
+ foreach ( $array['conditions'] as $cond_id => $cond ) {
1541
+ $array['conditional'] .= ' data-cond-' . $cond_id . '-action="' . esc_attr( $cond[0] ) . '" data-cond-' . $cond_id . '-field="' . esc_attr( $cond[1] ) . '" data-cond-' . $cond_id . '-operator="' . esc_attr( $cond[2] ) . '" data-cond-' . $cond_id . '-value="' . esc_attr( $cond[3] ) . '"';
1542
+ }
1543
+
1544
+ $array['classes'] .= ' um-is-conditional';
1545
+
1546
+ } else {
1547
+ $array['conditional'] = null;
1548
+ }
1549
+
1550
+ $fields_without_metakey = UM()->builtin()->get_fields_without_metakey();
1551
+
1552
+ if ( ! in_array( $array['type'], $fields_without_metakey ) ) {
1553
+ $array['classes'] .= ' um-field-' . esc_attr( $key );
1554
+ }
1555
+ $array['classes'] .= ' um-field-' . esc_attr( $array['type'] );
1556
+ $array['classes'] .= ' um-field-type_' . esc_attr( $array['type'] );
1557
+
1558
+ switch ( $array['type'] ) {
1559
+
1560
+ case 'googlemap':
1561
+ case 'youtube_video':
1562
+ case 'vimeo_video':
1563
+ case 'soundcloud_track':
1564
+ $array['disabled'] = '';
1565
+ $array['input'] = 'text';
1566
+ break;
1567
+
1568
+ case 'text':
1569
+
1570
+ $array['disabled'] = '';
1571
+
1572
+ if ( $key == 'user_login' && isset( $this->set_mode ) && $this->set_mode == 'account' ) {
1573
+ $array['disabled'] = 'disabled="disabled"';
1574
+ }
1575
+
1576
+ $array['input'] = 'text';
1577
+
1578
+ break;
1579
+
1580
+ case 'password':
1581
+
1582
+ $array['input'] = 'password';
1583
+
1584
+ break;
1585
+
1586
+ case 'number':
1587
+
1588
+ $array['disabled'] = '';
1589
+
1590
+ break;
1591
+
1592
+ case 'url':
1593
+
1594
+ $array['input'] = 'text';
1595
+
1596
+ break;
1597
+
1598
+ case 'date':
1599
+
1600
+ $array['input'] = 'text';
1601
+
1602
+ if ( ! isset( $array['format'] ) ) {
1603
+ $array['format'] = 'j M Y';
1604
+ }
1605
+
1606
+ switch ( $array['format'] ) {
1607
+ case 'j M Y':
1608
+ $js_format = 'd mmm yyyy';
1609
+ break;
1610
+ case 'j F Y':
1611
+ $js_format = 'd mmmm yyyy';
1612
+ break;
1613
+ case 'M j Y':
1614
+ $js_format = 'mmm d yyyy';
1615
+ break;
1616
+ case 'F j Y':
1617
+ $js_format = 'mmmm d yyyy';
1618
+ break;
1619
+ }
1620
+
1621
+ $array['js_format'] = $js_format;
1622
+
1623
+ if ( ! isset( $array['range'] ) ) {
1624
+ $array['range'] = 'years';
1625
+ }
1626
+ if ( ! isset( $array['years'] ) ) {
1627
+ $array['years'] = 100;
1628
+ }
1629
+ if ( ! isset( $array['years_x'] ) ) {
1630
+ $array['years_x'] = 'past';
1631
+ }
1632
+ if ( ! isset( $array['disabled_weekdays'] ) ) {
1633
+ $array['disabled_weekdays'] = '';
1634
+ }
1635
+
1636
+ if ( ! empty( $array['disabled_weekdays'] ) ) {
1637
+ $array['disabled_weekdays'] = '[' . implode( ',', $array['disabled_weekdays'] ) . ']';
1638
+ }
1639
+
1640
+ // When date range is strictly defined
1641
+ if ( $array['range'] == 'date_range' ) {
1642
+
1643
+ $array['date_min'] = str_replace( '/', ',', $array['range_start'] );
1644
+ $array['date_max'] = str_replace( '/', ',', $array['range_end'] );
1645
+
1646
+ } else {
1647
+
1648
+ if ( $array['years_x'] == 'past' ) {
1649
+
1650
+ $date = new \DateTime( date( 'Y-n-d' ) );
1651
+ $past = $date->modify( '-' . $array['years'] . ' years' );
1652
+ $past = $date->format( 'Y,n,d' );
1653
+
1654
+ $array['date_min'] = $past;
1655
+ $array['date_max'] = date( 'Y,n,d' );
1656
+
1657
+ } elseif ( $array['years_x'] == 'future' ) {
1658
+
1659
+ $date = new \DateTime( date( 'Y-n-d' ) );
1660
+ $future = $date->modify( '+' . $array['years'] . ' years' );
1661
+ $future = $date->format( 'Y,n,d' );
1662
+
1663
+ $array['date_min'] = date( 'Y,n,d' );
1664
+ $array['date_max'] = $future;
1665
+
1666
+ } else {
1667
+
1668
+ $date = new \DateTime( date( 'Y-n-d' ) );
1669
+ $date_f = new \DateTime( date( 'Y-n-d' ) );
1670
+ $past = $date->modify( '-' . ( $array['years'] / 2 ) . ' years' );
1671
+ $past = $date->format( 'Y,n,d' );
1672
+ $future = $date_f->modify( '+' . ( $array['years'] / 2 ) . ' years' );
1673
+ $future = $date_f->format( 'Y,n,d' );
1674
+
1675
+ $array['date_min'] = $past;
1676
+ $array['date_max'] = $future;
1677
+
1678
+ }
1679
+
1680
+ }
1681
+
1682
+ break;
1683
+
1684
+ case 'time':
1685
+
1686
+ $array['input'] = 'text';
1687
+
1688
+ if ( ! isset( $array['format'] ) ) {
1689
+ $array['format'] = 'g:i a';
1690
+ }
1691
+
1692
+ switch ( $array['format'] ) {
1693
+ case 'g:i a':
1694
+ $js_format = 'h:i a';
1695
+ break;
1696
+ case 'g:i A':
1697
+ $js_format = 'h:i A';
1698
+ break;
1699
+ case 'H:i':
1700
+ $js_format = 'HH:i';
1701
+ break;
1702
+ }
1703
+
1704
+ $array['js_format'] = $js_format;
1705
+
1706
+ if ( ! isset( $array['intervals'] ) ) {
1707
+ $array['intervals'] = 60;
1708
+ }
1709
+
1710
+ break;
1711
+
1712
+ case 'textarea':
1713
+
1714
+ if ( ! isset( $array['height'] ) ) {
1715
+ $array['height'] = '100px';
1716
+ }
1717
+
1718
+ break;
1719
+
1720
+ case 'rating':
1721
+
1722
+ if ( ! isset( $array['number'] ) ) {
1723
+ $array['number'] = 5;
1724
+ }
1725
+
1726
+ break;
1727
+
1728
+ case 'spacing':
1729
+
1730
+ if ( ! isset( $array['spacing'] ) ) {
1731
+ $array['spacing'] = '20px';
1732
+ }
1733
+
1734
+ break;
1735
+
1736
+ case 'divider':
1737
+
1738
+ if ( isset( $array['width'] ) ) {
1739
+ $array['borderwidth'] = $array['width'];
1740
+ } else {
1741
+ $array['borderwidth'] = 4;
1742
+ }
1743
+
1744
+ if ( isset( $array['color'] ) ) {
1745
+ $array['bordercolor'] = $array['color'];
1746
+ } else {
1747
+ $array['bordercolor'] = '#eee';
1748
+ }
1749
+
1750
+ if ( isset( $array['style'] ) ) {
1751
+ $array['borderstyle'] = $array['style'];
1752
+ } else {
1753
+ $array['borderstyle'] = 'solid';
1754
+ }
1755
+
1756
+ if ( ! isset( $array['divider_text'] ) ) {
1757
+ $array['divider_text'] = '';
1758
+ }
1759
+
1760
+ break;
1761
+
1762
+ case 'image':
1763
+
1764
+ if ( ! isset( $array['crop'] ) ) {
1765
+ $array['crop'] = 0;
1766
+ }
1767
+
1768
+ if ( $array['crop'] == 0 ) {
1769
+ $array['crop_data'] = 0;
1770
+ } elseif ( $array['crop'] == 1 ) {
1771
+ $array['crop_data'] = 'square';
1772
+ } elseif ( $array['crop'] == 2 ) {
1773
+ $array['crop_data'] = 'cover';
1774
+ } else {
1775
+ $array['crop_data'] = 'user';
1776
+ }
1777
+
1778
+ if ( ! isset( $array['modal_size'] ) ) {
1779
+ $array['modal_size'] = 'normal';
1780
+ }
1781
+
1782
+ if ( $array['crop'] > 0 ) {
1783
+ $array['crop_class'] = 'crop';
1784
+ } else {
1785
+ $array['crop_class'] = '';
1786
+ }
1787
+
1788
+ if ( ! isset( $array['ratio'] ) ) {
1789
+ $array['ratio'] = 1.0;
1790
+ }
1791
+
1792
+ if ( ! isset( $array['min_width'] ) ) {
1793
+ $array['min_width'] = '';
1794
+ }
1795
+ if ( ! isset( $array['min_height'] ) ) {
1796
+ $array['min_height'] = '';
1797
+ }
1798
+
1799
+ if ( $array['min_width'] == '' && $array['crop'] == 1 ) {
1800
+ $array['min_width'] = 600;
1801
+ }
1802
+ if ( $array['min_height'] == '' && $array['crop'] == 1 ) {
1803
+ $array['min_height'] = 600;
1804
+ }
1805
+
1806
+ if ( $array['min_width'] == '' && $array['crop'] == 3 ) {
1807
+ $array['min_width'] = 600;
1808
+ }
1809
+ if ( $array['min_height'] == '' && $array['crop'] == 3 ) {
1810
+ $array['min_height'] = 600;
1811
+ }
1812
+
1813
+ if ( ! isset( $array['invalid_image'] ) ) {
1814
+ $array['invalid_image'] = __( 'Please upload a valid image!', 'ultimate-member' );
1815
+ }
1816
+ if ( ! isset( $array['allowed_types'] ) ) {
1817
+ $array['allowed_types'] = 'gif,jpg,jpeg,png';
1818
+ } else {
1819
+ $array['allowed_types'] = implode( ',', $array['allowed_types'] );
1820
+ }
1821
+ if ( ! isset( $array['upload_text'] ) ) {
1822
+ $array['upload_text'] = '';
1823
+ }
1824
+ if ( ! isset( $array['button_text'] ) ) {
1825
+ $array['button_text'] = __( 'Upload', 'ultimate-member' );
1826
+ }
1827
+ if ( ! isset( $array['extension_error'] ) ) {
1828
+ $array['extension_error'] = __( 'Sorry this is not a valid image.', 'ultimate-member' );
1829
+ }
1830
+ if ( ! isset( $array['max_size_error'] ) ) {
1831
+ $array['max_size_error'] = __( 'This image is too large!', 'ultimate-member' );
1832
+ }
1833
+ if ( ! isset( $array['min_size_error'] ) ) {
1834
+ $array['min_size_error'] = __( 'This image is too small!', 'ultimate-member' );
1835
+ }
1836
+ if ( ! isset( $array['max_files_error'] ) ) {
1837
+ $array['max_files_error'] = __( 'You can only upload one image', 'ultimate-member' );
1838
+ }
1839
+ if ( empty( $array['max_size'] ) ) {
1840
+ $array['max_size'] = 999999999;
1841
+ }
1842
+ if ( ! isset( $array['upload_help_text'] ) ) {
1843
+ $array['upload_help_text'] = '';
1844
+ }
1845
+ if ( ! isset( $array['icon'] ) ) {
1846
+ $array['icon'] = '';
1847
+ }
1848
+
1849
+ break;
1850
+
1851
+ case 'file':
1852
+
1853
+ if ( ! isset( $array['modal_size'] ) ) {
1854
+ $array['modal_size'] = 'normal';
1855
+ }
1856
+
1857
+ if ( ! isset( $array['allowed_types'] ) ) {
1858
+ $array['allowed_types'] = 'pdf,txt';
1859
+ } else {
1860
+ $array['allowed_types'] = implode( ',', $array['allowed_types'] );
1861
+ }
1862
+ if ( ! isset( $array['upload_text'] ) ) {
1863
+ $array['upload_text'] = '';
1864
+ }
1865
+ if ( ! isset( $array['button_text'] ) ) {
1866
+ $array['button_text'] = __( 'Upload', 'ultimate-member' );
1867
+ }
1868
+ if ( ! isset( $array['extension_error'] ) ) {
1869
+ $array['extension_error'] = __( 'Sorry this is not a valid file.', 'ultimate-member' );
1870
+ }
1871
+ if ( ! isset( $array['max_size_error'] ) ) {
1872
+ $array['max_size_error'] = __( 'This file is too large!', 'ultimate-member' );
1873
+ }
1874
+ if ( ! isset( $array['min_size_error'] ) ) {
1875
+ $array['min_size_error'] = __( 'This file is too small!', 'ultimate-member' );
1876
+ }
1877
+ if ( ! isset( $array['max_files_error'] ) ) {
1878
+ $array['max_files_error'] = __( 'You can only upload one file', 'ultimate-member' );
1879
+ }
1880
+ if ( empty( $array['max_size'] ) ) {
1881
+ $array['max_size'] = 999999999;
1882
+ }
1883
+ if ( ! isset( $array['upload_help_text'] ) ) {
1884
+ $array['upload_help_text'] = '';
1885
+ }
1886
+ if ( ! isset( $array['icon'] ) ) {
1887
+ $array['icon'] = '';
1888
+ }
1889
+
1890
+ break;
1891
+
1892
+ case 'select':
1893
+
1894
+ break;
1895
+
1896
+ case 'multiselect':
1897
+
1898
+ break;
1899
+
1900
+ case 'group':
1901
+
1902
+ if ( ! isset( $array['max_entries'] ) ) {
1903
+ $array['max_entries'] = 0;
1904
+ }
1905
+
1906
+ break;
1907
+
1908
+ }
1909
+
1910
+ if ( ! isset( $array['visibility'] ) ) {
1911
+ $array['visibility'] = 'all';
1912
+ }
1913
+
1914
+ /**
1915
+ * UM hook
1916
+ *
1917
+ * @type filter
1918
+ * @title um_get_field__{$key}
1919
+ * @description Extend field data by field $key
1920
+ * @input_vars
1921
+ * [{"var":"$data","type":"array","desc":"Field Data"}]
1922
+ * @change_log
1923
+ * ["Since: 2.0"]
1924
+ * @usage add_filter( 'um_get_field__{$key}', 'function_name', 10, 1 );
1925
+ * @example
1926
+ * <?php
1927
+ * add_filter( 'um_get_field__{$key}', 'my_get_field', 10, 1 );
1928
+ * function my_get_field( $data ) {
1929
+ * // your code here
1930
+ * return $data;
1931
+ * }
1932
+ * ?>
1933
+ */
1934
+ $array = apply_filters( "um_get_field__{$key}", $array );
1935
+
1936
+ return $array;
1937
+ }
1938
+
1939
+
1940
+ /**
1941
+ * @param $option_value
1942
+ *
1943
+ * @return mixed|void
1944
+ */
1945
+ function filter_field_non_utf8_value( $option_value ) {
1946
+ /**
1947
+ * UM hook
1948
+ *
1949
+ * @type filter
1950
+ * @title um_field_non_utf8_value
1951
+ * @description Change dropdown option text
1952
+ * @input_vars
1953
+ * [{"var":"$value","type":"string","desc":"Option Value"}]
1954
+ * @change_log
1955
+ * ["Since: 2.0"]
1956
+ * @usage add_filter( 'um_field_non_utf8_value', 'function_name', 10, 1 );
1957
+ * @example
1958
+ * <?php
1959
+ * add_filter( 'um_field_non_utf8_value', 'my_field_non_utf8_value', 10, 1 );
1960
+ * function my_field_non_utf8_value( $value ) {
1961
+ * // your code here
1962
+ * return $value;
1963
+ * }
1964
+ * ?>
1965
+ */
1966
+ return apply_filters( 'um_field_non_utf8_value', $option_value );
1967
+ }
1968
+
1969
+
1970
+ /**
1971
+ * Getting the fields that need to be disabled in edit mode (profile)
1972
+ *
1973
+ * @param bool $_um_profile_id
1974
+ *
1975
+ * @return array
1976
+ */
1977
+ function get_restricted_fields_for_edit( $_um_profile_id = false ) {
1978
+ // fields that need to be disabled in edit mode (profile)
1979
+ $arr_restricted_fields = array( 'user_email', 'username', 'user_login', 'user_password', '_um_last_login' );
1980
+ $arr_restricted_fields = apply_filters( 'um_user_profile_restricted_edit_fields', $arr_restricted_fields, $_um_profile_id );
1981
+
1982
+ return $arr_restricted_fields;
1983
+ }
1984
+
1985
+
1986
+ /**
1987
+ * Gets a field in 'input mode'
1988
+ *
1989
+ * @param string $key
1990
+ * @param array $data
1991
+ * @param bool $rule
1992
+ * @param array $args
1993
+ *
1994
+ * @return string|null
1995
+ * @throws \Exception
1996
+ */
1997
+ function edit_field( $key, $data, $rule = false, $args = array() ) {
1998
+ global $_um_profile_id;
1999
+
2000
+ $output = '';
2001
+ $disabled = '';
2002
+ if ( empty( $_um_profile_id ) ) {
2003
+ $_um_profile_id = um_user( 'ID' );
2004
+ }
2005
+
2006
+ // get whole field data
2007
+ if ( isset( $data ) && is_array( $data ) ) {
2008
+ $data = $this->get_field( $key );
2009
+ if ( is_array( $data ) ) {
2010
+ /**
2011
+ * @var string $in_row
2012
+ * @var boolean $in_sub_row
2013
+ * @var boolean $in_column
2014
+ * @var string $type
2015
+ * @var string $metakey
2016
+ * @var int $position
2017
+ * @var string $title
2018
+ * @var string $help
2019
+ * @var array $options
2020
+ * @var string $visibility
2021
+ * @var string $label
2022
+ * @var string $placeholder
2023
+ * @var boolean $public
2024
+ * @var boolean $editable
2025
+ * @var string $icon
2026
+ * @var boolean $in_group
2027
+ * @var boolean $required
2028
+ * @var string $validate
2029
+ * @var string $default
2030
+ * @var string $conditional
2031
+ * @var string $input
2032
+ * @var string $js_format
2033
+ * @var string $date_max
2034
+ * @var string $date_min
2035
+ * @var string $disabled_weekdays
2036
+ * @var string $years_x
2037
+ * @var string $years
2038
+ * @var string $range
2039
+ * @var string $intervals
2040
+ * @var string $height
2041
+ * @var string $spacing
2042
+ * @var string $borderwidth
2043
+ * @var string $borderstyle
2044
+ * @var string $bordercolor
2045
+ * @var string $divider_text
2046
+ * @var string $crop_class
2047
+ * @var string $crop_data
2048
+ * @var string $modal_size
2049
+ * @var string $ratio
2050
+ * @var string $min_width
2051
+ * @var string $min_height
2052
+ * @var string $button_text
2053
+ * @var string $max_size
2054
+ * @var string $max_size_error
2055
+ * @var string $extension_error
2056
+ * @var string $allowed_types
2057
+ * @var string $upload_text
2058
+ * @var string $max_files_error
2059
+ * @var string $upload_help_text
2060
+ * @var string $min_size_error
2061
+ * @var string $filter
2062
+ * @var string $content
2063
+ * @var string $max_entries
2064
+ */
2065
+ extract( $data );
2066
+ }
2067
+ }
2068
+
2069
+ if ( ! isset( $data['type'] ) ) {
2070
+ return '';
2071
+ }
2072
+
2073
+ if ( isset( $data['in_group'] ) && $data['in_group'] != '' && $rule != 'group' ) {
2074
+ return '';
2075
+ }
2076
+
2077
+ // forbidden in edit mode? 'edit_forbidden' - it's field attribute predefined in the field data in code
2078
+ if ( isset( $data['edit_forbidden'] ) ) {
2079
+ return '';
2080
+ }
2081
+
2082
+ // required option? 'required_opt' - it's field attribute predefined in the field data in code
2083
+ if ( isset( $data['required_opt'] ) ) {
2084
+ $opt = $data['required_opt'];
2085
+ if ( UM()->options()->get( $opt[0] ) != $opt[1] ) {
2086
+ return '';
2087
+ }
2088
+ }
2089
+
2090
+ // required user permission 'required_perm' - it's field attribute predefined in the field data in code
2091
+ if ( isset( $data['required_perm'] ) ) {
2092
+ if ( ! UM()->roles()->um_user_can( $data['required_perm'] ) ) {
2093
+ return '';
2094
+ }
2095
+ }
2096
+
2097
+ // fields that need to be disabled in edit mode (profile) (email, username, etc.)
2098
+ $arr_restricted_fields = $this->get_restricted_fields_for_edit( $_um_profile_id );
2099
+ if ( in_array( $key, $arr_restricted_fields ) && $this->editing == true && $this->set_mode == 'profile' ) {
2100
+ return '';
2101
+ }
2102
+
2103
+
2104
+ if ( $visibility == 'view' && $this->set_mode != 'register' ) {
2105
+ return '';
2106
+ }
2107
+
2108
+ if ( ! um_can_view_field( $data ) ) {
2109
+ return '';
2110
+ }
2111
+
2112
+ um_fetch_user( $_um_profile_id );
2113
+
2114
+ // Stop return empty values build field attributes:
2115
+
2116
+ if ( $visibility == 'view' && $this->set_mode == 'register' ) {
2117
+
2118
+ um_fetch_user( get_current_user_id() );
2119
+ if ( ! um_user( 'can_edit_everyone' ) ) {
2120
+ $disabled = ' disabled="disabled" ';
2121
+ }
2122
+
2123
+ um_fetch_user( $_um_profile_id );
2124
+ if ( isset( $data['public'] ) && $data['public'] == '-2' && $data['roles'] ) {
2125
+ $current_user_roles = um_user( 'roles' );
2126
+ if ( ! empty( $current_user_roles ) && count( array_intersect( $current_user_roles, $data['roles'] ) ) > 0 ) {
2127
+ $disabled = '';
2128
+ }
2129
+ }
2130
+ }
2131
+
2132
+ if ( ! empty( $this->editing ) && $this->set_mode == 'profile' ) {
2133
+ if ( ! UM()->roles()->um_user_can( 'can_edit_everyone' ) ) {
2134
+ if ( isset( $data['editable'] ) && $data['editable'] == 0 ) {
2135
+ $disabled = ' disabled="disabled" ';
2136
+ }
2137
+ }
2138
+ }
2139
+
2140
+ $disabled = apply_filters( 'um_is_field_disabled', $disabled, $data );
2141
+
2142
+ if ( ! isset( $data['autocomplete'] ) ) {
2143
+ $autocomplete = 'off';
2144
+ }
2145
+
2146
+ if ( isset( $data['classes'] ) ) {
2147
+ $classes = explode( " ", $data['classes'] );
2148
+ }
2149
+
2150
+ um_fetch_user( $_um_profile_id );
2151
+
2152
+ /**
2153
+ * UM hook
2154
+ *
2155
+ * @type filter
2156
+ * @title um_hook_for_field_{$type}
2157
+ * @description Change field type
2158
+ * @input_vars
2159
+ * [{"var":"$type","type":"string","desc":"Field Type"}]
2160
+ * @change_log
2161
+ * ["Since: 2.0"]
2162
+ * @usage add_filter( 'um_hook_for_field_{$type}', 'function_name', 10, 1 );
2163
+ * @example
2164
+ * <?php
2165
+ * add_filter( 'um_hook_for_field_{$type}', 'my_field_type', 10, 1 );
2166
+ * function my_get_field( $type ) {
2167
+ * // your code here
2168
+ * return $type;
2169
+ * }
2170
+ * ?>
2171
+ */
2172
+ $type = apply_filters( "um_hook_for_field_{$type}", $type );
2173
+ switch ( $type ) {
2174
+
2175
+ case 'textarea':
2176
+ case 'multiselect':
2177
+ $field_id = $field_name = $key;
2178
+ $field_value = $this->field_value( $key, $default, $data );
2179
+ break;
2180
+
2181
+ case 'select':
2182
+ case 'radio':
2183
+ $form_key = str_replace( array( 'role_select', 'role_radio' ), 'role', $key );
2184
+ $field_id = $form_key;
2185
+ break;
2186
+ default:
2187
+ $field_id = '';
2188
+ break;
2189
+ }
2190
+
2191
+ /**
2192
+ * UM hook
2193
+ *
2194
+ * @type filter
2195
+ * @title um_completeness_field_id
2196
+ * @description use for change core id not allowed duplicate
2197
+ * @input_vars
2198
+ * [{"var":"$field_id","type":"string","desc":"Field id"},
2199
+ * {"var":"$data","type":"array","desc":"Field Data"}]
2200
+ * {"var":"$args","type":"array","desc":"Optional field arguments"}]
2201
+ * @change_log
2202
+ * ["Since: 2.0.13"]
2203
+ * @usage add_filter( 'um_completeness_field_id', 'function_name', 10, 3 );
2204
+ * @example
2205
+ * <?php
2206
+ * add_filter( 'um_completeness_field_id', 'function_name', 10, 3 );
2207
+ * function function_name( $field_id, $data, $args ) {
2208
+ * // your code here
2209
+ * return $field_id;
2210
+ * }
2211
+ * ?>
2212
+ */
2213
+ $field_id = apply_filters( 'um_completeness_field_id', $field_id, $data, $args );
2214
+
2215
+
2216
+ /* Begin by field type */
2217
+ switch ( $type ) {
2218
+
2219
+ /* Default: Integration */
2220
+ default:
2221
+ $mode = ( isset( $this->set_mode ) ) ? $this->set_mode : 'no_mode';
2222
+
2223
+ /**
2224
+ * UM hook
2225
+ *
2226
+ * @type filter
2227
+ * @title um_edit_field_{$mode}_{$type}
2228
+ * @description Change field html by $mode and field $type
2229
+ * @input_vars
2230
+ * [{"var":"$output","type":"string","desc":"Field HTML"},
2231
+ * {"var":"$data","type":"array","desc":"Field Data"}]
2232
+ * @change_log
2233
+ * ["Since: 2.0"]
2234
+ * @usage add_filter( 'um_edit_field_{$mode}_{$type}', 'function_name', 10, 2 );
2235
+ * @example
2236
+ * <?php
2237
+ * add_filter( 'um_edit_field_{$mode}_{$type}', 'my_edit_field_html', 10, 2 );
2238
+ * function my_edit_field_html( $output, $data ) {
2239
+ * // your code here
2240
+ * return $output;
2241
+ * }
2242
+ * ?>
2243
+ */
2244
+
2245
+ $output .= apply_filters( "um_edit_field_{$mode}_{$type}", $output, $data );
2246
+ break;
2247
+
2248
+ /* Other fields */
2249
+ case 'googlemap':
2250
+ case 'youtube_video':
2251
+ case 'vimeo_video':
2252
+ case 'soundcloud_track':
2253
+
2254
+ $output .= '<div ' . $this->get_atts( $key, $classes, $conditional, $data ) . '>';
2255
+
2256
+ if ( isset( $data['label'] ) ) {
2257
+ $output .= $this->field_label( $label, $key, $data );
2258
+ }
2259
+
2260
+ $output .= '<div class="um-field-area">';
2261
+
2262
+ if ( ! empty( $icon ) && isset( $this->field_icons ) && $this->field_icons == 'field' ) {
2263
+
2264
+ $output .= '<div class="um-field-icon"><i class="' . $icon . '"></i></div>';
2265
+
2266
+ }
2267
+
2268
+ $field_name = $key . UM()->form()->form_suffix;
2269
+ $field_value = htmlspecialchars( $this->field_value( $key, $default, $data ) );
2270
+
2271
+ $output .= '<input ' . $disabled . ' class="' . $this->get_class( $key, $data ) . '" type="' . esc_attr( $input ) . '" name="' . esc_attr( $field_name ) . '" id="' . esc_attr( $field_name ) . '" value="' . esc_attr( $field_value ) . '" placeholder="' . esc_attr( $placeholder ) . '" data-validate="' . esc_attr( $validate ) . '" data-key="' . esc_attr( $key ) . '" />
2272
+
2273
+ </div>';
2274
+
2275
+ if ( ! empty( $disabled ) ) {
2276
+ $output .= $this->disabled_hidden_field( $field_name, $field_value );
2277
+ }
2278
+
2279
+ if ( $this->is_error( $key ) ) {
2280
+ $output .= $this->field_error( $this->show_error( $key ) );
2281
+ }else if ( $this->is_notice( $key ) ) {
2282
+ $output .= $this->field_notice( $this->show_notice( $key ) );
2283
+ }
2284
+
2285
+ $output .= '</div>';
2286
+ break;
2287
+
2288
+ /* Text */
2289
+ case 'text':
2290
+
2291
+ $output .= '<div ' . $this->get_atts( $key, $classes, $conditional, $data ) . '>';
2292
+
2293
+ if ( isset( $data['label'] ) ) {
2294
+ $output .= $this->field_label( $label, $key, $data );
2295
+ }
2296
+
2297
+ $output .= '<div class="um-field-area">';
2298
+
2299
+ if ( ! empty( $icon ) && isset( $this->field_icons ) && $this->field_icons == 'field' ) {
2300
+
2301
+ $output .= '<div class="um-field-icon"><i class="' . esc_attr( $icon ) . '"></i></div>';
2302
+
2303
+ }
2304
+
2305
+ $field_name = $key . UM()->form()->form_suffix;
2306
+ $field_value = htmlspecialchars( $this->field_value( $key, $default, $data ) );
2307
+
2308
+ $output .= '<input ' . $disabled . ' autocomplete="' . esc_attr( $autocomplete ) . '" class="' . $this->get_class( $key, $data ) . '" type="' . esc_attr( $input ) . '" name="' . esc_attr( $field_name ) . '" id="' . esc_attr( $field_name ) . '" value="' . esc_attr( $field_value ) . '" placeholder="' . esc_attr( $placeholder ) . '" data-validate="' . esc_attr( $validate ) . '" data-key="' . esc_attr( $key ) . '" />
2309
+
2310
+ </div>';
2311
+
2312
+ if ( ! empty( $disabled ) ) {
2313
+ $output .= $this->disabled_hidden_field( $field_name, $field_value );
2314
+ }
2315
+
2316
+ if ( $this->is_error( $key ) ) {
2317
+ $output .= $this->field_error( $this->show_error( $key ) );
2318
+ }else if ( $this->is_notice( $key ) ) {
2319
+ $output .= $this->field_notice( $this->show_notice( $key ) );
2320
+ }
2321
+
2322
+ $output .= '</div>';
2323
+ break;
2324
+
2325
+ /* Number */
2326
+ case 'number':
2327
+
2328
+ $output .= '<div ' . $this->get_atts( $key, $classes, $conditional, $data ) . '>';
2329
+
2330
+ if ( isset( $data['label'] ) ) {
2331
+ $output .= $this->field_label( $label, $key, $data );
2332
+ }
2333
+
2334
+ $output .= '<div class="um-field-area">';
2335
+
2336
+ if ( ! empty( $icon ) && isset( $this->field_icons ) && $this->field_icons == 'field' ) {
2337
+
2338
+ $output .= '<div class="um-field-icon"><i class="' . esc_attr( $icon ) . '"></i></div>';
2339
+
2340
+ }
2341
+
2342
+ $number_limit = '';
2343
+ if ( isset( $min ) ) {
2344
+ $number_limit .= ' min="' . esc_attr( $min ) . '" ';
2345
+ }
2346
+ if ( isset( $max ) ) {
2347
+ $number_limit .= ' max="' . esc_attr( $max ) . '" ';
2348
+ }
2349
+
2350
+ $output .= '<input ' . $disabled . ' class="' . $this->get_class( $key, $data ) . '" type="number" name="' . esc_attr( $key . UM()->form()->form_suffix ) . '" id="' . esc_attr( $key . UM()->form()->form_suffix ) . '" value="' . esc_attr( htmlspecialchars( $this->field_value( $key, $default, $data ) ) ) . '" placeholder="' . esc_attr( $placeholder ) . '" data-validate="' . esc_attr( $validate ) . '" data-key="' . esc_attr( $key ) . '" ' . $number_limit . ' />
2351
+
2352
+ </div>';
2353
+
2354
+ if ( $this->is_error( $key ) ) {
2355
+ $output .= $this->field_error( $this->show_error( $key ) );
2356
+ }else if ( $this->is_notice( $key ) ) {
2357
+ $output .= $this->field_notice( $this->show_notice( $key ) );
2358
+ }
2359
+
2360
+ $output .= '</div>';
2361
+ break;
2362
+
2363
+ /* Password */
2364
+ case 'password':
2365
+
2366
+ $original_key = $key;
2367
+
2368
+ if ( $key == 'single_user_password' ) {
2369
+
2370
+ $key = $original_key;
2371
+
2372
+ $output .= '<div ' . $this->get_atts( $key, $classes, $conditional, $data ) . '>';
2373
+
2374
+ if ( isset( $data['label'] ) ) {
2375
+ $output .= $this->field_label( $label, $key, $data );
2376
+ }
2377
+
2378
+ $output .= '<div class="um-field-area">';
2379
+
2380
+ if ( ! empty( $icon ) && isset( $this->field_icons ) && $this->field_icons == 'field' ) {
2381
+
2382
+ $output .= '<div class="um-field-icon"><i class="' . esc_attr( $icon ) . '"></i></div>';
2383
+
2384
+ }
2385
+
2386
+ $output .= '<input class="' . $this->get_class( $key, $data ) . '" type="' . esc_attr( $input ) . '" name="' . esc_attr( $key . UM()->form()->form_suffix ) . '" id="' . esc_attr( $key . UM()->form()->form_suffix ) . '" value="' . $this->field_value( $key, $default, $data ) . '" placeholder="' . esc_attr( $placeholder ) . '" data-validate="' . esc_attr( $validate ) . '" data-key="' . esc_attr( $key ) . '" />
2387
+
2388
+ </div>';
2389
+
2390
+ if ( $this->is_error( $key ) ) {
2391
+ $output .= $this->field_error( $this->show_error( $key ) );
2392
+ }else if ( $this->is_notice( $key ) ) {
2393
+ $output .= $this->field_notice( $this->show_notice( $key ) );
2394
+ }
2395
+
2396
+ $output .= '</div>';
2397
+
2398
+ } else {
2399
+
2400
+ if ( UM()->account()->current_password_is_required( 'password' ) &&
2401
+ ( $this->set_mode == 'account' || um_is_core_page( 'account' ) ) ) {
2402
+
2403
+ $key = 'current_' . $original_key;
2404
+ $output .= '<div ' . $this->get_atts( $key, $classes, $conditional, $data ) . '>';
2405
+
2406
+ if ( isset( $data['label'] ) ) {
2407
+ $output .= $this->field_label( __( 'Current Password', 'ultimate-member' ), $key, $data );
2408
+ }
2409
+
2410
+ $output .= '<div class="um-field-area">';
2411
+
2412
+ if ( ! empty( $icon ) && isset( $this->field_icons ) && $this->field_icons == 'field') {
2413
+
2414
+ $output .= '<div class="um-field-icon"><i class="' . esc_attr( $icon ) . '"></i></div>';
2415
+
2416
+ }
2417
+
2418
+ $output .= '<input class="' . $this->get_class( $key, $data ) . '" type="' . esc_attr( $input ) . '" name="' . esc_attr( $key . UM()->form()->form_suffix ) . '" id="' . esc_attr( $key . UM()->form()->form_suffix ) . '" value="' . $this->field_value( $key, $default, $data ) . '" placeholder="' . esc_attr( $placeholder ) . '" data-validate="' . esc_attr( $validate ) . '" data-key="' . esc_attr( $key ) . '" />
2419
+
2420
+ </div>';
2421
+
2422
+ if ( $this->is_error( $key ) ) {
2423
+ $output .= $this->field_error( $this->show_error( $key ) );
2424
+ } elseif ( $this->is_notice( $key ) ) {
2425
+ $output .= $this->field_notice( $this->show_notice( $key ) );
2426
+ }
2427
+
2428
+ $output .= '</div>';
2429
+
2430
+ }
2431
+
2432
+ $key = $original_key;
2433
+
2434
+ $output .= '<div ' . $this->get_atts( $key, $classes, $conditional, $data ) . '>';
2435
+
2436
+ if ( $this->set_mode == 'account' && um_is_core_page( 'account' ) || $this->set_mode == 'password' && um_is_core_page( 'password-reset' ) ) {
2437
+
2438
+ $output .= $this->field_label( __( 'New Password', 'ultimate-member' ), $key, $data );
2439
+
2440
+ } elseif ( isset( $data['label'] ) ) {
2441
+
2442
+ $output .= $this->field_label( $label, $key, $data );
2443
+
2444
+ }
2445
+
2446
+ $output .= '<div class="um-field-area">';
2447
+
2448
+ if ( ! empty( $icon ) && isset( $this->field_icons ) && $this->field_icons == 'field') {
2449
+
2450
+ $output .= '<div class="um-field-icon"><i class="' . esc_attr( $icon ) . '"></i></div>';
2451
+
2452
+ }
2453
+
2454
+ $name = $key . UM()->form()->form_suffix;
2455
+ if ( $this->set_mode == 'password' && um_is_core_page( 'password-reset' ) ) {
2456
+ $name = $key;
2457
+ }
2458
+
2459
+ $output .= '<input class="' . $this->get_class( $key, $data ) . '" type="' . esc_attr( $input ) . '" name="' . esc_attr( $name ) . '" id="' . esc_attr( $key . UM()->form()->form_suffix ) . '" value="' . $this->field_value( $key, $default, $data ) . '" placeholder="' . esc_attr( $placeholder ) . '" data-validate="' . esc_attr( $validate ) . '" data-key="' . esc_attr( $key ) . '" />
2460
+
2461
+ </div>';
2462
+
2463
+ if ( $this->is_error( $key ) ) {
2464
+ $output .= $this->field_error( $this->show_error( $key ) );
2465
+ } elseif ( $this->is_notice( $key ) ) {
2466
+ $output .= $this->field_notice( $this->show_notice( $key ) );
2467
+ }
2468
+
2469
+ $output .= '</div>';
2470
+
2471
+ if ( $this->set_mode != 'login' && isset( $data['force_confirm_pass'] ) && $data['force_confirm_pass'] == 1 ) {
2472
+
2473
+ $key = 'confirm_' . $original_key;
2474
+ $output .= '<div ' . $this->get_atts( $key, $classes, $conditional, $data ) . '>';
2475
+
2476
+ if ( ! empty( $data['label_confirm_pass'] ) ) {
2477
+ $label_confirm_pass = __( $data['label_confirm_pass'], 'ultimate-member' );
2478
+ $output .= $this->field_label( $label_confirm_pass, $key, $data );
2479
+ } elseif ( isset( $data['label'] ) ) {
2480
+ $data['label'] = __( $data['label'], 'ultimate-member' );
2481
+ $output .= $this->field_label( sprintf( __( 'Confirm %s', 'ultimate-member' ), $data['label'] ), $key, $data );
2482
+ }
2483
+
2484
+ $output .= '<div class="um-field-area">';
2485
+
2486
+ if ( ! empty( $icon ) && isset( $this->field_icons ) && $this->field_icons == 'field' ) {
2487
+
2488
+ $output .= '<div class="um-field-icon"><i class="' . esc_attr( $icon ) . '"></i></div>';
2489
+
2490
+ }
2491
+
2492
+ $name = $key . UM()->form()->form_suffix;
2493
+ if ( $this->set_mode == 'password' && um_is_core_page( 'password-reset' ) ) {
2494
+ $name = $key;
2495
+ }
2496
+
2497
+ if ( ! empty( $label_confirm_pass ) ) {
2498
+ $placeholder = $label_confirm_pass;
2499
+ } elseif( ! empty( $placeholder ) && ! isset( $data['label'] ) ) {
2500
+ $placeholder = sprintf( __( 'Confirm %s', 'ultimate-member' ), $placeholder );
2501
+ } elseif( isset( $data['label'] ) ) {
2502
+ $placeholder = sprintf( __( 'Confirm %s', 'ultimate-member' ), $data['label'] );
2503
+ }
2504
+
2505
+
2506
+ $output .= '<input class="' . $this->get_class( $key, $data ) . '" type="' . esc_attr( $input ) . '" name="' . esc_attr( $name ) . '" id="' . esc_attr( $key . UM()->form()->form_suffix ) . '" value="' . $this->field_value( $key, $default, $data ) . '" placeholder="' . esc_attr( $placeholder ) . '" data-validate="' . esc_attr( $validate ) . '" data-key="' . esc_attr( $key ) . '" />';
2507
+
2508
+
2509
+ $output .= '</div>';
2510
+
2511
+ if ( $this->is_error( $key ) ) {
2512
+ $output .= $this->field_error( $this->show_error( $key ) );
2513
+ }else if ( $this->is_notice( $key ) ) {
2514
+ $output .= $this->field_notice( $this->show_notice( $key ) );
2515
+ }
2516
+
2517
+ $output .= '</div>';
2518
+
2519
+ }
2520
+
2521
+ }
2522
+
2523
+ break;
2524
+
2525
+ /* URL */
2526
+ case 'url':
2527
+
2528
+ $output .= '<div ' . $this->get_atts( $key, $classes, $conditional, $data ) . '>';
2529
+
2530
+ if ( isset( $data['label'] ) ) {
2531
+ $output .= $this->field_label( $label, $key, $data );
2532
+ }
2533
+
2534
+ $output .= '<div class="um-field-area">';
2535
+
2536
+ if ( ! empty( $icon ) && isset( $this->field_icons ) && $this->field_icons == 'field' ) {
2537
+
2538
+ $output .= '<div class="um-field-icon"><i class="' . esc_attr( $icon ) . '"></i></div>';
2539
+
2540
+ }
2541
+
2542
+ $output .= '<input ' . $disabled . ' class="' . $this->get_class( $key, $data ) . '" type="' . esc_attr( $input ) . '" name="' . esc_attr( $key . UM()->form()->form_suffix ) . '" id="' . esc_attr( $key . UM()->form()->form_suffix ) . '" value="' . esc_attr( $this->field_value( $key, $default, $data ) ) . '" placeholder="' . esc_attr( $placeholder ) . '" data-validate="' . esc_attr( $validate ) . '" data-key="' . esc_attr( $key ) . '" />
2543
+
2544
+ </div>';
2545
+
2546
+ if ( $this->is_error( $key ) ) {
2547
+ $output .= $this->field_error( $this->show_error( $key ) );
2548
+ }else if ( $this->is_notice( $key ) ) {
2549
+ $output .= $this->field_notice( $this->show_notice( $key ) );
2550
+ }
2551
+
2552
+ $output .= '</div>';
2553
+ break;
2554
+
2555
+ /* Date */
2556
+ case 'date':
2557
+
2558
+ $output .= '<div ' . $this->get_atts( $key, $classes, $conditional, $data ) . '>';
2559
+
2560
+ if (isset( $data['label'] )) {
2561
+ $output .= $this->field_label( $label, $key, $data );
2562
+ }
2563
+
2564
+ $output .= '<div class="um-field-area">';
2565
+
2566
+ if ( ! empty( $icon ) && isset( $this->field_icons ) && $this->field_icons == 'field' ) {
2567
+
2568
+ $output .= '<div class="um-field-icon"><i class="' . esc_attr( $icon ) . '"></i></div>';
2569
+
2570
+ }
2571
+
2572
+ $output .= '<input ' . $disabled . ' class="' . $this->get_class( $key, $data ) . '" type="' . esc_attr( $input ) . '" name="' . esc_attr( $key . UM()->form()->form_suffix ) . '" id="' . esc_attr( $key . UM()->form()->form_suffix ) . '" value="' . $this->field_value( $key, $default, $data ) . '" placeholder="' . esc_attr( $placeholder ) . '" data-validate="' . esc_attr( $validate ) . '" data-key="' . esc_attr( $key ) . '" data-range="' . esc_attr( $range ) . '" data-years="' . esc_attr( $years ) . '" data-years_x="' . esc_attr( $years_x ) . '" data-disabled_weekdays="' . esc_attr( $disabled_weekdays ) . '" data-date_min="' . esc_attr( $date_min ) . '" data-date_max="' . esc_attr( $date_max ) . '" data-format="' . esc_attr( $js_format ) . '" data-value="' . $this->field_value( $key, $default, $data ) . '" />
2573
+
2574
+ </div>';
2575
+
2576
+ if ( $this->is_error( $key ) ) {
2577
+ $output .= $this->field_error( $this->show_error( $key ) );
2578
+ }else if ( $this->is_notice( $key ) ) {
2579
+ $output .= $this->field_notice( $this->show_notice( $key ) );
2580
+ }
2581
+
2582
+ $output .= '</div>';
2583
+ break;
2584
+
2585
+ /* Time */
2586
+ case 'time':
2587
+
2588
+ $output .= '<div ' . $this->get_atts( $key, $classes, $conditional, $data ) . '>';
2589
+
2590
+ if (isset( $data['label'] )) {
2591
+ $output .= $this->field_label( $label, $key, $data );
2592
+ }
2593
+
2594
+ $output .= '<div class="um-field-area">';
2595
+
2596
+ if ( ! empty( $icon ) && isset( $this->field_icons ) && $this->field_icons == 'field' ) {
2597
+
2598
+ $output .= '<div class="um-field-icon"><i class="' . esc_attr( $icon ) . '"></i></div>';
2599
+
2600
+ }
2601
+
2602
+ $output .= '<input ' . $disabled . ' class="' . $this->get_class( $key, $data ) . '" type="' . esc_attr( $input ) . '" name="' . esc_attr( $key . UM()->form()->form_suffix ) . '" id="' . esc_attr( $key . UM()->form()->form_suffix ) . '" value="' . $this->field_value( $key, $default, $data ) . '" placeholder="' . esc_attr( $placeholder ) . '" data-validate="' . esc_attr( $validate ) . '" data-key="' . esc_attr( $key ) . '" data-format="' . esc_attr( $js_format ) . '" data-intervals="' . esc_attr( $intervals ) . '" data-value="' . $this->field_value( $key, $default, $data ) . '" />
2603
+
2604
+ </div>';
2605
+
2606
+ if ( $this->is_error( $key ) ) {
2607
+ $output .= $this->field_error( $this->show_error( $key ) );
2608
+ }else if ( $this->is_notice( $key ) ) {
2609
+ $output .= $this->field_notice( $this->show_notice( $key ) );
2610
+ }
2611
+
2612
+ $output .= '</div>';
2613
+ break;
2614
+
2615
+ /* Row */
2616
+ case 'row':
2617
+ $output .= '';
2618
+ break;
2619
+
2620
+ /* Textarea */
2621
+ case 'textarea':
2622
+ $output .= '<div ' . $this->get_atts( $key, $classes, $conditional, $data ) . '>';
2623
+
2624
+ if ( isset( $data['label'] ) ) {
2625
+ $output .= $this->field_label( $label, $key, $data );
2626
+ }
2627
+
2628
+ $output .= '<div class="um-field-area">';
2629
+
2630
+ if ( isset( $data['html'] ) && $data['html'] != 0 && $key != "description" ) {
2631
+
2632
+ $textarea_settings = array(
2633
+ 'media_buttons' => false,
2634
+ 'wpautop' => false,
2635
+ 'editor_class' => $this->get_class( $key, $data ),
2636
+ 'editor_height' => $height,
2637
+ 'tinymce' => array(
2638
+ 'toolbar1' => 'formatselect,bullist,numlist,bold,italic,underline,forecolor,blockquote,hr,removeformat,link,unlink,undo,redo',
2639
+ 'toolbar2' => '',
2640
+ )
2641
+ );
2642
+
2643
+ if ( ! empty( $disabled ) ) {
2644
+ $textarea_settings['tinymce']['readonly'] = true;
2645
+ }
2646
+
2647
+ /**
2648
+ * UM hook
2649
+ *
2650
+ * @type filter
2651
+ * @title um_form_fields_textarea_settings
2652
+ * @description Change WP Editor options for textarea init
2653
+ * @input_vars
2654
+ * [{"var":"$textarea_settings","type":"array","desc":"WP Editor settings"}]
2655
+ * @change_log
2656
+ * ["Since: 2.0"]
2657
+ * @usage add_filter( 'um_form_fields_textarea_settings', 'function_name', 10, 1 );
2658
+ * @example
2659
+ * <?php
2660
+ * add_filter( 'um_form_fields_textarea_settings', 'my_textarea_settings', 10, 1 );
2661
+ * function my_edit_field_html( $textarea_settings ) {
2662
+ * // your code here
2663
+ * return $textarea_settings;
2664
+ * }
2665
+ * ?>
2666
+ */
2667
+ $textarea_settings = apply_filters( 'um_form_fields_textarea_settings', $textarea_settings );
2668
+
2669
+ // turn on the output buffer
2670
+ ob_start();
2671
+
2672
+ // echo the editor to the buffer
2673
+ wp_editor( $field_value, $key, $textarea_settings );
2674
+
2675
+ // add the contents of the buffer to the output variable
2676
+ $output .= ob_get_clean();
2677
+ $output .= '<br /><span class="description">' . $placeholder . '</span>';
2678
+ } else {
2679
+ $textarea_field_value = ! empty( $data['html'] ) ? $field_value : strip_tags( $field_value );
2680
+ $output .= '<textarea ' . $disabled . ' style="height: ' . esc_attr( $height ) . ';" class="' . $this->get_class( $key, $data ) . '" name="' . esc_attr( $field_name ) . '" id="' . esc_attr( $field_id ) . '" placeholder="' . esc_attr( $placeholder ) . '">' . esc_textarea( $textarea_field_value ) . '</textarea>';
2681
+ }
2682
+
2683
+ $output .= '</div>';
2684
+
2685
+ if ( ! empty( $disabled ) ) {
2686
+ $output .= $this->disabled_hidden_field( $field_name, $field_value );
2687
+ }
2688
+
2689
+ if ( $this->is_error( $key ) ) {
2690
+ $output .= $this->field_error( $this->show_error( $key ) );
2691
+ }else if ( $this->is_notice( $key ) ) {
2692
+ $output .= $this->field_notice( $this->show_notice( $key ) );
2693
+ }
2694
+
2695
+ $output .= '</div>';
2696
+ break;
2697
+
2698
+ /* Rating */
2699
+ case 'rating':
2700
+ $output .= '<div ' . $this->get_atts( $key, $classes, $conditional, $data ) . '>';
2701
+
2702
+ if ( isset( $data['label'] ) ) {
2703
+ $output .= $this->field_label( $label, $key, $data );
2704
+ }
2705
+
2706
+ $output .= '<div class="um-field-area">';
2707
+
2708
+ $output .= '<div class="um-rating um-raty" id="' . esc_attr( $key ) . '" data-key="' . esc_attr( $key ) . '" data-number="' . esc_attr( $data['number'] ) . '" data-score="' . $this->field_value( $key, $default, $data ) . '"></div>';
2709
+ $output .= '</div>';
2710
+
2711
+ if ( $this->is_error( $key ) ) {
2712
+ $output .= $this->field_error( $this->show_error( $key ) );
2713
+ } elseif ( $this->is_notice( $key ) ) {
2714
+ $output .= $this->field_notice( $this->show_notice( $key ) );
2715
+ }
2716
+
2717
+ $output .= '</div>';
2718
+
2719
+ break;
2720
+
2721
+ /* Gap/Space */
2722
+ case 'spacing':
2723
+ $output .= '<div ' . $this->get_atts( $key, $classes, $conditional, $data, array( 'height' => $spacing ) ) . '></div>';
2724
+ break;
2725
+
2726
+ /* A line divider */
2727
+ case 'divider':
2728
+ $output .= '<div ' . $this->get_atts( $key, $classes, $conditional, $data, array( 'border-bottom' => $borderwidth . 'px ' . $borderstyle . ' ' . $bordercolor ) ) . '>';
2729
+ if ( $divider_text ) {
2730
+ $output .= '<div class="um-field-divider-text"><span>' . esc_html( $divider_text ) . '</span></div>';
2731
+ }
2732
+ $output .= '</div>';
2733
+ break;
2734
+
2735
+ /* Single Image Upload */
2736
+ case 'image':
2737
+ $output .= '<div ' . $this->get_atts( $key, $classes, $conditional, $data ) . ' data-mode="' . esc_attr( $this->set_mode ) . '" data-upload-label="' . ( ! empty( $data['button_text'] ) ? esc_attr( $data['button_text'] ) : esc_attr__( 'Upload', 'ultimate-member' ) ) . '">';
2738
+ if ( in_array( $key, array( 'profile_photo', 'cover_photo' ) ) ) {
2739
+ $field_value = '';
2740
+ } else {
2741
+ $field_value = $this->field_value( $key, $default, $data );
2742
+ }
2743
+ $output .= '<input type="hidden" name="' . esc_attr( $key . UM()->form()->form_suffix ) . '" id="' . esc_attr( $key . UM()->form()->form_suffix ) . '" value="' . $field_value . '" />';
2744
+ if ( isset( $data['label'] ) ) {
2745
+ $output .= $this->field_label( $label, $key, $data );
2746
+ }
2747
+ $modal_label = ( isset( $data['label'] ) ) ? $data['label'] : __( 'Upload Photo', 'ultimate-member' );
2748
+ $output .= '<div class="um-field-area" style="text-align: center;">';
2749
+
2750
+ if ( ! empty( $field_value ) && $field_value != 'empty_file' ) {
2751
+ if ( ! in_array( $key, array( 'profile_photo', 'cover_photo' ) ) ) {
2752
+ if ( isset( $this->set_mode ) && 'register' == $this->set_mode ) {
2753
+ $image_info = get_transient("um_{$field_value}");
2754
+ } else {
2755
+ $image_info = um_user( $data['metakey']."_metadata" );
2756
+ }
2757
+
2758
+ if ( ( isset( $this->set_mode ) && $this->set_mode == 'register' ) || file_exists( UM()->uploader()->get_core_temp_dir() . DIRECTORY_SEPARATOR . $field_value ) ) {
2759
+ $imgValue = UM()->uploader()->get_core_temp_url() . "/" . $this->field_value( $key, $default, $data );
2760
+ } else {
2761
+ $imgValue = UM()->files()->get_download_link( $this->set_id, $key, um_user( 'ID' ) );
2762
+ }
2763
+ $img = '<img src="' . $imgValue . '" alt="" />';
2764
+ } else {
2765
+ $img = '';
2766
+ }
2767
+ $output .= '<div class="um-single-image-preview show ' . $crop_class . '" data-crop="' . $crop_data . '" data-key="' . $key . '">';
2768
+ if ( empty( $disabled ) ) {
2769
+ $output .= '<a href="javascript:void(0);" class="cancel"><i class="um-icon-close"></i></a>';
2770
+ }
2771
+ $output .= $img;
2772
+ $output .= '</div>';
2773
+ if ( empty( $disabled ) ) {
2774
+ $output .= '<a href="javascript:void(0);" data-modal="um_upload_single" data-modal-size="' . $modal_size . '" data-modal-copy="1" class="um-button um-btn-auto-width">' . __( 'Change photo', 'ultimate-member' ) . '</a>';
2775
+ }
2776
+
2777
+
2778
+ } else {
2779
+ $output .= '<div class="um-single-image-preview ' . $crop_class . '" data-crop="' . $crop_data . '" data-key="' . $key . '">';
2780
+ if ( empty( $disabled ) ) {
2781
+ $output .= '<a href="javascript:void(0);" class="cancel"><i class="um-icon-close"></i></a>';
2782
+ }
2783
+ $output .= '<img src="" alt="" /><div class="um-clear"></div></div>';
2784
+ if ( empty( $disabled ) ) {
2785
+ $output .= '<a href="javascript:void(0);" data-modal="um_upload_single" data-modal-size="' . $modal_size . '" data-modal-copy="1" class="um-button um-btn-auto-width">' . $button_text . '</a>';
2786
+ }
2787
+
2788
+ }
2789
+ $output .= '</div>';
2790
+ /* modal hidden */
2791
+ if ( empty( $disabled ) ) {
2792
+ $output .= '<div class="um-modal-hidden-content">';
2793
+ $output .= '<div class="um-modal-header"> ' . $modal_label . '</div>';
2794
+ $output .= '<div class="um-modal-body">';
2795
+ if ( isset( $this->set_id ) ) {
2796
+ $set_id = $this->set_id;
2797
+ $set_mode = $this->set_mode;
2798
+ } else {
2799
+ $set_id = 0;
2800
+ $set_mode = '';
2801
+ }
2802
+ $nonce = wp_create_nonce( 'um_upload_nonce-' . $this->timestamp );
2803
+ $output .= '<div class="um-single-image-preview ' . $crop_class . '" data-crop="' . $crop_data . '" data-ratio="' . $ratio . '" data-min_width="' . $min_width . '" data-min_height="' . $min_height . '" data-coord=""><a href="javascript:void(0);" class="cancel"><i class="um-icon-close"></i></a><img src="" alt="" /><div class="um-clear"></div></div><div class="um-clear"></div>';
2804
+ $output .= '<div class="um-single-image-upload" data-user_id="' . esc_attr( $_um_profile_id ) . '" data-nonce="' . $nonce . '" data-timestamp="' . esc_attr( $this->timestamp ) . '" data-icon="' . esc_attr( $icon ) . '" data-set_id="' . esc_attr( $set_id ) . '" data-set_mode="' . esc_attr( $set_mode ) . '" data-type="' . esc_attr( $type ) . '" data-key="' . esc_attr( $key ) . '" data-max_size="' . esc_attr( $max_size ) . '" data-max_size_error="' . esc_attr( $max_size_error ) . '" data-min_size_error="' . esc_attr( $min_size_error ) . '" data-extension_error="' . esc_attr( $extension_error ) . '" data-allowed_types="' . esc_attr( $allowed_types ) . '" data-upload_text="' . esc_attr( $upload_text ) . '" data-max_files_error="' . esc_attr( $max_files_error ) . '" data-upload_help_text="' . esc_attr( $upload_help_text ) . '">' . $button_text . '</div>';
2805
+ $output .= '<div class="um-modal-footer">
2806
+ <div class="um-modal-right">
2807
+ <a href="javascript:void(0);" class="um-modal-btn um-finish-upload image disabled" data-key="' . $key . '" data-change="' . __( 'Change photo', 'ultimate-member' ) . '" data-processing="' . __( 'Processing...', 'ultimate-member' ) . '"> ' . __( 'Apply', 'ultimate-member' ) . '</a>
2808
+ <a href="javascript:void(0);" class="um-modal-btn alt" data-action="um_remove_modal"> ' . __( 'Cancel', 'ultimate-member' ) . '</a>
2809
+ </div>
2810
+ <div class="um-clear"></div>
2811
+ </div>';
2812
+ $output .= '</div>';
2813
+ $output .= '</div>';
2814
+ }
2815
+ /* end */
2816
+ if ( $this->is_error( $key ) ) {
2817
+ $output .= $this->field_error( $this->show_error( $key ) );
2818
+ }else if ( $this->is_notice( $key ) ) {
2819
+ $output .= $this->field_notice( $this->show_notice( $key ) );
2820
+ }
2821
+ $output .= '</div>';
2822
+
2823
+ break;
2824
+
2825
+ /* Single File Upload */
2826
+ case 'file':
2827
+ $output .= '<div ' . $this->get_atts( $key, $classes, $conditional, $data ) . ' data-mode="' . esc_attr( $this->set_mode ) . '" data-upload-label="' . ( ! empty( $data['button_text'] ) ? esc_attr( $data['button_text'] ) : esc_attr__( 'Upload', 'ultimate-member' ) ) . '">';
2828
+ $output .= '<input type="hidden" name="' . esc_attr( $key . UM()->form()->form_suffix ) . '" id="' . esc_attr( $key . UM()->form()->form_suffix ) . '" value="' . $this->field_value( $key, $default, $data ) . '" />';
2829
+ if ( isset( $data['label'] ) ) {
2830
+ $output .= $this->field_label( $label, $key, $data );
2831
+ }
2832
+ $modal_label = ( isset( $data['label'] ) ) ? $data['label'] : __( 'Upload File', 'ultimate-member' );
2833
+ $output .= '<div class="um-field-area" style="text-align: center;">';
2834
+
2835
+ $file_field_value = $this->field_value( $key, $default, $data );
2836
+
2837
+ if ( ! empty( $file_field_value ) && 'empty_file' !== $file_field_value ) {
2838
+ $file_type = wp_check_filetype( $file_field_value );
2839
+
2840
+ if ( um_is_temp_file( $file_field_value ) ) {
2841
+ $file_info = get_transient( "um_{$file_field_value}" );
2842
+ } else {
2843
+ $file_info = um_user( $data['metakey'] . "_metadata" );
2844
+ }
2845
+
2846
+ $file_field_name = $file_field_value;
2847
+ if ( ! empty( $file_info['original_name'] ) ) {
2848
+ $file_field_name = $file_info['original_name'];
2849
+ }
2850
+
2851
+ if ( ( isset( $this->set_mode ) && 'register' == $this->set_mode ) || file_exists( UM()->uploader()->get_core_temp_dir() . DIRECTORY_SEPARATOR . $file_field_value ) ) {
2852
+ $file_url = UM()->uploader()->get_core_temp_url() . DIRECTORY_SEPARATOR . $file_field_value;
2853
+ $file_dir = UM()->uploader()->get_core_temp_dir() . DIRECTORY_SEPARATOR . $file_field_value;
2854
+ } else {
2855
+ $file_url = UM()->files()->get_download_link( $this->set_id, $key, um_user( 'ID' ) );
2856
+ $file_dir = UM()->uploader()->get_upload_base_dir() . um_user( 'ID' ) . DIRECTORY_SEPARATOR . $this->field_value( $key, $default, $data );
2857
+ }
2858
+
2859
+ //multisite fix for old customers
2860
+ if ( ! file_exists( $file_dir ) && is_multisite() ) {
2861
+ $file_dir = str_replace( DIRECTORY_SEPARATOR . 'sites' . DIRECTORY_SEPARATOR . get_current_blog_id() . DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, $file_dir );
2862
+ }
2863
+
2864
+ if ( file_exists( $file_dir ) ) {
2865
+ $output .= "<div class=\"um-single-file-preview show\" data-key=\"{$key}\">";
2866
+ if ( empty( $disabled ) ) {
2867
+ $output .= "<a href=\"#\" class=\"cancel\"><i class=\"um-icon-close\"></i></a>";
2868
+ }
2869
+ $output .= "<div class=\"um-single-fileinfo\">
2870
+ <a href=\"{$file_url}\" target=\"_blank\">
2871
+ <span class=\"icon\" style=\"background:" . UM()->files()->get_fonticon_bg_by_ext( $file_type['ext'] ) . "\"><i class=\"" . UM()->files()->get_fonticon_by_ext( $file_type['ext'] ) . "\"></i></span>
2872
+ <span class=\"filename\">{$file_field_name}</span>
2873
+ </a>
2874
+ </div></div>";
2875
+ } else {
2876
+ $output .= "<div class=\"um-single-file-preview show\" data-key=\"{$key}\">" . __('This file has been removed.','ultimate-member') . "</div>";
2877
+ }
2878
+
2879
+ if ( empty( $disabled ) ) {
2880
+ $output .= "<a href=\"#\" data-modal=\"um_upload_single\" data-modal-size=\"{$modal_size}\" data-modal-copy=\"1\" class=\"um-button um-btn-auto-width\">" . __( 'Change file', 'ultimate-member' ) . "</a>";
2881
+ }
2882
+ } else {
2883
+ $output .= "<div class=\"um-single-file-preview\" data-key=\"{$key}\"></div>";
2884
+ if ( empty( $disabled ) ) {
2885
+ $output .= "<a href=\"#\" data-modal=\"um_upload_single\" data-modal-size=\"{$modal_size}\" data-modal-copy=\"1\" class=\"um-button um-btn-auto-width\">{$button_text}</a>";
2886
+ }
2887
+ }
2888
+ $output .= '</div>';
2889
+ /* modal hidden */
2890
+ if ( empty( $disabled ) ) {
2891
+ $output .= '<div class="um-modal-hidden-content">';
2892
+ $output .= '<div class="um-modal-header"> ' . $modal_label . '</div>';
2893
+ $output .= '<div class="um-modal-body">';
2894
+ if ( isset( $this->set_id ) ) {
2895
+ $set_id = $this->set_id;
2896
+ $set_mode = $this->set_mode;
2897
+ } else {
2898
+ $set_id = 0;
2899
+ $set_mode = '';
2900
+ }
2901
+ $output .= '<div class="um-single-file-preview">
2902
+ <a href="javascript:void(0);" class="cancel"><i class="um-icon-close"></i></a>
2903
+ <div class="um-single-fileinfo">
2904
+ <a href="" target="_blank">
2905
+ <span class="icon"><i></i></span>
2906
+ <span class="filename"></span>
2907
+ </a>
2908
+ </div>
2909
+ </div>';
2910
+ $nonce = wp_create_nonce( 'um_upload_nonce-' . $this->timestamp );
2911
+ $output .= '<div class="um-single-file-upload" data-user_id="' . esc_attr( $_um_profile_id ) . '" data-timestamp="' . esc_attr( $this->timestamp ) . '" data-nonce="' . $nonce . '" data-icon="' . esc_attr( $icon ) . '" data-set_id="' . esc_attr( $set_id ) . '" data-set_mode="' . esc_attr( $set_mode ) . '" data-type="' . esc_attr( $type ) . '" data-key="' . esc_attr( $key ) . '" data-max_size="' . esc_attr( $max_size ) . '" data-max_size_error="' . esc_attr( $max_size_error ) . '" data-min_size_error="' . esc_attr( $min_size_error ) . '" data-extension_error="' . esc_attr( $extension_error ) . '" data-allowed_types="' . esc_attr( $allowed_types ) . '" data-upload_text="' . esc_attr( $upload_text ) . '" data-max_files_error="' . esc_attr( $max_files_error ) . '" data-upload_help_text="' . esc_attr( $upload_help_text ) . '">' . $button_text . '</div>';
2912
+ $output .= '<div class="um-modal-footer">
2913
+ <div class="um-modal-right">
2914
+ <a href="javascript:void(0);" class="um-modal-btn um-finish-upload file disabled" data-key="' . esc_attr( $key ) . '" data-change="' . esc_attr__( 'Change file' ) . '" data-processing="' . esc_attr__( 'Processing...', 'ultimate-member' ) . '"> ' . __( 'Save', 'ultimate-member' ) . '</a>
2915
+ <a href="javascript:void(0);" class="um-modal-btn alt" data-action="um_remove_modal"> ' . __( 'Cancel', 'ultimate-member' ) . '</a>
2916
+ </div>
2917
+ <div class="um-clear"></div>
2918
+ </div>';
2919
+ $output .= '</div>';
2920
+ $output .= '</div>';
2921
+ }
2922
+ /* end */
2923
+ if ( $this->is_error( $key ) ) {
2924
+ $output .= $this->field_error( $this->show_error( $key ) );
2925
+ }else if ( $this->is_notice( $key ) ) {
2926
+ $output .= $this->field_notice( $this->show_notice( $key ) );
2927
+ }
2928
+ $output .= '</div>';
2929
+
2930
+ break;
2931
+
2932
+ /* Select dropdown */
2933
+ case 'select':
2934
+
2935
+ $output .= '<div ' . $this->get_atts( $key, $classes, $conditional, $data ) . '>';
2936
+
2937
+ if ( isset( $data['allowclear'] ) && $data['allowclear'] == 0 ) {
2938
+ $class = 'um-s2';
2939
+ } else {
2940
+ $class = 'um-s1';
2941
+ }
2942
+
2943
+ if ( isset( $data['label'] ) ) {
2944
+ $output .= $this->field_label( $label, $key, $data );
2945
+ }
2946
+
2947
+ $output .= '<div class="um-field-area ' . ( ! empty( $icon ) && isset( $this->field_icons ) && $this->field_icons == 'field' ? 'um-field-area-has-icon' : '' ) . ' ">';
2948
+ if ( ! empty( $icon ) && isset( $this->field_icons ) && $this->field_icons == 'field' ) {
2949
+ $output .= '<div class="um-field-icon"><i class="' . esc_attr( $icon ) . '"></i></div>';
2950
+ }
2951
+
2952
+ $options = array();
2953
+ $has_parent_option = false;
2954
+ $disabled_by_parent_option = '';
2955
+ $atts_ajax = '';
2956
+ $select_original_option_value = '';
2957
+
2958
+ if ( isset( $data[ 'options' ] ) && is_array( $data[ 'options' ] ) ) {
2959
+ $options = $data[ 'options' ];
2960
+ }
2961
+
2962
+ if ( ! empty( $data['parent_dropdown_relationship'] ) && ! UM()->user()->preview ) {
2963
+
2964
+ $disabled_by_parent_option = 'disabled = disabled';
2965
+
2966
+ $has_parent_option = true;
2967
+
2968
+ /**
2969
+ * UM hook
2970
+ *
2971
+ * @type filter
2972
+ * @title um_custom_dropdown_options_parent__{$form_key}
2973
+ * @description Change parent dropdown relationship by $form_key
2974
+ * @input_vars
2975
+ * [{"var":"$parent","type":"string","desc":"Parent dropdown relationship"},
2976
+ * {"var":"$data","type":"array","desc":"Field Data"}]
2977
+ * @change_log
2978
+ * ["Since: 2.0"]
2979
+ * @usage add_filter( 'um_custom_dropdown_options_parent__{$form_key}', 'function_name', 10, 2 );
2980
+ * @example
2981
+ * <?php
2982
+ * add_filter( 'um_custom_dropdown_options_parent__{$form_key}', 'my_custom_dropdown_options_parent', 10, 2 );
2983
+ * function my_custom_dropdown_options_parent( $parent, $data ) {
2984
+ * // your code here
2985
+ * return $parent;
2986
+ * }
2987
+ * ?>
2988
+ */
2989
+ $parent_dropdown_relationship = apply_filters( "um_custom_dropdown_options_parent__{$form_key}", $data['parent_dropdown_relationship'], $data );
2990
+ $atts_ajax .= " data-um-parent='{$parent_dropdown_relationship}' ";
2991
+
2992
+ if ( ! empty( $data['custom_dropdown_options_source'] ) && $has_parent_option && function_exists( $data['custom_dropdown_options_source'] ) &&
2993
+ um_user( $data['parent_dropdown_relationship'] )
2994
+ ) {
2995
+ $options = call_user_func( $data['custom_dropdown_options_source'], $data['parent_dropdown_relationship'] );
2996
+
2997
+ $disabled_by_parent_option = '';
2998
+ if ( um_user( $form_key ) ) {
2999
+ $select_original_option_value = " data-um-original-value='" . um_user( $form_key ) . "' ";
3000
+ }
3001
+ }
3002
+ }
3003
+
3004
+ // Child dropdown option selected
3005
+ if ( isset( UM()->form()->post_form[ $form_key ] ) ) {
3006
+ $select_original_option_value = " data-um-original-value='" . esc_attr( UM()->form()->post_form[ $form_key ] ) . "' ";
3007
+ }
3008
+
3009
+ // Child dropdown
3010
+ if ( $has_parent_option ) {
3011
+
3012
+ if ( ! empty( $data['custom_dropdown_options_source'] ) && $has_parent_option &&
3013
+ function_exists( $data['custom_dropdown_options_source'] ) && isset( UM()->form()->post_form[ $form_key ] ) ) {
3014
+ $options = call_user_func( $data['custom_dropdown_options_source'], $data['parent_dropdown_relationship'] );
3015
+ }
3016
+ }
3017
+
3018
+ if ( ! empty( $data['custom_dropdown_options_source'] ) ) {
3019
+
3020
+ /**
3021
+ * UM hook
3022
+ *
3023
+ * @type filter
3024
+ * @title um_custom_dropdown_options_source__{$form_key}
3025
+ * @description Change custom dropdown options source by $form_key
3026
+ * @input_vars
3027
+ * [{"var":"$source","type":"string","desc":"Dropdown options source"},
3028
+ * {"var":"$data","type":"array","desc":"Field Data"}]
3029
+ * @change_log
3030
+ * ["Since: 2.0"]
3031
+ * @usage add_filter( 'um_custom_dropdown_options_source__{$form_key}', 'function_name', 10, 2 );
3032
+ * @example
3033
+ * <?php
3034
+ * add_filter( 'um_custom_dropdown_options_source__{$form_key}', 'my_custom_dropdown_options_source', 10, 2 );
3035
+ * function my_custom_dropdown_options_source( $source, $data ) {
3036
+ * // your code here
3037
+ * return $source;
3038
+ * }
3039
+ * ?>
3040
+ */
3041
+ $ajax_source = apply_filters( "um_custom_dropdown_options_source__{$form_key}", $data['custom_dropdown_options_source'], $data );
3042
+ $atts_ajax .= ' data-um-ajax-source="' . esc_attr( $ajax_source ) . '" ';
3043
+
3044
+ /**
3045
+ * UM hook
3046
+ *
3047
+ * @type filter
3048
+ * @title um_custom_dropdown_options_source_url__{$form_key}
3049
+ * @description Change custom dropdown options source URL by $form_key
3050
+ * @input_vars
3051
+ * [{"var":"$url","type":"string","desc":"Dropdown options source URL"},
3052
+ * {"var":"$data","type":"array","desc":"Field Data"}]
3053
+ * @change_log
3054
+ * ["Since: 2.0"]
3055
+ * @usage add_filter( 'um_custom_dropdown_options_source_url__{$form_key}', 'function_name', 10, 2 );
3056
+ * @example
3057
+ * <?php
3058
+ * add_filter( 'um_custom_dropdown_options_source_url__{$form_key}', 'my_custom_dropdown_options_source_url', 10, 2 );
3059
+ * function my_custom_dropdown_options_source( $url, $data ) {
3060
+ * // your code here
3061
+ * return $url;
3062
+ * }
3063
+ * ?>
3064
+ */
3065
+ // todo maybe deprecate
3066
+ // $ajax_source_url = apply_filters( "um_custom_dropdown_options_source_url__{$form_key}", admin_url( 'admin-ajax.php' ), $data );
3067
+ // $atts_ajax .= ' data-um-ajax-url="' . esc_url( $ajax_source_url ) . '" ';
3068
+
3069
+ }
3070
+
3071
+ /**
3072
+ * UM hook
3073
+ *
3074
+ * @type filter
3075
+ * @title um_fields_options_enable_pairs__{$key}
3076
+ * @description Enable options pairs by field $key
3077
+ * @input_vars
3078
+ * [{"var":"$options_pairs","type":"string","desc":"Enable pairs"}]
3079
+ * @change_log
3080
+ * ["Since: 2.0"]
3081
+ * @usage add_filter( 'um_fields_options_enable_pairs__{$key}', 'function_name', 10, 1 );
3082
+ * @example
3083
+ * <?php
3084
+ * add_filter( 'um_fields_options_enable_pairs__{$key}', 'my_fields_options_enable_pairs', 10, 1 );
3085
+ * function my_fields_options_enable_pairs( $options_pairs ) {
3086
+ * // your code here
3087
+ * return $options_pairs;
3088
+ * }
3089
+ * ?>
3090
+ */
3091
+ $enable_options_pair = apply_filters( "um_fields_options_enable_pairs__{$key}", false );
3092
+
3093
+ if ( ! $has_parent_option ) {
3094
+ if ( isset( $options ) && $options == 'builtin' ) {
3095
+ $options = UM()->builtin()->get ( $filter );
3096
+ }
3097
+
3098
+ // 'country'
3099
+ if ( $key === 'country' && empty( $options ) ) {
3100
+ $options = UM()->builtin()->get( 'countries' );
3101
+ } else if ( empty( $options ) && isset( $data['options'] ) ) {
3102
+ $options = $data['options'];
3103
+ }
3104
+
3105
+ $options = apply_filters( 'um_selectbox_options', $options, $key );
3106
+
3107
+ if ( isset( $options ) ) {
3108
+ /**
3109
+ * UM hook
3110
+ *
3111
+ * @type filter
3112
+ * @title um_select_dropdown_dynamic_options
3113
+ * @description Extend dropdown dynamic options
3114
+ * @input_vars
3115
+ * [{"var":"$options","type":"array","desc":"Dynamic options"},
3116
+ * {"var":"$data","type":"array","desc":"Field Data"}]
3117
+ * @change_log
3118
+ * ["Since: 2.0"]
3119
+ * @usage add_filter( 'um_select_dropdown_dynamic_options', 'function_name', 10, 2 );
3120
+ * @example
3121
+ * <?php
3122
+ * add_filter( 'um_select_dropdown_dynamic_options', 'my_select_dropdown_dynamic_options', 10, 2 );
3123
+ * function my_select_dropdown_dynamic_options( $options, $data ) {
3124
+ * // your code here
3125
+ * return $options;
3126
+ * }
3127
+ * ?>
3128
+ */
3129
+ $options = apply_filters( 'um_select_dropdown_dynamic_options', $options, $data );
3130
+ /**
3131
+ * UM hook
3132
+ *
3133
+ * @type filter
3134
+ * @title um_select_dropdown_dynamic_options_{$key}
3135
+ * @description Extend dropdown dynamic options by field $key
3136
+ * @input_vars
3137
+ * [{"var":"$options","type":"array","desc":"Dynamic options"}]
3138
+ * @change_log
3139
+ * ["Since: 2.0"]
3140
+ * @usage add_filter( 'um_select_dropdown_dynamic_options_{$key}', 'function_name', 10, 1 );
3141
+ * @example
3142
+ * <?php
3143
+ * add_filter( 'um_select_dropdown_dynamic_options_{$key}', 'my_select_dropdown_dynamic_options', 10, 1 );
3144
+ * function my_select_dropdown_dynamic_options( $options ) {
3145
+ * // your code here
3146
+ * return $options;
3147
+ * }
3148
+ * ?>
3149
+ */
3150
+ $options = apply_filters( "um_select_dropdown_dynamic_options_{$key}", $options );
3151
+ }
3152
+ }
3153
+
3154
+ if ( $form_key === 'role' ) {
3155
+ $options = $this->get_available_roles( $form_key, $options );
3156
+ }
3157
+
3158
+ /**
3159
+ * UM hook
3160
+ *
3161
+ * @type filter
3162
+ * @title um_select_option_value
3163
+ * @description Enable options pair by field $data
3164
+ * @input_vars
3165
+ * [{"var":"$options_pair","type":"null","desc":"Enable pairs"},
3166
+ * {"var":"$data","type":"array","desc":"Field Data"}]
3167
+ */
3168
+ $options_pair = apply_filters( 'um_select_options_pair', null, $data );
3169
+
3170
+ // switch options pair for custom options from a callback function
3171
+ if ( ! empty( $data['custom_dropdown_options_source'] ) ) {
3172
+ $options_pair = true;
3173
+ }
3174
+
3175
+ $field_value = '';
3176
+
3177
+ if ( ! empty( $placeholder ) && is_string( $placeholder ) ) {
3178
+ $placeholder = strip_tags( $placeholder );
3179
+ }
3180
+
3181
+ $output .= '<select data-default="' . $data['default'] . '" ' . $disabled . ' ' . $select_original_option_value . ' ' . $disabled_by_parent_option . ' name="' . esc_attr( $form_key ) . '" id="' . esc_attr( $field_id ) . '" data-validate="' . esc_attr( $validate ) . '" data-key="' . esc_attr( $key ) . '" class="' . $this->get_class( $key, $data, $class ) . '" style="width: 100%" data-placeholder="' . esc_attr( $placeholder ) . '" ' . $atts_ajax . '>';
3182
+
3183
+ $output .= '<option value=""></option>';
3184
+
3185
+ // add options
3186
+ if ( ! empty( $options ) ) {
3187
+ foreach ( $options as $k => $v ) {
3188
+
3189
+ $v = rtrim( $v );
3190
+
3191
+ $option_value = $v;
3192
+ $um_field_checkbox_item_title = $v;
3193
+
3194
+
3195
+ if ( ! is_numeric( $k ) && in_array( $form_key, array( 'role' ) ) ||
3196
+ ( $this->set_mode == 'account' || um_is_core_page( 'account' ) ) ) {
3197
+ $option_value = $k;
3198
+ $um_field_checkbox_item_title = $v;
3199
+ }
3200
+
3201
+ if ( isset( $options_pair ) ) {
3202
+ $option_value = $k;
3203
+ $um_field_checkbox_item_title = $v;
3204
+ }
3205
+
3206
+ $option_value = $this->filter_field_non_utf8_value( $option_value );
3207
+
3208
+ $output .= '<option value="' . $option_value . '" ';
3209
+
3210
+ if ( $this->is_selected( $form_key, $option_value, $data ) ) {
3211
+ $output .= 'selected';
3212
+ $field_value = $option_value;
3213
+ } elseif ( ! isset( $options_pair ) && $this->is_selected( $form_key, $v, $data ) ) {
3214
+ $output .= 'selected';
3215
+ $field_value = $v;
3216
+ }
3217
+
3218
+ $output .= '>' . __( $um_field_checkbox_item_title, 'ultimate-member' ) . '</option>';
3219
+ }
3220
+ }
3221
+
3222
+ if ( ! empty( $disabled ) ) {
3223
+ $output .= $this->disabled_hidden_field( $form_key, $field_value );
3224
+ }
3225
+
3226
+ $output .= '</select>';
3227
+
3228
+ $output .= '</div>';
3229
+
3230
+
3231
+ if ( $this->is_error( $form_key ) ) {
3232
+ $output .= $this->field_error( $this->show_error( $form_key ) );
3233
+ } elseif ( $this->is_notice( $form_key ) ) {
3234
+ $output .= $this->field_notice( $this->show_notice( $form_key ) );
3235
+ }
3236
+
3237
+
3238
+ $output .= '</div>';
3239
+ break;
3240
+
3241
+ /* Multi-Select dropdown */
3242
+ case 'multiselect':
3243
+
3244
+ $max_selections = ( isset( $max_selections ) ) ? absint( $max_selections ) : 0;
3245
+
3246
+ $output .= '<div ' . $this->get_atts( $key, $classes, $conditional, $data ) . '>';
3247
+
3248
+ if ( isset( $data['allowclear'] ) && $data['allowclear'] == 0 ) {
3249
+ $class = 'um-s2';
3250
+ } else {
3251
+ $class = 'um-s1';
3252
+ }
3253
+
3254
+ if ( isset( $data['label'] ) ) {
3255
+ $output .= $this->field_label( $label, $key, $data );
3256
+ }
3257
+
3258
+ $field_icon = false;
3259
+ $field_icon_output = '';
3260
+
3261
+ /**
3262
+ * UM hook
3263
+ *
3264
+ * @type filter
3265
+ * @title um_multiselect_option_value
3266
+ * @description Change multiselect keyword data
3267
+ * @input_vars
3268
+ * [{"var":"$keyword","type":"int","desc":"Option Value"},
3269
+ * {"var":"$type","type":"string","desc":"Field Type"}]
3270
+ * @change_log
3271
+ * ["Since: 2.0"]
3272
+ * @usage add_filter( 'um_multiselect_option_value', 'function_name', 10, 2 );
3273
+ * @example
3274
+ * <?php
3275
+ * add_filter( 'um_multiselect_option_value', 'my_multiselect_option_value', 10, 2 );
3276
+ * function my_multiselect_option_value( $keyword, $type ) {
3277
+ * // your code here
3278
+ * return $keyword;
3279
+ * }
3280
+ * ?>
3281
+ */
3282
+ $use_keyword = apply_filters( 'um_multiselect_option_value', 0, $data['type'] );
3283
+
3284
+ $output .= '<div class="um-field-area ' . (! empty( $icon ) && isset( $this->field_icons ) && $this->field_icons == 'field' ? 'um-field-area-has-icon' : '' ) . ' ">';
3285
+ if ( ! empty( $icon ) && isset( $this->field_icons ) && $this->field_icons == 'field') {
3286
+ $output .= '<div class="um-field-icon"><i class="' . esc_attr( $icon ) . '"></i></div>';
3287
+ }
3288
+
3289
+ $output .= '<select ' . $disabled . ' multiple="multiple" name="' . esc_attr( $field_name ) . '[]" id="' . esc_attr( $field_id ) . '" data-maxsize="' . esc_attr( $max_selections ) . '" data-validate="' . esc_attr( $validate ) . '" data-key="' . esc_attr( $key ) . '" class="' . $this->get_class( $key, $data, $class ) . ' um-user-keyword_' . $use_keyword . '" style="width: 100%" data-placeholder="' . esc_attr( $placeholder ) . '">';
3290
+
3291
+
3292
+ if ( isset( $options ) && $options == 'builtin' ) {
3293
+ $options = UM()->builtin()->get( $filter );
3294
+ }
3295
+
3296
+ if ( ! isset( $options ) ) {
3297
+ $options = UM()->builtin()->get( 'countries' );
3298
+ }
3299
+
3300
+ if ( isset( $options ) ) {
3301
+ /**
3302
+ * UM hook
3303
+ *
3304
+ * @type filter
3305
+ * @title um_multiselect_options
3306
+ * @description Extend multiselect options
3307
+ * @input_vars
3308
+ * [{"var":"$options","type":"array","desc":"Multiselect Options"},
3309
+ * {"var":"$data","type":"array","desc":"Field Data"}]
3310
+ * @change_log
3311
+ * ["Since: 2.0"]
3312
+ * @usage add_filter( 'um_multiselect_options', 'function_name', 10, 2 );
3313
+ * @example
3314
+ * <?php
3315
+ * add_filter( 'um_multiselect_options', 'my_multiselect_options', 10, 2 );
3316
+ * function my_multiselect_options( $options, $data ) {
3317
+ * // your code here
3318
+ * return $options;
3319
+ * }
3320
+ * ?>
3321
+ */
3322
+ $options = apply_filters( 'um_multiselect_options', $options, $data );
3323
+ /**
3324
+ * UM hook
3325
+ *
3326
+ * @type filter
3327
+ * @title um_multiselect_options_{$key}
3328
+ * @description Extend multiselect options by field $key
3329
+ * @input_vars
3330
+ * [{"var":"$options","type":"array","desc":"Multiselect Options"}]
3331
+ * @change_log
3332
+ * ["Since: 2.0"]
3333
+ * @usage add_filter( 'um_multiselect_options_{$key}', 'function_name', 10, 1 );
3334
+ * @example
3335
+ * <?php
3336
+ * add_filter( 'um_multiselect_options_{$key}', 'my_multiselect_options', 10, 1 );
3337
+ * function my_multiselect_options( $options ) {
3338
+ * // your code here
3339
+ * return $options;
3340
+ * }
3341
+ * ?>
3342
+ */
3343
+ $options = apply_filters( "um_multiselect_options_{$key}", $options );
3344
+ /**
3345
+ * UM hook
3346
+ *
3347
+ * @type filter
3348
+ * @title um_multiselect_options_{$type}
3349
+ * @description Extend multiselect options by field $type
3350
+ * @input_vars
3351
+ * [{"var":"$options","type":"array","desc":"Multiselect Options"},
3352
+ * {"var":"$data","type":"array","desc":"Field Data"}]
3353
+ * @change_log
3354
+ * ["Since: 2.0"]
3355
+ * @usage add_filter( 'um_multiselect_options_{$type}', 'function_name', 10, 2 );
3356
+ * @example
3357
+ * <?php
3358
+ * add_filter( 'um_multiselect_options_{$type}', 'my_multiselect_options', 10, 2 );
3359
+ * function my_multiselect_option_value( $options, $data ) {
3360
+ * // your code here
3361
+ * return $options;
3362
+ * }
3363
+ * ?>
3364
+ */
3365
+ $options = apply_filters( "um_multiselect_options_{$data['type']}", $options, $data );
3366
+ }
3367
+
3368
+ /**
3369
+ * UM hook
3370
+ *
3371
+ * @type filter
3372
+ * @title um_select_option_value
3373
+ * @description Enable options pair by field $data
3374
+ * @input_vars
3375
+ * [{"var":"$options_pair","type":"null","desc":"Enable pairs"},
3376
+ * {"var":"$data","type":"array","desc":"Field Data"}]
3377
+ */
3378
+ $use_keyword = apply_filters( 'um_select_options_pair', null, $data );
3379
+
3380
+ // switch options pair for custom options from a callback function
3381
+ if ( ! empty( $data['custom_dropdown_options_source'] ) ) {
3382
+ $use_keyword = true;
3383
+ }
3384
+
3385
+ // add an empty option!
3386
+ $output .= '<option value=""></option>';
3387
+
3388
+ $arr_selected = array();
3389
+ // add options
3390
+ if ( ! empty( $options ) && is_array( $options ) ) {
3391
+ foreach ( $options as $k => $v ) {
3392
+
3393
+ $v = rtrim( $v );
3394
+
3395
+ $um_field_checkbox_item_title = $v;
3396
+ $opt_value = $v;
3397
+
3398
+ if ( $use_keyword ) {
3399
+ $um_field_checkbox_item_title = $v;
3400
+ $opt_value = $k;
3401
+ }
3402
+
3403
+ $opt_value = $this->filter_field_non_utf8_value( $opt_value );
3404
+
3405
+ $output .= '<option value="' . $opt_value . '" ';
3406
+ if ( $this->is_selected( $key, $opt_value, $data ) ) {
3407
+
3408
+ $output .= 'selected';
3409
+ $arr_selected[ $opt_value ] = $opt_value;
3410
+ }
3411
+
3412
+ $output .= '>' . __( $um_field_checkbox_item_title, 'ultimate-member' ) . '</option>';
3413
+
3414
+ }
3415
+ }
3416
+
3417
+ $output .= '</select>';
3418
+
3419
+ if ( ! empty( $disabled ) && ! empty( $arr_selected ) ) {
3420
+ foreach ( $arr_selected as $item ) {
3421
+ $output .= $this->disabled_hidden_field( $key . '[]', $item );
3422
+ }
3423
+ }
3424
+
3425
+ $output .= '</div>';
3426
+
3427
+
3428
+ if ( $this->is_error( $key ) ) {
3429
+ $output .= $this->field_error( $this->show_error( $key ) );
3430
+ }else if ( $this->is_notice( $key ) ) {
3431
+ $output .= $this->field_notice( $this->show_notice( $key ) );
3432
+ }
3433
+
3434
+ $output .= '</div>';
3435
+ break;
3436
+
3437
+ /* Radio */
3438
+ case 'radio':
3439
+
3440
+ if ( isset( $options ) ) {
3441
+ /**
3442
+ * UM hook
3443
+ *
3444
+ * @type filter
3445
+ * @title um_radio_field_options
3446
+ * @description Extend radio field options
3447
+ * @input_vars
3448
+ * [{"var":"$options","type":"array","desc":"Radio Field Options"},
3449
+ * {"var":"$data","type":"array","desc":"Field Data"}]
3450
+ * @change_log
3451
+ * ["Since: 2.0"]
3452
+ * @usage add_filter( 'um_radio_field_options', 'function_name', 10, 2 );
3453
+ * @example
3454
+ * <?php
3455
+ * add_filter( 'um_radio_field_options', 'my_radio_field_options', 10, 2 );
3456
+ * function my_radio_field_options( $options, $data ) {
3457
+ * // your code here
3458
+ * return $options;
3459
+ * }
3460
+ * ?>
3461
+ */
3462
+ $options = apply_filters( 'um_radio_field_options', $options, $data );
3463
+ /**
3464
+ * UM hook
3465
+ *
3466
+ * @type filter
3467
+ * @title um_radio_field_options_{$key}
3468
+ * @description Extend radio field options by field $key
3469
+ * @input_vars
3470
+ * [{"var":"$options","type":"array","desc":"Radio field Options"}]
3471
+ * @change_log
3472
+ * ["Since: 2.0"]
3473
+ * @usage add_filter( 'um_radio_field_options_{$key}', 'function_name', 10, 1 );
3474
+ * @example
3475
+ * <?php
3476
+ * add_filter( 'um_radio_field_options_{$key}', 'my_radio_field_options', 10, 1 );
3477
+ * function my_radio_field_options( $options ) {
3478
+ * // your code here
3479
+ * return $options;
3480
+ * }
3481
+ * ?>
3482
+ */
3483
+ $options = apply_filters( "um_radio_field_options_{$key}", $options );
3484
+ }
3485
+
3486
+ $output .= '<div ' . $this->get_atts( $key, $classes, $conditional, $data ) . '>';
3487
+
3488
+ if ( isset( $data['label'] ) ) {
3489
+ $output .= $this->field_label( $label, $key, $data );
3490
+ }
3491
+
3492
+ $output .= '<div class="um-field-area">';
3493
+
3494
+ $options = $this->get_available_roles( $form_key, $options );
3495
+
3496
+ // add options
3497
+ $i = 0;
3498
+ $field_value = array();
3499
+
3500
+ /**
3501
+ * UM hook
3502
+ *
3503
+ * @type filter
3504
+ * @title um_radio_option_value
3505
+ * @description Enable options pair by field $data
3506
+ * @input_vars
3507
+ * [{"var":"$options_pair","type":"null","desc":"Enable pairs"},
3508
+ * {"var":"$data","type":"array","desc":"Field Data"}]
3509
+ */
3510
+ $options_pair = apply_filters( "um_radio_options_pair__{$key}", false, $data );
3511
+
3512
+
3513
+ if ( ! empty( $options ) ) {
3514
+ foreach ( $options as $k => $v ) {
3515
+
3516
+ $v = rtrim( $v );
3517
+
3518
+ $um_field_checkbox_item_title = $v;
3519
+ $option_value = $v;
3520
+
3521
+ if ( ! is_numeric( $k ) && in_array( $form_key, array( 'role' ) ) ||
3522
+ ( $this->set_mode == 'account' || um_is_core_page( 'account' ) ) ) {
3523
+ $um_field_checkbox_item_title = $v;
3524
+ $option_value = $k;
3525
+ }
3526
+
3527
+ if( $options_pair ){
3528
+ $um_field_checkbox_item_title = $v;
3529
+ $option_value = $k;
3530
+ }
3531
+
3532
+ $i++;
3533
+ if ($i % 2 == 0) {
3534
+ $col_class = 'right';
3535
+ } else {
3536
+ $col_class = '';
3537
+ }
3538
+
3539
+ if ( $this->is_radio_checked( $key, $option_value, $data ) ) {
3540
+ $active = 'active';
3541
+ $class = "um-icon-android-radio-button-on";
3542
+ } else {
3543
+ $active = '';
3544
+ $class = "um-icon-android-radio-button-off";
3545
+ }
3546
+
3547
+
3548
+ if ( isset( $data['editable'] ) && $data['editable'] == 0 ) {
3549
+ $col_class .= " um-field-radio-state-disabled";
3550
+ }
3551
+
3552
+ $output .= '<label class="um-field-radio ' . esc_attr( $active ) . ' um-field-half ' . esc_attr( $col_class ) . '">';
3553
+
3554
+ $option_value = $this->filter_field_non_utf8_value( $option_value );
3555
+
3556
+ $output .= '<input ' . $disabled . ' type="radio" name="' . ( ( $form_key == 'role' ) ? esc_attr( $form_key ) : esc_attr( $form_key ) . '[]' ) . '" value="' . $option_value . '" ';
3557
+
3558
+ if ( $this->is_radio_checked( $key, $option_value, $data ) ) {
3559
+ $output .= 'checked';
3560
+ $field_value[ $key ] = $option_value;
3561
+ }
3562
+
3563
+ $output .= ' />';
3564
+
3565
+ $output .= '<span class="um-field-radio-state"><i class="' . esc_attr( $class ) . '"></i></span>';
3566
+ $output .= '<span class="um-field-radio-option">' . esc_html__( $um_field_checkbox_item_title, 'ultimate-member' ) . '</span>';
3567
+ $output .= '</label>';
3568
+
3569
+ if ( $i % 2 == 0 ) {
3570
+ $output .= '<div class="um-clear"></div>';
3571
+ }
3572
+
3573
+ }
3574
+ }
3575
+
3576
+ if ( ! empty( $disabled ) ) {
3577
+ foreach ( $field_value as $item ) {
3578
+ $output .= $this->disabled_hidden_field( $form_key, $item );
3579
+ }
3580
+ }
3581
+
3582
+ $output .= '<div class="um-clear"></div>';
3583
+
3584
+ $output .= '</div>';
3585
+
3586
+ if ( $this->is_error( $key ) ) {
3587
+ $output .= $this->field_error( $this->show_error( $key ) );
3588
+ }else if ( $this->is_notice( $key ) ) {
3589
+ $output .= $this->field_notice( $this->show_notice( $key ) );
3590
+ }
3591
+
3592
+ $output .= '</div>';
3593
+ break;
3594
+
3595
+ /* Checkbox */
3596
+ case 'checkbox':
3597
+
3598
+ if ( isset( $options ) ) {
3599
+ /**
3600
+ * UM hook
3601
+ *
3602
+ * @type filter
3603
+ * @title um_checkbox_field_options
3604
+ * @description Extend checkbox options
3605
+ * @input_vars
3606
+ * [{"var":"$options","type":"array","desc":"Checkbox Options"},
3607
+ * {"var":"$data","type":"array","desc":"Field Data"}]
3608
+ * @change_log
3609
+ * ["Since: 2.0"]
3610
+ * @usage add_filter( 'um_checkbox_field_options', 'function_name', 10, 2 );
3611
+ * @example
3612
+ * <?php
3613
+ * add_filter( 'um_checkbox_field_options', 'my_checkbox_options', 10, 2 );
3614
+ * function my_checkbox_options( $options, $data ) {
3615
+ * // your code here
3616
+ * return $options;
3617
+ * }
3618
+ * ?>
3619
+ */
3620
+ $options = apply_filters( 'um_checkbox_field_options', $options, $data );
3621
+ /**
3622
+ * UM hook
3623
+ *
3624
+ * @type filter
3625
+ * @title um_checkbox_field_options_{$key}
3626
+ * @description Extend checkbox options by field $key
3627
+ * @input_vars
3628
+ * [{"var":"$options","type":"array","desc":"Checkbox Options"}]
3629
+ * @change_log
3630
+ * ["Since: 2.0"]
3631
+ * @usage add_filter( 'um_checkbox_field_options_{$key}', 'function_name', 10, 1 );
3632
+ * @example
3633
+ * <?php
3634
+ * add_filter( 'um_checkbox_field_options_{$key}', 'my_checkbox_options', 10, 1 );
3635
+ * function my_checkbox_options( $options ) {
3636
+ * // your code here
3637
+ * return $options;
3638
+ * }
3639
+ * ?>
3640
+ */
3641
+ $options = apply_filters( "um_checkbox_field_options_{$key}", $options );
3642
+ }
3643
+
3644
+ $output .= '<div ' . $this->get_atts( $key, $classes, $conditional, $data ) . '>';
3645
+
3646
+ if ( isset( $data['label'] ) ) {
3647
+ $output .= $this->field_label( $label, $key, $data );
3648
+ }
3649
+
3650
+ $output .= '<div class="um-field-area">';
3651
+
3652
+ // add options
3653
+ $i = 0;
3654
+
3655
+ foreach ( $options as $k => $v ) {
3656
+
3657
+ $v = rtrim( $v );
3658
+
3659
+ $i++;
3660
+ if ( $i % 2 == 0 ) {
3661
+ $col_class = 'right';
3662
+ } else {
3663
+ $col_class = '';
3664
+ }
3665
+
3666
+ if ( $this->is_selected( $key, $v, $data ) ) {
3667
+ $active = 'active';
3668
+ $class = "um-icon-android-checkbox-outline";
3669
+ } else {
3670
+ $active = '';
3671
+ $class = "um-icon-android-checkbox-outline-blank";
3672
+ }
3673
+
3674
+ if ( isset( $data['editable'] ) && $data['editable'] == 0 ) {
3675
+ $col_class .= " um-field-radio-state-disabled";
3676
+ }
3677
+
3678
+ $output .= '<label class="um-field-checkbox ' . esc_attr( $active ) . ' um-field-half ' . esc_attr( $col_class ) . '">';
3679
+
3680
+ $um_field_checkbox_item_title = $v;
3681
+
3682
+ $v = $this->filter_field_non_utf8_value( $v );
3683
+
3684
+ $output .= '<input ' . $disabled . ' type="checkbox" name="' . esc_attr( $key ) . '[]" value="' . strip_tags( $v ) . '" ';
3685
+
3686
+ if ( $this->is_selected( $key, $v, $data ) ) {
3687
+ $output .= 'checked';
3688
+ }
3689
+
3690
+ $output .= ' />';
3691
+
3692
+ if ( ! empty( $disabled ) && $this->is_selected( $key, $v, $data ) ) {
3693
+ $output .= $this->disabled_hidden_field( $key . '[]', strip_tags( $v ) );
3694
+ }
3695
+
3696
+
3697
+ $output .= '<span class="um-field-checkbox-state"><i class="' . esc_attr( $class ) . '"></i></span>';
3698
+ /**
3699
+ * UM hook
3700
+ *
3701
+ * @type filter
3702
+ * @title um_field_checkbox_item_title
3703
+ * @description Change Checkbox item title
3704
+ * @input_vars
3705
+ * [{"var":"$checkbox_item_title","type":"array","desc":"Item Title"},
3706
+ * {"var":"$key","type":"string","desc":"Field Key"},
3707
+ * {"var":"$value","type":"string","desc":"Field Value"},
3708
+ * {"var":"$data","type":"array","desc":"Field Data"}]
3709
+ * @change_log
3710
+ * ["Since: 2.0"]
3711
+ * @usage add_filter( 'um_field_checkbox_item_title', 'function_name', 10, 4 );
3712
+ * @example
3713
+ * <?php
3714
+ * add_filter( 'um_field_checkbox_item_title', 'my_checkbox_item_title', 10, 4 );
3715
+ * function my_checkbox_item_title( $checkbox_item_title, $key, $value, $data ) {
3716
+ * // your code here
3717
+ * return $checkbox_item_title;
3718
+ * }
3719
+ * ?>
3720
+ */
3721
+ $um_field_checkbox_item_title = apply_filters( 'um_field_checkbox_item_title', $um_field_checkbox_item_title, $key, $v, $data );
3722
+ $output .= '<span class="um-field-checkbox-option">' . __( $um_field_checkbox_item_title, 'ultimate-member' ) . '</span>';
3723
+ $output .= '</label>';
3724
+
3725
+ if ( $i % 2 == 0 ) {
3726
+ $output .= '<div class="um-clear"></div>';
3727
+ }
3728
+
3729
+ }
3730
+
3731
+ $output .= '<div class="um-clear"></div>';
3732
+
3733
+ $output .= '</div>';
3734
+
3735
+
3736
+ if ( $this->is_error( $key ) ) {
3737
+ $output .= $this->field_error( $this->show_error( $key ) );
3738
+ }else if ( $this->is_notice( $key ) ) {
3739
+ $output .= $this->field_notice( $this->show_notice( $key ) );
3740
+ }
3741
+
3742
+ $output .= '</div>';
3743
+ break;
3744
+
3745
+ /* HTML */
3746
+ case 'block':
3747
+ $output .= '<div ' . $this->get_atts( $key, $classes, $conditional, $data ) . '>' . $content . '</div>';
3748
+ break;
3749
+
3750
+ /* Shortcode */
3751
+ case 'shortcode':
3752
+
3753
+ $content = str_replace( '{profile_id}', um_profile_id(), $content );
3754
+ if ( version_compare( get_bloginfo('version'),'5.4', '<' ) ) {
3755
+ $content = do_shortcode( $content );
3756
+ } else {
3757
+ $content = apply_shortcodes( $content );
3758
+ }
3759
+
3760
+ $output .= '<div ' . $this->get_atts( $key, $classes, $conditional, $data ) . '>' . $content . '</div>';
3761
+ break;
3762
+
3763
+ /* Unlimited Group */
3764
+ case 'group':
3765
+
3766
+ $fields = $this->get_fields_in_group( $key );
3767
+ if ( ! empty( $fields ) ) {
3768
+
3769
+ $output .= '<div class="um-field-group" data-max_entries="' . $max_entries . '">
3770
+ <div class="um-field-group-head"><i class="um-icon-plus"></i>' . esc_html__( $label, 'ultimate-member' ) . '</div>';
3771
+ $output .= '<div class="um-field-group-body"><a href="javascript:void(0);" class="um-field-group-cancel"><i class="um-icon-close"></i></a>';
3772
+
3773
+ foreach ( $fields as $subkey => $subdata ) {
3774
+ $output .= $this->edit_field( $subkey, $subdata, 'group' );
3775
+ }
3776
+
3777
+ $output .= '</div>';
3778
+ $output .= '</div>';
3779
+
3780
+ }
3781
+
3782
+ break;
3783
+
3784
+ }
3785
+
3786
+ // Custom filter for field output
3787
+ if ( isset( $this->set_mode ) ) {
3788
+ /**
3789
+ * UM hook
3790
+ *
3791
+ * @type filter
3792
+ * @title um_{$key}_form_edit_field
3793
+ * @description Change field HTML on edit mode by field $key
3794
+ * @input_vars
3795
+ * [{"var":"$output","type":"string","desc":"Field HTML"},
3796
+ * {"var":"$mode","type":"string","desc":"Fields Mode"}]
3797
+ * @change_log
3798
+ * ["Since: 2.0"]
3799
+ * @usage add_filter( 'um_{$key}_form_edit_field', 'function_name', 10, 2 );
3800
+ * @example
3801
+ * <?php
3802
+ * add_filter( 'um_{$key}_form_edit_field', 'my_form_edit_field', 10, 2 );
3803
+ * function my_form_edit_field( $output, $mode ) {
3804
+ * // your code here
3805
+ * return $output;
3806
+ * }
3807
+ * ?>
3808
+ */
3809
+ $output = apply_filters( "um_{$key}_form_edit_field", $output, $this->set_mode );
3810
+ }
3811
+
3812
+ return $output;
3813
+ }
3814
+
3815
+
3816
+ /**
3817
+ * Filter for user roles
3818
+ *
3819
+ * @param $form_key
3820
+ * @param array $options
3821
+ * @return array
3822
+ */
3823
+ function get_available_roles( $form_key, $options = array() ) {
3824
+ if ( $form_key != 'role' ) {
3825
+ return $options;
3826
+ }
3827
+
3828
+ // role field
3829
+ global $wp_roles;
3830
+ $role_keys = array_map( function( $item ) {
3831
+ return 'um_' . $item;
3832
+ }, get_option( 'um_roles', array() ) );
3833
+ $exclude_roles = array_diff( array_keys( $wp_roles->roles ), array_merge( $role_keys, array( 'subscriber' ) ) );
3834
+
3835
+ $roles = UM()->roles()->get_roles( false, $exclude_roles );
3836
+
3837
+ if ( ! empty( $options ) ) {
3838
+
3839
+ $roles = array_map( function( $item ) {
3840
+ return html_entity_decode( $item, ENT_QUOTES );
3841
+ }, $roles );
3842
+
3843
+ //fix when customers change options for role (radio/dropdown) fields
3844
+ $intersected_options = array();
3845
+ foreach ( $options as $key => $title ) {
3846
+ if ( false !== $search_key = array_search( $title, $roles ) ) {
3847
+ $intersected_options[ $search_key ] = $title;
3848
+ } elseif ( isset( $roles[ $key ] ) ) {
3849
+ $intersected_options[ $key ] = $title;
3850
+ }
3851
+ }
3852
+
3853
+ $options = $intersected_options;
3854
+ } else {
3855
+ $options = $roles;
3856
+ }
3857
+
3858
+ return $options;
3859
+ }
3860
+
3861
+
3862
+ /**
3863
+ * Sorts columns array
3864
+ *
3865
+ * @param array $arr
3866
+ * @param string $col
3867
+ * @param string $dir
3868
+ *
3869
+ * @return array $arr
3870
+ */
3871
+ function array_sort_by_column( $arr, $col, $dir = SORT_ASC ) {
3872
+ $sort_col = array();
3873
+ foreach ( $arr as $key => $row ) {
3874
+ if ( $key == 'form_id' ) {
3875
+ unset( $arr['form_id'] );
3876
+ continue;
3877
+ }
3878
+
3879
+ if ( isset( $row[ $col ] ) ) {
3880
+ $sort_col[ $key ] = $row[ $col ];
3881
+ } else {
3882
+ unset( $arr[ $key ] );
3883
+ }
3884
+ }
3885
+
3886
+ array_multisort( $sort_col, $dir, $arr );
3887
+
3888
+ return $arr;
3889
+ }
3890
+
3891
+
3892
+ /**
3893
+ * Get fields in row
3894
+ *
3895
+ * @param int $row_id
3896
+ *
3897
+ * @return string
3898
+ */
3899
+ function get_fields_by_row( $row_id ) {
3900
+ if ( ! isset( $this->get_fields ) ) {
3901
+ return '';
3902
+ }
3903
+
3904
+ foreach ( $this->get_fields as $key => $array ) {
3905
+ if ( ! isset( $array['in_row'] ) || ( isset( $array['in_row'] ) && $array['in_row'] == $row_id ) ) {
3906
+ $results[ $key ] = $array;
3907
+ }
3908
+ }
3909
+
3910
+ return ( isset ( $results ) ) ? $results : '';
3911
+ }
3912
+
3913
+
3914
+ /**
3915
+ * Get fields by sub row
3916
+ *
3917
+ * @param string $row_fields
3918
+ * @param integer $subrow_id
3919
+ *
3920
+ * @return mixed
3921
+ */
3922
+ function get_fields_in_subrow( $row_fields, $subrow_id ) {
3923
+ if ( ! is_array( $row_fields ) ) {
3924
+ return '';
3925
+ }
3926
+ foreach ( $row_fields as $key => $array ) {
3927
+ if ( ! isset( $array['in_sub_row'] ) || ( isset( $array['in_sub_row'] ) && $array['in_sub_row'] == $subrow_id ) ) {
3928
+ $results[ $key ] = $array;
3929
+ }
3930
+ }
3931
+
3932
+ return ( isset ( $results ) ) ? $results : '';
3933
+ }
3934
+
3935
+
3936
+ /**
3937
+ * Get fields in group
3938
+ *
3939
+ * @param integer $group_id
3940
+ *
3941
+ * @return mixed
3942
+ */
3943
+ function get_fields_in_group( $group_id ) {
3944
+ foreach ( $this->get_fields as $key => $array ) {
3945
+ if ( isset( $array['in_group'] ) && $array['in_group'] == $group_id ) {
3946
+ $results[ $key ] = $array;
3947
+ }
3948
+ }
3949
+
3950
+ return ( isset ( $results ) ) ? $results : '';
3951
+ }
3952
+
3953
+
3954
+ /**
3955
+ * Get fields in column
3956
+ *
3957
+ * @param array $fields
3958
+ * @param integer $col_number
3959
+ *
3960
+ * @return mixed
3961
+ */
3962
+ function get_fields_in_column( $fields, $col_number ) {
3963
+ foreach ( $fields as $key => $array ) {
3964
+ if ( isset( $array['in_column'] ) && $array['in_column'] == $col_number ) {
3965
+ $results[ $key ] = $array;
3966
+ }
3967
+ }
3968
+
3969
+ return ( isset ( $results ) ) ? $results : '';
3970
+ }
3971
+
3972
+
3973
+ /**
3974
+ * Display fields
3975
+ *
3976
+ * @param string $mode
3977
+ * @param array $args
3978
+ *
3979
+ * @return string|null
3980
+ * @throws \Exception
3981
+ */
3982
+ function display( $mode, $args ) {
3983
+ $output = null;
3984
+
3985
+ $this->global_args = $args;
3986
+
3987
+ UM()->form()->form_suffix = '-' . $this->global_args['form_id'];
3988
+
3989
+ $this->set_mode = $mode;
3990
+
3991
+ if ( 'profile' === $mode ) {
3992
+ UM()->form()->nonce = wp_create_nonce( 'um-profile-nonce' . UM()->user()->target_id );
3993
+ }
3994
+
3995
+ $this->set_id = $this->global_args['form_id'];
3996
+
3997
+ $this->field_icons = ( isset( $this->global_args['icons'] ) ) ? $this->global_args['icons'] : 'label';
3998
+
3999
+ // start output here
4000
+ $this->get_fields = $this->get_fields();
4001
+
4002
+ if ( ! empty( $this->get_fields ) ) {
4003
+
4004
+ // find rows
4005
+ foreach ( $this->get_fields as $key => $array ) {
4006
+ if ( $array['type'] == 'row' ) {
4007
+ $this->rows[ $key ] = $array;
4008
+ unset( $this->get_fields[ $key ] ); // not needed anymore
4009
+ }
4010
+ }
4011
+
4012
+ // rows fallback
4013
+ if ( ! isset( $this->rows ) ) {
4014
+ $this->rows = array(
4015
+ '_um_row_1' => array(
4016
+ 'type' => 'row',
4017
+ 'id' => '_um_row_1',
4018
+ 'sub_rows' => 1,
4019
+ 'cols' => 1,
4020
+ ),
4021
+ );
4022
+ }
4023
+
4024
+ // master rows
4025
+ foreach ( $this->rows as $row_id => $row_array ) {
4026
+
4027
+ $row_fields = $this->get_fields_by_row( $row_id );
4028
+ if ( $row_fields ) {
4029
+
4030
+ $output .= $this->new_row_output( $row_id, $row_array );
4031
+
4032
+ $sub_rows = ( isset( $row_array['sub_rows'] ) ) ? $row_array['sub_rows'] : 1;
4033
+ for ( $c = 0; $c < $sub_rows; $c++ ) {
4034
+
4035
+ // cols
4036
+ $cols = isset( $row_array['cols'] ) ? $row_array['cols'] : 1;
4037
+ if ( is_numeric( $cols ) ) {
4038
+ $cols_num = (int) $cols;
4039
+ } else {
4040
+ if ( strstr( $cols, ':' ) ) {
4041
+ $col_split = explode( ':', $cols );
4042
+ } else {
4043
+ $col_split = array( $cols );
4044
+ }
4045
+ $cols_num = $col_split[ $c ];
4046
+ }
4047
+
4048
+ // sub row fields
4049
+ $subrow_fields = null;
4050
+ $subrow_fields = $this->get_fields_in_subrow( $row_fields, $c );
4051
+
4052
+ if ( is_array( $subrow_fields ) ) {
4053
+
4054
+ $subrow_fields = $this->array_sort_by_column( $subrow_fields, 'position' );
4055
+
4056
+ if ( $cols_num == 1 ) {
4057
+
4058
+ $output .= '<div class="um-col-1">';
4059
+ $col1_fields = $this->get_fields_in_column( $subrow_fields, 1 );
4060
+ if ( $col1_fields ) {
4061
+ foreach ( $col1_fields as $key => $data ) {
4062
+ $output .= $this->edit_field( $key, $data );
4063
+ }
4064
+ }
4065
+ $output .= '</div>';
4066
+
4067
+ } else if ($cols_num == 2) {
4068
+
4069
+ $output .= '<div class="um-col-121">';
4070
+ $col1_fields = $this->get_fields_in_column( $subrow_fields, 1 );
4071
+ if ( $col1_fields ) {
4072
+ foreach ( $col1_fields as $key => $data ) {
4073
+ $output .= $this->edit_field( $key, $data );
4074
+ }
4075
+ }
4076
+ $output .= '</div>';
4077
+
4078
+ $output .= '<div class="um-col-122">';
4079
+ $col2_fields = $this->get_fields_in_column( $subrow_fields, 2 );
4080
+ if ( $col2_fields ) {
4081
+ foreach ( $col2_fields as $key => $data ) {
4082
+ $output .= $this->edit_field( $key, $data );
4083
+ }
4084
+ }
4085
+ $output .= '</div><div class="um-clear"></div>';
4086
+
4087
+ } else {
4088
+
4089
+ $output .= '<div class="um-col-131">';
4090
+ $col1_fields = $this->get_fields_in_column( $subrow_fields, 1 );
4091
+ if ( $col1_fields ) {
4092
+ foreach ( $col1_fields as $key => $data ) {
4093
+ $output .= $this->edit_field( $key, $data );
4094
+ }
4095
+ }
4096
+ $output .= '</div>';
4097
+
4098
+ $output .= '<div class="um-col-132">';
4099
+ $col2_fields = $this->get_fields_in_column( $subrow_fields, 2 );
4100
+ if ( $col2_fields ) {
4101
+ foreach ( $col2_fields as $key => $data ) {
4102
+ $output .= $this->edit_field( $key, $data );
4103
+ }
4104
+ }
4105
+ $output .= '</div>';
4106
+
4107
+ $output .= '<div class="um-col-133">';
4108
+ $col3_fields = $this->get_fields_in_column( $subrow_fields, 3 );
4109
+ if ( $col3_fields ) {
4110
+ foreach ( $col3_fields as $key => $data ) {
4111
+ $output .= $this->edit_field( $key, $data );
4112
+ }
4113
+ }
4114
+ $output .= '</div><div class="um-clear"></div>';
4115
+
4116
+ }
4117
+
4118
+ }
4119
+
4120
+ }
4121
+
4122
+ $output .= '</div>';
4123
+
4124
+ }
4125
+
4126
+ }
4127
+
4128
+ }
4129
+
4130
+ return $output;
4131
+ }
4132
+
4133
+
4134
+ /**
4135
+ * Gets a field in `view mode`
4136
+ *
4137
+ * @param string $key
4138
+ * @param array $data
4139
+ * @param bool $rule
4140
+ *
4141
+ * @return string|null
4142
+ * @throws \Exception
4143
+ */
4144
+ function view_field( $key, $data, $rule = false ) {
4145
+ $output = '';
4146
+
4147
+ // get whole field data
4148
+ if ( is_array( $data ) ) {
4149
+ $data = $this->get_field( $key );
4150
+
4151
+ if ( is_array( $data ) ) {
4152
+ /**
4153
+ * @var $visibility
4154
+ * @var $type
4155
+ * @var $default
4156
+ * @var $classes
4157
+ * @var $conditional
4158
+ * @var $content
4159
+ * @var $divider_text
4160
+ * @var $spacing
4161
+ * @var $borderwidth
4162
+ * @var $borderstyle
4163
+ * @var $bordercolor
4164
+ * @var $label
4165
+ */
4166
+ extract( $data );
4167
+ }
4168
+ }
4169
+
4170
+ //hide if empty type
4171
+ if ( ! isset( $data['type'] ) ) {
4172
+ return '';
4173
+ }
4174
+
4175
+ if ( isset( $data['in_group'] ) && $data['in_group'] != '' && $rule != 'group' ) {
4176
+ return '';
4177
+ }
4178
+
4179
+ //invisible on profile page
4180
+ if ( $visibility == 'edit' || $type == 'password' ) {
4181
+ return '';
4182
+ }
4183
+
4184
+ //hide if empty
4185
+ $fields_without_metakey = UM()->builtin()->get_fields_without_metakey();
4186
+ if ( ! in_array( $type, $fields_without_metakey ) ) {
4187
+ $_field_value = $this->field_value( $key, $default, $data );
4188
+
4189
+ if ( ! isset( $_field_value ) || $_field_value == '' ) {
4190
+ return '';
4191
+ }
4192
+ }
4193
+
4194
+ if ( ! um_can_view_field( $data ) ) {
4195
+ return '';
4196
+ }
4197
+
4198
+ // disable these fields in profile view only
4199
+ if ( in_array( $key, array( 'user_password' ) ) && $this->set_mode == 'profile' ) {
4200
+ return '';
4201
+ }
4202
+
4203
+ if ( ! um_field_conditions_are_met( $data ) ) {
4204
+ return '';
4205
+ }
4206
+
4207
+
4208
+ if ( isset( $data['classes'] ) ) {
4209
+ $classes = explode( " ", $data['classes'] );
4210
+ }
4211
+
4212
+ switch ( $type ) {
4213
+
4214
+ /* Default */
4215
+ default:
4216
+
4217
+ $_field_value = $this->field_value( $key, $default, $data );
4218
+
4219
+ if ( ! in_array( $type, $fields_without_metakey ) && ( ! isset( $_field_value ) || $_field_value == '' ) ) {
4220
+ $output = '';
4221
+ } else {
4222
+
4223
+ $output .= '<div ' . $this->get_atts( $key, $classes, $conditional, $data ) . '>';
4224
+
4225
+ if ( isset( $data['label'] ) || ! empty( $data['icon'] ) ) {
4226
+
4227
+ if ( ! isset( $data['label'] ) ) {
4228
+ $data['label'] = '';
4229
+ }
4230
+
4231
+ $output .= $this->field_label( $data['label'], $key, $data );
4232
+ }
4233
+
4234
+ $res = $this->field_value( $key, $default, $data );
4235
+
4236
+ if ( ! empty( $res ) ) {
4237
+ $res = stripslashes( $res );
4238
+ }
4239
+ if ( 'description' === $data['metakey'] ) {
4240
+ if ( UM()->options()->get( 'profile_show_html_bio' ) ) {
4241
+ $res = make_clickable( wpautop( wp_kses_post( $res ) ) );
4242
+ } else {
4243
+ $res = esc_html( $res );
4244
+ }
4245
+
4246
+ $res = nl2br( $res );
4247
+ }
4248
+
4249
+ $data['is_view_field'] = true;
4250
+ /**
4251
+ * UM hook
4252
+ *
4253
+ * @type filter
4254
+ * @title um_view_field
4255
+ * @description Change field HTML on view mode
4256
+ * @input_vars
4257
+ * [{"var":"$output","type":"string","desc":"Field HTML"},
4258
+ * {"var":"$data","type":"string","desc":"Field Data"},
4259
+ * {"var":"$type","type":"string","desc":"Field Type"}]
4260
+ * @change_log
4261
+ * ["Since: 2.0"]
4262
+ * @usage add_filter( 'um_view_field', 'function_name', 10, 3 );
4263
+ * @example
4264
+ * <?php
4265
+ * add_filter( 'um_view_field', 'my_view_field', 10, 3 );
4266
+ * function my_form_edit_field( $output, $data, $type ) {
4267
+ * // your code here
4268
+ * return $output;
4269
+ * }
4270
+ * ?>
4271
+ */
4272
+ $res = apply_filters( 'um_view_field', $res, $data, $type );
4273
+ /**
4274
+ * UM hook
4275
+ *
4276
+ * @type filter
4277
+ * @title um_view_field_value_{$type}
4278
+ * @description Change field HTML on view mode by field type
4279
+ * @input_vars
4280
+ * [{"var":"$output","type":"string","desc":"Field HTML"},
4281
+ * {"var":"$data","type":"string","desc":"Field Data"}]
4282
+ * @change_log
4283
+ * ["Since: 2.0"]
4284
+ * @usage add_filter( 'um_view_field_value_{$type}', 'function_name', 10, 2 );
4285
+ * @example
4286
+ * <?php
4287
+ * add_filter( 'um_view_field_value_{$type}', 'my_view_field', 10, 2 );
4288
+ * function my_form_edit_field( $output, $data ) {
4289
+ * // your code here
4290
+ * return $output;
4291
+ * }
4292
+ * ?>
4293
+ */
4294
+ $res = apply_filters( "um_view_field_value_{$type}", $res, $data );
4295
+
4296
+ $id_attr = '';
4297
+ if ( ! in_array( $type, $fields_without_metakey ) ) {
4298
+ $id_attr = ' id="' . esc_attr( $key . UM()->form()->form_suffix ) . '"';
4299
+ }
4300
+
4301
+ if ( empty( $res ) ) {
4302
+ $output = '';
4303
+ } else {
4304
+ $output .= '<div class="um-field-area">';
4305
+ $output .= '<div class="um-field-value"' . $id_attr . '>' . $res . '</div>';
4306
+ $output .= '</div>';
4307
+
4308
+ $output .= '</div>';
4309
+ }
4310
+ }
4311
+
4312
+ break;
4313
+
4314
+ /* HTML */
4315
+ case 'block':
4316
+ $output .= '<div ' . $this->get_atts( $key, $classes, $conditional, $data ) . '>' . $content . '</div>';
4317
+ break;
4318
+
4319
+ /* Shortcode */
4320
+ case 'shortcode':
4321
+
4322
+ $content = str_replace( '{profile_id}', um_profile_id(), $content );
4323
+ if ( version_compare( get_bloginfo('version'),'5.4', '<' ) ) {
4324
+ $content = do_shortcode( $content );
4325
+ } else {
4326
+ $content = apply_shortcodes( $content );
4327
+ }
4328
+
4329
+ $output .= '<div ' . $this->get_atts( $key, $classes, $conditional, $data ) . '>' . $content . '</div>';
4330
+ break;
4331
+
4332
+ /* Gap/Space */
4333
+ case 'spacing':
4334
+ $output .= '<div ' . $this->get_atts( $key, $classes, $conditional, $data, array( 'height' => $spacing ) ) . '></div>';
4335
+ break;
4336
+
4337
+ /* A line divider */
4338
+ case 'divider':
4339
+ $output .= '<div ' . $this->get_atts( $key, $classes, $conditional, $data, array( 'border-bottom' => $borderwidth . 'px ' . $borderstyle . ' ' . $bordercolor ) ) . '>';
4340
+ if ( $divider_text ) {
4341
+ $output .= '<div class="um-field-divider-text"><span>' . $divider_text . '</span></div>';
4342
+ }
4343
+ $output .= '</div>';
4344
+ break;
4345
+
4346
+ /* Rating */
4347
+ case 'rating':
4348
+
4349
+ $output .= '<div ' . $this->get_atts( $key, $classes, $conditional, $data ) . '>';
4350
+
4351
+ if ( isset( $data['label'] ) || ! empty( $data['icon'] ) ) {
4352
+ $output .= $this->field_label( $label, $key, $data );
4353
+ }
4354
+
4355
+ ob_start(); ?>
4356
+
4357
+ <div class="um-field-area">
4358
+ <div class="um-field-value">
4359
+ <div class="um-rating-readonly um-raty" id="<?php echo esc_attr( $key ) ?>"
4360
+ data-key="<?php echo esc_attr( $key ) ?>" data-number="<?php echo esc_attr( $data['number'] ) ?>"
4361
+ data-score="<?php echo $this->field_value( $key, $default, $data ) ?>"></div>
4362
+ </div>
4363
+ </div>
4364
+
4365
+ <?php $output .= ob_get_clean();
4366
+ $output .= '</div>';
4367
+
4368
+ break;
4369
+
4370
+ }
4371
+
4372
+ // Custom filter for field output
4373
+ if ( isset( $this->set_mode ) ) {
4374
+ /**
4375
+ * UM hook
4376
+ *
4377
+ * @type filter
4378
+ * @title um_{$key}_form_show_field
4379
+ * @description Change field HTML by field $key
4380
+ * @input_vars
4381
+ * [{"var":"$output","type":"string","desc":"Field HTML"},
4382
+ * {"var":"$mode","type":"string","desc":"Form Mode"}]
4383
+ * @change_log
4384
+ * ["Since: 2.0"]
4385
+ * @usage add_filter( 'um_{$key}_form_show_field', 'function_name', 10, 2 );
4386
+ * @example
4387
+ * <?php
4388
+ * add_filter( 'um_{$key}_form_show_field', 'my_form_show_field', 10, 2 );
4389
+ * function my_form_show_field( $output, $mode ) {
4390
+ * // your code here
4391
+ * return $output;
4392
+ * }
4393
+ * ?>
4394
+ */
4395
+ $output = apply_filters( "um_{$key}_form_show_field", $output, $this->set_mode );
4396
+ /**
4397
+ * UM hook
4398
+ *
4399
+ * @type filter
4400
+ * @title um_{$type}_form_show_field
4401
+ * @description Change field HTML by field $type
4402
+ * @input_vars
4403
+ * [{"var":"$output","type":"string","desc":"Field HTML"},
4404
+ * {"var":"$mode","type":"string","desc":"Form Mode"}]
4405
+ * @change_log
4406
+ * ["Since: 2.0"]
4407
+ * @usage add_filter( 'um_{$type}_form_show_field', 'function_name', 10, 2 );
4408
+ * @example
4409
+ * <?php
4410
+ * add_filter( 'um_{$type}_form_show_field', 'my_form_show_field', 10, 2 );
4411
+ * function my_form_show_field( $output, $mode ) {
4412
+ * // your code here
4413
+ * return $output;
4414
+ * }
4415
+ * ?>
4416
+ */
4417
+ $output = apply_filters( "um_{$type}_form_show_field", $output, $this->set_mode );
4418
+ }
4419
+
4420
+ return $output;
4421
+ }
4422
+
4423
+
4424
+ /**
4425
+ * Filter field data
4426
+ *
4427
+ * @param array $data
4428
+ *
4429
+ * @return array
4430
+ */
4431
+ function view_field_output( $data ) {
4432
+ /**
4433
+ * UM hook
4434
+ *
4435
+ * @type filter
4436
+ * @title um_view_field_output_{$type}
4437
+ * @description Change field data output by $type
4438
+ * @input_vars
4439
+ * [{"var":"$data","type":"array","desc":"Field Data"}]
4440
+ * @change_log
4441
+ * ["Since: 2.0"]
4442
+ * @usage add_filter( 'um_view_field_output_{$type}', 'function_name', 10, 1 );
4443
+ * @example
4444
+ * <?php
4445
+ * add_filter( 'um_view_field_output_{$type}', 'my_view_field_output', 10, 1 );
4446
+ * function my_view_field_output( $data ) {
4447
+ * // your code here
4448
+ * return $data;
4449
+ * }
4450
+ * ?>
4451
+ */
4452
+ return apply_filters( "um_view_field_output_" . $data['type'], $data );
4453
+ }
4454
+
4455
+
4456
+ /**
4457
+ * Display fields ( view mode )
4458
+ *
4459
+ * @param string $mode
4460
+ * @param array $args
4461
+ *
4462
+ * @return string|null
4463
+ * @throws \Exception
4464
+ */
4465
+ function display_view( $mode, $args ) {
4466
+ $output = null;
4467
+
4468
+ $this->global_args = $args;
4469
+
4470
+ UM()->form()->form_suffix = '-' . $this->global_args['form_id'];
4471
+
4472
+ $this->set_mode = $mode;
4473
+ $this->set_id = $this->global_args['form_id'];
4474
+
4475
+ $this->field_icons = ( isset( $this->global_args['icons'] ) ) ? $this->global_args['icons'] : 'label';
4476
+
4477
+ // start output here
4478
+ $this->get_fields = $this->get_fields();
4479
+
4480
+ if ( UM()->options()->get( 'profile_empty_text' ) ) {
4481
+
4482
+ $emo = UM()->options()->get( 'profile_empty_text_emo' );
4483
+ if ( $emo ) {
4484
+ $emo = '<i class="um-faicon-frown-o"></i>';
4485
+ } else {
4486
+ $emo = false;
4487
+ }
4488
+
4489
+ if ( um_is_myprofile() ) {
4490
+ $output .= '<p class="um-profile-note">' . $emo . '<span>' . sprintf( __( 'Your profile is looking a little empty. Why not <a href="%s">add</a> some information!', 'ultimate-member' ), esc_url( um_edit_profile_url() ) ) . '</span></p>';
4491
+ } else {
4492
+ $output .= '<p class="um-profile-note">' . $emo . '<span>' . __( 'This user has not added any information to their profile yet.', 'ultimate-member' ) . '</span></p>';
4493
+ }
4494
+ }
4495
+
4496
+ if ( ! empty( $this->get_fields ) ) {
4497
+
4498
+ // find rows
4499
+ foreach ( $this->get_fields as $key => $array ) {
4500
+ if ( $array['type'] == 'row' ) {
4501
+ $this->rows[ $key ] = $array;
4502
+ unset( $this->get_fields[ $key ] ); // not needed anymore
4503
+ }
4504
+ }
4505
+
4506
+ // rows fallback
4507
+ if ( ! isset( $this->rows ) ) {
4508
+ $this->rows = array(
4509
+ '_um_row_1' => array(
4510
+ 'type' => 'row',
4511
+ 'id' => '_um_row_1',
4512
+ 'sub_rows' => 1,
4513
+ 'cols' => 1,
4514
+ ),
4515
+ );
4516
+ }
4517
+
4518
+ // master rows
4519
+ foreach ( $this->rows as $row_id => $row_array ) {
4520
+
4521
+ $row_fields = $this->get_fields_by_row( $row_id );
4522
+
4523
+ if ( $row_fields ) {
4524
+
4525
+ $output .= $this->new_row_output( $row_id, $row_array );
4526
+
4527
+ $sub_rows = ( isset( $row_array['sub_rows'] ) ) ? $row_array['sub_rows'] : 1;
4528
+ for ( $c = 0; $c < $sub_rows; $c++ ) {
4529
+
4530
+ // cols
4531
+ $cols = isset( $row_array['cols'] ) ? $row_array['cols'] : 1;
4532
+ if ( is_numeric( $cols ) ) {
4533
+ $cols_num = (int) $cols;
4534
+ } else {
4535
+ if ( strstr( $cols, ':' ) ) {
4536
+ $col_split = explode( ':', $cols );
4537
+ } else {
4538
+ $col_split = array( $cols );
4539
+ }
4540
+ $cols_num = $col_split[ $c ];
4541
+ }
4542
+
4543
+ // sub row fields
4544
+ $subrow_fields = null;
4545
+ $subrow_fields = $this->get_fields_in_subrow( $row_fields, $c );
4546
+
4547
+ if ( is_array( $subrow_fields ) ) {
4548
+
4549
+ $subrow_fields = $this->array_sort_by_column( $subrow_fields, 'position' );
4550
+
4551
+ if ( $cols_num == 1 ) {
4552
+
4553
+ $output .= '<div class="um-col-1">';
4554
+ $col1_fields = $this->get_fields_in_column( $subrow_fields, 1 );
4555
+ if ( $col1_fields ) {
4556
+ foreach ( $col1_fields as $key => $data ) {
4557
+
4558
+ $data = $this->view_field_output( $data );
4559
+ $output .= $this->view_field( $key, $data );
4560
+
4561
+ }
4562
+ }
4563
+ $output .= '</div>';
4564
+
4565
+ } elseif ( $cols_num == 2 ) {
4566
+
4567
+ $output .= '<div class="um-col-121">';
4568
+ $col1_fields = $this->get_fields_in_column( $subrow_fields, 1 );
4569
+ if ( $col1_fields ) {
4570
+ foreach ( $col1_fields as $key => $data ) {
4571
+
4572
+ $data = $this->view_field_output( $data );
4573
+ $output .= $this->view_field( $key, $data );
4574
+
4575
+ }
4576
+ }
4577
+ $output .= '</div>';
4578
+
4579
+ $output .= '<div class="um-col-122">';
4580
+ $col2_fields = $this->get_fields_in_column( $subrow_fields, 2 );
4581
+ if ( $col2_fields ) {
4582
+ foreach ( $col2_fields as $key => $data ) {
4583
+
4584
+ $data = $this->view_field_output( $data );
4585
+ $output .= $this->view_field( $key, $data );
4586
+
4587
+ }
4588
+ }
4589
+ $output .= '</div><div class="um-clear"></div>';
4590
+
4591
+ } else {
4592
+
4593
+ $output .= '<div class="um-col-131">';
4594
+ $col1_fields = $this->get_fields_in_column( $subrow_fields, 1 );
4595
+ if ( $col1_fields ) {
4596
+ foreach ( $col1_fields as $key => $data ) {
4597
+
4598
+ $data = $this->view_field_output( $data );
4599
+ $output .= $this->view_field( $key, $data );
4600
+
4601
+ }
4602
+ }
4603
+ $output .= '</div>';
4604
+
4605
+ $output .= '<div class="um-col-132">';
4606
+ $col2_fields = $this->get_fields_in_column( $subrow_fields, 2 );
4607
+ if ( $col2_fields ) {
4608
+ foreach ( $col2_fields as $key => $data ) {
4609
+
4610
+ $data = $this->view_field_output( $data );
4611
+ $output .= $this->view_field( $key, $data );
4612
+
4613
+ }
4614
+ }
4615
+ $output .= '</div>';
4616
+
4617
+ $output .= '<div class="um-col-133">';
4618
+ $col3_fields = $this->get_fields_in_column( $subrow_fields, 3 );
4619
+ if ( $col3_fields ) {
4620
+ foreach ( $col3_fields as $key => $data ) {
4621
+
4622
+ $data = $this->view_field_output( $data );
4623
+ $output .= $this->view_field( $key, $data );
4624
+
4625
+ }
4626
+ }
4627
+ $output .= '</div><div class="um-clear"></div>';
4628
+
4629
+ }
4630
+
4631
+ }
4632
+
4633
+ }
4634
+
4635
+ $output .= '</div>';
4636
+
4637
+ }
4638
+
4639
+ }
4640
+
4641
+ }
4642
+
4643
+ return $output;
4644
+ }
4645
+
4646
+
4647
+ /**
4648
+ * Get new row in form
4649
+ *
4650
+ * @param string $row_id
4651
+ * @param array $row_array
4652
+ *
4653
+ * @return string
4654
+ */
4655
+ function new_row_output( $row_id, $row_array ) {
4656
+ $output = null;
4657
+ extract( $row_array );
4658
+
4659
+ $padding = ( isset( $padding ) ) ? $padding : '';
4660
+ $margin = ( isset( $margin ) ) ? $margin : '';
4661
+ $background = ( isset( $background ) ) ? $background : '';
4662
+ $text_color = ( isset( $text_color ) ) ? $text_color : '';
4663
+ $borderradius = ( isset( $borderradius ) ) ? $borderradius : '';
4664
+ $border = ( isset( $border ) ) ? $border : '';
4665
+ $bordercolor = ( isset( $bordercolor ) ) ? $bordercolor : '';
4666
+ $borderstyle = ( isset( $borderstyle ) ) ? $borderstyle : '';
4667
+ $heading = ( isset( $heading ) ) ? $heading : '';
4668
+ $css_class = ( isset( $css_class ) ) ? $css_class : '';
4669
+
4670
+ $css_padding = '';
4671
+ $css_margin = '';
4672
+ $css_background = '';
4673
+ $css_borderradius = '';
4674
+ $css_border = '';
4675
+ $css_bordercolor = '';
4676
+ $css_borderstyle = '';
4677
+ $css_heading_background_color = '';
4678
+ $css_heading_padding = '';
4679
+ $css_heading_text_color = '';
4680
+ $css_heading_borderradius = '';
4681
+ $css_text_color = '';
4682
+
4683
+ // row css rules
4684
+ if ( $padding ) {
4685
+ $css_padding = 'padding: ' . $padding . ';';
4686
+ }
4687
+ if ( $margin ) {
4688
+ $css_margin = 'margin: ' . $margin . ';';
4689
+ } else {
4690
+ $css_margin = 'margin: 0 0 30px 0;';
4691
+ }
4692
+
4693
+ if ( $background ) {
4694
+ $css_background = 'background-color: ' . $background . ';';
4695
+ }
4696
+ if ( $borderradius ) {
4697
+ $css_borderradius = 'border-radius: 0px 0px ' . $borderradius . ' ' . $borderradius . ';';
4698
+ }
4699
+ if ( $border ) {
4700
+ $css_border = 'border-width: ' . $border . ';';
4701
+ }
4702
+ if ( $bordercolor ) {
4703
+ $css_bordercolor = 'border-color: ' . $bordercolor . ';';
4704
+ }
4705
+ if ( $borderstyle ) {
4706
+ $css_borderstyle = 'border-style: ' . $borderstyle . ';';
4707
+ }
4708
+ if ( $text_color ) {
4709
+ $css_text_color = 'color: ' . $text_color . ' !important;';
4710
+ $css_class .= ' um-customized-row';
4711
+ }
4712
+
4713
+ // show the heading
4714
+ if ( $heading ) {
4715
+
4716
+ if ( ! empty( $heading_background_color ) ) {
4717
+ $css_heading_background_color = "background-color: $heading_background_color;";
4718
+ $css_heading_padding = 'padding: 10px 15px;';
4719
+ }
4720
+
4721
+ $css_heading_borderradius = empty( $borderradius ) ? '' : "border-radius: $borderradius $borderradius 0px 0px;";
4722
+ $css_heading_border = $css_border . $css_borderstyle . $css_bordercolor . $css_heading_borderradius . 'border-bottom-width: 0px;';
4723
+ $css_heading_margin = $css_margin . 'margin-bottom: 0px;';
4724
+ $css_heading_text_color = empty( $heading_text_color ) ? '' : "color: $heading_text_color;";
4725
+ $css_icon_color = empty( $icon_color ) ? '' : "color: $icon_color;";
4726
+
4727
+ $output .= '<div class="um-row-heading" style="' . $css_heading_margin . $css_heading_padding . $css_heading_border . $css_heading_background_color . $css_heading_text_color . '">';
4728
+
4729
+ if ( ! empty( $icon ) ) {
4730
+ $output .= '<span class="um-row-heading-icon" style="' . $css_icon_color . '"><i class="' . $icon . '"></i></span>';
4731
+ }
4732
+ if ( ! empty( $heading_text ) ) {
4733
+ $output .= htmlspecialchars( $heading_text );
4734
+ }
4735
+
4736
+ $output .= '</div>';
4737
+
4738
+ $css_border .= 'border-top-width: 0px;';
4739
+ $css_margin .= 'margin-top: 0px;';
4740
+
4741
+ } else {
4742
+
4743
+ // no heading
4744
+ $css_borderradius = empty( $borderradius ) ? '' : "border-radius: $borderradius;";
4745
+
4746
+ }
4747
+
4748
+ $output .= '<div class="um-row ' . $row_id . ' ' . $css_class . '" style="' . $css_padding . $css_background . $css_margin . $css_border . $css_borderstyle . $css_bordercolor . $css_borderradius . $css_text_color . '">';
4749
+
4750
+ return $output;
4751
+ }
4752
+
4753
+
4754
+ /**
4755
+ *
4756
+ */
4757
+ function do_ajax_action() {
4758
+ UM()->admin()->check_ajax_nonce();
4759
+
4760
+ if ( ! is_user_logged_in() || ! current_user_can( 'manage_options' ) ) {
4761
+ wp_send_json_error( __( 'Please login as administrator', 'ultimate-member' ) );
4762
+ }
4763
+
4764
+ /**
4765
+ * @var $in_row
4766
+ * @var $in_sub_row
4767
+ * @var $in_column
4768
+ * @var $in_group
4769
+ * @var $act_id
4770
+ * @var $arg1
4771
+ * @var $arg2
4772
+ */
4773
+ extract( $_POST );
4774
+
4775
+ $output = null;
4776
+
4777
+ $position = array();
4778
+ if ( ! empty( $in_column ) ) {
4779
+ $position['in_row'] = '_um_row_' . ( (int) $in_row + 1 );
4780
+ $position['in_sub_row'] = $in_sub_row;
4781
+ $position['in_column'] = $in_column;
4782
+ $position['in_group'] = $in_group;
4783
+ }
4784
+
4785
+ switch ( $act_id ) {
4786
+
4787
+ case 'um_admin_duplicate_field':
4788
+ $this->duplicate_field( $arg1, $arg2 );
4789
+ break;
4790
+
4791
+ case 'um_admin_remove_field_global':
4792
+ $this->delete_field_from_db( $arg1 );
4793
+ break;
4794
+
4795
+ case 'um_admin_remove_field':
4796
+ $this->delete_field_from_form( $arg1, $arg2 );
4797
+ break;
4798
+
4799
+ case 'um_admin_add_field_from_predefined':
4800
+ $this->add_field_from_predefined( $arg1, $arg2, $position );
4801
+ break;
4802
+
4803
+ case 'um_admin_add_field_from_list':
4804
+ $this->add_field_from_list( $arg1, $arg2, $position );
4805
+ break;
4806
+
4807
+ }
4808
+
4809
+ if ( is_array( $output ) ) {
4810
+ print_r( $output );
4811
+ } else {
4812
+ echo $output;
4813
+ }
4814
+ die;
4815
+
4816
+ }
4817
+
4818
+
4819
+
4820
+ /**
4821
+ * Get rendered field attributes
4822
+ *
4823
+ * @since 2.1.2
4824
+ *
4825
+ * @param string $key
4826
+ * @param array $classes
4827
+ * @param string $conditional
4828
+ * @param array $data
4829
+ * @param array $field_style
4830
+ *
4831
+ * @return string/html
4832
+ */
4833
+ function get_atts( $key, $classes, $conditional, $data, $field_style = array() ) {
4834
+
4835
+ array_unshift( $classes, 'um-field-' . $data['type'] );
4836
+ array_unshift( $classes, 'um-field' );
4837
+
4838
+ $field_atts = array(
4839
+ 'id' => array(
4840
+ "um_field_{$this->set_id}_{$key}",
4841
+ ),
4842
+ 'class' => $classes,
4843
+ 'data-key' => array(
4844
+ esc_attr( $key )
4845
+ )
4846
+ );
4847
+
4848
+ $fields_without_metakey = UM()->builtin()->get_fields_without_metakey();
4849
+
4850
+ if ( in_array( $data['type'], $fields_without_metakey ) ) {
4851
+ unset( $field_atts['id'] );
4852
+
4853
+ if ( empty( $field_atts['data-key'] ) ) {
4854
+ unset( $field_atts['data-key'] );
4855
+ }
4856
+ }
4857
+
4858
+ if ( ! empty( $field_style ) && is_array( $field_style ) ) {
4859
+
4860
+ $arr_inline_style = '';
4861
+ foreach ( $field_style as $style_attr => $style_value ) {
4862
+ $arr_inline_style .= esc_attr( $style_attr ) . ':' . esc_attr( $style_value ) . ';';
4863
+ }
4864
+ $field_atts['style'] = array( $arr_inline_style );
4865
+ }
4866
+
4867
+ /**
4868
+ * UM hook
4869
+ *
4870
+ * @type filter
4871
+ * @title um_field_extra_atts
4872
+ * @description user for adding extra field attributes
4873
+ * @input_vars
4874
+ * [{"var":"$field_atts","type":"array","desc":"Field attributes"},
4875
+ * [{"var":"$key","type":"string","desc":"Field id"},
4876
+ * {"var":"$data","type":"array","desc":"Field Data"}]
4877
+ * @change_log
4878
+ * ["Since: 2.0.57"]
4879
+ * @usage add_filter( 'um_field_extra_atts', 'function_name', 10, 3 );
4880
+ * @example
4881
+ * <?php
4882
+ * add_filter( 'um_field_extra_atts', 'function_name', 10, 3 );
4883
+ * function function_name( $field_atts, $key, $data ) {
4884
+ * // your code here
4885
+ * return $array_extra_atts;
4886
+ * }
4887
+ * ?>
4888
+ */
4889
+ $field_atts = apply_filters( 'um_field_extra_atts', $field_atts, $key, $data );
4890
+
4891
+ $html_atts = '';
4892
+ foreach ( $field_atts as $att_name => $att_values ) {
4893
+ $att_values = implode( " ", $att_values );
4894
+ $html_atts .= " {$att_name}=\"" . esc_attr( $att_values ) . "\"";
4895
+ }
4896
+
4897
+ $html_atts .= $conditional;
4898
+
4899
+ return $html_atts;
4900
+ }
4901
+ }
4902
+ }
includes/core/class-form.php CHANGED
@@ -1,831 +1,837 @@
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
- if ( empty( $allowed_callbacks ) ) {
136
- $arr_options['status'] = 'error';
137
- $arr_options['message'] = __( 'This is not possible for security reasons.', 'ultimate-member' );
138
- wp_send_json( $arr_options );
139
- }
140
-
141
- $allowed_callbacks = array_map( 'rtrim', explode( "\n", $allowed_callbacks ) );
142
-
143
- if ( ! in_array( $ajax_source_func, $allowed_callbacks, true ) ) {
144
- $arr_options['status'] = 'error';
145
- $arr_options['message'] = __( 'This is not possible for security reasons.', 'ultimate-member' );
146
-
147
- wp_send_json( $arr_options );
148
- }
149
-
150
- if ( isset( $_POST['form_id'] ) ) {
151
- UM()->fields()->set_id = absint( $_POST['form_id'] );
152
- }
153
- UM()->fields()->set_mode = 'profile';
154
- $form_fields = UM()->fields()->get_fields();
155
- $arr_options['fields'] = $form_fields;
156
-
157
- if ( isset( $arr_options['post']['members_directory'] ) && 'yes' === $arr_options['post']['members_directory'] ) {
158
- global $wpdb;
159
-
160
- $values_array = $wpdb->get_col(
161
- $wpdb->prepare(
162
- "SELECT DISTINCT meta_value
163
- FROM $wpdb->usermeta
164
- WHERE meta_key = %s AND
165
- meta_value != ''",
166
- $arr_options['post']['child_name']
167
- )
168
- );
169
-
170
- if ( ! empty( $values_array ) ) {
171
- $parent_dropdown = isset( $arr_options['field']['parent_dropdown_relationship'] ) ? $arr_options['field']['parent_dropdown_relationship'] : '';
172
- $arr_options['items'] = call_user_func( $ajax_source_func, $parent_dropdown );
173
-
174
- if ( array_keys( $arr_options['items'] ) !== range( 0, count( $arr_options['items'] ) - 1 ) ) {
175
- // array with dropdown items is associative
176
- $arr_options['items'] = array_intersect_key( array_map( 'trim', $arr_options['items'] ), array_flip( $values_array ) );
177
- } else {
178
- // array with dropdown items has sequential numeric keys, starting from 0 and there are intersected values with $values_array
179
- $arr_options['items'] = array_intersect( $arr_options['items'], $values_array );
180
- }
181
- } else {
182
- $arr_options['items'] = array();
183
- }
184
-
185
- wp_send_json( $arr_options );
186
- } else {
187
- /**
188
- * UM hook
189
- *
190
- * @type filter
191
- * @title um_ajax_select_options__debug_mode
192
- * @description Activate debug mode for AJAX select options
193
- * @input_vars
194
- * [{"var":"$debug_mode","type":"bool","desc":"Enable Debug mode"}]
195
- * @change_log
196
- * ["Since: 2.0"]
197
- * @usage
198
- * <?php add_filter( 'um_ajax_select_options__debug_mode', 'function_name', 10, 1 ); ?>
199
- * @example
200
- * <?php
201
- * add_filter( 'um_ajax_select_options__debug_mode', 'my_ajax_select_options__debug_mode', 10, 1 );
202
- * function my_ajax_select_options__debug_mode( $debug_mode ) {
203
- * // your code here
204
- * return $debug_mode;
205
- * }
206
- * ?>
207
- */
208
- $debug = apply_filters( 'um_ajax_select_options__debug_mode', false );
209
- if ( $debug ) {
210
- $arr_options['debug'] = array(
211
- $_POST,
212
- $form_fields,
213
- );
214
- }
215
-
216
- if ( ! empty( $_POST['child_callback'] ) && isset( $form_fields[ $_POST['child_name'] ] ) ) {
217
- // If the requested callback function is added in the form or added in the field option, execute it with call_user_func.
218
- if ( isset( $form_fields[ $_POST['child_name'] ]['custom_dropdown_options_source'] ) &&
219
- ! empty( $form_fields[ $_POST['child_name'] ]['custom_dropdown_options_source'] ) &&
220
- $form_fields[ $_POST['child_name'] ]['custom_dropdown_options_source'] === $ajax_source_func ) {
221
-
222
- $arr_options['field'] = $form_fields[ $_POST['child_name'] ];
223
-
224
- $arr_options['items'] = call_user_func( $ajax_source_func, $arr_options['field']['parent_dropdown_relationship'] );
225
- } else {
226
- $arr_options['status'] = 'error';
227
- $arr_options['message'] = __( 'This is not possible for security reasons.', 'ultimate-member' );
228
- }
229
- }
230
-
231
- wp_send_json( $arr_options );
232
- }
233
- }
234
-
235
-
236
- /**
237
- * Count the form errors.
238
- * @return integer
239
- */
240
- public function count_errors() {
241
- $errors = $this->errors;
242
-
243
- if ( $errors && is_array( $errors ) ) {
244
- return count( $errors );
245
- }
246
-
247
- return 0;
248
- }
249
-
250
-
251
- /**
252
- * Appends field errors
253
- *
254
- * @param string $key
255
- * @param string $error
256
- */
257
- public function add_error( $key, $error ) {
258
- if ( ! isset( $this->errors[ $key ] ) ) {
259
- /**
260
- * UM hook
261
- *
262
- * @type filter
263
- * @title um_submit_form_error
264
- * @description Change error text on submit form
265
- * @input_vars
266
- * [{"var":"$error","type":"string","desc":"Error String"},
267
- * {"var":"$key","type":"string","desc":"Error Key"}]
268
- * @change_log
269
- * ["Since: 2.0"]
270
- * @usage
271
- * <?php add_filter( 'um_submit_form_error', 'function_name', 10, 2 ); ?>
272
- * @example
273
- * <?php
274
- * add_filter( 'um_submit_form_error', 'my_submit_form_error', 10, 2 );
275
- * function my_submit_form_error( $error, $key ) {
276
- * // your code here
277
- * return $error;
278
- * }
279
- * ?>
280
- */
281
- $this->errors[ $key ] = apply_filters( 'um_submit_form_error', $error, $key );
282
- }
283
- }
284
-
285
- /**
286
- * Appends field notices
287
- * @param string $key
288
- * @param string $notice
289
- */
290
- public function add_notice( $key, $notice ) {
291
- if ( ! isset( $this->notices[ $key ] ) ) {
292
- /**
293
- * UM hook
294
- *
295
- * @type filter
296
- * @title um_submit_form_notice
297
- * @description Change notice text on submit form
298
- * @input_vars
299
- * [{"var":"$notice","type":"string","desc":"notice String"},
300
- * {"var":"$key","type":"string","desc":"notice Key"}]
301
- * @change_log
302
- * ["Since: 2.0"]
303
- * @usage
304
- * <?php add_filter( 'um_submit_form_notice', 'function_name', 10, 2 ); ?>
305
- * @example
306
- * <?php
307
- * add_filter( 'um_submit_form_notice', 'my_submit_form_notice', 10, 2 );
308
- * function my_submit_form_notice( $notice, $key ) {
309
- * // your code here
310
- * return $notice;
311
- * }
312
- * ?>
313
- */
314
- $this->notices[ $key ] = apply_filters( 'um_submit_form_notice', $notice, $key );
315
- }
316
- }
317
-
318
-
319
- /**
320
- * If a form has errors
321
- *
322
- * @param string $key
323
- * @return boolean
324
- */
325
- public function has_error( $key ) {
326
- if ( isset( $this->errors[ $key ] ) ) {
327
- return true;
328
- }
329
- return false;
330
- }
331
-
332
-
333
- /**
334
- * If a form has notices/info
335
- *
336
- * @param string $key
337
- * @return boolean
338
- */
339
- public function has_notice( $key ) {
340
- if ( isset( $this->notices[ $key ] ) ) {
341
- return true;
342
- }
343
- return false;
344
- }
345
-
346
-
347
- /**
348
- * Return the errors as a WordPress Error object
349
- *
350
- * @return \WP_Error
351
- */
352
- function get_wp_error() {
353
- $wp_error = new \WP_Error();
354
- if ( $this->count_errors() > 0 ) {
355
- foreach ( $this->errors as $key => $value ) {
356
- $wp_error->add( $key, $value );
357
- }
358
- }
359
- return $wp_error;
360
- }
361
-
362
-
363
- /**
364
- * Declare all fields
365
- */
366
- public function field_declare() {
367
- if ( isset( UM()->builtin()->custom_fields ) ) {
368
- $this->all_fields = UM()->builtin()->custom_fields;
369
- } else {
370
- $this->all_fields = null;
371
- }
372
- }
373
-
374
-
375
- /**
376
- * Validate form on submit
377
- */
378
- public function form_init() {
379
- if ( isset( $_SERVER['REQUEST_METHOD'] ) ) {
380
- $http_post = ( 'POST' === $_SERVER['REQUEST_METHOD'] );
381
- } else {
382
- $http_post = 'POST';
383
- }
384
-
385
- if ( $http_post && ! is_admin() && isset( $_POST['form_id'] ) && is_numeric( $_POST['form_id'] ) ) {
386
-
387
- $this->form_id = absint( $_POST['form_id'] );
388
- if ( 'um_form' !== get_post_type( $this->form_id ) ) {
389
- return;
390
- }
391
-
392
- $this->form_status = get_post_status( $this->form_id );
393
- if ( 'publish' !== $this->form_status ) {
394
- return;
395
- }
396
-
397
- $this->form_data = UM()->query()->post_data( $this->form_id );
398
-
399
- /**
400
- * UM hook
401
- *
402
- * @type action
403
- * @title um_before_submit_form_post
404
- * @description Before submit form
405
- * @change_log
406
- * ["Since: 2.0"]
407
- * @usage add_action( 'um_before_submit_form_post', 'function_name', 10, 1 );
408
- * @example
409
- * <?php
410
- * add_action( 'um_before_submit_form_post', 'my_before_submit_form_post', 10, 1 );
411
- * function my_run_ajax_function( $post ) {
412
- * // your code here
413
- * }
414
- * ?>
415
- */
416
- do_action( 'um_before_submit_form_post' );
417
-
418
- /* save entire form as global */
419
- /**
420
- * UM hook
421
- *
422
- * @type filter
423
- * @title um_submit_post_form
424
- * @description Change submitted data on form submit
425
- * @input_vars
426
- * [{"var":"$data","type":"array","desc":"Submitted data"}]
427
- * @change_log
428
- * ["Since: 2.0"]
429
- * @usage
430
- * <?php add_filter( 'um_submit_post_form', 'function_name', 10, 1 ); ?>
431
- * @example
432
- * <?php
433
- * add_filter( 'um_submit_post_form', 'my_submit_post_form', 10, 1 );
434
- * function my_submit_post_form( $data ) {
435
- * // your code here
436
- * return $data;
437
- * }
438
- * ?>
439
- */
440
- $this->post_form = apply_filters( 'um_submit_post_form', $_POST );
441
-
442
- if ( isset( $this->post_form[ UM()->honeypot ] ) && '' !== $this->post_form[ UM()->honeypot ] ) {
443
- wp_die( esc_html__( 'Hello, spam bot!', 'ultimate-member' ) );
444
- }
445
-
446
- $this->post_form = $this->beautify( $this->post_form );
447
- $this->post_form = $this->sanitize( $this->post_form );
448
- $this->post_form['submitted'] = $this->post_form;
449
-
450
- $this->post_form = array_merge( $this->form_data, $this->post_form );
451
-
452
- // Remove role from post_form at first if role ! empty and there aren't custom fields with role name
453
- if ( ! empty( $_POST['role'] ) ) {
454
- if ( ! isset( $this->form_data['custom_fields'] ) || ! strstr( $this->form_data['custom_fields'], 'role_' ) ) {
455
- unset( $this->post_form['role'] );
456
- unset( $this->post_form['submitted']['role'] );
457
- }
458
- }
459
-
460
- // Secure sanitize of the submitted data
461
- if ( ! empty( $this->post_form ) ) {
462
- $this->post_form = array_diff_key( $this->post_form, array_flip( UM()->user()->banned_keys ) );
463
- }
464
- if ( ! empty( $this->post_form['submitted'] ) ) {
465
- $this->post_form['submitted'] = array_diff_key( $this->post_form['submitted'], array_flip( UM()->user()->banned_keys ) );
466
- }
467
-
468
- // set default role from settings on registration form
469
- if ( isset( $this->post_form['mode'] ) && 'register' === $this->post_form['mode'] ) {
470
- $role = $this->assigned_role( $this->form_id );
471
- $this->post_form['role'] = $role;
472
- }
473
-
474
- if ( isset( $this->form_data['custom_fields'] ) && strstr( $this->form_data['custom_fields'], 'role_' ) ) { // Secure selected role
475
-
476
- if ( ! empty( $_POST['role'] ) ) {
477
- $custom_field_roles = $this->custom_field_roles( $this->form_data['custom_fields'] );
478
-
479
- if ( ! empty( $custom_field_roles ) ) {
480
- if ( is_array( $_POST['role'] ) ) {
481
- $role = current( $_POST['role'] );
482
- $role = sanitize_key( $role );
483
- } else {
484
- $role = sanitize_key( $_POST['role'] );
485
- }
486
-
487
- global $wp_roles;
488
- $role_keys = array_map(
489
- function( $item ) {
490
- return 'um_' . $item;
491
- },
492
- get_option( 'um_roles', array() )
493
- );
494
- $exclude_roles = array_diff( array_keys( $wp_roles->roles ), array_merge( $role_keys, array( 'subscriber' ) ) );
495
-
496
- if ( ! empty( $role ) &&
497
- ( ! in_array( $role, $custom_field_roles, true ) || in_array( $role, $exclude_roles, true ) ) ) {
498
- wp_die( esc_html__( 'This is not possible for security reasons.', 'ultimate-member' ) );
499
- }
500
-
501
- $this->post_form['role'] = $role;
502
- $this->post_form['submitted']['role'] = $role;
503
- } else {
504
- unset( $this->post_form['role'] );
505
- unset( $this->post_form['submitted']['role'] );
506
-
507
- // set default role for registration form if custom field hasn't proper value
508
- if ( isset( $this->post_form['mode'] ) && 'register' === $this->post_form['mode'] ) {
509
- $role = $this->assigned_role( $this->form_id );
510
- $this->post_form['role'] = $role;
511
- }
512
- }
513
- }
514
- }
515
-
516
- /**
517
- * UM hook
518
- *
519
- * @type filter
520
- * @title um_submit_form_data
521
- * @description Change submitted data on form submit
522
- * @input_vars
523
- * [{"var":"$data","type":"array","desc":"Submitted data"},
524
- * {"var":"$mode","type":"string","desc":"Form mode"}]
525
- * @change_log
526
- * ["Since: 2.0"]
527
- * @usage
528
- * <?php add_filter( 'um_submit_form_data', 'function_name', 10, 2 ); ?>
529
- * @example
530
- * <?php
531
- * add_filter( 'um_submit_form_data', 'my_submit_form_data', 10, 2 );
532
- * function my_submit_form_data( $data ) {
533
- * // your code here
534
- * return $data;
535
- * }
536
- * ?>
537
- */
538
- $this->post_form = apply_filters( 'um_submit_form_data', $this->post_form, $this->post_form['mode'] );
539
-
540
- /* Continue based on form mode - pre-validation */
541
-
542
- /**
543
- * UM hook
544
- *
545
- * @type action
546
- * @title um_submit_form_errors_hook
547
- * @description Action on submit form
548
- * @input_vars
549
- * [{"var":"$post","type":"int","desc":"Post data"}]
550
- * @change_log
551
- * ["Since: 2.0"]
552
- * @usage add_action( 'um_submit_form_errors_hook', 'function_name', 10, 1 );
553
- * @example
554
- * <?php
555
- * add_action( 'um_submit_form_errors_hook', 'my_submit_form_errors', 10, 1 );
556
- * function my_submit_form_errors( $post ) {
557
- * // your code here
558
- * }
559
- * ?>
560
- */
561
- do_action( 'um_submit_form_errors_hook', $this->post_form );
562
- /**
563
- * UM hook
564
- *
565
- * @type action
566
- * @title um_submit_form_{$mode}
567
- * @description Action on submit form
568
- * @input_vars
569
- * [{"var":"$post","type":"int","desc":"Post data"}]
570
- * @change_log
571
- * ["Since: 2.0"]
572
- * @usage add_action( 'um_submit_form_{$mode}', 'function_name', 10, 1 );
573
- * @example
574
- * <?php
575
- * add_action( 'um_submit_form_{$mode}', 'my_submit_form', 10, 1 );
576
- * function my_submit_form( $post ) {
577
- * // your code here
578
- * }
579
- * ?>
580
- */
581
- do_action( "um_submit_form_{$this->post_form['mode']}", $this->post_form );
582
-
583
- }
584
- }
585
-
586
-
587
- /**
588
- * Beautify form data
589
- *
590
- * @param array $form
591
- *
592
- * @return array $form
593
- */
594
- public function beautify( $form ) {
595
- if ( isset( $form['form_id'] ) ) {
596
- $this->form_suffix = '-' . $form['form_id'];
597
- $this->processing = $form['form_id'];
598
-
599
- foreach ( $form as $key => $value ) {
600
- if ( strstr( $key, $this->form_suffix ) ) {
601
- $a_key = str_replace( $this->form_suffix, '', $key );
602
- $form[ $a_key ] = $value;
603
- unset( $form[ $key ] );
604
- }
605
- }
606
- }
607
-
608
- return $form;
609
- }
610
-
611
-
612
- /**
613
- * Beautify form data
614
- *
615
- * @param array $form
616
- *
617
- * @return array $form
618
- */
619
- public function sanitize( $form ) {
620
-
621
- if ( isset( $form['form_id'] ) ) {
622
- if ( isset( $this->form_data['custom_fields'] ) ) {
623
- $custom_fields = maybe_unserialize( $this->form_data['custom_fields'] );
624
-
625
- if ( is_array( $custom_fields ) ) {
626
- foreach ( $custom_fields as $k => $field ) {
627
-
628
- if ( isset( $field['type'] ) ) {
629
- if ( isset( $form[ $k ] ) ) {
630
-
631
- switch ( $field['type'] ) {
632
- default:
633
- $form[ $k ] = apply_filters( 'um_sanitize_form_field', $form[ $k ], $field );
634
- break;
635
- case 'number':
636
- $form[ $k ] = (int) $form[ $k ];
637
- break;
638
- case 'textarea':
639
- if ( ! empty( $field['html'] ) || ( UM()->profile()->get_show_bio_key( $form ) === $k && UM()->options()->get( 'profile_show_html_bio' ) ) ) {
640
- $form[ $k ] = wp_kses_post( $form[ $k ] );
641
- } else {
642
- $form[ $k ] = sanitize_textarea_field( $form[ $k ] );
643
- }
644
- break;
645
- case 'url':
646
- $f = UM()->builtin()->get_a_field( $k );
647
-
648
- if ( array_key_exists( 'match', $f ) && array_key_exists( 'advanced', $f ) && 'social' === $f['advanced'] ) {
649
- $v = sanitize_text_field( $form[ $k ] );
650
-
651
- // Make a proper social link
652
- if ( ! empty( $v ) && ! strstr( $v, $f['match'] ) ) {
653
- $domain = trim( strtr( $f['match'], array(
654
- 'https://' => '',
655
- 'http://' => '',
656
- ) ), ' /' );
657
-
658
- if ( ! strstr( $v, $domain ) ) {
659
- $v = $f['match'] . $v;
660
- } else {
661
- $v = 'https://' . trim( strtr( $v, array(
662
- 'https://' => '',
663
- 'http://' => '',
664
- ) ), ' /' );
665
- }
666
- }
667
-
668
- $form[ $k ] = $v;
669
- } else {
670
- $form[ $k ] = esc_url_raw( $form[ $k ] );
671
- }
672
- break;
673
- case 'text':
674
- case 'select':
675
- case 'password':
676
- case 'image':
677
- case 'file':
678
- case 'date':
679
- case 'time':
680
- case 'rating':
681
- case 'googlemap':
682
- case 'youtube_video':
683
- case 'vimeo_video':
684
- case 'soundcloud_track':
685
- $form[ $k ] = sanitize_text_field( $form[ $k ] );
686
- break;
687
- case 'multiselect':
688
- case 'radio':
689
- case 'checkbox':
690
- $form[ $k ] = is_array( $form[ $k ] ) ? array_map( 'sanitize_text_field', $form[ $k ] ) : sanitize_text_field( $form[ $k ] );
691
- break;
692
- }
693
- }
694
- }
695
- }
696
- }
697
- }
698
- }
699
-
700
- return $form;
701
- }
702
-
703
-
704
- /**
705
- * Display form type as Title
706
- * @param string $mode
707
- * @param integer $post_id
708
- * @return string $output
709
- */
710
- public function display_form_type( $mode, $post_id ) {
711
- $output = null;
712
- switch ( $mode ) {
713
- case 'login':
714
- $output = __( 'Login', 'ultimate-member' );
715
- break;
716
- case 'profile':
717
- $output = __( 'Profile', 'ultimate-member' );
718
- break;
719
- case 'register':
720
- $output = __( 'Register', 'ultimate-member' );
721
- break;
722
- }
723
- return $output;
724
- }
725
-
726
-
727
- /**
728
- * Assigned roles to a form
729
- * @param integer $post_id
730
- * @return string $role
731
- */
732
- public function assigned_role( $post_id ) {
733
-
734
- $global_role = get_option( 'default_role' ); // WP Global settings
735
-
736
- $um_global_role = UM()->options()->get( 'register_role' ); // UM Settings Global settings
737
- if ( ! empty( $um_global_role ) ) {
738
- $global_role = $um_global_role; // Form Global settings
739
- }
740
-
741
- $mode = $this->form_type( $post_id );
742
-
743
- /**
744
- * @todo WPML integration to get role from original if it's empty
745
- */
746
- $use_custom = get_post_meta( $post_id, "_um_{$mode}_use_custom_settings", true );
747
- if ( $use_custom ) { // Custom Form settings
748
- $role = get_post_meta( $post_id, "_um_{$mode}_role", true );
749
- }
750
-
751
- if ( empty( $role ) ) { // custom role is default, return default role's slug
752
- $role = $global_role;
753
- }
754
-
755
- return $role;
756
- }
757
-
758
-
759
- /**
760
- * Get form type
761
- * @param integer $post_id
762
- * @return string
763
- */
764
- public function form_type( $post_id ) {
765
- $mode = get_post_meta( $post_id, '_um_mode', true );
766
- return $mode;
767
- }
768
-
769
-
770
- /**
771
- * Get custom field roles
772
- *
773
- * @param string $custom_fields serialized
774
- * @return bool|array roles
775
- */
776
- public function custom_field_roles( $custom_fields ) {
777
-
778
- $fields = maybe_unserialize( $custom_fields );
779
- if ( ! is_array( $fields ) ) {
780
- return false;
781
- }
782
-
783
- // role field
784
- global $wp_roles;
785
- $role_keys = array_map(
786
- function( $item ) {
787
- return 'um_' . $item;
788
- },
789
- get_option( 'um_roles', array() )
790
- );
791
- $exclude_roles = array_diff( array_keys( $wp_roles->roles ), array_merge( $role_keys, array( 'subscriber' ) ) );
792
-
793
- $roles = UM()->roles()->get_roles( false, $exclude_roles );
794
- $roles = array_map(
795
- function( $item ) {
796
- return html_entity_decode( $item, ENT_QUOTES );
797
- },
798
- $roles
799
- );
800
-
801
- foreach ( $fields as $field_key => $field_settings ) {
802
-
803
- if ( strstr( $field_key, 'role_' ) && is_array( $field_settings['options'] ) ) {
804
-
805
- if ( isset( $this->post_form['mode'] ) && 'profile' === $this->post_form['mode'] &&
806
- isset( $field_settings['editable'] ) && $field_settings['editable'] == 0 ) {
807
- continue;
808
- }
809
-
810
- if ( ! um_can_view_field( $field_settings ) ) {
811
- continue;
812
- }
813
-
814
- $intersected_options = array();
815
- foreach ( $field_settings['options'] as $key => $title ) {
816
- if ( false !== $search_key = array_search( $title, $roles ) ) {
817
- $intersected_options[ $search_key ] = $title;
818
- } elseif ( isset( $roles[ $key ] ) ) {
819
- $intersected_options[ $key ] = $title;
820
- }
821
- }
822
-
823
- // getting roles only from the first role fields
824
- return array_keys( $intersected_options );
825
- }
826
- }
827
-
828
- return false;
829
- }
830
- }
831
- }
 
 
 
 
 
 
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
+
543
+ /**
544
+ * UM hook
545
+ *
546
+ * @type action
547
+ * @title um_submit_form_errors_hook
548
+ * @description Action on submit form
549
+ * @input_vars
550
+ * [{"var":"$post","type":"int","desc":"Post data"}]
551
+ * @change_log
552
+ * ["Since: 2.0"]
553
+ * @usage add_action( 'um_submit_form_errors_hook', 'function_name', 10, 1 );
554
+ * @example
555
+ * <?php
556
+ * add_action( 'um_submit_form_errors_hook', 'my_submit_form_errors', 10, 1 );
557
+ * function my_submit_form_errors( $post ) {
558
+ * // your code here
559
+ * }
560
+ * ?>
561
+ */
562
+ do_action( 'um_submit_form_errors_hook', $this->post_form );
563
+ /**
564
+ * UM hook
565
+ *
566
+ * @type action
567
+ * @title um_submit_form_{$mode}
568
+ * @description Action on submit form
569
+ * @input_vars
570
+ * [{"var":"$post","type":"int","desc":"Post data"}]
571
+ * @change_log
572
+ * ["Since: 2.0"]
573
+ * @usage add_action( 'um_submit_form_{$mode}', 'function_name', 10, 1 );
574
+ * @example
575
+ * <?php
576
+ * add_action( 'um_submit_form_{$mode}', 'my_submit_form', 10, 1 );
577
+ * function my_submit_form( $post ) {
578
+ * // your code here
579
+ * }
580
+ * ?>
581
+ */
582
+ do_action( "um_submit_form_{$this->post_form['mode']}", $this->post_form );
583
+
584
+ }
585
+ }
586
+
587
+
588
+ /**
589
+ * Beautify form data
590
+ *
591
+ * @param array $form
592
+ *
593
+ * @return array $form
594
+ */
595
+ public function beautify( $form ) {
596
+ if ( isset( $form['form_id'] ) ) {
597
+ $this->form_suffix = '-' . $form['form_id'];
598
+ $this->processing = $form['form_id'];
599
+
600
+ foreach ( $form as $key => $value ) {
601
+ if ( strstr( $key, $this->form_suffix ) ) {
602
+ $a_key = str_replace( $this->form_suffix, '', $key );
603
+ $form[ $a_key ] = $value;
604
+ unset( $form[ $key ] );
605
+ }
606
+ }
607
+ }
608
+
609
+ return $form;
610
+ }
611
+
612
+
613
+ /**
614
+ * Beautify form data
615
+ *
616
+ * @param array $form
617
+ *
618
+ * @return array $form
619
+ */
620
+ public function sanitize( $form ) {
621
+
622
+ if ( isset( $form['form_id'] ) ) {
623
+ if ( isset( $this->form_data['custom_fields'] ) ) {
624
+ $custom_fields = maybe_unserialize( $this->form_data['custom_fields'] );
625
+
626
+ if ( is_array( $custom_fields ) ) {
627
+ foreach ( $custom_fields as $k => $field ) {
628
+
629
+ if ( isset( $field['type'] ) ) {
630
+ if ( isset( $form[ $k ] ) ) {
631
+
632
+ switch ( $field['type'] ) {
633
+ default:
634
+ $form[ $k ] = apply_filters( 'um_sanitize_form_field', $form[ $k ], $field );
635
+ break;
636
+ case 'number':
637
+ $form[ $k ] = (int) $form[ $k ];
638
+ break;
639
+ case 'textarea':
640
+ if ( ! empty( $field['html'] ) || ( UM()->profile()->get_show_bio_key( $form ) === $k && UM()->options()->get( 'profile_show_html_bio' ) ) ) {
641
+ $form[ $k ] = wp_kses_post( $form[ $k ] );
642
+ } else {
643
+ $form[ $k ] = sanitize_textarea_field( $form[ $k ] );
644
+ }
645
+ break;
646
+ case 'url':
647
+ $f = UM()->builtin()->get_a_field( $k );
648
+
649
+ if ( array_key_exists( 'match', $f ) && array_key_exists( 'advanced', $f ) && 'social' === $f['advanced'] ) {
650
+ $v = sanitize_text_field( $form[ $k ] );
651
+
652
+ // Make a proper social link
653
+ if ( ! empty( $v ) && ! strstr( $v, $f['match'] ) ) {
654
+ $domain = trim( strtr( $f['match'], array(
655
+ 'https://' => '',
656
+ 'http://' => '',
657
+ ) ), ' /' );
658
+
659
+ if ( ! strstr( $v, $domain ) ) {
660
+ $v = $f['match'] . $v;
661
+ } else {
662
+ $v = 'https://' . trim( strtr( $v, array(
663
+ 'https://' => '',
664
+ 'http://' => '',
665
+ ) ), ' /' );
666
+ }
667
+ }
668
+
669
+ $form[ $k ] = $v;
670
+ } else {
671
+ $form[ $k ] = esc_url_raw( $form[ $k ] );
672
+ }
673
+ break;
674
+ case 'password':
675
+ $form[ $k ] = trim( $form[ $k ] );
676
+ if ( array_key_exists( 'confirm_' . $k, $form ) ) {
677
+ $form[ 'confirm_' . $k ] = trim( $form[ 'confirm_' . $k ] );
678
+ }
679
+ break;
680
+ case 'text':
681
+ case 'select':
682
+ case 'image':
683
+ case 'file':
684
+ case 'date':
685
+ case 'time':
686
+ case 'rating':
687
+ case 'googlemap':
688
+ case 'youtube_video':
689
+ case 'vimeo_video':
690
+ case 'soundcloud_track':
691
+ $form[ $k ] = sanitize_text_field( $form[ $k ] );
692
+ break;
693
+ case 'multiselect':
694
+ case 'radio':
695
+ case 'checkbox':
696
+ $form[ $k ] = is_array( $form[ $k ] ) ? array_map( 'sanitize_text_field', $form[ $k ] ) : sanitize_text_field( $form[ $k ] );
697
+ break;
698
+ }
699
+ }
700
+ }
701
+ }
702
+ }
703
+ }
704
+ }
705
+
706
+ return $form;
707
+ }
708
+
709
+
710
+ /**
711
+ * Display form type as Title
712
+ * @param string $mode
713
+ * @param integer $post_id
714
+ * @return string $output
715
+ */
716
+ public function display_form_type( $mode, $post_id ) {
717
+ $output = null;
718
+ switch ( $mode ) {
719
+ case 'login':
720
+ $output = __( 'Login', 'ultimate-member' );
721
+ break;
722
+ case 'profile':
723
+ $output = __( 'Profile', 'ultimate-member' );
724
+ break;
725
+ case 'register':
726
+ $output = __( 'Register', 'ultimate-member' );
727
+ break;
728
+ }
729
+ return $output;
730
+ }
731
+
732
+
733
+ /**
734
+ * Assigned roles to a form
735
+ * @param integer $post_id
736
+ * @return string $role
737
+ */
738
+ public function assigned_role( $post_id ) {
739
+
740
+ $global_role = get_option( 'default_role' ); // WP Global settings
741
+
742
+ $um_global_role = UM()->options()->get( 'register_role' ); // UM Settings Global settings
743
+ if ( ! empty( $um_global_role ) ) {
744
+ $global_role = $um_global_role; // Form Global settings
745
+ }
746
+
747
+ $mode = $this->form_type( $post_id );
748
+
749
+ /**
750
+ * @todo WPML integration to get role from original if it's empty
751
+ */
752
+ $use_custom = get_post_meta( $post_id, "_um_{$mode}_use_custom_settings", true );
753
+ if ( $use_custom ) { // Custom Form settings
754
+ $role = get_post_meta( $post_id, "_um_{$mode}_role", true );
755
+ }
756
+
757
+ if ( empty( $role ) ) { // custom role is default, return default role's slug
758
+ $role = $global_role;
759
+ }
760
+
761
+ return $role;
762
+ }
763
+
764
+
765
+ /**
766
+ * Get form type
767
+ * @param integer $post_id
768
+ * @return string
769
+ */
770
+ public function form_type( $post_id ) {
771
+ $mode = get_post_meta( $post_id, '_um_mode', true );
772
+ return $mode;
773
+ }
774
+
775
+
776
+ /**
777
+ * Get custom field roles
778
+ *
779
+ * @param string $custom_fields serialized
780
+ * @return bool|array roles
781
+ */
782
+ public function custom_field_roles( $custom_fields ) {
783
+
784
+ $fields = maybe_unserialize( $custom_fields );
785
+ if ( ! is_array( $fields ) ) {
786
+ return false;
787
+ }
788
+
789
+ // role field
790
+ global $wp_roles;
791
+ $role_keys = array_map(
792
+ function( $item ) {
793
+ return 'um_' . $item;
794
+ },
795
+ get_option( 'um_roles', array() )
796
+ );
797
+ $exclude_roles = array_diff( array_keys( $wp_roles->roles ), array_merge( $role_keys, array( 'subscriber' ) ) );
798
+
799
+ $roles = UM()->roles()->get_roles( false, $exclude_roles );
800
+ $roles = array_map(
801
+ function( $item ) {
802
+ return html_entity_decode( $item, ENT_QUOTES );
803
+ },
804
+ $roles
805
+ );
806
+
807
+ foreach ( $fields as $field_key => $field_settings ) {
808
+
809
+ if ( strstr( $field_key, 'role_' ) && is_array( $field_settings['options'] ) ) {
810
+
811
+ if ( isset( $this->post_form['mode'] ) && 'profile' === $this->post_form['mode'] &&
812
+ isset( $field_settings['editable'] ) && $field_settings['editable'] == 0 ) {
813
+ continue;
814
+ }
815
+
816
+ if ( ! um_can_view_field( $field_settings ) ) {
817
+ continue;
818
+ }
819
+
820
+ $intersected_options = array();
821
+ foreach ( $field_settings['options'] as $key => $title ) {
822
+ if ( false !== $search_key = array_search( $title, $roles ) ) {
823
+ $intersected_options[ $search_key ] = $title;
824
+ } elseif ( isset( $roles[ $key ] ) ) {
825
+ $intersected_options[ $key ] = $title;
826
+ }
827
+ }
828
+
829
+ // getting roles only from the first role fields
830
+ return array_keys( $intersected_options );
831
+ }
832
+ }
833
+
834
+ return false;
835
+ }
836
+ }
837
+ }
includes/core/class-member-directory-meta.php CHANGED
@@ -1,864 +1,898 @@
1
- <?php
2
- namespace um\core;
3
-
4
-
5
- if ( ! defined( 'ABSPATH' ) ) exit;
6
-
7
-
8
- if ( ! class_exists( 'um\core\Member_Directory_Meta' ) ) {
9
-
10
-
11
- /**
12
- * Class Member_Directory_Meta
13
- * @package um\core
14
- */
15
- class Member_Directory_Meta extends Member_Directory {
16
-
17
-
18
- /**
19
- * @var string
20
- */
21
- var $joins = array();
22
- var $where_clauses = array();
23
-
24
- var $roles = array();
25
- var $roles_in_query = false;
26
-
27
- var $general_meta_joined = false;
28
-
29
- var $having = '';
30
- var $select = '';
31
- var $sql_limit = '';
32
- var $sql_order = '';
33
-
34
-
35
- /**
36
- * Member_Directory_Meta constructor.
37
- */
38
- function __construct() {
39
- parent::__construct();
40
-
41
- add_action( 'updated_user_meta', array( &$this, 'on_update_usermeta' ), 10, 4 );
42
- add_action( 'added_user_meta', array( &$this, 'on_update_usermeta' ), 10, 4 );
43
- add_action( 'deleted_user_meta', array( &$this, 'on_delete_usermeta' ), 10, 4 );
44
-
45
- add_action( 'um_add_new_field', array( &$this, 'on_new_field_added' ), 10, 2 );
46
- add_action( 'um_delete_custom_field', array( &$this, 'on_delete_custom_field' ), 10, 2 );
47
- }
48
-
49
-
50
- /**
51
- * Delete custom field and metakey from UM usermeta table
52
- *
53
- * @param $metakey
54
- * @param $args
55
- */
56
- function on_delete_custom_field( $metakey, $args ) {
57
- $metakeys = get_option( 'um_usermeta_fields', array() );
58
-
59
- if ( in_array( $metakey, $metakeys ) ) {
60
- unset( $metakeys[ array_search( $metakey, $metakeys ) ] );
61
-
62
- global $wpdb;
63
-
64
- $wpdb->delete(
65
- "{$wpdb->prefix}um_metadata",
66
- array(
67
- 'um_key' => $metakey
68
- ),
69
- array(
70
- '%s'
71
- )
72
- );
73
-
74
- update_option( 'um_usermeta_fields', array_values( $metakeys ) );
75
- }
76
-
77
- do_action( 'um_metadata_on_delete_custom_field', $metakeys, $metakey, $args );
78
- }
79
-
80
-
81
- /**
82
- * Add metakey to usermeta fields
83
- *
84
- * @param $metakey
85
- * @param $args
86
- */
87
- function on_new_field_added( $metakey, $args ) {
88
- $metakeys = get_option( 'um_usermeta_fields', array() );
89
-
90
- if ( ! in_array( $metakey, $metakeys ) ) {
91
- $metakeys[] = $metakey;
92
- update_option( 'um_usermeta_fields', array_values( $metakeys ) );
93
- }
94
-
95
- do_action( 'um_metadata_on_new_field_added', $metakeys, $metakey, $args );
96
- }
97
-
98
-
99
- /**
100
- * When you delete usermeta - remove row from um_metadata
101
- *
102
- * @param int|array $meta_ids
103
- * @param int $object_id
104
- * @param string $meta_key
105
- * @param mixed $_meta_value
106
- */
107
- function on_delete_usermeta( $meta_ids, $object_id, $meta_key, $_meta_value ) {
108
- $metakeys = get_option( 'um_usermeta_fields', array() );
109
- if ( ! in_array( $meta_key, $metakeys ) ) {
110
- return;
111
- }
112
-
113
- global $wpdb;
114
-
115
- $wpdb->delete(
116
- "{$wpdb->prefix}um_metadata",
117
- array(
118
- 'user_id' => $object_id,
119
- 'um_key' => $meta_key
120
- ),
121
- array(
122
- '%d',
123
- '%s'
124
- )
125
- );
126
- }
127
-
128
-
129
- /**
130
- * When you add/update usermeta - add/update row from um_metadata
131
- *
132
- * @param int $meta_id
133
- * @param int $object_id
134
- * @param string $meta_key
135
- * @param mixed $_meta_value
136
- */
137
- function on_update_usermeta( $meta_id, $object_id, $meta_key, $_meta_value ) {
138
-
139
- $metakeys = get_option( 'um_usermeta_fields', array() );
140
- if ( ! in_array( $meta_key, $metakeys ) ) {
141
- return;
142
- }
143
-
144
- global $wpdb;
145
-
146
- $result = $wpdb->get_var( $wpdb->prepare(
147
- "SELECT umeta_id
148
- FROM {$wpdb->prefix}um_metadata
149
- WHERE user_id = %d AND
150
- um_key = %s
151
- LIMIT 1",
152
- $object_id,
153
- $meta_key
154
- ) );
155
-
156
- if ( empty( $result ) ) {
157
- $wpdb->insert(
158
- "{$wpdb->prefix}um_metadata",
159
- array(
160
- 'user_id' => $object_id,
161
- 'um_key' => $meta_key,
162
- 'um_value' => maybe_serialize( $_meta_value ),
163
- ),
164
- array(
165
- '%d',
166
- '%s',
167
- '%s',
168
- )
169
- );
170
- } else {
171
- $wpdb->update(
172
- "{$wpdb->prefix}um_metadata",
173
- array(
174
- 'um_value' => maybe_serialize( $_meta_value ),
175
- ),
176
- array(
177
- 'umeta_id' => $result,
178
- ),
179
- array(
180
- '%s',
181
- ),
182
- array(
183
- '%d',
184
- )
185
- );
186
- }
187
- }
188
-
189
-
190
- /**
191
- * @param $directory_data
192
- * @param $field
193
- * @param $value
194
- * @param $i
195
- * @param bool $is_default
196
- */
197
- function handle_filter_query( $directory_data, $field, $value, $i, $is_default = false ) {
198
- global $wpdb;
199
-
200
- $join_slug = $is_default ? 'ummd' : 'umm' ;
201
-
202
- $blog_id = get_current_blog_id();
203
-
204
- switch ( $field ) {
205
- default:
206
-
207
- $filter_type = $this->filter_types[ $field ];
208
-
209
- /**
210
- * UM hook
211
- *
212
- * @type filter
213
- * @title um_query_args_{$field}__filter
214
- * @description Change field's query for search at Members Directory
215
- * @input_vars
216
- * [{"var":"$field_query","type":"array","desc":"Field query"}]
217
- * @change_log
218
- * ["Since: 2.0"]
219
- * @usage
220
- * <?php add_filter( 'um_query_args_{$field}__filter_meta', 'function_name', 10, 4 ); ?>
221
- * @example
222
- * <?php
223
- * add_filter( 'um_query_args_{$field}__filter_meta', 'my_query_args_filter', 10, 4 );
224
- * function my_query_args_filter( $field_query ) {
225
- * // your code here
226
- * return $field_query;
227
- * }
228
- * ?>
229
- */
230
- $skip_default = apply_filters( "um_query_args_{$field}__filter_meta", false, $this, $field, $value, $filter_type, $is_default );
231
-
232
- $skip_default = apply_filters( 'um_query_args_filter_global_meta', $skip_default, $this, $field, $value, $filter_type, $is_default );
233
-
234
- if ( ! $skip_default ) {
235
-
236
- switch ( $filter_type ) {
237
- default:
238
-
239
- do_action( "um_query_args_{$field}_{$filter_type}__filter_meta", $field, $value, $filter_type, $i, $is_default );
240
- break;
241
-
242
- case 'text':
243
-
244
- $this->joins[] = "LEFT JOIN {$wpdb->prefix}um_metadata {$join_slug}{$i} ON {$join_slug}{$i}.user_id = u.ID";
245
-
246
- $value = trim( stripslashes( $value ) );
247
-
248
- $compare = apply_filters( 'um_members_directory_filter_text', '=', $field );
249
- $value = apply_filters( 'um_members_directory_filter_text_meta_value', $value, $field );
250
-
251
- $this->where_clauses[] = $wpdb->prepare( "{$join_slug}{$i}.um_key = %s AND {$join_slug}{$i}.um_value {$compare} %s", $field, $value );
252
-
253
- if ( ! $is_default ) {
254
- $this->custom_filters_in_query[ $field ] = $value;
255
- }
256
-
257
- break;
258
-
259
- case 'select':
260
- if ( ! is_array( $value ) ) {
261
- $value = array( $value );
262
- }
263
-
264
- $this->joins[] = "LEFT JOIN {$wpdb->prefix}um_metadata {$join_slug}{$i} ON {$join_slug}{$i}.user_id = u.ID";
265
-
266
- $values_array = array();
267
- foreach ( $value as $single_val ) {
268
- $single_val = trim( stripslashes( $single_val ) );
269
-
270
- $values_array[] = $wpdb->prepare( "{$join_slug}{$i}.um_value LIKE %s", '%"' . $single_val . '"%' );
271
- $values_array[] = $wpdb->prepare( "{$join_slug}{$i}.um_value LIKE %s", '%' . serialize( (string) $single_val ) . '%' );
272
- $values_array[] = $wpdb->prepare( "{$join_slug}{$i}.um_value = %s", $single_val );
273
-
274
- if ( is_numeric( $single_val ) ) {
275
- $values_array[] = $wpdb->prepare( "{$join_slug}{$i}.um_value LIKE %s", '%' . serialize( (int) $single_val ) . '%' );
276
- }
277
- }
278
-
279
- $values = implode( ' OR ', $values_array );
280
-
281
- $this->where_clauses[] = $wpdb->prepare( "( {$join_slug}{$i}.um_key = %s AND ( {$values} ) )", $field );
282
-
283
- if ( ! $is_default ) {
284
- $this->custom_filters_in_query[ $field ] = $value;
285
- }
286
-
287
- break;
288
- case 'slider':
289
-
290
- $this->joins[] = "LEFT JOIN {$wpdb->prefix}um_metadata {$join_slug}{$i} ON {$join_slug}{$i}.user_id = u.ID";
291
-
292
- $min = min( $value );
293
- $max = max( $value );
294
-
295
- $this->where_clauses[] = $wpdb->prepare( "( {$join_slug}{$i}.um_key = %s AND {$join_slug}{$i}.um_value BETWEEN %d AND %d )", $field, $min, $max );
296
-
297
- if ( ! $is_default ) {
298
- $this->custom_filters_in_query[ $field ] = $value;
299
- }
300
-
301
- break;
302
- case 'datepicker':
303
-
304
- $offset = 0;
305
- if ( ! $is_default ) {
306
- if ( isset( $_POST['gmt_offset'] ) && is_numeric( $_POST['gmt_offset'] ) ) {
307
- $offset = (int) $_POST['gmt_offset'];
308
- }
309
- } else {
310
- $gmt_offset = get_post_meta( $directory_data['form_id'], '_um_search_filters_gmt', true );
311
- if ( is_numeric( $gmt_offset ) ) {
312
- $offset = $gmt_offset;
313
- }
314
- }
315
-
316
- $from_date = (int) min( $value ) + ( $offset * HOUR_IN_SECONDS ); // client time zone offset
317
- $to_date = (int) max( $value ) + ( $offset * HOUR_IN_SECONDS ) + DAY_IN_SECONDS - 1; // time 23:59
318
- $from_date = date( 'Y/m/d', $from_date );
319
- $to_date = date( 'Y/m/d', $to_date );
320
-
321
- $this->joins[] = "LEFT JOIN {$wpdb->prefix}um_metadata {$join_slug}{$i} ON {$join_slug}{$i}.user_id = u.ID";
322
-
323
- $this->where_clauses[] = $wpdb->prepare( "( {$join_slug}{$i}.um_key = %s AND {$join_slug}{$i}.um_value BETWEEN %s AND %s )", $field, $from_date, $to_date );
324
-
325
- if ( ! $is_default ) {
326
- $this->custom_filters_in_query[ $field ] = array( $from_date, $to_date );
327
- }
328
-
329
- break;
330
- case 'timepicker':
331
-
332
- $this->joins[] = "LEFT JOIN {$wpdb->prefix}um_metadata {$join_slug}{$i} ON {$join_slug}{$i}.user_id = u.ID";
333
- if ( $value[0] == $value[1] ) {
334
- $this->where_clauses[] = $wpdb->prepare( "( {$join_slug}{$i}.um_key = %s AND {$join_slug}{$i}.um_value = %s )", $field, $value[0] );
335
- } else {
336
- $this->where_clauses[] = $wpdb->prepare( "( {$join_slug}{$i}.um_key = %s AND CAST( {$join_slug}{$i}.um_value AS TIME ) BETWEEN %s AND %s )", $field, $value[0], $value[1] );
337
- }
338
-
339
- if ( ! $is_default ) {
340
- $this->custom_filters_in_query[ $field ] = $value;
341
- }
342
-
343
- break;
344
- }
345
-
346
- }
347
-
348
- break;
349
- case 'role':
350
- $value = array_map( 'strtolower', $value );
351
-
352
- if ( empty( $this->roles ) && ! is_multisite() ) {
353
- $this->joins[] = "LEFT JOIN {$wpdb->prefix}um_metadata umm_roles ON ( umm_roles.user_id = u.ID AND umm_roles.um_key = '" . $wpdb->get_blog_prefix( $blog_id ) . "capabilities' )";
354
- $this->roles = $value;
355
-
356
- $this->roles_in_query = true;
357
- }
358
-
359
- $roles_clauses = array();
360
- foreach ( $value as $role ) {
361
- $roles_clauses[] = $wpdb->prepare( "umm_roles.um_value LIKE %s", '%"' . $role . '"%' );
362
- }
363
-
364
- $this->where_clauses[] = '( ' . implode( ' OR ', $roles_clauses ) . ' )';
365
-
366
- if ( ! $is_default ) {
367
- $this->custom_filters_in_query[ $field ] = $value;
368
- }
369
-
370
- break;
371
- case 'birth_date':
372
-
373
- $from_date = date( 'Y/m/d', mktime( 0,0,0, date( 'm', time() ), date( 'd', time() ), date( 'Y', time() - min( $value ) * YEAR_IN_SECONDS ) ) );
374
- $to_date = date( 'Y/m/d', mktime( 0,0,0, date( 'm', time() ), date( 'd', time() ) + 1, date( 'Y', time() - ( max( $value ) + 1 ) * YEAR_IN_SECONDS ) ) );
375
-
376
- $this->joins[] = "LEFT JOIN {$wpdb->prefix}um_metadata {$join_slug}{$i} ON {$join_slug}{$i}.user_id = u.ID";
377
-
378
- $this->where_clauses[] = $wpdb->prepare( "( {$join_slug}{$i}.um_key = 'birth_date' AND {$join_slug}{$i}.um_value BETWEEN %s AND %s )", $to_date, $from_date );
379
-
380
- if ( ! $is_default ) {
381
- $this->custom_filters_in_query[ $field ] = array( $to_date, $from_date );
382
- }
383
-
384
- break;
385
- case 'user_registered':
386
-
387
- $offset = 0;
388
- if ( ! $is_default ) {
389
- if ( isset( $_POST['gmt_offset'] ) && is_numeric( $_POST['gmt_offset'] ) ) {
390
- $offset = (int) $_POST['gmt_offset'];
391
- }
392
- } else {
393
- $gmt_offset = get_post_meta( $directory_data['form_id'], '_um_search_filters_gmt', true );
394
- if ( is_numeric( $gmt_offset ) ) {
395
- $offset = (int) $gmt_offset;
396
- }
397
- }
398
-
399
- $from_date = date( 'Y-m-d H:s:i', strtotime( min( $value ) ) + $offset * HOUR_IN_SECONDS ); // client time zone offset
400
- $to_date = date( 'Y-m-d H:s:i', strtotime( max( $value ) ) + $offset * HOUR_IN_SECONDS + DAY_IN_SECONDS - 1 ); // time 23:59
401
-
402
- $this->where_clauses[] = $wpdb->prepare( "u.user_registered BETWEEN %s AND %s", $from_date, $to_date );
403
-
404
- if ( ! $is_default ) {
405
- $this->custom_filters_in_query[ $field ] = $value;
406
- }
407
-
408
- break;
409
- case 'last_login':
410
-
411
- $offset = 0;
412
- if ( ! $is_default ) {
413
- if ( isset( $_POST['gmt_offset'] ) && is_numeric( $_POST['gmt_offset'] ) ) {
414
- $offset = (int) $_POST['gmt_offset'];
415
- }
416
- } else {
417
- $gmt_offset = get_post_meta( $directory_data['form_id'], '_um_search_filters_gmt', true );
418
- if ( is_numeric( $gmt_offset ) ) {
419
- $offset = $gmt_offset;
420
- }
421
- }
422
-
423
- $from_date = (int) min( $value ) + ( $offset * HOUR_IN_SECONDS ); // client time zone offset
424
- $to_date = (int) max( $value ) + ( $offset * HOUR_IN_SECONDS ) + DAY_IN_SECONDS - 1; // time 23:59
425
-
426
- $this->joins[] = "LEFT JOIN {$wpdb->prefix}um_metadata {$join_slug}{$i} ON {$join_slug}{$i}.user_id = u.ID";
427
-
428
- $this->where_clauses[] = $wpdb->prepare( "( {$join_slug}{$i}.um_key = '_um_last_login' AND {$join_slug}{$i}.um_value BETWEEN %s AND %s )", $from_date, $to_date );
429
-
430
- if ( ! $is_default ) {
431
- $this->custom_filters_in_query[ $field ] = $value;
432
- }
433
-
434
- break;
435
- }
436
- }
437
-
438
-
439
- /**
440
- * Main Query function for getting members via AJAX
441
- */
442
- function ajax_get_members() {
443
- UM()->check_ajax_nonce();
444
-
445
- global $wpdb;
446
-
447
- $blog_id = get_current_blog_id();
448
-
449
- $directory_id = $this->get_directory_by_hash( $_POST['directory_id'] );
450
- $directory_data = UM()->query()->post_data( $directory_id );
451
-
452
- //predefined result for user without capabilities to see other members
453
- $this->predefined_no_caps( $directory_data );
454
-
455
- do_action( 'um_member_directory_before_query' );
456
-
457
- // Prepare for BIG SELECT query
458
- $wpdb->query( 'SET SQL_BIG_SELECTS=1' );
459
-
460
-
461
- if ( ! empty( $directory_data['show_these_users'] ) ) {
462
- $show_these_users = maybe_unserialize( $directory_data['show_these_users'] );
463
-
464
- if ( is_array( $show_these_users ) && ! empty( $show_these_users ) ) {
465
- $users_array = array();
466
- foreach ( $show_these_users as $username ) {
467
- if ( false !== ( $exists_id = username_exists( $username ) ) ) {
468
- $users_array[] = $exists_id;
469
- }
470
- }
471
-
472
- if ( ! empty( $users_array ) ) {
473
- $this->where_clauses[] = "u.ID IN ( '" . implode( "','", $users_array ) . "' )";
474
- }
475
- }
476
- }
477
-
478
- if ( ! empty( $directory_data['exclude_these_users'] ) ) {
479
- $exclude_these_users = maybe_unserialize( $directory_data['exclude_these_users'] );
480
-
481
- if ( is_array( $exclude_these_users ) && ! empty( $exclude_these_users ) ) {
482
- $users_array = array();
483
- foreach ( $exclude_these_users as $username ) {
484
- if ( false !== ( $exists_id = username_exists( $username ) ) ) {
485
- $users_array[] = $exists_id;
486
- }
487
- }
488
-
489
- if ( ! empty( $users_array ) ) {
490
- $this->where_clauses[] = "u.ID NOT IN ( '" . implode( "','", $users_array ) . "' )";
491
- }
492
- }
493
- }
494
-
495
-
496
- $profile_photo_where = '';
497
- if ( $directory_data['has_profile_photo'] == 1 ) {
498
- $profile_photo_where = " AND umm_general.um_value LIKE '%s:13:\"profile_photo\";b:1;%'";
499
- }
500
-
501
- $cover_photo_where = '';
502
- if ( $directory_data['has_cover_photo'] == 1 ) {
503
- $cover_photo_where = " AND umm_general.um_value LIKE '%s:11:\"cover_photo\";b:1;%'";
504
- }
505
-
506
- if ( ! UM()->roles()->um_user_can( 'can_edit_everyone' ) ) {
507
- if ( ! $this->general_meta_joined ) {
508
- $this->joins[] = "LEFT JOIN {$wpdb->prefix}um_metadata umm_general ON umm_general.user_id = u.ID";
509
- $this->general_meta_joined = true;
510
- }
511
- $this->where_clauses[] = "( umm_general.um_key = 'um_member_directory_data' AND
512
- umm_general.um_value LIKE '%s:14:\"account_status\";s:8:\"approved\";%' AND umm_general.um_value LIKE '%s:15:\"hide_in_members\";b:0;%'{$profile_photo_where}{$cover_photo_where} )";
513
- } else {
514
- if ( ! empty( $cover_photo_where ) || ! empty( $profile_photo_where ) ) {
515
- if ( ! $this->general_meta_joined ) {
516
- $this->joins[] = "LEFT JOIN {$wpdb->prefix}um_metadata umm_general ON umm_general.user_id = u.ID";
517
- $this->general_meta_joined = true;
518
- }
519
- $this->where_clauses[] = "( umm_general.um_key = 'um_member_directory_data'{$profile_photo_where}{$cover_photo_where} )";
520
- }
521
- }
522
-
523
- //$this->roles = array();
524
- if ( UM()->roles()->um_user_can( 'can_view_all' ) ) {
525
- $view_roles = um_user( 'can_view_roles' );
526
-
527
- if ( ! $view_roles ) {
528
- $view_roles = array();
529
- } else {
530
- $this->roles_in_query = true;
531
- }
532
-
533
- $this->roles = array_merge( $this->roles, maybe_unserialize( $view_roles ) );
534
- }
535
-
536
- if ( ! empty( $directory_data['roles'] ) ) {
537
- if ( ! empty( $this->roles ) ) {
538
- $this->roles = array_intersect( $this->roles, maybe_unserialize( $directory_data['roles'] ) );
539
- } else {
540
- $this->roles = array_merge( $this->roles, maybe_unserialize( $directory_data['roles'] ) );
541
- }
542
-
543
- $this->roles_in_query = true;
544
- }
545
-
546
- if ( ! empty( $this->roles ) ) {
547
- $this->joins[] = "LEFT JOIN {$wpdb->prefix}um_metadata umm_roles ON ( umm_roles.user_id = u.ID AND umm_roles.um_key = '" . $wpdb->get_blog_prefix( $blog_id ) . "capabilities' )";
548
-
549
- $roles_clauses = array();
550
- foreach ( $this->roles as $role ) {
551
- $roles_clauses[] = $wpdb->prepare( 'umm_roles.um_value LIKE %s', '%"' . $role . '"%' );
552
- }
553
-
554
- $this->where_clauses[] = '( ' . implode( ' OR ', $roles_clauses ) . ' )';
555
- } else {
556
-
557
- if ( ! $this->roles_in_query && is_multisite() ) {
558
- // select users who have capabilities for current blog
559
- $this->joins[] = "LEFT JOIN {$wpdb->prefix}um_metadata umm_roles ON ( umm_roles.user_id = u.ID AND umm_roles.um_key = '" . $wpdb->get_blog_prefix( $blog_id ) . "capabilities' )";
560
- $this->where_clauses[] = "umm_roles.um_value IS NOT NULL";
561
- } elseif ( $this->roles_in_query ) {
562
- $member_directory_response = apply_filters( 'um_ajax_get_members_response', array(
563
- 'pagination' => $this->calculate_pagination( $directory_data, 0 ),
564
- 'users' => array(),
565
- 'is_search' => $this->is_search,
566
- ), $directory_data );
567
-
568
- wp_send_json_success( $member_directory_response );
569
- }
570
- }
571
-
572
-
573
- if ( ! empty( $_POST['search'] ) ) {
574
- $search_line = trim( stripslashes( sanitize_text_field( $_POST['search'] ) ) );
575
-
576
- $searches = array();
577
- foreach ( $this->core_search_fields as $field ) {
578
- $searches[] = $wpdb->prepare( "u.{$field} LIKE %s", '%' . $search_line . '%' );
579
- }
580
-
581
- $core_search = implode( ' OR ', $searches );
582
-
583
- $this->joins[] = "LEFT JOIN {$wpdb->prefix}um_metadata umm_search ON umm_search.user_id = u.ID";
584
-
585
- $additional_search = apply_filters( 'um_member_directory_meta_general_search_meta_query', '', stripslashes( sanitize_text_field( $_POST['search'] ) ) );
586
-
587
- $search_like_string = apply_filters( 'um_member_directory_meta_search_like_type', '%' . $search_line . '%', $search_line );
588
-
589
- $this->where_clauses[] = $wpdb->prepare( "( umm_search.um_value = %s OR umm_search.um_value LIKE %s OR umm_search.um_value LIKE %s OR {$core_search}{$additional_search})", $search_line, $search_like_string, '%' . serialize( (string) $search_line ) . '%' );
590
-
591
- $this->is_search = true;
592
- }
593
-
594
-
595
- //filters
596
- $filter_query = array();
597
- if ( ! empty( $directory_data['search_fields'] ) ) {
598
- $search_filters = maybe_unserialize( $directory_data['search_fields'] );
599
- if ( ! empty( $search_filters ) && is_array( $search_filters ) ) {
600
- $filter_query = array_intersect_key( $_POST, array_flip( $search_filters ) );
601
- }
602
- }
603
-
604
- // added for user tags extension integration on individual tag page
605
- $ignore_empty_filters = apply_filters( 'um_member_directory_ignore_empty_filters', false );
606
-
607
- if ( ! empty( $filter_query ) || $ignore_empty_filters ) {
608
- $this->is_search = true;
609
-
610
- $i = 1;
611
- foreach ( $filter_query as $field => $value ) {
612
-
613
- $field = sanitize_text_field( $field );
614
- if ( is_array( $value ) ) {
615
- $value = array_map( 'sanitize_text_field', $value );
616
- } else {
617
- $value = sanitize_text_field( $value );
618
- }
619
-
620
- $attrs = UM()->fields()->get_field( $field );
621
- // skip private invisible fields
622
- if ( ! um_can_view_field( $attrs ) ) {
623
- continue;
624
- }
625
-
626
- $this->handle_filter_query( $directory_data, $field, $value, $i );
627
-
628
- $i++;
629
- }
630
- }
631
-
632
-
633
- //unable default filter in case if we select other filters in frontend filters
634
- //if ( empty( $this->custom_filters_in_query ) ) {
635
- $default_filters = array();
636
- if ( ! empty( $directory_data['search_filters'] ) ) {
637
- $default_filters = maybe_unserialize( $directory_data['search_filters'] );
638
- }
639
-
640
- if ( ! empty( $default_filters ) ) {
641
- $i = 1;
642
- foreach ( $default_filters as $field => $value ) {
643
-
644
- $this->handle_filter_query( $directory_data, $field, $value, $i, true );
645
-
646
- $i++;
647
- }
648
- }
649
- //}
650
-
651
- $order = 'ASC';
652
- $sortby = ! empty( $_POST['sorting'] ) ? sanitize_text_field( $_POST['sorting'] ) : $directory_data['sortby'];
653
- $sortby = ( $sortby == 'other' ) ? $directory_data['sortby_custom'] : $sortby;
654
-
655
- $custom_sort = array();
656
- if ( ! empty( $directory_data['sorting_fields'] ) ) {
657
- $sorting_fields = maybe_unserialize( $directory_data['sorting_fields'] );
658
- foreach ( $sorting_fields as $field ) {
659
- if ( is_array( $field ) ) {
660
- $field_keys = array_keys( $field );
661
- $custom_sort[] = $field_keys[0];
662
- }
663
- }
664
- }
665
-
666
- // handle sorting options
667
- // sort members by
668
- if ( $sortby == $directory_data['sortby_custom'] || in_array( $sortby, $custom_sort ) ) {
669
-
670
- $this->joins[] = "LEFT JOIN {$wpdb->prefix}um_metadata umm_sort ON ( umm_sort.user_id = u.ID AND umm_sort.um_key = '{$sortby}' )";
671
-
672
- $custom_sort_type = apply_filters( 'um_member_directory_custom_sorting_type', 'CHAR', $sortby, $directory_data );
673
-
674
- $this->sql_order = " ORDER BY CAST( umm_sort.um_value AS {$custom_sort_type} ) {$order} ";
675
-
676
- } elseif ( 'username' == $sortby ) {
677
-
678
- $this->sql_order = " ORDER BY u.user_login {$order} ";
679
-
680
- } elseif ( 'display_name' == $sortby ) {
681
-
682
- $display_name = UM()->options()->get( 'display_name' );
683
- if ( $display_name == 'username' ) {
684
-
685
- $this->sql_order = " ORDER BY u.user_login {$order} ";
686
-
687
- } else {
688
-
689
- $this->joins[] = "LEFT JOIN {$wpdb->prefix}um_metadata umm_sort ON ( umm_sort.user_id = u.ID AND umm_sort.um_key = 'full_name' )";
690
-
691
- $this->sql_order = " ORDER BY CAST( umm_sort.um_value AS CHAR ) {$order}, u.display_name {$order} ";
692
-
693
- }
694
-
695
- } elseif ( in_array( $sortby, array( 'last_name', 'first_name', 'nickname' ) ) ) {
696
-
697
- $this->joins[] = "LEFT JOIN {$wpdb->prefix}um_metadata umm_sort ON ( umm_sort.user_id = u.ID AND umm_sort.um_key = '{$sortby}' )";
698
-
699
- $this->sql_order = " ORDER BY CAST( umm_sort.um_value AS CHAR ) {$order} ";
700
-
701
- } elseif ( $sortby == 'last_login' ) {
702
-
703
- $this->joins[] = "LEFT JOIN {$wpdb->prefix}um_metadata umm_sort ON ( umm_sort.user_id = u.ID AND umm_sort.um_key = '_um_last_login' )";
704
-
705
- $this->sql_order = " ORDER BY CAST( umm_sort.um_value AS SIGNED ) DESC ";
706
-
707
- } elseif ( $sortby == 'last_first_name' ) {
708
-
709
- $this->joins[] = "LEFT JOIN {$wpdb->prefix}um_metadata umm_sort ON ( umm_sort.user_id = u.ID AND umm_sort.um_key = 'last_name' )";
710
- $this->joins[] = "LEFT JOIN {$wpdb->prefix}um_metadata umm_sort2 ON ( umm_sort2.user_id = u.ID AND umm_sort2.um_key = 'first_name' )";
711
-
712
- $this->sql_order = " ORDER BY CAST( umm_sort.um_value AS CHAR ) ASC, CAST( umm_sort2.um_value AS CHAR ) ASC ";
713
-
714
- } elseif ( $sortby == 'random' ) {
715
-
716
- if ( um_is_session_started() === false ) {
717
- @session_start();
718
- }
719
-
720
- // Reset seed on load of initial
721
- if ( empty( $_REQUEST['directory_id'] ) && isset( $_SESSION['um_member_directory_seed'] ) ) {
722
- unset( $_SESSION['um_member_directory_seed'] );
723
- }
724
-
725
- // Get seed from session variable if it exists
726
- $seed = false;
727
- if ( isset( $_SESSION['um_member_directory_seed'] ) ) {
728
- $seed = $_SESSION['um_member_directory_seed'];
729
- }
730
-
731
- // Set new seed if none exists
732
- if ( ! $seed ) {
733
- $seed = rand();
734
- $_SESSION['um_member_directory_seed'] = $seed;
735
- }
736
-
737
- $this->sql_order = 'ORDER BY RAND(' . $seed . ')';
738
-
739
- } else {
740
-
741
- if ( strstr( $sortby, '_desc' ) ) {
742
- $sortby = str_replace( '_desc', '', $sortby );
743
- $order = 'DESC';
744
- }
745
-
746
- if ( strstr( $sortby, '_asc' ) ) {
747
- $sortby = str_replace( '_asc', '', $sortby );
748
- $order = 'ASC';
749
- }
750
-
751
- $metakeys = get_option( 'um_usermeta_fields', array() );
752
- if ( false !== array_search( $sortby, $metakeys ) ) {
753
- $this->joins[] = "LEFT JOIN {$wpdb->prefix}um_metadata umm_sort ON ( umm_sort.user_id = u.ID AND umm_sort.um_key = '{$sortby}' )";
754
- $this->sql_order = " ORDER BY CAST( umm_sort.um_value AS CHAR ) {$order} ";
755
- } else {
756
- $this->sql_order = " ORDER BY u.{$sortby} {$order} ";
757
- }
758
- }
759
-
760
- $this->sql_order = apply_filters( 'um_modify_sortby_parameter_meta', $this->sql_order, $sortby );
761
-
762
-
763
- $profiles_per_page = $directory_data['profiles_per_page'];
764
- if ( UM()->mobile()->isMobile() && isset( $directory_data['profiles_per_page_mobile'] ) ) {
765
- $profiles_per_page = $directory_data['profiles_per_page_mobile'];
766
- }
767
-
768
- $query_number = ( ! empty( $directory_data['max_users'] ) && $directory_data['max_users'] <= $profiles_per_page ) ? $directory_data['max_users'] : $profiles_per_page;
769
- $query_paged = ! empty( $_POST['page'] ) ? absint( $_POST['page'] ) : 1;
770
-
771
- $number = $query_number;
772
- if ( ! empty( $directory_data['max_users'] ) && $query_paged*$query_number > $directory_data['max_users'] ) {
773
- $number = ( $query_paged*$query_number - ( $query_paged*$query_number - $directory_data['max_users'] ) ) % $query_number;
774
- }
775
-
776
- // limit
777
- if ( isset( $query_number ) && $query_number > 0 ) {
778
- $this->sql_limit .= $wpdb->prepare( 'LIMIT %d, %d', $query_number * ( $query_paged - 1 ), $number );
779
- }
780
-
781
- do_action( 'um_pre_users_query', $this, $directory_data, $sortby );
782
-
783
- $sql_join = implode( ' ', $this->joins );
784
- $sql_where = implode( ' AND ', $this->where_clauses );
785
- $sql_where = ! empty( $sql_where ) ? 'AND ' . $sql_where : '';
786
-
787
- global $wpdb;
788
-
789
- /*
790
- *
791
- * SQL_CALC_FOUND_ROWS is deprecated as of MySQL 8.0.17
792
- * https://core.trac.wordpress.org/ticket/47280
793
- *
794
- * */
795
- $user_ids = $wpdb->get_col(
796
- "SELECT SQL_CALC_FOUND_ROWS DISTINCT u.ID
797
- {$this->select}
798
- FROM {$wpdb->users} AS u
799
- {$sql_join}
800
- WHERE 1=1 {$sql_where}
801
- {$this->having}
802
- {$this->sql_order}
803
- {$this->sql_limit}"
804
- );
805
-
806
- $query = array(
807
- 'select' => $this->select,
808
- 'sql_where' => $sql_where,
809
- 'having' => $this->having,
810
- 'sql_limit' => $this->sql_limit,
811
- );
812
-
813
- $total_users = (int) $wpdb->get_var( 'SELECT FOUND_ROWS()' );
814
-
815
- /**
816
- * UM hook
817
- *
818
- * @type filter
819
- * @title um_prepare_user_results_array_meta
820
- * @description Extend member directory query result
821
- * @input_vars
822
- * [{"var":"$result","type":"array","desc":"Members Query Result"}]
823
- * @change_log
824
- * ["Since: 2.0"]
825
- * @usage
826
- * <?php add_filter( 'um_prepare_user_results_array', 'function_name', 10, 2 ); ?>
827
- * @example
828
- * <?php
829
- * add_filter( 'um_prepare_user_results_array', 'my_prepare_user_results', 10, 2 );
830
- * function my_prepare_user_results( $user_ids, $query ) {
831
- * // your code here
832
- * return $user_ids;
833
- * }
834
- * ?>
835
- */
836
- $user_ids = apply_filters( 'um_prepare_user_results_array_meta', $user_ids, $query );
837
-
838
- $pagination_data = $this->calculate_pagination( $directory_data, $total_users );
839
-
840
- $sizes = UM()->options()->get( 'cover_thumb_sizes' );
841
-
842
- $this->cover_size = UM()->mobile()->isTablet() ? $sizes[1] : end( $sizes );
843
-
844
- $avatar_size = UM()->options()->get( 'profile_photosize' );
845
- $this->avatar_size = str_replace( 'px', '', $avatar_size );
846
-
847
- $users = array();
848
- foreach ( $user_ids as $user_id ) {
849
- $users[] = $this->build_user_card_data( $user_id, $directory_data );
850
- }
851
-
852
- um_reset_user();
853
- // end of user card
854
-
855
- $member_directory_response = apply_filters( 'um_ajax_get_members_response', array(
856
- 'pagination' => $pagination_data,
857
- 'users' => $users,
858
- 'is_search' => $this->is_search,
859
- ), $directory_data );
860
-
861
- wp_send_json_success( $member_directory_response );
862
- }
863
- }
864
- }
1
+ <?php
2
+ namespace um\core;
3
+
4
+
5
+ if ( ! defined( 'ABSPATH' ) ) exit;
6
+
7
+
8
+ if ( ! class_exists( 'um\core\Member_Directory_Meta' ) ) {
9
+
10
+
11
+ /**
12
+ * Class Member_Directory_Meta
13
+ * @package um\core
14
+ */
15
+ class Member_Directory_Meta extends Member_Directory {
16
+
17
+
18
+ /**
19
+ * @var string
20
+ */
21
+ var $joins = array();
22
+ var $where_clauses = array();
23
+
24
+ var $roles = array();
25
+ var $roles_in_query = false;
26
+
27
+ var $general_meta_joined = false;
28
+
29
+ var $having = '';
30
+ var $select = '';
31
+ var $sql_limit = '';
32
+ var $sql_order = '';
33
+
34
+
35
+ /**
36
+ * Member_Directory_Meta constructor.
37
+ */
38
+ function __construct() {
39
+ parent::__construct();
40
+
41
+ add_action( 'updated_user_meta', array( &$this, 'on_update_usermeta' ), 10, 4 );
42
+ add_action( 'added_user_meta', array( &$this, 'on_update_usermeta' ), 10, 4 );
43
+ add_action( 'deleted_user_meta', array( &$this, 'on_delete_usermeta' ), 10, 4 );
44
+
45
+ add_action( 'um_add_new_field', array( &$this, 'on_new_field_added' ), 10, 2 );
46
+ add_action( 'um_delete_custom_field', array( &$this, 'on_delete_custom_field' ), 10, 2 );
47
+ }
48
+
49
+
50
+ /**
51
+ * Delete custom field and metakey from UM usermeta table
52
+ *
53
+ * @param $metakey
54
+ * @param $args
55
+ */
56
+ function on_delete_custom_field( $metakey, $args ) {
57
+ $metakeys = get_option( 'um_usermeta_fields', array() );
58
+
59
+ if ( in_array( $metakey, $metakeys ) ) {
60
+ unset( $metakeys[ array_search( $metakey, $metakeys ) ] );
61
+
62
+ global $wpdb;
63
+
64
+ $wpdb->delete(
65
+ "{$wpdb->prefix}um_metadata",
66
+ array(
67
+ 'um_key' => $metakey
68
+ ),
69
+ array(
70
+ '%s'
71
+ )
72
+ );
73
+
74
+ update_option( 'um_usermeta_fields', array_values( $metakeys ) );
75
+ }
76
+
77
+ do_action( 'um_metadata_on_delete_custom_field', $metakeys, $metakey, $args );
78
+ }
79
+
80
+
81
+ /**
82
+ * Add metakey to usermeta fields
83
+ *
84
+ * @param $metakey
85
+ * @param $args
86
+ */
87
+ function on_new_field_added( $metakey, $args ) {
88
+ $metakeys = get_option( 'um_usermeta_fields', array() );
89
+
90
+ if ( ! in_array( $metakey, $metakeys ) ) {
91
+ $metakeys[] = $metakey;
92
+ update_option( 'um_usermeta_fields', array_values( $metakeys ) );
93
+ }
94
+
95
+ do_action( 'um_metadata_on_new_field_added', $metakeys, $metakey, $args );
96
+ }
97
+
98
+
99
+ /**
100
+ * When you delete usermeta - remove row from um_metadata
101
+ *
102
+ * @param int|array $meta_ids
103
+ * @param int $object_id
104
+ * @param string $meta_key
105
+ * @param mixed $_meta_value
106
+ */
107
+ function on_delete_usermeta( $meta_ids, $object_id, $meta_key, $_meta_value ) {
108
+ $metakeys = get_option( 'um_usermeta_fields', array() );
109
+ if ( ! in_array( $meta_key, $metakeys ) ) {
110
+ return;
111
+ }
112
+
113
+ global $wpdb;
114
+
115
+ $wpdb->delete(
116
+ "{$wpdb->prefix}um_metadata",
117
+ array(
118
+ 'user_id' => $object_id,
119
+ 'um_key' => $meta_key
120
+ ),
121
+ array(
122
+ '%d',
123
+ '%s'
124
+ )
125
+ );
126
+ }
127
+
128
+
129
+ /**
130
+ * When you add/update usermeta - add/update row from um_metadata
131
+ *
132
+ * @param int $meta_id
133
+ * @param int $object_id
134
+ * @param string $meta_key
135
+ * @param mixed $_meta_value
136
+ */
137
+ function on_update_usermeta( $meta_id, $object_id, $meta_key, $_meta_value ) {
138
+
139
+ $metakeys = get_option( 'um_usermeta_fields', array() );
140
+ if ( ! in_array( $meta_key, $metakeys ) ) {
141
+ return;
142
+ }
143
+
144
+ global $wpdb;
145
+
146
+ $result = $wpdb->get_var( $wpdb->prepare(
147
+ "SELECT umeta_id
148
+ FROM {$wpdb->prefix}um_metadata
149
+ WHERE user_id = %d AND
150
+ um_key = %s
151
+ LIMIT 1",
152
+ $object_id,
153
+ $meta_key
154
+ ) );
155
+
156
+ if ( empty( $result ) ) {
157
+ $wpdb->insert(
158
+ "{$wpdb->prefix}um_metadata",
159
+ array(
160
+ 'user_id' => $object_id,
161
+ 'um_key' => $meta_key,
162
+ 'um_value' => maybe_serialize( $_meta_value ),
163
+ ),
164
+ array(
165
+ '%d',
166
+ '%s',
167
+ '%s',
168
+ )
169
+ );
170
+ } else {
171
+ $wpdb->update(
172
+ "{$wpdb->prefix}um_metadata",
173
+ array(
174
+ 'um_value' => maybe_serialize( $_meta_value ),
175
+ ),
176
+ array(
177
+ 'umeta_id' => $result,
178
+ ),
179
+ array(
180
+ '%s',
181
+ ),
182
+ array(
183
+ '%d',
184
+ )
185
+ );
186
+ }
187
+ }
188
+
189
+
190
+ /**
191
+ * @param $directory_data
192
+ * @param $field
193
+ * @param $value
194
+ * @param $i
195
+ * @param bool $is_default
196
+ */
197
+ function handle_filter_query( $directory_data, $field, $value, $i, $is_default = false ) {
198
+ global $wpdb;
199
+
200
+ $join_slug = $is_default ? 'ummd' : 'umm' ;
201
+
202
+ $blog_id = get_current_blog_id();
203
+
204
+ switch ( $field ) {
205
+ default:
206
+
207
+ $filter_type = $this->filter_types[ $field ];
208
+
209
+ /**
210
+ * UM hook
211
+ *
212
+ * @type filter
213
+ * @title um_query_args_{$field}__filter
214
+ * @description Change field's query for search at Members Directory
215
+ * @input_vars
216
+ * [{"var":"$field_query","type":"array","desc":"Field query"}]
217
+ * @change_log
218
+ * ["Since: 2.0"]
219
+ * @usage
220
+ * <?php add_filter( 'um_query_args_{$field}__filter_meta', 'function_name', 10, 4 ); ?>
221
+ * @example
222
+ * <?php
223
+ * add_filter( 'um_query_args_{$field}__filter_meta', 'my_query_args_filter', 10, 4 );
224
+ * function my_query_args_filter( $field_query ) {
225
+ * // your code here
226
+ * return $field_query;
227
+ * }
228
+ * ?>
229
+ */
230
+ $skip_default = apply_filters( "um_query_args_{$field}__filter_meta", false, $this, $field, $value, $filter_type, $is_default );
231
+
232
+ $skip_default = apply_filters( 'um_query_args_filter_global_meta', $skip_default, $this, $field, $value, $filter_type, $is_default );
233
+
234
+ if ( ! $skip_default ) {
235
+
236
+ switch ( $filter_type ) {
237
+ default:
238
+
239
+ do_action( "um_query_args_{$field}_{$filter_type}__filter_meta", $field, $value, $filter_type, $i, $is_default );
240
+ break;
241
+
242
+ case 'text':
243
+
244
+ $this->joins[] = "LEFT JOIN {$wpdb->prefix}um_metadata {$join_slug}{$i} ON {$join_slug}{$i}.user_id = u.ID";
245
+
246
+ $value = trim( stripslashes( $value ) );
247
+
248
+ $compare = apply_filters( 'um_members_directory_filter_text', '=', $field );
249
+ $value = apply_filters( 'um_members_directory_filter_text_meta_value', $value, $field );
250
+
251
+ $this->where_clauses[] = $wpdb->prepare( "{$join_slug}{$i}.um_key = %s AND {$join_slug}{$i}.um_value {$compare} %s", $field, $value );
252
+
253
+ if ( ! $is_default ) {
254
+ $this->custom_filters_in_query[ $field ] = $value;
255
+ }
256
+
257
+ break;
258
+
259
+ case 'select':
260
+ if ( ! is_array( $value ) ) {
261
+ $value = array( $value );
262
+ }
263
+
264
+ $this->joins[] = "LEFT JOIN {$wpdb->prefix}um_metadata {$join_slug}{$i} ON {$join_slug}{$i}.user_id = u.ID";
265
+
266
+ $values_array = array();
267
+ foreach ( $value as $single_val ) {
268
+ $single_val = trim( stripslashes( $single_val ) );
269
+
270
+ $values_array[] = $wpdb->prepare( "{$join_slug}{$i}.um_value LIKE %s", '%"' . $single_val . '"%' );
271
+ $values_array[] = $wpdb->prepare( "{$join_slug}{$i}.um_value LIKE %s", '%' . serialize( (string) $single_val ) . '%' );
272
+ $values_array[] = $wpdb->prepare( "{$join_slug}{$i}.um_value = %s", $single_val );
273
+
274
+ if ( is_numeric( $single_val ) ) {
275
+ $values_array[] = $wpdb->prepare( "{$join_slug}{$i}.um_value LIKE %s", '%' . serialize( (int) $single_val ) . '%' );
276
+ }
277
+ }
278
+
279
+ $values = implode( ' OR ', $values_array );
280
+
281
+ $this->where_clauses[] = $wpdb->prepare( "( {$join_slug}{$i}.um_key = %s AND ( {$values} ) )", $field );
282
+
283
+ if ( ! $is_default ) {
284
+ $this->custom_filters_in_query[ $field ] = $value;
285
+ }
286
+
287
+ break;
288
+ case 'slider':
289
+
290
+ $this->joins[] = "LEFT JOIN {$wpdb->prefix}um_metadata {$join_slug}{$i} ON {$join_slug}{$i}.user_id = u.ID";
291
+
292
+ $min = min( $value );
293
+ $max = max( $value );
294
+
295
+ $this->where_clauses[] = $wpdb->prepare( "( {$join_slug}{$i}.um_key = %s AND {$join_slug}{$i}.um_value BETWEEN %d AND %d )", $field, $min, $max );
296
+
297
+ if ( ! $is_default ) {
298
+ $this->custom_filters_in_query[ $field ] = $value;
299
+ }
300
+
301
+ break;
302
+ case 'datepicker':
303
+
304
+ $offset = 0;
305
+ if ( ! $is_default ) {
306
+ if ( isset( $_POST['gmt_offset'] ) && is_numeric( $_POST['gmt_offset'] ) ) {
307
+ $offset = (int) $_POST['gmt_offset'];
308
+ }
309
+ } else {
310
+ $gmt_offset = get_post_meta( $directory_data['form_id'], '_um_search_filters_gmt', true );
311
+ if ( is_numeric( $gmt_offset ) ) {
312
+ $offset = $gmt_offset;
313
+ }
314
+ }
315
+
316
+ $from_date = (int) min( $value ) + ( $offset * HOUR_IN_SECONDS ); // client time zone offset
317
+ $to_date = (int) max( $value ) + ( $offset * HOUR_IN_SECONDS ) + DAY_IN_SECONDS - 1; // time 23:59
318
+ $from_date = date( 'Y/m/d', $from_date );
319
+ $to_date = date( 'Y/m/d', $to_date );
320
+
321
+ $this->joins[] = "LEFT JOIN {$wpdb->prefix}um_metadata {$join_slug}{$i} ON {$join_slug}{$i}.user_id = u.ID";
322
+
323
+ $this->where_clauses[] = $wpdb->prepare( "( {$join_slug}{$i}.um_key = %s AND {$join_slug}{$i}.um_value BETWEEN %s AND %s )", $field, $from_date, $to_date );
324
+
325
+ if ( ! $is_default ) {
326
+ $this->custom_filters_in_query[ $field ] = array( $from_date, $to_date );
327
+ }
328
+
329
+ break;
330
+ case 'timepicker':
331
+
332
+ $this->joins[] = "LEFT JOIN {$wpdb->prefix}um_metadata {$join_slug}{$i} ON {$join_slug}{$i}.user_id = u.ID";
333
+ if ( $value[0] == $value[1] ) {
334
+ $this->where_clauses[] = $wpdb->prepare( "( {$join_slug}{$i}.um_key = %s AND {$join_slug}{$i}.um_value = %s )", $field, $value[0] );
335
+ } else {
336
+ $this->where_clauses[] = $wpdb->prepare( "( {$join_slug}{$i}.um_key = %s AND CAST( {$join_slug}{$i}.um_value AS TIME ) BETWEEN %s AND %s )", $field, $value[0], $value[1] );
337
+ }
338
+
339
+ if ( ! $is_default ) {
340
+ $this->custom_filters_in_query[ $field ] = $value;
341
+ }
342
+
343
+ break;
344
+ }
345
+
346
+ }
347
+
348
+ break;
349
+ case 'role':
350
+ $value = array_map( 'strtolower', $value );
351
+
352
+ if ( empty( $this->roles ) && ! is_multisite() ) {
353
+ $this->joins[] = "LEFT JOIN {$wpdb->prefix}um_metadata umm_roles ON ( umm_roles.user_id = u.ID AND umm_roles.um_key = '" . $wpdb->get_blog_prefix( $blog_id ) . "capabilities' )";
354
+ $this->roles = $value;
355
+
356
+ $this->roles_in_query = true;
357
+ }
358
+
359
+ $roles_clauses = array();
360
+ foreach ( $value as $role ) {
361
+ $roles_clauses[] = $wpdb->prepare( "umm_roles.um_value LIKE %s", '%"' . $role . '"%' );
362
+ }
363
+
364
+ $this->where_clauses[] = '( ' . implode( ' OR ', $roles_clauses ) . ' )';
365
+
366
+ if ( ! $is_default ) {
367
+ $this->custom_filters_in_query[ $field ] = $value;
368
+ }
369
+
370
+ break;
371
+ case 'birth_date':
372
+
373
+ $from_date = date( 'Y/m/d', mktime( 0,0,0, date( 'm', time() ), date( 'd', time() ), date( 'Y', time() - min( $value ) * YEAR_IN_SECONDS ) ) );
374
+ $to_date = date( 'Y/m/d', mktime( 0,0,0, date( 'm', time() ), date( 'd', time() ) + 1, date( 'Y', time() - ( max( $value ) + 1 ) * YEAR_IN_SECONDS ) ) );
375
+
376
+ $this->joins[] = "LEFT JOIN {$wpdb->prefix}um_metadata {$join_slug}{$i} ON {$join_slug}{$i}.user_id = u.ID";
377
+
378
+ $this->where_clauses[] = $wpdb->prepare( "( {$join_slug}{$i}.um_key = 'birth_date' AND {$join_slug}{$i}.um_value BETWEEN %s AND %s )", $to_date, $from_date );
379
+
380
+ if ( ! $is_default ) {
381
+ $this->custom_filters_in_query[ $field ] = array( $to_date, $from_date );
382
+ }
383
+
384
+ break;
385
+ case 'user_registered':
386
+
387
+ $offset = 0;
388
+ if ( ! $is_default ) {
389
+ if ( isset( $_POST['gmt_offset'] ) && is_numeric( $_POST['gmt_offset'] ) ) {
390
+ $offset = (int) $_POST['gmt_offset'];
391
+ }
392
+ } else {
393
+ $gmt_offset = get_post_meta( $directory_data['form_id'], '_um_search_filters_gmt', true );
394
+ if ( is_numeric( $gmt_offset ) ) {
395
+ $offset = (int) $gmt_offset;
396
+ }
397
+ }
398
+
399
+ $from_date = date( 'Y-m-d H:s:i', strtotime( min( $value ) ) + $offset * HOUR_IN_SECONDS ); // client time zone offset
400
+ $to_date = date( 'Y-m-d H:s:i', strtotime( max( $value ) ) + $offset * HOUR_IN_SECONDS + DAY_IN_SECONDS - 1 ); // time 23:59
401
+
402
+ $this->where_clauses[] = $wpdb->prepare( "u.user_registered BETWEEN %s AND %s", $from_date, $to_date );
403
+
404
+ if ( ! $is_default ) {
405
+ $this->custom_filters_in_query[ $field ] = $value;
406
+ }
407
+
408
+ break;
409
+ case 'last_login':
410
+
411
+ $offset = 0;
412
+ if ( ! $is_default ) {
413
+ if ( isset( $_POST['gmt_offset'] ) && is_numeric( $_POST['gmt_offset'] ) ) {
414
+ $offset = (int) $_POST['gmt_offset'];
415
+ }
416
+ } else {
417
+ $gmt_offset = get_post_meta( $directory_data['form_id'], '_um_search_filters_gmt', true );
418
+ if ( is_numeric( $gmt_offset ) ) {
419
+ $offset = $gmt_offset;
420
+ }
421
+ }
422
+
423
+ $from_date = (int) min( $value ) + ( $offset * HOUR_IN_SECONDS ); // client time zone offset
424
+ $to_date = (int) max( $value ) + ( $offset * HOUR_IN_SECONDS ) + DAY_IN_SECONDS - 1; // time 23:59
425
+
426
+ $this->joins[] = "LEFT JOIN {$wpdb->prefix}um_metadata {$join_slug}{$i} ON {$join_slug}{$i}.user_id = u.ID";
427
+
428
+ $this->where_clauses[] = $wpdb->prepare( "( {$join_slug}{$i}.um_key = '_um_last_login' AND {$join_slug}{$i}.um_value BETWEEN %s AND %s )", $from_date, $to_date );
429
+
430
+ if ( ! $is_default ) {
431
+ $this->custom_filters_in_query[ $field ] = $value;
432
+ }
433
+
434
+ break;
435
+ }
436
+ }
437
+
438
+
439
+ /**
440
+ * Main Query function for getting members via AJAX
441
+ */
442
+ function ajax_get_members() {
443
+ UM()->check_ajax_nonce();
444
+
445
+ global $wpdb;
446
+
447
+ $blog_id = get_current_blog_id();
448
+
449
+ $directory_id = $this->get_directory_by_hash( $_POST['directory_id'] );
450
+ $directory_data = UM()->query()->post_data( $directory_id );
451
+
452
+ //predefined result for user without capabilities to see other members
453
+ $this->predefined_no_caps( $directory_data );
454
+
455
+ do_action( 'um_member_directory_before_query' );
456
+
457
+ // Prepare for BIG SELECT query
458
+ $wpdb->query( 'SET SQL_BIG_SELECTS=1' );
459
+
460
+
461
+ if ( ! empty( $directory_data['show_these_users'] ) ) {
462
+ $show_these_users = maybe_unserialize( $directory_data['show_these_users'] );
463
+
464
+ if ( is_array( $show_these_users ) && ! empty( $show_these_users ) ) {
465
+ $users_array = array();
466
+ foreach ( $show_these_users as $username ) {
467
+ if ( false !== ( $exists_id = username_exists( $username ) ) ) {
468
+ $users_array[] = $exists_id;
469
+ }
470
+ }
471
+
472
+ if ( ! empty( $users_array ) ) {
473
+ $this->where_clauses[] = "u.ID IN ( '" . implode( "','", $users_array ) . "' )";
474
+ }
475
+ }
476
+ }
477
+
478
+ if ( ! empty( $directory_data['exclude_these_users'] ) ) {
479
+ $exclude_these_users = maybe_unserialize( $directory_data['exclude_these_users'] );
480
+
481
+ if ( is_array( $exclude_these_users ) && ! empty( $exclude_these_users ) ) {
482
+ $users_array = array();
483
+ foreach ( $exclude_these_users as $username ) {
484
+ if ( false !== ( $exists_id = username_exists( $username ) ) ) {
485
+ $users_array[] = $exists_id;
486
+ }
487
+ }
488
+
489
+ if ( ! empty( $users_array ) ) {
490
+ $this->where_clauses[] = "u.ID NOT IN ( '" . implode( "','", $users_array ) . "' )";
491
+ }
492
+ }
493
+ }
494
+
495
+
496
+ $profile_photo_where = '';
497
+ if ( $directory_data['has_profile_photo'] == 1 ) {
498
+ $profile_photo_where = " AND umm_general.um_value LIKE '%s:13:\"profile_photo\";b:1;%'";
499
+ }
500
+
501
+ $cover_photo_where = '';
502
+ if ( $directory_data['has_cover_photo'] == 1 ) {
503
+ $cover_photo_where = " AND umm_general.um_value LIKE '%s:11:\"cover_photo\";b:1;%'";
504
+ }
505
+
506
+ if ( ! UM()->roles()->um_user_can( 'can_edit_everyone' ) ) {
507
+ if ( ! $this->general_meta_joined ) {
508
+ $this->joins[] = "LEFT JOIN {$wpdb->prefix}um_metadata umm_general ON umm_general.user_id = u.ID";
509
+ $this->general_meta_joined = true;
510
+ }
511
+ $this->where_clauses[] = "( umm_general.um_key = 'um_member_directory_data' AND
512
+ umm_general.um_value LIKE '%s:14:\"account_status\";s:8:\"approved\";%' AND umm_general.um_value LIKE '%s:15:\"hide_in_members\";b:0;%'{$profile_photo_where}{$cover_photo_where} )";
513
+ } else {
514
+ if ( ! empty( $cover_photo_where ) || ! empty( $profile_photo_where ) ) {
515
+ if ( ! $this->general_meta_joined ) {
516
+ $this->joins[] = "LEFT JOIN {$wpdb->prefix}um_metadata umm_general ON umm_general.user_id = u.ID";
517
+ $this->general_meta_joined = true;
518
+ }
519
+ $this->where_clauses[] = "( umm_general.um_key = 'um_member_directory_data'{$profile_photo_where}{$cover_photo_where} )";
520
+ }
521
+ }
522
+
523
+ //$this->roles = array();
524
+ if ( UM()->roles()->um_user_can( 'can_view_all' ) ) {
525
+ $view_roles = um_user( 'can_view_roles' );
526
+
527
+ if ( ! $view_roles ) {
528
+ $view_roles = array();
529
+ } else {
530
+ $this->roles_in_query = true;
531
+ }
532
+
533
+ $this->roles = array_merge( $this->roles, maybe_unserialize( $view_roles ) );
534
+ }
535
+
536
+ if ( ! empty( $directory_data['roles'] ) ) {
537
+ if ( ! empty( $this->roles ) ) {
538
+ $this->roles = array_intersect( $this->roles, maybe_unserialize( $directory_data['roles'] ) );
539
+ } else {
540
+ $this->roles = array_merge( $this->roles, maybe_unserialize( $directory_data['roles'] ) );
541
+ }
542
+
543
+ $this->roles_in_query = true;
544
+ }
545
+
546
+ if ( ! empty( $this->roles ) ) {
547
+ $this->joins[] = "LEFT JOIN {$wpdb->prefix}um_metadata umm_roles ON ( umm_roles.user_id = u.ID AND umm_roles.um_key = '" . $wpdb->get_blog_prefix( $blog_id ) . "capabilities' )";
548
+
549
+ $roles_clauses = array();
550
+ foreach ( $this->roles as $role ) {
551
+ $roles_clauses[] = $wpdb->prepare( 'umm_roles.um_value LIKE %s', '%"' . $role . '"%' );
552
+ }
553
+
554
+ $this->where_clauses[] = '( ' . implode( ' OR ', $roles_clauses ) . ' )';
555
+ } else {
556
+
557
+ if ( ! $this->roles_in_query && is_multisite() ) {
558
+ // select users who have capabilities for current blog
559
+ $this->joins[] = "LEFT JOIN {$wpdb->prefix}um_metadata umm_roles ON ( umm_roles.user_id = u.ID AND umm_roles.um_key = '" . $wpdb->get_blog_prefix( $blog_id ) . "capabilities' )";
560
+ $this->where_clauses[] = "umm_roles.um_value IS NOT NULL";
561
+ } elseif ( $this->roles_in_query ) {
562
+ $member_directory_response = apply_filters( 'um_ajax_get_members_response', array(
563
+ 'pagination' => $this->calculate_pagination( $directory_data, 0 ),
564
+ 'users' => array(),
565
+ 'is_search' => $this->is_search,
566
+ ), $directory_data );
567
+
568
+ wp_send_json_success( $member_directory_response );
569
+ }
570
+ }
571
+
572
+
573
+ if ( ! empty( $_POST['search'] ) ) {
574
+ $search_line = trim( stripslashes( sanitize_text_field( $_POST['search'] ) ) );
575
+
576
+ $searches = array();
577
+ foreach ( $this->core_search_fields as $field ) {
578
+ $searches[] = $wpdb->prepare( "u.{$field} LIKE %s", '%' . $search_line . '%' );
579
+ }
580
+
581
+ $core_search = implode( ' OR ', $searches );
582
+
583
+ $this->joins[] = "LEFT JOIN {$wpdb->prefix}um_metadata umm_search ON umm_search.user_id = u.ID";
584
+
585
+ $additional_search = apply_filters( 'um_member_directory_meta_general_search_meta_query', '', stripslashes( sanitize_text_field( $_POST['search'] ) ) );
586
+
587
+ $search_like_string = apply_filters( 'um_member_directory_meta_search_like_type', '%' . $search_line . '%', $search_line );
588
+
589
+ $this->where_clauses[] = $wpdb->prepare( "( umm_search.um_value = %s OR umm_search.um_value LIKE %s OR umm_search.um_value LIKE %s OR {$core_search}{$additional_search})", $search_line, $search_like_string, '%' . serialize( (string) $search_line ) . '%' );
590
+
591
+ $this->is_search = true;
592
+ }
593
+
594
+
595
+ //filters
596
+ $filter_query = array();
597
+ if ( ! empty( $directory_data['search_fields'] ) ) {
598
+ $search_filters = maybe_unserialize( $directory_data['search_fields'] );
599
+ if ( ! empty( $search_filters ) && is_array( $search_filters ) ) {
600
+ $filter_query = array_intersect_key( $_POST, array_flip( $search_filters ) );
601
+ }
602
+ }
603
+
604
+ // added for user tags extension integration on individual tag page
605
+ $ignore_empty_filters = apply_filters( 'um_member_directory_ignore_empty_filters', false );
606
+
607
+ if ( ! empty( $filter_query ) || $ignore_empty_filters ) {
608
+ $this->is_search = true;
609
+
610
+ $i = 1;
611
+ foreach ( $filter_query as $field => $value ) {
612
+
613
+ $field = sanitize_text_field( $field );
614
+ if ( is_array( $value ) ) {
615
+ $value = array_map( 'sanitize_text_field', $value );
616
+ } else {
617
+ $value = sanitize_text_field( $value );
618
+ }
619
+
620
+ $attrs = UM()->fields()->get_field( $field );
621
+ // skip private invisible fields
622
+ if ( ! um_can_view_field( $attrs ) ) {
623
+ continue;
624
+ }
625
+
626
+ $this->handle_filter_query( $directory_data, $field, $value, $i );
627
+
628
+ $i++;
629
+ }
630
+ }
631
+
632
+
633
+ //unable default filter in case if we select other filters in frontend filters
634
+ //if ( empty( $this->custom_filters_in_query ) ) {
635
+ $default_filters = array();
636
+ if ( ! empty( $directory_data['search_filters'] ) ) {
637
+ $default_filters = maybe_unserialize( $directory_data['search_filters'] );
638
+ }
639
+
640
+ if ( ! empty( $default_filters ) ) {
641
+ $i = 1;
642
+ foreach ( $default_filters as $field => $value ) {
643
+
644
+ $this->handle_filter_query( $directory_data, $field, $value, $i, true );
645
+
646
+ $i++;
647
+ }
648
+ }
649
+ //}
650
+
651
+ $order = 'ASC';
652
+ $sortby = ! empty( $_POST['sorting'] ) ? sanitize_text_field( $_POST['sorting'] ) : $directory_data['sortby'];
653
+ $sortby = ( $sortby == 'other' ) ? $directory_data['sortby_custom'] : $sortby;
654
+
655
+ $custom_sort = array();
656
+ if ( ! empty( $directory_data['sorting_fields'] ) ) {
657
+ $sorting_fields = maybe_unserialize( $directory_data['sorting_fields'] );
658
+ foreach ( $sorting_fields as $field ) {
659
+ if ( is_array( $field ) ) {
660
+ $field_keys = array_keys( $field );
661
+ $custom_sort[] = $field_keys[0];
662
+ }
663
+ }
664
+ }
665
+
666
+ $numeric_sorting_keys = array();
667
+
668
+ if ( ! empty( UM()->builtin()->saved_fields ) ) {
669
+ foreach ( UM()->builtin()->saved_fields as $key => $data ) {
670
+ if ( $key == '_um_last_login' ) {
671
+ continue;
672
+ }
673
+
674
+ if ( isset( $data['type'] ) && 'number' === $data['type'] ) {
675
+ if ( array_key_exists( $key . '_desc', $this->sort_fields ) ) {
676
+ $numeric_sorting_keys[] = $key . '_desc';
677
+ }
678
+ if ( array_key_exists( $key . '_asc', $this->sort_fields ) ) {
679
+ $numeric_sorting_keys[] = $key . '_asc';
680
+ }
681
+ }
682
+ }
683
+ }
684
+
685
+ // handle sorting options
686
+ // sort members by
687
+ if ( $sortby == $directory_data['sortby_custom'] || in_array( $sortby, $custom_sort ) ) {
688
+
689
+ $this->joins[] = "LEFT JOIN {$wpdb->prefix}um_metadata umm_sort ON ( umm_sort.user_id = u.ID AND umm_sort.um_key = '{$sortby}' )";
690
+
691
+ $custom_sort_type = apply_filters( 'um_member_directory_custom_sorting_type', 'CHAR', $sortby, $directory_data );
692
+
693
+ $this->sql_order = " ORDER BY CAST( umm_sort.um_value AS {$custom_sort_type} ) {$order} ";
694
+
695
+ } elseif ( count( $numeric_sorting_keys ) && in_array( $sortby, $numeric_sorting_keys ) ) {
696
+
697
+ if ( strstr( $sortby, '_desc' ) ) {
698
+ $sortby = str_replace( '_desc', '', $sortby );
699
+ $order = 'DESC';
700
+ }
701
+
702
+ if ( strstr( $sortby, '_asc' ) ) {
703
+ $sortby = str_replace( '_asc', '', $sortby );
704
+ $order = 'ASC';
705
+ }
706
+
707
+ $this->joins[] = "LEFT JOIN {$wpdb->prefix}um_metadata umm_sort ON ( umm_sort.user_id = u.ID AND umm_sort.um_key = '{$sortby}' )";
708
+ $this->sql_order = " ORDER BY CAST( umm_sort.um_value AS SIGNED ) {$order}, u.user_registered DESC ";
709
+
710
+ } elseif ( 'username' == $sortby ) {
711
+
712
+ $this->sql_order = " ORDER BY u.user_login {$order} ";
713
+
714
+ } elseif ( 'display_name' == $sortby ) {
715
+
716
+ $display_name = UM()->options()->get( 'display_name' );
717
+ if ( $display_name == 'username' ) {
718
+
719
+ $this->sql_order = " ORDER BY u.user_login {$order} ";
720
+
721
+ } else {
722
+
723
+ $this->joins[] = "LEFT JOIN {$wpdb->prefix}um_metadata umm_sort ON ( umm_sort.user_id = u.ID AND umm_sort.um_key = 'full_name' )";
724
+
725
+ $this->sql_order = " ORDER BY CAST( umm_sort.um_value AS CHAR ) {$order}, u.display_name {$order} ";
726
+
727
+ }
728
+
729
+ } elseif ( in_array( $sortby, array( 'last_name', 'first_name', 'nickname' ) ) ) {
730
+
731
+ $this->joins[] = "LEFT JOIN {$wpdb->prefix}um_metadata umm_sort ON ( umm_sort.user_id = u.ID AND umm_sort.um_key = '{$sortby}' )";
732
+
733
+ $this->sql_order = " ORDER BY CAST( umm_sort.um_value AS CHAR ) {$order} ";
734
+
735
+ } elseif ( $sortby == 'last_login' ) {
736
+
737
+ $this->joins[] = "LEFT JOIN {$wpdb->prefix}um_metadata umm_sort ON ( umm_sort.user_id = u.ID AND umm_sort.um_key = '_um_last_login' )";
738
+
739
+ $this->sql_order = " ORDER BY CAST( umm_sort.um_value AS SIGNED ) DESC ";
740
+
741
+ } elseif ( $sortby == 'last_first_name' ) {
742
+
743
+ $this->joins[] = "LEFT JOIN {$wpdb->prefix}um_metadata umm_sort ON ( umm_sort.user_id = u.ID AND umm_sort.um_key = 'last_name' )";
744
+ $this->joins[] = "LEFT JOIN {$wpdb->prefix}um_metadata umm_sort2 ON ( umm_sort2.user_id = u.ID AND umm_sort2.um_key = 'first_name' )";
745
+
746
+ $this->sql_order = " ORDER BY CAST( umm_sort.um_value AS CHAR ) ASC, CAST( umm_sort2.um_value AS CHAR ) ASC ";
747
+
748
+ } elseif ( $sortby == 'random' ) {
749
+
750
+ if ( um_is_session_started() === false ) {
751
+ @session_start();
752
+ }
753
+
754
+ // Reset seed on load of initial
755
+ if ( empty( $_REQUEST['directory_id'] ) && isset( $_SESSION['um_member_directory_seed'] ) ) {
756
+ unset( $_SESSION['um_member_directory_seed'] );
757
+ }
758
+
759
+ // Get seed from session variable if it exists
760
+ $seed = false;
761
+ if ( isset( $_SESSION['um_member_directory_seed'] ) ) {
762
+ $seed = $_SESSION['um_member_directory_seed'];
763
+ }
764
+
765
+ // Set new seed if none exists
766
+ if ( ! $seed ) {
767
+ $seed = rand();
768
+ $_SESSION['um_member_directory_seed'] = $seed;
769
+ }
770
+
771
+ $this->sql_order = 'ORDER BY RAND(' . $seed . ')';
772
+
773
+ } else {
774
+
775
+ if ( strstr( $sortby, '_desc' ) ) {
776
+ $sortby = str_replace( '_desc', '', $sortby );
777
+ $order = 'DESC';
778
+ }
779
+
780
+ if ( strstr( $sortby, '_asc' ) ) {
781
+ $sortby = str_replace( '_asc', '', $sortby );
782
+ $order = 'ASC';
783
+ }
784
+
785
+ $metakeys = get_option( 'um_usermeta_fields', array() );
786
+ if ( false !== array_search( $sortby, $metakeys ) ) {
787
+ $this->joins[] = "LEFT JOIN {$wpdb->prefix}um_metadata umm_sort ON ( umm_sort.user_id = u.ID AND umm_sort.um_key = '{$sortby}' )";
788
+ $this->sql_order = " ORDER BY CAST( umm_sort.um_value AS CHAR ) {$order} ";
789
+ } else {
790
+ $this->sql_order = " ORDER BY u.{$sortby} {$order} ";
791
+ }
792
+ }
793
+
794
+ $this->sq