formconfirmed. * * Tabs: Overview (status, counters, connection test), Forms (switch every form on or off), * Settings (keys, message check, backup check, what happens to unclear messages), Held messages, * Developers (shortcode, PHP functions, Contact Form 7 tag, filters). Also the notice while the * service gives no clear answer, and the paragraph for the privacy policy guide. */ class Formconfirmed_Admin { const PAGE = 'formconfirmed'; const TABS = array( 'overview', 'forms', 'settings', 'held', 'fields', 'developers' ); public static function init() { if ( ! is_admin() ) { return; } add_action( 'admin_menu', array( __CLASS__, 'menu' ) ); add_action( 'admin_enqueue_scripts', array( __CLASS__, 'assets' ) ); add_action( 'admin_init', array( __CLASS__, 'privacy' ) ); add_action( 'admin_notices', array( __CLASS__, 'notice' ) ); add_action( 'admin_post_formconfirmed_save', array( __CLASS__, 'action_save' ) ); add_action( 'admin_post_formconfirmed_save_forms', array( __CLASS__, 'action_save_forms' ) ); add_action( 'admin_post_formconfirmed_save_fields', array( __CLASS__, 'action_save_fields' ) ); add_action( 'admin_post_formconfirmed_test', array( __CLASS__, 'action_test' ) ); add_action( 'admin_post_formconfirmed_report', array( __CLASS__, 'action_report' ) ); add_action( 'admin_post_formconfirmed_connect', array( __CLASS__, 'action_connect' ) ); add_action( 'admin_post_formconfirmed_dismiss', array( __CLASS__, 'action_dismiss' ) ); add_filter( 'plugin_action_links_' . plugin_basename( FORMCONFIRMED_FILE ), array( __CLASS__, 'links' ) ); } public static function menu() { add_options_page( 'formconfirmed', 'formconfirmed', 'manage_options', self::PAGE, array( __CLASS__, 'page' ) ); } public static function assets( $hook ) { if ( 'settings_page_' . self::PAGE === $hook ) { wp_enqueue_style( 'formconfirmed-admin', plugins_url( 'assets/css/admin.css', FORMCONFIRMED_FILE ), array(), FORMCONFIRMED_VERSION ); } } public static function url( $args = array() ) { return add_query_arg( array_merge( array( 'page' => self::PAGE ), $args ), admin_url( 'options-general.php' ) ); } public static function links( $links ) { array_unshift( $links, '' . esc_html__( 'Settings', 'formconfirmed' ) . '' ); return $links; } /** The site is connected to a formexposed account through the formexposed plugin (one-click keys). */ public static function formexposed_linked() { return class_exists( 'Formexposed_Core' ) && method_exists( 'Formexposed_Core', 'linked' ) && Formexposed_Core::linked() && defined( 'FORMEXPOSED_API' ) && '' !== FORMEXPOSED_API; } // ------------------------------------------------------------------ problems /** A problem with the service in the last 24 hours, after which no clear answer came. */ public static function recent_problem() { $o = Formconfirmed_Core::opt(); if ( empty( $o['problem']['at'] ) || (int) $o['problem']['at'] < time() - DAY_IN_SECONDS ) { return null; } if ( (int) $o['ok_at'] > (int) $o['problem']['at'] ) { return null; } return $o['problem']; } public static function problem_text( $code ) { $codes = explode( ',', (string) $code ); if ( array_intersect( $codes, array( 'invalid-input-secret', 'missing-input-secret' ) ) ) { return __( 'The service does not accept the secret key. Enter it again or create new keys in your account.', 'formconfirmed' ); } if ( in_array( 'site-paused', $codes, true ) ) { return __( 'The protected site is paused in your account (or its plan ended). Activate it again there.', 'formconfirmed' ); } if ( in_array( 'service-disabled', $codes, true ) ) { return __( 'The service is switched off at the moment.', 'formconfirmed' ); } if ( in_array( 'service_unavailable', $codes, true ) ) { return __( 'A visitor\'s browser could not reach the service (for example a network filter blocks it).', 'formconfirmed' ); } return __( 'The service could not be reached or did not give a valid answer.', 'formconfirmed' ); } /** The state of the protection: off, waiting, problem or on. */ public static function state() { if ( ! Formconfirmed_Core::on() ) { return 'off'; } if ( Formconfirmed_Core::paused() ) { return 'waiting'; } return self::recent_problem() ? 'problem' : 'on'; } public static function notice() { if ( ! current_user_can( 'manage_options' ) ) { return; } $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null; if ( ! $screen || ! in_array( $screen->id, array( 'dashboard', 'plugins' ), true ) ) { return; } if ( Formconfirmed_Core::paused() ) { echo '

formconfirmed: ' . esc_html__( 'Waiting: the form protection tab of the formexposed plugin still checks your forms. Update formexposed to 1.10.0 or later - then formconfirmed takes over with the same keys.', 'formconfirmed' ) . '

'; return; } if ( ! Formconfirmed_Core::on() && 'plugins' === $screen->id ) { echo '

formconfirmed: ' . esc_html__( 'Add your keys to protect your forms.', 'formconfirmed' ) . ' ' . esc_html__( 'Set up formconfirmed', 'formconfirmed' ) . '

'; return; } $p = self::recent_problem(); if ( ! $p || (int) get_option( 'formconfirmed_notice_off', 0 ) > time() ) { return; } echo '

formconfirmed: ' . esc_html( self::problem_text( $p['code'] ) ) . ' ' . esc_html__( 'Messages without a clear check are delivered only if the backup check on this site passed; otherwise they are held or refused, never let through unseen.', 'formconfirmed' ) . ' ' . esc_html__( 'Open formconfirmed', 'formconfirmed' ) . ' ยท ' . '' . esc_html__( 'Hide for a day', 'formconfirmed' ) . '

'; } public static function action_dismiss() { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'Not allowed.', 'formconfirmed' ) ); } check_admin_referer( 'formconfirmed_dismiss' ); update_option( 'formconfirmed_notice_off', time() + DAY_IN_SECONDS, false ); wp_safe_redirect( wp_get_referer() ? wp_get_referer() : admin_url() ); exit; } // ------------------------------------------------------------------ page public static function page() { if ( ! current_user_can( 'manage_options' ) ) { return; } $tab = sanitize_key( (string) filter_input( INPUT_GET, 'tab', FILTER_UNSAFE_RAW ) ); // only picks the tab that is shown $tab = in_array( $tab, self::TABS, true ) ? $tab : 'overview'; $msg = get_transient( 'formconfirmed_msg' ); delete_transient( 'formconfirmed_msg' ); $open = Formconfirmed_Held::count_open(); $labels = array( 'overview' => __( 'Overview', 'formconfirmed' ), 'forms' => __( 'Forms', 'formconfirmed' ), 'settings' => __( 'Settings', 'formconfirmed' ), 'held' => __( 'Held messages', 'formconfirmed' ), 'fields' => __( 'Field mapping', 'formconfirmed' ), 'developers' => __( 'Developers', 'formconfirmed' ), ); ?>

formconfirmed

__( 'Not active', 'formconfirmed' ), 'waiting' => __( 'Waiting', 'formconfirmed' ), 'problem' => __( 'Active, with a problem', 'formconfirmed' ), 'on' => __( 'Active', 'formconfirmed' ), ); return '' . esc_html( $t[ $state ] ) . ''; } /** True for a POST request; the method is read, unslashed and sanitized. */ public static function is_post() { return isset( $_SERVER['REQUEST_METHOD'] ) && 'POST' === sanitize_text_field( wp_unslash( $_SERVER['REQUEST_METHOD'] ) ); } /** Read-only screen filter from the query string. It changes nothing, so it needs no nonce. */ private static function query_arg( $key ) { $value = filter_input( INPUT_GET, $key, FILTER_UNSAFE_RAW ); return is_string( $value ) ? sanitize_text_field( $value ) : ''; } public static function action_report() { if ( ! self::is_post() || ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'Not allowed.', 'formconfirmed' ) ); } check_admin_referer( 'formconfirmed_report' ); $before = Formconfirmed_Core::report_status(); $ok = Formconfirmed_Core::report_integration( true ); $after = Formconfirmed_Core::report_status(); $msg = $ok ? array( 'ok', __( 'The technical report was accepted by the service.', 'formconfirmed' ) ) : array( 'warning', $after['attempt']===$before['attempt'] ? __( 'No new report was sent. Check that protection is active and wait at least 30 seconds between attempts.', 'formconfirmed' ) : __( 'The report was not accepted. A retry is scheduled; the last successful delivery remains visible below.', 'formconfirmed' ) ); set_transient( 'formconfirmed_msg', $msg, 120 ); wp_safe_redirect( self::url() . '#fc-report-status' ); exit; } private static function report_panel() { $s = Formconfirmed_Core::report_status(); $format = get_option( 'date_format' ) . ' ' . get_option( 'time_format' ); ?>

__( 'Last attempt', 'formconfirmed' ), 'success'=>__( 'Last accepted report', 'formconfirmed' ) ) as $key=>$label ) : ?>

array( 'class' => true ) ) ); ?>

$title ) { if ( Formconfirmed_Core::form_enabled( $a, $id ) ) { $out[] = $labels[ $a ] . ': ' . $title; } } } else { $out[] = $labels[ $a ]; } } return $out; } /** Where a form is edited in its own plugin. */ private static function edit_url( $adapter, $id ) { $id = absint( $id ); switch ( $adapter ) { case 'cf7': return admin_url( 'admin.php?page=wpcf7&post=' . $id . '&action=edit' ); case 'wpforms': return admin_url( 'admin.php?page=wpforms-builder&view=fields&form_id=' . $id ); case 'gravityforms': return admin_url( 'admin.php?page=gf_edit_forms&id=' . $id ); case 'fluentform': return admin_url( 'admin.php?page=fluent_forms&route=editor&form_id=' . $id ); case 'formidable': return admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . $id ); } return ''; } /** A switch: a real checkbox with its label, styled as a toggle. */ private static function toggle( $name, $checked, $label, $id ) { ?> __( 'Every Elementor Pro form on the site.', 'formconfirmed' ), 'comments' => __( 'The comment form of your theme. Logged-in moderators are never checked.', 'formconfirmed' ), 'register' => __( 'wp-login.php?action=register. During an outage of the service a registration is refused and the visitor can try again.', 'formconfirmed' ), 'woo_register' => __( 'The registration on the WooCommerce "My account" page (not the account creation in the checkout).', 'formconfirmed' ), 'login' => __( 'Off by default. Only "block" stops a login with the correct password; when the service gives no clear answer, the password decides.', 'formconfirmed' ), 'gravityforms' => __( 'Messages that are not passed are filed under Entries -> Spam.', 'formconfirmed' ), ); ?>

General).', 'formconfirmed' ) : esc_html__( 'Not installed', 'formconfirmed' ); ?>

$title ) : ?>

' . esc_html__( 'Local quarantine cleanup', 'formconfirmed' ) . '

'; if ( ! $s['available'] ) { echo '

' . esc_html__( 'Cleanup status is unavailable. Check the local database.', 'formconfirmed' ) . '

'; return; } /* translators: 1: count of messages older than retention limit */ echo '

' . esc_html( sprintf( __( 'Messages older than 14 days: %1$d', 'formconfirmed' ), $s['overdue'] ) ) . '

'; $format = get_option( 'date_format' ) . ' ' . get_option( 'time_format' ); $last = $s['last_success'] ? get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $s['last_success'] ), $format ) : __( 'Not run yet', 'formconfirmed' ); $next = $s['next_run'] ? get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $s['next_run'] ), $format ) : __( 'Not scheduled', 'formconfirmed' ); /* translators: 1: local date/time or not run yet */ echo '

' . esc_html( sprintf( __( 'Last successful cleanup batch: %1$s', 'formconfirmed' ), $last ) ) . '

'; /* translators: 1: local date/time or not scheduled */ echo '

' . esc_html( sprintf( __( 'Next cleanup: %1$s', 'formconfirmed' ), $next ) ) . '

'; if ( $s['failed'] ) { echo '

' . esc_html__( 'Some entries could not be removed. A later batch will retry; check storage if this persists.', 'formconfirmed' ) . '

'; } echo '

' . esc_html__( 'Cleanup runs in batches of at most 100 messages. On low-traffic sites, configure a system scheduler for WordPress cron as described in the plugin readme.', 'formconfirmed' ) . '

'; } private static function page_held() { self::cleanup_notice(); if ( Formconfirmed_Held::external() ) { echo '

' . esc_html__( 'The formexposed plugin is active: held messages wait in its quarantine (Settings -> formexposed -> Quarantine), together with the messages its protection layer stopped.', 'formconfirmed' ) . '

'; return; } /* translators: 1: number of days, 2: e-mail address */ echo '

' . esc_html( sprintf( __( 'Messages that were not passed wait here for %1$d days. "Send" passes one to the mailer for %2$s; this does not confirm delivery.', 'formconfirmed' ), Formconfirmed_Held::DAYS, Formconfirmed_Held::recipient() ) ) . '

'; $filters = Formconfirmed_Held::filters( array( 'status' => self::query_arg( 'held_status' ), 'form' => self::query_arg( 'held_form' ), 'after' => self::query_arg( 'held_after' ), 'before' => self::query_arg( 'held_before' ) ) ); $page = max( 1, absint( self::query_arg( 'held_page' ) ) ); $list = Formconfirmed_Held::listing( $filters, $page, 50 ); $rows = $list['rows']; self::held_filters( $filters ); self::held_pagination( $list ); echo '

' . esc_html__( 'Rate a message explicitly as Not spam or Spam. Only its opaque check ID and your rating are sent to the service. Sending or deleting a message does not rate it. Older messages without a check ID cannot be rated.', 'formconfirmed' ) . '

'; if ( ! $rows ) { echo '

' . esc_html__( 'No held messages.', 'formconfirmed' ) . '

'; return; } ?>
:
'held','held_status'=>$f['status'],'held_form'=>$f['form'],'held_after'=>$f['after'],'held_before'=>$f['before']); echo ''; } private static function page_fields() { $choices=array();$labels=Formconfirmed_Core::labels(); foreach(Formconfirmed_Core::PER_FORM as $adapter)foreach(Formconfirmed_Core::forms_of($adapter) as $id=>$title)$choices[$adapter.':'.$id]=$labels[$adapter].' โ€” '.$title; $pick=self::query_arg('mapping'); if(!isset($choices[$pick]))$pick=$choices?array_key_first($choices):''; ?>

'.esc_html__('No supported forms found.','formconfirmed').'

';return;} list($adapter,$id)=explode(':',$pick,2);$defs=Formconfirmed_Fields::definitions($adapter,(int)$id);$saved=Formconfirmed_Fields::saved_roles($adapter,(int)$id); ?>

'fields','mapping'=>$adapter.':'.$id)));exit; } private static function page_developers() { $php = "):\n" . "echo formconfirmed_widget( 'contact' ); // same as the shortcode [formconfirmed]\n\n" . "// In the handler of the form:\n" . "\$r = formconfirmed_check( array(\n" . " 'purpose' => 'contact',\n" . " 'content' => \$message, // optional, for the content check\n" . " 'email' => \$email, // optional\n" . " 'name' => \$name, // optional, for the name check\n" . " 'form' => 'Callback form', // optional: keep a copy when not passed ...\n" . " 'fields' => array( array( 'Name', \$name ), array( 'Message', \$message ) ), // ... with these fields\n" . ") );\n" . "if ( \$r['pass'] ) {\n" . " // send or store the message\n" . "} elseif ( 'hold' === \$r['decision'] ) {\n" . " // not sure: keep it for review (a copy is under Held messages when 'form' and 'fields' were given)\n" . "} else {\n" . " // refused: show \$r['message'] to the visitor\n" . '}'; ?>

[formconfirmed]
[formconfirmed purpose="newsletter"]

Contact Form 7

[formconfirmed]

formconfirmed_field_roles
formconfirmed_client_ip
formconfirmed_held_recipient
formconfirmed_pow_max
FORMCONFIRMED_API
'settings' ) ) ); exit; } /** Forms tab: form plugins on/off, single forms on/off, new forms. */ public static function action_save_forms() { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'Not allowed.', 'formconfirmed' ) ); } check_admin_referer( 'formconfirmed_save_forms' ); $o = Formconfirmed_Core::opt(); $adapters = isset( $_POST['adapters'] ) && is_array( $_POST['adapters'] ) ? array_map( 'sanitize_key', array_keys( map_deep( wp_unslash( $_POST['adapters'] ), 'sanitize_key' ) ) ) : array(); $o['adapters'] = array_values( array_intersect( Formconfirmed_Core::ADAPTERS, $adapters ) ); $o['new_forms'] = ! empty( $_POST['new_forms'] ); $seen = isset( $_POST['seen'] ) && is_array( $_POST['seen'] ) ? map_deep( wp_unslash( $_POST['seen'] ), 'absint' ) : array(); $on = isset( $_POST['forms'] ) && is_array( $_POST['forms'] ) ? map_deep( wp_unslash( $_POST['forms'] ), 'absint' ) : array(); foreach ( Formconfirmed_Core::PER_FORM as $a ) { if ( empty( $seen[ $a ] ) || ! is_array( $seen[ $a ] ) ) { continue; // not shown (plugin not installed): keep what was saved } foreach ( $seen[ $a ] as $id ) { $id = (string) absint( $id ); if ( '0' === $id ) { continue; } $o['forms'][ $a ][ $id ] = ! empty( $on[ $a ][ $id ] ); } } Formconfirmed_Core::save_opt( $o ); set_transient( 'formconfirmed_msg', array( 'ok', __( 'Saved. If a page cache or CDN serves your pages, clear it so the forms show the change.', 'formconfirmed' ) ), 120 ); wp_safe_redirect( self::url( array( 'tab' => 'forms' ) ) ); exit; } /** "Test the connection": the health endpoint, the secret key (an empty response is refused, the code tells why), the backup check. */ public static function action_test() { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'Not allowed.', 'formconfirmed' ) ); } check_admin_referer( 'formconfirmed_test' ); $h = wp_remote_get( FORMCONFIRMED_API . '/health', array( 'timeout' => Formconfirmed_Core::TIMEOUT ) ); if ( is_wp_error( $h ) || 200 !== (int) wp_remote_retrieve_response_code( $h ) ) { /* translators: %s: error message or HTTP status */ $msg = array( 'error', sprintf( __( 'The service did not answer (%s). Until it does, messages are delivered only if the backup check passed; otherwise they are held or refused.', 'formconfirmed' ), is_wp_error( $h ) ? __( 'network error', 'formconfirmed' ) : 'HTTP ' . (int) wp_remote_retrieve_response_code( $h ) ) ); } else { $r = wp_remote_post( FORMCONFIRMED_API . '/verify', array( 'timeout' => Formconfirmed_Core::TIMEOUT, 'body' => array( 'secret' => Formconfirmed_Core::opt()['secret'], 'response' => '' ), ) ); $j = is_wp_error( $r ) ? null : json_decode( (string) wp_remote_retrieve_body( $r ), true ); $codes = is_array( $j ) && isset( $j['error-codes'] ) ? array_filter( (array) $j['error-codes'], 'is_string' ) : array(); if ( in_array( 'missing-input-response', $codes, true ) ) { $o = Formconfirmed_Core::opt(); $o['ok_at'] = time(); Formconfirmed_Core::save_opt( $o ); Formconfirmed_Core::report_integration(); $msg = array( 'ok', __( 'Connected: the service answers and accepts the secret key.', 'formconfirmed' ) ); } elseif ( $codes ) { $msg = array( 'error', self::problem_text( implode( ',', $codes ) ) ); } else { $msg = array( 'error', __( 'The service gave an answer this plugin does not understand.', 'formconfirmed' ) ); } } if ( Formconfirmed_Backup::own() ) { $t = Formconfirmed_Backup::self_test(); if ( is_wp_error( $t ) ) { $msg = array( 'ok' === $msg[0] ? 'warning' : 'error', $msg[1] . ' ' . __( 'The backup self-test failed.', 'formconfirmed' ) ); } else { $msg[1] .= ' ' . __( 'Backup check: self-test passed.', 'formconfirmed' ); } } set_transient( 'formconfirmed_msg', $msg, 120 ); wp_safe_redirect( self::url() ); exit; } /** Keys from the account the formexposed plugin connected this site to (POST /api/plugin/protect). */ public static function action_connect() { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'Not allowed.', 'formconfirmed' ) ); } check_admin_referer( 'formconfirmed_connect' ); if ( ! self::formexposed_linked() ) { wp_safe_redirect( self::url( array( 'tab' => 'settings' ) ) ); exit; } $r = wp_remote_post( FORMEXPOSED_API . '/api/plugin/protect', array( 'timeout' => 15, 'body' => array( 'site' => Formexposed_Core::host(), 'key' => Formexposed_Core::key(), 'secret' => Formexposed_Core::secret(), ), ) ); $j = is_wp_error( $r ) ? null : json_decode( wp_remote_retrieve_body( $r ), true ); if ( is_array( $j ) && 'success' === ( isset( $j['status'] ) ? $j['status'] : '' ) && ! empty( $j['site_key'] ) && ! empty( $j['secret'] ) ) { $o = Formconfirmed_Core::opt(); $o['site_key'] = preg_replace( '/[^a-z0-9_]/', '', strtolower( sanitize_text_field( (string) $j['site_key'] ) ) ); $o['secret'] = sanitize_text_field( (string) $j['secret'] ); Formconfirmed_Core::save_opt( $o ); set_transient( 'formconfirmed_msg', array( 'ok', __( 'Connected. The forms are protected now.', 'formconfirmed' ) ), 120 ); } else { $m = is_array( $j ) && ! empty( $j['message'] ) ? sanitize_text_field( (string) $j['message'] ) : ( is_wp_error( $r ) ? $r->get_error_message() : __( 'The service did not answer.', 'formconfirmed' ) ); set_transient( 'formconfirmed_msg', array( 'error', $m ), 120 ); } wp_safe_redirect( self::url( array( 'tab' => 'settings' ) ) ); exit; } /** Paragraph for the privacy policy guide (Settings -> Privacy). */ public static function privacy() { if ( ! function_exists( 'wp_add_privacy_policy_content' ) ) { return; } $text = __( 'Our forms are protected by formconfirmed, a service of LW IT Solutions with servers in the EU. On pages with a protected form your browser loads a script of the service and solves a small calculation task; no cookies are set and nothing is stored on your device. When you send the form, this website sends the result, your IP address, the e-mail address entered in the form and - if enabled - the mapped contact name, registration name or comment author and the message text to the service, which checks them for spam and returns a decision. The message text is processed briefly on the service servers. AI checks use a temporary internal queue. The IP address is only kept shortened and hashed. If the check cannot be completed, your message is delivered only after an independent check on this website; otherwise it is held for review or refused, not delivered unchecked. Messages that are not passed are kept on this website for 14 days so they can be reviewed.', 'formconfirmed' ); wp_add_privacy_policy_content( 'formconfirmed', wpautop( esc_html( $text ) ) ); } }