/deprecated/includes/deprecated.php

  1. <?php if ( ! defined( 'ABSPATH' ) ) exit; 
  2.  
  3. /** 
  4. * Deprecated as of version 2.7. 
  5. */ 
  6.  
  7. // Hook into our new save sub filter to add any deprecated filters 
  8. function nf_old_save_sub_filter( $user_value, $field_id ) { 
  9. return apply_filters( 'ninja_forms_save_sub', $user_value, $field_id ); 
  10.  
  11. add_filter( 'nf_save_sub_user_value', 'nf_old_save_sub_filter', 10, 2 ); 
  12.  
  13. // Hook into our new nf_save_sub action and add any actions hooked into our old action hooks. 
  14. function nf_old_save_sub_action( $sub_id ) { 
  15. do_action( 'ninja_forms_insert_sub', $sub_id ); 
  16.  
  17. add_action( 'nf_save_sub', 'nf_old_save_sub_action' ); 
  18.  
  19. // Hook into our new submissions CSV filename filter. 
  20. function nf_old_subs_csv_filename( $filename ) { 
  21. return apply_filters( 'ninja_forms_export_subs_csv_file_name', $filename ); 
  22.  
  23. add_filter( 'nf_subs_csv_filename', 'nf_old_subs_csv_filename' ); 
  24.  
  25. // Hook into our new submissions CSV label filter. 
  26. function nf_old_subs_csv_label( $label, $field_id ) { 
  27. return apply_filters( 'ninja_forms_export_sub_label', $label, $field_id ); 
  28.  
  29. add_filter( 'nf_subs_csv_field_label', 'nf_old_subs_csv_label', 10, 2 ); 
  30.  
  31. // Hook into our new submissions CSV label array filter. 
  32. function nf_old_subs_csv_label_array( $label_array, $sub_ids ) { 
  33. return apply_filters( 'ninja_forms_export_subs_label_array', $label_array, $sub_ids ); 
  34.  
  35. add_filter( 'nf_subs_csv_label_array', 'nf_old_subs_csv_label_array', 10, 2 ); 
  36.  
  37. // Hook into our new submissions CSV pre_value filter. 
  38. function nf_old_subs_csv_pre_value( $user_value, $field_id ) { 
  39. return apply_filters( 'ninja_forms_export_sub_pre_value', $user_value, $field_id ); 
  40.  
  41. add_filter( 'nf_subs_export_pre_value', 'nf_old_subs_csv_pre_value', 10, 2 ); 
  42.  
  43. // Hook into our new submissions CSV value filter. 
  44. function nf_old_subs_csv_value( $user_value, $field_id ) { 
  45. return apply_filters( 'ninja_forms_export_sub_value', $user_value, $field_id ); 
  46.  
  47. add_filter( 'nf_subs_csv_field_value', 'nf_old_subs_csv_value', 10, 2 ); 
  48.  
  49. // Hook into our new submissions CSV value array filter. 
  50. function nf_old_subs_csv_value_array( $values_array, $sub_ids ) { 
  51. return apply_filters( 'ninja_forms_export_subs_value_array', $values_array, $sub_ids ); 
  52.  
  53. add_filter( 'nf_subs_csv_value_array', 'nf_old_subs_csv_value_array', 10, 2 ); 
  54.  
  55. // Hook into our new CSV BOM filter 
  56. function nf_old_subs_csv_bom( $bom ) { 
  57. return apply_filters( 'ninja_forms_csv_bom', $bom ); 
  58.  
  59. add_filter( 'nf_sub_csv_bom', 'nf_old_subs_csv_bom' ); 
  60.  
  61. // Hook into our new CSV delimiter filter 
  62. function nf_old_subs_csv_delimiter( $delimiter ) { 
  63. return apply_filters( 'ninja_forms_csv_delimiter', $delimiter ); 
  64.  
  65. add_filter( 'nf_sub_csv_delimiter', 'nf_old_subs_csv_delimiter' ); 
  66.  
  67. // Hook into our new CSV enclosure filter 
  68. function nf_old_subs_csv_enclosure( $enclosure ) { 
  69. return apply_filters( 'ninja_forms_csv_enclosure', $enclosure ); 
  70.  
  71. add_filter( 'nf_sub_csv_enclosure', 'nf_old_subs_csv_enclosure' ); 
  72.  
  73. // Hook into our new CSV terminator filter 
  74. function nf_old_subs_csv_terminator( $terminator ) { 
  75. return apply_filters( 'ninja_forms_csv_terminator', $terminator ); 
  76.  
  77. add_filter( 'nf_sub_csv_terminator', 'nf_old_subs_csv_terminator' ); 
  78.  
  79. // Hook into our new Submissions table row-actions filter 
  80. function nf_old_subs_table_row_actions_filter( $actions, $sub_id, $form_id ) { 
  81. return apply_filters( 'ninja_forms_sub_table_row_actions', array(), false, $sub_id, $form_id ); 
  82.  
  83. add_filter( 'nf_sub_table_row_actions', 'nf_old_subs_table_row_actions_filter', 10, 3 ); 
  84.  
  85. /** 
  86. * ninja_forms_get_subs() has been deprecated in favour of Ninja_Forms()->subs()->get( $args ) or Ninja_Forms()->form( 23 )->get_subs( $args ) 
  87. * You can also use WordPress queries , since this is a custom post type. 
  88. *  
  89. * @since 2.7 
  90. */ 
  91.  
  92. function ninja_forms_get_subs( $args = array() ) { 
  93.  
  94. $plugin_settings = nf_get_settings(); 
  95.  
  96. if ( isset ( $plugin_settings['date_format'] ) ) { 
  97. $date_format = $plugin_settings['date_format']; 
  98. } else { 
  99. $date_format = 'm/d/Y'; 
  100.  
  101. if( is_array( $args ) AND ! empty( $args ) ) { 
  102.  
  103. $subs_results = array(); 
  104. $meta_query = array(); 
  105. $date_query = array(); 
  106.  
  107. if( isset( $args['form_id'] ) ) { 
  108. $meta_query[] = array( 
  109. 'key' => '_form_id',  
  110. 'value' => $args['form_id'],  
  111. ); 
  112.  
  113. if( isset( $args['action'])) { 
  114. $meta_query[] = array( 
  115. 'key' => '_action',  
  116. 'value' => $args['action'],  
  117. ); 
  118.  
  119. $query_args = array( 
  120. 'post_type' => 'nf_sub',  
  121. 'date_query' => $date_query,  
  122. 'meta_query' => $meta_query,  
  123. 'posts_per_page' => -1,  
  124. ); 
  125.  
  126. if( isset( $args['user_id'] ) ) { 
  127. $query_args['author'] = $args['user_id']; 
  128.  
  129.  
  130.  
  131. if( isset( $args['begin_date'] ) AND $args['begin_date'] != '') { 
  132. $query_args['date_query']['after'] = nf_get_begin_date( $args['begin_date'] )->format("Y-m-d G:i:s"); 
  133.  
  134. if( isset( $args['end_date'] ) AND $args['end_date'] != '' ) { 
  135. $query_args['date_query']['before'] = nf_get_end_date( $args['end_date'] )->format("Y-m-d G:i:s"); 
  136.  
  137. $subs = get_posts( $query_args ); 
  138.  
  139. if ( is_array( $subs ) && ! empty( $subs ) ) { 
  140. $x = 0; 
  141. foreach ( $subs as $sub ) { 
  142. $data = array(); 
  143. $subs_results[$x]['id'] = $sub->ID; 
  144. $subs_results[$x]['user_id'] = $sub->post_author; 
  145. $subs_results[$x]['form_id'] = get_post_meta( $sub->ID, '_form_id' ); 
  146. $subs_results[$x]['action'] = get_post_meta( $sub->ID, '_action' ); 
  147.  
  148. $meta = get_post_custom( $sub->ID ); 
  149.  
  150. foreach ( $meta as $key => $array ) { 
  151. if ( strpos( $key, '_field_' ) !== false ) { 
  152. $field_id = str_replace( '_field_', '', $key ); 
  153. $user_value = $array[0]; 
  154. $data[] = array( 'field_id' => $field_id, 'user_value' => $user_value ); 
  155.  
  156. $subs_results[$x]['data'] = $data; 
  157. $subs_results[$x]['date_updated'] = $sub->post_modified; 
  158.  
  159. $x++; 
  160.  
  161. return $subs_results; 
  162.  
  163. /** 
  164. * ninja_forms_get_sub_count() has been deprecated in favour of Ninja_Forms()->form( 23 )->sub_count or nf_get_sub_count() 
  165. * Function that returns a count of the number of submissions. 
  166. * 
  167. * @since 2.7 
  168. */ 
  169.  
  170. function ninja_forms_get_sub_count( $args = array() ) { 
  171. return count( ninja_forms_get_subs( $args ) ); 
  172.  
  173. /** 
  174. * ninja_forms_get_sub_by_id( $sub_id ) has been deprecated in favour of Ninja_Forms()->sub( 23 ); 
  175. *  
  176. * @since 2.7 
  177. */ 
  178.  
  179. function ninja_forms_get_sub_by_id( $sub_id ) { 
  180. $sub = Ninja_Forms()->sub( $sub_id ); 
  181. if ( $sub ) { 
  182. $sub_row = array(); 
  183. $data = array(); 
  184. $sub_row['id'] = $sub_id; 
  185. $sub_row['user_id'] = $sub->user_id; 
  186. $sub_row['form_id'] = $sub->form_id; 
  187. $sub_row['action'] = $sub->action; 
  188.  
  189. if ( $sub->action == 'submit' ) { 
  190. $sub_row['status'] = 1; 
  191. } else { 
  192. $sub_row['status'] = 0; 
  193.  
  194. $meta = get_post_custom( $sub_id ); 
  195.  
  196. foreach ( $meta as $key => $array ) { 
  197. if ( strpos( $key, '_field_' ) !== false ) { 
  198. $field_id = str_replace( '_field_', '', $key ); 
  199. $user_value = is_serialized( $array[0] ) ? unserialize( $array[0] ) : $array[0]; 
  200. $data[] = array( 'field_id' => $field_id, 'user_value' => $user_value ); 
  201.  
  202. $sub_row['data'] = $data; 
  203. $sub_row['date_updated'] = $sub->date_submitted; 
  204.  
  205. return $sub_row; 
  206. } else { 
  207. return false; 
  208.  
  209. /** 
  210. * ninja_forms_get_all_subs() has been deprecated in favour of Ninja_Forms()->subs()->get(); 
  211. *  
  212. * @since 2.7 
  213. */ 
  214.  
  215. function ninja_forms_get_all_subs( $form_id = '' ) { 
  216. if ( $form_id == '' ) 
  217. return false; 
  218.  
  219. $args = array( 'form_id' => $form_id ); 
  220. return ninja_forms_get_subs( $args ); 
  221.  
  222. /** 
  223. * ninja_forms_insert_sub() has been deprecated in favour of Ninja_Forms()->subs()->create( $form_id ); 
  224. * Because submissions are now a CPT, this function will only return false.  
  225. * Please replace any instances of this function with the replacement. 
  226. *  
  227. * @since 2.7 
  228. */ 
  229.  
  230. function ninja_forms_insert_sub( $args ) { 
  231.  
  232. if ( ! isset ( $args['form_id'] ) ) 
  233. return false; 
  234.  
  235. $form_id = $args['form_id']; 
  236.  
  237. $sub_id = Ninja_Forms()->subs()->create( $form_id ); 
  238. $args['sub_id'] = $sub_id; 
  239.  
  240. ninja_forms_update_sub( $args ); 
  241.  
  242. return $sub_id; 
  243.  
  244. /** 
  245. * ninja_forms_update_sub() has been deprecated in favour of Ninja_Forms()->sub( 23 )->update_field( id, value ); 
  246. * Because submissions are now a CPT, this function will only return false.  
  247. * Please replace any instances of this function with the replacement. 
  248. *  
  249. * @since 2.7 
  250. */ 
  251.  
  252. function ninja_forms_update_sub( $args ) { 
  253. if ( ! isset ( $args['sub_id'] ) ) 
  254. return false; 
  255.  
  256. $sub_id = $args['sub_id']; 
  257. $sub = Ninja_Forms()->sub( $sub_id ); 
  258.  
  259. if ( isset ( $args['data'] ) ) { 
  260. $data = $args['data']; 
  261. unset ( $args['data'] ); 
  262.  
  263. if ( is_serialized( $data ) ) { 
  264. $data = unserialize( $data ); 
  265.  
  266. foreach ( $data as $d ) { 
  267. $field_id = $d['field_id']; 
  268. $user_value = $d['user_value']; 
  269. $sub->add_field( $field_id, $user_value ); 
  270. }  
  271.  
  272. foreach ( $args as $key => $value ) { 
  273. $sub->update_meta( '_' . $key, $value ); 
  274.  
  275.  
  276. /** 
  277. * ninja_forms_export_subs_to_csv() has been deprecated in favour of Ninja_Forms()->subs()->export( sub_ids, return ); 
  278. * or Ninja_Forms()->sub( 23 )->export( return ); 
  279. * Please replace any instances of this function with the replacement. 
  280. *  
  281. * @since 2.7 
  282. */ 
  283.  
  284. function ninja_forms_export_subs_to_csv( $sub_ids = '', $return = false ) { 
  285. Ninja_Forms()->subs()->export( $sub_ids, $return ); 
  286.  
  287. function ninja_forms_implode_r($glue, $pieces) { 
  288. $out = ''; 
  289. foreach ( $pieces as $piece ) { 
  290. if ( is_array ( $piece ) ) { 
  291. if ( $out == '' ) { 
  292. $out = ninja_forms_implode_r($glue, $piece); 
  293. } else { 
  294. $out .= ninja_forms_implode_r($glue, $piece); // recurse 
  295. }  
  296. } else { 
  297. if ( $out == '' ) { 
  298. $out .= $piece; 
  299. } else { 
  300. $out .= $glue.$piece; 
  301. return $out; 
  302.  
  303.  
  304. /** 
  305. * Get the csv delimiter 
  306. *  
  307. * @return string 
  308. */ 
  309. function ninja_forms_get_csv_delimiter() { 
  310. return apply_filters( 'ninja_forms_csv_delimiter', ', ' ); 
  311.  
  312. /** 
  313. * Get the csv enclosure 
  314. *  
  315. * @return string 
  316. */ 
  317. function ninja_forms_get_csv_enclosure() { 
  318. return apply_filters( 'ninja_forms_csv_enclosure', '"' ); 
  319.  
  320. /** 
  321. * Get the csv delimiter 
  322. *  
  323. * @return string 
  324. */ 
  325. function ninja_forms_get_csv_terminator() { 
  326. return apply_filters( 'ninja_forms_csv_terminator', "\n" ); 
  327.  
  328. /** 
  329. * Wrapper for nf_save_sub() 
  330. */ 
  331. function ninja_forms_save_sub() { 
  332. nf_save_sub(); 
  333.  
  334. function nf_change_all_forms_filter( $cap ) { 
  335. return apply_filters( 'ninja_forms_admin_menu_capabilities', $cap ); 
  336.  
  337. add_filter( 'ninja_forms_admin_all_forms_capabilities', 'nf_change_all_forms_filter' ); 
  338.  
  339. function nf_change_admin_menu_filter( $cap ) { 
  340. return apply_filters( 'ninja_forms_admin_menu_capabilities', $cap ); 
  341.  
  342. add_filter( 'ninja_forms_admin_parent_menu_capabilities', 'nf_change_admin_menu_filter' ); 
  343.  
  344. /**  
  345. * Deprecated as of version 2.8  
  346. */ 
  347.  
  348. // The admin_mailto setting has been deprecated. Because users may have used this setting to modify who receives the admin email,  
  349. // we need to make sure that it is backwards compatible. 
  350. function nf_clear_admin_mailto() { 
  351. global $ninja_forms_processing; 
  352.  
  353. $ninja_forms_processing->update_form_setting( 'admin_mailto', array() ); 
  354.  
  355. add_action( 'ninja_forms_before_pre_process', 'nf_clear_admin_mailto' ); 
  356.  
  357. function nf_modify_admin_mailto( $setting, $setting_name, $id ) { 
  358. global $ninja_forms_processing; 
  359.  
  360. // Bail if this isn't our admin notification 
  361. if ( ! nf_get_object_meta_value( $id, 'admin_email' ) ) 
  362. return $setting; 
  363.  
  364. // Bail if this isn't the "to" setting. 
  365. if ( $setting_name != 'to' ) 
  366. return $setting; 
  367.  
  368. $admin_mailto = $ninja_forms_processing->get_form_setting( 'admin_mailto' ); 
  369. $ninja_forms_processing->update_form_setting( 'admin_mailto', '' ); 
  370.  
  371. if ( is_array( $admin_mailto ) && ! empty ( $admin_mailto ) ) { 
  372. $setting = array_merge( $setting, $admin_mailto ); 
  373.  
  374. return $setting; 
  375.  
  376. add_filter( 'nf_email_notification_process_setting', 'nf_modify_admin_mailto', 10, 3 ); 
  377.  
  378. add_action('init', 'ninja_forms_register_filter_email_add_fields', 15 ); 
  379. function ninja_forms_register_filter_email_add_fields() { 
  380. global $ninja_forms_processing; 
  381.  
  382. if( is_object( $ninja_forms_processing ) ) { 
  383. if( $ninja_forms_processing->get_form_setting( 'user_email_fields' ) == 1 ) { 
  384. add_filter( 'ninja_forms_user_email', 'ninja_forms_filter_email_add_fields' ); 
  385.  
  386. if( is_object( $ninja_forms_processing ) ) { 
  387. if( $ninja_forms_processing->get_form_setting( 'admin_email_fields' ) == 1 ) { 
  388. add_filter( 'ninja_forms_admin_email', 'ninja_forms_filter_email_add_fields' ); 
  389.  
  390. function ninja_forms_filter_email_add_fields( $message ) { 
  391. global $ninja_forms_processing, $ninja_forms_fields; 
  392.  
  393. $form_id = $ninja_forms_processing->get_form_ID(); 
  394. $all_fields = ninja_forms_get_fields_by_form_id( $form_id ); 
  395. //$all_fields = $ninja_forms_processing->get_all_fields(); 
  396. $tmp_array = array(); 
  397. if( is_array( $all_fields ) ) { 
  398. foreach( $all_fields as $field ) { 
  399. if( $ninja_forms_processing->get_field_value( $field['id'] ) ) { 
  400. $tmp_array[$field['id']] = $ninja_forms_processing->get_field_value( $field['id'] ); 
  401. $all_fields = apply_filters( 'ninja_forms_email_all_fields_array', $tmp_array, $form_id ); 
  402.  
  403. $email_type = $ninja_forms_processing->get_form_setting( 'email_type' ); 
  404. if(is_array($all_fields) AND !empty($all_fields)) { 
  405. if($email_type == 'html') { 
  406. $message .= "<br><br>"; 
  407. $message .= apply_filters( 'nf_email_user_values_title', __( 'User Submitted Values:', 'ninja-forms' ) ); 
  408. $message .= "<table>"; 
  409. }else{ 
  410. $message = str_replace("<p>", "\r\n", $message); 
  411. $message = str_replace("</p>", "", $message); 
  412. $message = str_replace("<br>", "\r\n", $message); 
  413. $message = str_replace("<br />", "\r\n", $message); 
  414. $message = strip_tags($message); 
  415. $message .= "\r\n \r\n"; 
  416. $message .= apply_filters( 'nf_email_user_values_title', __( 'User Submitted Values:', 'ninja-forms' ) ); 
  417. $message .= "\r\n"; 
  418. foreach( $all_fields as $field_id => $user_value ) { 
  419.  
  420. $field_row = $ninja_forms_processing->get_field_settings( $field_id ); 
  421. $field_label = $field_row['data']['label']; 
  422. $field_label = apply_filters( 'ninja_forms_email_field_label', $field_label, $field_id ); 
  423. $user_value = apply_filters( 'ninja_forms_email_user_value', $user_value, $field_id ); 
  424. $field_type = $field_row['type']; 
  425.  
  426. if( $ninja_forms_fields[$field_type]['process_field'] ) { 
  427. if( is_array( $user_value ) AND !empty( $user_value ) ) { 
  428. $x = 0; 
  429. foreach($user_value as $val) { 
  430. if(!is_array($val)) { 
  431. if($x > 0) { 
  432. $field_label = '----'; 
  433. $field_label = apply_filters( 'ninja_forms_email_field_label', $field_label, $field_id ); 
  434. if($email_type == 'html') { 
  435. $message .= "<tr><td width='50%'>".$field_label.":</td><td width='50%'>".$val."</td></tr>"; 
  436. }else{ 
  437. $message .= $field_label." - ".$val."\r\n"; 
  438. }else{ 
  439. foreach($val as $v) { 
  440. if(!is_array($v)) { 
  441. if($x > 0) { 
  442. $field_label = '----'; 
  443. $field_label = apply_filters( 'ninja_forms_email_field_label', $field_label, $field_id ); 
  444. if($email_type == 'html') { 
  445. $message .= "<tr><td width='50%'>".$field_label.":</td><td width='50%'>".$v."</td></tr>"; 
  446. }else{ 
  447. $message .= $field_label." - ".$v."\r\n"; 
  448. }else{ 
  449. foreach($v as $a) { 
  450. if($x > 0) { 
  451. $field_label = '----'; 
  452. $field_label = apply_filters( 'ninja_forms_email_field_label', $field_label, $field_id ); 
  453. if($email_type == 'html') { 
  454. $message .= "<tr><td width='50%'>".$field_label.":</td><td width='50%'>".$a."</td></tr>"; 
  455. }else{ 
  456. $message .= $field_label." - ".$a."\r\n"; 
  457. $x++; 
  458. }else{ 
  459. if($email_type == 'html') { 
  460. $message .= "<tr><td width='50%'>".$field_label.":</td><td width='50%'>".$user_value."</td></tr>"; 
  461. }else{ 
  462. $message .= $field_label." - ".$user_value."\r\n"; 
  463.  
  464. if($email_type == 'html') { 
  465. $message .= "</table>"; 
  466. $message = apply_filters( 'ninja_forms_email_field_list', $message, $form_id ); 
  467.  
  468. return $message; 
  469.  
  470. add_action( 'init', 'ninja_forms_register_email_admin' ); 
  471. function ninja_forms_register_email_admin() { 
  472. add_action( 'ninja_forms_post_process', 'ninja_forms_email_admin', 1000 ); 
  473.  
  474. function ninja_forms_email_admin() { 
  475. global $ninja_forms_processing; 
  476.  
  477. do_action( 'ninja_forms_email_admin' ); 
  478.  
  479. $form_ID = $ninja_forms_processing->get_form_ID(); 
  480. $form_title = $ninja_forms_processing->get_form_setting( 'form_title' ); 
  481. $admin_mailto = $ninja_forms_processing->get_form_setting( 'admin_mailto' ); 
  482. $email_from_name = $ninja_forms_processing->get_form_setting( 'email_from_name' ); 
  483. $email_from = $ninja_forms_processing->get_form_setting( 'email_from' ); 
  484. $email_type = $ninja_forms_processing->get_form_setting( 'email_type' ); 
  485. $subject = $ninja_forms_processing->get_form_setting( 'admin_subject' ); 
  486. $message = $ninja_forms_processing->get_form_setting( 'admin_email_msg' ); 
  487. $email_reply = $ninja_forms_processing->get_form_setting( 'admin_email_replyto' ); 
  488.  
  489. if ( $ninja_forms_processing->get_form_setting( 'admin_email_name' ) ) { 
  490. $email_from_name = $ninja_forms_processing->get_form_setting( 'admin_email_name' ); 
  491.  
  492. if ( $email_from_name AND $email_reply ) { 
  493. $email_reply = $email_from_name . ' <' . $email_reply . '>'; 
  494.  
  495. if ( !$subject ) { 
  496. $subject = $form_title; 
  497. if ( !$message ) { 
  498. $message = ''; 
  499. if ( !$email_type ) { 
  500. $email_type = ''; 
  501.  
  502. if ( $email_type !== 'plain' ) { 
  503. $message = apply_filters( 'ninja_forms_admin_email_message_wpautop', wpautop( $message ) ); 
  504.  
  505. $email_from = $email_from_name.' <'.$email_from.'>'; 
  506.  
  507. $email_from = apply_filters( 'ninja_forms_admin_email_from', $email_from, $email_reply, $form_ID ); 
  508.  
  509. $headers = array(); 
  510. $headers[] = 'From: ' . $email_from; 
  511. if( $email_reply ) { 
  512. $headers[] = 'Reply-To: ' . $email_reply; 
  513. $headers[] = 'Content-Type: text/' . $email_type; 
  514. $headers[] = 'charset=utf-8'; 
  515.  
  516. $attachments = false; 
  517. if ($ninja_forms_processing->get_form_setting( 'admin_attachments' ) ) { 
  518. $attachments = $ninja_forms_processing->get_form_setting( 'admin_attachments' ); 
  519.  
  520. if ( is_array( $admin_mailto ) AND !empty( $admin_mailto ) ) { 
  521. foreach( $admin_mailto as $to ) { 
  522. if ( $attachments ) { 
  523. wp_mail( $to, $subject, $message, $headers, $attachments ); 
  524. } else { 
  525. wp_mail( $to, $subject, $message, $headers ); 
  526.  
  527. // Delete our admin CSV if one is present. 
  528. if ( file_exists( $ninja_forms_processing->get_extra_value( '_attachment_csv_path' ) ) ) { 
  529. unlink ( $ninja_forms_processing->get_extra_value( '_attachment_csv_path' ) ); 
  530.  
  531. add_action('init', 'ninja_forms_register_email_user'); 
  532. function ninja_forms_register_email_user() { 
  533. add_action( 'ninja_forms_post_process', 'ninja_forms_email_user', 1000 ); 
  534.  
  535. function ninja_forms_email_user() { 
  536. global $ninja_forms_processing; 
  537.  
  538. do_action( 'ninja_forms_email_user' ); 
  539.  
  540. $form_ID = $ninja_forms_processing->get_form_ID(); 
  541. $form_title = $ninja_forms_processing->get_form_setting('form_title'); 
  542. $user_mailto = array(); 
  543. $all_fields = $ninja_forms_processing->get_all_fields(); 
  544. if(is_array($all_fields) AND !empty($all_fields)) { 
  545. foreach($all_fields as $field_id => $user_value) { 
  546. $field_row = $ninja_forms_processing->get_field_settings( $field_id ); 
  547.  
  548. if(isset($field_row['data']['send_email'])) { 
  549. $send_email = $field_row['data']['send_email']; 
  550. }else{ 
  551. $send_email = 0; 
  552.  
  553. if($send_email) { 
  554. array_push($user_mailto, $user_value); 
  555.  
  556. $email_from = $ninja_forms_processing->get_form_setting('email_from'); 
  557. $email_from_name = $ninja_forms_processing->get_form_setting( 'email_from_name' ); 
  558. $email_type = $ninja_forms_processing->get_form_setting('email_type'); 
  559. $subject = $ninja_forms_processing->get_form_setting('user_subject'); 
  560. $message = $ninja_forms_processing->get_form_setting('user_email_msg'); 
  561. $default_email = get_option( 'admin_email' ); 
  562.  
  563. if(!$subject) { 
  564. $subject = $form_title; 
  565. if(!$message) { 
  566. $message = __('Thank you for filling out this form.', 'ninja-forms'); 
  567. if(!$email_from) { 
  568. $email_from = $default_email; 
  569. if(!$email_type) { 
  570. $email_type = ''; 
  571.  
  572. if( $email_type !== 'plain' ) { 
  573. $message = apply_filters( 'ninja_forms_user_email_message_wpautop', wpautop( $message ) ); 
  574.  
  575. $email_from = $email_from_name.' <'.$email_from.'>'; 
  576.  
  577. $email_from = htmlspecialchars_decode($email_from); 
  578. $email_from = htmlspecialchars_decode($email_from); 
  579.  
  580. $headers = array(); 
  581. $headers[] = 'From: '.$email_from; 
  582. $headers[] = 'Content-Type: text/'.$email_type; 
  583. $headers[] = 'charset=utf-8'; 
  584.  
  585. $attachments = false; 
  586. if ( $ninja_forms_processing->get_form_setting( 'user_attachments' ) ) { 
  587. $attachments = $ninja_forms_processing->get_form_setting('user_attachments'); 
  588.  
  589. if ( is_array( $user_mailto ) AND ! empty( $user_mailto ) ) { 
  590. // check to make sure there's an attachment before attaching one 
  591. if ( $attachments ) { 
  592. wp_mail( $user_mailto, $subject, $message, $headers, $attachments ); 
  593. } else { 
  594. wp_mail( $user_mailto, $subject, $message, $headers ); 
  595.  
  596.  
  597. add_action( 'nf_save_sub', 'nf_csv_attachment' ); 
  598.  
  599. function nf_csv_attachment( $sub_id ) { 
  600. global $ninja_forms_processing; 
  601.  
  602. // make sure this form is supposed to attach a CSV 
  603. if( 1 == $ninja_forms_processing->get_form_setting( 'admin_attach_csv' ) AND 'submit' == $ninja_forms_processing->get_action() ) { 
  604.  
  605. // create CSV content 
  606. $csv_content = Ninja_Forms()->sub( $sub_id )->export( true ); 
  607.  
  608. $upload_dir = wp_upload_dir(); 
  609. $path = trailingslashit( $upload_dir['path'] ); 
  610.  
  611. // create temporary file 
  612. $path = tempnam( $path, 'Sub' ); 
  613. $temp_file = fopen( $path, 'r+' ); 
  614.  
  615. // write to temp file 
  616. fwrite( $temp_file, $csv_content ); 
  617. fclose( $temp_file ); 
  618.  
  619. // find the directory we will be using for the final file 
  620. $path = pathinfo( $path ); 
  621. $dir = $path['dirname']; 
  622. $basename = $path['basename']; 
  623.  
  624. // create name for file 
  625. $new_name = apply_filters( 'ninja_forms_submission_csv_name', 'ninja-forms-submission' ); 
  626.  
  627. // remove a file if it already exists 
  628. if( file_exists( $dir.'/'.$new_name.'.csv' ) ) { 
  629. unlink( $dir.'/'.$new_name.'.csv' ); 
  630.  
  631. // move file 
  632. rename( $dir.'/'.$basename, $dir.'/'.$new_name.'.csv' ); 
  633. $file1 = $dir.'/'.$new_name.'.csv'; 
  634.  
  635. // add new file to array of existing files 
  636. $files = $ninja_forms_processing->get_form_setting( 'admin_attachments' ); 
  637. array_push( $files, $file1 ); 
  638. $ninja_forms_processing->update_form_setting( 'admin_attachments', $files ); 
  639. $ninja_forms_processing->update_extra_value( '_attachment_csv_path', $file1 ); 
  640.  
  641. // Move any attachments that exist for our "admin" and "user" emails. 
  642. function nf_modify_attachments( $files, $n_id ) { 
  643. global $ninja_forms_processing; 
  644.  
  645. if ( Ninja_Forms()->notification( $n_id )->get_setting( 'admin_email' ) ) { 
  646. if ( is_array( $ninja_forms_processing->get_form_setting( 'admin_attachments' ) ) ) { 
  647. $files = array_merge( $files, $ninja_forms_processing->get_form_setting( 'admin_attachments' ) ); 
  648. } else if ( Ninja_Forms()->notification( $n_id )->get_setting( 'user_email' ) ) { 
  649. if ( is_array( $ninja_forms_processing->get_form_setting( 'user_attachments' ) ) ) { 
  650. $files = array_merge( $files, $ninja_forms_processing->get_form_setting( 'user_attachments' ) ); 
  651.  
  652. $ninja_forms_processing->update_form_setting( 'admin_attachments', '' ); 
  653.  
  654. return $files; 
  655.  
  656. add_filter( 'nf_email_notification_attachments', 'nf_modify_attachments', 10, 2 ); 
  657.  
  658. // Deprecate old "add all fields" filters 
  659. function nf_deprecate_all_fields_email_field_label( $value, $field_id ) { 
  660. return apply_filters( 'ninja_forms_email_field_label', $value, $field_id ); 
  661.  
  662. add_filter( 'nf_all_fields_field_label', 'nf_deprecate_all_fields_email_field_label', 10, 2 ); 
  663.  
  664. function nf_deprecate_all_fields_email_field_value( $value, $field_id ) { 
  665. return apply_filters( 'ninja_forms_email_user_value', $value, $field_id ); 
  666.  
  667. add_filter( 'nf_all_fields_field_value', 'nf_deprecate_all_fields_email_field_value', 10, 2 ); 
  668.  
  669. function nf_deprecate_all_fields_email_table( $value, $form_id ) { 
  670. return apply_filters( 'ninja_forms_email_field_list', $value, $form_id ); 
  671.  
  672. add_filter( 'nf_all_fields_table', 'nf_deprecate_all_fields_email_table', 10, 2 ); 
  673.  
  674. // Deprecate our old success message filter 
  675. function nf_deprecate_success_message_filter( $message, $n_id ) { 
  676. return apply_filters( 'ninja_forms_success_msg', $message ); 
  677.  
  678. add_filter( 'nf_success_msg', 'nf_deprecate_success_message_filter', 10, 2 ); 
  679.  
  680. // Remove any references to "admin email" from our imported forms. 
  681. function nf_deprecate_form_import( $form ) { 
  682. if ( isset ( $form['data']['admin_mailto'] ) ) 
  683. unset( $form['data']['admin_mailto'] ); 
  684.  
  685. if ( isset ( $form['data']['admin_email'] ) ) 
  686. unset( $form['data']['admin_email'] ); 
  687.  
  688. if ( isset ( $form['data']['admin_subject'] ) ) 
  689. unset( $form['data']['admin_subject'] ); 
  690.  
  691. if ( isset ( $form['data']['user_mailto'] ) ) 
  692. unset( $form['data']['user_mailto'] ); 
  693.  
  694. if ( isset ( $form['data']['user_email'] ) ) 
  695. unset( $form['data']['user_email'] ); 
  696.  
  697. if ( isset ( $form['data']['user_subject'] ) ) 
  698. unset ( $form['data']['user_subject'] ); 
  699.  
  700. if ( isset ( $form['data']['landing_page'] ) ) 
  701. unset ( $form['data']['landing_page'] ); 
  702.  
  703. return $form; 
  704.  
  705. add_filter( 'ninja_forms_before_import_form', 'nf_deprecate_form_import' ); 
  706.  
  707. // Remove any references to "user email" from our imported forms. 
  708. function nf_deprecate_field_import( $data ) { 
  709. if ( isset ( $data['send_email'] ) ) 
  710. unset ( $data['send_email'] ); 
  711.  
  712. if ( isset ( $data['from_email'] ) ) 
  713. unset ( $data['from_email'] ); 
  714.  
  715. if ( isset ( $data['replyto_email'] ) ) 
  716. unset ( $data['replyto_email'] ); 
  717.  
  718. return $data; 
  719.  
  720. add_filter( 'nf_before_import_field', 'nf_deprecate_field_import' ); 
  721.  
  722.  
  723. /**  
  724. * Deprecated as of version 2.9 
  725. * 
  726. */ 
  727.  
  728.  
  729. /** 
  730. * Get an array of form settings by form ID 
  731. * 
  732. * @since 2.7 
  733. * @param int $form_id 
  734. * @return array $form['data'] 
  735. */ 
  736. function nf_get_form_settings( $form_id ) { 
  737. return nf_get_object_meta( $form_id ); 
  738.  
  739. /** 
  740. * Return form data 
  741. *  
  742. * @since 1.0 
  743. * @param int $form_id 
  744. * @return array $form 
  745. */ 
  746. function ninja_forms_get_form_by_id( $form_id ) { 
  747. $settings = Ninja_Forms()->form( $form_id )->get_all_settings(); 
  748. $date_updated = Ninja_Forms()->form( $form_id )->get_setting( 'date_updated' ); 
  749. return array( 'id' => $form_id, 'data' => $settings, 'date_updated' => $date_updated ); 
  750.  
  751. /** 
  752. * Get a form by field id 
  753. *  
  754. * @since 1.0 
  755. * @param int $field_id 
  756. * @param array $form 
  757. */ 
  758. function ninja_forms_get_form_by_field_id( $field_id ) { 
  759. global $wpdb; 
  760. $form_id = $wpdb->get_row($wpdb->prepare("SELECT form_id FROM ".NINJA_FORMS_FIELDS_TABLE_NAME." WHERE id = %d", $field_id), ARRAY_A); 
  761. $form_id = $form_id['form_id']; 
  762. $form = ninja_forms_get_form_by_id( $form_id ); 
  763. return $form; 
  764.  
  765. /** 
  766. * Delete a form 
  767. * 
  768. * @since 1.0 
  769. */ 
  770. function ninja_forms_delete_form( $form_id = '' ) { 
  771. global $wpdb; 
  772.  
  773. // Bail if we aren't in the admin 
  774. if ( ! is_admin() ) 
  775. return false; 
  776.  
  777. // Bail if we don't have proper permissions 
  778. if ( ! current_user_can( apply_filters( 'nf_delete_form_capabilities', 'manage_options' ) ) ) 
  779. return false; 
  780.  
  781. if( $form_id == '' ) { 
  782. $ajax = true; 
  783. $form_id = absint( $_REQUEST['form_id'] ); 
  784. check_ajax_referer( 'nf_ajax', 'nf_ajax_nonce' ); 
  785. }else{ 
  786. $ajax = false; 
  787.  
  788. Ninja_Forms()->form( $form_id )->delete(); 
  789.  
  790. if( $ajax ) { 
  791. die(); 
  792.  
  793. add_action('wp_ajax_ninja_forms_delete_form', 'ninja_forms_delete_form'); 
  794.  
  795. function ninja_forms_get_all_forms( $debug = false ) { 
  796. $forms = Ninja_Forms()->forms()->get_all(); 
  797.  
  798. $tmp_array = array(); 
  799. $x = 0; 
  800. foreach ( $forms as $form_id ) { 
  801. $tmp_array[ $x ]['id'] = $form_id; 
  802. $tmp_array[ $x ]['data'] = Ninja_Forms()->form( $form_id )->get_all_settings(); 
  803. $tmp_array[ $x ]['name'] = Ninja_Forms()->form( $form_id )->get_setting( 'form_title' ); 
  804. $x++; 
  805.  
  806. return $tmp_array; 
  807.  
  808. /** 
  809. * Return our form count 
  810. * 
  811. * @since 2.8 
  812. * @return int $count 
  813. */ 
  814.  
  815. function nf_get_form_count() { 
  816. global $wpdb; 
  817.  
  818. $forms = Ninja_Forms()->forms()->get_all(); 
  819. return count( $forms ); 
  820.  
  821. /** 
  822. * Old update form function. 
  823. *  
  824. * @since 1.0 
  825. * @return void 
  826. */ 
  827. function ninja_forms_update_form( $args ) { 
  828. // Get our form id 
  829. $form_id = $args['where']['id']; 
  830. $update_array = $args['update_array']; 
  831. if ( isset ( $update_array['data'] ) ) { 
  832. $data = maybe_unserialize( $update_array['data'] ); 
  833. if ( is_array( $data ) ) { 
  834. foreach ( $data as $key => $val ) { 
  835. Ninja_Forms()->form( $form_id )->update_setting( $key, $val ); 
  836. }  
  837. unset( $update_array['data'] );  
  838.  
  839. foreach ( $update_array as $key => $val ) { 
  840. Ninja_Forms()->form( $form_id )->update_setting( $key, $val ); 
  841.  
  842. Ninja_Forms()->form( $form_id )->dump_cache(); 
  843.  
  844.  
  845. // Add our old form fields 
  846. require_once( NINJA_FORMS_DIR . "/includes/fields/honeypot.php" ); 
.