WPCF7_Contact_Form_List_Table

The Contact Form 7 WPCF7 Contact Form List Table class.

Defined (1)

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

/admin/includes/class-contact-forms-list-table.php  
  1. class WPCF7_Contact_Form_List_Table extends WP_List_Table { 
  2.  
  3. public static function define_columns() { 
  4. $columns = array( 
  5. 'cb' => '<input type="checkbox" />',  
  6. 'title' => __( 'Title', 'contact-form-7' ),  
  7. 'shortcode' => __( 'Shortcode', 'contact-form-7' ),  
  8. 'author' => __( 'Author', 'contact-form-7' ),  
  9. 'date' => __( 'Date', 'contact-form-7' ),  
  10. ); 
  11.  
  12. return $columns; 
  13.  
  14. function __construct() { 
  15. parent::__construct( array( 
  16. 'singular' => 'post',  
  17. 'plural' => 'posts',  
  18. 'ajax' => false,  
  19. ) ); 
  20.  
  21. function prepare_items() { 
  22. $current_screen = get_current_screen(); 
  23. $per_page = $this->get_items_per_page( 'cfseven_contact_forms_per_page' ); 
  24.  
  25. $this->_column_headers = $this->get_column_info(); 
  26.  
  27. $args = array( 
  28. 'posts_per_page' => $per_page,  
  29. 'orderby' => 'title',  
  30. 'order' => 'ASC',  
  31. 'offset' => ( $this->get_pagenum() - 1 ) * $per_page,  
  32. ); 
  33.  
  34. if ( ! empty( $_REQUEST['s'] ) ) { 
  35. $args['s'] = $_REQUEST['s']; 
  36.  
  37. if ( ! empty( $_REQUEST['orderby'] ) ) { 
  38. if ( 'title' == $_REQUEST['orderby'] ) { 
  39. $args['orderby'] = 'title'; 
  40. } elseif ( 'author' == $_REQUEST['orderby'] ) { 
  41. $args['orderby'] = 'author'; 
  42. } elseif ( 'date' == $_REQUEST['orderby'] ) { 
  43. $args['orderby'] = 'date'; 
  44.  
  45. if ( ! empty( $_REQUEST['order'] ) ) { 
  46. if ( 'asc' == strtolower( $_REQUEST['order'] ) ) { 
  47. $args['order'] = 'ASC'; 
  48. } elseif ( 'desc' == strtolower( $_REQUEST['order'] ) ) { 
  49. $args['order'] = 'DESC'; 
  50.  
  51. $this->items = WPCF7_ContactForm::find( $args ); 
  52.  
  53. $total_items = WPCF7_ContactForm::count(); 
  54. $total_pages = ceil( $total_items / $per_page ); 
  55.  
  56. $this->set_pagination_args( array( 
  57. 'total_items' => $total_items,  
  58. 'total_pages' => $total_pages,  
  59. 'per_page' => $per_page,  
  60. ) ); 
  61.  
  62. function get_columns() { 
  63. return get_column_headers( get_current_screen() ); 
  64.  
  65. function get_sortable_columns() { 
  66. $columns = array( 
  67. 'title' => array( 'title', true ),  
  68. 'author' => array( 'author', false ),  
  69. 'date' => array( 'date', false ),  
  70. ); 
  71.  
  72. return $columns; 
  73.  
  74. function get_bulk_actions() { 
  75. $actions = array( 
  76. 'delete' => __( 'Delete', 'contact-form-7' ),  
  77. ); 
  78.  
  79. return $actions; 
  80.  
  81. function column_default( $item, $column_name ) { 
  82. return ''; 
  83.  
  84. function column_cb( $item ) { 
  85. return sprintf( 
  86. '<input type="checkbox" name="%1$s[]" value="%2$s" />',  
  87. $this->_args['singular'],  
  88. $item->id() ); 
  89.  
  90. function column_title( $item ) { 
  91. $url = admin_url( 'admin.php?page=wpcf7&post=' . absint( $item->id() ) ); 
  92. $edit_link = add_query_arg( array( 'action' => 'edit' ), $url ); 
  93.  
  94. $output = sprintf( 
  95. '<a class="row-title" href="%1$s" title="%2$s">%3$s</a>',  
  96. esc_url( $edit_link ),  
  97. esc_attr( sprintf( __( 'Edit “%s”', 'contact-form-7' ),  
  98. $item->title() ) ),  
  99. esc_html( $item->title() ) 
  100. ); 
  101.  
  102. $output = sprintf( '<strong>%s</strong>', $output ); 
  103.  
  104. if ( wpcf7_validate_configuration() 
  105. && current_user_can( 'wpcf7_edit_contact_form', $item->id() ) ) { 
  106. $config_validator = new WPCF7_ConfigValidator( $item ); 
  107. $config_validator->restore(); 
  108.  
  109. if ( $count_errors = $config_validator->count_errors() ) { 
  110. $error_notice = sprintf( 
  111. _n( 
  112. '%s configuration error detected',  
  113. '%s configuration errors detected',  
  114. $count_errors, 'contact-form-7' ),  
  115. number_format_i18n( $count_errors ) ); 
  116. $output .= sprintf( 
  117. '<div class="config-error"><span class="dashicons dashicons-warning"></span> %s</div>',  
  118. $error_notice ); 
  119.  
  120. $actions = array( 
  121. 'edit' => sprintf( '<a href="%1$s">%2$s</a>',  
  122. esc_url( $edit_link ),  
  123. esc_html( __( 'Edit', 'contact-form-7' ) ) ) ); 
  124.  
  125. if ( current_user_can( 'wpcf7_edit_contact_form', $item->id() ) ) { 
  126. $copy_link = wp_nonce_url( 
  127. add_query_arg( array( 'action' => 'copy' ), $url ),  
  128. 'wpcf7-copy-contact-form_' . absint( $item->id() ) ); 
  129.  
  130. $actions = array_merge( $actions, array( 
  131. 'copy' => sprintf( '<a href="%1$s">%2$s</a>',  
  132. esc_url( $copy_link ),  
  133. esc_html( __( 'Duplicate', 'contact-form-7' ) ) 
  134. ),  
  135. ) ); 
  136.  
  137. $output .= $this->row_actions( $actions ); 
  138.  
  139. return $output; 
  140.  
  141. function column_author( $item ) { 
  142. $post = get_post( $item->id() ); 
  143.  
  144. if ( ! $post ) { 
  145. return; 
  146.  
  147. $author = get_userdata( $post->post_author ); 
  148.  
  149. if ( false === $author ) { 
  150. return; 
  151.  
  152. return esc_html( $author->display_name ); 
  153.  
  154. function column_shortcode( $item ) { 
  155. $shortcodes = array( $item->shortcode() ); 
  156.  
  157. $output = ''; 
  158.  
  159. foreach ( $shortcodes as $shortcode ) { 
  160. $output .= "\n" . '<span class="shortcode"><input type="text"' 
  161. . ' onfocus="this.select();" readonly="readonly"' 
  162. . ' value="' . esc_attr( $shortcode ) . '"' 
  163. . ' class="large-text code" /></span>'; 
  164.  
  165. return trim( $output ); 
  166.  
  167. function column_date( $item ) { 
  168. $post = get_post( $item->id() ); 
  169.  
  170. if ( ! $post ) { 
  171. return; 
  172.  
  173. $t_time = mysql2date( __( 'Y/m/d g:i:s A', 'contact-form-7' ),  
  174. $post->post_date, true ); 
  175. $m_time = $post->post_date; 
  176. $time = mysql2date( 'G', $post->post_date ) 
  177. - get_option( 'gmt_offset' ) * 3600; 
  178.  
  179. $time_diff = time() - $time; 
  180.  
  181. if ( $time_diff > 0 && $time_diff < 24*60*60 ) { 
  182. $h_time = sprintf( 
  183. __( '%s ago', 'contact-form-7' ), human_time_diff( $time ) ); 
  184. } else { 
  185. $h_time = mysql2date( __( 'Y/m/d', 'contact-form-7' ), $m_time ); 
  186.  
  187. return '<abbr title="' . $t_time . '">' . $h_time . '</abbr>';