/deprecated/includes/fields/spam.php

  1. <?php if ( ! defined( 'ABSPATH' ) ) exit; 
  2. function ninja_forms_register_field_spam() { 
  3. $args = array( 
  4. 'name' => __( 'Anti-Spam', 'ninja-forms' ),  
  5. 'edit_function' => '',  
  6. 'display_function' => 'ninja_forms_field_spam_display',  
  7. 'group' => 'standard_fields',  
  8. 'edit_label' => false,  
  9. 'edit_label_pos' => true,  
  10. 'edit_req' => false,  
  11. 'edit_custom_class' => true,  
  12. 'edit_help' => true,  
  13. 'edit_meta' => false,  
  14. 'sidebar' => 'template_fields',  
  15. 'display_label' => true,  
  16. 'edit_conditional' => true,  
  17. 'conditional' => array( 
  18. 'value' => array( 
  19. 'type' => 'text',  
  20. ),  
  21. ),  
  22. 'pre_process' => 'ninja_forms_field_spam_pre_process',  
  23. 'process_field' => false,  
  24. 'limit' => 1,  
  25. 'edit_options' => array( 
  26. array( 
  27. 'name' => 'label',  
  28. 'type' => 'text',  
  29. 'label' => __( 'Spam Question', 'ninja-forms' ),  
  30. 'width' => 'wide',  
  31. 'class' => 'widefat',  
  32. ),  
  33. array( 
  34. 'name' => 'spam_answer',  
  35. 'type' => 'text',  
  36. 'label' => __( 'Spam Answer', 'ninja-forms' ),  
  37. 'width' => 'wide',  
  38. 'class' => 'widefat',  
  39. ),  
  40. ),  
  41. 'req' => true,  
  42. ); 
  43.  
  44. ninja_forms_register_field('_spam', $args); 
  45.  
  46. add_action('init', 'ninja_forms_register_field_spam'); 
  47.  
  48. function ninja_forms_field_spam_edit( $field_id, $data ) { 
  49. if(isset($data['label'])) { 
  50. $question = $data['label']; 
  51. }else{ 
  52. $question = ''; 
  53.  
  54. if(isset($data['answer'])) { 
  55. $answer = $data['answer']; 
  56. }else{ 
  57. $answer = ''; 
  58. ?> 
  59. <input type="hidden" name="ninja_forms_field_<?php echo $field_id;?>[req]" value="1"> 
  60. <p class="description description-wide"> 
  61. <label for=""> 
  62. <?php _e( 'Spam Question' , 'ninja-forms'); ?><br /> 
  63. <input type="text" class="widefat code ninja-forms-field-label" name="ninja_forms_field_<?php echo $field_id;?>[label]" id="ninja_forms_field_<?php echo $field_id;?>_label" value="<?php echo stripslashes( $question );?>"> 
  64. </label> 
  65. </p> 
  66. <p class="description description-wide"> 
  67. <label for=""> 
  68. <?php _e( 'Spam Answer', 'ninja-forms'); ?><br /> 
  69. <input type="text" class="widefat" name="ninja_forms_field_<?php echo $field_id;?>[answer]" id="" value="<?php echo $answer;?>"> 
  70. </label> 
  71. </p> 
  72. <?php 
  73.  
  74. function ninja_forms_field_spam_display( $field_id, $data, $form_id = '' ) { 
  75. if(isset($data['default_value'])) { 
  76. $default_value = $data['default_value']; 
  77. }else{ 
  78. $default_value = ''; 
  79.  
  80. if(isset($data['show_field'])) { 
  81. $show_field = $data['show_field']; 
  82. }else{ 
  83. $show_field = true; 
  84.  
  85. $field_class = ninja_forms_get_field_class( $field_id, $form_id ); 
  86. if(isset($data['label_pos'])) { 
  87. $label_pos = $data['label_pos']; 
  88. }else{ 
  89. $label_pos = "left"; 
  90.  
  91. if(isset($data['label'])) { 
  92. $label = $data['label']; 
  93. }else{ 
  94. $label = ''; 
  95.  
  96. if($label_pos == 'inside') { 
  97. $default_value = $label; 
  98.  
  99. ?> 
  100. <input id="ninja_forms_field_<?php echo $field_id;?>" name="ninja_forms_field_<?php echo $field_id;?>" type="text" class="<?php echo $field_class;?>" value="<?php echo $default_value;?>" rel="<?php echo $field_id;?>" /> 
  101. <?php 
  102.  
  103.  
  104. function ninja_forms_field_spam_pre_process( $field_id, $user_value ) { 
  105. global $ninja_forms_processing; 
  106.  
  107. $plugin_settings = nf_get_settings(); 
  108. if(isset($plugin_settings['spam_error'])) { 
  109. $spam_error = __( $plugin_settings['spam_error'], 'ninja-forms' ); 
  110. $field_row = ninja_forms_get_field_by_id($field_id); 
  111. $field_data = $field_row['data']; 
  112. $spam_answer = $field_data['spam_answer']; 
  113.  
  114. $form_row = ninja_forms_get_form_by_field_id($field_id); 
  115. $form_id = $form_row['id']; 
  116.  
  117. if( $ninja_forms_processing->get_action() != 'save' AND $ninja_forms_processing->get_action() != 'mp_save' AND !isset($_POST['_wp_login']) AND $user_value != $spam_answer) { 
  118. if( is_object( $ninja_forms_processing)) { 
  119. if( $user_value != '' ) { 
  120. $ninja_forms_processing->add_error('spam-general', $spam_error, 'general'); 
  121. $ninja_forms_processing->add_error('spam-'.$field_id, $spam_error, $field_id);  
.