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