PluginProbe ʕ •ᴥ•ʔ
Admin Columns / 3.0.5
Admin Columns v3.0.5
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
Addon 8 years ago Admin 8 years ago Column 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 Addons.php 8 years ago Admin.php 8 years ago Autoloader.php 8 years ago Collection.php 8 years ago Column.php 8 years ago Container.php 8 years ago Groups.php 8 years ago Helper.php 8 years ago ListScreen.php 8 years ago ListScreenPost.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
456 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_table = $this->get_current_list_screen()->get_list_table();
161
162 echo sprintf( '<div class="hidden">%s</div>', $list_table->column_name( $term ) );
163
164 return $actions;
165 }
166
167 /**
168 * Adds a body class which is used to set individual column widths
169 *
170 * @since 1.4.0
171 *
172 * @param string $classes body classes
173 *
174 * @return string
175 */
176 public function admin_class( $classes ) {
177 if ( ! $this->current_list_screen ) {
178 return $classes;
179 }
180
181 $classes .= " ac-" . $this->current_list_screen->get_key();
182
183 return apply_filters( 'ac/table/body_class', $classes, $this );
184 }
185
186 /**
187 * @since 2.2.4
188 *
189 * @param AC_ListScreen $list_screen
190 */
191 public function admin_scripts() {
192 if ( ! $this->current_list_screen ) {
193 return;
194 }
195
196 $list_screen = $this->current_list_screen;
197
198 // Tooltip
199 wp_register_script( 'jquery-qtip2', AC()->get_plugin_url() . "external/qtip2/jquery.qtip" . AC()->minified() . ".js", array( 'jquery' ), AC()->get_version() );
200 wp_enqueue_style( 'jquery-qtip2', AC()->get_plugin_url() . "external/qtip2/jquery.qtip" . AC()->minified() . ".css", array(), AC()->get_version() );
201
202 // Main
203 wp_enqueue_script( 'ac-table', AC()->get_plugin_url() . "assets/js/table" . AC()->minified() . ".js", array( 'jquery', 'jquery-qtip2' ), AC()->get_version() );
204 wp_enqueue_style( 'ac-table', AC()->get_plugin_url() . "assets/css/table" . AC()->minified() . ".css", array(), AC()->get_version() );
205
206 wp_localize_script( 'ac-table', 'AC', array(
207 'list_screen' => $list_screen->get_key(),
208 'layout' => $list_screen->get_layout_id(),
209 'column_types' => $this->get_column_types_mapping( $list_screen ),
210 'ajax_nonce' => wp_create_nonce( 'ac-ajax' ),
211 'table_id' => $list_screen->get_table_attr_id(),
212 'edit_link' => $this->get_edit_link( $list_screen ),
213 'i18n' => array(
214 'edit_columns' => esc_html( __( 'Edit columns', 'codepress-admin-columns' ) ),
215 ),
216 )
217 );
218
219 /**
220 * @param AC_ListScreen $list_screen
221 */
222 do_action( 'ac/table_scripts', $list_screen );
223
224 // Column specific scripts
225 foreach ( $list_screen->get_columns() as $column ) {
226 $column->scripts();
227 }
228 }
229
230 /**
231 * @param AC_ListScreen $list_screen
232 *
233 * @return array
234 */
235 private function get_column_types_mapping( AC_ListScreen $list_screen ) {
236 $types = array();
237 foreach ( $list_screen->get_columns() as $column ) {
238 $types[ $column->get_name() ] = $column->get_type();
239 }
240
241 return $types;
242 }
243
244 public function get_current_list_screen() {
245 return $this->current_list_screen;
246 }
247
248 /**
249 * Applies the width setting to the table headers
250 */
251 private function display_width_styles() {
252 if ( $this->current_list_screen->get_settings() ) {
253
254 // CSS: columns width
255 $css_column_width = false;
256
257 foreach ( $this->current_list_screen->get_columns() as $column ) {
258
259 /* @var AC_Settings_Column_Width $setting */
260 $setting = $column->get_setting( 'width' );
261
262 if ( $width = $setting->get_display_width() ) {
263 $css_column_width .= ".ac-" . $this->current_list_screen->get_key() . " .wrap table th.column-" . $column->get_name() . " { width: " . $width . " !important; }";
264 $css_column_width .= "body.acp-overflow-table.ac-" . $this->current_list_screen->get_key() . " .wrap th.column-" . $column->get_name() . " { min-width: " . $width . " !important; }";
265 }
266 }
267
268 if ( $css_column_width ) : ?>
269 <style>
270 @media screen and (min-width: 783px) {
271 <?php echo $css_column_width; ?>
272 }
273 </style>
274 <?php
275 endif;
276 }
277 }
278
279 /**
280 * @param AC_ListScreen $list_screen
281 *
282 * @return string|false
283 */
284 private function get_edit_link( AC_ListScreen $list_screen ) {
285 if ( ! AC()->user_can_manage_admin_columns() ) {
286 return false;
287 }
288
289 /* @var AC_Admin_Page_Settings $settings */
290 $settings = AC()->admin()->get_page( 'settings' );
291
292 if ( ! $settings->show_edit_button() ) {
293 return false;
294 }
295
296 return $list_screen->get_edit_link();
297 }
298
299 /**
300 * Admin CSS for Column width and Settings Icon
301 *
302 * @since 1.4.0
303 */
304 public function admin_footer_scripts() {
305 if ( ! $this->current_list_screen ) {
306 return;
307 }
308
309 $this->display_width_styles();
310
311 /**
312 * Add header scripts that only apply to column screens.
313 * @since 2.3.5
314 *
315 * @param object CPAC Main Class
316 */
317 do_action( 'ac/admin_footer', $this->current_list_screen, $this );
318 }
319
320 /**
321 * Load current list screen
322 *
323 * @param WP_Screen $current_screen
324 */
325 public function load_list_screen( $current_screen ) {
326 if ( $list_screen = AC()->get_list_screen_by_wpscreen( $current_screen ) ) {
327 $this->set_current_list_screen( $list_screen );
328 }
329 }
330
331 /**
332 * Runs when doing Quick Edit, a native WordPress ajax call
333 */
334 public function load_list_screen_doing_quick_edit() {
335 $this->set_current_list_screen( AC()->get_list_screen( $this->get_list_screen_when_doing_quick_edit() ) );
336 }
337
338 /**
339 * @param AC_ListScreen $list_screen
340 */
341 public function set_current_list_screen( $list_screen ) {
342 if ( ! $list_screen ) {
343 return;
344 }
345
346 $this->current_list_screen = $list_screen;
347
348 // Init Values
349 $list_screen->set_manage_value_callback();
350
351 /**
352 * Init Headings
353 * @see get_column_headers() for filter location
354 */
355 add_filter( "manage_" . $list_screen->get_screen_id() . "_columns", array( $this, 'add_headings' ), 200 );
356
357 /**
358 * @since 3.0
359 *
360 * @param AC_ListScreen
361 */
362 do_action( 'ac/table/list_screen', $list_screen );
363 }
364
365 /**
366 * Is WordPress doing ajax
367 *
368 * @since 2.5
369 * @return string List screen key
370 */
371 public function get_list_screen_when_doing_quick_edit() {
372 $list_screen = false;
373
374 if ( AC()->is_doing_ajax() ) {
375
376 switch ( filter_input( INPUT_POST, 'action' ) ) {
377
378 // Quick edit post
379 case 'inline-save' :
380 $list_screen = filter_input( INPUT_POST, 'post_type' );
381 break;
382
383 // Adding term & Quick edit term
384 case 'add-tag' :
385 case 'inline-save-tax' :
386 $list_screen = 'wp-taxonomy_' . filter_input( INPUT_POST, 'taxonomy' );
387 break;
388
389 // Quick edit comment & Inline reply on comment
390 case 'edit-comment' :
391 case 'replyto-comment' :
392 $list_screen = 'wp-comments';
393 break;
394 }
395 }
396
397 return $list_screen;
398 }
399
400 /**
401 * @since 2.0
402 */
403 public function add_headings( $columns ) {
404 if ( empty( $columns ) ) {
405 return $columns;
406 }
407
408 if ( ! $this->current_list_screen ) {
409 return $columns;
410 }
411
412 // Store default headings
413 if ( ! AC()->is_doing_ajax() ) {
414 $this->current_list_screen->save_default_headings( $columns );
415 }
416
417 // Run once
418 if ( $this->column_headings ) {
419 return $this->column_headings;
420 }
421
422 // Nothing stored. Show default columns on screen.
423 if ( ! $this->current_list_screen->get_settings() ) {
424 return $columns;
425 }
426
427 // Add mandatory checkbox
428 if ( isset( $columns['cb'] ) ) {
429 $this->column_headings['cb'] = $columns['cb'];
430 }
431
432 // On first visit 'columns' can be empty, because they were put in memory before 'default headings'
433 // were stored. We force get_columns() to be re-populated.
434 if ( ! $this->current_list_screen->get_columns() ) {
435 $this->current_list_screen->reset();
436 $this->current_list_screen->reset_original_columns();
437 }
438
439 foreach ( $this->current_list_screen->get_columns() as $column ) {
440
441 /**
442 * @since 3.0
443 *
444 * @param string $label
445 * @param AC_Column $column
446 */
447 $label = apply_filters( 'ac/headings/label', $column->get_setting( 'label' )->get_value(), $column );
448
449 $this->column_headings[ $column->get_name() ] = $label;
450 }
451
452 return apply_filters( 'ac/headings', $this->column_headings, $this->current_list_screen );
453 }
454
455 }
456