| 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 |
/** |
| 233 |
* Send deactivation feedback from the plugins screen modal. |
| 234 |
* |
| 235 |
* @param array $reason_data Sanitized reason payload from the popup form. |
| 236 |
*/ |
| 237 |
function wppb_send_deactivation_feedback( $reason_data ) { |
| 238 |
|
| 239 |
if ( ! is_array( $reason_data ) || empty( $reason_data['reason'] ) ) |
| 240 |
return; |
| 241 |
|
| 242 |
$body = array( |
| 243 |
'unique_identifier' => hash( 'sha256', home_url( '', 'https' ) ), |
| 244 |
'product' => 'wppb', |
| 245 |
'action' => 'end', |
| 246 |
'reason' => sanitize_key( $reason_data['reason'] ), |
| 247 |
); |
| 248 |
|
| 249 |
$reason_key = $reason_data['reason'] . '_reason'; |
| 250 |
|
| 251 |
if ( ! empty( $reason_data[ $reason_key ] ) ) |
| 252 |
$body['extra_metadata'] = sanitize_text_field( $reason_data[ $reason_key ] ); |
| 253 |
|
| 254 |
wp_remote_post( 'https://usagetracker.cozmoslabs.com/syncPlugin', array( |
| 255 |
'body' => $body, |
| 256 |
'timeout' => 3, |
| 257 |
'blocking' => false, |
| 258 |
) ); |
| 259 |
} |
| 260 |
|
| 261 |
/** |
| 262 |
* Store the deactivation reason selected in the popup |
| 263 |
*/ |
| 264 |
function wppb_store_deactivation_reason() { |
| 265 |
|
| 266 |
if ( ! check_ajax_referer( 'wppb_deactivation_reason', 'nonce', false ) ) |
| 267 |
wp_send_json_error( array( 'message' => __( 'We could not verify your request. Please refresh the page and try again.', 'profile-builder' ) ), 403 ); |
| 268 |
|
| 269 |
if ( ! current_user_can( 'activate_plugins' ) ) |
| 270 |
wp_send_json_error( array( 'message' => __( 'You do not have permission to deactivate plugins on this site.', 'profile-builder' ) ), 403 ); |
| 271 |
|
| 272 |
$valid_reasons = array( |
| 273 |
'dont_need_it', |
| 274 |
'switched_to_another_plugin', |
| 275 |
'missing_features', |
| 276 |
'did_not_work', |
| 277 |
'temporary_deactivation', |
| 278 |
'other', |
| 279 |
'skip', |
| 280 |
); |
| 281 |
|
| 282 |
$reason = ''; |
| 283 |
|
| 284 |
if ( isset( $_POST['reason'] ) ) |
| 285 |
$reason = sanitize_key( wp_unslash( $_POST['reason'] ) ); |
| 286 |
|
| 287 |
if ( ! in_array( $reason, $valid_reasons, true ) ) |
| 288 |
wp_send_json_error( array( 'message' => __( 'We could not save your deactivation feedback. Please try again.', 'profile-builder' ) ), 400 ); |
| 289 |
|
| 290 |
$reason_data = array( |
| 291 |
'reason' => $reason, |
| 292 |
); |
| 293 |
|
| 294 |
if ( $reason === 'switched_to_another_plugin' && ! empty( $_POST['switched_to_another_plugin_reason'] ) ) |
| 295 |
$reason_data['switched_to_another_plugin_reason'] = sanitize_text_field( wp_unslash( $_POST['switched_to_another_plugin_reason'] ) ); |
| 296 |
|
| 297 |
if ( $reason === 'missing_features' && ! empty( $_POST['missing_features_reason'] ) ) |
| 298 |
$reason_data['missing_features_reason'] = sanitize_text_field( wp_unslash( $_POST['missing_features_reason'] ) ); |
| 299 |
|
| 300 |
if ( $reason === 'other' && ! empty( $_POST['other_reason'] ) ) |
| 301 |
$reason_data['other_reason'] = sanitize_text_field( wp_unslash( $_POST['other_reason'] ) ); |
| 302 |
|
| 303 |
wppb_send_deactivation_feedback( $reason_data ); |
| 304 |
|
| 305 |
wp_send_json_success(); |
| 306 |
} |
| 307 |
add_action( 'wp_ajax_wppb_store_deactivation_reason', 'wppb_store_deactivation_reason' ); |
| 308 |
|
| 309 |
/* hook to create pages for out forms when a user press the create pages/setup button */ |
| 310 |
add_action( 'admin_init', 'wppb_create_form_pages' ); |
| 311 |
function wppb_create_form_pages(){ |
| 312 |
|
| 313 |
if( !isset( $_GET['page'] ) || $_GET['page'] != 'profile-builder-basic-info' || !isset( $_GET['wppb_create_pages'] ) || $_GET['wppb_create_pages'] != 'true' ) |
| 314 |
return; |
| 315 |
|
| 316 |
if( !isset( $_GET['_wpnonce'] ) || !wp_verify_nonce( sanitize_text_field( $_GET['_wpnonce'] ), 'wppb_create_pages' ) ) |
| 317 |
return; |
| 318 |
|
| 319 |
if( !current_user_can( 'manage_options' ) ) |
| 320 |
return; |
| 321 |
|
| 322 |
$wppb_pages_created = get_option( 'wppb_pages_created' ); |
| 323 |
|
| 324 |
if( empty( $wppb_pages_created ) || ( isset( $_GET['wppb_force_create_pages'] ) && $_GET['wppb_force_create_pages'] === 'true' ) ) { |
| 325 |
$register_page = array( |
| 326 |
'post_title' => 'Register', |
| 327 |
'post_content' => '[wppb-register]', |
| 328 |
'post_status' => 'publish', |
| 329 |
'post_type' => 'page' |
| 330 |
); |
| 331 |
$register_id = wp_insert_post($register_page); |
| 332 |
|
| 333 |
$edit_page = array( |
| 334 |
'post_title' => 'Edit Profile', |
| 335 |
'post_content' => '[wppb-edit-profile]', |
| 336 |
'post_status' => 'publish', |
| 337 |
'post_type' => 'page' |
| 338 |
); |
| 339 |
$edit_id = wp_insert_post($edit_page); |
| 340 |
|
| 341 |
$login_page = array( |
| 342 |
'post_title' => 'Log In', |
| 343 |
'post_content' => '[wppb-login]', |
| 344 |
'post_status' => 'publish', |
| 345 |
'post_type' => 'page' |
| 346 |
); |
| 347 |
$login_id = wp_insert_post($login_page); |
| 348 |
|
| 349 |
update_option('wppb_pages_created', 'true' ); |
| 350 |
|
| 351 |
wp_safe_redirect( admin_url('edit.php?s=%5Bwppb-&post_status=all&post_type=page&action=-1&m=0&paged=1&action2=-1') ); |
| 352 |
} |
| 353 |
} |
| 354 |
|
| 355 |
/** |
| 356 |
* Function that prepares labels to pass to the WCK api...we have a quirk in wck api that labels are wrapped |
| 357 |
* in %label%...so if we want to have % inside the label for example 25% off...we will have a bad time |
| 358 |
* @param string $label |
| 359 |
* @return string|string[] |
| 360 |
*/ |
| 361 |
function wppb_prepare_wck_labels( $label ){ |
| 362 |
return trim( str_replace( '%', '%', $label ) ); |
| 363 |
} |
| 364 |
|
| 365 |
/** |
| 366 |
* Function that returns the reserved meta name list |
| 367 |
*/ |
| 368 |
function wppb_get_reserved_meta_name_list( $all_fields, $posted_values ){ |
| 369 |
|
| 370 |
$unique_meta_name_list = array( 'first_name', 'last_name', 'nickname', 'description', 'role' ); |
| 371 |
|
| 372 |
// Default contact methods were removed in WP 3.6. A filter dictates contact methods. |
| 373 |
if ( apply_filters( 'wppb_remove_default_contact_methods', get_site_option( 'initial_db_version' ) < 23588 ) ){ |
| 374 |
$unique_meta_name_list[] = 'aim'; |
| 375 |
$unique_meta_name_list[] = 'yim'; |
| 376 |
$unique_meta_name_list[] = 'jabber'; |
| 377 |
} |
| 378 |
|
| 379 |
$add_reserved = true; |
| 380 |
|
| 381 |
// source: https://codex.wordpress.org/Reserved_Terms |
| 382 |
$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', |
| 383 |
'comments_popup', 'custom', 'customize_messenger_channel', 'customized', 'cpage', 'day', 'debug', 'embed', 'error', 'exact', 'feed', 'fields', 'hour', 'link_category', 'm', 'map', 'minute', 'monthnum', 'more', |
| 384 |
'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', |
| 385 |
'post_status', 'post_tag', 'post_type', 'posts', 'posts_per_archive_page', 'posts_per_page', 'preview', 'robots', 's', 'search', 'second', 'sentence', 'showposts', 'static', 'status', 'subpost', |
| 386 |
'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' ); |
| 387 |
|
| 388 |
$args = array( |
| 389 |
'public' => true, |
| 390 |
'_builtin' => true |
| 391 |
); |
| 392 |
$post_types = get_post_types( $args, 'names', 'or' ); |
| 393 |
$taxonomies = get_taxonomies( $args, 'names', 'or' ); |
| 394 |
|
| 395 |
|
| 396 |
/*reserved meta names were added in PB 3.1.2 so to avoid the situation where someone updates an already existing field |
| 397 |
with a reserved name and gets an error check if it is an update or new field */ |
| 398 |
if( !empty( $all_fields ) && !empty($posted_values['id'] ) && !empty($posted_values['meta-name']) ){ |
| 399 |
foreach( $all_fields as $field ){ |
| 400 |
if( $field['id'] === $posted_values['id'] && $field['meta-name'] === $posted_values['meta-name'] ){//it is an update |
| 401 |
$add_reserved = false; |
| 402 |
} |
| 403 |
} |
| 404 |
} |
| 405 |
|
| 406 |
if( $add_reserved ) |
| 407 |
$unique_meta_name_list = array_merge( $unique_meta_name_list, $reserved_meta_names, $post_types, $taxonomies ); |
| 408 |
|
| 409 |
return apply_filters ( 'wppb_unique_meta_name_list', $unique_meta_name_list ); |
| 410 |
} |
| 411 |
|
| 412 |
add_action('admin_head', 'wppb_maybe_remove_add_new_button_for_cpt' ); |
| 413 |
function wppb_maybe_remove_add_new_button_for_cpt() { |
| 414 |
|
| 415 |
global $pagenow; |
| 416 |
|
| 417 |
$target_slugs = [ 'wppb-rf-cpt', 'wppb-epf-cpt', 'wppb-ul-cpt' ]; |
| 418 |
$current_slug = ''; |
| 419 |
$pointer_content = ''; |
| 420 |
|
| 421 |
$correct_page = false; |
| 422 |
|
| 423 |
if ( $pagenow === 'edit.php' && isset( $_GET['post_type'] ) && in_array( sanitize_text_field( $_GET['post_type'] ), $target_slugs ) ) { |
| 424 |
$correct_page = true; |
| 425 |
$current_slug = sanitize_text_field( $_GET['post_type'] ); |
| 426 |
} else if( $pagenow === 'post.php' && isset( $_GET['post'] ) ) { |
| 427 |
|
| 428 |
$post_type = get_post_type( absint( $_GET['post'] ) ); |
| 429 |
|
| 430 |
if ( in_array( $post_type, $target_slugs ) ) { |
| 431 |
$correct_page = true; |
| 432 |
$current_slug = $post_type; |
| 433 |
} |
| 434 |
|
| 435 |
} |
| 436 |
|
| 437 |
if ( $correct_page ) { |
| 438 |
$license_status = wppb_get_serial_number_status(); |
| 439 |
|
| 440 |
if( $current_slug === 'wppb-rf-cpt' ) { |
| 441 |
if( $license_status == 'missing' ) { |
| 442 |
$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>'; |
| 443 |
} else { |
| 444 |
$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>'; |
| 445 |
} |
| 446 |
} else if( $current_slug === 'wppb-epf-cpt' ) { |
| 447 |
if( $license_status == 'missing' ) { |
| 448 |
$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>'; |
| 449 |
} else { |
| 450 |
$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>'; |
| 451 |
} |
| 452 |
} else if( $current_slug === 'wppb-ul-cpt' ) { |
| 453 |
if( $license_status == 'missing' ) { |
| 454 |
$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>'; |
| 455 |
} else { |
| 456 |
$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>'; |
| 457 |
} |
| 458 |
} |
| 459 |
|
| 460 |
if( $license_status !== 'valid' ) { |
| 461 |
wp_enqueue_style('wp-pointer'); |
| 462 |
wp_enqueue_script('wp-pointer'); |
| 463 |
|
| 464 |
echo ' |
| 465 |
<script> |
| 466 |
jQuery(document).ready(function($) { |
| 467 |
let button_text = $(".page-title-action").text(); |
| 468 |
$(".page-title-action").remove(); |
| 469 |
|
| 470 |
$(".wrap .wp-heading-inline").after(`<a class="page-title-action page-title-action-disabled" style="cursor:pointer;">${button_text}</a>`); |
| 471 |
|
| 472 |
$(".page-title-action-disabled").on("click", function(e) { |
| 473 |
e.preventDefault(); |
| 474 |
|
| 475 |
let pointer_content = '. json_encode( $pointer_content ) .'; |
| 476 |
|
| 477 |
jQuery( this ).pointer({ |
| 478 |
content: pointer_content, |
| 479 |
position: { edge: "right", align: "middle" } |
| 480 |
}).pointer("open"); |
| 481 |
}); |
| 482 |
}); |
| 483 |
</script>'; |
| 484 |
} |
| 485 |
|
| 486 |
} |
| 487 |
|
| 488 |
// This shows the Add new button. Since the above action removes it completelty, we can just attempt to show it here |
| 489 |
echo '<script> |
| 490 |
jQuery(document).ready(function($) { |
| 491 |
if( $(".page-title-action").length > 0 ) { |
| 492 |
$(".page-title-action").css("display", "inline-flex"); |
| 493 |
} |
| 494 |
}); |
| 495 |
</script>'; |
| 496 |
|
| 497 |
// Manage fields |
| 498 |
if( isset( $_GET['page'] ) && $_GET['page'] === 'manage-fields' ) { |
| 499 |
$license_status = wppb_get_serial_number_status(); |
| 500 |
$pointer_content_cl = ''; |
| 501 |
$pointer_content_fv = ''; |
| 502 |
$pointer_content_epaa = ''; |
| 503 |
|
| 504 |
if( $license_status == 'missing' ) { |
| 505 |
$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>'; |
| 506 |
$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>'; |
| 507 |
$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>'; |
| 508 |
} else { |
| 509 |
$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>'; |
| 510 |
$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>'; |
| 511 |
$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>'; |
| 512 |
} |
| 513 |
|
| 514 |
if( $license_status != 'valid' ) { |
| 515 |
wp_enqueue_style('wp-pointer'); |
| 516 |
wp_enqueue_script('wp-pointer'); |
| 517 |
|
| 518 |
echo ' |
| 519 |
<script> |
| 520 |
jQuery(document).ready(function($) { |
| 521 |
|
| 522 |
$(document).on( "wpbFormMetaLoaded", function(e, meta) { |
| 523 |
|
| 524 |
wppb_manage_fields_license_invalid( e ); |
| 525 |
|
| 526 |
}); |
| 527 |
|
| 528 |
wppb_manage_fields_license_invalid(); |
| 529 |
|
| 530 |
function wppb_manage_fields_license_invalid(){ |
| 531 |
|
| 532 |
if( $(".row-conditional-logic-enabled").length > 0 ) { |
| 533 |
|
| 534 |
$(".row-conditional-logic").hide(); |
| 535 |
|
| 536 |
$("#edit_form_conditional-logic-enabled_yes, label[for=conditional-logic-enabled_yes]").on("click", function(e) { |
| 537 |
e.preventDefault(); |
| 538 |
e.stopPropagation(); |
| 539 |
e.stopImmediatePropagation(); |
| 540 |
|
| 541 |
let pointer_content = '. json_encode( $pointer_content_cl ) .'; |
| 542 |
let pointer_target = jQuery( this ).parent( ".cozmoslabs-toggle-container" ); |
| 543 |
|
| 544 |
if( e && e.currentTarget && jQuery( e.currentTarget ).hasClass( "cozmoslabs-form-field-label" ) ) { |
| 545 |
pointer_target = jQuery( this ); |
| 546 |
} |
| 547 |
|
| 548 |
pointer_target.pointer({ |
| 549 |
content: pointer_content, |
| 550 |
position: { edge: "right", align: "middle" } |
| 551 |
}).pointer("open"); |
| 552 |
}); |
| 553 |
} |
| 554 |
|
| 555 |
if( $(".row-edit-profile-approved-by-admin").length > 0 ) { |
| 556 |
|
| 557 |
$("#edit_form_edit-profile-approved-by-admin_yes, label[for=edit-profile-approved-by-admin_yes]").on("click", function(e) { |
| 558 |
e.preventDefault(); |
| 559 |
e.stopPropagation(); |
| 560 |
e.stopImmediatePropagation(); |
| 561 |
|
| 562 |
let pointer_content = '. json_encode( $pointer_content_epaa ) .'; |
| 563 |
let pointer_target = jQuery( this ).parent( ".cozmoslabs-toggle-container" ); |
| 564 |
|
| 565 |
if( e && e.currentTarget && jQuery( e.currentTarget ).hasClass( "cozmoslabs-form-field-label" ) ) { |
| 566 |
pointer_target = jQuery( this ); |
| 567 |
} |
| 568 |
|
| 569 |
pointer_target.pointer({ |
| 570 |
content: pointer_content, |
| 571 |
position: { edge: "right", align: "middle" } |
| 572 |
}).pointer("open"); |
| 573 |
}); |
| 574 |
} |
| 575 |
|
| 576 |
if( $(".row-visibility").length > 0 ) { |
| 577 |
|
| 578 |
$("select#visibility").on("mousedown", function(e) { |
| 579 |
e.preventDefault(); |
| 580 |
e.stopPropagation(); |
| 581 |
e.stopImmediatePropagation(); |
| 582 |
|
| 583 |
let pointer_content = '. json_encode( $pointer_content_fv ) .'; |
| 584 |
|
| 585 |
jQuery( this ).pointer({ |
| 586 |
content: pointer_content, |
| 587 |
position: { edge: "right", align: "middle" } |
| 588 |
}).pointer("open"); |
| 589 |
}); |
| 590 |
|
| 591 |
} |
| 592 |
|
| 593 |
if( $(".row-user-role-visibility").length > 0 ) { |
| 594 |
|
| 595 |
$(".row-user-role-visibility .wck-checkboxes input").attr("disabled", true).css("pointer-events", "none"); |
| 596 |
|
| 597 |
$(".row-user-role-visibility .wck-checkboxes").on("click", function(e) { |
| 598 |
e.preventDefault(); |
| 599 |
e.stopPropagation(); |
| 600 |
e.stopImmediatePropagation(); |
| 601 |
|
| 602 |
let pointer_content = '. json_encode( $pointer_content_fv ) .'; |
| 603 |
|
| 604 |
jQuery( this ).pointer({ |
| 605 |
content: pointer_content, |
| 606 |
position: { edge: "right", align: "middle" } |
| 607 |
}).pointer("open"); |
| 608 |
}); |
| 609 |
|
| 610 |
} |
| 611 |
|
| 612 |
if( $(".row-location-visibility").length > 0 ) { |
| 613 |
|
| 614 |
$(".row-location-visibility .wck-checkboxes input").attr("disabled", true).css("pointer-events", "none"); |
| 615 |
|
| 616 |
$(".row-location-visibility .wck-checkboxes").on("click", function(e) { |
| 617 |
e.preventDefault(); |
| 618 |
e.stopPropagation(); |
| 619 |
e.stopImmediatePropagation(); |
| 620 |
|
| 621 |
let pointer_content = '. json_encode( $pointer_content_fv ) .'; |
| 622 |
|
| 623 |
jQuery( this ).pointer({ |
| 624 |
content: pointer_content, |
| 625 |
position: { edge: "right", align: "middle" } |
| 626 |
}).pointer("open"); |
| 627 |
}); |
| 628 |
|
| 629 |
} |
| 630 |
|
| 631 |
} |
| 632 |
|
| 633 |
}); |
| 634 |
</script>'; |
| 635 |
} |
| 636 |
} |
| 637 |
|
| 638 |
} |
| 639 |
|
| 640 |
function wppb_filter_own_post_creation( $data, $postarr ) { |
| 641 |
if ( in_array( $data['post_type'], [ 'wppb-rf-cpt', 'wppb-epf-cpt', 'wppb-ul-cpt' ] ) && empty( $postarr['ID'] ) ) { |
| 642 |
|
| 643 |
$license_status = wppb_get_serial_number_status(); |
| 644 |
|
| 645 |
if( $license_status != 'valid' ) { |
| 646 |
wp_die( 'An active Profile Builder license is required to create new posts of this type.' ); |
| 647 |
} |
| 648 |
|
| 649 |
} |
| 650 |
|
| 651 |
return $data; |
| 652 |
} |
| 653 |
add_filter( 'wp_insert_post_data', 'wppb_filter_own_post_creation', 10, 2 ); |
| 654 |
|
| 655 |
add_filter( 'wck_update_meta_filter_values_wppb_manage_fields', 'wppb_filter_extra_manage_fields_options', 10, 2 ); |
| 656 |
function wppb_filter_extra_manage_fields_options( $values, $element_id ) { |
| 657 |
|
| 658 |
$license_status = wppb_get_serial_number_status(); |
| 659 |
|
| 660 |
if( $license_status == 'valid' ) |
| 661 |
return $values; |
| 662 |
|
| 663 |
if( !empty( $values['id'] ) ) { |
| 664 |
$manage_fields = get_option( 'wppb_manage_fields', array() ); |
| 665 |
$existing_field = false; |
| 666 |
|
| 667 |
if( !empty( $manage_fields ) ) { |
| 668 |
foreach( $manage_fields as $field ) { |
| 669 |
if( $field['id'] == $values['id'] ) { |
| 670 |
$existing_field = $field; |
| 671 |
break; |
| 672 |
} |
| 673 |
} |
| 674 |
} |
| 675 |
|
| 676 |
if( !empty( $existing_field ) ) { |
| 677 |
|
| 678 |
$target_keys = [ |
| 679 |
'visibility', |
| 680 |
'location-visibility', |
| 681 |
'user-role-visibility', |
| 682 |
'conditional-logic-enabled', |
| 683 |
'edit-profile-approved-by-admin', |
| 684 |
]; |
| 685 |
|
| 686 |
foreach( $target_keys as $key ) { |
| 687 |
if( !empty( $existing_field[$key] ) ) { |
| 688 |
$values[$key] = $existing_field[$key]; |
| 689 |
} |
| 690 |
} |
| 691 |
|
| 692 |
} |
| 693 |
|
| 694 |
} |
| 695 |
|
| 696 |
return $values; |
| 697 |
|
| 698 |
} |
| 699 |
|
| 700 |
function wppb_international_telephone_input_admin_notification() { |
| 701 |
|
| 702 |
if( !current_user_can( 'manage_options' ) ) |
| 703 |
return; |
| 704 |
|
| 705 |
/* initiate the plugin notifications class */ |
| 706 |
$notifications = WPPB_Plugin_Notifications::get_instance(); |
| 707 |
/* this must be unique */ |
| 708 |
$notification_id = 'wppb_international_telephone_input_notification_pb'; |
| 709 |
|
| 710 |
$docs_url = 'https://www.cozmoslabs.com/docs/profile-builder/manage-user-fields/international-telephone-input/'; |
| 711 |
$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>'; |
| 712 |
|
| 713 |
$docs_link = sprintf( __( '%1$sRead the documentation%2$s', 'profile-builder' ), '<a href="' . esc_url( $docs_url ) . '" target="_blank" rel="noopener noreferrer">', '</a>' ); |
| 714 |
|
| 715 |
$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'; |
| 716 |
|
| 717 |
if( defined( 'WPPB_PAID_PLUGIN_DIR' ) ) { |
| 718 |
$extra_message = sprintf( |
| 719 |
/* translators: 1: documentation link (HTML), 2: opening Form Fields link, 3: closing Form Fields link */ |
| 720 |
__( '%1$s to set it up, or add the field under %2$sProfile Builder → Form Fields%3$s.', 'profile-builder' ), |
| 721 |
$docs_link, |
| 722 |
'<a href="' . esc_url( admin_url( 'admin.php?page=manage-fields' ) ) . '">', |
| 723 |
'</a>' |
| 724 |
); |
| 725 |
} else { |
| 726 |
$extra_message = sprintf( |
| 727 |
/* translators: 1: documentation link (HTML), 2: opening upgrade link, 3: closing upgrade link */ |
| 728 |
__( '%1$s. This field is available in Profile Builder Basic and Pro. %2$sUpgrade now%3$s to use it.', 'profile-builder' ), |
| 729 |
$docs_link, |
| 730 |
'<a href="' . esc_url( $buy_url ) . '" target="_blank" rel="noopener noreferrer">', |
| 731 |
'</a>' |
| 732 |
); |
| 733 |
} |
| 734 |
|
| 735 |
$notification_message .= '<p style="font-size: 15px; margin-top:4px; padding-left: 77px;">' . $extra_message . '</p>'; |
| 736 |
|
| 737 |
$ul_icon_url = ( file_exists( WPPB_PLUGIN_DIR . 'assets/images/pb-logo.svg' ) ) ? WPPB_PLUGIN_URL . 'assets/images/pb-logo.svg' : ''; |
| 738 |
$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">' : ''; |
| 739 |
|
| 740 |
$message = $ul_icon; |
| 741 |
$message .= '<h3 style="margin-bottom: 0;">' . esc_html__( 'New field: International Telephone Input.', 'profile-builder' ) . '</h3>'; |
| 742 |
$message .= $notification_message; |
| 743 |
$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>'; |
| 744 |
|
| 745 |
$notifications->add_notification( $notification_id, $message, 'wppb-notice notice notice-info', true, array( 'manage-fields' ) ); |
| 746 |
|
| 747 |
} |
| 748 |
add_action( 'admin_init', 'wppb_international_telephone_input_admin_notification' ); |
| 749 |
|
| 750 |
/** |
| 751 |
* Get the Profile Builder Page or Post slug |
| 752 |
* |
| 753 |
*/ |
| 754 |
function wppb_get_pb_page_post_slug() { |
| 755 |
if ( isset( $_GET['post_type'] ) ) |
| 756 |
$post_type = sanitize_text_field( $_GET['post_type'] ); |
| 757 |
elseif ( isset( $_GET['post'] ) ) |
| 758 |
$post_type = get_post_type( (int)$_GET['post'] ); |
| 759 |
elseif ( isset( $_GET['page'] ) ) |
| 760 |
$post_type = sanitize_text_field( $_GET['page'] ); |
| 761 |
else $post_type = ''; |
| 762 |
|
| 763 |
$possible_slugs = array( |
| 764 |
'pb', |
| 765 |
'wppb', |
| 766 |
'profile-builder', |
| 767 |
'user-email-customizer', |
| 768 |
'admin-email-customizer', |
| 769 |
'manage-fields', |
| 770 |
'custom-redirects', |
| 771 |
'profile-user-profile-picture' |
| 772 |
); |
| 773 |
|
| 774 |
if ( !empty( $post_type ) ) { |
| 775 |
foreach ( $possible_slugs as $slug ) { |
| 776 |
if ( ($post_type === $slug || strpos( $post_type, $slug ) === 0) && strpos($post_type, 'pb_backupbuddy') === false ) { |
| 777 |
|
| 778 |
return $post_type; |
| 779 |
|
| 780 |
} |
| 781 |
} |
| 782 |
} |
| 783 |
|
| 784 |
return ''; |
| 785 |
} |
| 786 |
|
| 787 |
/** |
| 788 |
* Insert the PB Admin area Header Banner |
| 789 |
* |
| 790 |
*/ |
| 791 |
function wppb_insert_page_banner() { |
| 792 |
$pb_slug = wppb_get_pb_page_post_slug(); |
| 793 |
|
| 794 |
if ( $pb_slug === 'profile-builder-dashboard' && isset( $_GET['subpage'] ) && $_GET['subpage'] === 'wppb-setup' ) |
| 795 |
return; |
| 796 |
|
| 797 |
$page_name = ''; |
| 798 |
if ( $pb_slug == 'profile-builder-add-ons' ) |
| 799 |
$page_name = ' Add-Ons'; |
| 800 |
|
| 801 |
if ( !empty( $pb_slug ) ) |
| 802 |
wppb_output_page_banner($page_name); |
| 803 |
|
| 804 |
} |
| 805 |
add_action( 'in_admin_header', 'wppb_insert_page_banner' ); |
| 806 |
|
| 807 |
/** |
| 808 |
* Output the PB Admin area Header Banner content |
| 809 |
* |
| 810 |
*/ |
| 811 |
function wppb_output_page_banner( $page_name ) { |
| 812 |
|
| 813 |
$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"> |
| 814 |
<img src="'. esc_url(WPPB_PLUGIN_URL) . 'assets/images/upgrade-link-icon.svg" alt=""> |
| 815 |
Upgrade to PRO |
| 816 |
</a>'; |
| 817 |
|
| 818 |
$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"> |
| 819 |
<img src="'. esc_url(WPPB_PLUGIN_URL) . 'assets/images/upgrade-link-icon.svg" alt=""> |
| 820 |
Upgrade to PRO |
| 821 |
</a>'; |
| 822 |
|
| 823 |
$support_url = 'https://wordpress.org/support/plugin/profile-builder/'; |
| 824 |
|
| 825 |
$output = '<div class="cozmoslabs-banner"> |
| 826 |
<div class="cozmoslabs-banner-title"> |
| 827 |
<img src="'. esc_url(WPPB_PLUGIN_URL) . 'assets/images/pb-logo.svg" alt=""> |
| 828 |
<h4>Profile Builder'. $page_name .'</h4> |
| 829 |
</div> |
| 830 |
<div class="cozmoslabs-banner-buttons"> |
| 831 |
<a class="cozmoslabs-banner-link cozmoslabs-support-link" href="'. $support_url .'" target="_blank"> |
| 832 |
<img src="'. esc_url(WPPB_PLUGIN_URL) . 'assets/images/support-link-icon.svg" alt=""> |
| 833 |
Support |
| 834 |
</a> |
| 835 |
|
| 836 |
<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"> |
| 837 |
<img src="'. esc_url(WPPB_PLUGIN_URL) . 'assets/images/docs-link-icon.svg" alt=""> |
| 838 |
Documentation |
| 839 |
</a>'; |
| 840 |
|
| 841 |
if ( !defined( 'WPPB_PAID_PLUGIN_DIR' ) || ( defined( 'PROFILE_BUILDER_PAID_VERSION' ) && PROFILE_BUILDER_PAID_VERSION === 'dev' ) ) |
| 842 |
$output .= $upgrade_button; |
| 843 |
|
| 844 |
// Add Basic version upgrade button (not to account, to plugin purchase page) |
| 845 |
if( defined( 'PROFILE_BUILDER' ) && PROFILE_BUILDER == 'Profile Builder Basic' ){ |
| 846 |
$output .= $upgrade_button_basic; |
| 847 |
} |
| 848 |
|
| 849 |
$output .= ' </div> |
| 850 |
</div>'; |
| 851 |
|
| 852 |
echo $output; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 853 |
} |
| 854 |
|
| 855 |
|
| 856 |
/** |
| 857 |
* Remove PMS Styles from PB Pages and Posts |
| 858 |
* |
| 859 |
*/ |
| 860 |
function wppb_maybe_remove_pms_styles() { |
| 861 |
if ( !empty( wppb_get_pb_page_post_slug() ) && wp_style_is('pms-style-back-end', 'enqueued') ) { |
| 862 |
wp_dequeue_style('pms-style-back-end'); |
| 863 |
} |
| 864 |
} |
| 865 |
add_action('admin_enqueue_scripts', 'wppb_maybe_remove_pms_styles', 100); |
| 866 |
|
| 867 |
|
| 868 |
/** |
| 869 |
* Output the deactivation confirmation popup on the Plugins page |
| 870 |
* |
| 871 |
*/ |
| 872 |
function wppb_output_deactivation_popup() { |
| 873 |
|
| 874 |
if ( defined( 'WPPB_PAID_PLUGIN_DIR' ) ) |
| 875 |
return; |
| 876 |
|
| 877 |
$screen = get_current_screen(); |
| 878 |
|
| 879 |
if ( empty( $screen ) ) |
| 880 |
return; |
| 881 |
|
| 882 |
$is_plugins_screen = in_array( $screen->base, array( 'plugins', 'plugins-network' ), true ) || in_array( $screen->id, array( 'plugins', 'plugins-network' ), true ); |
| 883 |
|
| 884 |
if ( !$is_plugins_screen ) |
| 885 |
return; |
| 886 |
|
| 887 |
?> |
| 888 |
<div id="wppb-deactivation-popup" title="<?php esc_attr_e( 'Before You Go', 'profile-builder' ); ?>" data-plugin="<?php echo esc_attr( WPPB_PLUGIN_BASENAME ); ?>"> |
| 889 |
<div class="wppb-deactivation-popup-header"> |
| 890 |
<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"> |
| 891 |
|
| 892 |
<p class="wppb-deactivation-popup-description"> |
| 893 |
<?php esc_html_e( 'If you have a moment, please share the reason you are deactivating Profile Builder:', 'profile-builder' ); ?> |
| 894 |
</p> |
| 895 |
</div> |
| 896 |
|
| 897 |
<form class="wppb-deactivation-popup-form"> |
| 898 |
<fieldset class="wppb-deactivation-popup-fieldset"> |
| 899 |
<label class="wppb-deactivation-popup-option"> |
| 900 |
<input type="radio" name="wppb_deactivation_reason" value="dont_need_it"> |
| 901 |
<span><?php esc_html_e( 'I no longer need the plugin', 'profile-builder' ); ?></span> |
| 902 |
</label> |
| 903 |
|
| 904 |
<label class="wppb-deactivation-popup-option"> |
| 905 |
<input type="radio" name="wppb_deactivation_reason" value="switched_to_another_plugin"> |
| 906 |
<span><?php esc_html_e( 'I found a better plugin', 'profile-builder' ); ?></span> |
| 907 |
<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' ); ?>"> |
| 908 |
</label> |
| 909 |
|
| 910 |
<label class="wppb-deactivation-popup-option"> |
| 911 |
<input type="radio" name="wppb_deactivation_reason" value="missing_features"> |
| 912 |
<span><?php esc_html_e( 'I didn\'t find the feature I need', 'profile-builder' ); ?></span> |
| 913 |
<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' ); ?>"> |
| 914 |
</label> |
| 915 |
|
| 916 |
<label class="wppb-deactivation-popup-option"> |
| 917 |
<input type="radio" name="wppb_deactivation_reason" value="did_not_work"> |
| 918 |
<span><?php esc_html_e( 'I couldn\'t get the plugin to work', 'profile-builder' ); ?></span> |
| 919 |
</label> |
| 920 |
|
| 921 |
<label class="wppb-deactivation-popup-option"> |
| 922 |
<input type="radio" name="wppb_deactivation_reason" value="temporary_deactivation"> |
| 923 |
<span><?php esc_html_e( 'Temporary deactivation', 'profile-builder' ); ?></span> |
| 924 |
</label> |
| 925 |
|
| 926 |
<label class="wppb-deactivation-popup-option"> |
| 927 |
<input type="radio" name="wppb_deactivation_reason" value="other"> |
| 928 |
<span><?php esc_html_e( 'Other', 'profile-builder' ); ?></span> |
| 929 |
<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' ); ?>"> |
| 930 |
</label> |
| 931 |
</fieldset> |
| 932 |
|
| 933 |
<p class="wppb-deactivation-popup-error"></p> |
| 934 |
</form> |
| 935 |
|
| 936 |
<div class="wppb-deactivation-popup-actions"> |
| 937 |
<button type="button" class="button button-primary wppb-deactivation-popup-confirm"> |
| 938 |
<?php esc_html_e( 'Submit & deactivate', 'profile-builder' ); ?> |
| 939 |
</button> |
| 940 |
|
| 941 |
<button type="button" class="button wppb-deactivation-popup-skip"> |
| 942 |
<?php esc_html_e( 'Skip & deactivate', 'profile-builder' ); ?> |
| 943 |
</button> |
| 944 |
</div> |
| 945 |
</div> |
| 946 |
<style> |
| 947 |
#wppb-deactivation-popup { |
| 948 |
display: none; |
| 949 |
} |
| 950 |
|
| 951 |
.wppb-deactivation-popup-header { |
| 952 |
display: flex; |
| 953 |
align-items: center; |
| 954 |
gap: 16px; |
| 955 |
margin-bottom: 20px; |
| 956 |
} |
| 957 |
|
| 958 |
.wppb-deactivation-popup-description { |
| 959 |
margin: 0; |
| 960 |
} |
| 961 |
|
| 962 |
.wppb-deactivation-popup-fieldset { |
| 963 |
margin: 0; |
| 964 |
padding: 0; |
| 965 |
border: 0; |
| 966 |
} |
| 967 |
|
| 968 |
.wppb-deactivation-popup-option { |
| 969 |
display: block; |
| 970 |
margin-bottom: 12px; |
| 971 |
} |
| 972 |
|
| 973 |
.wppb-deactivation-popup-extra { |
| 974 |
display: none; |
| 975 |
width: 100%; |
| 976 |
margin-top: 8px; |
| 977 |
} |
| 978 |
|
| 979 |
.wppb-deactivation-popup-error { |
| 980 |
display: none; |
| 981 |
color: #b32d2e; |
| 982 |
margin: 0px 0px 12px 0px; |
| 983 |
} |
| 984 |
|
| 985 |
.wppb-deactivation-popup-actions { |
| 986 |
display: flex; |
| 987 |
align-items: center; |
| 988 |
justify-content: space-between; |
| 989 |
gap: 12px; |
| 990 |
} |
| 991 |
|
| 992 |
.wppb-deactivation-popup-extra.error { |
| 993 |
border: 1px solid #b32d2e; |
| 994 |
} |
| 995 |
|
| 996 |
.ui-dialog[aria-describedby="wppb-deactivation-popup"] .ui-dialog-titlebar { |
| 997 |
background: transparent; |
| 998 |
border: none; |
| 999 |
} |
| 1000 |
</style> |
| 1001 |
<?php |
| 1002 |
} |
| 1003 |
add_action( 'admin_footer', 'wppb_output_deactivation_popup' ); |
| 1004 |
|
| 1005 |
|
| 1006 |
/** |
| 1007 |
* Check if current screen is a Profile Builder admin page. |
| 1008 |
* |
| 1009 |
* @return bool |
| 1010 |
*/ |
| 1011 |
function wppb_is_profile_builder_admin_page() { |
| 1012 |
|
| 1013 |
if ( ! is_admin() ) |
| 1014 |
return false; |
| 1015 |
|
| 1016 |
$screen = get_current_screen(); |
| 1017 |
|
| 1018 |
if ( ! $screen ) |
| 1019 |
return false; |
| 1020 |
|
| 1021 |
$pb_pages = array( |
| 1022 |
'profile-builder', |
| 1023 |
'profile-builder-dashboard', |
| 1024 |
'profile-builder-basic-info', |
| 1025 |
'profile-builder-general-settings', |
| 1026 |
'profile-builder-add-ons', |
| 1027 |
'manage-fields', |
| 1028 |
); |
| 1029 |
|
| 1030 |
foreach ( $pb_pages as $page ) { |
| 1031 |
|
| 1032 |
if ( strpos( $screen->id, $page ) !== false ) |
| 1033 |
return true; |
| 1034 |
|
| 1035 |
} |
| 1036 |
|
| 1037 |
if ( ! empty( $screen->post_type ) ) { |
| 1038 |
$pb_cpt_pages = array( 'wppb-ul-cpt', 'wppb-rf-cpt', 'wppb-epf-cpt' ); |
| 1039 |
|
| 1040 |
if ( in_array( $screen->post_type, $pb_cpt_pages, true ) ) |
| 1041 |
return true; |
| 1042 |
} |
| 1043 |
|
| 1044 |
return false; |
| 1045 |
} |
| 1046 |
|
| 1047 |
|
| 1048 |
/** |
| 1049 |
* Output the popup markup used for documentation links from the admin. |
| 1050 |
* |
| 1051 |
* @return void |
| 1052 |
*/ |
| 1053 |
function wppb_output_docs_link_popup() { |
| 1054 |
|
| 1055 |
if ( ! wppb_is_profile_builder_admin_page() ) |
| 1056 |
return; |
| 1057 |
|
| 1058 |
?> |
| 1059 |
<div id="wppb-docs-link-popup" class="wppb-docs-link-popup" title="<?php echo esc_attr__( 'Need Help?', 'profile-builder' ); ?>" style="display:none;"> |
| 1060 |
<div class="wppb-docs-link-popup-content"> |
| 1061 |
<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"> |
| 1062 |
<div> |
| 1063 |
<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> |
| 1064 |
<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> |
| 1065 |
</div> |
| 1066 |
</div> |
| 1067 |
<div class="wppb-docs-link-popup-actions cozmoslabs-wrap"> |
| 1068 |
<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> |
| 1069 |
<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> |
| 1070 |
</div> |
| 1071 |
</div> |
| 1072 |
<?php |
| 1073 |
} |
| 1074 |
add_action( 'admin_footer', 'wppb_output_docs_link_popup' ); |
| 1075 |
|