/deprecated/classes/subs-cpt.php

  1. <?php if ( ! defined( 'ABSPATH' ) ) exit; 
  2. /** 
  3. * Submission CPT. 
  4. * This class adds our submission CPT and handles displaying submissions in the wp-admin. 
  5. * 
  6. * @package Ninja Forms 
  7. * @subpackage Classes/Submissions 
  8. * @copyright Copyright (c) 2014, WPNINJAS 
  9. * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License 
  10. * @since 2.7 
  11. */ 
  12.  
  13. class NF_Subs_CPT { 
  14.  
  15. var $form_id; 
  16.  
  17. var $screen_options; 
  18.  
  19. var $filename; 
  20.  
  21. /** 
  22. * Get things started 
  23. * 
  24. * @access public 
  25. * @since 2.7 
  26. * @return void 
  27. */ 
  28. function __construct() { 
  29.  
  30. // Register our submission custom post type. 
  31. add_action( 'init', array( $this, 'register_cpt' ), 5 ); 
  32.  
  33. // Populate our field settings var 
  34. add_action( 'current_screen', array( $this, 'setup_fields' ) ); 
  35.  
  36. // Filter our hidden columns by form ID. 
  37. add_action( 'wp', array( $this, 'filter_hidden_columns' ) ); 
  38.  
  39. // Add our submenu for the submissions page. 
  40. add_action( 'admin_menu', array( $this, 'add_submenu' ), 10 ); 
  41.  
  42. // Change our submission columns. 
  43. add_filter( 'manage_nf_sub_posts_columns', array( $this, 'change_columns' ) ); 
  44.  
  45. // Make our columns sortable. 
  46. add_filter( 'manage_edit-nf_sub_sortable_columns', array( $this, 'sortable_columns' ) ); 
  47.  
  48. // Actually do the sorting 
  49. add_filter( 'request', array( $this, 'sort_columns' ) ); 
  50.  
  51. // Add the appropriate data for our custom columns. 
  52. add_action( 'manage_posts_custom_column', array( $this, 'custom_columns' ), 10, 2 ); 
  53.  
  54. // Add our submission filters. 
  55. add_action( 'restrict_manage_posts', array( $this, 'add_filters' ) ); 
  56. add_filter( 'parse_query', array( $this, 'table_filter' ) ); 
  57. add_filter( 'posts_clauses', array( $this, 'search' ), 20 ); 
  58.  
  59. add_action( 'admin_footer', array( $this, 'jquery_remove_counts' ) ); 
  60.  
  61. // Filter our post counts 
  62. add_filter( 'wp_count_posts', array( $this, 'count_posts' ), 10, 3 ); 
  63.  
  64. // Filter our bulk actions 
  65. add_filter( 'bulk_actions-edit-nf_sub', array( $this, 'remove_bulk_edit' ) ); 
  66. add_action( 'admin_footer-edit.php', array( $this, 'bulk_admin_footer' ) ); 
  67.  
  68. // Filter our bulk updated/trashed messages 
  69. add_filter( 'bulk_post_updated_messages', array( $this, 'updated_messages_filter' ), 10, 2 ); 
  70.  
  71. // Filter singular updated/trashed messages 
  72. add_filter( 'post_updated_messages', array( $this, 'post_updated_messages' ) ); 
  73.  
  74. // Add our metabox for editing field values 
  75. add_action( 'add_meta_boxes', array( $this, 'add_metaboxes' ) ); 
  76.  
  77. // Save our metabox values 
  78. add_action( 'save_post', array( $this, 'save_sub' ), 10, 2 ); 
  79.  
  80. // Save our hidden columns by form id. 
  81. add_action( 'wp_ajax_nf_hide_columns', array( $this, 'hide_columns' ) ); 
  82.  
  83. // Load any custom screen options 
  84. add_filter( 'screen_settings', array( $this, 'output_screen_options' ), 10, 2 ); 
  85.  
  86. // Listen for our exports button. 
  87. add_action( 'load-edit.php', array( $this, 'export_listen' ) ); 
  88.  
  89. // Filter our submission capabilities 
  90. add_filter( 'user_has_cap', array( $this, 'cap_filter' ), 10, 3 ); 
  91.  
  92.  
  93. /** 
  94. * Register our submission CPT 
  95. * 
  96. * @access public 
  97. * @since 2.7 
  98. * @return void 
  99. */ 
  100. public function register_cpt() { 
  101. if ( ! isset ( $_REQUEST['form_id'] ) || empty( $_REQUEST['form_id'] ) ) { 
  102. $not_found = __( 'Please select a form to view submissions', 'ninja-forms' ); 
  103. } else { 
  104. $not_found = __( 'No Submissions Found', 'ninja-forms' ); 
  105.  
  106. $name = _x( 'Submissions', 'post type general name', 'ninja-forms' ); 
  107.  
  108. if ( ! empty ( $_REQUEST['form_id'] ) ) { 
  109. $form_title = Ninja_Forms()->form( absint( $_REQUEST['form_id'] ) )->get_setting( 'form_title' ); 
  110. $name =$name . ' - ' . $form_title; 
  111.  
  112. $labels = array( 
  113. 'name' => $name,  
  114. 'singular_name' => _x( 'Submission', 'post type singular name', 'ninja-forms' ),  
  115. 'add_new' => _x( 'Add New', 'nf_sub' ),  
  116. 'add_new_item' => __( 'Add New Submission', 'ninja-forms' ),  
  117. 'edit_item' => __( 'Edit Submission', 'ninja-forms' ),  
  118. 'new_item' => __( 'New Submission', 'ninja-forms' ),  
  119. 'view_item' => __( 'View Submission', 'ninja-forms' ),  
  120. 'search_items' => __( 'Search Submissions', 'ninja-forms' ),  
  121. 'not_found' => $not_found,  
  122. 'not_found_in_trash' => __( 'No Submissions Found In The Trash', 'ninja-forms' ),  
  123. 'parent_item_colon' => '' 
  124. ); 
  125.  
  126. $args = array( 
  127. 'labels' => $labels,  
  128. 'public' => false,  
  129. 'publicly_queryable' => false,  
  130. 'show_ui' => true,  
  131. '_builtin' => false, // It's a custom post type, not built in! 
  132. 'query_var' => true,  
  133. 'has_archive' => false,  
  134. 'show_in_menu' => false,  
  135. 'hierarchical' => false,  
  136. 'menu_events' => null,  
  137. 'rewrite' => array( 'slug' => 'nf_sub' ), // Permalinks format 
  138. 'supports' => array( 'custom-fields' ),  
  139. 'capability_type' => 'nf_sub',  
  140. 'capabilities' => array( 
  141. 'publish_posts' => 'nf_sub',  
  142. 'edit_posts' => 'nf_sub',  
  143. 'edit_others_posts' => 'nf_sub',  
  144. 'delete_posts' => 'nf_sub',  
  145. 'delete_others_posts' => 'nf_sub',  
  146. 'read_private_posts' => 'nf_sub',  
  147. 'edit_post' => 'nf_sub',  
  148. 'delete_post' => 'nf_sub',  
  149. 'read_post' => 'nf_sub',  
  150. ),  
  151. ); 
  152.  
  153. register_post_type( 'nf_sub', $args ); 
  154.  
  155.  
  156. /** 
  157. * Populate our fields var with all the fields. This keeps us from needing to ping the database later. 
  158. * 
  159. * @access public 
  160. * @since 2.7 
  161. */ 
  162. public function setup_fields() { 
  163. global $pagenow, $typenow; 
  164.  
  165. // Bail if we aren't on the edit.php page, we aren't editing our custom post type, or we don't have a form_id set. 
  166. if ( ( $pagenow != 'edit.php' && $pagenow != 'post.php' ) || $typenow != 'nf_sub' ) 
  167. return false; 
  168.  
  169. if ( isset ( $_REQUEST['form_id'] ) ) { 
  170. $form_id = absint( $_REQUEST['form_id'] ); 
  171. } else if ( isset ( $_REQUEST['post'] ) ) { 
  172. $form_id = Ninja_Forms()->sub( absint( $_REQUEST['post'] ) )->form_id; 
  173. } else { 
  174. $form_id = ''; 
  175.  
  176. $this->form_id = $form_id; 
  177.  
  178. Ninja_Forms()->form( $form_id ); 
  179.  
  180. /** 
  181. * Add our submissions submenu 
  182. * 
  183. * @access public 
  184. * @since 2.7 
  185. * @return void 
  186. */ 
  187. public function add_submenu() { 
  188. // Add our submissions submenu 
  189. $sub_page = add_submenu_page( 'ninja-forms', __( 'Submissions', 'ninja-forms' ), __( 'Submissions', 'ninja-forms' ), apply_filters( 'ninja_forms_admin_submissions_capabilities', 'manage_options' ), 'edit.php?post_type=nf_sub' ); 
  190. // Enqueue our JS on the edit page. 
  191. //add_action( 'load-' . $sub_page, array( $this, 'load_js' ) ); 
  192. add_action( 'admin_print_styles', array( $this, 'load_js' ) ); 
  193. add_action( 'admin_print_styles', array( $this, 'load_css' ) ); 
  194. // Remove the publish box from the submission editing page. 
  195. remove_meta_box( 'submitdiv', 'nf_sub', 'side' ); 
  196.  
  197.  
  198. /** 
  199. * Enqueue our submissions JS file. 
  200. * 
  201. * @access public 
  202. * @since 2.7 
  203. * @return void 
  204. */ 
  205. public function load_js() { 
  206. global $pagenow, $typenow; 
  207. // Bail if we aren't on the edit.php page or we aren't editing our custom post type. 
  208. if ( ( $pagenow != 'edit.php' && $pagenow != 'post.php' ) || $typenow != 'nf_sub' ) 
  209. return false; 
  210.  
  211. $form_id = isset ( $_REQUEST['form_id'] ) ? absint( $_REQUEST['form_id'] ) : ''; 
  212.  
  213. if ( defined( 'NINJA_FORMS_JS_DEBUG' ) && NINJA_FORMS_JS_DEBUG ) { 
  214. $suffix = ''; 
  215. $src = 'dev'; 
  216. } else { 
  217. $suffix = '.min'; 
  218. $src = 'min'; 
  219.  
  220. $suffix = ''; 
  221. $src = 'dev'; 
  222.  
  223. $plugin_settings = nf_get_settings(); 
  224. $date_format = ninja_forms_date_to_datepicker( $plugin_settings['date_format'] ); 
  225.  
  226. $datepicker_args = array(); 
  227. if ( !empty( $date_format ) ) { 
  228. $datepicker_args['dateFormat'] = $date_format; 
  229.  
  230. wp_enqueue_script( 'subs-cpt',  
  231. NF_PLUGIN_URL . 'assets/js/' . $src .'/subs-cpt' . $suffix . '.js',  
  232. array('jquery', 'jquery-ui-datepicker') ); 
  233.  
  234. wp_localize_script( 'subs-cpt', 'nf_sub', array( 'form_id' => $form_id, 'datepicker_args' => apply_filters( 'ninja_forms_admin_submissions_datepicker_args', $datepicker_args ) ) ); 
  235.  
  236.  
  237. /** 
  238. * Enqueue our submissions CSS file. 
  239. * 
  240. * @access public 
  241. * @since 2.7 
  242. * @return void 
  243. */ 
  244. public function load_css() { 
  245. global $pagenow, $typenow; 
  246.  
  247. // Bail if we aren't on the edit.php page or the post.php page. 
  248. if ( ( $pagenow != 'edit.php' && $pagenow != 'post.php' ) || $typenow != 'nf_sub' ) 
  249. return false; 
  250.  
  251. wp_enqueue_style( 'nf-sub', NF_PLUGIN_URL .'assets/css/cpt.css' ); 
  252. wp_enqueue_style( 'nf-jquery-ui-freshness', NF_PLUGIN_URL .'assets/css/jquery-ui-fresh.min.css' ); 
  253.  
  254. /** 
  255. * Modify the columns of our submissions table. 
  256. * 
  257. * @access public 
  258. * @since 2.7 
  259. * @return array $cols 
  260. */ 
  261. public function change_columns( $cols ) { 
  262. // Compatibility with old field registration system. Can be removed when the new one is in place. 
  263. global $ninja_forms_fields; 
  264. // End Compatibility 
  265.  
  266. $cols = array( 
  267. 'cb' => '<input type="checkbox" />',  
  268. 'id' => __( '#', 'ninja-forms' ),  
  269. ); 
  270.  
  271. // Compatibility with old field registration system. Can be removed when the new one is in place. 
  272. if ( isset ( $_GET['form_id'] ) && $_GET['form_id'] != '' ) { 
  273. $form_id = absint( $_GET['form_id'] ); 
  274. if ( is_object( Ninja_Forms()->form( $this->form_id ) ) && is_array ( Ninja_Forms()->form( $this->form_id )->fields ) ) { 
  275. foreach ( Ninja_Forms()->form( $this->form_id )->fields as $field ) { 
  276. $field_id = $field['id']; 
  277. $field_type = $field['type']; 
  278. if ( isset ( $ninja_forms_fields[ $field_type ] ) ) { 
  279. $reg_field = $ninja_forms_fields[ $field_type ]; 
  280. $process_field = $reg_field['process_field']; 
  281. } else { 
  282. $process_field = false; 
  283. if ( isset ( $field['data']['admin_label'] ) && ! empty ( $field['data']['admin_label'] ) ) { 
  284. $label = $field['data']['admin_label']; 
  285. } else if ( isset ( $field['data']['label'] ) ) { 
  286. $label = $field['data']['label']; 
  287. } else { 
  288. $label = ''; 
  289.  
  290. if ( strlen( $label ) > 140 ) 
  291. $label = substr( $label, 0, 140 ); 
  292.  
  293. if ( isset ( $field['data']['label'] ) && $process_field ) 
  294. $cols[ 'form_' . $form_id . '_field_' . $field_id ] = $label; 
  295. } else { 
  296. $form_id = ''; 
  297. // End Compatibility 
  298. // Add our date column 
  299. $cols['sub_date'] = __( 'Date', 'ninja-forms' ); 
  300.  
  301. return apply_filters( 'nf_sub_table_columns', $cols, $form_id ); 
  302.  
  303. /** 
  304. * Make our columns sortable 
  305. * 
  306. * @access public 
  307. * @since 2.7 
  308. * @return array 
  309. */ 
  310. public function sortable_columns() { 
  311. // Get a list of all of our fields. 
  312. $columns = get_column_headers( 'edit-nf_sub' ); 
  313. $tmp_array = array(); 
  314. foreach ( $columns as $slug => $c ) { 
  315. if ( $slug != 'cb' ) { 
  316. $tmp_array[ $slug ] = $slug; 
  317. return $tmp_array; 
  318.  
  319. /** 
  320. * Actually sort our columns 
  321. * 
  322. * @access public 
  323. * @since 2.7 
  324. * @return array $vars 
  325. */ 
  326. public function sort_columns( $vars ) { 
  327. global $pagenow, $typenow; 
  328. if( array_key_exists( 'orderby', $vars ) ) { 
  329. if( strpos( $vars['orderby'], 'form_' ) !== false ) { 
  330. $args = explode( '_', $vars['orderby'] ); 
  331. $field_id = $args[3]; 
  332.  
  333. if ( isset ( Ninja_Forms()->form( $this->form_id )->fields[ $field_id ]['data']['num_sort'] ) && Ninja_Forms()->form( $this->form_id )->fields[ $field_id ]['data']['num_sort'] == 1 ) { 
  334. $orderby = 'meta_value_num'; 
  335. } else { 
  336. $orderby = 'meta_value'; 
  337.  
  338. $vars['orderby'] = $orderby; 
  339. $vars['meta_key'] = '_field_' . $field_id; 
  340. } else if ( $vars['orderby'] == 'id' ) { 
  341. $vars['orderby'] = 'meta_value_num'; 
  342. $vars['meta_key'] = '_seq_num'; 
  343. } else if( is_admin() && $typenow == 'nf_sub' && $pagenow == 'edit.php' ) { 
  344. $vars['orderby'] = 'meta_value_num'; 
  345. $vars['meta_key'] = '_seq_num'; 
  346. $vars['order'] = 'DESC'; 
  347. return $vars; 
  348.  
  349. /** 
  350. * Add our custom column data 
  351. * 
  352. * @access public 
  353. * @since 2.7 
  354. * @return void 
  355. */ 
  356. public function custom_columns( $column, $sub_id ) { 
  357. if ( isset ( $_GET['form_id'] ) ) { 
  358. $form_id = $_GET['form_id']; 
  359. if ( $column == 'id' ) { 
  360. echo apply_filters( 'nf_sub_table_seq_num', Ninja_Forms()->sub( $sub_id )->get_seq_num(), $sub_id, $column ); 
  361. echo '<div class="locked-info"><span class="locked-avatar"></span> <span class="locked-text"></span></div>'; 
  362. if ( !isset ( $_GET['post_status'] ) || $_GET['post_status'] == 'all' ) { 
  363. echo '<div class="row-actions custom-row-actions">'; 
  364. do_action( 'nf_sub_table_before_row_actions', $sub_id, $column ); 
  365. echo '<span class="edit"><a href="post.php?post=' . $sub_id . '&action=edit&ref=' . urlencode( esc_url( add_query_arg( array() ) ) ) . '" title="' . __( 'Edit this item', 'ninja-forms' ) . '">' . __( 'Edit', 'ninja-forms' ) . '</a> | </span>  
  366. <span class="edit"><a href="' . esc_url( add_query_arg( array( 'export_single' => $sub_id ) ) ) . '" title="' . __( 'Export this item', 'ninja-forms' ) . '">' . __( 'Export', 'ninja-forms' ) . '</a> | </span>'; 
  367. $row_actions = apply_filters( 'nf_sub_table_row_actions', array(), $sub_id, $form_id ); 
  368. if ( ! empty( $row_actions ) ) { 
  369. echo implode(" | ", $row_actions); 
  370. echo '| '; 
  371. echo '<span class="trash"><a class="submitdelete" title="' . __( 'Move this item to the Trash', 'ninja-forms' ) . '" href="' . get_delete_post_link( $sub_id ) . '">' . __( 'Trash', 'ninja-forms' ) . '</a> </span>'; 
  372. do_action( 'nf_sub_table_after_row_actions', $sub_id, $column ); 
  373. echo '</div>'; 
  374. } else { 
  375. echo '<div class="row-actions custom-row-actions">'; 
  376. do_action( 'nf_sub_table_before_row_actions_trash', $sub_id, $column ); 
  377. echo '<span class="untrash"><a title="' . esc_attr( __( 'Restore this item from the Trash' ) ) . '" href="' . wp_nonce_url( sprintf( get_edit_post_link( $sub_id ) . '&action=untrash', $sub_id ) , 'untrash-post_' . $sub_id ) . '">' . __( 'Restore' ) . '</a> | </span>  
  378. <span class="delete"><a class="submitdelete" title="' . esc_attr( __( 'Delete this item permanently' ) ) . '" href="' . get_delete_post_link( $sub_id, '', true ) . '">' . __( 'Delete Permanently' ) . '</a></span>'; 
  379. do_action( 'nf_sub_table_after_row_actions_trash', $sub_id, $column ); 
  380. echo '</div>'; 
  381. } else if ( $column == 'sub_date' ) { 
  382. $post = get_post( $sub_id ); 
  383. if ( '0000-00-00 00:00:00' == $post->post_date ) { 
  384. $t_time = $h_time = __( 'Unpublished' ); 
  385. $time_diff = 0; 
  386. } else { 
  387. $t_time = get_the_time( 'Y/m/d g:i:s A' ); 
  388. $m_time = $post->post_date; 
  389. $time = get_post_time( 'G', true, $post ); 
  390.  
  391. $time_diff = time() - $time; 
  392.  
  393. if ( $time_diff > 0 && $time_diff < DAY_IN_SECONDS ) 
  394. $h_time = sprintf( __( '%s ago' ), human_time_diff( $time ) ); 
  395. else 
  396. $h_time = mysql2date( 'Y/m/d', $m_time ); 
  397.  
  398. $t_time = apply_filters( 'nf_sub_title_time', $t_time ); 
  399. $h_time = apply_filters( 'nf_sub_human_time', $h_time ); 
  400.  
  401. /** This filter is documented in wp-admin/includes/class-wp-posts-list-table.php */ 
  402. echo '<abbr title="' . $t_time . '">' . $h_time . '</abbr>'; 
  403.  
  404. echo '<br />'; 
  405. echo apply_filters( 'nf_sub_table_status', __( 'Submitted', 'ninja-forms' ), $sub_id ); 
  406.  
  407. } else if ( strpos( $column, '_field_' ) !== false ) { 
  408. global $ninja_forms_fields; 
  409.  
  410. $field_id = str_replace( 'form_' . $form_id . '_field_', '', $column ); 
  411. //if ( apply_filters( 'nf_add_sub_value', Ninja_Forms()->field( $field_id )->type->add_to_sub, $field_id ) ) { 
  412. $field = Ninja_Forms()->form( $form_id )->fields[ $field_id ]; 
  413. $field_type = $field['type']; 
  414. if ( isset ( $ninja_forms_fields[ $field_type ] ) ) { 
  415. $reg_field = $ninja_forms_fields[ $field_type ]; 
  416. } else { 
  417. $reg_field = array(); 
  418.  
  419. if ( isset ( $reg_field['sub_table_value'] ) ) { 
  420. $edit_value_function = $reg_field['sub_table_value']; 
  421. } else { 
  422. $edit_value_function = 'nf_field_text_sub_table_value'; 
  423.  
  424. $user_value = Ninja_Forms()->sub( $sub_id )->get_field( $field_id ); 
  425.  
  426. $args['field_id'] = $field_id; 
  427. $args['user_value'] = ninja_forms_esc_html_deep( $user_value ); 
  428. $args['field'] = $field; 
  429.  
  430. call_user_func_array( $edit_value_function, $args ); 
  431. //} 
  432.  
  433. /** 
  434. * Add our submission filters 
  435. * 
  436. * @access public 
  437. * @since 2.7 
  438. * @return void 
  439. */ 
  440. public function add_filters() { 
  441. global $typenow; 
  442.  
  443. // Bail if we aren't in our submission custom post type. 
  444. if ( $typenow != 'nf_sub' ) 
  445. return false; 
  446.  
  447. // Add our Form selection dropdown. 
  448. // Get our list of forms 
  449. $forms = Ninja_Forms()->forms()->get_all(); 
  450.  
  451. $form_id = isset( $_GET['form_id'] ) ? $_GET['form_id'] : ''; 
  452.  
  453. $begin_date = isset ( $_GET['begin_date'] ) ? $_GET['begin_date'] : ''; 
  454. $end_date = isset ( $_GET['end_date'] ) ? $_GET['end_date'] : ''; 
  455.  
  456. // Add begin date and end date filter fields. 
  457. $html = '<div style="float:left;">'; 
  458. $html .= '<span style="float:left;" class="spinner"></span>'; 
  459. $html .= '<select name="form_id" id="form_id" class="nf-form-jump">'; 
  460. $html .= '<option value="">- ' . __( 'Select a form', 'ninja-forms' ) . '</option>'; 
  461. if ( is_array( $forms ) ) { 
  462. foreach ( $forms as $f_id ) { 
  463. $form_title = Ninja_Forms()->form( $f_id )->get_setting( 'form_title' ); 
  464. $html .= '<option value="' . $f_id . '" ' . selected( $form_id, $f_id, false ) . '>' . $form_title . '</option>'; 
  465. $html .= '</select>'; 
  466.  
  467. $html .= '<input name="begin_date" type="text" class="datepicker" placeholder="' . __( 'Begin Date', 'ninja-forms' ) . '" value="' . $begin_date . '" /> '; 
  468. $html .= '<input name="end_date" type="text" class="datepicker" placeholder="' . __( 'End Date', 'ninja-forms' ) . '" value="' . $end_date . '" />'; 
  469. $html .= '</div>'; 
  470.  
  471. echo $html; 
  472.  
  473.  
  474. /** 
  475. * Filter our submission list by form_id 
  476. * 
  477. * @access public 
  478. * @since 2.7 
  479. * @return void 
  480. */ 
  481. public function table_filter( $query ) { 
  482. global $pagenow; 
  483.  
  484. if( $pagenow == 'edit.php' && is_admin() && ( isset ( $query->query['post_type'] ) && $query->query['post_type'] == 'nf_sub' ) && is_main_query() ) { 
  485.  
  486. $qv = &$query->query_vars; 
  487.  
  488. if( !empty( $_GET['form_id'] ) ) { 
  489. $form_id = $_GET['form_id']; 
  490. } else { 
  491. $form_id = 0; 
  492.  
  493. $plugin_settings = nf_get_settings(); 
  494. $date_format = $plugin_settings['date_format']; 
  495.  
  496. if ( !empty ( $_GET['begin_date'] ) ) { 
  497. $begin_date = nf_get_begin_date( $_GET['begin_date'] )->format("Y-m-d G:i:s"); 
  498. } else { 
  499. $begin_date = ''; 
  500.  
  501. if ( !empty ( $_GET['end_date'] ) ) { 
  502. $end_date = nf_get_end_date( $_GET['end_date'] )->format("Y-m-d G:i:s"); 
  503. } else { 
  504. $end_date = ''; 
  505.  
  506. if ( $begin_date > $end_date ) { 
  507. $begin_date = new DateTime( $begin_date ); 
  508. $end_date = new DateTime( $end_date ); 
  509. $end_date_temp = $begin_date; 
  510. $begin_date_temp = $end_date; 
  511. $begin_date = $begin_date_temp; 
  512. $end_date = $end_date_temp; 
  513. $_GET['begin_date'] = $begin_date->format('m/d/Y'); 
  514. $_GET['end_date'] = $end_date->format('m/d/Y'); 
  515. $begin_date = $begin_date->format("Y-m-d G:i:s"); 
  516. $end_date = $end_date->format("Y-m-d G:i:s"); 
  517.  
  518. if ( ! isset ( $qv['date_query'] ) ) { 
  519. $qv['date_query'] = array( 
  520. 'after' => $begin_date,  
  521. 'before' => $end_date,  
  522. ); 
  523.  
  524. if ( ! isset ( $qv['meta_query'] ) ) { 
  525. $qv['meta_query'] = array( 
  526. array( 
  527. 'key' => '_form_id',  
  528. 'value' => $form_id,  
  529. 'compare' => '=',  
  530. ),  
  531. ); 
  532.  
  533. $qv = apply_filters( 'nf_subs_table_qv', $qv, $form_id ); 
  534.  
  535. /** 
  536. * Filter our search 
  537. * 
  538. * @access public 
  539. * @since 2.7 
  540. * @return void 
  541. */ 
  542. public function search( $pieces ) { 
  543. global $typenow; 
  544. // filter to select search query 
  545. if ( is_search() && is_admin() && $typenow == 'nf_sub' && isset ( $_GET['s'] ) ) { 
  546. global $wpdb; 
  547.  
  548. $keywords = explode(' ', get_query_var('s')); 
  549. $query = ""; 
  550.  
  551. foreach ($keywords as $word) { 
  552.  
  553. $query .= " (mypm1.meta_value LIKE '%{$word}%') OR "; 
  554.  
  555. if (!empty($query)) { 
  556. // add to where clause 
  557. $pieces['where'] = str_replace("((({$wpdb->posts}.post_title LIKE '%", "( {$query} (({$wpdb->posts}.post_title LIKE '%", $pieces['where']); 
  558.  
  559. $pieces['join'] = $pieces['join'] . " INNER JOIN {$wpdb->postmeta} AS mypm1 ON ({$wpdb->posts}.ID = mypm1.post_id)"; 
  560.  
  561. return ($pieces); 
  562.  
  563. /** 
  564. * Filter our bulk updated/trashed messages so that it uses "submission" rather than "post" 
  565. * 
  566. * @access public 
  567. * @since 2.7 
  568. * @return array $bulk_messages 
  569. */ 
  570. public function updated_messages_filter( $bulk_messages, $bulk_counts ) { 
  571. $bulk_messages['nf_sub'] = array( 
  572. 'updated' => _n( '%s submission updated.', '%s submissions updated.', $bulk_counts['updated'], 'ninja-forms' ),  
  573. 'locked' => _n( '%s submission not updated, somebody is editing it.', '%s submissions not updated, somebody is editing them.', $bulk_counts['locked'], 'ninja-forms' ),  
  574. 'deleted' => _n( '%s submission permanently deleted.', '%s submissions permanently deleted.', $bulk_counts['deleted'], 'ninja-forms' ),  
  575. 'trashed' => _n( '%s submission moved to the Trash.', '%s submissions moved to the Trash.', $bulk_counts['trashed'], 'ninja-forms' ),  
  576. 'untrashed' => _n( '%s submission restored from the Trash.', '%s submissions restored from the Trash.', $bulk_counts['untrashed'], 'ninja-forms' ),  
  577. ); 
  578.  
  579. return $bulk_messages; 
  580.  
  581. /** 
  582. * Filter our updated/trashed post messages 
  583. * 
  584. * @access public 
  585. * @since 2.7 
  586. * @return array $messages 
  587. */ 
  588. function post_updated_messages( $messages ) { 
  589.  
  590. global $post, $post_ID; 
  591. $post_type = 'nf_sub'; 
  592.  
  593. $obj = get_post_type_object( $post_type ); 
  594. $singular = $obj->labels->singular_name; 
  595.  
  596. $messages[$post_type] = array( 
  597. 0 => '', // Unused. Messages start at index 1. 
  598. 1 => sprintf( __( '%s updated.', 'ninja-forms' ), $singular ),  
  599. 2 => __( 'Custom field updated.' ),  
  600. 3 => __( 'Custom field deleted.' ),  
  601. 4 => sprintf( __( '%s updated.', 'ninja-forms' ), $singular ),  
  602. /** translators: %s: date and time of the revision */ 
  603. 5 => isset($_GET['revision']) ? sprintf( __( '%1$s restored to revision from %2$s.' ), $singular, wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,  
  604. 6 => sprintf( __( '%s published.', 'ninja-forms' ), $singular ),  
  605. 7 => sprintf( __( '%s saved.', 'ninja-forms' ), $singular ),  
  606. 8 => sprintf( __( '%1$s submitted. <a href="%2$s" target="_blank">Preview %3$s</a>', 'ninja-forms' ), $singular, esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ), $singular ),  
  607. 9 => sprintf( __( '%1$s scheduled for: <strong>%2$s</strong>. <a href="%3$s" target="_blank">Preview %4$s</a>', 'ninja-forms' ), $singular, date_i18n( get_option( 'data_format' ) . ' ' . get_option( 'time_format' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID ) ), $singular ),  
  608. 10 => sprintf( __( '%1$s draft updated. <a href="%2$s" target="_blank">Preview %3$s</a>', 'ninja-forms' ), $singular, esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ), $singular ),  
  609. ); 
  610.  
  611. return $messages; 
  612.  
  613. /** 
  614. * Remove the 'edit' bulk action 
  615. * 
  616. * @access public 
  617. * @since 2.7 
  618. * @return array $actions 
  619. */ 
  620. public function remove_bulk_edit( $actions ) { 
  621. unset( $actions['edit'] ); 
  622. return $actions; 
  623.  
  624. /** 
  625. * Add our "export" bulk action 
  626. * 
  627. * @access public 
  628. * @since 2.7 
  629. * @return void 
  630. */ 
  631. public function bulk_admin_footer() { 
  632. global $post_type; 
  633.  
  634. if ( ! is_admin() ) 
  635. return false; 
  636.  
  637. if( $post_type == 'nf_sub' && isset ( $_REQUEST['post_status'] ) && $_REQUEST['post_status'] == 'all' ) { 
  638. ?> 
  639. <script type="text/javascript"> 
  640. jQuery(document).ready(function() { 
  641. jQuery('<option>').val('export').text('<?php _e('Export')?>').appendTo("select[name='action']"); 
  642. jQuery('<option>').val('export').text('<?php _e('Export')?>').appendTo("select[name='action2']"); 
  643. <?php 
  644. if ( ( isset ( $_POST['action'] ) && $_POST['action'] == 'export' ) || ( isset ( $_POST['action2'] ) && $_POST['action2'] == 'export' ) ) { 
  645. ?> 
  646. setInterval(function() { 
  647. jQuery( "select[name='action'" ).val( '-1' ); 
  648. jQuery( "select[name='action2'" ).val( '-1' ); 
  649. jQuery( '#posts-filter' ).submit(); 
  650. }, 5000); 
  651. <?php 
  652.  
  653. if ( isset ( $_REQUEST['form_id'] ) && ! empty ( $_REQUEST['form_id'] ) ) { 
  654. $redirect = urlencode( remove_query_arg( array( 'download_all', 'download_file' ) ) ); 
  655. $url = admin_url( 'admin.php?page=nf-processing&action=download_all_subs&form_id=' . absint( $_REQUEST['form_id'] ) . '&redirect=' . $redirect ); 
  656. $url = esc_url( $url ); 
  657. ?> 
  658. var button = '<a href="<?php echo $url; ?>" class="button-secondary nf-download-all"><?php echo __( 'Download All Submissions', 'ninja-forms' ); ?></a>'; 
  659. jQuery( '#doaction2' ).after( button ); 
  660. <?php 
  661.  
  662. if ( isset ( $_REQUEST['download_all'] ) && $_REQUEST['download_all'] != '' ) { 
  663. $redirect = esc_url_raw( add_query_arg( array( 'download_file' => esc_html( $_REQUEST['download_all'] ) ) ) ); 
  664. $redirect = remove_query_arg( array( 'download_all' ), $redirect ); 
  665. ?> 
  666. document.location.href = "<?php echo $redirect; ?>"; 
  667. <?php 
  668.  
  669. ?> 
  670. }); 
  671. </script> 
  672. <?php 
  673.  
  674. /** 
  675. * jQuery that hides some of our post-related page items. 
  676. * Also adds the active class to All and Trash links, and changes those 
  677. * links to match the current filter. 
  678. * 
  679. * @access public 
  680. * @since 2.7 
  681. * @return void 
  682. */ 
  683. public function jquery_remove_counts() { 
  684. global $typenow, $pagenow; 
  685. if ( $typenow == 'nf_sub' && $pagenow == 'edit.php' ) { 
  686. // Remove our transient 
  687. delete_transient( 'nf_sub_edit_ref' ); 
  688.  
  689. if ( ! isset ( $_GET['post_status'] ) || $_GET['post_status'] == 'all' ) { 
  690. $active = 'all'; 
  691. } else if ( $_GET['post_status'] == 'trash' ) { 
  692. $active = 'trash'; 
  693.  
  694. $all_url = esc_url_raw( add_query_arg( array( 'post_status' => 'all' ) ) ); 
  695. $all_url = remove_query_arg( 's', $all_url ); 
  696. $trash_url = esc_url_raw( add_query_arg( array( 'post_status' => 'trash' ) ) ); 
  697. $trash_url = remove_query_arg( 's', $trash_url ); 
  698. if ( isset ( $_GET['form_id'] ) ) { 
  699. $trashed_sub_count = nf_get_sub_count( $_GET['form_id'], 'trash' ); 
  700. } else { 
  701. $trashed_sub_count = 0; 
  702.  
  703. ?> 
  704. <script type="text/javascript"> 
  705. jQuery(function() { 
  706. jQuery( "li.all" ).find( "a" ).attr( "href", "<?php echo $all_url; ?>" ); 
  707. jQuery( "li.<?php echo $active; ?>" ).addClass( "current" ); 
  708. jQuery( "li.<?php echo $active; ?>" ).find( "a" ).addClass( "current" ); 
  709. jQuery( "li.trash" ).find( "a" ).attr( "href", "<?php echo $trash_url; ?>" ); 
  710. jQuery( ".view-switch" ).remove(); 
  711. <?php 
  712. if ( $trashed_sub_count == 0 ) { 
  713. ?> 
  714. var text = jQuery( "li.all" ).prop( "innerHTML" ); 
  715. text = text.replace( " |", "" ); 
  716. jQuery( "li.all" ).prop( "innerHTML", text ); 
  717. <?php 
  718. ?> 
  719. }); 
  720. </script> 
  721.  
  722. <style> 
  723. .add-new-h2 { 
  724. display:none; 
  725. li.publish { 
  726. display:none; 
  727. select[name=m] { 
  728. display:none; 
  729. </style> 
  730. <?php 
  731. } else if ( $typenow == 'nf_sub' && $pagenow == 'post.php' ) { 
  732. if ( isset ( $_REQUEST['ref'] ) ) { 
  733. $back_url = esc_url_raw( $_REQUEST['ref'] ); 
  734. } else { 
  735. $back_url = get_transient( 'nf_sub_edit_ref' ); 
  736.  
  737. if ( $back_url ) { 
  738. $back_url = urldecode( $back_url ); 
  739. } else { 
  740. $back_url = ''; 
  741. ?> 
  742. <script type="text/javascript"> 
  743. jQuery(function() { 
  744. var html = '<a href="<?php echo $back_url; ?>" class="back button-secondary"><?php _e( 'Back to list', 'ninja-forms' ); ?></a>'; 
  745. jQuery( 'div.wrap' ).children( 'h2:first' ).append( html ); 
  746. jQuery( 'li#toplevel_page_ninja-forms' ).children( 'a' ).removeClass( 'wp-not-current-submenu' ); 
  747. jQuery( 'li#toplevel_page_ninja-forms' ).removeClass( 'wp-not-current-submenu' ); 
  748. jQuery( 'li#toplevel_page_ninja-forms' ).addClass( 'wp-menu-open wp-has-current-submenu' ); 
  749. jQuery( 'li#toplevel_page_ninja-forms' ).children( 'a' ).addClass( 'wp-menu-open wp-has-current-submenu' ); 
  750.  
  751. }); 
  752. </script> 
  753. <style> 
  754. .add-new-h2 { 
  755. display:none; 
  756. </style> 
  757.  
  758. <?php 
  759.  
  760. /** 
  761. * Filter our post counts for the submission listing page 
  762. * 
  763. * @access public 
  764. * @since 2.7 
  765. * @return int $count 
  766. */ 
  767. public function count_posts( $count, $post_type, $perm ) { 
  768.  
  769. // Bail if we aren't working with our custom post type. 
  770. if ( $post_type != 'nf_sub' ) 
  771. return $count; 
  772.  
  773. if ( isset ( $_GET['form_id'] ) ) { 
  774. $sub_count = nf_get_sub_count( $_GET['form_id'] ); 
  775. $trashed_sub_count = nf_get_sub_count( $_GET['form_id'], 'trash' ); 
  776. $count->publish = $sub_count; 
  777. $count->trash = $trashed_sub_count; 
  778. } else { 
  779. $count->publish = 0; 
  780. $count->trash = 0; 
  781.  
  782. return $count; 
  783.  
  784. /** 
  785. * Add our field editing metabox to the CPT editing page. 
  786. * 
  787. * @access public 
  788. * @since 2.7 
  789. * @return void 
  790. */ 
  791. public function add_metaboxes() { 
  792. // Remove the 'custom fields' metabox from our CPT edit page 
  793. remove_meta_box( 'postcustom', 'nf_sub', 'normal' ); 
  794. // Remove the 'slug' metabox from our CPT edit page. 
  795. remove_meta_box( 'slugdiv', 'nf_sub', 'normal' ); 
  796. // Add our field editing metabox. 
  797. add_meta_box( 'nf_fields', __( 'User Submitted Values', 'ninja-forms' ), array( $this, 'edit_sub_metabox' ), 'nf_sub', 'normal', 'default'); 
  798. // Add our save field values metabox 
  799. add_meta_box( 'nf_fields_save', __( 'Submission Stats', 'ninja-forms' ), array( $this, 'save_sub_metabox' ), 'nf_sub', 'side', 'default'); 
  800.  
  801.  
  802. /** 
  803. * Output our field editing metabox to the CPT editing page. 
  804. * 
  805. * @access public 
  806. * @since 2.7 
  807. * @return void 
  808. */ 
  809. public function edit_sub_metabox( $post ) { 
  810. global $ninja_forms_fields; 
  811. // Get all the post meta 
  812. $form_id = Ninja_Forms()->sub( $post->ID )->form_id; 
  813. $fields = Ninja_Forms()->form( $this->form_id )->fields; 
  814.  
  815. if ( isset ( $_REQUEST['ref'] ) ) { 
  816. $ref = esc_url_raw( $_REQUEST['ref'] ); 
  817. } else if ( get_transient( 'nf_sub_edit_ref' ) ) { 
  818. $ref = get_transient( 'nf_sub_edit_ref' ); 
  819. } else { 
  820. $ref = ''; 
  821. ?> 
  822. <input type="hidden" name="ref" value="<?php echo $ref; ?>" /> 
  823. <div id="postcustomstuff"> 
  824. <table id="list-table"> 
  825. <thead> 
  826. <tr> 
  827. <th class="left"><?php _e( 'Field', 'ninja-forms' ); ?></th> 
  828. <th><?php _e( 'Value', 'ninja-forms' ); ?></th> 
  829. </tr> 
  830. </thead> 
  831. <tbody id="the-list"> 
  832. <?php 
  833. // Loop through our post meta and keep our field values 
  834. foreach ( $fields as $field_id => $field ) { 
  835. $user_value = Ninja_Forms()->sub( $post->ID )->get_field( $field_id ); 
  836. $field_type = $field['type']; 
  837.  
  838. if ( isset ( $field['data']['admin_label'] ) && $field['data']['admin_label'] != '' ) { 
  839. $label = $field['data']['admin_label']; 
  840. } else if ( isset ( $field['data']['label'] ) ) { 
  841. $label = $field['data']['label']; 
  842. } else { 
  843. $label = ''; 
  844.  
  845. if ( isset ( $ninja_forms_fields[ $field_type ] ) ) { 
  846. $reg_field = $ninja_forms_fields[ $field_type ]; 
  847. $process_field = $reg_field['process_field']; 
  848. } else { 
  849. $process_field = false; 
  850.  
  851. if ( isset ( Ninja_Forms()->form( $this->form_id )->fields[ $field_id ] ) && $process_field ) { 
  852. ?> 
  853. <tr> 
  854. <td class="left"><?php echo $label; ?></td> 
  855. <td> 
  856. <div class="nf-sub-edit-value type-<?php echo $field_type; ?>"> 
  857. <?php 
  858. if ( isset ( $reg_field['edit_sub_value'] ) ) { 
  859. $edit_value_function = $reg_field['edit_sub_value']; 
  860. } else { 
  861. $edit_value_function = 'nf_field_text_edit_sub_value'; 
  862. $args['field_id'] = $field_id; 
  863. $args['user_value'] = nf_wp_kses_post_deep( $user_value ); 
  864. $args['field'] = $field; 
  865. $args['sub_id'] = $post->ID; 
  866.  
  867. call_user_func_array( $edit_value_function, $args ); 
  868.  
  869. ?> 
  870. </div> 
  871. </td> 
  872. </tr> 
  873. <?php 
  874.  
  875. ?> 
  876. </tbody> 
  877. </table> 
  878. </div> 
  879. <?php 
  880.  
  881. /** 
  882. * Output our field editing metabox to the CPT editing page. 
  883. * 
  884. * @access public 
  885. * @since 2.7 
  886. * @return void 
  887. */ 
  888. public function save_sub_metabox( $post ) { 
  889. $date_submitted = apply_filters( 'nf_edit_sub_date_submitted', date( 'M j, Y @ h:i', strtotime( $post->post_date ) ), $post->ID ); 
  890. $date_modified = apply_filters( 'nf_edit_sub_date_modified', date( 'M j, Y @ h:i', strtotime( $post->post_modified ) ), $post->ID ); 
  891.  
  892. if ( $post->post_author != 0 ) { 
  893. $user_data = get_userdata( $post->post_author ); 
  894.  
  895. $first_name = $user_data->first_name; 
  896. $last_name = $user_data->last_name; 
  897.  
  898. if ( $first_name != '' && $last_name != '' ) { 
  899. $name = $first_name . ' ' . $last_name; 
  900. } else if ( $user_data->display_name != '' ) { 
  901. $name = $user_data->display_name; 
  902. } else { 
  903. $name = $user_data->user_login; 
  904.  
  905. $name = apply_filters( 'nf_edit_sub_username', $name, $post->post_author ); 
  906.  
  907. $form_id = Ninja_Forms()->sub( $post->ID )->form_id; 
  908. $form_title = Ninja_Forms()->form( $form_id )->get_setting( 'form_title' ); 
  909. ?> 
  910. <input type="hidden" name="nf_edit_sub" value="1"> 
  911. <div class="submitbox" id="submitpost"> 
  912. <div id="minor-publishing"> 
  913. <div id="misc-publishing-actions"> 
  914. <div class="misc-pub-section misc-pub-post-status"> 
  915. <label for="post_status"><?php _e( '#', 'ninja-forms' ); ?>:</label> 
  916. <span id="sub-seq-num-display"><?php echo Ninja_Forms()->sub( $post->ID )->get_seq_num(); ?></span> 
  917. </div> 
  918. <div class="misc-pub-section misc-pub-post-status"> 
  919. <label for="post_status"><?php _e( 'Status', 'ninja-forms' ); ?>:</label> 
  920. <span id="sub-status-display"><?php echo apply_filters( 'nf_sub_edit_status', __( 'Submitted', 'ninja-forms' ), $post->ID ); ?></span> 
  921. <?php do_action( 'nf_sub_edit_after_status', $post ); ?> 
  922. </div> 
  923. <div class="misc-pub-section misc-pub-post-status"> 
  924. <label for="post_status"><?php _e( 'Form', 'ninja-forms' ); ?>:</label> 
  925. <span id="sub-form-title-display"><?php echo $form_title; ?></span> 
  926. </div> 
  927. <div class="misc-pub-section curtime misc-pub-curtime"> 
  928. <span id="timestamp"> 
  929. <?php _e( 'Submitted on', 'ninja-forms' ); ?>: <b><?php echo $date_submitted; ?></b> 
  930. </span> 
  931. <?php do_action( 'nf_sub_edit_date_submitted', $post ); ?> 
  932. </div> 
  933. <div class="misc-pub-section curtime misc-pub-curtime"> 
  934. <span id="timestamp"> 
  935. <?php _e( 'Modified on', 'ninja-forms', $post ); ?>: <b><?php echo $date_modified; ?></b> 
  936. </span> 
  937. <?php do_action( 'nf_sub_edit_date_modified', $post ); ?> 
  938. </div> 
  939. <?php 
  940. if ( $post->post_author != 0 ) { 
  941. ?> 
  942. <div class="misc-pub-section misc-pub-visibility" id="visibility"> 
  943. <?php _e( 'Submitted By', 'ninja-forms' ); ?>: <span id="post-visibility-display"><?php echo $name; ?></span> 
  944. </div> 
  945. <?php 
  946. ?> 
  947. </div> 
  948. </div> 
  949. <div id="major-publishing-actions"> 
  950. <div id="delete-action"> 
  951.  
  952. <!-- <a class="submitdelete deletion" href="<?php echo get_delete_post_link( $post->ID ); ?>">Move to Trash</a>--></div> 
  953.  
  954. <div id="publishing-action"> 
  955. <span class="spinner"></span> 
  956. <input name="original_publish" type="hidden" id="original_publish" value="<?php _e( 'Update', 'ninja-forms' ); ?>"> 
  957. <input name="save" type="submit" class="button button-primary button-large" id="publish" accesskey="p" value="<?php _e( 'Update', 'ninja-forms' ); ?>"> 
  958. </div> 
  959. <div class="clear"></div> 
  960. </div> 
  961. </div> 
  962. <?php 
  963.  
  964. /** 
  965. * Save our submission user values 
  966. * 
  967. * @access public 
  968. * @since 2.7 
  969. * @return void 
  970. */ 
  971. public function save_sub( $sub_id, $post ) { 
  972. global $pagenow; 
  973.  
  974. if ( ! isset ( $_POST['nf_edit_sub'] ) || $_POST['nf_edit_sub'] != 1 ) 
  975. return $sub_id; 
  976.  
  977. // verify if this is an auto save routine. 
  978. // If it is our form has not been submitted, so we dont want to do anything 
  979. if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) 
  980. return $sub_id; 
  981.  
  982. if ( $pagenow != 'post.php' ) 
  983. return $sub_id; 
  984.  
  985. if ( $post->post_type != 'nf_sub' ) 
  986. return $sub_id; 
  987.  
  988. /** Get the post type object. */ 
  989. $post_type = get_post_type_object( $post->post_type ); 
  990.  
  991. /** Check if the current user has permission to edit the post. */ 
  992. if ( !current_user_can( $post_type->cap->edit_post, $sub_id ) ) 
  993. return $sub_id; 
  994.  
  995. foreach ( $_POST['fields'] as $field_id => $user_value ) { 
  996. $user_value = nf_wp_kses_post_deep( apply_filters( 'nf_edit_sub_user_value', $user_value, $field_id, $sub_id ) ); 
  997. Ninja_Forms()->sub( $sub_id )->update_field( $field_id, $user_value ); 
  998.  
  999. set_transient( 'nf_sub_edit_ref', esc_url_raw( $_REQUEST['ref'] ) ); 
  1000.  
  1001. /** 
  1002. * Filter our hidden columns so that they are handled on a per-form basis. 
  1003. * 
  1004. * @access public 
  1005. * @since 2.7 
  1006. * @return void 
  1007. */ 
  1008. public function filter_hidden_columns() { 
  1009. global $pagenow; 
  1010. // Bail if we aren't on the edit.php page, we aren't editing our custom post type, or we don't have a form_id set. 
  1011. if ( $pagenow != 'edit.php' || ! isset ( $_REQUEST['post_type'] ) || $_REQUEST['post_type'] != 'nf_sub' || ! isset ( $_REQUEST['form_id'] ) ) 
  1012. return false; 
  1013.  
  1014. // Grab our current user. 
  1015. $user = wp_get_current_user(); 
  1016. // Grab our form id. 
  1017. $form_id = absint( $_REQUEST['form_id'] ); 
  1018. // Get the columns that should be hidden for this form ID. 
  1019. $hidden_columns = get_user_option( 'manageedit-nf_subcolumnshidden-form-' . $form_id ); 
  1020.  
  1021. if ( $hidden_columns === false ) { 
  1022. // If we don't have custom hidden columns set up for this form, then only show the first five columns. 
  1023. // Get our column headers 
  1024. $columns = get_column_headers( 'edit-nf_sub' ); 
  1025. $hidden_columns = array(); 
  1026. $x = 0; 
  1027. foreach ( $columns as $slug => $name ) { 
  1028. if ( $x > 5 ) { 
  1029. if ( $slug != 'sub_date' ) 
  1030. $hidden_columns[] = $slug; 
  1031. $x++; 
  1032. update_user_option( $user->ID, 'manageedit-nf_subcolumnshidden', $hidden_columns, true ); 
  1033.  
  1034. /** 
  1035. * Save our hidden columns per form id. 
  1036. * 
  1037. * @access public 
  1038. * @since 2.7 
  1039. * @return void 
  1040. */ 
  1041. public function hide_columns() { 
  1042. // Grab our current user. 
  1043. $user = wp_get_current_user(); 
  1044. // Grab our form id. 
  1045. $form_id = absint( $_REQUEST['form_id'] ); 
  1046. $hidden = isset( $_POST['hidden'] ) ? explode( ', ', esc_html( $_POST['hidden'] ) ) : array(); 
  1047. $hidden = array_filter( $hidden ); 
  1048. update_user_option( $user->ID, 'manageedit-nf_subcolumnshidden-form-' . $form_id, $hidden, true ); 
  1049. die(); 
  1050.  
  1051. /** 
  1052. * Add custom screen options 
  1053. * 
  1054. * @access public 
  1055. * @since 2.7 
  1056. * @return void 
  1057. */ 
  1058. public function output_screen_options( $status, $args ) { 
  1059. if ( $args->base == 'edit' && $args->post_type == 'nf_sub' ) { 
  1060. $status .= '<span id="nf-subs-screen-options">' . $this->screen_options . '</span>'; 
  1061. return $status; 
  1062.  
  1063. /** 
  1064. * Listen for exporting subs 
  1065. * 
  1066. * @access public 
  1067. * @since 2.7.3 
  1068. * @return void 
  1069. */ 
  1070. public function export_listen() { 
  1071. // Bail if we aren't in the admin 
  1072. if ( ! is_admin() ) 
  1073. return false; 
  1074.  
  1075. if ( ! isset ( $_REQUEST['form_id'] ) || empty ( $_REQUEST['form_id'] ) ) 
  1076. return false; 
  1077.  
  1078. if ( isset ( $_REQUEST['export_single'] ) && ! empty( $_REQUEST['export_single'] ) ) 
  1079. Ninja_Forms()->sub( esc_html( $_REQUEST['export_single'] ) )->export(); 
  1080.  
  1081. if ( ( isset ( $_REQUEST['action'] ) && $_REQUEST['action'] == 'export' ) || ( isset ( $_REQUEST['action2'] ) && $_REQUEST['action2'] == 'export' ) ) { 
  1082. Ninja_Forms()->subs()->export( ninja_forms_esc_html_deep( $_REQUEST['post'] ) ); 
  1083.  
  1084. if ( isset ( $_REQUEST['download_file'] ) && ! empty( $_REQUEST['download_file'] ) ) { 
  1085. // Open our download all file 
  1086. $filename = esc_html( $_REQUEST['download_file'] ); 
  1087.  
  1088. $upload_dir = wp_upload_dir(); 
  1089.  
  1090. $file_path = trailingslashit( $upload_dir['path'] ) . $filename . '.csv'; 
  1091.  
  1092. if ( file_exists( $file_path ) ) { 
  1093. $myfile = file_get_contents ( $file_path ); 
  1094. } else { 
  1095. $redirect = esc_url_raw( remove_query_arg( array( 'download_file', 'download_all' ) ) ); 
  1096. wp_redirect( $redirect ); 
  1097. die(); 
  1098.  
  1099. unlink( $file_path ); 
  1100.  
  1101. $form_name = Ninja_Forms()->form( absint( $_REQUEST['form_id'] ) )->get_setting( 'form_title' ); 
  1102. $form_name = sanitize_title( $form_name ); 
  1103.  
  1104. $today = date( 'Y-m-d', current_time( 'timestamp' ) ); 
  1105.  
  1106. $filename = apply_filters( 'nf_download_all_filename', $form_name . '-all-subs-' . $today ); 
  1107.  
  1108. header( 'Content-type: application/csv'); 
  1109. header( 'Content-Disposition: attachment; filename="'.$filename .'.csv"' ); 
  1110. header( 'Pragma: no-cache'); 
  1111. header( 'Expires: 0' ); 
  1112.  
  1113. echo $myfile; 
  1114.  
  1115. die(); 
  1116.  
  1117. /** 
  1118. * Filter user capabilities 
  1119. * 
  1120. * @access public 
  1121. * @since 2.7.7 
  1122. * @return void 
  1123. */ 
  1124. public function cap_filter( $allcaps, $cap, $args ) { 
  1125.  
  1126. $sub_cap = apply_filters( 'ninja_forms_admin_submissions_capabilities', 'manage_options' ); 
  1127.  
  1128. if ( ! empty( $allcaps[ $sub_cap ] ) ) { 
  1129. $allcaps['nf_sub'] = true; 
  1130.  
  1131. return $allcaps; 
  1132.  
.