| 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 |
?> |
| 36 |
<div class="wrap wppb-wrap"> |
| 37 |
<?php |
| 38 |
$versions = array( 'Profile Builder Pro', 'Profile Builder Elite', 'Profile Builder Unlimited', 'Profile Builder Dev' ); |
| 39 |
|
| 40 |
if( in_array( PROFILE_BUILDER, $versions ) ) { |
| 41 |
wppb_serial_form('pro'); |
| 42 |
} elseif ( PROFILE_BUILDER == 'Profile Builder Hobbyist' || PROFILE_BUILDER == 'Profile Builder Basic' ){ |
| 43 |
wppb_serial_form('hobbyist'); |
| 44 |
} |
| 45 |
?> |
| 46 |
|
| 47 |
</div> |
| 48 |
<?php |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* Function that creates the "Register your version" form depending on Pro or Hobbyist version |
| 53 |
* |
| 54 |
* @since v.2.0 |
| 55 |
* |
| 56 |
* @return void |
| 57 |
*/ |
| 58 |
function wppb_serial_form($version){ |
| 59 |
?> |
| 60 |
|
| 61 |
<h2><?php printf( esc_html__( "Register your version of %s", 'profile-builder' ), esc_html( PROFILE_BUILDER ) ); ?></h2> |
| 62 |
|
| 63 |
<form method="post" action="<?php echo esc_url( get_admin_url( 1, 'options.php' ) ) ?>"> |
| 64 |
|
| 65 |
<?php $wppb_profile_builder_serial = get_option( 'wppb_profile_builder_'.$version.'_serial' ); ?> |
| 66 |
<?php $wppb_profile_builder_serial_status = get_option( 'wppb_profile_builder_'.$version.'_serial_status' ); ?> |
| 67 |
<?php settings_fields( 'wppb_profile_builder_'.$version.'_serial' ); ?> |
| 68 |
|
| 69 |
<p><?php printf( esc_html__( "Now that you acquired a copy of %s, you should take the time and register it with the serial number you received", 'profile-builder'), esc_html( PROFILE_BUILDER ));?></p> |
| 70 |
<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> |
| 71 |
<p class="wppb-serial-wrap"> |
| 72 |
<label for="wppb_profile_builder_<?php echo esc_attr( $version ); ?>_serial"><?php esc_html_e(' Serial Number:', 'profile-builder' );?></label> |
| 73 |
<input type="password" size="50" name="wppb_profile_builder_<?php echo esc_attr( $version ); ?>_serial" id="wppb_profile_builder_<?php echo esc_attr( $version ); ?>_serial" class="regular-text" <?php if ( $wppb_profile_builder_serial != ''){ echo ' value="'.esc_attr( $wppb_profile_builder_serial ).'"';} ?>/> |
| 74 |
|
| 75 |
<?php |
| 76 |
if( $wppb_profile_builder_serial_status == 'found' ) |
| 77 |
echo '<span class="validateStatus"><img src="'.esc_url( WPPB_PLUGIN_URL ).'/assets/images/accept.png" title="'.esc_html__( 'The serial number was successfully validated!', 'profile-builder' ).'"/></span>'; |
| 78 |
elseif ( $wppb_profile_builder_serial_status == 'notFound' ) |
| 79 |
echo '<span class="validateStatus"><img src="'.esc_url( WPPB_PLUGIN_URL ).'/assets/images/icon_error.png" title="'.esc_html__( 'The serial number entered couldn\'t be validated!','profile-builder' ).'"/></span>'; |
| 80 |
elseif ( strpos( $wppb_profile_builder_serial_status, 'aboutToExpire') !== false )//instead of aboutToExpire if the client has autobbiling on then he will receive 'found' instead |
| 81 |
echo '<span class="validateStatus"><img src="' . esc_url( WPPB_PLUGIN_URL ) . '/assets/images/icon_error.png" title="' . esc_html__('The serial number is about to expire soon!', 'profile-builder') . '"/>'. sprintf( esc_html__(' Your serial number is about to expire, please %1$s Renew Your License%2$s.','profile-builder'), "<a href='https://www.cozmoslabs.com/account/?utm_source=PB&utm_medium=dashboard&utm_campaign=PB-Renewal' >", "</a>").'</span>'; |
| 82 |
elseif ( $wppb_profile_builder_serial_status == 'expired' ) |
| 83 |
echo '<span class="validateStatus"><img src="'.esc_url( WPPB_PLUGIN_URL ).'/assets/images/icon_error.png" title="'.esc_html__( 'The serial number couldn\'t be validated because it expired!','profile-builder' ).'"/>'. sprintf( esc_html__(' Your serial number is expired, please %1$s Renew Your License%2$s.','profile-builder'), "<a href='https://www.cozmoslabs.com/account/?utm_source=PB&utm_medium=dashboard&utm_campaign=PB-Renewal' >", "</a>").'</span>'; |
| 84 |
elseif ( $wppb_profile_builder_serial_status == 'serverDown' ) |
| 85 |
echo '<span class="validateStatus"><img src="'.esc_url( WPPB_PLUGIN_URL ).'/assets/images/icon_error.png" title="'.esc_html__( 'The serial number couldn\'t be validated because process timed out. This is possible due to the server being down. Please try again later!','profile-builder' ).'"/></span>'; |
| 86 |
?> |
| 87 |
<span class="wppb-serialnumber-descr"><?php esc_html_e( '(e.g. CLPB-15-SN-253a55baa4fbe7bf595b2aabb8d72985)', 'profile-builder' );?></span> |
| 88 |
</p> |
| 89 |
|
| 90 |
|
| 91 |
<div id="wppb_submit_button_div"> |
| 92 |
<input type="hidden" name="action" value="update" /> |
| 93 |
<p class="submit"> |
| 94 |
<?php wp_nonce_field( 'wppb_register_version_nonce', 'wppb_register_version_nonce' ); ?> |
| 95 |
<input type="submit" name="wppb_serial_number_activate" class="button-primary" value="<?php esc_html_e( 'Save Changes', 'profile-builder' ) ?>" /> |
| 96 |
</p> |
| 97 |
</div> |
| 98 |
|
| 99 |
</form> |
| 100 |
<?php |
| 101 |
} |
| 102 |
|
| 103 |
|
| 104 |
//the function to check the validity of the serial number and save a variable in the DB; purely visual |
| 105 |
function wppb_check_serial_number($oldVal, $newVal, $resetCron = false){ |
| 106 |
|
| 107 |
$serial_number_set = $newVal; |
| 108 |
|
| 109 |
$response = wp_remote_get( 'http://updatemetadata.cozmoslabs.com/checkserial/?serialNumberSent='.$serial_number_set ); |
| 110 |
|
| 111 |
$versions = array( 'Profile Builder Pro', 'Profile Builder Elite', 'Profile Builder Unlimited', 'Profile Builder Dev' ); |
| 112 |
|
| 113 |
if( in_array( PROFILE_BUILDER, $versions ) ) { |
| 114 |
wppb_update_serial_status($response, 'pro'); |
| 115 |
|
| 116 |
if( $resetCron === true ) |
| 117 |
wp_clear_scheduled_hook( "check_plugin_updates-profile-builder-pro-update" ); |
| 118 |
|
| 119 |
} else { |
| 120 |
wppb_update_serial_status($response, 'hobbyist'); |
| 121 |
|
| 122 |
if( $resetCron === true ) |
| 123 |
wp_clear_scheduled_hook( "check_plugin_updates-profile-builder-hobbyist-update" ); |
| 124 |
} |
| 125 |
|
| 126 |
$user_ID = get_current_user_id(); |
| 127 |
delete_user_meta( $user_ID, 'wppb_dismiss_notification' ); |
| 128 |
|
| 129 |
} |
| 130 |
|
| 131 |
add_action( 'update_option_wppb_profile_builder_pro_serial', 'wppb_check_serial_number', 10, 2 ); |
| 132 |
add_action( 'update_option_wppb_profile_builder_hobbyist_serial', 'wppb_check_serial_number', 10, 2 ); |
| 133 |
|
| 134 |
add_action( 'add_option_wppb_profile_builder_pro_serial', 'wppb_check_serial_number', 10, 2 ); |
| 135 |
add_action( 'add_option_wppb_profile_builder_hobbyist_serial', 'wppb_check_serial_number', 10, 2 ); |
| 136 |
|
| 137 |
/** |
| 138 |
* @param $response |
| 139 |
*/ |
| 140 |
function wppb_update_serial_status($response, $version) |
| 141 |
{ |
| 142 |
if (is_wp_error($response)) { |
| 143 |
update_option('wppb_profile_builder_'.$version.'_serial_status', 'serverDown'); //server down |
| 144 |
} elseif ((trim($response['body']) != 'notFound') && (trim($response['body']) != 'found') && (trim($response['body']) != 'expired') && (strpos( $response['body'], 'aboutToExpire' ) === false)) { |
| 145 |
update_option('wppb_profile_builder_'.$version.'_serial_status', 'serverDown'); //unknown response parameter |
| 146 |
update_option('wppb_profile_builder_'.$version.'_serial', ''); //reset the entered password, since the user will need to try again later |
| 147 |
|
| 148 |
} else { |
| 149 |
update_option('wppb_profile_builder_'.$version.'_serial_status', trim($response['body'])); //either found, notFound or expired |
| 150 |
} |
| 151 |
} |
| 152 |
|
| 153 |
//the update didn't work when the old value = new value, so we need to apply a filter on get_option (that is run before update_option), that resets the old value |
| 154 |
function wppb_check_serial_number_fix($newvalue, $oldvalue){ |
| 155 |
|
| 156 |
if ( $newvalue == $oldvalue ) |
| 157 |
wppb_check_serial_number( $oldvalue, $newvalue, true ); |
| 158 |
|
| 159 |
return $newvalue; |
| 160 |
} |
| 161 |
add_filter( 'pre_update_option_wppb_profile_builder_pro_serial', 'wppb_check_serial_number_fix', 10, 2 ); |
| 162 |
add_filter( 'pre_update_option_wppb_profile_builder_hobbyist_serial', 'wppb_check_serial_number_fix', 10, 2 ); |
| 163 |
|
| 164 |
|
| 165 |
/** |
| 166 |
* Class that adds a notice when either the serial number wasn't found, or it has expired |
| 167 |
* |
| 168 |
* @since v.2.0 |
| 169 |
* |
| 170 |
* @return void |
| 171 |
*/ |
| 172 |
class WPPB_add_notices{ |
| 173 |
public $pluginPrefix = ''; |
| 174 |
public $pluginName = ''; |
| 175 |
public $notificaitonMessage = ''; |
| 176 |
public $pluginSerialStatus = ''; |
| 177 |
|
| 178 |
function __construct( $pluginPrefix, $pluginName, $notificaitonMessage, $pluginSerialStatus ){ |
| 179 |
$this->pluginPrefix = $pluginPrefix; |
| 180 |
$this->pluginName = $pluginName; |
| 181 |
$this->notificaitonMessage = $notificaitonMessage; |
| 182 |
$this->pluginSerialStatus = $pluginSerialStatus; |
| 183 |
|
| 184 |
add_action( 'admin_notices', array( $this, 'add_admin_notice' ) ); |
| 185 |
add_action( 'admin_init', array( $this, 'dismiss_notification' ) ); |
| 186 |
} |
| 187 |
|
| 188 |
|
| 189 |
// Display a notice that can be dismissed in case the serial number is inactive |
| 190 |
function add_admin_notice() { |
| 191 |
global $current_user ; |
| 192 |
global $pagenow; |
| 193 |
|
| 194 |
$user_id = $current_user->ID; |
| 195 |
|
| 196 |
do_action( $this->pluginPrefix.'_before_notification_displayed', $current_user, $pagenow ); |
| 197 |
|
| 198 |
if ( current_user_can( 'manage_options' ) ){ |
| 199 |
|
| 200 |
$plugin_serial_status = get_option( $this->pluginSerialStatus ); |
| 201 |
if ( $plugin_serial_status != 'found' ){ |
| 202 |
|
| 203 |
//we want to show the expiration notice on our plugin pages even if the user dismissed it on the rest of the site |
| 204 |
$force_show = false; |
| 205 |
if ( $plugin_serial_status == 'expired' ) { |
| 206 |
$notification_instance = WPPB_Plugin_Notifications::get_instance(); |
| 207 |
if ($notification_instance->is_plugin_page()){ |
| 208 |
$force_show = true; |
| 209 |
} |
| 210 |
} |
| 211 |
|
| 212 |
// Check that the user hasn't already clicked to ignore the message |
| 213 |
if ( ! get_user_meta($user_id, $this->pluginPrefix.'_dismiss_notification' ) || $force_show ) { |
| 214 |
echo wp_kses_post( $finalMessage = apply_filters($this->pluginPrefix.'_notification_message','<div class="error wppb-serial-notification" >'.$this->notificaitonMessage.'</div>', $this->notificaitonMessage) ); |
| 215 |
} |
| 216 |
} |
| 217 |
|
| 218 |
do_action( $this->pluginPrefix.'_notification_displayed', $current_user, $pagenow, $plugin_serial_status ); |
| 219 |
|
| 220 |
} |
| 221 |
|
| 222 |
do_action( $this->pluginPrefix.'_after_notification_displayed', $current_user, $pagenow ); |
| 223 |
|
| 224 |
} |
| 225 |
|
| 226 |
function dismiss_notification() { |
| 227 |
global $current_user; |
| 228 |
|
| 229 |
$user_id = $current_user->ID; |
| 230 |
|
| 231 |
do_action( $this->pluginPrefix.'_before_notification_dismissed', $current_user ); |
| 232 |
|
| 233 |
// If user clicks to ignore the notice, add that to their user meta |
| 234 |
if ( isset( $_GET[$this->pluginPrefix.'_dismiss_notification']) && '0' == $_GET[$this->pluginPrefix.'_dismiss_notification'] ) |
| 235 |
add_user_meta( $user_id, $this->pluginPrefix.'_dismiss_notification', 'true', true ); |
| 236 |
|
| 237 |
do_action( $this->pluginPrefix.'_after_notification_dismissed', $current_user ); |
| 238 |
} |
| 239 |
} |
| 240 |
|
| 241 |
|
| 242 |
if( defined( 'WPPB_PAID_PLUGIN_DIR' ) ){ |
| 243 |
|
| 244 |
// Switch to the main site |
| 245 |
if( is_multisite() && function_exists( 'switch_to_blog' ) |
| 246 |
&& function_exists( 'get_main_site_id' )) |
| 247 |
switch_to_blog( get_main_site_id() ); |
| 248 |
|
| 249 |
if ( file_exists(WPPB_PAID_PLUGIN_DIR . '/add-ons/add-ons.php') ){ |
| 250 |
$wppb_profile_builder_pro_hobbyist_serial_status = get_option('wppb_profile_builder_pro_serial'); |
| 251 |
$version = 'pro'; |
| 252 |
} else { |
| 253 |
$wppb_profile_builder_pro_hobbyist_serial_status = get_option('wppb_profile_builder_hobbyist_serial'); |
| 254 |
$version = 'hobbyist'; |
| 255 |
} |
| 256 |
|
| 257 |
if( is_multisite() && function_exists( 'restore_current_blog' ) ) |
| 258 |
restore_current_blog(); |
| 259 |
|
| 260 |
if ( $wppb_profile_builder_pro_hobbyist_serial_status == 'notFound' || $wppb_profile_builder_pro_hobbyist_serial_status == 'empty' ){ |
| 261 |
if( !is_multisite() ) |
| 262 |
$register_url = 'admin.php?page=profile-builder-register'; |
| 263 |
else |
| 264 |
$register_url = network_admin_url( 'admin.php?page=profile-builder-register' ); |
| 265 |
|
| 266 |
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_profile_builder_pro_serial_status' ); |
| 267 |
} |
| 268 |
elseif ( $wppb_profile_builder_pro_hobbyist_serial_status == 'expired' ){ |
| 269 |
/* on our plugin pages do not add the dismiss button for the expired notification*/ |
| 270 |
$notification_instance = WPPB_Plugin_Notifications::get_instance(); |
| 271 |
if( $notification_instance->is_plugin_page() ) |
| 272 |
$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>'; |
| 273 |
else |
| 274 |
$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>'; |
| 275 |
|
| 276 |
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_profile_builder_pro_serial_status' ); |
| 277 |
} |
| 278 |
elseif( strpos( $wppb_profile_builder_pro_hobbyist_serial_status, 'aboutToExpire' ) === 0 ){ |
| 279 |
$serial_status_parts = explode( '#', $wppb_profile_builder_pro_hobbyist_serial_status ); |
| 280 |
$date = $serial_status_parts[1]; |
| 281 |
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, "<a href='". esc_url( add_query_arg( 'wppb_about_to_expire_dismiss_notification', '0' ) )."' class='wppb-dismiss-notification'>", "</a>" ), 'wppb_profile_builder_pro_serial_status' ); |
| 282 |
} |
| 283 |
|
| 284 |
} |
| 285 |
|
| 286 |
|