@@ -273,7 +273,7 @@ public function cf7a_options_init() {
273
273
/* Settings check_bad_ip */
274
274
add_settings_field (
275
275
'check_bad_ip ' ,
276
- __ ( 'IP Address ' , 'cf7-antispam ' ),
276
+ __ ( 'Check Bad IP Address ' , 'cf7-antispam ' ),
277
277
array ( $ this , 'cf7a_check_bad_ip_callback ' ),
278
278
'cf7a-settings ' ,
279
279
'cf7a_bad_ip '
@@ -920,6 +920,43 @@ public function cf7a_enable_geo( $enabled ) {
920
920
}
921
921
}
922
922
923
+ /**
924
+ * Handles WP-cron task registrations
925
+ *
926
+ * @param array $input - The post input values.
927
+ * @param string $input_name - The value of the input field.
928
+ * @param string $cron_task - The slug of the Post value.
929
+ * @param array $schedule - The schedules list obtained with wp_get_schedules().
930
+ *
931
+ * @return array|false the new value that the user has selected
932
+ */
933
+ private function cf7a_input_cron_schedule ( $ input , $ input_name , $ cron_task , $ schedule ) {
934
+ $ new_value = false ;
935
+
936
+ if ( ! empty ( $ input [$ input_name ] ) && in_array ( $ input [$ input_name ], array_keys ( $ schedule ), true ) ) {
937
+ if ( $ this ->options [$ input_name ] !== $ input [$ input_name ] ) {
938
+ $ new_value = $ input [$ input_name ];
939
+ /* delete previous scheduled events */
940
+ $ timestamp = wp_next_scheduled ( $ cron_task );
941
+ if ( $ timestamp ) {
942
+ wp_clear_scheduled_hook ( $ cron_task );
943
+ }
944
+
945
+ /* add the new scheduled event */
946
+ wp_schedule_event ( time () + $ schedule [ $ new_value ]['interval ' ], $ new_value , $ cron_task );
947
+ }
948
+ } else {
949
+ /* Get the timestamp for the next event. */
950
+ $ timestamp = wp_next_scheduled ( $ cron_task );
951
+ if ( $ timestamp ) {
952
+ wp_clear_scheduled_hook ( $ cron_task );
953
+ }
954
+ $ new_value [$ input_name ] = 'disabled ' ;
955
+ }
956
+ return $ new_value ;
957
+ }
958
+
959
+
923
960
/**
924
961
* Sanitize each setting field as needed
925
962
*
@@ -975,26 +1012,9 @@ public function cf7a_sanitize_options( $input ) {
975
1012
976
1013
/* auto-unban delay */
977
1014
$ schedule = wp_get_schedules ();
978
- if ( ! empty ( $ input ['unban_after ' ] ) && in_array ( $ input ['unban_after ' ], array_keys ( $ schedule ), true ) ) {
979
- if ( $ this ->options ['unban_after ' ] !== $ input ['unban_after ' ] ) {
980
- $ new_input ['unban_after ' ] = $ input ['unban_after ' ];
981
- /* delete previous scheduled events */
982
- $ timestamp = wp_next_scheduled ( 'cf7a_cron ' );
983
- if ( $ timestamp ) {
984
- wp_clear_scheduled_hook ( 'cf7a_cron ' );
985
- }
986
1015
987
- /* add the new scheduled event */
988
- wp_schedule_event ( time () + $ schedule [ $ new_input ['unban_after ' ] ]['interval ' ], $ new_input ['unban_after ' ], 'cf7a_cron ' );
989
- }
990
- } else {
991
- /* Get the timestamp for the next event. */
992
- $ timestamp = wp_next_scheduled ( 'cf7a_cron ' );
993
- if ( $ timestamp ) {
994
- wp_clear_scheduled_hook ( 'cf7a_cron ' );
995
- }
996
- $ new_input ['unban_after ' ] = 'disabled ' ;
997
- }
1016
+ /* unban after */
1017
+ $ new_input ['unban_after ' ] = $ this ->cf7a_input_cron_schedule ( $ input , 'unban_after ' , 'cf7a_cron ' , $ schedule );
998
1018
999
1019
/* bad ip */
1000
1020
$ new_input ['check_refer ' ] = isset ( $ input ['check_refer ' ] ) ? 1 : 0 ;
0 commit comments