' . esc_html__( 'Settings', 'advanced-age-verification-popup' ) . '' ); $links[] = '' . esc_html__( 'Get Pro', 'advanced-age-verification-popup' ) . ''; return $links; } add_filter( 'plugin_row_meta', 'avp_free_row_meta', 10, 2 ); function avp_free_row_meta( $links, $file ) { if ( plugin_basename( AVP_FREE_FILE ) === $file ) { $links[] = '' . esc_html__( 'Documentation', 'advanced-age-verification-popup' ) . ''; $links[] = '' . esc_html__( 'Support', 'advanced-age-verification-popup' ) . ''; } return $links; } /* First activation only: go to the settings screen, where the setup wizard opens. */ add_action( 'admin_init', 'avp_free_activation_redirect' ); function avp_free_activation_redirect() { if ( get_option( 'avp_free_activation_redirect' ) !== '1' ) { return; } delete_option( 'avp_free_activation_redirect' ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- core's own bulk-activation flag. if ( wp_doing_ajax() || is_network_admin() || isset( $_GET['activate-multi'] ) || ! current_user_can( 'manage_options' ) ) { return; } wp_safe_redirect( admin_url( 'admin.php?page=age-verification' ) ); exit; } /* Settings registered for the plain (no-JavaScript) form submit through options.php. */ add_action( 'admin_init', 'avp_free_register_settings' ); function avp_free_register_settings() { foreach ( avp_free_setting_keys() as $key ) { register_setting( 'avp-settings', $key, array( 'sanitize_callback' => function ( $value ) use ( $key ) { return avp_free_sanitize( $key, $value ); }, ) ); } } function avp_free_is_screen() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended $page = isset( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : ''; return in_array( $page, array( 'age-verification', 'avp-pro-landing' ), true ); } add_action( 'admin_enqueue_scripts', 'avp_free_admin_assets' ); function avp_free_admin_assets() { if ( ! avp_free_is_screen() ) { return; } $ver = AVP_FREE_VERSION; wp_enqueue_style( 'avp-free-admin', AVP_FREE_URL . 'assets/css/admin.css', array( 'wp-color-picker' ), $ver ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- which admin screen is open. $page = isset( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : ''; if ( 'age-verification' === $page ) { wp_enqueue_media(); wp_enqueue_script( 'avp-free-admin', AVP_FREE_URL . 'assets/js/admin.js', array( 'jquery', 'wp-color-picker' ), $ver, true ); $fresh = get_option( 'avp_wizard_done' ) !== '1' && get_option( 'avp_title', false ) === false; wp_localize_script( 'avp-free-admin', 'avpAdmin', array( 'ajaxUrl' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'avp_free_admin' ), 'home' => home_url( '/' ), 'previewUrl' => add_query_arg( 'avp_preview', '1', home_url( '/' ) ), 'proUrl' => AVP_FREE_PRO_URL, 'docsUrl' => AVP_FREE_DOCS_URL, 'showWizard' => $fresh || isset( $_GET['avp_wizard'] ), // phpcs:ignore WordPress.Security.NonceVerification.Recommended 'styles' => avp_free_color_styles(), 'tokens' => avp_free_link_tokens(), 'linkText' => __( 'link text', 'advanced-age-verification-popup' ), 'i18n' => array( 'saved' => __( 'All changes saved', 'advanced-age-verification-popup' ), 'unsaved' => __( 'Unsaved changes', 'advanced-age-verification-popup' ), 'saving' => __( 'Saving…', 'advanced-age-verification-popup' ), 'saveOk' => __( 'Settings saved.', 'advanced-age-verification-popup' ), 'saveFail' => __( 'Could not save. Please reload the page and try again.', 'advanced-age-verification-popup' ), 'leave' => __( 'You have unsaved changes.', 'advanced-age-verification-popup' ), 'chooseLogo' => __( 'Choose logo', 'advanced-age-verification-popup' ), 'useLogo' => __( 'Use this image', 'advanced-age-verification-popup' ), 'verifyAge' => __( 'Verify Age', 'advanced-age-verification-popup' ), 'month' => __( 'Month', 'advanced-age-verification-popup' ), 'or' => __( 'OR', 'advanced-age-verification-popup' ), 'remember' => __( 'Remember me', 'advanced-age-verification-popup' ), 'custom' => __( 'Custom', 'advanced-age-verification-popup' ), 'customD' => __( 'Your own colours below', 'advanced-age-verification-popup' ), 'sorryOk' => __( 'Page created and selected. Click Save Changes to use it.', 'advanced-age-verification-popup' ), 'sorryFail' => __( 'The page could not be created. Please try again.', 'advanced-age-verification-popup' ), 'creating' => __( 'Creating…', 'advanced-age-verification-popup' ), 'statusLive' => __( 'Live', 'advanced-age-verification-popup' ), 'statusTest' => __( 'Test mode', 'advanced-age-verification-popup' ), 'subLive' => __( 'Visitors see the gate', 'advanced-age-verification-popup' ), 'subTest' => __( 'Only administrators see the gate', 'advanced-age-verification-popup' ), ), 'wz' => array( 'steps_age' => __( 'Age', 'advanced-age-verification-popup' ), 'steps_design' => __( 'Design', 'advanced-age-verification-popup' ), 'steps_live' => __( 'Go live', 'advanced-age-verification-popup' ), 'wizard' => __( 'Setup wizard', 'advanced-age-verification-popup' ), 'close' => __( 'Close', 'advanced-age-verification-popup' ), 'h1' => __( 'Who is allowed in?', 'advanced-age-verification-popup' ), 'p1' => __( 'Pick the legal age for your site and how visitors confirm it.', 'advanced-age-verification-popup' ), 'custom' => __( 'Custom', 'advanced-age-verification-popup' ), 'm_yesno' => __( 'Yes / No buttons', 'advanced-age-verification-popup' ), 'm_yesno_d' => __( 'Fastest. Best for most sites.', 'advanced-age-verification-popup' ), 'm_dob' => __( 'Date of birth', 'advanced-age-verification-popup' ), 'm_dob_d' => __( 'Day / Month / Year picker. Stronger check for alcohol, vape & CBD stores.', 'advanced-age-verification-popup' ), 'm_both' => __( 'Both', 'advanced-age-verification-popup' ), 'm_both_d' => __( 'Yes / No buttons with a date-of-birth option.', 'advanced-age-verification-popup' ), 'pro_q' => __( 'Need real ID checks or a different check per country?', 'advanced-age-verification-popup' ), 'pro_a' => __( 'That\'s in Pro ↗', 'advanced-age-verification-popup' ), 'h2' => __( 'Make it yours', 'advanced-age-verification-popup' ), 'p2' => __( 'Choose a colour style and the words visitors will see.', 'advanced-age-verification-popup' ), 'title' => __( 'Title', 'advanced-age-verification-popup' ), 'subtitle' => __( 'Subtitle', 'advanced-age-verification-popup' ), 'enter' => __( 'Enter button', 'advanced-age-verification-popup' ), 'exit' => __( 'Exit button', 'advanced-age-verification-popup' ), 'h3' => __( 'Rules & go live', 'advanced-age-verification-popup' ), 'p3' => __( 'How long visitors stay verified, where under-age visitors go, and whether the gate is live.', 'advanced-age-verification-popup' ), 'days' => __( 'Remember visitors for (days)', 'advanced-age-verification-popup' ), 'redirect' => __( 'Send under-age visitors to', 'advanced-age-verification-popup' ), 'loggedin' => __( 'Skip the popup for logged-in users', 'advanced-age-verification-popup' ), 'seo' => __( 'Let search engines crawl without the popup (SEO)', 'advanced-age-verification-popup' ), 'live' => __( 'Show the age gate to visitors now', 'advanced-age-verification-popup' ), 'live_d' => __( 'Go live as soon as you click Finish.', 'advanced-age-verification-popup' ), 'test' => __( 'Keep test mode', 'advanced-age-verification-popup' ), 'test_d' => __( 'Only administrators see the gate until you turn test mode off.', 'advanced-age-verification-popup' ), 'done' => __( 'You\'re all set!', 'advanced-age-verification-popup' ), 'cache' => __( 'Clear your page cache (WP Rocket, LiteSpeed, Cloudflare…) so visitors get the new popup.', 'advanced-age-verification-popup' ), 'tune' => __( 'Fine-tune texts and colours in the other tabs at any time.', 'advanced-age-verification-popup' ), 'preview' => __( 'Preview on site ↗', 'advanced-age-verification-popup' ), 'docs' => __( 'Read the docs ↗', 'advanced-age-verification-popup' ), 'skip' => __( 'Skip setup', 'advanced-age-verification-popup' ), 'back' => __( 'Back', 'advanced-age-verification-popup' ), 'next' => __( 'Continue', 'advanced-age-verification-popup' ), 'finish' => __( 'Finish & save', 'advanced-age-verification-popup' ), /* translators: %d: minimum age */ 'yes_t' => __( 'I am %d or older', 'advanced-age-verification-popup' ), /* translators: %d: minimum age */ 'no_t' => __( 'I am under %d', 'advanced-age-verification-popup' ), /* translators: %d: minimum age */ 'done_live' => __( 'Your age gate is live. Visitors now have to confirm they are %d or older.', 'advanced-age-verification-popup' ), 'done_test' => __( 'Your settings are saved. Test mode is on, so only administrators see the gate for now.', 'advanced-age-verification-popup' ), ), ) ); } } /** Small helper for the toggle rows. */ function avp_free_toggle( $name, $title, $desc ) { ?>

'', 'content' => '', 'design' => '', 'rules' => '', 'pro' => '', 'help' => '', 'shield' => '', 'id' => '', 'globe' => '', 'cart' => '', 'report' => '', 'chart' => '', 'palette' => '', 'lock' => '', 'plug' => '', 'check' => '', 'pass' => '', 'block' => '', 'status' => '', 'star' => '', 'arrow' => '', 'sparkle' => '', 'page' => '', ); $size = absint( $size ); return ''; } /** Shared page header (settings screen and Free vs Pro page). */ function avp_free_header( $on_settings = true ) { ?>

true ), 'names' ) as $type ) { if ( 'attachment' === $type ) { continue; } add_meta_box( 'avp-free-exempt', __( 'Age verification', 'advanced-age-verification-popup' ), 'avp_free_render_meta_box', $type, 'side', 'low' ); } } function avp_free_render_meta_box( $post ) { wp_nonce_field( 'avp_free_exempt', 'avp_free_exempt_nonce' ); ?>

↗

'publish', 'sort_column' => 'menu_order,post_title', 'number' => 500, ) ); return is_array( $pages ) ? $pages : array(); } /* ------------------------------------------------------------------ Settings screen */ function avp_free_settings_page() { if ( ! current_user_can( 'manage_options' ) ) { return; } $method = avp_free_method(); $logo = avp_free_get( 'avp_logo' ); $pages = avp_free_pages(); $redirect = avp_free_get( 'avp_redirect_url' ); $stats = avp_free_stats( 30 ); $test = avp_free_get( 'avp_pro_test_mode' ) === '1'; $tabs = array( 'general' => array( __( 'General', 'advanced-age-verification-popup' ), __( 'How visitors confirm their age, the minimum age and where under-age visitors go.', 'advanced-age-verification-popup' ) ), 'content' => array( __( 'Popup Content', 'advanced-age-verification-popup' ), __( 'Logo, title, button labels and the warning line visitors see.', 'advanced-age-verification-popup' ) ), 'design' => array( __( 'Design', 'advanced-age-verification-popup' ), __( 'Pick a colour style or set your own colours.', 'advanced-age-verification-popup' ) ), 'rules' => array( __( 'Behaviour', 'advanced-age-verification-popup' ), __( 'How long visitors stay verified, who skips the gate, pages without the popup and test mode.', 'advanced-age-verification-popup' ) ), ); $max_bar = 1; foreach ( array_slice( $stats['days'], -14 ) as $d ) { $max_bar = max( $max_bar, $d['p'] + $d['f'] ); } ?>

array( __( 'Yes / No buttons', 'advanced-age-verification-popup' ), __( 'Fastest. Best for most sites.', 'advanced-age-verification-popup' ) ), 'dob' => array( __( 'Date of birth', 'advanced-age-verification-popup' ), __( 'Day / Month / Year picker. A stronger check for alcohol, vape & CBD stores.', 'advanced-age-verification-popup' ) ), 'both' => array( __( 'Both', 'advanced-age-verification-popup' ), __( 'Yes / No buttons with a date-of-birth option underneath.', 'advanced-age-verification-popup' ) ), ); foreach ( $methods as $value => $m ) : ?>
PRO

' . avp_free_icon( 'check', 16 ) . ''; } if ( false === $v ) { return '—'; } return '' . esc_html( $v ) . ''; }; $free_list = array( __( 'Yes / No and date-of-birth popup', 'advanced-age-verification-popup' ), __( 'Any minimum age, under-age redirect', 'advanced-age-verification-popup' ), __( 'Colour styles, logo, live preview', 'advanced-age-verification-popup' ), __( 'Pages without the popup', 'advanced-age-verification-popup' ), __( 'Cache and SEO friendly', 'advanced-age-verification-popup' ), ); $pro_list = array( __( 'Everything in Free', 'advanced-age-verification-popup' ), __( 'Real ID checks and ID upload', 'advanced-age-verification-popup' ), __( 'Rules per country, state and the EU', 'advanced-age-verification-popup' ), __( 'WooCommerce product and checkout tools', 'advanced-age-verification-popup' ), __( 'Audit log, reports and analytics', 'advanced-age-verification-popup' ), __( 'Designer templates and priority support', 'advanced-age-verification-popup' ), ); ?>

' . esc_html__( 'Free vs Pro', 'advanced-age-verification-popup' ) . '

'; avp_free_header( false ); avp_free_pro_compare(); echo ''; } /* ------------------------------------------------------------------ AJAX */ add_action( 'wp_ajax_avp_free_save', 'avp_free_ajax_save' ); function avp_free_ajax_save() { if ( ! current_user_can( 'manage_options' ) || ! check_ajax_referer( 'avp_free_admin', 'nonce', false ) ) { wp_send_json_error( array( 'message' => __( 'Permission denied.', 'advanced-age-verification-popup' ) ), 403 ); } $raw = isset( $_POST['settings'] ) ? wp_unslash( $_POST['settings'] ) : array(); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- each value is sanitized below. if ( ! is_array( $raw ) ) { wp_send_json_error( array( 'message' => __( 'Invalid data.', 'advanced-age-verification-popup' ) ), 400 ); } $checkboxes = avp_free_checkbox_keys(); foreach ( avp_free_setting_keys() as $key ) { if ( in_array( $key, $checkboxes, true ) ) { update_option( $key, avp_free_sanitize( $key, isset( $raw[ $key ] ) ? '1' : '0' ) ); } elseif ( array_key_exists( $key, $raw ) ) { update_option( $key, avp_free_sanitize( $key, $raw[ $key ] ) ); } } // Pages without the popup: only the pages listed on the screen are changed. if ( ! empty( $raw['avp_exempt_present'] ) ) { $chosen = isset( $raw['avp_exempt_pages'] ) && is_array( $raw['avp_exempt_pages'] ) ? array_map( 'absint', $raw['avp_exempt_pages'] ) : array(); foreach ( avp_free_pages() as $pg ) { if ( in_array( (int) $pg->ID, $chosen, true ) ) { update_post_meta( $pg->ID, AVP_FREE_EXEMPT_META, '1' ); } else { delete_post_meta( $pg->ID, AVP_FREE_EXEMPT_META ); } } } wp_send_json_success( array( 'message' => __( 'Settings saved.', 'advanced-age-verification-popup' ) ) ); } add_action( 'wp_ajax_avp_free_wizard_done', 'avp_free_ajax_wizard_done' ); function avp_free_ajax_wizard_done() { if ( ! current_user_can( 'manage_options' ) || ! check_ajax_referer( 'avp_free_admin', 'nonce', false ) ) { wp_send_json_error( null, 403 ); } update_option( 'avp_wizard_done', '1', false ); wp_send_json_success(); } /* ------------------------------------------------------------------ One-click "Sorry" page */ add_action( 'wp_ajax_avp_free_sorry_page', 'avp_free_ajax_sorry_page' ); function avp_free_ajax_sorry_page() { if ( ! current_user_can( 'manage_options' ) || ! current_user_can( 'publish_pages' ) || ! check_ajax_referer( 'avp_free_admin', 'nonce', false ) ) { wp_send_json_error( null, 403 ); } // Re-use the page made earlier if it still exists. $existing = absint( get_option( 'avp_free_sorry_page' ) ); if ( $existing && 'publish' === get_post_status( $existing ) ) { $page_id = $existing; } else { $age = absint( avp_free_get( 'avp_min_age' ) ); $content = '

' . esc_html__( 'Sorry, you can’t visit this site yet', 'advanced-age-verification-popup' ) . '

' /* translators: %d: minimum age */ . '

' . esc_html( sprintf( __( 'This website offers age-restricted products. Please come back when you are %d or older.', 'advanced-age-verification-popup' ), $age ? $age : 18 ) ) . '

' . '

' . esc_html__( 'Thank you for understanding.', 'advanced-age-verification-popup' ) . '

'; $page_id = wp_insert_post( array( 'post_type' => 'page', 'post_status' => 'publish', 'post_title' => __( 'Sorry, come back later', 'advanced-age-verification-popup' ), 'post_content' => $content, ), true ); if ( is_wp_error( $page_id ) || ! $page_id ) { wp_send_json_error( null, 500 ); } update_option( 'avp_free_sorry_page', (int) $page_id, false ); } update_post_meta( $page_id, AVP_FREE_EXEMPT_META, '1' ); wp_send_json_success( array( 'id' => (int) $page_id, 'url' => get_permalink( $page_id ), 'title' => get_the_title( $page_id ), ) ); } /* ------------------------------------------------------------------ Dashboard widget */ add_action( 'wp_dashboard_setup', 'avp_free_dashboard_setup' ); function avp_free_dashboard_setup() { if ( current_user_can( 'manage_options' ) ) { wp_add_dashboard_widget( 'avp_free_dashboard', __( 'Age verification this week', 'advanced-age-verification-popup' ), 'avp_free_dashboard_widget' ); } } add_action( 'admin_enqueue_scripts', 'avp_free_dashboard_assets' ); function avp_free_dashboard_assets( $hook ) { if ( 'index.php' === $hook && current_user_can( 'manage_options' ) ) { wp_enqueue_style( 'avp-free-dashboard', AVP_FREE_URL . 'assets/css/dashboard.css', array(), AVP_FREE_VERSION ); } } function avp_free_dashboard_widget() { $test = avp_free_get( 'avp_pro_test_mode' ) === '1'; $settings = admin_url( 'admin.php?page=age-verification' ); echo '
'; echo '

' . ( $test ? esc_html__( 'Test mode — only administrators see the gate', 'advanced-age-verification-popup' ) : esc_html__( 'Live — visitors see the age gate', 'advanced-age-verification-popup' ) ) . '

'; if ( avp_free_get( 'avp_free_stats_on' ) !== '1' ) { echo '

' . esc_html__( 'Counting verifications is turned off.', 'advanced-age-verification-popup' ) . ' ' . esc_html__( 'Turn it on', 'advanced-age-verification-popup' ) . '

'; return; } $stats = avp_free_stats( 7 ); $total = $stats['pass'] + $stats['fail']; $rate = $total ? round( $stats['pass'] / $total * 100 ) : 0; $max = 1; foreach ( $stats['days'] as $d ) { $max = max( $max, $d['p'] + $d['f'] ); } echo '
'; echo '
' . esc_html( number_format_i18n( $stats['pass'] ) ) . '' . esc_html__( 'Verified', 'advanced-age-verification-popup' ) . '
'; echo '
' . esc_html( number_format_i18n( $stats['fail'] ) ) . '' . esc_html__( 'Turned away', 'advanced-age-verification-popup' ) . '
'; echo '
' . esc_html( $total ? $rate . '%' : '—' ) . '' . esc_html__( 'Pass rate', 'advanced-age-verification-popup' ) . '
'; echo '
'; echo '

' . esc_html__( 'Age verification settings', 'advanced-age-verification-popup' ) . ' →

'; echo ''; }