@@ -314,7 +314,7 @@ function secupress_fightspam_blacklist_as_spam_check( $approved, $commentdata )
314
314
}
315
315
316
316
// Test.
317
- if ( wp_blacklist_check (
317
+ if ( wp_check_comment_disallowed_list (
318
318
$ commentdata ['comment_author ' ],
319
319
$ commentdata ['comment_author_email ' ],
320
320
$ commentdata ['comment_author_url ' ],
@@ -758,3 +758,148 @@ function secupress_fightspam_get_spam_status( $value ) {
758
758
759
759
return $ status ;
760
760
}
761
+
762
+ add_action ( 'wp_footer ' , 'secupress_fightspam_dont_comment_too_soon_timer ' );
763
+ /**
764
+ * Add a timer to change and disabled the submit button on the comment form
765
+ *
766
+ * @author Julio Potier
767
+ * @since 2.3
768
+ **/
769
+ function secupress_fightspam_dont_comment_too_soon_timer () {
770
+ // Do not do it if the setting is not set
771
+ if ( ! secupress_get_module_option ( 'antispam_comment-delay ' , 1 , 'antispam ' ) ) {
772
+ return ;
773
+ }
774
+ // Only do this if we are on a post type page which supports comments with a non logged in user
775
+ if ( is_user_logged_in () || ! get_post_type () || ! post_type_supports ( get_post_type (), 'comments ' ) ) {
776
+ return ;
777
+ }
778
+ // Set our timer in PHP with a filter
779
+ /**
780
+ * Filter the default timer, 30 by default
781
+ */
782
+ $ secupress_dcts_timer = (int ) apply_filters ( 'secupress.plugins.fightspam.comment_timer ' , 30 );
783
+ // Just check if it's correct (>0)
784
+ if ( $ secupress_dcts_timer <= 0 ) {
785
+ return ;
786
+ }
787
+ // Get the 2 filtered IDs for the form
788
+ $ comment_form_defaults = [ 'id_form ' => 'commentform ' , 'id_submit ' => 'submit ' ];
789
+ $ comment_form_defaults = wp_parse_args ( $ comment_form_defaults , apply_filters ( 'comment_form_defaults ' , $ comment_form_defaults ) );
790
+ ?>
791
+ <script>
792
+ //<![CDATA[
793
+ // Get the submit from the WP comment form
794
+ var secupress_dcts_submit = document.getElementById('<?php echo esc_js ( $ comment_form_defaults ['id_form ' ] ); ?> ').querySelectorAll('#<?php echo esc_js ( $ comment_form_defaults ['id_submit ' ] ); ?> ');
795
+ // If there is not, bail.
796
+ if ( secupress_dcts_submit.length ) {
797
+ // Get the button label
798
+ var secupress_dcts_submit_value = secupress_dcts_submit[0].value;
799
+ // Set our timer in JS from our filter
800
+ var secupress_dcts_timer = <?php echo esc_js ( $ secupress_dcts_timer ); ?> ;
801
+ // Disable the button and make it alpha 50%
802
+ secupress_dcts_submit[0].setAttribute("disabled", "");
803
+ secupress_dcts_submit[0].style.opacity = 0.5;
804
+ // Change the label to include the timer at max value
805
+ secupress_dcts_submit[0].value = secupress_dcts_submit[0].value + ' (' + secupress_dcts_timer + ')';
806
+ // Every second, reduce the timer by 1 and print it in the button
807
+ secupress_dcts_submit_interval = setInterval(
808
+ function() {
809
+ secupress_dcts_timer--;
810
+ secupress_dcts_submit[0].value = secupress_dcts_submit_value + ' (' + secupress_dcts_timer + ')';
811
+ },
812
+ 1000 );
813
+ // When the timer is done, rset the label, alpha, disabled status of the button
814
+ setTimeout(
815
+ function() {
816
+ clearInterval( secupress_dcts_submit_interval );
817
+ secupress_dcts_submit[0].value = secupress_dcts_submit_value;
818
+ secupress_dcts_submit[0].removeAttribute("disabled");
819
+ secupress_dcts_submit[0].style.opacity = 1;
820
+ },
821
+ secupress_dcts_timer * 1000 );
822
+
823
+ var xmlhttp = new XMLHttpRequest();
824
+ // Do the AJAX request, vanilla style
825
+ xmlhttp.onreadystatechange = function() {
826
+ if (xmlhttp.readyState == XMLHttpRequest.DONE) { // XMLHttpRequest.DONE == 4
827
+ if (xmlhttp.status == 200) {
828
+ document.getElementById("secupress_dcts_timer").value = xmlhttp.responseText;
829
+ }
830
+ }
831
+ };
832
+
833
+ xmlhttp.open("GET", "<?php echo esc_js ( esc_url ( admin_url ( 'admin-ajax.php?action=secupress_dcts_timer ' ) ) ); ?> ", true);
834
+ xmlhttp.send();
835
+ }
836
+ //]]>
837
+ </script>
838
+ <?php
839
+ }
840
+
841
+ add_action ( 'comment_form_top ' , 'secupress_fightspam_dont_comment_too_soon_field ' );
842
+ /**
843
+ * Add our field at the top of the form
844
+ *
845
+ * @since 2.3
846
+ * @author Julio Potier
847
+ **/
848
+ function secupress_fightspam_dont_comment_too_soon_field () {
849
+ // Do not do it if the setting is not set
850
+ if ( ! secupress_get_module_option ( 'antispam_comment-delay ' , 1 , 'antispam ' ) ) {
851
+ return ;
852
+ }
853
+ // Trust the logged in users.
854
+ if ( is_user_logged_in () ) {
855
+ return ;
856
+ }
857
+ // Our timer field
858
+ echo '<input type="hidden" name="secupress_dcts_timer" id="secupress_dcts_timer" value=" ' . time () . '" /> ' ;
859
+ }
860
+
861
+ add_action ( 'pre_comment_on_post ' , 'secupress_fightspam_dont_comment_too_soon_check ' , 9 );
862
+ /**
863
+ * Early block the comment if the timer is too short
864
+ *
865
+ * @author Julio Potier
866
+ * @return void
867
+ **/
868
+ function secupress_fightspam_dont_comment_too_soon_check () {
869
+ // Do not do it if the setting is not set
870
+ if ( ! secupress_get_module_option ( 'antispam_comment-delay ' , 1 , 'antispam ' ) ) {
871
+ return ;
872
+ }
873
+ // Trust the logged in users.
874
+ if ( is_user_logged_in () ) {
875
+ return ;
876
+ }
877
+ /**
878
+ * Filter the deffault timer, 30 by default
879
+ */
880
+ $ secupress_dcts_timer = (int ) apply_filters ( 'secupress.plugins.fightspam.comment_timer ' , 30 );
881
+ // Bad timer? Bail!
882
+ if ( $ secupress_dcts_timer <= 0 ) {
883
+ return ;
884
+ }
885
+ // Timer is too short, block!
886
+ if ( ! isset ( $ _POST ['secupress_dcts_timer ' ] ) || ( time () - $ _POST ['secupress_dcts_timer ' ] ) < ( $ secupress_dcts_timer + 1 ) ) { // +1sec because of page load + AJAX call.
887
+ secupress_block ( 'ATS ' , __ ( 'Sorry, you cannot send that now. ' , 'secupress ' ) );
888
+ }
889
+ }
890
+
891
+ add_action ( 'wp_ajax_nopriv_secupress_dcts_timer ' , 'secupress_dcts_timer_cb ' );
892
+ /**
893
+ * Get a timer with AJAX
894
+ *
895
+ * @author Julio Potier
896
+ * @since 2.3
897
+ **/
898
+ function secupress_dcts_timer_cb () {
899
+ // Do not do it if the setting is not set
900
+ if ( ! secupress_get_module_option ( 'antispam_comment-delay ' , 1 , 'antispam ' ) ) {
901
+ return ;
902
+ }
903
+ echo time ();
904
+ die ();
905
+ }
0 commit comments