false, 'show_ui' => false, 'show_in_rest' => false, 'exclude_from_search' => true, 'publicly_queryable' => false, 'rewrite' => false, 'query_var' => false, 'can_export' => false, 'supports' => array( 'title', 'editor', 'excerpt' ), ) ); } public static function kept_here( $form ) { return in_array( $form, array( 'wpforms', 'elementor', 'fluent' ), true ) || ( 'cf7' === $form && ! class_exists( 'Flamingo_Inbound_Message' ) ); } public static function keep( $form, array $fields, $ref ) { $clean = array(); foreach ( $fields as $label => $value ) { if ( is_array( $value ) ) { $value = implode( ', ', array_filter( array_map( 'strval', $value ), 'is_scalar' ) ); } if ( ! is_scalar( $value ) ) { continue; } $label = sanitize_text_field( (string) $label ); $value = sanitize_textarea_field( (string) $value ); if ( '' === $label || '' === trim( $value ) ) { continue; } $clean[ substr( $label, 0, 80 ) ] = substr( $value, 0, 4000 ); if ( count( $clean ) >= 30 ) { break; } } if ( empty( $clean ) ) { return 0; } $id = wp_insert_post( array( 'post_type' => self::TYPE, 'post_status' => 'private', 'post_title' => 1 === preg_match( '/^[0-9a-f]{6}$/', (string) $ref ) ? $ref : '', 'post_excerpt' => sanitize_key( (string) $form ), 'post_content' => wp_json_encode( $clean ), ), false ); return is_int( $id ) && $id > 0 ? $id : 0; } public static function recent() { $posts = get_posts( array( 'post_type' => self::TYPE, 'post_status' => 'private', 'posts_per_page' => self::MOST, 'orderby' => 'date', 'order' => 'DESC', ) ); $out = array(); foreach ( $posts as $p ) { $fields = json_decode( (string) $p->post_content, true ); if ( ! is_array( $fields ) || '' === (string) $p->post_title ) { continue; } $out[ (string) $p->post_title ][] = array( 'id' => (int) $p->ID, 't' => (int) get_post_time( 'U', true, $p ), 'form' => (string) $p->post_excerpt, 'fields' => $fields, 'sent' => (bool) get_post_meta( (int) $p->ID, 'rabbitproof_sent', true ), ); } return $out; } public static function purge() { $old = get_posts( array( 'post_type' => self::TYPE, 'post_status' => 'private', 'posts_per_page' => -1, 'fields' => 'ids', 'date_query' => array( array( 'before' => self::DAYS . ' days ago', 'column' => 'post_date_gmt' ) ), ) ); foreach ( $old as $id ) { wp_delete_post( (int) $id, true ); } $extra = get_posts( array( 'post_type' => self::TYPE, 'post_status' => 'private', 'posts_per_page' => -1, 'fields' => 'ids', 'orderby' => 'date', 'order' => 'DESC', 'offset' => self::MOST, ) ); foreach ( $extra as $id ) { wp_delete_post( (int) $id, true ); } } public static function send( $id ) { $p = get_post( (int) $id ); if ( ! $p || self::TYPE !== $p->post_type ) { return false; } $fields = json_decode( (string) $p->post_content, true ); if ( ! is_array( $fields ) ) { return false; } $lines = array(); foreach ( $fields as $label => $value ) { $lines[] = $label . ': ' . $value; } $site = (string) wp_parse_url( home_url( '/' ), PHP_URL_HOST ); /* translators: 1: the form's name, 2: the website */ $subject = sprintf( __( 'A message Rabbitproof refused on %2$s (%1$s)', 'rabbitproof' ), self::form_name( (string) $p->post_excerpt ), $site ); $body = implode( "\n", $lines ) . "\n\n" . __( 'Rabbitproof refused this as a spam bot and you unblocked the sender. Reply to them from here.', 'rabbitproof' ); $ok = wp_mail( (string) get_option( 'admin_email' ), $subject, $body ); if ( $ok ) { update_post_meta( (int) $id, 'rabbitproof_sent', 1 ); } return (bool) $ok; } public static function send_for( $ref ) { $ref = (string) $ref; if ( '' === $ref ) { return 0; } $all = self::recent(); $n = 0; foreach ( isset( $all[ $ref ] ) ? $all[ $ref ] : array() as $m ) { if ( empty( $m['sent'] ) && self::send( $m['id'] ) ) { $n++; } } return $n; } public static function fluent_spam( $form, array $form_data ) { global $wpdb; $form_id = is_object( $form ) && isset( $form->id ) ? (int) $form->id : 0; if ( ! $form_id || ! isset( $wpdb ) || ! is_object( $wpdb ) ) { return 0; } $response = array(); foreach ( $form_data as $name => $value ) { if ( is_string( $name ) && 0 !== strpos( $name, '_' ) && ( is_scalar( $value ) || is_array( $value ) ) ) { $response[ $name ] = $value; } } $table = $wpdb->prefix . 'fluentform_submissions'; $serial = (int) $wpdb->get_var( $wpdb->prepare( 'SELECT MAX(serial_number) FROM %i WHERE form_id = %d', $table, $form_id ) ) + 1; // phpcs:ignore WordPress.DB.DirectDatabaseQuery $now = current_time( 'mysql' ); $done = $wpdb->insert( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery $table, array( 'form_id' => $form_id, 'serial_number' => $serial, 'response' => wp_json_encode( $response ), 'source_url' => isset( $_SERVER['HTTP_REFERER'] ) ? esc_url_raw( wp_unslash( $_SERVER['HTTP_REFERER'] ) ) : '', 'status' => 'spam', 'is_favourite' => 0, 'created_at' => $now, 'updated_at' => $now, ) ); return $done ? (int) $wpdb->insert_id : 0; } public static function remove_all() { $all = get_posts( array( 'post_type' => self::TYPE, 'post_status' => 'any', 'posts_per_page' => -1, 'fields' => 'ids' ) ); foreach ( $all as $id ) { wp_delete_post( (int) $id, true ); } } public static function form_name( $form ) { $names = array( 'cf7' => 'Contact Form 7', 'wpforms' => 'WPForms', 'elementor' => 'Elementor', 'fluent' => 'Fluent Forms', ); return isset( $names[ $form ] ) ? $names[ $form ] : __( 'Form', 'rabbitproof' ); } }