pluginPrefix = $pluginPrefix;
$this->pluginName = $pluginName;
$this->notificaitonMessage = $notificaitonMessage;
$this->pluginSerialStatus = $pluginSerialStatus;
add_action( 'admin_notices', array( $this, 'add_admin_notice' ) );
add_action( 'admin_init', array( $this, 'dismiss_notification' ) );
}
// Display a notice that can be dismissed in case the serial number is inactive
function add_admin_notice() {
global $current_user ;
global $pagenow;
$user_id = $current_user->ID;
do_action( $this->pluginPrefix.'_before_notification_displayed', $current_user, $pagenow );
if ( current_user_can( 'manage_options' ) ){
$plugin_serial_status = get_option( $this->pluginSerialStatus );
if ( $plugin_serial_status != 'found' ){
//we want to show the expiration notice on our plugin pages even if the user dismissed it on the rest of the site
$force_show = false;
if ( $plugin_serial_status == 'expired' ) {
$notification_instance = WPPB_Plugin_Notifications::get_instance();
if ($notification_instance->is_plugin_page()){
$force_show = true;
}
}
// Check that the user hasn't already clicked to ignore the message
if ( ! get_user_meta($user_id, $this->pluginPrefix.'_dismiss_notification' ) || $force_show ) {
echo wp_kses_post( $finalMessage = apply_filters($this->pluginPrefix.'_notification_message',''.$this->notificaitonMessage.'
', $this->notificaitonMessage) );
}
}
do_action( $this->pluginPrefix.'_notification_displayed', $current_user, $pagenow, $plugin_serial_status );
}
do_action( $this->pluginPrefix.'_after_notification_displayed', $current_user, $pagenow );
}
function dismiss_notification() {
global $current_user;
$user_id = $current_user->ID;
do_action( $this->pluginPrefix.'_before_notification_dismissed', $current_user );
// If user clicks to ignore the notice, add that to their user meta
if ( isset( $_GET[$this->pluginPrefix.'_dismiss_notification']) && '0' == $_GET[$this->pluginPrefix.'_dismiss_notification'] )
add_user_meta( $user_id, $this->pluginPrefix.'_dismiss_notification', 'true', true );
do_action( $this->pluginPrefix.'_after_notification_dismissed', $current_user );
}
}
if( defined( 'WPPB_PAID_PLUGIN_DIR' ) ){
// Switch to the main site
if( is_multisite() && function_exists( 'switch_to_blog' )
&& function_exists( 'get_main_site_id' ))
switch_to_blog( get_main_site_id() );
$wppb_serial_number = wppb_get_serial_number();
$wppb_serial_status = wppb_get_serial_number_status();
$license_details = get_option( 'wppb_license_details', false );
if( is_multisite() && function_exists( 'restore_current_blog' ) )
restore_current_blog();
if( empty( $wppb_serial_number ) || $wppb_serial_status == 'missing' ) {
if( !is_multisite() )
$register_url = 'admin.php?page=profile-builder-general-settings';
else
$register_url = network_admin_url( 'admin.php?page=profile-builder-general-settings' );
new WPPB_add_notices( 'wppb', 'profile_builder_pro', sprintf( '' . __( 'Your Profile Builder serial number is invalid or missing.
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') . '
', "", "", "", "" ), 'wppb_license_status' );
}
elseif ( $wppb_serial_status == 'expired' ){
/* on our plugin pages do not add the dismiss button for the expired notification*/
$notification_instance = WPPB_Plugin_Notifications::get_instance();
if( $notification_instance->is_plugin_page() )
$message = '' . __( 'Your Profile Builder license has expired.
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') . '
';
else
$message = '' . __( 'Your Profile Builder license has expired.
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') . '
';
new WPPB_add_notices( 'wppb_expired', 'profile_builder_pro', sprintf( $message, "", "", "", "", "", "" ), 'wppb_license_status' );
}
// Maybe add about to expire notice
if( !empty( $license_details ) && !empty( $license_details->expires ) && $license_details->expires !== 'lifetime' ){
if( ( !isset( $license_details->subscription_status ) || $license_details->subscription_status != 'active' ) && strtotime( $license_details->expires ) < strtotime( '+14 days' ) ){
new WPPB_add_notices( 'wppb_about_to_expire', 'profile_builder_pro', sprintf( '' . __( 'Your Profile Builder license is about to expire on %5$s.
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') . '
', "", "", "", "", date_i18n( get_option( 'date_format' ), strtotime( $license_details->expires ) ), "", "" ), 'wppb_license_status' );
}
}
if( isset( $license_details->license ) && $license_details->license == 'invalid' ){
if( isset( $license_details->error ) && $license_details->error == 'no_activations_left' ){
$activations_limit_message = '' . sprintf( __( 'Your Profile Builder Basic license has reached its activation limit.
Upgrade now to Pro for unlimited activations and extra features like multiple registration and edit profile forms, userlisting, custom redirects and more. Upgrade now', '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' ) ) . '
';
$notification_instance = WPPB_Plugin_Notifications::get_instance();
if( !$notification_instance->is_plugin_page() ) {//add the dismiss button only on other pages in admin
$activations_limit_message .= sprintf(__(' %1$sDismiss%2$s', 'profile-builder'), "", "");
$force_show = false;
} else {
$force_show = true;//sets the forceShow parameter of WPPB_add_notices to true so we don't take into consideration the dismiss user meta
}
new WPPB_add_notices( 'wppb_basic_activations_limit',
'profile_builder_basic',
$activations_limit_message,
'error',
'',
'',
$force_show );
}
}
}