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