NF_Subs_CPT

Submission CPT.

Defined (1)

The class is defined in the following location(s).

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