is_paying() ) { return true; } } return false; } private function in_campaign_window() { $now = time(); return $now >= strtotime( self::START ) && $now <= strtotime( self::END ); } /** Base eligibility shared by the notice and the settings banner. */ private function campaign_eligible() { if ( ! current_user_can( 'manage_options' ) || $this->is_pro() ) { return false; } return $this->is_preview() || $this->in_campaign_window(); } private function should_show_notice() { if ( ! $this->campaign_eligible() ) { return false; } if ( $this->is_preview() ) { return true; } $screen = get_current_screen(); if ( ! $screen || ! in_array( $screen->id, [ 'dashboard' ], true ) ) { return false; } $installed = (int) get_option( self::INSTALL_OPT, 0 ); if ( $installed && ( time() - $installed ) < self::MIN_INSTALL_DAYS * DAY_IN_SECONDS ) { return false; } $state = $this->get_state(); if ( 'dismissed' === $state['status'] ) { return false; } if ( 'snoozed' === $state['status'] ) { $last_chance = strtotime( self::LAST_CHANCE_FROM ); // Snoozed before the last-chance window opened -> show once more. if ( time() >= $last_chance && $state['at'] < $last_chance ) { return true; } return time() >= $state['until']; } return true; } private function get_state() { $all = get_user_meta( get_current_user_id(), self::META_KEY, true ); $state = ( is_array( $all ) && isset( $all[ self::CAMPAIGN ] ) ) ? $all[ self::CAMPAIGN ] : []; return wp_parse_args( $state, [ 'status' => '', 'at' => 0, 'until' => 0 ] ); } /* ======================= Hooks ======================= */ public function maybe_set_install_time() { if ( get_option( self::INSTALL_OPT ) ) { return; } // Existing users (slug already configured) count as long-time installs. $time = get_option( 'jh_new_login_url' ) ? time() - 30 * DAY_IN_SECONDS : time(); update_option( self::INSTALL_OPT, $time, false ); } public function enqueue_assets() { $screen = get_current_screen(); $on_settings = $screen && 'toplevel_page_admin-login-url-change' === $screen->id; if ( ! ( $on_settings ? $this->campaign_eligible() : $this->should_show_notice() ) ) { return; } $css_ver = ALUC_Plugin::VERSION . '.' . filemtime( ALUC_PLUGIN_PATH . 'assets/css/promo.css' ); $js_ver = ALUC_Plugin::VERSION . '.' . filemtime( ALUC_PLUGIN_PATH . 'assets/js/promo.js' ); wp_enqueue_style( 'aluc-promo', ALUC_PLUGIN_URL . 'assets/css/promo.css', [], $css_ver ); wp_enqueue_script( 'aluc-promo', ALUC_PLUGIN_URL . 'assets/js/promo.js', [], $js_ver, true ); wp_localize_script( 'aluc-promo', 'aluc_promo', [ 'ajax_url' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( self::NONCE ), 'copied' => __( 'Copied!', 'admin-login-url-change' ), ] ); } public function ajax_dismiss() { check_ajax_referer( self::NONCE, 'nonce' ); if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error( null, 403 ); } $type = isset( $_POST['type'] ) ? sanitize_key( wp_unslash( $_POST['type'] ) ) : 'snooze'; $user_id = get_current_user_id(); $all = get_user_meta( $user_id, self::META_KEY, true ); $all = is_array( $all ) ? $all : []; $all[ self::CAMPAIGN ] = ( 'dismiss' === $type ) ? [ 'status' => 'dismissed', 'at' => time(), 'until' => 0 ] : [ 'status' => 'snoozed', 'at' => time(), 'until' => time() + self::SNOOZE_DAYS * DAY_IN_SECONDS ]; update_user_meta( $user_id, self::META_KEY, $all ); wp_send_json_success(); } /* ======================= Rendering ======================= */ private function upgrade_url() { // Freemius merges $_GET into the pricing/checkout config, so the coupon // is forwarded and pre-filled where the checkout supports it. return add_query_arg( 'coupon', rawurlencode( self::COUPON ), admin_url( 'admin.php?page=admin-login-url-change-pricing' ) ); } private function render_howto() { ?>

' . esc_html( self::COUPON ) . '' ); ?>

= strtotime( self::LAST_CHANCE_FROM ); } private function render_coupon() { ?> should_show_notice() ) { return; } $eyebrow = $this->is_last_chance() ? __( 'Last chance · Black Friday Deal', 'admin-login-url-change' ) : __( 'Black Friday Deal', 'admin-login-url-change' ); ?>
%

render_coupon(); ?>
render_howto(); ?>
campaign_eligible() ) { return; } ?>
%

render_howto(); ?>
render_coupon(); ?>