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' ) . '
$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' ),
);
?>
' . 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() ) ) . '
' . 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' ) . '
'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"
. '}';
?>