self::PAGE ), $a ), admin_url( 'admin.php' ) ); } public static function save(): void { if ( ! current_user_can( self::CAP ) ) { wp_die( esc_html__( 'You are not allowed to do this.', 'ason-chat-button' ), 403 ); } check_admin_referer( 'ason_cb_save' ); $in = isset( $_POST['s'] ) && is_array( $_POST['s'] ) ? wp_unslash( $_POST['s'] ) : array(); $new = Settings::sanitize( (array) $in ); update_option( Settings::OPT, $new, true ); Settings::register_strings(); $args = array( 'saved' => 1 ); if ( isset( $in['phone'] ) && '' !== trim( (string) $in['phone'] ) && '' === $new['phone'] ) { $args['bad_phone'] = 1; } wp_safe_redirect( self::url( $args ) ); exit; } private static function tabs(): array { return (array) apply_filters( 'ason_chat_button_admin_tabs', array( 'settings' => __( 'Settings', 'ason-chat-button' ), 'usage' => __( 'Usage', 'ason-chat-button' ), ) ); } public static function render(): void { if ( ! current_user_can( self::CAP ) ) { return; } $tabs = self::tabs(); $tab = isset( $_GET['tab'] ) ? sanitize_key( wp_unslash( $_GET['tab'] ) ) : 'settings'; $tab = isset( $tabs[ $tab ] ) ? $tab : 'settings'; echo '

' . esc_html__( 'Chat button', 'ason-chat-button' ) . '

'; if ( isset( $_GET['saved'] ) ) { echo '

' . esc_html__( 'Settings saved.', 'ason-chat-button' ) . '

'; } if ( isset( $_GET['bad_phone'] ) ) { echo '

' . esc_html__( 'The phone number is not valid. Enter it with the country code, digits only (8–15 digits), e.g. 90 5xx xxx xx xx. The button is hidden until a valid number is saved.', 'ason-chat-button' ) . '

'; } echo ''; $m = 'render_' . $tab; if ( method_exists( __CLASS__, $m ) ) { self::$m(); } else { do_action( 'ason_chat_button_render_tab', $tab ); } echo '
'; } private static function row( string $label, string $field, string $for = '' ): void { echo wp_kses( '' . ( '' !== $for ? '' : esc_html( $label ) ) . '' . $field . '', ason_kses_allowed() ); } private static function check( string $key, int $val, string $text ): string { return ''; } private static function desc( string $t ): string { return '

' . esc_html( $t ) . '

'; } private static function render_settings(): void { $s = Settings::all(); echo '
'; wp_nonce_field( 'ason_cb_save' ); echo ''; echo '

' . esc_html__( 'Button', 'ason-chat-button' ) . '

'; self::row( __( 'Status', 'ason-chat-button' ), self::check( 'enabled', (int) $s['enabled'], __( 'Show the WhatsApp button on the site', 'ason-chat-button' ) ) ); self::row( __( 'WhatsApp number', 'ason-chat-button' ), '' . self::desc( __( 'With the country code. Spaces, "+" and "00" are removed. The button stays hidden until a valid number is saved.', 'ason-chat-button' ) ), 'wa-phone' ); self::row( __( 'Devices', 'ason-chat-button' ), self::check( 'show_desktop', (int) $s['show_desktop'], __( 'Floating button on desktop', 'ason-chat-button' ) ) . '
' . self::check( 'show_mobile', (int) $s['show_mobile'], __( 'Floating button on phones (narrower than 768 px)', 'ason-chat-button' ) ) ); self::row( __( 'Corner', 'ason-chat-button' ), '', 'wa-pos' ); self::row( __( 'Size (px)', 'ason-chat-button' ), '' . self::desc( __( 'Default 48. You can make it smaller (down to 32) or larger (up to 72).', 'ason-chat-button' ) ), 'wa-size' ); self::row( __( 'Distance from the side (px)', 'ason-chat-button' ), '', 'wa-ox' ); self::row( __( 'Distance from the bottom (px)', 'ason-chat-button' ), '' . self::desc( __( 'Increase it if the button covers the reCAPTCHA badge or a "back to top" button (e.g. 90).', 'ason-chat-button' ) ), 'wa-oy' ); self::row( __( 'Colour', 'ason-chat-button' ), '' . self::desc( __( 'Hex colour, e.g. #25d366. Text on the colour switches between white and dark automatically for readability.', 'ason-chat-button' ) ), 'wa-color' ); self::row( __( 'Accessible name', 'ason-chat-button' ), '' . self::desc( __( 'Read by screen readers. Empty = "Chat on WhatsApp" in the visitor language.', 'ason-chat-button' ) ), 'wa-label' ); echo ''; self::render_menu( $s ); echo '

' . esc_html__( 'Messages', 'ason-chat-button' ) . '

' . esc_html__( 'Placeholders: {title} = page or product name, {url} = page address, {site} = site name. Empty = default text in the visitor language. Texts you enter can be translated in Polylang, WPML or Ason Translate (string translation).', 'ason-chat-button' ) . '

'; self::row( __( 'Product page message', 'ason-chat-button' ), '', 'wa-mp' ); self::row( __( 'Message on other pages', 'ason-chat-button' ), '', 'wa-mg' ); $types = ''; foreach ( get_post_types( array( 'public' => true ), 'objects' ) as $pt ) { if ( 'attachment' === $pt->name ) { continue; } $types .= ' '; } self::row( __( 'Product pages are', 'ason-chat-button' ), $types . self::desc( __( 'Single pages of these content types use the product message. If your machines are pages or a custom type, tick it here.', 'ason-chat-button' ) ) ); self::row( __( 'WooCommerce product page', 'ason-chat-button' ), self::check( 'woo_button', (int) $s['woo_button'], __( 'Add a WhatsApp button below the product summary', 'ason-chat-button' ) ) . '
' ); echo ''; echo '

' . esc_html__( 'Privacy (KVKK / GDPR)', 'ason-chat-button' ) . '

'; self::row( __( 'Information note', 'ason-chat-button' ), self::check( 'note', (int) $s['note'], __( 'Show a short note before the visitor goes to WhatsApp', 'ason-chat-button' ) ) . self::desc( __( 'The floating button first opens a small panel with the note and a "Continue to WhatsApp" link; inline buttons show the note below them.', 'ason-chat-button' ) ) ); self::row( __( 'Note text', 'ason-chat-button' ), '', 'wa-nt' ); self::row( __( 'Privacy notice page', 'ason-chat-button' ), '' . self::desc( __( 'Link shown after the note. Empty = the WordPress privacy policy page (Settings → Privacy).', 'ason-chat-button' ) ), 'wa-pu' ); echo ''; submit_button(); echo '
'; if ( '' !== $s['phone'] ) { $ctx = array( 'type' => 'general', 'title' => wp_specialchars_decode( (string) get_bloginfo( 'name' ), ENT_QUOTES ), 'url' => home_url( '/' ), 'site' => wp_specialchars_decode( (string) get_bloginfo( 'name' ), ENT_QUOTES ), 'id' => 0, ); echo '

' . esc_html__( 'Example link (home page)', 'ason-chat-button' ) . '

' . esc_html( Render::link( $s['phone'], Render::message( $ctx ) ) ) . '

'; } } private static function render_menu( array $s ): void { $names = array( 'whatsapp' => __( 'WhatsApp (number above)', 'ason-chat-button' ), 'call' => __( 'Call', 'ason-chat-button' ), 'email' => __( 'Email', 'ason-chat-button' ), 'map' => __( 'Location', 'ason-chat-button' ), 'consent' => __( 'Cookie settings (Ason Consent)', 'ason-chat-button' ), 'top' => __( 'Back to top', 'ason-chat-button' ), ); $items = (array) $s['menu_items']; echo '

' . esc_html__( 'Quick actions menu', 'ason-chat-button' ) . '

' . esc_html__( 'One floating "⋯" button replaces the WhatsApp button and opens the actions below. Works without JavaScript; a small optional script closes the menu after an action. Corner, size, distances and devices above also apply to this button.', 'ason-chat-button' ) . '

'; self::row( __( 'Status', 'ason-chat-button' ), self::check( 'menu', (int) $s['menu'], __( 'Show the quick actions menu instead of the WhatsApp button', 'ason-chat-button' ) ) ); $rows = ''; foreach ( Settings::MENU_KEYS as $i => $k ) { $p = array_search( $k, $items, true ); $pos = false === $p ? count( Settings::MENU_KEYS ) + $i + 1 : (int) $p + 1; $rows .= '
'; } self::row( __( 'Actions', 'ason-chat-button' ), $rows . self::desc( __( 'An action without data is not shown (e.g. Call without a number, Cookie settings without Ason Consent).', 'ason-chat-button' ) ) ); self::row( __( 'Phone for "Call"', 'ason-chat-button' ), '', 'm-phone' ); self::row( __( 'Email address', 'ason-chat-button' ), '', 'm-email' ); self::row( __( 'Map link', 'ason-chat-button' ), '', 'm-map' ); self::row( __( 'Accent colour', 'ason-chat-button' ), '', 'm-color' ); self::row( __( 'Dark colour (open state)', 'ason-chat-button' ), '', 'm-dark' ); self::row( __( 'WhatsApp icon colour', 'ason-chat-button' ), self::check( 'menu_wa_color', (int) $s['menu_wa_color'], __( 'Use the WhatsApp colour above for the WhatsApp action', 'ason-chat-button' ) ) ); self::row( __( 'Corner radius (px)', 'ason-chat-button' ), '' . self::desc( __( '0 = sharp corners.', 'ason-chat-button' ) ), 'm-radius' ); self::row( __( 'Hide overlapping buttons', 'ason-chat-button' ), self::check( 'menu_hide_consent', (int) $s['menu_hide_consent'], __( 'Hide the Ason Consent corner button (only when "Cookie settings" is in the menu)', 'ason-chat-button' ) ) . '
' . self::check( 'menu_hide_top', (int) $s['menu_hide_top'], __( 'Hide common theme "back to top" buttons', 'ason-chat-button' ) ) . '
' . esc_html( Settings::TOP_PRESET ) . '' ); self::row( __( 'More selectors to hide', 'ason-chat-button' ), '' . self::desc( __( 'CSS selectors, comma separated. Hidden only while the menu is shown; untick or empty the field to restore them.', 'ason-chat-button' ) ), 'm-sel' ); echo ''; } private static function render_usage(): void { echo '

' . esc_html__( 'Shortcode', 'ason-chat-button' ) . '

'; echo '

[ason_chat_button] ' . esc_html__( 'adds an inline WhatsApp button, e.g. next to a product call to action.', 'ason-chat-button' ) . '

'; echo '

[ason_chat_button text="Get a quote" message="Hello, I need a quote for {title} ({url})"]

'; echo '

' . esc_html__( 'How it works', 'ason-chat-button' ) . '

'; do_action( 'ason_chat_button_usage_after' ); } }