| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 3 |
/** |
| 4 |
* Function that creates the "Register your version" submenu page |
| 5 |
* |
| 6 |
* @since v.2.0 |
| 7 |
* |
| 8 |
* @return void |
| 9 |
*/ |
| 10 |
|
| 11 |
if( !is_multisite() ){ |
| 12 |
function wppb_register_your_version_submenu_page(){ |
| 13 |
if ( PROFILE_BUILDER != 'Profile Builder Free' ) |
| 14 |
add_submenu_page('profile-builder', __('Register Your Version', 'profile-builder'), __('Register Version', 'profile-builder'), 'manage_options', 'profile-builder-register', 'wppb_register_your_version_content'); |
| 15 |
} |
| 16 |
add_action('admin_menu', 'wppb_register_your_version_submenu_page', 29); |
| 17 |
} else { |
| 18 |
function wppb_multisite_register_your_version_page() { |
| 19 |
if ( PROFILE_BUILDER != 'Profile Builder Free' ) |
| 20 |
add_menu_page(__('Profile Builder Register', 'profile-builder'), __('Profile Builder Register', 'profile-builder'), 'manage_options', 'profile-builder-register', 'wppb_register_your_version_content', WPPB_PLUGIN_URL . 'assets/images/pb-menu-icon.png'); |
| 21 |
} |
| 22 |
add_action('network_admin_menu', 'wppb_multisite_register_your_version_page', 29); |
| 23 |
} |
| 24 |
|
| 25 |
|
| 26 |
/** |
| 27 |
* Function that adds content to the "Register your Version" submenu page |
| 28 |
* |
| 29 |
* @since v.2.0 |
| 30 |
* |
| 31 |
* @return string |
| 32 |
*/ |
| 33 |
function wppb_register_your_version_content() { |
| 34 |
?> |
| 35 |
<div class="wrap wppb-wrap"> |
| 36 |
<?php wppb_serial_form(); ?> |
| 37 |
</div> |
| 38 |
<?php |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* Function that creates the "Register your version" form |
| 43 |
* |
| 44 |
* @since v.2.0 |
| 45 |
* |
| 46 |
* @return void |
| 47 |
*/ |
| 48 |
function wppb_serial_form(){ |
| 49 |
$status = wppb_get_serial_number_status(); |
| 50 |
$license = wppb_get_serial_number(); |
| 51 |
?> |
| 52 |
<div id="wppb-register-version-page" class="wrap"> |
| 53 |
<h2> |
| 54 |
<?php esc_html_e( "Register your version of Profile Builder", 'profile-builder' ); ?> |
| 55 |
<a href="https://www.cozmoslabs.com/docs/profile-builder-2/basic-information-installation/?utm_source=wpbackend&utm_medium=pb-documentation&utm_campaign=PBDocs#Register_your_version" target="_blank" data-code="f223" class="wppb-docs-link dashicons dashicons-editor-help"></a> |
| 56 |
</h2> |
| 57 |
|
| 58 |
<p><?php esc_html_e( 'Now that you acquired a copy of Profile Builder Pro, you should take the time and register it with the serial number you received.', 'profile-builder' ) ?></p> |
| 59 |
|
| 60 |
<p><?php esc_html_e( 'If you register this version of Profile Builder, you\'ll receive information regarding upgrades, patches, and technical support.', 'profile-builder' ) ?></p> |
| 61 |
|
| 62 |
<div class="wppb-serial-wrap"> |
| 63 |
<form method="post" action="<?php echo !is_multisite() ? 'options.php' : 'edit.php'; ?>"> |
| 64 |
<?php settings_fields( 'wppb_license_key' ); ?> |
| 65 |
|
| 66 |
<label for="wppb_license_key"><?php esc_html_e( 'License key', 'profile-builder' ); ?></label> |
| 67 |
|
| 68 |
<div class="wppb-serial-wrap__holder"> |
| 69 |
<input id="wppb_license_key" name="wppb_license_key" type="password" class="regular-text" value="<?php echo esc_attr( $license ); ?>" /> |
| 70 |
<?php wp_nonce_field( 'wppb_license_nonce', 'wppb_license_nonce' ); ?> |
| 71 |
|
| 72 |
<?php if( $status !== false && $status == 'valid' ) { |
| 73 |
$button_name = 'wppb_edd_license_deactivate'; |
| 74 |
$button_value = __('Deactivate License', 'profile-builder' ); |
| 75 |
|
| 76 |
if( empty( $details['invalid'] ) ) |
| 77 |
echo '<span title="'. esc_html__( 'Active on this site', 'profile-builder' ) .'" class="wppb-active-license dashicons dashicons-yes"></span>'; |
| 78 |
else |
| 79 |
echo '<span title="'. esc_html__( 'Your license is invalid', 'profile-builder' ) .'" class="wppb-invalid-license dashicons dashicons-warning"></span>'; |
| 80 |
|
| 81 |
} else { |
| 82 |
$button_name = 'wppb_edd_license_activate'; |
| 83 |
$button_value = __('Activate License', 'profile-builder'); |
| 84 |
} |
| 85 |
?> |
| 86 |
<input type="submit" class="button-secondary" name="<?php echo esc_attr( $button_name ); ?>" value="<?php echo esc_attr( $button_value ); ?>"/> |
| 87 |
</div> |
| 88 |
</form> |
| 89 |
</div> |
| 90 |
</div> |
| 91 |
|
| 92 |
<?php |
| 93 |
} |
| 94 |
|
| 95 |
/** |
| 96 |
* Retrieve saved license key |
| 97 |
*/ |
| 98 |
function wppb_get_serial_number(){ |
| 99 |
|
| 100 |
$license = get_option( 'wppb_license_key', false ); |
| 101 |
|
| 102 |
// try to grab the license from the old options if it's not available |
| 103 |
if( empty( $license ) ){ |
| 104 |
$versions = array( 'Profile Builder Pro', 'Profile Builder Elite', 'Profile Builder Unlimited', 'Profile Builder Dev' ); |
| 105 |
|
| 106 |
if( in_array( PROFILE_BUILDER, $versions ) ) |
| 107 |
$version = 'pro'; |
| 108 |
elseif ( PROFILE_BUILDER == 'Profile Builder Hobbyist' || PROFILE_BUILDER == 'Profile Builder Basic' ) |
| 109 |
$version = 'hobbyist'; |
| 110 |
|
| 111 |
$old_license = get_option( 'wppb_profile_builder_'.$version.'_serial' ); |
| 112 |
|
| 113 |
if( !empty( $old_license ) ){ |
| 114 |
update_option( 'wppb_license_key', $old_license ); |
| 115 |
$license = $old_license; |
| 116 |
} |
| 117 |
|
| 118 |
} |
| 119 |
|
| 120 |
return $license; |
| 121 |
|
| 122 |
} |
| 123 |
|
| 124 |
/** |
| 125 |
* Retrieve license key status |
| 126 |
*/ |
| 127 |
function wppb_get_serial_number_status(){ |
| 128 |
return get_option( 'wppb_license_status' ); |
| 129 |
} |
| 130 |
|
| 131 |
/** |
| 132 |
* Class that adds a notice when either the serial number wasn't found, or it has expired |
| 133 |
* |
| 134 |
* @since v.2.0 |
| 135 |
* |
| 136 |
* @return void |
| 137 |
*/ |
| 138 |
class WPPB_add_notices{ |
| 139 |
public $pluginPrefix = ''; |
| 140 |
public $pluginName = ''; |
| 141 |
public $notificaitonMessage = ''; |
| 142 |
public $pluginSerialStatus = ''; |
| 143 |
|
| 144 |
function __construct( $pluginPrefix, $pluginName, $notificaitonMessage, $pluginSerialStatus ){ |
| 145 |
$this->pluginPrefix = $pluginPrefix; |
| 146 |
$this->pluginName = $pluginName; |
| 147 |
$this->notificaitonMessage = $notificaitonMessage; |
| 148 |
$this->pluginSerialStatus = $pluginSerialStatus; |
| 149 |
|
| 150 |
add_action( 'admin_notices', array( $this, 'add_admin_notice' ) ); |
| 151 |
add_action( 'admin_init', array( $this, 'dismiss_notification' ) ); |
| 152 |
} |
| 153 |
|
| 154 |
|
| 155 |
// Display a notice that can be dismissed in case the serial number is inactive |
| 156 |
function add_admin_notice() { |
| 157 |
global $current_user ; |
| 158 |
global $pagenow; |
| 159 |
|
| 160 |
$user_id = $current_user->ID; |
| 161 |
|
| 162 |
do_action( $this->pluginPrefix.'_before_notification_displayed', $current_user, $pagenow ); |
| 163 |
|
| 164 |
if ( current_user_can( 'manage_options' ) ){ |
| 165 |
|
| 166 |
$plugin_serial_status = get_option( $this->pluginSerialStatus ); |
| 167 |
if ( $plugin_serial_status != 'found' ){ |
| 168 |
|
| 169 |
//we want to show the expiration notice on our plugin pages even if the user dismissed it on the rest of the site |
| 170 |
$force_show = false; |
| 171 |
if ( $plugin_serial_status == 'expired' ) { |
| 172 |
$notification_instance = WPPB_Plugin_Notifications::get_instance(); |
| 173 |
if ($notification_instance->is_plugin_page()){ |
| 174 |
$force_show = true; |
| 175 |
} |
| 176 |
} |
| 177 |
|
| 178 |
// Check that the user hasn't already clicked to ignore the message |
| 179 |
if ( ! get_user_meta($user_id, $this->pluginPrefix.'_dismiss_notification' ) || $force_show ) { |
| 180 |
echo wp_kses_post( $finalMessage = apply_filters($this->pluginPrefix.'_notification_message','<div class="error wppb-serial-notification" >'.$this->notificaitonMessage.'</div>', $this->notificaitonMessage) ); |
| 181 |
} |
| 182 |
} |
| 183 |
|
| 184 |
do_action( $this->pluginPrefix.'_notification_displayed', $current_user, $pagenow, $plugin_serial_status ); |
| 185 |
|
| 186 |
} |
| 187 |
|
| 188 |
do_action( $this->pluginPrefix.'_after_notification_displayed', $current_user, $pagenow ); |
| 189 |
|
| 190 |
} |
| 191 |
|
| 192 |
function dismiss_notification() { |
| 193 |
global $current_user; |
| 194 |
|
| 195 |
$user_id = $current_user->ID; |
| 196 |
|
| 197 |
do_action( $this->pluginPrefix.'_before_notification_dismissed', $current_user ); |
| 198 |
|
| 199 |
// If user clicks to ignore the notice, add that to their user meta |
| 200 |
if ( isset( $_GET[$this->pluginPrefix.'_dismiss_notification']) && '0' == $_GET[$this->pluginPrefix.'_dismiss_notification'] ) |
| 201 |
add_user_meta( $user_id, $this->pluginPrefix.'_dismiss_notification', 'true', true ); |
| 202 |
|
| 203 |
do_action( $this->pluginPrefix.'_after_notification_dismissed', $current_user ); |
| 204 |
} |
| 205 |
} |
| 206 |
|
| 207 |
if( defined( 'WPPB_PAID_PLUGIN_DIR' ) ){ |
| 208 |
|
| 209 |
// Switch to the main site |
| 210 |
if( is_multisite() && function_exists( 'switch_to_blog' ) |
| 211 |
&& function_exists( 'get_main_site_id' )) |
| 212 |
switch_to_blog( get_main_site_id() ); |
| 213 |
|
| 214 |
$wppb_serial_number = wppb_get_serial_number(); |
| 215 |
$wppb_serial_status = wppb_get_serial_number_status(); |
| 216 |
$license_details = get_option( 'wppb_license_details', false ); |
| 217 |
|
| 218 |
if( is_multisite() && function_exists( 'restore_current_blog' ) ) |
| 219 |
restore_current_blog(); |
| 220 |
|
| 221 |
if( empty( $wppb_serial_number ) || $wppb_serial_status == 'missing' ) { |
| 222 |
|
| 223 |
if( !is_multisite() ) |
| 224 |
$register_url = 'admin.php?page=profile-builder-register'; |
| 225 |
else |
| 226 |
$register_url = network_admin_url( 'admin.php?page=profile-builder-register' ); |
| 227 |
|
| 228 |
new WPPB_add_notices( 'wppb', 'profile_builder_pro', sprintf( '<p>' . __( 'Your <strong>Profile Builder</strong> serial number is invalid or missing. <br/>Please %1$sregister your copy%2$s to receive access to automatic updates and support. Need a license key? %3$sPurchase one now%4$s', 'profile-builder') . '</p>', "<a href='". esc_url( $register_url ) ."'>", "</a>", "<a href='https://www.cozmoslabs.com/wordpress-profile-builder/?utm_source=PB&utm_medium=dashboard&utm_campaign=PB-SN-Purchase' target='_blank' class='button-primary'>", "</a>" ), 'wppb_license_status' ); |
| 229 |
|
| 230 |
} |
| 231 |
elseif ( $wppb_serial_status == 'expired' ){ |
| 232 |
/* on our plugin pages do not add the dismiss button for the expired notification*/ |
| 233 |
$notification_instance = WPPB_Plugin_Notifications::get_instance(); |
| 234 |
if( $notification_instance->is_plugin_page() ) |
| 235 |
$message = '<p>' . __( 'Your <strong>Profile Builder</strong> license has expired. <br/>Please %1$sRenew Your Licence%2$s to continue receiving access to product downloads, automatic updates and support. %3$sRenew now %4$s', 'profile-builder') . '</p>'; |
| 236 |
else |
| 237 |
$message = '<p>' . __( 'Your <strong>Profile Builder</strong> license has expired. <br/>Please %1$sRenew Your Licence%2$s to continue receiving access to product downloads, automatic updates and support. %3$sRenew now %4$s %5$sDismiss%6$s', 'profile-builder') . '</p>'; |
| 238 |
|
| 239 |
new WPPB_add_notices( 'wppb_expired', 'profile_builder_pro', sprintf( $message, "<a href='https://www.cozmoslabs.com/account/?utm_source=PB&utm_medium=dashboard&utm_campaign=PB-Renewal' target='_blank'>", "</a>", "<a href='https://www.cozmoslabs.com/account/?utm_source=PB&utm_medium=dashboard&utm_campaign=PB-Renewal' target='_blank' class='button-primary'>", "</a>", "<a href='". esc_url( add_query_arg( 'wppb_expired_dismiss_notification', '0' ) ) ."' class='wppb-dismiss-notification'>", "</a>" ), 'wppb_license_status' ); |
| 240 |
} |
| 241 |
|
| 242 |
|
| 243 |
// Maybe add about to expire notice |
| 244 |
if( !empty( $license_details ) && !empty( $license_details->expires ) ){ |
| 245 |
|
| 246 |
if( strtotime( $license_details->expires ) < strtotime( '+14 days' ) ){ |
| 247 |
new WPPB_add_notices( 'wppb_about_to_expire', 'profile_builder_pro', sprintf( '<p>' . __( 'Your <strong>Profile Builder</strong> license is about to expire on %5$s. <br/>Please %1$sRenew Your Licence%2$s to continue receiving access to product downloads, automatic updates and support. %3$sRenew now %4$s %6$sDismiss%7$s', 'profile-builder') . '</p>', "<a href='https://www.cozmoslabs.com/account/?utm_source=PB&utm_medium=dashboard&utm_campaign=PB-Renewal' target='_blank'>", "</a>", "<a href='https://www.cozmoslabs.com/account/?utm_source=PB&utm_medium=dashboard&utm_campaign=PB-Renewal' target='_blank' class='button-primary'>", "</a>", date_i18n( get_option( 'date_format' ), strtotime( $license_details->expires ) ), "<a href='". esc_url( add_query_arg( 'wppb_about_to_expire_dismiss_notification', '0' ) )."' class='wppb-dismiss-notification'>", "</a>" ), 'wppb_license_status' ); |
| 248 |
} |
| 249 |
|
| 250 |
} |
| 251 |
|
| 252 |
if( isset( $license_details->license ) && $license_details->license == 'invalid' ){ |
| 253 |
|
| 254 |
if( isset( $license_details->error ) && $license_details->error == 'no_activations_left' ){ |
| 255 |
|
| 256 |
$activations_limit_message = sprintf( __( 'Your <strong>Profile Builder Basic</strong> license has reached its activation limit.<br> Upgrade now to <strong>Pro</strong> for unlimited activations and extra features like multiple registration and edit profile forms, userlisting, custom redirects and more. <a class="button-primary" href="%s">Upgrade now</a>', 'profile-builder' ), esc_url( 'https://www.cozmoslabs.com/account/?utm_source=wpbackend&utm_medium=clientsite&utm_campaign=WPPB&utm_content=add-on-page-license-activation-limit' ) ); |
| 257 |
|
| 258 |
$notification_instance = WPPB_Plugin_Notifications::get_instance(); |
| 259 |
if( !$notification_instance->is_plugin_page() ) {//add the dismiss button only on other pages in admin |
| 260 |
$activations_limit_message .= sprintf(__(' %1$sDismiss%2$s', 'profile-builder'), "<a class='dismiss-right' href='" . esc_url(add_query_arg('wppb_basic_activations_limit_dismiss_notification', '0')) . "'>", "</a>"); |
| 261 |
$force_show = false; |
| 262 |
} else { |
| 263 |
$force_show = true;//sets the forceShow parameter of WPPB_add_notices to true so we don't take into consideration the dismiss user meta |
| 264 |
} |
| 265 |
|
| 266 |
new WPPB_add_notices( 'wppb_basic_activations_limit', |
| 267 |
$activations_limit_message, |
| 268 |
'error', |
| 269 |
'', |
| 270 |
'', |
| 271 |
$force_show ); |
| 272 |
} |
| 273 |
|
| 274 |
} |
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
} |
| 279 |
|
| 280 |
|