Changeset 2903553
- Timestamp:
- 04/25/2023 12:24:41 AM (3 years ago)
- Location:
- gravity-forms-zero-spam/trunk
- Files:
-
- 3 edited
-
gravityforms-zero-spam-form-settings.php (modified) (5 diffs)
-
gravityforms-zero-spam.php (modified) (2 diffs)
-
readme.txt (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
gravity-forms-zero-spam/trunk/gravityforms-zero-spam-form-settings.php
r2867489 r2903553 18 18 protected $_short_title = 'Zero Spam'; 19 19 20 const REPORT_LAST_SENT_DATE_OPTION = 'gf_zero_spam_report_last_date'; 21 22 const REPORT_CRON_HOOK_NAME = 'gf_zero_spam_send_report'; 23 20 24 public function init() { 21 25 parent::init(); … … 27 31 // per-form setting may still _override_ the default. 28 32 add_filter( 'gf_zero_spam_check_key_field', array( $this, 'filter_gf_zero_spam_check_key_field' ), 20, 2 ); 29 } 30 31 /** 32 * Use per-form settings to determine whether to check for spam. 33 34 add_filter( 'gf_zero_spam_add_key_field', array( $this, 'filter_gf_zero_spam_add_key_field' ), 20 ); 35 36 add_filter( 'cron_schedules', array( $this, 'add_cron_schedules' ) ); 37 add_action( self::REPORT_CRON_HOOK_NAME, array( $this, 'send_report' ) ); 38 add_action( 'gform_after_submission', array( $this, 'after_submission' ) ); 39 add_action( 'gform_update_status', array( $this, 'update_status' ), 10, 2 ); 40 } 41 42 /** 43 * @inheritdoc 44 * @since 1.4 45 */ 46 public function get_menu_icon() { 47 return '<svg style="height: 28px; width: 37px; max-width: 37px" width="1358" height="1056" viewBox="0 0 1358 1056" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1058.52 262.19L767.31 478.75C729.344 507.251 683.153 522.66 635.68 522.66C588.207 522.66 542.016 507.251 504.05 478.75L212.84 262.19C204 255.619 198.133 245.806 196.529 234.909C194.924 224.012 197.714 212.925 204.285 204.085C210.856 195.245 220.669 189.378 231.566 187.774C242.463 186.169 253.55 188.959 262.39 195.53L553.6 412.13C577.276 429.899 606.078 439.505 635.68 439.505C665.282 439.505 694.084 429.899 717.76 412.13L1008.97 195.53C1013.34 192.276 1018.32 189.916 1023.6 188.585C1028.89 187.253 1034.39 186.975 1039.78 187.768C1045.17 188.56 1050.36 190.407 1055.04 193.204C1059.72 196 1063.8 199.691 1067.05 204.065C1070.31 208.439 1072.67 213.412 1074 218.698C1075.33 223.985 1075.61 229.481 1074.82 234.875C1074.02 240.269 1072.18 245.454 1069.38 250.133C1066.59 254.813 1062.89 258.896 1058.52 262.15V262.19ZM1276.96 974.8C1276.55 975.21 1276.07 975.48 1275.65 975.87C1226.01 1025.06 1159.49 1053.49 1089.62 1055.37C1019.76 1057.25 951.81 1032.45 899.59 986H189.38C84.95 986 0 901 0 796.62V189.45C0 84.99 85 0 189.38 0H1081.96C1186.43 0 1271.41 85 1271.41 189.45V580.16C1298.08 605.314 1319.45 635.55 1334.26 669.087C1349.06 702.625 1357.01 738.786 1357.63 775.442C1358.25 812.097 1351.53 848.507 1337.87 882.526C1324.21 916.546 1303.87 947.488 1278.07 973.53C1277.64 973.91 1277.37 974.39 1276.96 974.8ZM1274.6 780.04C1274.6 673.94 1188.29 587.63 1082.2 587.63C1045.54 587.597 1009.64 598.108 978.78 617.91L1244.32 883.45C1264.12 852.595 1274.63 816.7 1274.6 780.04ZM189.38 902.97H835.82C810.095 851.575 801.133 793.407 810.198 736.653C819.262 679.898 845.896 627.415 886.35 586.59C886.74 586.16 887.02 585.68 887.43 585.27C887.84 584.86 888.32 584.58 888.74 584.19C927.343 545.965 976.404 520.03 1029.73 509.658C1083.06 499.286 1138.26 504.941 1188.38 525.91V189.45C1188.35 161.235 1177.13 134.186 1157.18 114.235C1137.22 94.284 1110.17 83.0618 1081.96 83.03H189.38C161.182 83.0829 134.156 94.3155 114.227 114.265C94.2984 134.214 83.0938 161.252 83.07 189.45V796.62C83.1017 824.809 94.3111 851.835 114.24 871.772C134.169 891.708 161.191 902.928 189.38 902.97ZM1082.2 972.44C1118.86 972.467 1154.75 961.956 1185.61 942.16L920.07 676.62C900.272 707.478 889.762 743.377 889.79 780.04C889.79 886.13 976.07 972.44 1082.2 972.44Z" fill="black"/></svg>'; 48 } 49 50 /** 51 * Use global and per-form settings to determine whether to check for spam. 33 52 * 34 53 * @param bool $check_key_field … … 44 63 } 45 64 46 return $check_key_field; 65 $enabled = $this->get_plugin_setting( 'gf_zero_spam_blocking' ); 66 67 if ( is_null( $enabled ) ) { 68 return $check_key_field; 69 } 70 71 return ! empty( $enabled ); 72 } 73 74 /** 75 * Use global setting to modify whether to add the spam key field to the form. 76 * 77 * @param bool $add_key_field Whether to add the spam key field to the form. 78 * 79 * @return bool Whether to add the spam key field to the form. 80 */ 81 public function filter_gf_zero_spam_add_key_field( $add_key_field = true ) { 82 83 $enabled = $this->get_plugin_setting( 'gf_zero_spam_blocking' ); 84 85 // Not yet set. 86 if ( is_null( $enabled ) ) { 87 return $add_key_field; 88 } 89 90 return ! empty( $enabled ); 47 91 } 48 92 … … 74 118 75 119 $fields['form_options']['fields'][] = array( 76 'name'=> 'enableGFZeroSpam',77 'type'=> 'toggle',78 'label'=> esc_html__( 'Prevent spam using Gravity Forms Zero Spam', 'gf-zero-spam' ),79 'tooltip'=> gform_tooltip( 'enableGFZeroSpam', '', true ),80 'default_value' => apply_filters( 'gf_zero_spam_check_key_field', true, $form ),120 'name' => 'enableGFZeroSpam', 121 'type' => 'toggle', 122 'label' => esc_html__( 'Prevent spam using Gravity Forms Zero Spam', 'gf-zero-spam' ), 123 'tooltip' => gform_tooltip( 'enableGFZeroSpam', '', true ), 124 'default_value' => apply_filters( 'gf_zero_spam_check_key_field', true, $form ), 81 125 ); 82 126 … … 85 129 86 130 /** 87 * Logging is not currently supported. 88 * 89 * @param array $plugins An array of plugins that support logging. 131 * Register addon global settings 90 132 * 91 133 * @return array 92 134 */ 93 public function set_logging_supported( $plugins ) { 94 95 return $plugins; 135 public function plugin_settings_fields() { 136 137 $spam_report_description = sprintf( '<h3 style="margin-top: 0">%s</h3><p>%s</p><p><strong>%s</strong></p><p>%s</p><hr style="margin: 1em 0;">', 138 esc_html__( 'Know when entries are flagged as spam.', 'gf-zero-spam' ), 139 esc_html__( 'It can be hard to know when entries are being marked as spam. When enabled, this feature will send an automated spam report, giving you a summary of recent spam entries. If no spam entries have been submitted, no report will be sent.', 'gf-zero-spam' ), 140 esc_html__( 'This feature works with any spam filter, including the Gravity Forms spam honeypot, Gravity Forms Zero Spam, reCAPTCHA, or others.', 'gf-zero-spam' ), 141 strtr( esc_html__( 'Note: Depending on site traffic, time-based reports may not always be sent at the scheduled frequency. {{link}}See how to set up a "cron" to make this more reliable{{/link}}.', 'gf-zero-spam' ), array( 142 '{{heading}}' => 'Spam Report', 143 '{{link}}' => '<a href="https://deliciousbrains.com/wp-offload-ses/doc/cron-setup/" rel="nofollow noopener noreferrer" target="_blank"><span class="screen-reader-text">' . esc_html__( 'Link opens in a new tab', 'gf-zero-spam' ) . '</span>', 144 '{{/link}}' => '</a>', 145 ) ) 146 ); 147 148 // translators: Do not translate the placeholders inside the curly brackets, like this {{placeholders}}. 149 $email_body = '<h2>' . esc_html_x( 'Gravity Forms Spam Report', 'The heading inside the email body.', 'gf-zero-spam' ) . '</h2>'; 150 // translators: Do not translate the placeholders inside the curly brackets, like this {{placeholders}}. 151 $email_body .= wpautop( esc_html__( 'You have received {{total_spam_count}} spam entries from the following form(s):', 'gf-zero-spam' ) ); 152 $email_body .= '{{spam_report_list}}'; 153 // translators: Do not translate the placeholders inside the curly brackets, like this {{placeholders}}. 154 $email_body .= wpautop( '<em>' . esc_html__( 'To modify or disable this email, visit {{settings_link}}the Gravity Forms Zero Spam settings page{{/settings_link}}.', 'gf-zero-spam' ) . '</em>' ); 155 156 $available_variables_message = wpautop( esc_html__( 'The following variables may be used:', 'gf-zero-spam' ) ); 157 $available_variables_message .= '<ul class="ul-disc" style="margin-bottom: 1em;">'; 158 $available_variables_message .= '<li style="list-style: disc;"><code>{{site_name}}</code> - ' . esc_html__( 'The name of this website', 'gf-zero-spam' ) . '</li>'; 159 $available_variables_message .= '<li style="list-style: disc;"><code>{{admin_email}}</code> - ' . esc_html__( 'The email of the site administrator', 'gf-zero-spam' ) . '</li>'; 160 $available_variables_message .= '<li style="list-style: disc;"><code>{{total_spam_count}}</code> - ' . esc_html__( 'The total number of spam emails received since the last report.', 'gf-zero-spam' ) . '</li>'; 161 $available_variables_message .= '<li style="list-style: disc;"><code>{{spam_report_list}}</code> - ' . esc_html__( 'A list of forms and the number of spam entries since the last report.', 'gf-zero-spam' ) . '</li>'; 162 $available_variables_message .= '<li style="list-style: disc;"><code>{{settings_link}}</code> and <code>{{/settings_link}}</code> - ' . esc_html__( 'A link to the plugin settings page. Text inside the variables will be the link text. Make sure to include both the opening and closing variables.', 'gf-zero-spam' ) . '</li>'; 163 $available_variables_message .= '</ul>'; 164 165 return array( 166 array( 167 'title' => esc_html__( 'Spam Blocking', 'gf-zero-spam' ), 168 'description' => esc_html__( 'Enable to fight spam using a simple, effective method that is more effective than the built-in anti-spam honeypot.', 'gf-zero-spam' ) . ' ' . esc_html__( 'It is possible to enable or disable spam blocking on a per-form basis inside each form\'s settings.', 'gf-zero-spam' ), 169 'fields' => array( 170 array( 171 'label' => esc_html__( 'Enable Zero Spam by Default', 'gf-zero-spam' ), 172 'type' => 'radio', 173 'name' => 'gf_zero_spam_blocking', 174 'default_value' => '1', 175 'choices' => array( 176 array( 177 'label' => __( 'Enabled: Add Zero Spam to Gravity Forms forms', 'gf-zero-spam' ), 178 'value' => '1', 179 ), 180 array( 181 'label' => __( 'Disabled: Use Gravity Forms\' built-in spam prevention', 'gf-zero-spam' ), 182 'value' => '0', 183 ), 184 ), 185 'required' => false, 186 ), 187 ), 188 ), 189 array( 190 'title' => esc_html__( 'Spam Report Email', 'gf-zero-spam' ), 191 'description' => $spam_report_description, 192 'fields' => array( 193 array( 194 'label' => esc_html__( 'Spam Report Frequency', 'gf-zero-spam' ), 195 // translators: Do not translate the placeholders inside the curly brackets, like this {{placeholders}}. 196 'description' => wpautop( esc_html__( 'How frequently should spam report emails be sent?', 'gf-zero-spam' ) ), 197 'type' => 'radio', 198 'name' => 'gf_zero_spam_email_frequency', 199 'value' => '', 200 'choices' => array( 201 array( 202 'label' => __( 'Disabled', 'gf-zero-spam' ), 203 'value' => '', 204 ), 205 array( 206 'label' => __( 'Threshold-Based', 'gf-zero-spam' ), 207 'value' => 'entry_limit', 208 ), 209 array( 210 'label' => __( 'Twice Daily', 'gf-zero-spam' ), 211 'value' => 'twicedaily', 212 ), 213 array( 214 'label' => __( 'Daily', 'gf-zero-spam' ), 215 'value' => 'daily', 216 ), 217 array( 218 'label' => __( 'Weekly', 'gf-zero-spam' ), 219 'value' => 'weekly', 220 ), 221 array( 222 'label' => __( 'Monthly', 'gf-zero-spam' ), 223 'value' => 'monthly', 224 ), 225 ), 226 'required' => false, 227 'save_callback' => function ( $field, $value ) { 228 return $this->update_cron_job( $value ); 229 }, 230 ), 231 232 array( 233 'label' => esc_html__( 'Spam Entry Threshold', 'gf-zero-spam' ), 234 'description' => esc_html__( 'A spam report email will be sent when the specified number of spam entries is reached.', 'gf-zero-spam' ), 235 'type' => 'text', 236 'input_type' => 'number', 237 'min' => 1, 238 'value' => 10, 239 'step' => 1, 240 'name' => 'gf_zero_spam_entry_limit', 241 'dependency' => array( 242 'live' => true, 243 'fields' => array( 244 array( 245 'field' => 'gf_zero_spam_email_frequency', 246 'values' => array( 'entry_limit' ), 247 ), 248 ), 249 ), 250 'validation_callback' => function ( $field, $value ) { 251 if ( (int) $value < 1 ) { 252 $field->set_error( esc_html__( 'Entry limit has to be 1 or more.', 'gf-zero-spam' ) ); 253 } 254 }, 255 ), 256 257 array( 258 'label' => esc_html__( 'Email Address', 'gf-zero-spam' ), 259 'description' => esc_html__( 'Send spam report to this email address.', 'gf-zero-spam' ), 260 'type' => 'text', 261 'input_type' => 'email', 262 'value' => '{{admin_email}}', 263 'name' => 'gf_zero_spam_report_email', 264 'required' => true, 265 'validation_callback' => function ( $field, $value ) { 266 if ( is_email( $value ) || '{{admin_email}}' === $value ) { 267 return; 268 } 269 $field->set_error( esc_html__( 'The email entered is invalid.', 'gf-zero-spam' ) ); 270 }, 271 'dependency' => array( 272 'live' => true, 273 'fields' => array( 274 array( 275 'field' => 'gf_zero_spam_email_frequency', 276 ), 277 ), 278 ), 279 ), 280 281 array( 282 'name' => 'gf_zero_spam_subject', 283 'label' => esc_html__( 'Email Subject', 'gf-zero-spam' ), 284 'type' => 'text', 285 'value' => esc_html__( 'Your Gravity Forms spam report for {{site_name}}', 'gf-zero-spam' ), 286 'required' => true, 287 'dependency' => array( 288 'live' => true, 289 'fields' => array( 290 array( 291 'field' => 'gf_zero_spam_email_frequency', 292 ), 293 ), 294 ), 295 ), 296 array( 297 'name' => 'gf_zero_spam_message', 298 'label' => esc_html__( 'Email Message', 'gf-zero-spam' ), 299 'description' => $available_variables_message, 300 'type' => 'textarea', 301 'value' => trim( $email_body ), 302 'use_editor' => true, 303 'required' => true, 304 'dependency' => array( 305 'live' => true, 306 'fields' => array( 307 array( 308 'field' => 'gf_zero_spam_email_frequency', 309 ), 310 ), 311 ), 312 ), 313 array( 314 'name' => 'gf_zero_spam_test_email', 315 'type' => 'hidden', 316 'value' => '', 317 'save_callback' => function ( $field, $value ) { 318 if ( empty( $value ) ) { 319 return; 320 } 321 322 $this->send_report( array(), true ); 323 }, 324 ), 325 array( 326 'name' => 'gf_zero_spam_test_email_button', 327 'type' => 'button', 328 'label' => esc_html__( 'Send Test Email & Save Settings', 'gf-zero-spam' ), 329 'value' => esc_html__( 'Send Email & Save Settings', 'gf-zero-spam' ), 330 'class' => 'button', 331 'onclick' => 'jQuery( "#gf_zero_spam_test_email" ).val( "1" ); jQuery( "#gform-settings-save" ).click();', 332 ), 333 ), 334 ), 335 ); 336 337 } 338 339 /** 340 * Check if entry limit has been reached after status update. 341 * 342 * @since 1.4 343 * 344 * @param int $entry_id The entry ID. 345 * @param string $property_value The new status. 346 * 347 * @return void 348 */ 349 public function update_status( $entry_id, $property_value ) { 350 351 if ( $property_value !== 'spam' ) { 352 return; 353 } 354 355 $this->check_entry_limit(); 356 } 357 358 /** 359 * Check if entry limit has been reached after submission. 360 * 361 * @since 1.4 362 * 363 * @param array $entry 364 * @param array $form 365 * 366 * @return void 367 */ 368 public function after_submission( $entry ) { 369 370 if ( $entry['status'] !== 'spam' ) { 371 return; 372 } 373 374 $this->check_entry_limit(); 375 } 376 377 /** 378 * Check if entry limit has been reached. 379 * 380 * @return bool 381 */ 382 public function check_entry_limit( $send_report = true ) { 383 $frequency = $this->get_plugin_setting( 'gf_zero_spam_email_frequency' ); 384 385 if ( $frequency !== 'entry_limit' ) { 386 return false; 387 } 388 389 $results = $this->get_latest_spam_entries(); 390 $limit = $this->get_plugin_setting( 'gf_zero_spam_entry_limit' ); 391 392 if ( $limit && count( $results ) < (int) $limit ) { 393 return false; 394 } 395 396 if ( $send_report ) { 397 $this->send_report( $results ); 398 } 399 400 return true; 401 } 402 403 /** 404 * Add monthly intervals to existing cron schedules. 405 * 406 * @param array $schedules 407 * 408 * @return array 409 */ 410 public function add_cron_schedules( $schedules ) { 411 412 if ( isset( $schedules['monthly'] ) ) { 413 return $schedules; 414 } 415 416 $schedules['monthly'] = array( 417 'interval' => MONTH_IN_SECONDS, 418 'display' => __( 'Once Monthly', 'gf-zero-spam' ), 419 ); 420 421 return $schedules; 422 } 423 424 /** 425 * Send spam report. 426 * 427 * @return boolean 428 */ 429 public function send_report( $results = array(), $is_test = false ) { 430 431 // When called from cron, $results will be empty. 432 if ( empty( $results ) ) { 433 $results = $this->get_latest_spam_entries(); 434 } 435 436 if ( empty( $results ) && ! $is_test ) { 437 return false; 438 } 439 440 if ( $is_test ) { 441 $settings = $this->get_posted_settings(); 442 } else { 443 $settings = $this->get_plugin_settings(); 444 } 445 446 $email = rgar( $settings, 'gf_zero_spam_report_email' ); 447 448 if ( empty( $email ) ) { 449 return false; 450 } 451 452 $email = $this->replace_tags( $email ); 453 454 if ( ! is_email( $email ) ) { 455 return false; 456 } 457 458 $subject = rgar( $settings, 'gf_zero_spam_subject' ); 459 $message = rgar( $settings, 'gf_zero_spam_message' ); 460 461 if ( $subject === '' || $message === '' ) { 462 return false; 463 } 464 465 $subject = $this->replace_tags( $subject ); 466 $message = $this->replace_tags( $message ); 467 $message = wpautop( $message ); 468 469 $headers = array( 'Content-type' => 'Content-type: text/html; charset=' . esc_attr( get_option( 'blog_charset' ) ) ); 470 $success = wp_mail( $email, $subject, $message, $headers ); 471 472 // Don't log or update last sent date when sending test email. 473 if ( $is_test ) { 474 return $success; 475 } 476 477 if ( $success ) { 478 $this->log_debug( __METHOD__ . '(): Spam report email sent successfully.' ); 479 update_option( self::REPORT_LAST_SENT_DATE_OPTION, current_time( 'timestamp' ) ); 480 } else { 481 $this->log_error( __METHOD__ . '(): Spam report email failed to send.' ); 482 } 483 484 return false; 485 } 486 487 /** 488 * Replace tags in email template. 489 * 490 * @param string $value 491 * 492 * @return string 493 */ 494 private function replace_tags( $value = '' ) { 495 $replace = array( 496 '{{site_name}}' => get_bloginfo( 'name' ), 497 '{{admin_email}}' => get_bloginfo( 'admin_email' ), 498 '{{total_spam_count}}' => (string) $this->get_spam_count(), 499 '{{spam_report_list}}' => $this->get_report_list(), 500 '{{settings_link}}' => '<a href="' . esc_url( admin_url( 'admin.php?page=gf_settings&subview=gf-zero-spam' ) ) . '">', 501 '{{/settings_link}}' => '</a>', 502 ); 503 504 return strtr( $value, $replace ); 505 } 506 507 /** 508 * Get latest spam entries. 509 * 510 * @return array 511 */ 512 private function get_latest_spam_entries() { 513 global $wpdb; 514 515 $sql = $wpdb->prepare( "SELECT `id`, `form_id` FROM {$wpdb->prefix}gf_entry WHERE `status`=%s AND `date_created` >= %s ORDER BY `form_id`", 'spam', $this->get_last_report_date( 'Y-m-d H:i:s' ) ); 516 517 return $wpdb->get_results( $sql, ARRAY_A ); 518 } 519 520 /** 521 * Returns the date the last report was set. 522 * 523 * @param string $date_format Date format to return. 524 * 525 * @return string Date in format passed by $date_format. 526 */ 527 private function get_last_report_date( $date_format = 'Y-m-d' ) { 528 529 $last_report_timestamp = get_option( self::REPORT_LAST_SENT_DATE_OPTION, current_time( 'timestamp' ) ); 530 531 return date( $date_format, $last_report_timestamp ); 532 } 533 534 /** 535 * Get report list. 536 * 537 * @return string HTML list of spam entries. 538 */ 539 private function get_report_list() { 540 541 $results = $this->get_latest_spam_entries(); 542 543 if ( empty( $results ) ) { 544 return ''; 545 } 546 547 $counted_results = array(); 548 foreach ( $results as $result ) { 549 if ( isset( $counted_results[ $result['form_id'] ] ) ) { 550 $counted_results[ $result['form_id'] ] ++; 551 } else { 552 $counted_results[ $result['form_id'] ] = 1; 553 } 554 } 555 556 $last_date = $this->get_last_report_date( 'Y-m-d' ); 557 558 $results_output = array(); 559 foreach ( $counted_results as $form_id => $count ) { 560 561 $form_info = GFFormsModel::get_form( $form_id ); 562 563 // Don't include forms that are in the trash. 564 if ( ! $form_info ) { 565 continue; 566 } 567 568 $args = array( 569 'id' => $form_id, 570 'filter' => 'spam', 571 ); 572 573 // If last report date is set, the link will go to spam entries submitted after that date. 574 if ( $last_date ) { 575 $args['s'] = $last_date; 576 $args['field_id'] = 'date_created'; 577 $args['orderby'] = '0'; 578 $args['order'] = 'ASC'; 579 $args['operator'] = '>'; 580 } 581 582 $link = add_query_arg( 583 $args, 584 admin_url( 'admin.php?page=gf_entries&view=entries' ) 585 ); 586 587 $count = (int) $count; 588 589 $results_output[] = strtr( '{{form_link}}: {{count}} {{new_entries}}', array( 590 '{{form_link}}' => '<a href="' . esc_url( $link ) . '">' . esc_html( $form_info->title ) . '</a>', 591 '{{count}}' => $count, 592 '{{new_entries}}' => _n( 'spam entry', 'spam entries', $count, 'gf-zero-spam' ), 593 ) ); 594 } 595 596 $output = '<ul><li>' . implode( '</li><li>', $results_output ) . '</li></ul>'; 597 598 return $output; 599 } 600 601 /** 602 * Get spam count. 603 * 604 * @return int $count The number of spam entries since the last report was sent. 605 */ 606 private function get_spam_count() { 607 $results = $this->get_latest_spam_entries(); 608 609 return count( $results ); 610 } 611 612 /** 613 * Add cron job for spam reporting. 614 * 615 * @param string $frequency 616 * 617 * @return string 618 */ 619 public function update_cron_job( $frequency ) { 620 621 // Always remove the existing cron job. 622 wp_clear_scheduled_hook( self::REPORT_CRON_HOOK_NAME ); 623 624 if ( empty( $frequency ) ) { 625 return $frequency; 626 } 627 628 if ( $frequency === 'entry_limit' ) { 629 return $frequency; 630 } 631 632 wp_schedule_event( time(), $frequency, self::REPORT_CRON_HOOK_NAME ); 633 634 return $frequency; 96 635 } 97 636 98 637 } 99 638 100 new GF_Zero_Spam_AddOn ();639 new GF_Zero_Spam_AddOn; -
gravity-forms-zero-spam/trunk/gravityforms-zero-spam.php
r2867494 r2903553 43 43 public static function deactivate() { 44 44 delete_option( 'gf_zero_spam_key' ); 45 46 if ( class_exists( 'GF_Zero_Spam_AddOn' ) ) { 47 wp_clear_scheduled_hook( GF_Zero_Spam_AddOn::REPORT_CRON_HOOK_NAME ); 48 } 45 49 } 46 50 … … 77 81 */ 78 82 public function add_key_field( $form ) { 83 84 /** 85 * Allows the zero spam key field to be disabled by returning false. 86 * @since 1.4 87 * @param bool $add_key_field Whether to add the key field to the form. Default true. 88 */ 89 $add_key_field = apply_filters( 'gf_zero_spam_add_key_field', true ); 90 91 if ( ! $add_key_field ) { 92 return; 93 } 79 94 80 95 $spam_key = esc_js( $this->get_key() ); -
gravity-forms-zero-spam/trunk/readme.txt
r2867494 r2903553 14 14 == Description == 15 15 16 This Gravity Forms add-on blocks spam using a non-obtrusive anti-spam measure. There are no settings or configuration needed: all you need to do is activate the plugin! 16 This Gravity Forms add-on blocks spam using a non-obtrusive anti-spam measure and can email a spam report summary. 17 18 19 ## Spam blocking 20 21 To get started, all you need to do is activate the plugin! 17 22 18 23 ### Is the Gravity Forms honeypot field not working for you? 🍯 🐝 … … 27 32 28 33 If you only want the plugin for specific forms, that's possible! The plugin adds a simple "Prevent spam using Gravity Forms Zero Spam" setting to each form (requires Gravity Forms 2.5 or newer). 34 35 ## Spam report emails 36 37 Spam summary report emails are disabled by default. Once enabled, a spam summary that includes the number of entries per-form will be sent via email. 38 39 Choose whether you want to be notified after the number of entries reaches a threshold (e.g. 10 spam entries) or after a certain number of days (e.g. every week). If there are no spam entries, no report will be sent. 40 41 ------- 29 42 30 43 Requires [Gravity Forms](https://www.gravityforms.com/?partner_id=1210629&irgwc=1&utm_medium=affiliate&utm_campaign=1210629&utm_source=Katz%20Web%20Services%2C%20Inc.). … … 76 89 New form submissions will not be checked using Zero Spam. 77 90 78 = I only want on sepecific forms. How do I disable Zero Spam by default? = 79 80 To disable by default, add this code to your site ([here's how](https://docs.gravitykit.com/article/210-where-to-put-code-samples)): 81 82 `add_filter( 'gf_zero_spam_check_key_field', '__return_false' );` 83 84 Once you have added that code to your site: 91 = I only want on specific forms. How do I disable Zero Spam by default? = 92 93 To disable by default, from your Dashboard, go to Forms, then Settings, then the Zero Spam tab. Under the "Enable Zero Spam by Default" setting, choose "Disabled", then save the form. 94 95 Once you have saved the setting, to enable for specific forms: 85 96 86 97 1. Go to the form … … 99 110 First, **de-activate and re-activate the plugin**. Then let us know on the support tab! 100 111 112 = Spam summary report emails = 113 114 You can enable a spam summary report email. This email will be sent to the email address configured in the "Spam Summary Email" setting on the Gravity Forms "Forms" menu, click Settings, then click the Zero Spam tab. 101 115 102 116 == Changelog == 117 118 = 1.4 on April 24, 2023 = 119 120 * Added: **Spam summary email reports** are now available! Receive a helpful email summarizing spam messages received. To enable, from your Dashboard, go to Forms, then Settings, then Zero Spam to enable and configure this feature. 121 - Choose when to send the report (threshold-based or frequency-based) 122 - Customize the report message 123 - Works with any spam messages, not just those blocked by Zero Spam 124 * Added: A setting to globally enable or disable Zero Spam by default (default: Enabled) 103 125 104 126 = 1.3 on February 18, 2023 =
Note: See TracChangeset
for help on using the changeset viewer.