PluginProbe ʕ •ᴥ•ʔ
Admin Columns / 3.1.3
Admin Columns v3.1.3
7.0.19 2.3.5 2.4 2.4.1 2.4.10 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.6.1 2.5.6.2 2.5.6.3 2.5.6.4 3.0 3.0.1 3.0.2 3.0.3 3.0.5 3.0.7 3.1 3.1.1 3.1.10 3.1.2 3.1.3 3.1.5 3.2.3 3.2.7 3.3.1 3.4.1 3.4.6 3.4.8 4.0.1 4.0.3 4.1.6 4.2.2 4.2.5 4.3 4.3.2 4.4.1 4.4.4 4.4.5 4.5.5 4.6.1 4.7.18 4.7.19 4.7.20 4.7.7 7.0.13 7.0.14 7.0.16 trunk 1.0 1.1 1.1.3 1.2 1.2.1 1.3 1.3.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.5.1 1.4.6 1.4.6.1 1.4.6.2 1.4.6.3 1.4.6.4 1.4.7 1.4.8 1.4.9 2.0.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.2 2.2.1 2.2.1.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.5.1 2.2.6 2.2.6.1 2.2.6.2 2.2.6.3 2.2.6.4 2.2.7 2.2.8 2.2.8.1 2.2.9 2.3.1 2.3.2 2.3.3
codepress-admin-columns / classes / TableScreen.php
codepress-admin-columns / classes Last commit date
Admin 8 years ago Column 8 years ago Form 8 years ago Helper 8 years ago ListScreen 8 years ago Meta 8 years ago Notice 8 years ago Plugin 8 years ago Relation 8 years ago Settings 8 years ago ThirdParty 8 years ago API.php 8 years ago Addon.php 8 years ago Admin.php 8 years ago Autoloader.php 8 years ago Collection.php 8 years ago Column.php 8 years ago Groups.php 8 years ago Helper.php 8 years ago ListScreen.php 8 years ago ListScreenPost.php 8 years ago ListScreenWP.php 8 years ago Plugin.php 8 years ago PluginInformation.php 8 years ago Preferences.php 8 years ago Relation.php 8 years ago TableScreen.php 8 years ago View.php 8 years ago ViewInterface.php 8 years ago
TableScreen.php
472 lines
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit;
5 }
6
7 final class AC_TableScreen {
8
9 /**
10 * @var array $column_headings
11 */
12 private $column_headings = array();
13
14 /**
15 * @var AC_ListScreen $list_screen
16 */
17 private $current_list_screen;
18
19 public function __construct() {
20 add_action( 'current_screen', array( $this, 'load_list_screen' ) );
21 add_action( 'admin_init', array( $this, 'load_list_screen_doing_quick_edit' ) );
22 add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
23 add_action( 'admin_footer', array( $this, 'admin_footer_scripts' ) );
24 add_filter( 'admin_body_class', array( $this, 'admin_class' ) );
25 add_filter( 'list_table_primary_column', array( $this, 'set_primary_column' ), 20 );
26 add_action( 'wp_ajax_ac_get_column_value', array( $this, 'ajax_get_column_value' ) );
27 }
28
29 /**
30 * Get column value by ajax.
31 */
32 public function ajax_get_column_value() {
33 check_ajax_referer( 'ac-ajax' );
34
35 // Get ID of entry to edit
36 $id = intval( filter_input( INPUT_POST, 'pk' ) );
37
38 if ( ! $id ) {
39 $this->ajax_error( __( 'Invalid item ID.', 'codepress-admin-columns' ) );
40 }
41
42 $list_screen = AC()->get_list_screen( filter_input( INPUT_POST, 'list_screen' ) );
43
44 if ( ! $list_screen ) {
45 $this->ajax_error( __( 'Invalid list screen.', 'codepress-admin-columns' ) );
46 }
47
48 $list_screen->set_layout_id( filter_input( INPUT_POST, 'layout' ) );
49
50 $column = $list_screen->get_column_by_name( filter_input( INPUT_POST, 'column' ) );
51
52 if ( ! $column ) {
53 $this->ajax_error( __( 'Invalid column.', 'codepress-admin-columns' ) );
54 }
55
56 if ( ! $column instanceof AC_Column_AjaxValue ) {
57 $this->ajax_error( __( 'Invalid method.', 'codepress-admin-columns' ) );
58 }
59
60 // Trigger ajax callback
61 echo $column->get_ajax_value( $id );
62 exit;
63 }
64
65 private function ajax_error( $message ) {
66 wp_die( $message, null, 400 );
67 }
68
69 /**
70 * Set the primary columns for the Admin Columns columns. Used to place the actions bar.
71 *
72 * @since 2.5.5
73 */
74 public function set_primary_column( $default ) {
75 if ( $this->current_list_screen ) {
76
77 if ( ! $this->current_list_screen->get_column_by_name( $default ) ) {
78 $default = key( $this->current_list_screen->get_columns() );
79 }
80
81 // If actions column is present, set it as primary
82 foreach ( $this->current_list_screen->get_columns() as $column ) {
83 if ( 'column-actions' == $column->get_type() ) {
84 $default = $column->get_name();
85
86 if ( $this->current_list_screen instanceof AC_ListScreen_Media ) {
87
88 // Add download button to the actions column
89 add_filter( 'media_row_actions', array( $this, 'set_media_row_actions' ), 10, 2 );
90 }
91 }
92 };
93
94 // Set inline edit data if the default column (title) is not present
95 if ( $this->current_list_screen instanceof AC_ListScreen_Post && 'title' !== $default ) {
96 add_filter( 'page_row_actions', array( $this, 'set_inline_edit_data' ), 20, 2 );
97 add_filter( 'post_row_actions', array( $this, 'set_inline_edit_data' ), 20, 2 );
98 }
99
100 // Remove inline edit action if the default column (author) is not present
101 if ( $this->current_list_screen instanceof AC_ListScreen_Comment && 'comment' !== $default ) {
102 add_filter( 'comment_row_actions', array( $this, 'remove_quick_edit_from_actions' ), 20, 2 );
103 }
104
105 // Adds the default hidden bulk edit markup for the new primary column
106 if ( $this->current_list_screen instanceof ACP_ListScreen_Taxonomy && 'name' !== $default ) {
107 add_filter( 'tag_row_actions', array( $this, 'add_taxonomy_hidden_quick_edit_markup' ), 20, 2 );
108 }
109 }
110
111 return $default;
112 }
113
114 /**
115 * Add a download link to the table screen
116 *
117 * @param array $actions
118 * @param WP_Post $post
119 */
120 public function set_media_row_actions( $actions, $post ) {
121 $link_attributes = array(
122 'download' => '',
123 'title' => __( 'Download', 'codepress-admin-columns' ),
124 );
125 $actions['download'] = ac_helper()->html->link( wp_get_attachment_url( $post->ID ), __( 'Download', 'codepress-admin-columns' ), $link_attributes );
126
127 return $actions;
128 }
129
130 /**
131 * Sets the inline data when the title columns is not present on a AC_ListScreen_Post screen
132 *
133 * @param array $actions
134 * @param WP_Post $post
135 */
136 public function set_inline_edit_data( $actions, $post ) {
137 get_inline_data( $post );
138
139 return $actions;
140 }
141
142 /**
143 * Remove quick edit from actions
144 *
145 * @param array $actions
146 */
147 public function remove_quick_edit_from_actions( $actions ) {
148 unset( $actions['quickedit'] );
149
150 return $actions;
151 }
152
153 /**
154 * Add the default markup for the default primary column for the Taxonomy list screen which is necessary for bulk edit
155 *
156 * @param $actions
157 * @param $term
158 */
159 public function add_taxonomy_hidden_quick_edit_markup( $actions, $term ) {
160 $list_screen = $this->get_current_list_screen();
161
162 if ( $list_screen instanceof ACP_ListScreen_Taxonomy ) {
163 echo sprintf( '<div class="hidden">%s</div>', $list_screen->get_list_table()->column_name( $term ) );
164 }
165
166 return $actions;
167 }
168
169 /**
170 * Adds a body class which is used to set individual column widths
171 *
172 * @since 1.4.0
173 *
174 * @param string $classes body classes
175 *
176 * @return string
177 */
178 public function admin_class( $classes ) {
179 if ( ! $this->current_list_screen ) {
180 return $classes;
181 }
182
183 $classes .= " ac-" . $this->current_list_screen->get_key();
184
185 return apply_filters( 'ac/table/body_class', $classes, $this );
186 }
187
188 /**
189 * @since 2.2.4
190 *
191 * @param AC_ListScreen $list_screen
192 */
193 public function admin_scripts() {
194 if ( ! $this->current_list_screen ) {
195 return;
196 }
197
198 $list_screen = $this->current_list_screen;
199
200 // Tooltip
201 wp_register_script( 'jquery-qtip2', AC()->get_plugin_url() . "external/qtip2/jquery.qtip" . AC()->minified() . ".js", array( 'jquery' ), AC()->get_version() );
202 wp_enqueue_style( 'jquery-qtip2', AC()->get_plugin_url() . "external/qtip2/jquery.qtip" . AC()->minified() . ".css", array(), AC()->get_version() );
203
204 // Main
205 wp_enqueue_script( 'ac-table', AC()->get_plugin_url() . "assets/js/table" . AC()->minified() . ".js", array( 'jquery', 'jquery-qtip2' ), AC()->get_version() );
206 wp_enqueue_style( 'ac-table', AC()->get_plugin_url() . "assets/css/table" . AC()->minified() . ".css", array(), AC()->get_version() );
207
208 wp_localize_script( 'ac-table', 'AC', array(
209 'list_screen' => $list_screen->get_key(),
210 'layout' => $list_screen->get_layout_id(),
211 'column_types' => $this->get_column_types_mapping( $list_screen ),
212 'ajax_nonce' => wp_create_nonce( 'ac-ajax' ),
213 'table_id' => $list_screen->get_table_attr_id(),
214 'edit_link' => $this->get_edit_link( $list_screen ),
215 'screen' => $this->get_current_screen_id(),
216 'i18n' => array(
217 'edit_columns' => esc_html( __( 'Edit columns', 'codepress-admin-columns' ) ),
218 ),
219 )
220 );
221
222 /**
223 * @param AC_ListScreen $list_screen
224 */
225 do_action( 'ac/table_scripts', $list_screen );
226
227 // Column specific scripts
228 foreach ( $list_screen->get_columns() as $column ) {
229 $column->scripts();
230 }
231 }
232
233 /**
234 * @return false|string
235 */
236 private function get_current_screen_id() {
237 $screen = get_current_screen();
238
239 if ( ! $screen ) {
240 return false;
241 }
242
243 return $screen->id;
244 }
245
246 /**
247 * @param AC_ListScreen $list_screen
248 *
249 * @return array
250 */
251 private function get_column_types_mapping( AC_ListScreen $list_screen ) {
252 $types = array();
253 foreach ( $list_screen->get_columns() as $column ) {
254 $types[ $column->get_name() ] = $column->get_type();
255 }
256
257 return $types;
258 }
259
260 public function get_current_list_screen() {
261 return $this->current_list_screen;
262 }
263
264 /**
265 * Applies the width setting to the table headers
266 */
267 private function display_width_styles() {
268 if ( $this->current_list_screen->get_settings() ) {
269
270 // CSS: columns width
271 $css_column_width = false;
272
273 foreach ( $this->current_list_screen->get_columns() as $column ) {
274
275 /* @var AC_Settings_Column_Width $setting */
276 $setting = $column->get_setting( 'width' );
277
278 if ( $width = $setting->get_display_width() ) {
279 $css_column_width .= ".ac-" . $this->current_list_screen->get_key() . " .wrap table th.column-" . $column->get_name() . " { width: " . $width . " !important; }";
280 $css_column_width .= "body.acp-overflow-table.ac-" . $this->current_list_screen->get_key() . " .wrap th.column-" . $column->get_name() . " { min-width: " . $width . " !important; }";
281 }
282 }
283
284 if ( $css_column_width ) : ?>
285 <style>
286 @media screen and (min-width: 783px) {
287 <?php echo $css_column_width; ?>
288 }
289 </style>
290 <?php
291 endif;
292 }
293 }
294
295 /**
296 * @param AC_ListScreen $list_screen
297 *
298 * @return string|false
299 */
300 private function get_edit_link( AC_ListScreen $list_screen ) {
301 if ( ! AC()->user_can_manage_admin_columns() ) {
302 return false;
303 }
304
305 /* @var AC_Admin_Page_Settings $settings */
306 $settings = AC()->admin()->get_page( 'settings' );
307
308 if ( ! $settings->show_edit_button() ) {
309 return false;
310 }
311
312 return $list_screen->get_edit_link();
313 }
314
315 /**
316 * Admin CSS for Column width and Settings Icon
317 *
318 * @since 1.4.0
319 */
320 public function admin_footer_scripts() {
321 if ( ! $this->current_list_screen ) {
322 return;
323 }
324
325 $this->display_width_styles();
326
327 /**
328 * Add header scripts that only apply to column screens.
329 * @since 2.3.5
330 *
331 * @param object CPAC Main Class
332 */
333 do_action( 'ac/admin_footer', $this->current_list_screen, $this );
334 }
335
336 /**
337 * Load current list screen
338 *
339 * @param WP_Screen $current_screen
340 */
341 public function load_list_screen( $current_screen ) {
342 if ( $list_screen = AC()->get_list_screen_by_wpscreen( $current_screen ) ) {
343 $this->set_current_list_screen( $list_screen );
344 }
345 }
346
347 /**
348 * Runs when doing Quick Edit, a native WordPress ajax call
349 */
350 public function load_list_screen_doing_quick_edit() {
351 $this->set_current_list_screen( AC()->get_list_screen( $this->get_list_screen_when_doing_quick_edit() ) );
352 }
353
354 /**
355 * @param AC_ListScreen $list_screen
356 */
357 public function set_current_list_screen( $list_screen ) {
358 if ( ! $list_screen ) {
359 return;
360 }
361
362 $this->current_list_screen = $list_screen;
363
364 // Init Values
365 $list_screen->set_manage_value_callback();
366
367 /**
368 * Init Headings
369 * @see get_column_headers() for filter location
370 */
371 add_filter( "manage_" . $list_screen->get_screen_id() . "_columns", array( $this, 'add_headings' ), 200 );
372
373 /**
374 * @since 3.0
375 *
376 * @param AC_ListScreen
377 */
378 do_action( 'ac/table/list_screen', $list_screen );
379 }
380
381 /**
382 * Is WordPress doing ajax
383 *
384 * @since 2.5
385 * @return string List screen key
386 */
387 public function get_list_screen_when_doing_quick_edit() {
388 $list_screen = false;
389
390 if ( AC()->is_doing_ajax() ) {
391
392 switch ( filter_input( INPUT_POST, 'action' ) ) {
393
394 // Quick edit post
395 case 'inline-save' :
396 $list_screen = filter_input( INPUT_POST, 'post_type' );
397 break;
398
399 // Adding term & Quick edit term
400 case 'add-tag' :
401 case 'inline-save-tax' :
402 $list_screen = 'wp-taxonomy_' . filter_input( INPUT_POST, 'taxonomy' );
403 break;
404
405 // Quick edit comment & Inline reply on comment
406 case 'edit-comment' :
407 case 'replyto-comment' :
408 $list_screen = 'wp-comments';
409 break;
410 }
411 }
412
413 return $list_screen;
414 }
415
416 /**
417 * @since 2.0
418 */
419 public function add_headings( $columns ) {
420 if ( empty( $columns ) ) {
421 return $columns;
422 }
423
424 if ( ! $this->current_list_screen ) {
425 return $columns;
426 }
427
428 // Store default headings
429 if ( ! AC()->is_doing_ajax() ) {
430 $this->current_list_screen->save_default_headings( $columns );
431 }
432
433 // Run once
434 if ( $this->column_headings ) {
435 return $this->column_headings;
436 }
437
438 // Nothing stored. Show default columns on screen.
439 if ( ! $this->current_list_screen->get_settings() ) {
440 return $columns;
441 }
442
443 // Add mandatory checkbox
444 if ( isset( $columns['cb'] ) ) {
445 $this->column_headings['cb'] = $columns['cb'];
446 }
447
448 // On first visit 'columns' can be empty, because they were put in memory before 'default headings'
449 // were stored. We force get_columns() to be re-populated.
450 if ( ! $this->current_list_screen->get_columns() ) {
451 $this->current_list_screen->reset();
452 $this->current_list_screen->reset_original_columns();
453 }
454
455 foreach ( $this->current_list_screen->get_columns() as $column ) {
456
457 /**
458 * @since 3.0
459 *
460 * @param string $label
461 * @param AC_Column $column
462 */
463 $label = apply_filters( 'ac/headings/label', $column->get_setting( 'label' )->get_value(), $column );
464
465 $this->column_headings[ $column->get_name() ] = $label;
466 }
467
468 return apply_filters( 'ac/headings', $this->column_headings, $this->current_list_screen );
469 }
470
471 }
472