3 if ( ! class_exists( 'WP_List_Table' ) )
4 require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
6 class WPCF7_Contact_Form_List_Table extends WP_List_Table {
8 public static function define_columns() {
10 'cb' => '<input type="checkbox" />',
11 'title' => __( 'Title', 'contact-form-7' ),
12 'shortcode' => __( 'Shortcode', 'contact-form-7' ),
13 'author' => __( 'Author', 'contact-form-7' ),
14 'date' => __( 'Date', 'contact-form-7' ) );
19 function __construct() {
20 parent::__construct( array(
26 function prepare_items() {
27 $current_screen = get_current_screen();
28 $per_page = $this->get_items_per_page( 'cfseven_contact_forms_per_page' );
30 $this->_column_headers = $this->get_column_info();
33 'posts_per_page' => $per_page,
36 'offset' => ( $this->get_pagenum() - 1 ) * $per_page );
38 if ( ! empty( $_REQUEST['s'] ) )
39 $args['s'] = $_REQUEST['s'];
41 if ( ! empty( $_REQUEST['orderby'] ) ) {
42 if ( 'title' == $_REQUEST['orderby'] )
43 $args['orderby'] = 'title';
44 elseif ( 'author' == $_REQUEST['orderby'] )
45 $args['orderby'] = 'author';
46 elseif ( 'date' == $_REQUEST['orderby'] )
47 $args['orderby'] = 'date';
50 if ( ! empty( $_REQUEST['order'] ) ) {
51 if ( 'asc' == strtolower( $_REQUEST['order'] ) )
52 $args['order'] = 'ASC';
53 elseif ( 'desc' == strtolower( $_REQUEST['order'] ) )
54 $args['order'] = 'DESC';
57 $this->items = WPCF7_ContactForm::find( $args );
59 $total_items = WPCF7_ContactForm::count();
60 $total_pages = ceil( $total_items / $per_page );
62 $this->set_pagination_args( array(
63 'total_items' => $total_items,
64 'total_pages' => $total_pages,
65 'per_page' => $per_page ) );
68 function get_columns() {
69 return get_column_headers( get_current_screen() );
72 function get_sortable_columns() {
74 'title' => array( 'title', true ),
75 'author' => array( 'author', false ),
76 'date' => array( 'date', false ) );
81 function get_bulk_actions() {
83 'delete' => __( 'Delete', 'contact-form-7' ) );
88 function column_default( $item, $column_name ) {
92 function column_cb( $item ) {
94 '<input type="checkbox" name="%1$s[]" value="%2$s" />',
95 $this->_args['singular'],
99 function column_title( $item ) {
100 $url = admin_url( 'admin.php?page=wpcf7&post=' . absint( $item->id() ) );
101 $edit_link = add_query_arg( array( 'action' => 'edit' ), $url );
104 'edit' => sprintf( '<a href="%1$s">%2$s</a>',
105 esc_url( $edit_link ),
106 esc_html( __( 'Edit', 'contact-form-7' ) ) ) );
108 if ( current_user_can( 'wpcf7_edit_contact_form', $item->id() ) ) {
109 $copy_link = wp_nonce_url(
110 add_query_arg( array( 'action' => 'copy' ), $url ),
111 'wpcf7-copy-contact-form_' . absint( $item->id() ) );
113 $actions = array_merge( $actions, array(
114 'copy' => sprintf( '<a href="%1$s">%2$s</a>',
115 esc_url( $copy_link ),
116 esc_html( __( 'Duplicate', 'contact-form-7' ) ) ) ) );
119 $a = sprintf( '<a class="row-title" href="%1$s" title="%2$s">%3$s</a>',
120 esc_url( $edit_link ),
121 esc_attr( sprintf( __( 'Edit “%s”', 'contact-form-7' ),
123 esc_html( $item->title() ) );
125 return '<strong>' . $a . '</strong> ' . $this->row_actions( $actions );
128 function column_author( $item ) {
129 $post = get_post( $item->id() );
134 $author = get_userdata( $post->post_author );
136 return esc_html( $author->display_name );
139 function column_shortcode( $item ) {
140 $shortcodes = array( $item->shortcode() );
144 foreach ( $shortcodes as $shortcode ) {
145 $output .= "\n" . '<span class="shortcode"><input type="text"'
146 . ' onfocus="this.select();" readonly="readonly"'
147 . ' value="' . esc_attr( $shortcode ) . '"'
148 . ' class="large-text code" /></span>';
151 return trim( $output );
154 function column_date( $item ) {
155 $post = get_post( $item->id() );
160 $t_time = mysql2date( __( 'Y/m/d g:i:s A', 'contact-form-7' ), $post->post_date, true );
161 $m_time = $post->post_date;
162 $time = mysql2date( 'G', $post->post_date ) - get_option( 'gmt_offset' ) * 3600;
164 $time_diff = time() - $time;
166 if ( $time_diff > 0 && $time_diff < 24*60*60 )
167 $h_time = sprintf( __( '%s ago', 'contact-form-7' ), human_time_diff( $time ) );
169 $h_time = mysql2date( __( 'Y/m/d', 'contact-form-7' ), $m_time );
171 return '<abbr title="' . $t_time . '">' . $h_time . '</abbr>';