functions.php
8.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
<?php
/**
* Understrap Child Theme functions and definitions
*
* @package UnderstrapChild
*/
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;
include 'inc/shortcodes.php';
include 'inc/blocks.php';
include 'inc/shortcodes-resources.php';
include 'inc/menu.php';
include 'inc/shortcodes-contest.php';
include 'inc/shortcodes-disqus.php';
include 'inc/shortcodes-members.php';
/**
* Removes the parent themes stylesheet and scripts from inc/enqueue.php
*/
function understrap_remove_scripts() {
wp_dequeue_style( 'understrap-styles' );
wp_deregister_style( 'understrap-styles' );
wp_dequeue_script( 'understrap-scripts' );
wp_deregister_script( 'understrap-scripts' );
}
add_action( 'wp_enqueue_scripts', 'understrap_remove_scripts', 20 );
/**
* Enqueue our stylesheet and javascript file
*/
function theme_enqueue_styles() {
// Get the theme data.
$the_theme = wp_get_theme();
$theme_version = $the_theme->get( 'Version' );
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
// Grab asset urls.
$theme_styles = "/css/child-theme{$suffix}.css";
$theme_scripts = "/js/child-theme{$suffix}.js";
$css_version = $theme_version . '.' . filemtime( get_stylesheet_directory() . $theme_styles );
wp_enqueue_style( 'child-understrap-styles', get_stylesheet_directory_uri() . $theme_styles, array(), $css_version );
wp_enqueue_script( 'jquery' );
$js_version = $theme_version . '.' . filemtime( get_stylesheet_directory() . $theme_scripts );
wp_enqueue_script( 'child-understrap-scripts', get_stylesheet_directory_uri() . $theme_scripts, array(), $js_version, true );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
}
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
/**
* Load the child theme's text domain
*/
function add_child_theme_textdomain() {
load_child_theme_textdomain( 'understrap-child', get_stylesheet_directory() . '/languages' );
}
add_action( 'after_setup_theme', 'add_child_theme_textdomain' );
/**
* Overrides the theme_mod to default to Bootstrap 5
*
* This function uses the `theme_mod_{$name}` hook and
* can be duplicated to override other theme settings.
*
* @return string
*/
function understrap_default_bootstrap_version() {
return 'bootstrap5';
}
add_filter( 'theme_mod_understrap_bootstrap_version', 'understrap_default_bootstrap_version', 20 );
/**
* Loads javascript for showing customizer warning dialog.
*/
function understrap_child_customize_controls_js() {
wp_enqueue_script(
'understrap_child_customizer',
get_stylesheet_directory_uri() . '/js/customizer-controls.js',
array( 'customize-preview' ),
'20130508',
true
);
}
add_action( 'customize_controls_enqueue_scripts', 'understrap_child_customize_controls_js' );
// require_once __DIR__.'/inc/filters.php';
remove_action( 'um_logout_user_links', 'um_logout_user_links', 100 );
add_action( 'um_logout_user_links', 'um_logout_user_links_new', 100 );
/**
* Adds main links to a logout widget
*
* @param $args
*/
function um_logout_user_links_new( $args ) {
?>
<li>
<a href="<?php echo esc_url( um_get_core_page( 'account' ) ); ?>">
<?php _e( 'My Profile', 'ultimate-member' ); ?>
</a>
</li>
<li>
<a href="<?php echo esc_url( add_query_arg( 'redirect_to', UM()->permalinks()->get_current_url( true ), um_get_core_page( 'logout' ) ) ); ?>">
<?php _e( 'Logout', 'ultimate-member' ); ?>
</a>
</li>
<?php
}
function um_validate_email_domain( $args ) {
// Change allowed email domains here
$allowed_email_domains = apply_filters( 'um_allowed_email_domains', array(
'gotenzing.com',
'ekccu.com',
'heritagecu.ca',
'stellervista.com'
) );
// Change error message here
$message = __( 'You can not use this email domain for registration', 'ultimate-member' );
if ( isset( $args['user_email'] ) && is_email( $args['user_email'] ) ) {
$email_domain = array_pop( explode( '@', trim( $args['user_email'] ) ) );
if ( !in_array( $email_domain, $allowed_email_domains ) ) {
UM()->form()->add_error( 'user_email', $message );
}
}
}
add_action( 'um_submit_form_errors_hook__registration', 'um_validate_email_domain', 20 );
function is_valid_email_domain($login, $email, $errors ){
$allowed_email_domains = array("gotenzing.com","heritagecu.ca","ekccu.com","stellervista.com");// allowed domains
$valid = false; // sets default validation to false
if ( isset( $email ) && is_email( $email ) ) {
$email_domain = array_pop( explode( '@', trim( $email) ) );
if ( in_array( $email_domain, $allowed_email_domains ) ) {
$valid = true;
}
}
// Return error message for invalid domains
if( $valid === false ){
$errors->add('domain_whitelist_error',__( '<strong>ERROR</strong>: Registration is only allowed from selected approved domains. If you think you are seeing this in error, please contact the system administrator.' ));
}
}
add_action('register_post', 'is_valid_email_domain',10,3 );
add_filter( 'um_profile_field_filter_hook__phone_number_12', 'my_profile_phone_number', 10, 2 );
add_filter( 'um_profile_field_filter_hook__phone_number', 'my_profile_phone_number', 10, 2 );
function my_profile_phone_number( $value, $data ) {
$value = format_phone_string( $value );
return $value;
}
add_filter( 'um_view_label_phone_number', 'my_phone_number_label', 10, 1 );
function my_phone_number_label( $label ) {
$label = "Direct Line / Branch";
return $label;
}
function format_phone_string( $phoneNumber ) {
// Return the phone number in parentheses format, e.g. (123) 456-7890.
// Handles 10 digit numbers with or without country codes and extensions
// Source 2nd part from: https://stackoverflow.com/questions/4708248/formatting-phone-numbers-in-php
$phoneNumber = preg_replace('/[^0-9]/','',$phoneNumber);
if(strlen($phoneNumber) > 10) {
$countryCode = substr($phoneNumber, 0, strlen($phoneNumber)-10);
$areaCode = substr($phoneNumber, -10, 3);
$nextThree = substr($phoneNumber, -7, 3);
$lastFour = substr($phoneNumber, -4, 4);
$phoneNumber = '+'.$countryCode.' ('.$areaCode.') '.$nextThree.'-'.$lastFour;
}
else if(strlen($phoneNumber) == 10) {
$areaCode = substr($phoneNumber, 0, 3);
$nextThree = substr($phoneNumber, 3, 3);
$lastFour = substr($phoneNumber, 6, 4);
$phoneNumber = '('.$areaCode.') '.$nextThree.'-'.$lastFour;
}
else if(strlen($phoneNumber) == 7) {
$nextThree = substr($phoneNumber, 0, 3);
$lastFour = substr($phoneNumber, 3, 4);
$phoneNumber = $nextThree.'-'.$lastFour;
}
return $phoneNumber;
}
add_filter( 'um_profile_field_filter_hook__department_email', 'um_get_department_email', 99, 2);
function um_get_department_email( $data ) {
$arr = explode(">", $data);
$arr = explode("<", $arr[1]);
$data = $arr[0];
return $data;
}
add_action( 'init', 'wpa_34245' );
function wpa_34245() {
// if query var is not present just return
if ( isset( $_REQUEST['my_listener'] ) || 'update_office_email' == $_REQUEST['my_listener'] ){
$users = get_users( array( 'fields' => array( 'ID' ) ) );
foreach($users as $user){
update_office_email($user->ID);
}
}else if ( isset( $_REQUEST['my_listener'] ) || 'update_fax' == $_REQUEST['my_listener'] ){
$users = get_users( array( 'fields' => array( 'ID' ) ) );
foreach($users as $user){
update_branch_fax($user->ID);
}
}else{
return;
}
}
add_action( 'profile_update', function ( $user_id, $old_user_data ) {
update_office_email($user_id);
update_branch_fax($user_id);
}, 10, 2 );
function update_branch_fax($userID) {
$department_branch = get_user_meta($userID, 'department_branch', true );
$department_fax = find_branch_info($department_branch, 'fax');
update_user_meta( $userID, 'phone_number_12', $department_fax);
}
function update_office_email($userID) {
$department_branch = get_user_meta( $userID, 'department_branch', true );
$department_email = find_branch_info($department_branch, 'email');
update_user_meta( $userID, 'department_email',$department_email );
}
function find_branch_info($department_branch, $field){
if( have_rows('departments_and_branches', 'option') ):
while ( have_rows('departments_and_branches' , 'option') ) : the_row();
if(get_sub_field('departmentbranch') == $department_branch ):
return get_sub_field($field);
endif;
endwhile;
endif;
}