set_variables(); if ( $this->dismiss_notice == 1 ) { return; } $p = $this->prefix; add_action( 'admin_notices', array( $this, 'admin_notices' ) ); add_action( 'wp_ajax_'.$p.'_notice_dismiss', array( $this, 'notice_dismiss' ) ); } /** * Hooked from 'admin_notices' */ public function admin_notices() { $screen = get_current_screen(); if ( !isset($screen->post_type) || $screen->post_type !== 'custom-css-js' ) return; if ( ! $notice = $this->choose_notice() ) return; if ( time() - $this->activation_time <= 3600 ) return; $message = $this->get_message( $notice ); $this->print_message( $notice, $message ); } /** * Get the options from the database or set them on install or upgrade */ public function set_variables() { $now = time(); $p = $this->prefix; $this->activation_time = get_option( $p . '_activation_time', '' ); $this->version = get_option( $p.'_version', '' ); $this->dismiss_notice = get_option( $p.'_dismiss_notice', false ); if ( empty( $this->activation_time ) || version_compare( $this->version, CCJ_VERSION, '<' ) ) { $this->activation_time = $now; update_option( $p.'_activation_time', $now ); update_option( $p.'_version', CCJ_VERSION ); update_option( $p.'_dismiss_notice', false ); } } /** * Choose which notice to be shown */ public function choose_notice() { $now = time(); $days_passed = floor( ( $now - $this->activation_time ) / 86400 ); switch ( $days_passed ) { case 0 : return '1_day'; case 1 : return '2_day'; case 2 : break; //return '3_day'; case 3 : break; case 4 : break; case 5 : break; case 6 : break; // return '7_day'; case 7 : break; case 8 : break; case 9 : break; case 10 : break; case 11 : break; //return '12_day'; default: break; } } /** * Get the text of the message */ public function get_message( $notice ) { $message = ''; $percentage = '30'; $product_name = 'Simple Custom CSS and JS PRO'; $expiration_date = $this->activation_time + ( $this->expiration_days * 86400 ); $expiration_date = date( get_option( 'date_format') , $expiration_date ); $expiration_period = date('j M', $this->activation_time - 3*86400 ) . ' - ' . date('j M', $this->activation_time + 2*86400 ); if ( $notice == '12_days' ) { $link = 'https://www.silkypress.com/simple-custom-css-js-pro/?utm_source=wordpress&utm_campaign=ccj_free&utm_medium=banner'; } else { $link = 'https://www.silkypress.com/simple-custom-css-js-pro/?a=' . $this->convert_numbers_letters( $this->activation_time ) . '&utm_source=wordpress&utm_campaign=ccj_free&utm_medium=banner'; } $lower_part = sprintf( '
%s | %s
', $link, __('Get your discount now', 'custom-css-js'), __('Dismiss this notice', 'custom-css-js') ); switch ( $notice ) { case '1_day' : $message = '
Only between '. $expiration_period .': '.$percentage.'% Off from '.$product_name.' for our WordPress.org users.
' . $lower_part; break; case '2_day' : $message = '
Limited offer ending today. '.$percentage.'% Off from '.$product_name.' for our WordPress.org users.
' . $lower_part; break; case '3_day' : $message = '
Limited offer ending today. '.$percentage.'% Off from '.$product_name.' for our WordPress.org users.
' . $lower_part; break; case '7_day' : $message = ''; break; case '12_day' : $message = '
Special Offer: 30% Off from '.$product_name.' for our WordPress.org users.
' . $lower_part; break; } return $message; } /** * Print the message */ public function print_message( $option_name = '', $message = '' ) { if ( empty( $message ) || empty( $option_name ) ) return; $p = $this->prefix; ?>

prefix; check_ajax_referer( $p . '_notice', 'nonce' ); update_option( $p.'_dismiss_notice', 1 ); wp_die(); } } return new CustomCSSandJS_Notices();