'string', 'sanitize_callback' => 'odrop_support_sanitize_card', 'default' => '', 'show_in_rest' => false, ]); } add_action('admin_init', 'odrop_support_register_settings'); /** * What is saved when Save is pressed: the card in its canonical spelling, '' for an empty field * (the button goes away), or - for anything that is not a card - the card that was already there, * with the reason shown at the top of the screen. */ function odrop_support_sanitize_card($value): string { $pasted = is_string($value) ? $value : ''; if (trim($pasted) === '') { return ''; } $read = odrop_support_read_card($pasted); if (isset($read['card'])) { return $read['card']; } add_settings_error( ODROP_SUPPORT_OPT_CARD, 'odrop_support_card_' . $read['error'], odrop_support_card_refusal($read['error']) ); return odrop_support_saved_card(); } /** The plain reason a pasted card was refused, one per reason the engine can give. */ function odrop_support_card_refusal(string $reason): string { if ($reason === 'version') { return esc_html__('This card is from a newer ODrop™ app. Update this plugin, then paste it again.', 'odrop-support'); } if ($reason === 'key') { return esc_html__('This card is damaged. Copy the line again from the ODrop™ app.', 'odrop-support'); } return esc_html__('That is not a support card. Copy the line again from the ODrop™ app and paste all of it.', 'odrop-support'); } /** What the button sends where. readme.txt's "External services" section carries the same words. */ function odrop_support_external_services_text(): string { return __('When a visitor opens the chat, and when they come back within 30 days of a conversation, the button connects to odrop.app, so odrop.app sees that visitor\'s internet address. When they write, their name (if they give one), this site\'s address and their messages go through odrop.app sealed, so only you can read them. odrop.app also counts, under this site\'s name, how often the chat is opened and written in.', 'odrop-support'); } /** Render the screen. */ function odrop_support_render_settings(): void { if (!current_user_can('manage_options')) { return; } $card = odrop_support_saved_card(); ?>