PluginProbe
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor / 3.16.1
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor v3.16.1
4.0.3 4.0.2 4.0.1 4.0.0 3.16.6 3.16.5 3.16.4 3.16.3 3.16.2 3.16.1 3.16.0 3.15.9 3.9.9 3.9.5 3.9.6 3.9.7 3.9.8 1.1.7 1.1.8 1.1.9 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 All 341 releases
profile-builder / admin / admin-functions.php

admin-functions.php in User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor 3.16.1, at admin/admin-functions.php

1,114 lines 48.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
4 /**
5 * Function which returns the same field-format over and over again.
6 *
7 * @since v.2.0
8 *
9 * @param string $field
10 * @param string $field_title
11 *
12 * @return string
13 */
14 function wppb_field_format ( $field_title, $field ){
15
16 return trim( $field_title ).' ( '.trim( $field ).' )';
17 }
18
19 /**
20 * Add a notification for either the Username or the Email field letting the user know that, even though it is there, it won't do anything
21 *
22 * @since v.2.0
23 *
24 * @param string $form
25 * @param integer $id
26 * @param string $value
27 *
28 * @return string $form
29 */
30
31 function wppb_manage_fields_display_field_title_slug( $form ){
32 // add a notice to fields
33 global $wppb_results_field;
34 switch ($wppb_results_field){
35 case 'Default - Username':
36 $wppb_generalSettings = get_option( 'wppb_general_settings', 'not_found' );
37 if ( $wppb_generalSettings != 'not_found' && $wppb_generalSettings['loginWith'] == 'email' ) {
38 $form .= '<div id="wppb-login-email-nag" class="wppb-backend-notice">' . sprintf(__('Login is set to be done using the Email. This field will NOT appear in the front-end! ( you can change these settings under the "%s" tab )', 'profile-builder'), '<a href="' . admin_url('admin.php?page=profile-builder-general-settings') . '" target="_blank">' . __('General Settings', 'profile-builder') . '</a>') . '</div>';
39 }
40 break;
41 case 'Default - Display name publicly as':
42 $form .= '<div id="wppb-display-name-nag" class="wppb-backend-notice">' . __( 'Display name publicly as - only appears on the Edit Profile page!', 'profile-builder' ) . '</div>';
43 break;
44 case 'Default - Blog Details':
45 $form .= '<div id="wppb-blog-details-nag" class="wppb-backend-notice">' . __( 'Blog Details - only appears on the Registration page!', 'profile-builder' ) . '</div>';
46 break;
47 }
48
49 return $form;
50 }
51
52 add_filter( 'wck_after_content_element', 'wppb_manage_fields_display_field_title_slug' );
53
54 /**
55 * Check if field type is 'Default - Display name publicly as' so we can add a notification for it
56 *
57 * @since v.2.2
58 *
59 * @param string $wck_element_class
60 * @param string $meta
61 * @param array $results
62 * @param integer $element_id
63 *
64 */
65 function wppb_manage_fields_display_name_notice( $wck_element_class, $meta, $results, $element_id ) {
66 global $wppb_results_field;
67
68 $wppb_results_field = $results[$element_id]['field'];
69 }
70 add_filter( 'wck_element_class_wppb_manage_fields', 'wppb_manage_fields_display_name_notice', 10, 4 );
71
72 /**
73 * Function that adds a custom class to the existing container
74 *
75 * @since v.2.0
76 *
77 * @param string $update_container_class - the new class name
78 * @param string $meta - the name of the meta
79 * @param array $results
80 * @param integer $element_id - the ID of the element
81 *
82 * @return string
83 */
84 function wppb_update_container_class( $update_container_class, $meta, $results, $element_id ) {
85 $wppb_element_type = Wordpress_Creation_Kit_PB::wck_generate_slug( $results[$element_id]["field"] );
86
87 return "class='wck_update_container update_container_$meta update_container_$wppb_element_type element_type_$wppb_element_type'";
88 }
89 add_filter( 'wck_update_container_class_wppb_manage_fields', 'wppb_update_container_class', 10, 4 );
90
91 /**
92 * Function that adds a custom class to the existing element
93 *
94 * @since v.2.0
95 *
96 * @param string $element_class - the new class name
97 * @param string $meta - the name of the meta
98 * @param array $results
99 * @param integer $element_id - the ID of the element
100 *
101 * @return string
102 */
103 function wppb_element_class( $element_class, $meta, $results, $element_id ){
104 $wppb_element_type = Wordpress_Creation_Kit_PB::wck_generate_slug( $results[$element_id]["field"] );
105
106 return "class='element_type_$wppb_element_type added_fields_list'";
107 }
108 add_filter( 'wck_element_class_wppb_manage_fields', 'wppb_element_class', 10, 4 );
109
110 /**
111 * Functions to check password length and strength
112 *
113 * @since v.2.0
114 */
115 /* on add user and update profile from WP admin area */
116 add_action( 'user_profile_update_errors', 'wppb_password_check_on_profile_update', 0, 3 );
117 function wppb_password_check_on_profile_update( $errors, $update, $user ){
118 wppb_password_check_extra_conditions( $errors, $user );
119 }
120
121 /* on reset password */
122 add_action( 'validate_password_reset', 'wppb_password_check_extra_conditions', 10, 2 );
123 function wppb_password_check_extra_conditions( $errors, $user ){
124 $password = ( isset( $_POST[ 'pass1' ] ) && trim( $_POST[ 'pass1' ] ) ) ? $_POST[ 'pass1' ] : false; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash
125
126 if( $password && ( !isset( $_POST['pw_weak'] ) || $_POST['pw_weak'] != 'on' ) ){
127 $wppb_generalSettings = get_option( 'wppb_general_settings' );
128
129 if( !empty( $wppb_generalSettings['minimum_password_length'] ) ){
130 if( strlen( $password ) < $wppb_generalSettings['minimum_password_length'] )
131 $errors->add( 'pass', sprintf( __( '<strong>ERROR:</strong> The password must have the minimum length of %s characters', 'profile-builder' ), $wppb_generalSettings['minimum_password_length'] ) );
132 }
133
134 if( isset( $_POST['wppb_password_strength'] ) && !empty( $wppb_generalSettings['minimum_password_strength'] ) ){
135 $password_strength_array = array( 'short' => 0, 'bad' => 1, 'good' => 2, 'strong' => 3 );
136 $password_strength_text = array( 'short' => __( 'Very weak', 'profile-builder' ), 'bad' => __( 'Weak', 'profile-builder' ), 'good' => __( 'Medium', 'profile-builder' ), 'strong' => __( 'Strong', 'profile-builder' ) );
137
138 foreach( $password_strength_text as $psr_key => $psr_text ){
139 if( $psr_text == sanitize_text_field( $_POST['wppb_password_strength'] ) ){
140 $password_strength_result_slug = $psr_key;
141 break;
142 }
143 }
144
145 if( !empty( $password_strength_result_slug ) ){
146 if( $password_strength_array[$password_strength_result_slug] < $password_strength_array[$wppb_generalSettings['minimum_password_strength']] )
147 $errors->add( 'pass', sprintf( __( '<strong>ERROR:</strong> The password must have a minimum strength of %s', 'profile-builder' ), $password_strength_text[$wppb_generalSettings['minimum_password_strength']] ) );
148 }
149 }
150 }
151
152 return $errors;
153 }
154
155 /* we need to create a hidden field that contains the results of the password strength from the js strength tester */
156 add_action( 'admin_footer', 'wppb_add_hidden_password_strength_on_backend' );
157 add_action( 'login_footer', 'wppb_add_hidden_password_strength_on_backend' );
158 function wppb_add_hidden_password_strength_on_backend(){
159 if( $GLOBALS['pagenow'] == 'profile.php' || $GLOBALS['pagenow'] == 'user-new.php' || ( $GLOBALS['pagenow'] == 'wp-login.php' && isset( $_GET['action'] ) && ( $_GET['action'] === 'rp' || $_GET['action'] === 'resetpass' ) ) ){
160 $wppb_generalSettings = get_option( 'wppb_general_settings' );
161 if( !empty( $wppb_generalSettings['minimum_password_strength'] ) ){
162 ?>
163 <script type="text/javascript">
164 jQuery( document ).ready( function() {
165 var passswordStrengthResult = jQuery( '#pass-strength-result' );
166 // Check for password strength meter
167 if ( passswordStrengthResult.length ) {
168 // Attach submit event to form
169 passswordStrengthResult.parents( 'form' ).on( 'submit', function() {
170 // Store check results in hidden field
171 jQuery( this ).append( '<input type="hidden" name="wppb_password_strength" value="' + passswordStrengthResult.text() + '">' );
172 });
173 }
174 });
175 </script>
176 <?php
177 }
178 }
179 }
180
181 /* Modify the Add Entry buttons for WCK metaboxes according to context */
182 add_filter( 'wck_add_entry_button', 'wppb_change_add_entry_button', 10, 2 );
183 function wppb_change_add_entry_button( $string, $meta ){
184 if( $meta == 'wppb_manage_fields' || $meta == 'wppb_epf_fields' || $meta == 'wppb_rf_fields' ){
185 return __( "Add Field", 'profile-builder' );
186 }elseif( $meta == 'wppb_epf_page_settings' || $meta == 'wppb_rf_page_settings' || $meta == 'wppb_ul_page_settings' ){
187 return __( "Save Settings", 'profile-builder' );
188 }
189
190 return $string;
191 }
192
193 /**
194 * add links on plugin page
195 */
196 add_filter( 'plugin_action_links', 'wppb_plugin_action_links', 10, 2 );
197 function wppb_plugin_action_links( $links, $file ) {
198 if ( $file != WPPB_PLUGIN_BASENAME ) {
199 return $links;
200 }
201
202 if ( ! current_user_can( 'manage_options' ) ) {
203 return $links;
204 }
205
206 $settings_link = sprintf( '<a href="%1$s">%2$s</a>',
207 menu_page_url( 'profile-builder-general-settings', false ),
208 esc_html( __( 'Settings', 'profile-builder' ) ) );
209
210 array_unshift( $links, $settings_link );
211
212 return $links;
213 }
214
215 /**
216 * add links on plugin page
217 */
218 add_filter( 'plugin_row_meta', 'wppb_plugin_row_meta', 10, 2 );
219 function wppb_plugin_row_meta( $links, $file ) {
220 if ( WPPB_PLUGIN_BASENAME == $file ) {
221 $row_meta = array(
222 'docs' => '<a href="' . esc_url( 'https://www.cozmoslabs.com/docs/profile-builder/' ) . '" target="_blank" aria-label="' . esc_attr__( 'View Profile Builder documentation', 'profile-builder' ) . '">' . esc_html__( 'Docs', 'profile-builder' ) . '</a>',
223 'get_support' => '<a href="' . esc_url( apply_filters( 'wppb_docs_url', 'https://wordpress.org/support/plugin/profile-builder/' ) ) . '" title="' . esc_attr( __( 'Get Support', 'profile-builder' ) ) . '" target="_blank">' . __( 'Get Support', 'profile-builder' ) . '</a>',
224 );
225
226 return array_merge( $links, $row_meta );
227 }
228
229 return (array) $links;
230 }
231
232 function wppb_sync_api( $action ) {
233
234 $base = 'https://usagetracker.cozmoslabs.com';
235 $url = $base . '/syncPlugin';
236 $body = array(
237 'unique_identifier' => hash( 'sha256', home_url( '', 'https' ) ),
238 'product' => 'wppb',
239 'action' => $action,
240 );
241
242 $body = apply_filters( 'wppb_sync_api_body', $body, $action );
243
244 wp_remote_post( $url, array(
245 'body' => $body,
246 'timeout' => 3,
247 'blocking' => false,
248 ) );
249
250 }
251
252 function wppb_handle_plugin_activation(){
253
254 $general_settings = get_option( 'wppb_general_settings' );
255
256 if( empty( $general_settings ) || !is_array( $general_settings ) || empty( $general_settings['extraFieldsLayout'] ) ){
257 wppb_sync_api( 'start' );
258 }
259
260 }
261
262 function wppb_handle_plugin_deactivation(){
263 wppb_sync_api( 'end' );
264 }
265
266 /**
267 * Add the stored deactivation reason to the sync payload
268 *
269 * @param array $body Sync request body
270 * @param string $action Sync action slug
271 *
272 * @return array
273 */
274 function wppb_add_deactivation_reason_to_sync_body( $body, $action ) {
275
276 if ( $action !== 'end' )
277 return $body;
278
279 $reason_data = get_option( 'wppb_deactivation_reason', array() );
280
281 if ( ! is_array( $reason_data ) )
282 $reason_data = array();
283
284 if ( empty( $reason_data['reason'] ) )
285 $reason_data['reason'] = 'skip';
286
287 $body['reason'] = sanitize_key( $reason_data['reason'] );
288
289 $reason_key = $reason_data['reason'] . '_reason';
290
291 if ( ! empty( $reason_data[ $reason_key ] ) )
292 $body['extra_metadata'] = sanitize_text_field( $reason_data[ $reason_key ] );
293
294 delete_option( 'wppb_deactivation_reason' );
295
296 return $body;
297 }
298 add_filter( 'wppb_sync_api_body', 'wppb_add_deactivation_reason_to_sync_body', 10, 2 );
299
300 /**
301 * Store the deactivation reason selected in the popup
302 */
303 function wppb_store_deactivation_reason() {
304
305 if ( ! check_ajax_referer( 'wppb_deactivation_reason', 'nonce', false ) )
306 wp_send_json_error( array( 'message' => __( 'We could not verify your request. Please refresh the page and try again.', 'profile-builder' ) ), 403 );
307
308 if ( ! current_user_can( 'activate_plugins' ) )
309 wp_send_json_error( array( 'message' => __( 'You do not have permission to deactivate plugins on this site.', 'profile-builder' ) ), 403 );
310
311 $valid_reasons = array(
312 'dont_need_it',
313 'switched_to_another_plugin',
314 'missing_features',
315 'did_not_work',
316 'temporary_deactivation',
317 'other',
318 'skip',
319 );
320
321 $reason = '';
322
323 if ( isset( $_POST['reason'] ) )
324 $reason = sanitize_key( wp_unslash( $_POST['reason'] ) );
325
326 if ( ! in_array( $reason, $valid_reasons, true ) )
327 wp_send_json_error( array( 'message' => __( 'We could not save your deactivation feedback. Please try again.', 'profile-builder' ) ), 400 );
328
329 $reason_data = array(
330 'reason' => $reason,
331 );
332
333 if ( $reason === 'switched_to_another_plugin' && ! empty( $_POST['switched_to_another_plugin_reason'] ) )
334 $reason_data['switched_to_another_plugin_reason'] = sanitize_text_field( wp_unslash( $_POST['switched_to_another_plugin_reason'] ) );
335
336 if ( $reason === 'missing_features' && ! empty( $_POST['missing_features_reason'] ) )
337 $reason_data['missing_features_reason'] = sanitize_text_field( wp_unslash( $_POST['missing_features_reason'] ) );
338
339 if ( $reason === 'other' && ! empty( $_POST['other_reason'] ) )
340 $reason_data['other_reason'] = sanitize_text_field( wp_unslash( $_POST['other_reason'] ) );
341
342 update_option( 'wppb_deactivation_reason', $reason_data, false );
343
344 wp_send_json_success();
345 }
346 add_action( 'wp_ajax_wppb_store_deactivation_reason', 'wppb_store_deactivation_reason' );
347
348 /* hook to create pages for out forms when a user press the create pages/setup button */
349 add_action( 'admin_init', 'wppb_create_form_pages' );
350 function wppb_create_form_pages(){
351
352 if( !isset( $_GET['page'] ) || $_GET['page'] != 'profile-builder-basic-info' || !isset( $_GET['wppb_create_pages'] ) || $_GET['wppb_create_pages'] != 'true' )
353 return;
354
355 if( !isset( $_GET['_wpnonce'] ) || !wp_verify_nonce( sanitize_text_field( $_GET['_wpnonce'] ), 'wppb_create_pages' ) )
356 return;
357
358 if( !current_user_can( 'manage_options' ) )
359 return;
360
361 $wppb_pages_created = get_option( 'wppb_pages_created' );
362
363 if( empty( $wppb_pages_created ) || ( isset( $_GET['wppb_force_create_pages'] ) && $_GET['wppb_force_create_pages'] === 'true' ) ) {
364 $register_page = array(
365 'post_title' => 'Register',
366 'post_content' => '[wppb-register]',
367 'post_status' => 'publish',
368 'post_type' => 'page'
369 );
370 $register_id = wp_insert_post($register_page);
371
372 $edit_page = array(
373 'post_title' => 'Edit Profile',
374 'post_content' => '[wppb-edit-profile]',
375 'post_status' => 'publish',
376 'post_type' => 'page'
377 );
378 $edit_id = wp_insert_post($edit_page);
379
380 $login_page = array(
381 'post_title' => 'Log In',
382 'post_content' => '[wppb-login]',
383 'post_status' => 'publish',
384 'post_type' => 'page'
385 );
386 $login_id = wp_insert_post($login_page);
387
388 update_option('wppb_pages_created', 'true' );
389
390 wp_safe_redirect( admin_url('edit.php?s=%5Bwppb-&post_status=all&post_type=page&action=-1&m=0&paged=1&action2=-1') );
391 }
392 }
393
394 /**
395 * Function that prepares labels to pass to the WCK api...we have a quirk in wck api that labels are wrapped
396 * in %label%...so if we want to have % inside the label for example 25% off...we will have a bad time
397 * @param string $label
398 * @return string|string[]
399 */
400 function wppb_prepare_wck_labels( $label ){
401 return trim( str_replace( '%', '&#37;', $label ) );
402 }
403
404 /**
405 * Function that returns the reserved meta name list
406 */
407 function wppb_get_reserved_meta_name_list( $all_fields, $posted_values ){
408
409 $unique_meta_name_list = array( 'first_name', 'last_name', 'nickname', 'description', 'role' );
410
411 // Default contact methods were removed in WP 3.6. A filter dictates contact methods.
412 if ( apply_filters( 'wppb_remove_default_contact_methods', get_site_option( 'initial_db_version' ) < 23588 ) ){
413 $unique_meta_name_list[] = 'aim';
414 $unique_meta_name_list[] = 'yim';
415 $unique_meta_name_list[] = 'jabber';
416 }
417
418 $add_reserved = true;
419
420 // source: https://codex.wordpress.org/Reserved_Terms
421 $reserved_meta_names = array( 'action', 'attachment', 'attachment_id', 'author', 'author_name', 'calendar', 'cat', 'category', 'category__and', 'category__in', 'category__not_in', 'category_name', 'comments_per_page',
422 'comments_popup', 'custom', 'customize_messenger_channel', 'customized', 'cpage', 'day', 'debug', 'embed', 'error', 'exact', 'feed', 'fields', 'hour', 'link_category', 'm', 'map', 'minute', 'monthnum', 'more',
423 'name', 'nav_menu', 'nonce', 'nopaging', 'offset', 'order', 'orderby', 'p', 'page', 'page_id', 'paged', 'pagename', 'pb', 'perm', 'post', 'post__in', 'post__not_in', 'post_format', 'post_mime_type',
424 'post_status', 'post_tag', 'post_type', 'posts', 'posts_per_archive_page', 'posts_per_page', 'preview', 'robots', 's', 'search', 'second', 'sentence', 'showposts', 'static', 'status', 'subpost',
425 'subpost_id', 'tag', 'tag__and', 'tag__in', 'tag__not_in', 'tag_id', 'tag_slug__and', 'tag_slug__in', 'taxonomy', 'tb', 'term', 'terms', 'theme', 'title', 'type', 'types', 'w', 'withcomments', 'withoutcomments', 'year' );
426
427 $args = array(
428 'public' => true,
429 '_builtin' => true
430 );
431 $post_types = get_post_types( $args, 'names', 'or' );
432 $taxonomies = get_taxonomies( $args, 'names', 'or' );
433
434
435 /*reserved meta names were added in PB 3.1.2 so to avoid the situation where someone updates an already existing field
436 with a reserved name and gets an error check if it is an update or new field */
437 if( !empty( $all_fields ) && !empty($posted_values['id'] ) && !empty($posted_values['meta-name']) ){
438 foreach( $all_fields as $field ){
439 if( $field['id'] === $posted_values['id'] && $field['meta-name'] === $posted_values['meta-name'] ){//it is an update
440 $add_reserved = false;
441 }
442 }
443 }
444
445 if( $add_reserved )
446 $unique_meta_name_list = array_merge( $unique_meta_name_list, $reserved_meta_names, $post_types, $taxonomies );
447
448 return apply_filters ( 'wppb_unique_meta_name_list', $unique_meta_name_list );
449 }
450
451 add_action('admin_head', 'wppb_maybe_remove_add_new_button_for_cpt' );
452 function wppb_maybe_remove_add_new_button_for_cpt() {
453
454 global $pagenow;
455
456 $target_slugs = [ 'wppb-rf-cpt', 'wppb-epf-cpt', 'wppb-ul-cpt' ];
457 $current_slug = '';
458 $pointer_content = '';
459
460 $correct_page = false;
461
462 if ( $pagenow === 'edit.php' && isset( $_GET['post_type'] ) && in_array( sanitize_text_field( $_GET['post_type'] ), $target_slugs ) ) {
463 $correct_page = true;
464 $current_slug = sanitize_text_field( $_GET['post_type'] );
465 } else if( $pagenow === 'post.php' && isset( $_GET['post'] ) ) {
466
467 $post_type = get_post_type( absint( $_GET['post'] ) );
468
469 if ( in_array( $post_type, $target_slugs ) ) {
470 $correct_page = true;
471 $current_slug = $post_type;
472 }
473
474 }
475
476 if ( $correct_page ) {
477 $license_status = wppb_get_serial_number_status();
478
479 if( $current_slug === 'wppb-rf-cpt' ) {
480 if( $license_status == 'missing' ) {
481 $pointer_content .= '<p>' . sprintf( __( 'Please %1$senter your license key%2$s first, to add new User Registration Forms.', 'profile-builder' ), '<a href="'. admin_url( 'admin.php?page=profile-builder-general-settings' ) .'">', '</a>' ) . '</p>';
482 } else {
483 $pointer_content .= '<p>' . sprintf( __( 'You need an active license to add new User Registration Forms. %1$sRenew%2$s or %3$spurchase a new one%4$s.', 'profile-builder' ), '<a href="https://www.cozmoslabs.com/account/?utm_source=pb-registration-forms&utm_medium=client-site&utm_campaign=pb-expired-license">', '</a>', '<a href="https://www.cozmoslabs.com/wordpress-profile-builder/?utm_source=pb-registration-forms&utm_medium=client-site&utm_campaign=pb-multi-registration-addon#pricing" target="_blank">', '</a>' ) . '</p>';
484 }
485 } else if( $current_slug === 'wppb-epf-cpt' ) {
486 if( $license_status == 'missing' ) {
487 $pointer_content .= '<p>' . sprintf( __( 'Please %1$senter your license key%2$s first, to add new Edit Profile Forms.', 'profile-builder' ), '<a href="'. admin_url( 'admin.php?page=profile-builder-general-settings' ) .'">', '</a>' ) . '</p>';
488 } else {
489 $pointer_content .= '<p>' . sprintf( __( 'You need an active license to add new Edit Profile Forms. %1$sRenew%2$s or %3$spurchase a new one%4$s.', 'profile-builder' ), '<a href="https://www.cozmoslabs.com/account/?utm_source=pb-edit-profile-forms&utm_medium=client-site&utm_campaign=pb-expired-license">', '</a>', '<a href="https://www.cozmoslabs.com/wordpress-profile-builder/?utm_source=pb-edit-profile-forms&utm_medium=client-site&utm_campaign=pb-multi-edit-profile-addon#pricing" target="_blank">', '</a>' ) . '</p>';
490 }
491 } else if( $current_slug === 'wppb-ul-cpt' ) {
492 if( $license_status == 'missing' ) {
493 $pointer_content .= '<p>' . sprintf( __( 'Please %1$senter your license key%2$s first, to add new User Listing.', 'profile-builder' ), '<a href="'. admin_url( 'admin.php?page=profile-builder-general-settings' ) .'">', '</a>' ) . '</p>';
494 } else {
495 $pointer_content .= '<p>' . sprintf( __( 'You need an active license to add a new User Listing. %1$sRenew%2$s or %3$spurchase a new one%4$s.', 'profile-builder' ), '<a href="https://www.cozmoslabs.com/account/?utm_source=pb-user-listing&utm_medium=client-site&utm_campaign=pb-expired-license">', '</a>', '<a href="https://www.cozmoslabs.com/wordpress-profile-builder/?utm_source=pb-user-listing&utm_medium=client-site&utm_campaign=pb-user-listing-addon#pricing" target="_blank">', '</a>' ) . '</p>';
496 }
497 }
498
499 if( $license_status !== 'valid' ) {
500 wp_enqueue_style('wp-pointer');
501 wp_enqueue_script('wp-pointer');
502
503 echo '
504 <script>
505 jQuery(document).ready(function($) {
506 let button_text = $(".page-title-action").text();
507 $(".page-title-action").remove();
508
509 $(".wrap .wp-heading-inline").after(`<a class="page-title-action page-title-action-disabled" style="cursor:pointer;">${button_text}</a>`);
510
511 $(".page-title-action-disabled").on("click", function(e) {
512 e.preventDefault();
513
514 let pointer_content = '. json_encode( $pointer_content ) .';
515
516 jQuery( this ).pointer({
517 content: pointer_content,
518 position: { edge: "right", align: "middle" }
519 }).pointer("open");
520 });
521 });
522 </script>';
523 }
524
525 }
526
527 // This shows the Add new button. Since the above action removes it completelty, we can just attempt to show it here
528 echo '<script>
529 jQuery(document).ready(function($) {
530 if( $(".page-title-action").length > 0 ) {
531 $(".page-title-action").css("display", "inline-flex");
532 }
533 });
534 </script>';
535
536 // Manage fields
537 if( isset( $_GET['page'] ) && $_GET['page'] === 'manage-fields' ) {
538 $license_status = wppb_get_serial_number_status();
539 $pointer_content_cl = '';
540 $pointer_content_fv = '';
541 $pointer_content_epaa = '';
542
543 if( $license_status == 'missing' ) {
544 $pointer_content_cl .= '<p>' . sprintf( __( 'Please %1$senter your license key%2$s first, to use the Conditional Logic feature.', 'profile-builder' ), '<a href="'. admin_url( 'admin.php?page=profile-builder-general-settings' ) .'">', '</a>' ) . '</p>';
545 $pointer_content_fv .= '<p>' . sprintf( __( 'Please %1$senter your license key%2$s first, to configure Field Visibility options.', 'profile-builder' ), '<a href="'. admin_url( 'admin.php?page=profile-builder-general-settings' ) .'">', '</a>' ) . '</p>';
546 $pointer_content_epaa .= '<p>' . sprintf( __( 'Please %1$senter your license key%2$s first, to use the Edit Profile Updates Approved by Admin addon feature.', 'profile-builder' ), '<a href="'. admin_url( 'admin.php?page=profile-builder-general-settings' ) .'">', '</a>' ) . '</p>';
547 } else {
548 $pointer_content_cl .= '<p>' . sprintf( __( 'You need an active license to configure the Condi tional Logic feature. %1$sRenew%2$s or %3$spurchase a new one%4$s.', 'profile-builder' ), '<a href="https://www.cozmoslabs.com/account/?utm_source=pb-form-fields-conditional&utm_medium=client-site&utm_campaign=pb-expired-license">', '</a>', '<a href="https://www.cozmoslabs.com/wordpress-profile-builder/?utm_source=pb-form-fields-conditional&utm_medium=client-site&utm_campaign=pb-conditional-logic#pricing" target="_blank">', '</a>' ) . '</p>';
549 $pointer_content_fv .= '<p>' . sprintf( __( 'You need an active license to configure Field Visibility options. %1$sRenew%2$s or %3$spurchase a new one%4$s.', 'profile-builder' ), '<a href="https://www.cozmoslabs.com/account/?utm_source=pb-form-fields-visibility&utm_medium=client-site&utm_campaign=pb-expired-license">', '</a>', '<a href="https://www.cozmoslabs.com/wordpress-profile-builder/?utm_source=pb-form-fields-visibility&utm_medium=client-site&utm_campaign=pb-field-visibility#pricing" target="_blank">', '</a>' ) . '</p>';
550 $pointer_content_epaa .= '<p>' . sprintf( __( 'You need an active license to use the Edit Profile Updates Approved by Admin addon. %1$sRenew%2$s or %3$spurchase a new one%4$s.', 'profile-builder' ), '<a href="https://www.cozmoslabs.com/account/?utm_source=pb-form-fields-approval-on-edit-profile&utm_medium=client-site&utm_campaign=pb-expired-license">', '</a>', '<a href="https://www.cozmoslabs.com/wordpress-profile-builder/?utm_source=pb-form-fields-approval-on-edit-profile&utm_medium=client-site&utm_campaign=pb-approval-on-edit-profile#pricing" target="_blank">', '</a>' ) . '</p>';
551 }
552
553 if( $license_status != 'valid' ) {
554 wp_enqueue_style('wp-pointer');
555 wp_enqueue_script('wp-pointer');
556
557 echo '
558 <script>
559 jQuery(document).ready(function($) {
560
561 $(document).on( "wpbFormMetaLoaded", function(e, meta) {
562
563 wppb_manage_fields_license_invalid( e );
564
565 });
566
567 wppb_manage_fields_license_invalid();
568
569 function wppb_manage_fields_license_invalid(){
570
571 if( $(".row-conditional-logic-enabled").length > 0 ) {
572
573 $(".row-conditional-logic").hide();
574
575 $("#edit_form_conditional-logic-enabled_yes, label[for=conditional-logic-enabled_yes]").on("click", function(e) {
576 e.preventDefault();
577 e.stopPropagation();
578 e.stopImmediatePropagation();
579
580 let pointer_content = '. json_encode( $pointer_content_cl ) .';
581 let pointer_target = jQuery( this ).parent( ".cozmoslabs-toggle-container" );
582
583 if( e && e.currentTarget && jQuery( e.currentTarget ).hasClass( "cozmoslabs-form-field-label" ) ) {
584 pointer_target = jQuery( this );
585 }
586
587 pointer_target.pointer({
588 content: pointer_content,
589 position: { edge: "right", align: "middle" }
590 }).pointer("open");
591 });
592 }
593
594 if( $(".row-edit-profile-approved-by-admin").length > 0 ) {
595
596 $("#edit_form_edit-profile-approved-by-admin_yes, label[for=edit-profile-approved-by-admin_yes]").on("click", function(e) {
597 e.preventDefault();
598 e.stopPropagation();
599 e.stopImmediatePropagation();
600
601 let pointer_content = '. json_encode( $pointer_content_epaa ) .';
602 let pointer_target = jQuery( this ).parent( ".cozmoslabs-toggle-container" );
603
604 if( e && e.currentTarget && jQuery( e.currentTarget ).hasClass( "cozmoslabs-form-field-label" ) ) {
605 pointer_target = jQuery( this );
606 }
607
608 pointer_target.pointer({
609 content: pointer_content,
610 position: { edge: "right", align: "middle" }
611 }).pointer("open");
612 });
613 }
614
615 if( $(".row-visibility").length > 0 ) {
616
617 $("select#visibility").on("mousedown", function(e) {
618 e.preventDefault();
619 e.stopPropagation();
620 e.stopImmediatePropagation();
621
622 let pointer_content = '. json_encode( $pointer_content_fv ) .';
623
624 jQuery( this ).pointer({
625 content: pointer_content,
626 position: { edge: "right", align: "middle" }
627 }).pointer("open");
628 });
629
630 }
631
632 if( $(".row-user-role-visibility").length > 0 ) {
633
634 $(".row-user-role-visibility .wck-checkboxes input").attr("disabled", true).css("pointer-events", "none");
635
636 $(".row-user-role-visibility .wck-checkboxes").on("click", function(e) {
637 e.preventDefault();
638 e.stopPropagation();
639 e.stopImmediatePropagation();
640
641 let pointer_content = '. json_encode( $pointer_content_fv ) .';
642
643 jQuery( this ).pointer({
644 content: pointer_content,
645 position: { edge: "right", align: "middle" }
646 }).pointer("open");
647 });
648
649 }
650
651 if( $(".row-location-visibility").length > 0 ) {
652
653 $(".row-location-visibility .wck-checkboxes input").attr("disabled", true).css("pointer-events", "none");
654
655 $(".row-location-visibility .wck-checkboxes").on("click", function(e) {
656 e.preventDefault();
657 e.stopPropagation();
658 e.stopImmediatePropagation();
659
660 let pointer_content = '. json_encode( $pointer_content_fv ) .';
661
662 jQuery( this ).pointer({
663 content: pointer_content,
664 position: { edge: "right", align: "middle" }
665 }).pointer("open");
666 });
667
668 }
669
670 }
671
672 });
673 </script>';
674 }
675 }
676
677 }
678
679 function wppb_filter_own_post_creation( $data, $postarr ) {
680 if ( in_array( $data['post_type'], [ 'wppb-rf-cpt', 'wppb-epf-cpt', 'wppb-ul-cpt' ] ) && empty( $postarr['ID'] ) ) {
681
682 $license_status = wppb_get_serial_number_status();
683
684 if( $license_status != 'valid' ) {
685 wp_die( 'An active Profile Builder license is required to create new posts of this type.' );
686 }
687
688 }
689
690 return $data;
691 }
692 add_filter( 'wp_insert_post_data', 'wppb_filter_own_post_creation', 10, 2 );
693
694 add_filter( 'wck_update_meta_filter_values_wppb_manage_fields', 'wppb_filter_extra_manage_fields_options', 10, 2 );
695 function wppb_filter_extra_manage_fields_options( $values, $element_id ) {
696
697 $license_status = wppb_get_serial_number_status();
698
699 if( $license_status == 'valid' )
700 return $values;
701
702 if( !empty( $values['id'] ) ) {
703 $manage_fields = get_option( 'wppb_manage_fields', array() );
704 $existing_field = false;
705
706 if( !empty( $manage_fields ) ) {
707 foreach( $manage_fields as $field ) {
708 if( $field['id'] == $values['id'] ) {
709 $existing_field = $field;
710 break;
711 }
712 }
713 }
714
715 if( !empty( $existing_field ) ) {
716
717 $target_keys = [
718 'visibility',
719 'location-visibility',
720 'user-role-visibility',
721 'conditional-logic-enabled',
722 'edit-profile-approved-by-admin',
723 ];
724
725 foreach( $target_keys as $key ) {
726 if( !empty( $existing_field[$key] ) ) {
727 $values[$key] = $existing_field[$key];
728 }
729 }
730
731 }
732
733 }
734
735 return $values;
736
737 }
738
739 function wppb_international_telephone_input_admin_notification() {
740
741 if( !current_user_can( 'manage_options' ) )
742 return;
743
744 /* initiate the plugin notifications class */
745 $notifications = WPPB_Plugin_Notifications::get_instance();
746 /* this must be unique */
747 $notification_id = 'wppb_international_telephone_input_notification_pb';
748
749 $docs_url = 'https://www.cozmoslabs.com/docs/profile-builder/manage-user-fields/international-telephone-input/';
750 $notification_message = '<p style="font-size: 15px; margin-top:4px;">' . __( 'Let users pick their country, see flags and placeholders, and validate numbers in a familiar format.', 'profile-builder' ) . '</p>';
751
752 $docs_link = sprintf( __( '%1$sRead the documentation%2$s', 'profile-builder' ), '<a href="' . esc_url( $docs_url ) . '" target="_blank" rel="noopener noreferrer">', '</a>' );
753
754 $buy_url = 'https://www.cozmoslabs.com/wordpress-profile-builder/?utm_source=wpbackend&utm_medium=clientsite&utm_content=international_telephone_input_notification&utm_campaign=PBFree#pricing';
755
756 if( defined( 'WPPB_PAID_PLUGIN_DIR' ) ) {
757 $extra_message = sprintf(
758 /* translators: 1: documentation link (HTML), 2: opening Form Fields link, 3: closing Form Fields link */
759 __( '%1$s to set it up, or add the field under %2$sProfile Builder → Form Fields%3$s.', 'profile-builder' ),
760 $docs_link,
761 '<a href="' . esc_url( admin_url( 'admin.php?page=manage-fields' ) ) . '">',
762 '</a>'
763 );
764 } else {
765 $extra_message = sprintf(
766 /* translators: 1: documentation link (HTML), 2: opening upgrade link, 3: closing upgrade link */
767 __( '%1$s. This field is available in Profile Builder Basic and Pro. %2$sUpgrade now%3$s to use it.', 'profile-builder' ),
768 $docs_link,
769 '<a href="' . esc_url( $buy_url ) . '" target="_blank" rel="noopener noreferrer">',
770 '</a>'
771 );
772 }
773
774 $notification_message .= '<p style="font-size: 15px; margin-top:4px; padding-left: 77px;">' . $extra_message . '</p>';
775
776 $ul_icon_url = ( file_exists( WPPB_PLUGIN_DIR . 'assets/images/pb-logo.svg' ) ) ? WPPB_PLUGIN_URL . 'assets/images/pb-logo.svg' : '';
777 $ul_icon = ( !empty( $ul_icon_url ) ) ? '<img src="' . esc_url( $ul_icon_url ) . '" width="64" height="64" style="float: left; margin: 15px 12px 15px 0; max-width: 100px;" alt="Profile Builder">' : '';
778
779 $message = $ul_icon;
780 $message .= '<h3 style="margin-bottom: 0;">' . esc_html__( 'New field: International Telephone Input.', 'profile-builder' ) . '</h3>';
781 $message .= $notification_message;
782 $message .= '<a href="' . esc_url( wp_nonce_url( add_query_arg( array( 'wppb_dismiss_admin_notification' => $notification_id ) ), 'wppb_plugin_notice_dismiss' ) ) . '" type="button" class="notice-dismiss"><span class="screen-reader-text">' . esc_html__( 'Dismiss this notice.', 'profile-builder' ) . '</span></a>';
783
784 $notifications->add_notification( $notification_id, $message, 'wppb-notice notice notice-info', true, array( 'manage-fields' ) );
785
786 }
787 add_action( 'admin_init', 'wppb_international_telephone_input_admin_notification' );
788
789 /**
790 * Get the Profile Builder Page or Post slug
791 *
792 */
793 function wppb_get_pb_page_post_slug() {
794 if ( isset( $_GET['post_type'] ) )
795 $post_type = sanitize_text_field( $_GET['post_type'] );
796 elseif ( isset( $_GET['post'] ) )
797 $post_type = get_post_type( (int)$_GET['post'] );
798 elseif ( isset( $_GET['page'] ) )
799 $post_type = sanitize_text_field( $_GET['page'] );
800 else $post_type = '';
801
802 $possible_slugs = array(
803 'pb',
804 'wppb',
805 'profile-builder',
806 'user-email-customizer',
807 'admin-email-customizer',
808 'manage-fields',
809 'custom-redirects',
810 'profile-user-profile-picture'
811 );
812
813 if ( !empty( $post_type ) ) {
814 foreach ( $possible_slugs as $slug ) {
815 if ( ($post_type === $slug || strpos( $post_type, $slug ) === 0) && strpos($post_type, 'pb_backupbuddy') === false ) {
816
817 return $post_type;
818
819 }
820 }
821 }
822
823 return '';
824 }
825
826 /**
827 * Insert the PB Admin area Header Banner
828 *
829 */
830 function wppb_insert_page_banner() {
831 $pb_slug = wppb_get_pb_page_post_slug();
832
833 if ( $pb_slug === 'profile-builder-dashboard' && isset( $_GET['subpage'] ) && $_GET['subpage'] === 'wppb-setup' )
834 return;
835
836 $page_name = '';
837 if ( $pb_slug == 'profile-builder-add-ons' )
838 $page_name = ' Add-Ons';
839
840 if ( !empty( $pb_slug ) )
841 wppb_output_page_banner($page_name);
842
843 }
844 add_action( 'in_admin_header', 'wppb_insert_page_banner' );
845
846 /**
847 * Output the PB Admin area Header Banner content
848 *
849 */
850 function wppb_output_page_banner( $page_name ) {
851
852 $upgrade_button = '<a class="cozmoslabs-banner-link cozmoslabs-upgrade-link" href="https://www.cozmoslabs.com/wordpress-profile-builder/?utm_source=pb-settings&utm_medium=client-site&utm_campaign=pb-header-upsell#pricing" target="_blank">
853 <img src="'. esc_url(WPPB_PLUGIN_URL) . 'assets/images/upgrade-link-icon.svg" alt="">
854 Upgrade to PRO
855 </a>';
856
857 $upgrade_button_basic = '<a class="cozmoslabs-banner-link cozmoslabs-upgrade-link" href="https://www.cozmoslabs.com/wordpress-profile-builder/?utm_source=pb-settings&utm_medium=client-site&utm_campaign=pb-header-upsell#pricing" target="_blank">
858 <img src="'. esc_url(WPPB_PLUGIN_URL) . 'assets/images/upgrade-link-icon.svg" alt="">
859 Upgrade to PRO
860 </a>';
861
862 $support_url = 'https://wordpress.org/support/plugin/profile-builder/';
863
864 $output = '<div class="cozmoslabs-banner">
865 <div class="cozmoslabs-banner-title">
866 <img src="'. esc_url(WPPB_PLUGIN_URL) . 'assets/images/pb-logo.svg" alt="">
867 <h4>Profile Builder'. $page_name .'</h4>
868 </div>
869 <div class="cozmoslabs-banner-buttons">
870 <a class="cozmoslabs-banner-link cozmoslabs-support-link" href="'. $support_url .'" target="_blank">
871 <img src="'. esc_url(WPPB_PLUGIN_URL) . 'assets/images/support-link-icon.svg" alt="">
872 Support
873 </a>
874
875 <a class="cozmoslabs-banner-link cozmoslabs-documentation-link" href="https://www.cozmoslabs.com/docs/profile-builder/?utm_source=pb-settings&utm_medium=client-site&utm_campaign=pb-header-upsell" target="_blank">
876 <img src="'. esc_url(WPPB_PLUGIN_URL) . 'assets/images/docs-link-icon.svg" alt="">
877 Documentation
878 </a>';
879
880 if ( !defined( 'WPPB_PAID_PLUGIN_DIR' ) || ( defined( 'PROFILE_BUILDER_PAID_VERSION' ) && PROFILE_BUILDER_PAID_VERSION === 'dev' ) )
881 $output .= $upgrade_button;
882
883 // Add Basic version upgrade button (not to account, to plugin purchase page)
884 if( defined( 'PROFILE_BUILDER' ) && PROFILE_BUILDER == 'Profile Builder Basic' ){
885 $output .= $upgrade_button_basic;
886 }
887
888 $output .= ' </div>
889 </div>';
890
891 echo $output; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
892 }
893
894
895 /**
896 * Remove PMS Styles from PB Pages and Posts
897 *
898 */
899 function wppb_maybe_remove_pms_styles() {
900 if ( !empty( wppb_get_pb_page_post_slug() ) && wp_style_is('pms-style-back-end', 'enqueued') ) {
901 wp_dequeue_style('pms-style-back-end');
902 }
903 }
904 add_action('admin_enqueue_scripts', 'wppb_maybe_remove_pms_styles', 100);
905
906
907 /**
908 * Output the deactivation confirmation popup on the Plugins page
909 *
910 */
911 function wppb_output_deactivation_popup() {
912
913 if ( defined( 'WPPB_PAID_PLUGIN_DIR' ) )
914 return;
915
916 $screen = get_current_screen();
917
918 if ( empty( $screen ) )
919 return;
920
921 $is_plugins_screen = in_array( $screen->base, array( 'plugins', 'plugins-network' ), true ) || in_array( $screen->id, array( 'plugins', 'plugins-network' ), true );
922
923 if ( !$is_plugins_screen )
924 return;
925
926 ?>
927 <div id="wppb-deactivation-popup" title="<?php esc_attr_e( 'Before You Go', 'profile-builder' ); ?>" data-plugin="<?php echo esc_attr( WPPB_PLUGIN_BASENAME ); ?>">
928 <div class="wppb-deactivation-popup-header">
929 <img src="<?php echo esc_url( WPPB_PLUGIN_URL . 'assets/images/pb-logo.svg' ); ?>" alt="<?php esc_attr_e( 'Profile Builder', 'profile-builder' ); ?>" width="44" height="44">
930
931 <p class="wppb-deactivation-popup-description">
932 <?php esc_html_e( 'If you have a moment, please share the reason you are deactivating Profile Builder:', 'profile-builder' ); ?>
933 </p>
934 </div>
935
936 <form class="wppb-deactivation-popup-form">
937 <fieldset class="wppb-deactivation-popup-fieldset">
938 <label class="wppb-deactivation-popup-option">
939 <input type="radio" name="wppb_deactivation_reason" value="dont_need_it">
940 <span><?php esc_html_e( 'I no longer need the plugin', 'profile-builder' ); ?></span>
941 </label>
942
943 <label class="wppb-deactivation-popup-option">
944 <input type="radio" name="wppb_deactivation_reason" value="switched_to_another_plugin">
945 <span><?php esc_html_e( 'I found a better plugin', 'profile-builder' ); ?></span>
946 <input type="text" name="switched_to_another_plugin_reason" class="wppb-deactivation-popup-extra" data-reason="switched_to_another_plugin" placeholder="<?php esc_attr_e( 'Which plugin', 'profile-builder' ); ?>">
947 </label>
948
949 <label class="wppb-deactivation-popup-option">
950 <input type="radio" name="wppb_deactivation_reason" value="missing_features">
951 <span><?php esc_html_e( 'I didn\'t find the feature I need', 'profile-builder' ); ?></span>
952 <input type="text" name="missing_features_reason" class="wppb-deactivation-popup-extra" data-reason="missing_features" placeholder="<?php esc_attr_e( 'Which feature', 'profile-builder' ); ?>">
953 </label>
954
955 <label class="wppb-deactivation-popup-option">
956 <input type="radio" name="wppb_deactivation_reason" value="did_not_work">
957 <span><?php esc_html_e( 'I couldn\'t get the plugin to work', 'profile-builder' ); ?></span>
958 </label>
959
960 <label class="wppb-deactivation-popup-option">
961 <input type="radio" name="wppb_deactivation_reason" value="temporary_deactivation">
962 <span><?php esc_html_e( 'Temporary deactivation', 'profile-builder' ); ?></span>
963 </label>
964
965 <label class="wppb-deactivation-popup-option">
966 <input type="radio" name="wppb_deactivation_reason" value="other">
967 <span><?php esc_html_e( 'Other', 'profile-builder' ); ?></span>
968 <input type="text" name="other_reason" class="wppb-deactivation-popup-extra" data-reason="other" placeholder="<?php esc_attr_e( 'Please tell us more', 'profile-builder' ); ?>">
969 </label>
970 </fieldset>
971
972 <p class="wppb-deactivation-popup-error"></p>
973 </form>
974
975 <div class="wppb-deactivation-popup-actions">
976 <button type="button" class="button button-primary wppb-deactivation-popup-confirm">
977 <?php esc_html_e( 'Submit & deactivate', 'profile-builder' ); ?>
978 </button>
979
980 <button type="button" class="button wppb-deactivation-popup-skip">
981 <?php esc_html_e( 'Skip & deactivate', 'profile-builder' ); ?>
982 </button>
983 </div>
984 </div>
985 <style>
986 #wppb-deactivation-popup {
987 display: none;
988 }
989
990 .wppb-deactivation-popup-header {
991 display: flex;
992 align-items: center;
993 gap: 16px;
994 margin-bottom: 20px;
995 }
996
997 .wppb-deactivation-popup-description {
998 margin: 0;
999 }
1000
1001 .wppb-deactivation-popup-fieldset {
1002 margin: 0;
1003 padding: 0;
1004 border: 0;
1005 }
1006
1007 .wppb-deactivation-popup-option {
1008 display: block;
1009 margin-bottom: 12px;
1010 }
1011
1012 .wppb-deactivation-popup-extra {
1013 display: none;
1014 width: 100%;
1015 margin-top: 8px;
1016 }
1017
1018 .wppb-deactivation-popup-error {
1019 display: none;
1020 color: #b32d2e;
1021 margin: 0px 0px 12px 0px;
1022 }
1023
1024 .wppb-deactivation-popup-actions {
1025 display: flex;
1026 align-items: center;
1027 justify-content: space-between;
1028 gap: 12px;
1029 }
1030
1031 .wppb-deactivation-popup-extra.error {
1032 border: 1px solid #b32d2e;
1033 }
1034
1035 .ui-dialog[aria-describedby="wppb-deactivation-popup"] .ui-dialog-titlebar {
1036 background: transparent;
1037 border: none;
1038 }
1039 </style>
1040 <?php
1041 }
1042 add_action( 'admin_footer', 'wppb_output_deactivation_popup' );
1043
1044
1045 /**
1046 * Check if current screen is a Profile Builder admin page.
1047 *
1048 * @return bool
1049 */
1050 function wppb_is_profile_builder_admin_page() {
1051
1052 if ( ! is_admin() )
1053 return false;
1054
1055 $screen = get_current_screen();
1056
1057 if ( ! $screen )
1058 return false;
1059
1060 $pb_pages = array(
1061 'profile-builder',
1062 'profile-builder-dashboard',
1063 'profile-builder-basic-info',
1064 'profile-builder-general-settings',
1065 'profile-builder-add-ons',
1066 'manage-fields',
1067 );
1068
1069 foreach ( $pb_pages as $page ) {
1070
1071 if ( strpos( $screen->id, $page ) !== false )
1072 return true;
1073
1074 }
1075
1076 if ( ! empty( $screen->post_type ) ) {
1077 $pb_cpt_pages = array( 'wppb-ul-cpt', 'wppb-rf-cpt', 'wppb-epf-cpt' );
1078
1079 if ( in_array( $screen->post_type, $pb_cpt_pages, true ) )
1080 return true;
1081 }
1082
1083 return false;
1084 }
1085
1086
1087 /**
1088 * Output the popup markup used for documentation links from the admin.
1089 *
1090 * @return void
1091 */
1092 function wppb_output_docs_link_popup() {
1093
1094 if ( ! wppb_is_profile_builder_admin_page() )
1095 return;
1096
1097 ?>
1098 <div id="wppb-docs-link-popup" class="wppb-docs-link-popup" title="<?php echo esc_attr__( 'Need Help?', 'profile-builder' ); ?>" style="display:none;">
1099 <div class="wppb-docs-link-popup-content">
1100 <img src="<?php echo esc_url( WPPB_PLUGIN_URL . 'assets/images/pb-logo.svg' ); ?>" alt="<?php esc_attr_e( 'Profile Builder', 'profile-builder' ); ?>" width="44" height="44" class="wppb-docs-link-popup-logo">
1101 <div>
1102 <p class="wppb-docs-link-popup-description"><?php esc_html_e( 'If you need a hand with this setting, you can check the documentation or open a support ticket on WordPress.org.', 'profile-builder' ); ?></p>
1103 <p class="wppb-docs-link-popup-description"><?php esc_html_e( 'We will do our best to help you figure it out.', 'profile-builder' ); ?></p>
1104 </div>
1105 </div>
1106 <div class="wppb-docs-link-popup-actions cozmoslabs-wrap">
1107 <a href="#" target="_blank" rel="noopener noreferrer" class="button button-primary wppb-docs-link-popup-open-docs"><?php esc_html_e( 'View Documentation', 'profile-builder' ); ?></a>
1108 <a href="https://wordpress.org/support/plugin/profile-builder/#new-topic-0" target="_blank" rel="noopener noreferrer" class="button button-primary wppb-docs-link-popup-open-wporg"><?php esc_html_e( 'Open Support Ticket', 'profile-builder' ); ?></a>
1109 </div>
1110 </div>
1111 <?php
1112 }
1113 add_action( 'admin_footer', 'wppb_output_docs_link_popup' );
1114