/deprecated/includes/display/form/display-form.php

  1. <?php if ( ! defined( 'ABSPATH' ) ) exit; 
  2.  
  3. /** 
  4. * Function that checks to see if we are processing a submission 
  5. * 
  6. * @since 2.6.2 
  7. * @return void 
  8. */ 
  9.  
  10. function nf_check_post() { 
  11. if( isset ( $_POST['_ninja_forms_display_submit'] ) AND absint ( $_POST['_ninja_forms_display_submit'] ) == 1 ) { 
  12. /** 
  13. * Nonces don't really secure anything from non-logged in users. 
  14. * Using them for those users, however, can cause other issues. 
  15. * Because of this, we are removing the nonce check for now. 
  16. *  
  17. * In 3.0, we need to look at creating our own system. 
  18. */ 
  19. /** 
  20. // If our nonce isn't set, bail 
  21. if ( !isset ( $_POST['_wpnonce'] ) ) 
  22. return false; 
  23.   
  24. // If our nonce doesn't validate, bail 
  25. if ( ! wp_verify_nonce( $_POST['_wpnonce'], 'nf_form_' . absint( $_POST['_form_id'] ) ) ) 
  26. return false; 
  27. */ 
  28. $ajax = Ninja_Forms()->form( absint( $_POST['_form_id'] ) )->get_setting( 'ajax' ); 
  29.  
  30. if( $ajax != 1 ) { 
  31. add_action( 'init', 'ninja_forms_setup_processing_class', 5 ); 
  32. add_action( 'init', 'ninja_forms_pre_process', 999 ); 
  33. }else if( $ajax == 1 AND $_REQUEST['action'] == 'ninja_forms_ajax_submit' ) { 
  34. add_action( 'init', 'ninja_forms_setup_processing_class', 5 ); 
  35. add_action( 'init', 'ninja_forms_pre_process', 999 ); 
  36.  
  37. add_action( 'plugins_loaded', 'nf_check_post' ); 
  38.  
  39.  
  40. /** 
  41. * 
  42. * Function that checks to see if session variables have been set that indicate we are on a success page. 
  43. * If we are, intialize the global processing class for access to the form's settings and user values. 
  44. * 
  45. * @since 2.2.45 
  46. * @return void 
  47. */ 
  48.  
  49. function ninja_forms_session_class_setup() { 
  50. $cache = Ninja_Forms()->session->get( 'nf_cache' ); 
  51. if ( $cache && ! is_admin() ) { 
  52. add_action( 'init', 'ninja_forms_setup_processing_class', 5 ); 
  53.  
  54. add_action( 'init', 'ninja_forms_session_class_setup', 4 ); 
  55.  
  56. /** 
  57. * 
  58. * Function that clears any transient values that have been stored in cache for this user. 
  59. * 
  60. * @since 2.2.45 
  61. * @return void 
  62. */ 
  63.  
  64. function ninja_forms_clear_transient() { 
  65. ninja_forms_delete_transient(); 
  66.  
  67. add_action( 'wp_head', 'ninja_forms_clear_transient' ); 
  68.  
  69. function ninja_forms_page_append_check() { 
  70. global $post, $ninja_forms_append_page_form_id; 
  71.  
  72. if ( ! empty ( $_REQUEST['preview'] ) && ! empty ( $_REQUEST['preview'] ) ) { 
  73. if(is_array($ninja_forms_append_page_form_id)) { 
  74. unset($ninja_forms_append_page_form_id); 
  75.  
  76. if(!isset($ninja_forms_append_page_form_id)) { 
  77. $ninja_forms_append_page_form_id = array(); 
  78.  
  79. if ( $post ) { 
  80. $form_ids = ninja_forms_get_form_ids_by_post_id($post->ID); 
  81. if(is_array($form_ids) AND !empty($form_ids)) { 
  82. foreach($form_ids as $form_id) { 
  83. $ninja_forms_append_page_form_id[] = $form_id; 
  84. //remove_filter('the_content', 'wpautop'); 
  85. add_filter( 'the_content', 'ninja_forms_append_to_page', 9999 ); 
  86. }  
  87.  
  88. add_action('wp_head', 'ninja_forms_page_append_check'); 
  89.  
  90. function ninja_forms_append_to_page($content) { 
  91. global $ninja_forms_append_page_form_id; 
  92.  
  93. if( !is_admin() && is_main_query() && ( is_page() OR is_single() ) ) { 
  94. $form = ''; 
  95. if(is_array($ninja_forms_append_page_form_id) && !empty($ninja_forms_append_page_form_id)) { 
  96. foreach($ninja_forms_append_page_form_id as $form_id) { 
  97. $form .= ninja_forms_return_echo('ninja_forms_display_form', $form_id); 
  98. }else{ 
  99. $form = ninja_forms_return_echo('ninja_forms_display_form', $ninja_forms_append_page_form_id); 
  100. $content .= $form; 
  101. return $content; 
  102.  
  103. /** 
  104. * Main function used to display a Ninja Form. 
  105. * ninja_forms_display_form() can be called anywhere on in a WordPress template. 
  106. * By default it's called by the ninja_forms_append_to_page() function in the main ninja_forms.php file. 
  107. * 
  108. **/ 
  109.  
  110. function ninja_forms_display_form( $form_id = '' ) { 
  111. //Define our global variables 
  112. global $post, $wpdb, $ninja_forms_fields, $ninja_forms_loading, $ninja_forms_processing; 
  113.  
  114. //Get the settings telling us whether or not we should clear/hide the completed form. 
  115. //Check to see if the form_id has been sent. 
  116. if($form_id == '') { 
  117. $function = false; 
  118. if(isset($_REQUEST['form_id'])) { //If it hasn't, set it to our requested form_id. Sometimes this function can be called without an expressly passed form_id. 
  119. $form_id = absint( $_REQUEST['form_id'] ); 
  120. }else{ 
  121. $function = true; 
  122. if($form_id != '') { //Make sure that we have an active form_id. 
  123. do_action( 'nf_before_display_loading', $form_id ); 
  124.  
  125. // Instantiate our loading global singleton. 
  126. if ( !isset ( $ninja_forms_processing ) or ( isset ( $ninja_forms_processing ) and $ninja_forms_processing->get_form_ID() != $form_id ) ) { 
  127. $ninja_forms_loading = new Ninja_Forms_Loading( $form_id ); 
  128.  
  129. // Run our two loading action hooks. 
  130. do_action( 'ninja_forms_display_pre_init', $form_id ); 
  131. do_action( 'ninja_forms_display_init', $form_id ); 
  132.  
  133. if ( isset ( $ninja_forms_loading ) ) { 
  134. $ajax = $ninja_forms_loading->get_form_setting( 'ajax' ); 
  135. } else { 
  136. $ajax = $ninja_forms_processing->get_form_setting( 'ajax' ); 
  137.  
  138. if ( !$ajax ) { 
  139. $ajax = 0; 
  140.  
  141. if ( isset ( $ninja_forms_loading ) ) { 
  142. $logged_in = $ninja_forms_loading->get_form_setting( 'logged_in' ); 
  143. } else { 
  144. $logged_in = $ninja_forms_processing->get_form_setting( 'logged_in' ); 
  145.  
  146. if ( !$logged_in ) { 
  147. $logged_in = 0; 
  148.  
  149. $display = true; 
  150.  
  151. if( $logged_in == 1 ) { 
  152. if( !is_user_logged_in() ) { 
  153. $display = false; 
  154.  
  155. $display = apply_filters( 'ninja_forms_display_show_form', $display, $form_id ); 
  156.  
  157. if($ajax == 1) { 
  158. $url = admin_url( 'admin-ajax.php' ); 
  159. $url = esc_url_raw( add_query_arg('action', 'ninja_forms_ajax_submit', $url ) ); 
  160. }else{ 
  161. $url = ''; 
  162.  
  163. if( $display ) { 
  164. do_action( 'ninja_forms_before_form_display', $form_id ); 
  165.  
  166. do_action('ninja_forms_display_before_form_wrap', $form_id); 
  167. do_action('ninja_forms_display_open_form_wrap', $form_id); 
  168.  
  169. do_action('ninja_forms_display_before_form_title', $form_id); 
  170. do_action('ninja_forms_display_form_title', $form_id); 
  171. do_action('ninja_forms_display_after_form_title', $form_id); 
  172.  
  173. do_action('ninja_forms_display_before_form', $form_id); 
  174. do_action('ninja_forms_display_open_form_tag', $form_id); 
  175. do_action('ninja_forms_display_after_open_form_tag', $form_id); 
  176.  
  177. do_action('ninja_forms_display_before_fields', $form_id); 
  178. do_action('ninja_forms_display_fields', $form_id); 
  179. do_action('ninja_forms_display_after_fields', $form_id); 
  180.  
  181. do_action('ninja_forms_display_close_form_tag', $form_id); 
  182. do_action('ninja_forms_display_after_form', $form_id); 
  183.  
  184. do_action('ninja_forms_display_close_form_wrap', $form_id); 
  185. do_action('ninja_forms_display_after_form_wrap', $form_id); 
  186.  
  187. do_action( 'ninja_forms_after_form_display', $form_id ); 
  188.  
  189. do_action( 'ninja_forms_display_js', $form_id ); 
  190. do_action( 'ninja_forms_display_css', $form_id ); 
  191. }else{ 
  192. do_action( 'ninja_forms_display_user_not_logged_in', $form_id ); 
.