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' => '<a href="' . $edit_link . '">' . __( 'Edit', 'contact-form-7' ) . '</a>' );
106 if ( current_user_can( 'wpcf7_edit_contact_form', $item->id() ) ) {
107 $copy_link = wp_nonce_url(
108 add_query_arg( array( 'action' => 'copy' ), $url ),
109 'wpcf7-copy-contact-form_' . absint( $item->id() ) );
111 $actions = array_merge( $actions, array(
112 'copy' => '<a href="' . $copy_link . '">' . __( 'Copy', 'contact-form-7' ) . '</a>' ) );
115 $a = sprintf( '<a class="row-title" href="%1$s" title="%2$s">%3$s</a>',
117 esc_attr( sprintf( __( 'Edit “%s”', 'contact-form-7' ),
119 esc_html( $item->title() ) );
121 return '<strong>' . $a . '</strong> ' . $this->row_actions( $actions );
124 function column_author( $item ) {
125 $post = get_post( $item->id() );
130 $author = get_userdata( $post->post_author );
132 return esc_html( $author->display_name );
135 function column_shortcode( $item ) {
137 sprintf( '[contact-form-7 id="%1$d" title="%2$s"]',
138 $item->id(), $item->title() ) );
142 foreach ( $shortcodes as $shortcode ) {
143 $output .= "\n" . '<input type="text"'
144 . ' onfocus="this.select();" readonly="readonly"'
145 . ' value="' . esc_attr( $shortcode ) . '"'
146 . ' class="shortcode-in-list-table wp-ui-text-highlight code" />';
149 return trim( $output );
152 function column_date( $item ) {
153 $post = get_post( $item->id() );
158 $t_time = mysql2date( __( 'Y/m/d g:i:s A', 'contact-form-7' ), $post->post_date, true );
159 $m_time = $post->post_date;
160 $time = mysql2date( 'G', $post->post_date ) - get_option( 'gmt_offset' ) * 3600;
162 $time_diff = time() - $time;
164 if ( $time_diff > 0 && $time_diff < 24*60*60 )
165 $h_time = sprintf( __( '%s ago', 'contact-form-7' ), human_time_diff( $time ) );
167 $h_time = mysql2date( __( 'Y/m/d', 'contact-form-7' ), $m_time );
169 return '<abbr title="' . $t_time . '">' . $h_time . '</abbr>';