| 1 |
<?php |
| 2 |
/** |
| 3 |
* Function that creates the "Register your version" submenu page |
| 4 |
* |
| 5 |
* @since v.2.0 |
| 6 |
* |
| 7 |
* @return void |
| 8 |
*/ |
| 9 |
|
| 10 |
if( !is_multisite() ){ |
| 11 |
function wppb_register_your_version_submenu_page() |
| 12 |
{ |
| 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', 20); |
| 17 |
} |
| 18 |
else{ |
| 19 |
function wppb_multisite_register_your_version_page() |
| 20 |
{ |
| 21 |
if (PROFILE_BUILDER != 'Profile Builder Free') |
| 22 |
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'); |
| 23 |
} |
| 24 |
add_action('network_admin_menu', 'wppb_multisite_register_your_version_page', 20); |
| 25 |
} |
| 26 |
|
| 27 |
|
| 28 |
/** |
| 29 |
* Function that adds content to the "Register your Version" submenu page |
| 30 |
* |
| 31 |
* @since v.2.0 |
| 32 |
* |
| 33 |
* @return string |
| 34 |
*/ |
| 35 |
function wppb_register_your_version_content() { |
| 36 |
|
| 37 |
?> |
| 38 |
<div class="wrap wppb-wrap"> |
| 39 |
<?php |
| 40 |
if ( PROFILE_BUILDER == 'Profile Builder Pro' ){ |
| 41 |
wppb_serial_form('pro', 'Profile Builder Pro'); |
| 42 |
}elseif ( PROFILE_BUILDER == 'Profile Builder Hobbyist' ){ |
| 43 |
wppb_serial_form('hobbyist', 'Profile Builder 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, $fullname){ |
| 59 |
?> |
| 60 |
|
| 61 |
<h2><?php printf( __( "Register your version of %s", 'profile-builder' ), $fullname ); ?></h2> |
| 62 |
|
| 63 |
<form method="post" action="<?php echo 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( __( "Now that you acquired a copy of %s, you should take the time and register it with the serial number you received", 'profile-builder'), $fullname);?></p> |
| 70 |
<p><?php _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 $version; ?>_serial"><?php _e(' Serial Number:', 'profile-builder' );?></label> |
| 73 |
<input type="password" size="50" name="wppb_profile_builder_<?php echo $version; ?>_serial" id="wppb_profile_builder_<?php echo $version; ?>_serial" class="regular-text" <?php if ( $wppb_profile_builder_serial != ''){ echo ' value="'.$wppb_profile_builder_serial.'"';} ?>/> |
| 74 |
|
| 75 |
<?php |
| 76 |
if( $wppb_profile_builder_serial_status == 'found' ) |
| 77 |
echo '<span class="validateStatus"><img src="'.WPPB_PLUGIN_URL.'/assets/images/accept.png" title="'.__( 'The serial number was successfully validated!', 'profile-builder' ).'"/></span>'; |
| 78 |
elseif ( $wppb_profile_builder_serial_status == 'notFound' ) |
| 79 |
echo '<span class="validateStatus"><img src="'.WPPB_PLUGIN_URL.'/assets/images/icon_error.png" title="'.__( '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="' . WPPB_PLUGIN_URL . '/assets/images/icon_error.png" title="' . __('The serial number is about to expire soon!', 'profile-builder') . '"/>'. sprintf( __(' 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="'.WPPB_PLUGIN_URL.'/assets/images/icon_error.png" title="'.__( 'The serial number couldn\'t be validated because it expired!','profile-builder' ).'"/>'. sprintf( __(' 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="'.WPPB_PLUGIN_URL.'/assets/images/icon_error.png" title="'.__( '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 _e( '(e.g. RMPB-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 _e('Save Changes') ?>" /> |
| 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){ |
| 106 |
|
| 107 |
$serial_number_set = $newVal; |
| 108 |
|
| 109 |
|
| 110 |
$response = wp_remote_get( 'http://updatemetadata.cozmoslabs.com/checkserial/?serialNumberSent='.$serial_number_set ); |
| 111 |
if ( PROFILE_BUILDER == 'Profile Builder Pro' ){ |
| 112 |
wppb_update_serial_status($response, 'pro'); |
| 113 |
wp_clear_scheduled_hook( "check_plugin_updates-profile-builder-pro-update" ); |
| 114 |
} else { |
| 115 |
wppb_update_serial_status($response, 'hobbyist'); |
| 116 |
wp_clear_scheduled_hook( "check_plugin_updates-profile-builder-hobbyist-update" ); |
| 117 |
} |
| 118 |
$user_ID = get_current_user_id(); |
| 119 |
delete_user_meta( $user_ID, 'wppb_dismiss_notification' ); |
| 120 |
|
| 121 |
} |
| 122 |
|
| 123 |
add_action( 'update_option_wppb_profile_builder_pro_serial', 'wppb_check_serial_number', 10, 2 ); |
| 124 |
add_action( 'update_option_wppb_profile_builder_hobbyist_serial', 'wppb_check_serial_number', 10, 2 ); |
| 125 |
|
| 126 |
add_action( 'add_option_wppb_profile_builder_pro_serial', 'wppb_check_serial_number', 10, 2 ); |
| 127 |
add_action( 'add_option_wppb_profile_builder_hobbyist_serial', 'wppb_check_serial_number', 10, 2 ); |
| 128 |
|
| 129 |
/** |
| 130 |
* @param $response |
| 131 |
*/ |
| 132 |
function wppb_update_serial_status($response, $version) |
| 133 |
{ |
| 134 |
if (is_wp_error($response)) { |
| 135 |
update_option('wppb_profile_builder_'.$version.'_serial_status', 'serverDown'); //server down |
| 136 |
} elseif ((trim($response['body']) != 'notFound') && (trim($response['body']) != 'found') && (trim($response['body']) != 'expired') && (strpos( $response['body'], 'aboutToExpire' ) === false)) { |
| 137 |
update_option('wppb_profile_builder_'.$version.'_serial_status', 'serverDown'); //unknown response parameter |
| 138 |
update_option('wppb_profile_builder_'.$version.'_serial', ''); //reset the entered password, since the user will need to try again later |
| 139 |
|
| 140 |
} else { |
| 141 |
update_option('wppb_profile_builder_'.$version.'_serial_status', trim($response['body'])); //either found, notFound or expired |
| 142 |
} |
| 143 |
} |
| 144 |
|
| 145 |
//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 |
| 146 |
function wppb_check_serial_number_fix($newvalue, $oldvalue){ |
| 147 |
|
| 148 |
if ( $newvalue == $oldvalue ) |
| 149 |
wppb_check_serial_number( $oldvalue, $newvalue ); |
| 150 |
|
| 151 |
return $newvalue; |
| 152 |
} |
| 153 |
add_filter( 'pre_update_option_wppb_profile_builder_pro_serial', 'wppb_check_serial_number_fix', 10, 2 ); |
| 154 |
add_filter( 'pre_update_option_wppb_profile_builder_hobbyist_serial', 'wppb_check_serial_number_fix', 10, 2 ); |
| 155 |
|
| 156 |
|
| 157 |
/** |
| 158 |
* Class that adds a notice when either the serial number wasn't found, or it has expired |
| 159 |
* |
| 160 |
* @since v.2.0 |
| 161 |
* |
| 162 |
* @return void |
| 163 |
*/ |
| 164 |
class wppb_add_notices{ |
| 165 |
public $pluginPrefix = ''; |
| 166 |
public $pluginName = ''; |
| 167 |
public $notificaitonMessage = ''; |
| 168 |
public $pluginSerialStatus = ''; |
| 169 |
|
| 170 |
function __construct( $pluginPrefix, $pluginName, $notificaitonMessage, $pluginSerialStatus ){ |
| 171 |
$this->pluginPrefix = $pluginPrefix; |
| 172 |
$this->pluginName = $pluginName; |
| 173 |
$this->notificaitonMessage = $notificaitonMessage; |
| 174 |
$this->pluginSerialStatus = $pluginSerialStatus; |
| 175 |
|
| 176 |
add_action( 'admin_notices', array( $this, 'add_admin_notice' ) ); |
| 177 |
add_action( 'admin_init', array( $this, 'dismiss_notification' ) ); |
| 178 |
} |
| 179 |
|
| 180 |
|
| 181 |
// Display a notice that can be dismissed in case the serial number is inactive |
| 182 |
function add_admin_notice() { |
| 183 |
global $current_user ; |
| 184 |
global $pagenow; |
| 185 |
|
| 186 |
$user_id = $current_user->ID; |
| 187 |
|
| 188 |
do_action( $this->pluginPrefix.'_before_notification_displayed', $current_user, $pagenow ); |
| 189 |
|
| 190 |
if ( current_user_can( 'manage_options' ) ){ |
| 191 |
|
| 192 |
$plugin_serial_status = get_option( $this->pluginSerialStatus ); |
| 193 |
if ( $plugin_serial_status != 'found' ){ |
| 194 |
// Check that the user hasn't already clicked to ignore the message |
| 195 |
if ( ! get_user_meta($user_id, $this->pluginPrefix.'_dismiss_notification' ) ) { |
| 196 |
echo $finalMessage = apply_filters($this->pluginPrefix.'_notification_message','<div class="error wppb-serial-notification" >'.$this->notificaitonMessage.'</div>', $this->notificaitonMessage); |
| 197 |
} |
| 198 |
} |
| 199 |
|
| 200 |
do_action( $this->pluginPrefix.'_notification_displayed', $current_user, $pagenow, $plugin_serial_status ); |
| 201 |
|
| 202 |
} |
| 203 |
|
| 204 |
do_action( $this->pluginPrefix.'_after_notification_displayed', $current_user, $pagenow ); |
| 205 |
|
| 206 |
} |
| 207 |
|
| 208 |
function dismiss_notification() { |
| 209 |
global $current_user; |
| 210 |
|
| 211 |
$user_id = $current_user->ID; |
| 212 |
|
| 213 |
do_action( $this->pluginPrefix.'_before_notification_dismissed', $current_user ); |
| 214 |
|
| 215 |
// If user clicks to ignore the notice, add that to their user meta |
| 216 |
if ( isset( $_GET[$this->pluginPrefix.'_dismiss_notification']) && '0' == $_GET[$this->pluginPrefix.'_dismiss_notification'] ) |
| 217 |
add_user_meta( $user_id, $this->pluginPrefix.'_dismiss_notification', 'true', true ); |
| 218 |
|
| 219 |
do_action( $this->pluginPrefix.'_after_notification_dismissed', $current_user ); |
| 220 |
} |
| 221 |
} |
| 222 |
|
| 223 |
if( is_multisite() && function_exists( 'switch_to_blog' ) ) |
| 224 |
switch_to_blog(1); |
| 225 |
|
| 226 |
if ( PROFILE_BUILDER == 'Profile Builder Pro' ){ |
| 227 |
$wppb_profile_builder_pro_hobbyist_serial_status = get_option( 'wppb_profile_builder_pro_serial_status', 'empty' ); |
| 228 |
$version = 'pro'; |
| 229 |
|
| 230 |
} elseif( PROFILE_BUILDER == 'Profile Builder Hobbyist' ) { |
| 231 |
$wppb_profile_builder_pro_hobbyist_serial_status = get_option( 'wppb_profile_builder_hobbyist_serial_status', 'empty' ); |
| 232 |
$version = 'hobbyist'; |
| 233 |
} |
| 234 |
if( is_multisite() && function_exists( 'restore_current_blog' ) ) |
| 235 |
restore_current_blog(); |
| 236 |
|
| 237 |
if ( $wppb_profile_builder_pro_hobbyist_serial_status == 'notFound' || $wppb_profile_builder_pro_hobbyist_serial_status == 'empty' ){ |
| 238 |
if( !is_multisite() ) |
| 239 |
$register_url = 'admin.php?page=profile-builder-register'; |
| 240 |
else |
| 241 |
$register_url = network_admin_url( 'admin.php?page=profile-builder-register' ); |
| 242 |
|
| 243 |
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</p>', 'profile-builder'), "<a href='". $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' ); |
| 244 |
} |
| 245 |
elseif ( $wppb_profile_builder_pro_hobbyist_serial_status == 'expired' ){ |
| 246 |
new wppb_add_notices( 'wppb_expired', 'profile_builder_pro', sprintf( __( '<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 and get 40% off %4$s %5$sDismiss%6$s</p>', 'profile-builder'), "<a href='https://www.cozmoslabs.com/downloads/profile-builder-". $version ."-v2-yearly-renewal/?utm_source=PB&utm_medium=dashboard&utm_campaign=PB-Renewal' target='_blank'>", "</a>", "<a href='https://www.cozmoslabs.com/downloads/profile-builder-".$version."-v2-yearly-renewal/?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' ); |
| 247 |
} |
| 248 |
elseif( strpos( $wppb_profile_builder_pro_hobbyist_serial_status, 'aboutToExpire' ) === 0 ){ |
| 249 |
$serial_status_parts = explode( '#', $wppb_profile_builder_pro_hobbyist_serial_status ); |
| 250 |
$date = $serial_status_parts[1]; |
| 251 |
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 and get 40% off %4$s %6$sDismiss%7$s</p>', 'profile-builder'), "<a href='https://www.cozmoslabs.com/downloads/profile-builder-". $version ."-v2-yearly-renewal/?utm_source=PB&utm_medium=dashboard&utm_campaign=PB-Renewal' target='_blank'>", "</a>", "<a href='https://www.cozmoslabs.com/downloads/profile-builder-".$version."-v2-yearly-renewal/?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' ); |
| 252 |
} |