pre-process.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php if ( ! defined( 'ABSPATH' ) ) exit;
  2. function ninja_forms_setup_processing_class( $form_id = '' ){
  3. global $ninja_forms_processing;
  4. $session_reflection = new ReflectionMethod( 'WP_Session', 'set_cookie' );
  5. if( $session_reflection->isPublic() ){
  6. // Manually set the cookie.
  7. Ninja_Forms()->session->init()->set_cookie();
  8. }
  9. $cache = Ninja_Forms()->session->get( 'nf_cache' );
  10. //Set the form id
  11. if ( $form_id == '' ) {
  12. if ( isset ( $_REQUEST['_form_id'] ) ) {
  13. $form_id = absint( $_REQUEST['_form_id'] );
  14. } else if ( $cache ) {
  15. $form_id = $cache['form_id'];
  16. }
  17. }
  18. //Initiate our processing class with our designated global variable.
  19. $ninja_forms_processing = new Ninja_Forms_Processing($form_id);
  20. $ninja_forms_processing->setup_submitted_vars();
  21. }
  22. function ninja_forms_pre_process(){
  23. global $ninja_forms_processing;
  24. $ajax = $ninja_forms_processing->get_form_setting('ajax');
  25. $form_id = $ninja_forms_processing->get_form_ID();
  26. do_action('ninja_forms_before_pre_process');
  27. if(!$ninja_forms_processing->get_all_errors()){
  28. do_action('ninja_forms_pre_process');
  29. }
  30. if(!$ninja_forms_processing->get_all_errors()){
  31. ninja_forms_process();
  32. }else{
  33. if($ajax == 1){
  34. $json = ninja_forms_json_response();
  35. //header('Content-Type', 'application/json');
  36. echo $json;
  37. die();
  38. }else{
  39. //echo 'pre-processing';
  40. //print_r($ninja_forms_processing->get_all_errors());
  41. }
  42. }
  43. }