Admin Columns - Version 1.2.1

Version Description

  • added word count sorting
  • added attachment count sorting
  • added template name sorting
  • minor styling changes
  • bug fix with sorting by slug
  • bug fix with sorting by attachment
Download this release

Release Info

Developer codepress
Plugin Icon 128x128 Admin Columns
Version 1.2.1
Comparing to
See all releases

Code changes from version 1.0 to 1.2.1

assets/css/admin-column.css CHANGED
@@ -1,4 +1,3 @@
1
- #general-cpac-settings {}
2
#cpac .postbox {
3
margin: 0 10px 10px 0;
4
}
@@ -39,13 +38,19 @@
39
}
40
#general-cpac-settings .cpac-option-list {
41
overflow: hidden;
42
- width: 360px;
43
}
44
#general-cpac-settings .cpac-reorder-msg {
45
- background: transparent url('../images/reorder.png') no-repeat scroll 0 0;
46
margin-left: 5px;
47
height: 23px;
48
- width: 171px;
49
clear: both;
50
}
51
#general-cpac-settings .cpac-option-list li {
@@ -63,19 +68,9 @@
63
background-image: -webkit-linear-gradient(top, #f9f9f9, #ececec);
64
background-image: linear-gradient(top, #f9f9f9, #ececec);
65
border-radius: 3px 3px 3px 3px;
66
- border: 1px solid #DFDFDF;
67
margin-top: 1px;
68
}
69
- #general-cpac-settings .cpac-option-list li.active {
70
- background-color: #d8d8d8;
71
- background-image: -ms-linear-gradient(top, #f0f0f0, #d8d8d8);
72
- background-image: -moz-linear-gradient(top, #f0f0f0, #d8d8d8);
73
- background-image: -o-linear-gradient(top, #f0f0f0, #d8d8d8);
74
- background-image: -webkit-gradient(linear, left top, left bottom, from(#f0f0f0), to(#d8d8d8));
75
- background-image: -webkit-linear-gradient(top, #f0f0f0, #d8d8d8);
76
- background-image: linear-gradient(top, #f0f0f0, #d8d8d8);
77
- border-color: #c5c5c5;
78
- }
79
#general-cpac-settings .cpac-option-list li .cpac-sort-handle {
80
background: transparent url('../images/sort.png') no-repeat 5px 5px;
81
width: 20px;
@@ -109,7 +104,8 @@
109
display: block;
110
margin-right: 30px;
111
overflow: hidden;
112
- height: 15px;
113
}
114
#general-cpac-settings .cpac-option-list li .cpac-type-options input {
115
margin-top: 6px;
@@ -130,6 +126,11 @@
130
text-indent: -999em;
131
overflow: hidden;
132
}
133
#general-cpac-settings .cpac-option-list li div.cpac-meta-title span {
134
display: inline-block;
135
margin: 5px 5px 0 0;
@@ -187,6 +188,25 @@
187
color: #832525;
188
text-shadow: none;
189
}
190
#restore-cpac-settings .inside {
191
padding: 10px;
192
}
@@ -206,4 +226,24 @@
206
}
207
#restore-cpac-settings .inside .description {
208
color: #832525;
209
}
1
#cpac .postbox {
2
margin: 0 10px 10px 0;
3
}
38
}
39
#general-cpac-settings .cpac-option-list {
40
overflow: hidden;
41
+ width: 360px;
42
+ margin-bottom: 5px;
43
}
44
#general-cpac-settings .cpac-reorder-msg {
45
+ background: transparent url('../images/reorder_arrow.png') no-repeat scroll 0 0;
46
margin-left: 5px;
47
height: 23px;
48
+ line-height: 25px;
49
+ padding-left: 25px;
50
+ color: #727272;
51
+ font-size: 12px;
52
+ font-family: 'Trebuchet MS', Arial, Verdana;
53
+ font-style: italic;
54
clear: both;
55
}
56
#general-cpac-settings .cpac-option-list li {
68
background-image: -webkit-linear-gradient(top, #f9f9f9, #ececec);
69
background-image: linear-gradient(top, #f9f9f9, #ececec);
70
border-radius: 3px 3px 3px 3px;
71
+ border: 1px solid #cbcbcb;
72
margin-top: 1px;
73
}
74
#general-cpac-settings .cpac-option-list li .cpac-sort-handle {
75
background: transparent url('../images/sort.png') no-repeat 5px 5px;
76
width: 20px;
104
display: block;
105
margin-right: 30px;
106
overflow: hidden;
107
+ height: 17px;
108
+ line-height: 17px;
109
}
110
#general-cpac-settings .cpac-option-list li .cpac-type-options input {
111
margin-top: 6px;
126
text-indent: -999em;
127
overflow: hidden;
128
}
129
+ #general-cpac-settings .cpac-option-list li.opened a.cpac-action {}
130
+ #general-cpac-settings .cpac-option-list li.active a.cpac-action {
131
+ background-position: 50% -66px;
132
+ }
133
+ #general-cpac-settings .cpac-option-list li.active.opened a.cpac-action {}
134
#general-cpac-settings .cpac-option-list li div.cpac-meta-title span {
135
display: inline-block;
136
margin: 5px 5px 0 0;
188
color: #832525;
189
text-shadow: none;
190
}
191
+ #general-cpac-settings .cpac-option-list li.active {
192
+ background-color: #c7c7c7;
193
+ background-image: -ms-linear-gradient(top, #e9e9e9, #c7c7c7);
194
+ background-image: -moz-linear-gradient(top, #e9e9e9, #c7c7c7);
195
+ background-image: -o-linear-gradient(top, #e9e9e9, #c7c7c7);
196
+ background-image: -webkit-gradient(linear, left top, left bottom, from(#e9e9e9), to(#c7c7c7));
197
+ background-image: -webkit-linear-gradient(top, #e9e9e9, #c7c7c7);
198
+ background-image: linear-gradient(top, #e9e9e9, #c7c7c7);
199
+ border-color: #aeaeae;
200
+ }
201
+ #general-cpac-settings .cpac-option-list li.active .cpac-sort-handle {
202
+ background-position: 5px -19px;
203
+ }
204
+ #general-cpac-settings .cpac-option-list li.active div.cpac-meta-title {
205
+ color: #151515;
206
+ }
207
+ #general-cpac-settings .cpac-option-list li.active div.cpac-meta-title span {
208
+ color: #5c5c5c
209
+ }
210
#restore-cpac-settings .inside {
211
padding: 10px;
212
}
226
}
227
#restore-cpac-settings .inside .description {
228
color: #832525;
229
+ }
230
+ #likethisplugin-cpac-settings {
231
+ padding: 0 0 10px;
232
+ }
233
+ #likethisplugin-cpac-settings ul {
234
+ margin-left: 20px;
235
+ }
236
+ #likethisplugin-cpac-settings li {
237
+ list-style: square;
238
+ line-height: 16px;
239
+ }
240
+ #likethisplugin-cpac-settings li a {
241
+ text-decoration: none;
242
+ }
243
+ #likethisplugin-cpac-settings li.donate_link a {
244
+ color: green;
245
+ text-decoration: underline;
246
+ }
247
+ #likethisplugin-cpac-settings li.donate_link a:hover {
248
+ color: darkgreen;
249
}
assets/images/arrows.png CHANGED
Binary file
assets/images/reorder_arrow.png ADDED
Binary file
assets/images/sort.png CHANGED
Binary file
assets/js/admin-column.js CHANGED
@@ -2,7 +2,11 @@
2
* fires when the dom is ready
3
*
4
*/
5
- jQuery(document).ready(function(){
6
cpac_sortable();
7
cpac_checked();
8
cpac_box_events();
@@ -15,7 +19,7 @@ jQuery(document).ready(function(){
15
*
16
*/
17
function cpac_sortable()
18
- {
19
jQuery('ul.cpac-option-list').sortable({
20
handle: 'div.cpac-sort-handle',
21
placeholder: 'cpac-placeholder',
@@ -38,7 +42,7 @@ function cpac_checked()
38
// toggle on
39
if ( value != 'on') {
40
li.addClass('active');
41
- state.attr('value', 'on');
42
}
43
44
// toggle off
@@ -59,7 +63,10 @@ function cpac_box_events()
59
// fold in/out
60
jQuery('#cpac .cpac-option-list .cpac-action').unbind('click').click(function(e){
61
e.preventDefault();
62
- jQuery(this).closest('li').find('.cpac-type-inside').slideToggle(150);
63
});
64
65
// remove custom field box
@@ -72,8 +79,7 @@ function cpac_box_events()
72
height: 0
73
}, 350, function() {
74
el.remove();
75
- });
76
-
77
});
78
}
79
2
* fires when the dom is ready
3
*
4
*/
5
+ jQuery(document).ready(function()
6
+ {
7
+ if (jQuery('#cpac').length == 0)
8
+ return false;
9
+
10
cpac_sortable();
11
cpac_checked();
12
cpac_box_events();
19
*
20
*/
21
function cpac_sortable()
22
+ {
23
jQuery('ul.cpac-option-list').sortable({
24
handle: 'div.cpac-sort-handle',
25
placeholder: 'cpac-placeholder',
42
// toggle on
43
if ( value != 'on') {
44
li.addClass('active');
45
+ state.attr('value', 'on');
46
}
47
48
// toggle off
63
// fold in/out
64
jQuery('#cpac .cpac-option-list .cpac-action').unbind('click').click(function(e){
65
e.preventDefault();
66
+ var li = jQuery(this).closest('li');
67
+ li.find('.cpac-type-inside').slideToggle(150, function() {
68
+ li.toggleClass('opened');
69
+ });
70
});
71
72
// remove custom field box
79
height: 0
80
}, 350, function() {
81
el.remove();
82
+ });
83
});
84
}
85
codepress-admin-columns.php CHANGED
@@ -1,9 +1,9 @@
1
<?php
2
/*
3
Plugin Name: Codepress Admin Columns
4
- Version: 1.0.1
5
- Description: This plugin makes it easy to customize Admin Columns for your Posts, Pages and Custom Post Type Screens.
6
- Author: Tobias Schutter
7
Author URI: http://www.codepress.nl
8
Plugin URI: http://www.codepress.nl/plugins/codepress-admin-columns/
9
Text Domain: codepress-admin-columns
@@ -26,14 +26,14 @@ along with this program; if not, write to the Free Software
26
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27
*/
28
29
- define( 'CPAC_VERSION', '1.0.1' );
30
31
/**
32
* Init Class
33
*
34
* @since 1.0
35
*/
36
- $cpac = new Codepress_Admin_Columns;
37
38
/**
39
* Advanced Admin Columns Class
@@ -44,10 +44,9 @@ $cpac = new Codepress_Admin_Columns;
44
class Codepress_Admin_Columns
45
{
46
private $post_types,
47
- $options,
48
- $options_default,
49
$slug,
50
- $textdomain;
51
52
/**
53
* Construct
@@ -60,39 +59,42 @@ class Codepress_Admin_Columns
60
}
61
62
/**
63
- * Initilize plugin.
64
*
65
* Loading sequence is determined and intialized.
66
*
67
* @since 1.0
68
*/
69
function init()
70
- {
71
// vars
72
$this->post_types = $this->get_post_types();
73
- $this->handle_requests();
74
- $this->options = get_option('cpac_options');
75
- $this->options_default = get_option('cpac_options_default');
76
-
77
- // slug
78
$this->slug = 'codepress-admin-columns';
79
$this->textdomain = 'codepress-admin-columns';
80
81
// translations
82
load_plugin_textdomain( $this->textdomain, false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
83
84
- // Actions and hooks
85
- add_action( 'admin_menu', array( &$this, 'settings_menu') );
86
add_action( 'admin_init', array( &$this, 'register_settings') );
87
- add_action( 'admin_init', array( &$this, 'register_columns' ) );
88
- add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts') );
89
- add_action( 'manage_pages_custom_column', array( &$this, 'manage_column_value'), 10, 2 );
90
- add_action( 'manage_posts_custom_column', array( &$this, 'manage_column_value'), 10, 2 );
91
add_action( 'admin_print_styles' , array( &$this, 'column_styles') );
92
- add_filter( 'request', array( &$this, 'handle_requests_orderby_column') );
93
- add_filter( 'plugin_action_links', array( &$this, 'add_settings_link'), 10, 2);
94
}
95
-
96
/**
97
* Admin Menu.
98
*
@@ -114,9 +116,10 @@ class Codepress_Admin_Columns
114
// Callback
115
array( &$this, 'plugin_settings_page')
116
);
117
-
118
- // css scripts
119
add_action( "admin_print_styles-$page", array( &$this, 'admin_styles') );
120
}
121
122
/**
@@ -140,187 +143,143 @@ class Codepress_Admin_Columns
140
*/
141
public function register_columns()
142
{
143
- foreach ( $this->post_types as $post_type ) {
144
-
145
// register column per post type
146
- add_filter("manage_edit-{$post_type}_columns", array(&$this, 'callback_set_column'));
147
148
// register column as sortable
149
- add_filter( "manage_edit-{$post_type}_sortable_columns", array(&$this, 'callback_set_sortable_column'));
150
- }
151
}
152
153
/**
154
- * Callback Set Column
155
*
156
* @since 1.0
157
*/
158
- public function callback_set_column($columns)
159
- {
160
global $post_type;
161
- $columns = $this->set_column($columns, $post_type);
162
-
163
- return $columns;
164
}
165
166
/**
167
- * Callback Set Sortable Column
168
*
169
- * @since 1.0
170
*/
171
- public function callback_set_sortable_column($columns)
172
- {
173
- global $post_type;
174
- $columns = $this->set_sortable_filter($columns, $post_type);
175
-
176
- return $columns;
177
}
178
179
/**
180
- * Settings Page Template.
181
- *
182
- * This function in conjunction with others usei the WordPress
183
- * Settings API to create a settings page where users can adjust
184
- * the behaviour of this plugin.
185
*
186
- * @since 1.0
187
*/
188
- public function plugin_settings_page()
189
{
190
- // loop through post types
191
- $rows = '';
192
- foreach ( $this->post_types as $post_type ) {
193
-
194
- // post type label
195
- $label = $this->get_singular_name($post_type);
196
-
197
- // id
198
- $id = $this->sanitize_string($post_type);
199
-
200
- // build draggable boxes
201
- $boxes = $this->get_column_options($post_type);
202
-
203
- // class
204
- $class = $this->is_menu_type_current($post_type) ? ' current' : ' hidden';
205
206
- $rows .= "
207
- <tr id='cpac-box-{$id}' valign='top' class='cpac-box-row{$class}'>
208
- <th class='cpac_post_type' scope='row'>
209
- {$label}
210
- </th>
211
- <td>
212
- <h3 class='cpac_post_type hidden'>{$label}</h3>
213
- {$boxes}
214
- </td>
215
- </tr>
216
- ";
217
}
218
219
- // Post Type Menu
220
- $menu = $this->get_post_type_menu();
221
222
- ?>
223
- <div id="cpac" class="wrap">
224
- <?php screen_icon($this->slug) ?>
225
- <h2><?php _e('Codepress Admin Columns', $this->textdomain); ?></h2>
226
- <?php echo $menu ?>
227
- <div class="postbox-container" style="width:70%;">
228
- <div class="metabox-holder">
229
- <div class="meta-box-sortables">
230
-
231
- <div id="general-cpac-settings" class="postbox">
232
- <div title="Click to toggle" class="handlediv"><br></div>
233
- <h3 class="hndle">
234
- <span><?php _e('Admin Columns', $this->textdomain ); ?></span>
235
- </h3>
236
- <div class="inside">
237
- <form method="post" action="options.php">
238
-
239
- <?php settings_fields( 'cpac-settings-group' ); ?>
240
-
241
- <table class="form-table">
242
-
243
- <?php echo $rows ?>
244
-
245
- <tr class="bottom" valign="top">
246
- <th scope="row"></th>
247
- <td>
248
- <p class="submit">
249
- <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
250
- </p>
251
- </td>
252
- </tr>
253
- </table>
254
- </form>
255
- </div>
256
- </div><!-- general-settings -->
257
-
258
- <div id="restore-cpac-settings" class="postbox">
259
- <div title="Click to toggle" class="handlediv"><br></div>
260
- <h3 class="hndle">
261
- <span><?php _e('Restore defaults', $this->textdomain) ?></span>
262
- </h3>
263
- <div class="inside">
264
- <form method="post" action="">
265
- <input type="submit" class="button" name="cpac-restore-defaults" value="<?php _e('Restore default settings', $this->textdomain ) ?>" onclick="return confirm('<?php _e("Warning! ALL saved admin columns data will be deleted. This cannot be undone. \'OK\' to delete, \'Cancel\' to stop", $this->textdomain); ?>');" />
266
- </form>
267
- <p class="description"><?php _e('This will delete all column settings and restore the default settings.', $this->textdomain); ?></p>
268
- </div>
269
- </div><!-- restore-cpac-settings -->
270
-
271
- </div>
272
- </div>
273
- </div><!-- .postbox-container -->
274
-
275
- <div class="postbox-container" style="width:20%;">
276
- <div class="metabox-holder">
277
- <div class="meta-box-sortables">
278
-
279
- <div id="side-cpac-settings" class="postbox">
280
- <div title="Click to toggle" class="handlediv"><br></div>
281
- <h3 class="hndle">
282
- <span><?php _e('Need support?', $this->textdomain) ?></span>
283
- </h3>
284
- <div class="inside">
285
- <p><?php printf(__('If you are having problems with this plugin, please talk about them in the <a href="%s">Support forums</a>.', $this->textdomain), 'http://wordpress.org/tags/codepress-admin-columns' );?></p>
286
- <p><?php printf(__("If you're sure you've found a bug, or have a feature request, please <a href='%s'>submit your feedback</a>.", $this->textdomain), 'http://www.codepress.nl/plugins/codepress-admin-columns#feedback');?></p>
287
- </div>
288
- </div><!-- side-cpac-settings -->
289
-
290
- </div>
291
- </div>
292
- </div><!-- .postbox-container -->
293
-
294
- </div>
295
- <?php
296
}
297
298
/**
299
* Get a list of Column options per post type
300
*
301
* @since 1.0
302
*/
303
- private function get_column_options($post_type)
304
{
305
// merge all columns
306
- $display_columns = $this->get_merged_columns($post_type);
307
-
308
// define
309
$list = '';
310
311
// loop throught the active columns
312
if ( $display_columns ) {
313
- foreach ( $display_columns as $key => $values ) {
314
315
// add items to the list
316
- $list .= $this->get_box($post_type, $key, $values);
317
318
}
319
}
320
321
// custom field button
322
$button_add_column = '';
323
- if ( $this->get_postmeta_by_posttype($post_type) )
324
$button_add_column = "<a href='javacript:;' class='cpac-add-customfield-column button'>+ " . __('Add Custom Field Column') . "</a>";
325
326
return "
@@ -329,7 +288,7 @@ class Codepress_Admin_Columns
329
{$list}
330
</ul>
331
{$button_add_column}
332
- <div class='cpac-reorder-msg'></div>
333
</div>
334
";
335
}
@@ -339,60 +298,90 @@ class Codepress_Admin_Columns
339
*
340
* @since 1.0
341
*/
342
- private function get_merged_columns($post_type)
343
{
344
//get saved database columns
345
- $db_columns = $this->get_db_columns($post_type);
346
-
347
- // get wp default columns
348
- $wp_default_columns = $this->get_wp_default_columns($post_type);
349
-
350
- // get custom columns
351
- $wp_custom_columns = $this->get_custom_columns($post_type);
352
353
- // merge wp default and custom columns
354
$default_columns = wp_parse_args($wp_custom_columns, $wp_default_columns);
355
-
356
// loop throught the active columns
357
if ( $db_columns ) {
358
- foreach ( $db_columns as $key => $values ) {
359
360
// get column meta options from custom columns
361
- if ( strpos($key, 'column-meta-') !== false )
362
- $db_columns[$key]['options'] = $wp_custom_columns['column-meta-1']['options'];
363
364
// add static options
365
- else
366
- $db_columns[$key]['options'] = $default_columns[$key]['options'];
367
368
- unset($default_columns[$key]);
369
}
370
}
371
372
// merge all
373
- $display_columns = wp_parse_args($db_columns, $default_columns);
374
-
375
return $display_columns;
376
}
377
-
378
-
379
/**
380
* Get checkbox
381
*
382
* @since 1.0
383
*/
384
- private function get_box($post_type, $key, $values)
385
{
386
$classes = array();
387
388
// set state
389
$state = isset($values['state']) ? $values['state'] : '';
390
391
- // set sortorder
392
- $sortorder = isset($values['sortorder']) && $values['sortorder'] == 'on' ? 'on' : '';
393
-
394
// class
395
- $classes[] = "cpac-box-{$key}";
396
if ( $state )
397
$classes[] = 'active';
398
if ( ! empty($values['options']['class']) )
@@ -400,11 +389,17 @@ class Codepress_Admin_Columns
400
$class = implode(' ', $classes);
401
402
// more box options
403
- $more_options = $this->get_additional_box_options($post_type, $key, $values);
404
$action = "<a class='cpac-action' href='#open'>open</a>";
405
406
// hide box options
407
- if ( ! empty($values['options']['hide_options']) ) {
408
$action = $more_options = '';
409
}
410
@@ -414,17 +409,16 @@ class Codepress_Admin_Columns
414
<div class='cpac-type-options'>
415
416
<div class='cpac-checkbox'></div>
417
- <input type='hidden' class='cpac-state' name='cpac_options[columns][{$post_type}][{$key}][state]' value='{$state}'/>
418
- <input type='hidden' name='cpac_options[columns][{$post_type}][{$key}][sortorder]' value='{$sortorder}'/>
419
<label class='main-label'>{$values['label']}</label>
420
</div>
421
<div class='cpac-meta-title'>
422
{$action}
423
- <span>{$values['options']['type_label']}</span>
424
</div>
425
<div class='cpac-type-inside'>
426
- <label for='cpac_options[columns][{$post_type}][{$key}][label]'>Label: </label>
427
- <input type='text' name='cpac_options[columns][{$post_type}][{$key}][label]' value='{$values['label']}' class='text'/>
428
<br/>
429
{$more_options}
430
</div>
@@ -439,13 +433,13 @@ class Codepress_Admin_Columns
439
*
440
* @since 1.0
441
*/
442
- private function get_additional_box_options($post_type, $key, $values)
443
{
444
$fields = '';
445
446
// Custom Fields
447
- if ( strpos($key, 'column-meta-') !== false )
448
- $fields .= $this->get_box_options_customfields($post_type, $key, $values);
449
450
return $fields;
451
}
@@ -455,10 +449,10 @@ class Codepress_Admin_Columns
455
*
456
* @since 1.0
457
*/
458
- private function get_box_options_customfields($post_type, $key, $values)
459
{
460
// get post meta fields
461
- $fields = $this->get_postmeta_by_posttype($post_type);
462
463
if ( empty($fields) )
464
return false;
@@ -485,10 +479,13 @@ class Codepress_Admin_Columns
485
'library_id' => __('Media Library Icon', $this->textdomain),
486
'excerpt' => __('Excerpt'),
487
'array' => __('Multiple Values', $this->textdomain),
488
);
489
490
- // add filters
491
- $fieldtypes = apply_filters('cpac-field-types', $fieldtypes );
492
foreach ( $fieldtypes as $fkey => $fieldtype ) {
493
$fieldtype_options .= sprintf
494
(
@@ -499,12 +496,16 @@ class Codepress_Admin_Columns
499
);
500
}
501
502
if ( empty($field_options) )
503
return false;
504
505
// add remove button
506
$remove = '<p class="remove-description description">'.__('This field can not be removed', $this->textdomain).'</p>';
507
- if ( $key != 'column-meta-1') {
508
$remove = "
509
<p>
510
<a href='javascript:;' class='cpac-delete-custom-field-box'>".__('Remove')."</a>
@@ -513,12 +514,18 @@ class Codepress_Admin_Columns
513
}
514
515
$inside = "
516
- <label for='cpac_options[columns][{$post_type}][{$key}][field]'>Custom Field: </label>
517
- <select name='cpac_options[columns][{$post_type}][{$key}][field]'>{$field_options}</select>
518
<br/>
519
- <label for='cpac_options[columns][{$post_type}][{$key}][field_type]'>Field Type: </label>
520
- <select name='cpac_options[columns][{$post_type}][{$key}][field_type]'>{$fieldtype_options}</select>
521
<br/>
522
{$remove}
523
";
524
@@ -526,17 +533,27 @@ class Codepress_Admin_Columns
526
}
527
528
/**
529
- * Get post meta fields by post type
530
*
531
* @since 1.0
532
*/
533
- private function get_postmeta_by_posttype($post_type)
534
{
535
global $wpdb;
536
- // get mata fields
537
- $sql = 'SELECT DISTINCT meta_key FROM '.$wpdb->postmeta.' pm JOIN '.$wpdb->posts.' p ON pm.post_id = p.ID WHERE p.post_type = "' . mysql_real_escape_string($post_type) . '" ORDER BY 1';
538
- $fields = $wpdb->get_results($sql, ARRAY_N);
539
540
// postmeta
541
if ( $fields ) {
542
$meta_fields = array();
@@ -546,9 +563,8 @@ class Codepress_Admin_Columns
546
$meta_fields[] = $field[0];
547
}
548
}
549
-
550
return $meta_fields;
551
- }
552
553
return false;
554
}
@@ -558,13 +574,24 @@ class Codepress_Admin_Columns
558
*
559
* @since 1.0
560
*/
561
- public function admin_enqueue_scripts()
562
{
563
- wp_enqueue_script( 'dashboard' );
564
- wp_enqueue_script( 'jquery-ui-sortable' );
565
- wp_enqueue_script( 'cpac-admin', $this->plugin_url('/assets/js/admin-column.js'), array('jquery', 'jquery-ui-sortable'), CPAC_VERSION );
566
}
567
-
568
/**
569
* Get post types
570
*
@@ -609,7 +636,7 @@ class Codepress_Admin_Columns
609
public function register_settings()
610
{
611
// If we have no options in the database, let's add them now.
612
- if ( false === $this->options )
613
add_option( 'cpac_options', array(&$this, 'get_default_plugin_options') );
614
615
register_setting( 'cpac-settings-group', 'cpac_options', array(&$this, 'options_callback') );
@@ -630,7 +657,7 @@ class Codepress_Admin_Columns
630
}
631
632
/**
633
- * Save geocode coordinates of focus location.
634
*
635
* @since 1.0
636
*/
@@ -644,23 +671,40 @@ class Codepress_Admin_Columns
644
*
645
* @since 1.0
646
*/
647
- private function handle_requests()
648
{
649
// settings updated
650
- if ( ! empty($_REQUEST['settings-updated']) ) {
651
-
652
- // stores the default columns that are set by WP or set in the theme.
653
- $wp_default_columns = array();
654
- foreach ( $this->post_types as $post_type ) {
655
- $wp_default_columns[$post_type] = $this->get_wp_default_columns($post_type);
656
- }
657
- update_option( 'cpac_options_default', $wp_default_columns );
658
- }
659
660
// restore defaults
661
- if ( ! empty($_REQUEST['cpac-restore-defaults']) ) {
662
$this->restore_defaults();
663
- }
664
}
665
666
/**
@@ -679,15 +723,16 @@ class Codepress_Admin_Columns
679
*
680
* @since 1.0
681
*/
682
- private function get_post_excerpt($post_id, $charlength = 100)
683
{
684
- global $post;
685
$save_post = $post;
686
$post = get_post($post_id);
687
$excerpt = get_the_excerpt();
688
$post = $save_post;
689
690
- $output = $this->get_shortened_string($excerpt, $charlength );
691
692
return $output;
693
}
@@ -720,20 +765,20 @@ class Codepress_Admin_Columns
720
*
721
* @since 1.0
722
*/
723
- public function manage_column_value($key, $post_id)
724
{
725
- $type = $key;
726
727
// Check for taxonomies, such as column-taxonomy-[taxname]
728
if ( strpos($type, 'column-taxonomy-') !== false )
729
$type = 'column-taxonomy';
730
731
// Check for custom fields, such as column-meta-[customfieldname]
732
- if ( strpos($type, 'column-meta-') !== false )
733
- $type = 'column-meta';
734
735
// Hook
736
- do_action('cpac-manage-column', $type, $key, $post_id);
737
738
// Switch Types
739
$result = '';
@@ -776,10 +821,9 @@ class Codepress_Admin_Columns
776
case "column-page-template" :
777
// file name
778
$page_template = get_post_meta($post_id, '_wp_page_template', true);
779
- // all page templates
780
- $templates = get_page_templates();
781
- // template name
782
- $result = array_search($page_template, $templates);
783
break;
784
785
// Slug
@@ -787,9 +831,14 @@ class Codepress_Admin_Columns
787
$result = get_post($post_id)->post_name;
788
break;
789
790
// Taxonomy
791
case "column-taxonomy" :
792
- $tax = str_replace('column-taxonomy-','',$key);
793
$tags = get_the_terms($post_id, $tax);
794
$tarr = array();
795
if ( $tax == 'post_format' && empty($tags) ) {
@@ -804,17 +853,22 @@ class Codepress_Admin_Columns
804
break;
805
806
// Custom Field
807
- case "column-meta" :
808
- $result = $this->get_column_value_custom_field($post_id, $key);
809
break;
810
811
// Attachment
812
case "column-attachment" :
813
$result = $this->get_column_value_attachments($post_id);
814
break;
815
816
default :
817
- $result = get_post_meta( $post_id, $key, true );
818
819
endswitch;
820
@@ -823,46 +877,142 @@ class Codepress_Admin_Columns
823
824
echo $result;
825
}
826
-
827
/**
828
- * Get column value of post attachments
829
*
830
- * @since 1.0
831
*/
832
- private function get_column_value_attachments($post_id)
833
{
834
$result = '';
835
- $attachments = get_posts(array(
836
- 'post_type' => 'attachment',
837
- 'numberposts' => -1,
838
- 'post_status' => null,
839
- 'post_parent' => $post_id
840
- ));
841
- if ( $attachments ) {
842
- foreach ( $attachments as $attach ) {
843
- $result .= wp_get_attachment_image( $attach->ID, array(80,80), true );
844
}
845
}
846
return $result;
847
}
848
849
/**
850
* Get column value of Custom Field
851
*
852
* @since 1.0
853
- */
854
- private function get_column_value_custom_field($post_id, $key)
855
{
856
- $columns = $this->get_db_columns( get_post_type($post_id) );
857
- $field = isset($columns[$key]['field']) ? $columns[$key]['field'] : '';
858
- $fieldtype = isset($columns[$key]['field_type']) ? $columns[$key]['field_type'] : '';
859
860
// Get meta field value
861
- $meta = get_post_meta($post_id, $field, true);
862
863
// multiple meta values
864
if ( ( $fieldtype == 'array' && is_array($meta) ) || is_array($meta) ) {
865
- $meta = get_post_meta($post_id, $field);
866
$meta = $this->recursive_implode(', ', $meta);
867
}
868
@@ -886,11 +1036,68 @@ class Codepress_Admin_Columns
886
887
// Excerpt
888
case "excerpt" :
889
- $meta = $this->get_shortened_string($meta, 100);
890
break;
891
892
endswitch;
893
894
return $meta;
895
}
896
@@ -909,55 +1116,30 @@ class Codepress_Admin_Columns
909
$retVal[] = $r_pieces;
910
}
911
}
912
- return implode( $glue, $retVal );
913
- }
914
-
915
- /**
916
- * Set Columns for Registering
917
- *
918
- * @since 1.0
919
- */
920
- private function set_column($columns, $post_type)
921
- {
922
- $db_columns = $this->get_db_columns($post_type);
923
924
- if ( !$db_columns )
925
- return $columns;
926
-
927
- // set already loaded columns by plugins
928
- $set_columns = $this->filter_preset_columns($columns, $post_type);
929
-
930
- // loop through columns
931
- foreach ( $db_columns as $key => $values ) {
932
-
933
- // is active
934
- if ( isset($values['state']) && $values['state'] == 'on' ){
935
-
936
- // register format
937
- $set_columns[$key] = $values['label'];
938
- }
939
- }
940
- return $set_columns;
941
- }
942
943
/**
944
* Set columns. These columns apply either for every post or set by a plugin.
945
*
946
* @since 1.0
947
*/
948
- private function filter_preset_columns($columns, $post_type = 'post')
949
{
950
- $options = $this->options_default;
951
952
if ( !$options )
953
return $columns;
954
955
// we use the wp default columns for filtering...
956
- $db_columns = $options[$post_type];
957
958
// ... the ones that are set by plugins, theme functions and such.
959
- $dif_columns = array_diff(array_keys($columns), array_keys($db_columns));
960
-
961
// we add those to the columns
962
$pre_columns = array();
963
if ( $dif_columns ) {
@@ -967,44 +1149,30 @@ class Codepress_Admin_Columns
967
}
968
969
return $pre_columns;
970
- }
971
972
/**
973
- * Set sortable columns
974
*
975
* @since 1.0
976
*/
977
- private function set_sortable_filter($columns, $post_type)
978
{
979
- $db_columns = $this->get_db_columns($post_type);
980
-
981
- if ( !$db_columns )
982
- return $columns;
983
984
- // loop through columns
985
- foreach ( $db_columns as $key => $values ) {
986
987
- // is active
988
- if ( isset($values['sortorder']) && $values['sortorder'] == 'on' ){
989
-
990
- // register format
991
- $columns[$key] = $this->sanitize_string($values['label']);
992
- }
993
- }
994
- return $columns;
995
- }
996
-
997
- /**
998
- * Get WP default supported admin columns per post type.
999
- *
1000
- * @since 1.0
1001
- */
1002
- private function get_wp_default_columns($post_type = 'post')
1003
- {
1004
- // load some dependencies
1005
- require_once(ABSPATH . 'wp-admin\includes\template.php');
1006
- require_once(ABSPATH . 'wp-admin\includes\class-wp-list-table.php');
1007
- require_once(ABSPATH . 'wp-admin\includes\class-wp-posts-list-table.php');
1008
1009
// we need to change the current screen
1010
global $current_screen;
@@ -1016,12 +1184,56 @@ class Codepress_Admin_Columns
1016
// ...so we can get its columns
1017
$columns = WP_Posts_List_Table::get_columns();
1018
1019
// we remove the checkbox column as an option...
1020
- unset($columns['cb']);
1021
1022
// change to uniform format
1023
$uniform_columns = array();
1024
- foreach ( $columns as $key => $label ) {
1025
$hide_options = false;
1026
$type_label = $label;
1027
@@ -1030,8 +1242,8 @@ class Codepress_Admin_Columns
1030
$type_label = __('Comments', $this->textdomain);
1031
$hide_options = true;
1032
}
1033
-
1034
- $uniform_colums[$key] = array(
1035
'label' => $label,
1036
'state' => 'on',
1037
'options' => array(
@@ -1041,96 +1253,78 @@ class Codepress_Admin_Columns
1041
)
1042
);
1043
}
1044
-
1045
- // reset current screen
1046
- $current_screen = $org_current_screen;
1047
-
1048
return $uniform_colums;
1049
}
1050
-
1051
/**
1052
- * Add extra columns
1053
*
1054
* @since 1.0
1055
*/
1056
- private function get_custom_columns($post_type)
1057
{
1058
$custom_columns = array();
1059
1060
- // default arguments
1061
- $defaults = array(
1062
- 'label' => '',
1063
- 'sortorder' => '',
1064
- 'state' => '',
1065
-
1066
- // options are static
1067
- 'options' => array(
1068
- 'type_label' => __('Custom', $this->textdomain),
1069
- 'hide_options' => false,
1070
- 'class' => 'cpac-box-custom',
1071
- )
1072
- );
1073
-
1074
// Thumbnail support
1075
if ( post_type_supports($post_type, 'thumbnail') ) {
1076
- $custom_columns['column-featured_image'] = wp_parse_args( array(
1077
'label' => __('Featured Image', $this->textdomain),
1078
'options' => array(
1079
'type_label' => __('Image', $this->textdomain)
1080
)
1081
- ), $defaults);
1082
}
1083
1084
// Excerpt support
1085
if ( post_type_supports($post_type, 'editor') ) {
1086
- $custom_columns['column-excerpt'] = wp_parse_args( array(
1087
'label' => __('Excerpt', $this->textdomain),
1088
'options' => array(
1089
'type_label' => __('Excerpt', $this->textdomain)
1090
)
1091
- ), $defaults);
1092
}
1093
1094
// Sticky support
1095
if ( $post_type == 'post' ) {
1096
- $custom_columns['column-sticky'] = wp_parse_args( array(
1097
'label' => __('Sticky', $this->textdomain),
1098
'options' => array(
1099
'type_label' => __('Sticky', $this->textdomain)
1100
)
1101
- ), $defaults);
1102
}
1103
1104
// Order support
1105
if ( post_type_supports($post_type, 'page-attributes') ) {
1106
- $custom_columns['column-order'] = wp_parse_args( array(
1107
- 'label' => __('Page Order', $this->textdomain),
1108
- 'sortorder' => 'on',
1109
'options' => array(
1110
- 'type_label' => __('Order', $this->textdomain)
1111
)
1112
- ), $defaults);
1113
}
1114
1115
// Page Template
1116
if ( $post_type == 'page' ) {
1117
- $custom_columns['column-page-template'] = wp_parse_args( array(
1118
'label' => __('Page Template', $this->textdomain),
1119
- 'sortorder' => 'on',
1120
'options' => array(
1121
- 'type_label' => __('Page Template', $this->textdomain)
1122
)
1123
- ), $defaults);
1124
}
1125
1126
// Post Formats
1127
if ( post_type_supports($post_type, 'post-formats') ) {
1128
- $custom_columns['column-post_formats'] = wp_parse_args( array(
1129
'label' => __('Post Format', $this->textdomain),
1130
'options' => array(
1131
'type_label' => __('Post Format', $this->textdomain)
1132
)
1133
- ), $defaults);
1134
}
1135
1136
// Taxonomy support
@@ -1138,57 +1332,189 @@ class Codepress_Admin_Columns
1138
if ( $taxonomies ) {
1139
foreach ( $taxonomies as $tax_slug => $tax ) {
1140
if ( $tax_slug != 'post_tag' && $tax_slug != 'category' && $tax_slug != 'post_format' ) {
1141
- $custom_columns['column-taxonomy-'.$tax->name] = wp_parse_args( array(
1142
'label' => $tax->label,
1143
'options' => array(
1144
'type_label' => __('Taxonomy', $this->textdomain)
1145
)
1146
- ), $defaults);
1147
}
1148
}
1149
}
1150
1151
// Post ID support
1152
- $custom_columns['column-postid'] = wp_parse_args( array(
1153
- 'label' => 'ID',
1154
- 'sortorder' => 'on',
1155
'options' => array(
1156
'type_label' => 'ID',
1157
)
1158
- ), $defaults);
1159
1160
// Slug support
1161
- $custom_columns['column-page-slug'] = wp_parse_args( array(
1162
'label' => __('Slug', $this->textdomain),
1163
- 'sortorder' => 'on',
1164
'options' => array(
1165
'type_label' => __('Slug', $this->textdomain),
1166
)
1167
- ), $defaults);
1168
1169
// Attachment support
1170
- $custom_columns['column-attachment'] = wp_parse_args( array(
1171
'label' => __('Attachment', $this->textdomain),
1172
- 'sortorder' => 'on',
1173
'options' => array(
1174
- 'type_label' => __('Attachment', $this->textdomain)
1175
)
1176
- ), $defaults);
1177
1178
// Custom Field support
1179
- if ( $this->get_postmeta_by_posttype($post_type) ) {
1180
- $custom_columns['column-meta-1'] = wp_parse_args( array(
1181
'label' => __('Custom Field', $this->textdomain),
1182
'field' => '',
1183
'field_type' => '',
1184
'options' => array(
1185
'type_label' => __('Field', $this->textdomain),
1186
- 'class' => 'cpac-box-metafield'
1187
)
1188
- ), $defaults);
1189
}
1190
1191
- return apply_filters('cpac-custom-columns', $custom_columns);
1192
}
1193
1194
/**
@@ -1196,14 +1522,14 @@ class Codepress_Admin_Columns
1196
*
1197
* @since 1.0
1198
*/
1199
- private function get_db_columns($post_type)
1200
{
1201
// get plugin options
1202
- $options = $this->options;
1203
1204
// get saved columns
1205
- if ( isset($options['columns'][$post_type]) )
1206
- return $options['columns'][$post_type];
1207
1208
return false;
1209
}
@@ -1213,7 +1539,7 @@ class Codepress_Admin_Columns
1213
*
1214
* @since 1.0
1215
*/
1216
- private function get_post_type_menu()
1217
{
1218
// set
1219
$menu = '';
@@ -1225,16 +1551,16 @@ class Codepress_Admin_Columns
1225
$referer = $_REQUEST['cpac_type'];
1226
1227
// loop
1228
- foreach ( $this->post_types as $post_type ) {
1229
- $label = $this->get_singular_name($post_type);
1230
- $clean_label = $this->sanitize_string($post_type);
1231
1232
// divider
1233
$divider = $count++ == 1 ? '' : ' | ';
1234
1235
// current
1236
$current = '';
1237
- if ( $this->is_menu_type_current($post_type) )
1238
$current = ' class="current"';
1239
1240
// menu list
@@ -1258,9 +1584,7 @@ class Codepress_Admin_Columns
1258
* @since 1.0
1259
*/
1260
private function is_menu_type_current( $post_type )
1261
- {
1262
- //print_r($post_type);
1263
-
1264
// referer
1265
$referer = '';
1266
if ( ! empty($_REQUEST['cpac_type']) )
@@ -1292,10 +1616,18 @@ class Codepress_Admin_Columns
1292
*
1293
* @since 1.0
1294
*/
1295
- private function get_singular_name( $post_type )
1296
{
1297
- $posttype_obj = get_post_type_object($post_type);
1298
- $label = $posttype_obj->labels->singular_name;
1299
return $label;
1300
}
1301
@@ -1306,25 +1638,173 @@ class Codepress_Admin_Columns
1306
*/
1307
public function handle_requests_orderby_column( $vars )
1308
{
1309
- if ( isset( $vars['orderby'] ) ) {
1310
- // get saved columns
1311
- $db_columns = $this->get_db_columns($vars['post_type']);
1312
1313
- // Column Page Order
1314
- if ( isset($db_columns['column-order']) ) {
1315
1316
- // sanitizing label
1317
- $label = $this->sanitize_string($db_columns['column-order']['label']);
1318
1319
- // Check for Page Order
1320
- if ( $vars['orderby'] == $label ) {
1321
- $vars['orderby'] = 'menu_order';
1322
}
1323
}
1324
- }
1325
return $vars;
1326
- }
1327
1328
/**
1329
* Sanitize label
1330
*
@@ -1334,12 +1814,11 @@ class Codepress_Admin_Columns
1334
*/
1335
private function sanitize_string($string)
1336
{
1337
- $string = esc_url($string);
1338
- return str_replace('http://','', $string);
1339
}
1340
1341
/**
1342
- * Get a url to a file in this plugin.
1343
*
1344
* @since 1.0
1345
*/
@@ -1348,6 +1827,19 @@ class Codepress_Admin_Columns
1348
return plugins_url($file, __FILE__);
1349
}
1350
1351
/**
1352
* Get a thumbnail
1353
*
@@ -1357,14 +1849,172 @@ class Codepress_Admin_Columns
1357
{
1358
if ( empty($image) )
1359
return false;
1360
-
1361
$image_path = str_replace( WP_CONTENT_URL, WP_CONTENT_DIR, $image);
1362
- $new = image_resize( $image_path, 120, 80, true);
1363
1364
- if ( ! is_wp_error( $new ) )
1365
- $image = str_replace( WP_CONTENT_DIR, WP_CONTENT_URL, $new);
1366
1367
- return "<img src='{$image}' alt='' width='120' height='80' />";
1368
- }
1369
}
1370
?>
1
<?php
2
/*
3
Plugin Name: Codepress Admin Columns
4
+ Version: 1.2.1
5
+ Description: This plugin makes it easy to Manage Custom Columns for your Posts, Pages and Custom Post Type Screens.
6
+ Author: Codepress
7
Author URI: http://www.codepress.nl
8
Plugin URI: http://www.codepress.nl/plugins/codepress-admin-columns/
9
Text Domain: codepress-admin-columns
26
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27
*/
28
29
+ define( 'CPAC_VERSION', '1.2.1' );
30
31
/**
32
* Init Class
33
*
34
* @since 1.0
35
*/
36
+ new Codepress_Admin_Columns();
37
38
/**
39
* Advanced Admin Columns Class
44
class Codepress_Admin_Columns
45
{
46
private $post_types,
47
$slug,
48
+ $textdomain,
49
+ $excerpt_length;
50
51
/**
52
* Construct
59
}
60
61
/**
62
+ * Initialize plugin.
63
*
64
* Loading sequence is determined and intialized.
65
*
66
* @since 1.0
67
*/
68
function init()
69
+ {
70
// vars
71
$this->post_types = $this->get_post_types();
72
+
73
+ // set
74
$this->slug = 'codepress-admin-columns';
75
$this->textdomain = 'codepress-admin-columns';
76
+ $this->excerpt_length = 100;
77
78
// translations
79
load_plugin_textdomain( $this->textdomain, false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
80
81
+ // actions
82
+ add_action( 'admin_menu', array( &$this, 'settings_menu') );
83
add_action( 'admin_init', array( &$this, 'register_settings') );
84
+ add_action( 'admin_init', array( &$this, 'register_columns' ) );
85
+ add_action( 'manage_pages_custom_column', array( &$this, 'manage_posts_column_value'), 10, 2 );
86
+ add_action( 'manage_posts_custom_column', array( &$this, 'manage_posts_column_value'), 10, 2 );
87
+ add_action( 'manage_users_custom_column', array( &$this, 'manage_users_column_value'), 10, 3 );
88
add_action( 'admin_print_styles' , array( &$this, 'column_styles') );
89
+
90
+ // handle requests gets a low priority so it will trigger when all other plugins have loaded their columns
91
+ add_action( 'admin_init', array( &$this, 'handle_requests' ), 1000 );
92
+
93
+ // filters
94
+ add_filter( 'request', array( &$this, 'handle_requests_orderby_column') );
95
+ add_filter( 'plugin_action_links', array( &$this, 'add_settings_link'), 1, 2);
96
}
97
+
98
/**
99
* Admin Menu.
100
*
116
// Callback
117
array( &$this, 'plugin_settings_page')
118
);
119
+
120
+ // settings page specific styles and scripts
121
add_action( "admin_print_styles-$page", array( &$this, 'admin_styles') );
122
+ add_action( "admin_print_scripts-$page", array( &$this, 'admin_scripts') );
123
}
124
125
/**
143
*/
144
public function register_columns()
145
{
146
+ /** Posts */
147
+ foreach ( $this->post_types as $post_type ) {
148
+
149
// register column per post type
150
+ add_filter("manage_edit-{$post_type}_columns", array(&$this, 'callback_add_posts_column'));
151
152
// register column as sortable
153
+ add_filter( "manage_edit-{$post_type}_sortable_columns", array(&$this, 'callback_add_sortable_posts_column'));
154
+ }
155
+
156
+ /** Users */
157
+ add_filter( "manage_users_columns", array(&$this, 'callback_add_users_column'));
158
+ add_filter( "manage_users_sortable_columns", array(&$this, 'callback_add_sortable_users_column'));
159
}
160
161
/**
162
+ * Callback add Posts Column
163
*
164
* @since 1.0
165
*/
166
+ public function callback_add_posts_column($columns)
167
+ {
168
global $post_type;
169
+
170
+ return $this->add_managed_columns($post_type, $columns);
171
}
172
173
/**
174
+ * Callback add Users column
175
*
176
+ * @since 1.1
177
*/
178
+ public function callback_add_users_column($columns)
179
+ {
180
+ return $this->add_managed_columns('wp-users', $columns);
181
}
182
183
/**
184
+ * Add managed columns by Type
185
*
186
+ * @since 1.1
187
*/
188
+ private function add_managed_columns( $type = 'post', $columns )
189
{
190
+ // only get stored columns.. the rest we don't need
191
+ $db_columns = $this->get_stored_columns($type);
192
+
193
+ if ( !$db_columns )
194
+ return $columns;
195
+
196
+ // filter already loaded columns by plugins
197
+ $set_columns = $this->filter_preset_columns($columns, $type);
198
+
199
+ // loop through columns
200
+ foreach ( $db_columns as $id => $values ) {
201
202
+ // is active
203
+ if ( isset($values['state']) && $values['state'] == 'on' ){
204
+
205
+ // register format
206
+ $set_columns[$id] = $values['label'];
207
+ }
208
}
209
210
+ return $set_columns;
211
+ }
212
+
213
+ /**
214
+ * Callback add Posts sortable column
215
+ *
216
+ * @since 1.0
217
+ */
218
+ public function callback_add_sortable_posts_column($columns)
219
+ {
220
+ global $post_type;
221
222
+ return $this->add_managed_sortable_columns($post_type, $columns);
223
}
224
225
+ /**
226
+ * Callback add Users sortable column
227
+ *
228
+ * @since 1.1
229
+ */
230
+ public function callback_add_sortable_users_column($columns)
231
+ {
232
+ return $this->add_managed_sortable_columns('wp-users', $columns);
233
+ }
234
+
235
+ /**
236
+ * Add managed sortable columns by Type
237
+ *
238
+ * @since 1.1
239
+ */
240
+ private function add_managed_sortable_columns( $type = 'post', $columns )
241
+ {
242
+ $display_columns = $this->get_merged_columns($type);
243
+
244
+ if ( ! $display_columns )
245
+ return $columns;
246
+
247
+ foreach ( $display_columns as $id => $vars ) {
248
+ if ( isset($vars['options']['sortorder']) && $vars['options']['sortorder'] == 'on' ){
249
+
250
+ // register format
251
+ $columns[$id] = $this->sanitize_string($vars['label']);
252
+ }
253
+ }
254
+ return $columns;
255
+ }
256
+
257
/**
258
* Get a list of Column options per post type
259
*
260
* @since 1.0
261
*/
262
+ private function get_column_boxes($type)
263
{
264
// merge all columns
265
+ $display_columns = $this->get_merged_columns($type);
266
+
267
// define
268
$list = '';
269
270
// loop throught the active columns
271
if ( $display_columns ) {
272
+ foreach ( $display_columns as $id => $values ) {
273
274
// add items to the list
275
+ $list .= $this->get_box($type, $id, $values);
276
277
}
278
}
279
280
// custom field button
281
$button_add_column = '';
282
+ if ( $this->get_meta_by_type($type) )
283
$button_add_column = "<a href='javacript:;' class='cpac-add-customfield-column button'>+ " . __('Add Custom Field Column') . "</a>";
284
285
return "
288
{$list}
289
</ul>
290
{$button_add_column}
291
+ <div class='cpac-reorder-msg'>" . __('drag and drop to reorder', $this->textdomain) . "</div>
292
</div>
293
";
294
}
298
*
299
* @since 1.0
300
*/
301
+ private function get_merged_columns( $type )
302
{
303
//get saved database columns
304
+ $db_columns = $this->get_stored_columns($type);
305
+
306
+ /** Users */
307
+ if ( $type == 'wp-users' ) {
308
+ $wp_default_columns = $this->get_wp_default_users_columns();
309
+ $wp_custom_columns = $this->get_custom_users_columns();
310
+ }
311
312
+ /** Posts */
313
+ else {
314
+ $wp_default_columns = $this->get_wp_default_posts_columns($type);
315
+ $wp_custom_columns = $this->get_custom_posts_columns($type);
316
+ }
317
+
318
+ // merge columns
319
$default_columns = wp_parse_args($wp_custom_columns, $wp_default_columns);
320
+
321
// loop throught the active columns
322
if ( $db_columns ) {
323
+
324
+ // let's remove any unavailable columns.. such as disabled plugins
325
+ $db_columns = $this->remove_unavailable_columns($db_columns, $default_columns);
326
+
327
+ foreach ( $db_columns as $id => $values ) {
328
329
// get column meta options from custom columns
330
+ if ( $this->is_column_meta($id) )
331
+ $db_columns[$id]['options'] = $wp_custom_columns['column-meta-1']['options'];
332
333
// add static options
334
+ elseif ( isset($default_columns[$id]['options']) )
335
+ $db_columns[$id]['options'] = $default_columns[$id]['options'];
336
337
+ unset($default_columns[$id]);
338
}
339
}
340
341
// merge all
342
+ $display_columns = wp_parse_args($db_columns, $default_columns);
343
+
344
return $display_columns;
345
}
346
+
347
+ /**
348
+ * Remove deactivated (plugin) columns
349
+ *
350
+ * This will remove any columns that have been stored, but are no longer available. This happends
351
+ * when plugins are deactivated or when they are removed from the theme functions.
352
+ *
353
+ * @since 1.2
354
+ */
355
+ private function remove_unavailable_columns( array $db_columns, array $default_columns)
356
+ {
357
+ // check or differences
358
+ $diff = array_diff( array_keys($db_columns), array_keys($default_columns) );
359
+ if ( ! empty($diff) && is_array($diff) ) {
360
+ foreach ( $diff as $column_name ){
361
+ // make an exception for column-meta-xxx
362
+ if ( ! $this->is_column_meta($column_name) ) {
363
+ unset($db_columns[$column_name]);
364
+ }
365
+ }
366
+ }
367
+
368
+ return $db_columns;
369
+ }
370
+
371
/**
372
* Get checkbox
373
*
374
* @since 1.0
375
*/
376
+ private function get_box($type, $id, $values)
377
{
378
$classes = array();
379
380
// set state
381
$state = isset($values['state']) ? $values['state'] : '';
382
383
// class
384
+ $classes[] = "cpac-box-{$id}";
385
if ( $state )
386
$classes[] = 'active';
387
if ( ! empty($values['options']['class']) )
389
$class = implode(' ', $classes);
390
391
// more box options
392
+ $more_options = $this->get_additional_box_options($type, $id, $values);
393
$action = "<a class='cpac-action' href='#open'>open</a>";
394
+
395
+ // type label
396
+ $type_label = isset($values['options']['type_label']) ? $values['options']['type_label'] : '';
397
+
398
+ // label
399
+ $label = isset($values['label']) ? str_replace("'", '"', $values['label']) : '';
400
401
// hide box options
402
+ if ( ! empty($values['options']['hide_options']) || strpos($label, '<img') !== false ) {
403
$action = $more_options = '';
404
}
405
409
<div class='cpac-type-options'>
410
411
<div class='cpac-checkbox'></div>
412
+ <input type='hidden' class='cpac-state' name='cpac_options[columns][{$type}][{$id}][state]' value='{$state}'/>
413
<label class='main-label'>{$values['label']}</label>
414
</div>
415
<div class='cpac-meta-title'>
416
{$action}
417
+ <span>{$type_label}</span>
418
</div>
419
<div class='cpac-type-inside'>
420
+ <label for='cpac_options[columns][{$type}][{$id}][label]'>Label: </label>
421
+ <input type='text' name='cpac_options[columns][{$type}][{$id}][label]' value='{$label}' class='text'/>
422
<br/>
423
{$more_options}
424
</div>
433
*
434
* @since 1.0
435
*/
436
+ private function get_additional_box_options($post_type, $id, $values)
437
{
438
$fields = '';
439
440
// Custom Fields
441
+ if ( $this->is_column_meta($id) )
442
+ $fields .= $this->get_box_options_customfields($post_type, $id, $values);
443
444
return $fields;
445
}
449
*
450
* @since 1.0
451
*/
452
+ private function get_box_options_customfields($type, $id, $values)
453
{
454
// get post meta fields
455
+ $fields = $this->get_meta_by_type($type);
456
457
if ( empty($fields) )
458
return false;
479
'library_id' => __('Media Library Icon', $this->textdomain),
480
'excerpt' => __('Excerpt'),
481
'array' => __('Multiple Values', $this->textdomain),
482
+ 'numeric' => __('Numeric', $this->textdomain),
483
);
484
485
+ // add filter
486
+ $fieldtypes = apply_filters('cpac-field-types', $fieldtypes );
487
+
488
+ // set select options
489
foreach ( $fieldtypes as $fkey => $fieldtype ) {
490
$fieldtype_options .= sprintf
491
(
496
);
497
}
498
499
+ // before and after string
500
+ $before = ! empty($values['before']) ? $values['before'] : '' ;
501
+ $after = ! empty($values['after']) ? $values['after'] : '' ;
502
+
503
if ( empty($field_options) )
504
return false;
505
506
// add remove button
507
$remove = '<p class="remove-description description">'.__('This field can not be removed', $this->textdomain).'</p>';
508
+ if ( $id != 'column-meta-1') {
509
$remove = "
510
<p>
511
<a href='javascript:;' class='cpac-delete-custom-field-box'>".__('Remove')."</a>
514
}
515
516
$inside = "
517
+ <label for='cpac_options[columns][{$type}][{$id}][field]'>Custom Field: </label>
518
+ <select name='cpac_options[columns][{$type}][{$id}][field]'>{$field_options}</select>
519
<br/>
520
+ <label for='cpac_options[columns][{$type}][{$id}][field_type]'>Field Type: </label>
521
+ <select name='cpac_options[columns][{$type}][{$id}][field_type]'>{$fieldtype_options}</select>
522
<br/>
523
+ <label for='cpac_options[columns][{$type}][{$id}][before]'>Before: </label>
524
+ <input type='text' class='cpac-before' name='cpac_options[columns][{$type}][{$id}][before]' value='{$before}'/>
525
+ <br/>
526
+ <label for='cpac_options[columns][{$type}][{$id}][before]'>After: </label>
527
+ <input type='text' class='cpac-after' name='cpac_options[columns][{$type}][{$id}][after]' value='{$after}'/>
528
+ <br/>
529
{$remove}
530
";
531
533
}
534
535
/**
536
+ * Get post meta fields by type; post(types) or users.
537
*
538
* @since 1.0
539
*/
540
+ private function get_meta_by_type($type = 'post')
541
{
542
global $wpdb;
543
544
+ /** Users */
545
+ if ( $type == 'wp-users') {
546
+ $sql = 'SELECT DISTINCT meta_key FROM '.$wpdb->usermeta.' ORDER BY 1';
547
+ }
548
+
549
+ /** Posts */
550
+ else {
551
+ $sql = 'SELECT DISTINCT meta_key FROM '.$wpdb->postmeta.' pm JOIN '.$wpdb->posts.' p ON pm.post_id = p.ID WHERE p.post_type = "' . mysql_real_escape_string($type) . '" ORDER BY 1';
552
+ }
553
+
554
+ // run sql
555
+ $fields = $wpdb->get_results($sql, ARRAY_N);
556
+
557
// postmeta
558
if ( $fields ) {
559
$meta_fields = array();
563
$meta_fields[] = $field[0];
564
}
565
}
566
return $meta_fields;
567
+ }
568
569
return false;
570
}
574
*
575
* @since 1.0
576
*/
577
+ public function admin_scripts()
578
{
579
+ wp_enqueue_script( 'cpac-admin', $this->plugin_url('/assets/js/admin-column.js'), array('jquery', 'dashboard', 'jquery-ui-sortable'), CPAC_VERSION );
580
}
581
+
582
+ /**
583
+ * Get column types
584
+ *
585
+ * @since 1.1
586
+ */
587
+ private function get_types()
588
+ {
589
+ $types = $this->post_types;
590
+ $types['wp-users'] = 'wp-users';
591
+
592
+ return $types;
593
+ }
594
+
595
/**
596
* Get post types
597
*
636
public function register_settings()
637
{
638
// If we have no options in the database, let's add them now.
639
+ if ( false === get_option('cpac_options') )
640
add_option( 'cpac_options', array(&$this, 'get_default_plugin_options') );
641
642
register_setting( 'cpac-settings-group', 'cpac_options', array(&$this, 'options_callback') );
657
}
658
659
/**
660
+ * Optional callback.
661
*
662
* @since 1.0
663
*/
671
*
672
* @since 1.0
673
*/
674
+ public function handle_requests()
675
{
676
// settings updated
677
+ if ( ! empty($_REQUEST['settings-updated']) )
678
+ $this->store_wp_default_columns();
679
680
// restore defaults
681
+ if ( ! empty($_REQUEST['cpac-restore-defaults']) )
682
$this->restore_defaults();
683
+
684
+ }
685
+
686
+ /**
687
+ * Stores WP default columns
688
+ *
689
+ * This will store columns that are set by WordPress core or
690
+ * set by the theme for page, post(types) and user columns
691
+ *
692
+ * @since 1.2
693
+ */
694
+ private function store_wp_default_columns()
695
+ {
696
+ // stores the default columns that are set by WP or set in the theme.
697
+ $wp_default_columns = array();
698
+
699
+ // Posts
700
+ foreach ( $this->post_types as $post_type ) {
701
+ $wp_default_columns[$post_type] = $this->get_wp_default_posts_columns($post_type);
702
+ }
703
+
704
+ // Users
705
+ $wp_default_columns['wp-users'] = $this->get_wp_default_users_columns();
706
+
707
+ update_option( 'cpac_options_default', $wp_default_columns );
708
}
709
710
/**
723
*
724
* @since 1.0
725
*/
726
+ private function get_post_excerpt($post_id)
727
{
728
+ global $post;
729
+
730
$save_post = $post;
731
$post = get_post($post_id);
732
$excerpt = get_the_excerpt();
733
$post = $save_post;
734
735
+ $output = $this->get_shortened_string($excerpt, $this->excerpt_length );
736
737
return $output;
738
}
765
*
766
* @since 1.0
767
*/
768
+ public function manage_posts_column_value($column_name, $post_id)
769
{
770
+ $type = $column_name;
771
772
// Check for taxonomies, such as column-taxonomy-[taxname]
773
if ( strpos($type, 'column-taxonomy-') !== false )
774
$type = 'column-taxonomy';
775
776
// Check for custom fields, such as column-meta-[customfieldname]
777
+ if ( $this->is_column_meta($type) )
778
+ $type = 'column-post-meta';
779
780
// Hook
781
+ do_action('cpac-manage-posts-column', $type, $column_name, $post_id);
782
783
// Switch Types
784
$result = '';
821
case "column-page-template" :
822
// file name
823
$page_template = get_post_meta($post_id, '_wp_page_template', true);
824
+
825
+ // get template nice name
826
+ $result = array_search($page_template, get_page_templates());
827
break;
828
829
// Slug
831
$result = get_post($post_id)->post_name;
832
break;
833
834
+ // Slug
835
+ case "column-word-count" :
836
+ $result = str_word_count( strip_tags( get_post($post_id)->post_content ) );
837
+ break;
838
+
839
// Taxonomy
840
case "column-taxonomy" :
841
+ $tax = str_replace('column-taxonomy-', '', $column_name);
842
$tags = get_the_terms($post_id, $tax);
843
$tarr = array();
844
if ( $tax == 'post_format' && empty($tags) ) {
853
break;
854
855
// Custom Field
856
+ case "column-post-meta" :
857
+ $result = $this->get_column_value_custom_field($post_id, $column_name, 'post');
858
break;
859
860
// Attachment
861
case "column-attachment" :
862
$result = $this->get_column_value_attachments($post_id);
863
break;
864
+
865
+ // Attachment count
866
+ case "column-attachment-count" :
867
+ $result = count($this->get_attachment_ids($post_id));
868
+ break;
869
870
default :
871
+ $result = get_post_meta( $post_id, $column_name, true );
872
873
endswitch;
874
877
878
echo $result;
879
}
880
+
881
/**
882
+ * Manage custom column for Users.
883
*
884
+ * @since 1.1
885
*/
886
+ public function manage_users_column_value( $value, $column_name, $user_id )
887
{
888
+ $type = $column_name;
889
+
890
+ $userdata = get_userdata( $user_id );
891
+
892
+ if ( ! $userdata )
893
+ return false;
894
+
895
+ // Check for user custom fields, such as column-meta-[customfieldname]
896
+ if ( $this->is_column_meta($type) )
897
+ $type = 'column-user-meta';
898
+
899
+ // Hook
900
+ do_action('cpac-manage-users-column', $type, $column_name, $user_id);
901
+
902
$result = '';
903
+ switch ($type) :
904
+
905
+ // user id
906
+ case "column-user_id" :
907
+ $result = $user_id;
908
+ break;
909
+
910
+ // first name
911
+ case "column-first_name" :
912
+ $result = $userdata->first_name;
913
+ break;
914
+
915
+ // last name
916
+ case "column-last_name" :
917
+ $result = $userdata->last_name;
918
+ break;
919
+
920
+ // user url
921
+ case "column-user_url" :
922
+ $result = $userdata->user_url;
923
+ break;
924
+
925
+ // user registration date
926
+ case "column-user_registered" :
927
+ $result = $userdata->user_registered;
928
+ break;
929
+
930
+ // user description
931
+ case "column-user_description" :
932
+ $result = $this->get_shortened_string( get_the_author_meta('user_description', $user_id), $this->excerpt_length );
933
+ break;
934
+
935
+ // user meta data ( custom field )
936
+ case "column-user-meta" :
937
+ $result = $this->get_column_value_custom_field($user_id, $column_name, 'user');
938
+ break;
939
+
940
+ default :
941
+ $result = get_user_meta( $user_id, $column_name, true );
942
+
943
+ endswitch;
944
+
945
+ if ( empty($result) )
946
+ $result = '&nbsp;';
947
+
948
+ return $result;
949
+ }
950
+
951
+ /**
952
+ * Get column value of post attachments
953
+ *
954
+ * @since 1.0
955
+ */
956
+ private function get_column_value_attachments( $post_id )
957
+ {
958
+ $result = '';
959
+ $attachment_ids = $this->get_attachment_ids($post_id);
960
+ if ( $attachment_ids ) {
961
+ foreach ( $attachment_ids as $attach_id ) {
962
+ $result .= wp_get_attachment_image( $attach_id, array(80,80), true );
963
}
964
}
965
return $result;
966
}
967
968
+ /**
969
+ * Get column value of post attachments
970
+ *
971
+ * @since 1.2.1
972
+ */
973
+ private function get_attachment_ids( $post_id )
974
+ {
975
+ return get_posts(array(
976
+ 'post_type' => 'attachment',
977
+ 'numberposts' => -1,
978
+ 'post_status' => null,
979
+ 'post_parent' => $post_id,
980
+ 'fields' => 'ids'
981
+ ));
982
+ }
983
+
984
/**
985
* Get column value of Custom Field
986
*
987
* @since 1.0
988
+ */
989
+ private function get_column_value_custom_field($object_id, $column_name, $meta_type = 'post')
990
{
991
+ /** Users */
992
+ if ( $meta_type == 'user' ) {
993
+ $type = 'wp-users';
994
+ }
995
+
996
+ /** Posts */
997
+ else {
998
+ $type = get_post_type($object_id);
999
+ }
1000
+
1001
+ // get column
1002
+ $columns = $this->get_stored_columns($type);
1003
+
1004
+ // inputs
1005
+ $field = isset($columns[$column_name]['field']) ? $columns[$column_name]['field'] : '';
1006
+ $fieldtype = isset($columns[$column_name]['field_type']) ? $columns[$column_name]['field_type'] : '';
1007
+ $before = isset($columns[$column_name]['before']) ? $columns[$column_name]['before'] : '';
1008
+ $after = isset($columns[$column_name]['after']) ? $columns[$column_name]['after'] : '';
1009
1010
// Get meta field value
1011
+ $meta = get_metadata($meta_type, $object_id, $field, true);
1012
1013
// multiple meta values
1014
if ( ( $fieldtype == 'array' && is_array($meta) ) || is_array($meta) ) {
1015
+ $meta = get_metadata($meta_type, $object_id, $field, true);
1016
$meta = $this->recursive_implode(', ', $meta);
1017
}
1018
1036
1037
// Excerpt
1038
case "excerpt" :
1039
+ $meta = $this->get_shortened_string($meta, $this->excerpt_length);
1040
+ break;
1041
+
1042
+ endswitch;
1043
+
1044
+ // add before and after string
1045
+ $meta = "{$before}{$meta}{$after}";
1046
+
1047
+ return $meta;
1048
+ }
1049
+
1050
+ /**
1051
+ * Get column value of Custom Field
1052
+ *
1053
+ * @since 1.2
1054
+ */
1055
+ private function get_user_column_value_custom_field($user_id, $id)
1056
+ {
1057
+ $columns = $this->get_stored_columns('wp-users');
1058
+
1059
+ // inputs
1060
+ $field = isset($columns[$id]['field']) ? $columns[$id]['field'] : '';
1061
+ $fieldtype = isset($columns[$id]['field_type']) ? $columns[$id]['field_type'] : '';
1062
+ $before = isset($columns[$id]['before']) ? $columns[$id]['before'] : '';
1063
+ $after = isset($columns[$id]['after']) ? $columns[$id]['after'] : '';
1064
+
1065
+ // Get meta field value
1066
+ $meta = get_user_meta($user_id, $field, true);
1067
+
1068
+ // multiple meta values
1069
+ if ( ( $fieldtype == 'array' && is_array($meta) ) || is_array($meta) ) {
1070
+ $meta = get_user_meta($user_id, $field);
1071
+ $meta = $this->recursive_implode(', ', $meta);
1072
+ }
1073
+
1074
+ // make sure there are no serialized arrays or empty meta data
1075
+ if ( empty($meta) || !is_string($meta) )
1076
+ return false;
1077
+
1078
+ // handles each field type differently..
1079
+ switch ($fieldtype) :
1080
+
1081
+ // Image
1082
+ case "image" :
1083
+ $meta = $this->get_thumbnail($meta);
1084
+ break;
1085
+
1086
+ // Media Library ID
1087
+ case "library_id" :
1088
+ $meta = wp_get_attachment_url($meta) ? wp_get_attachment_image( $meta, array(80,80), true ) : '';
1089
+ break;
1090
+
1091
+ // Excerpt
1092
+ case "excerpt" :
1093
+ $meta = $this->get_shortened_string($meta, $this->excerpt_length);
1094
break;
1095
1096
endswitch;
1097
1098
+ // add before and after string
1099
+ $meta = "{$before}{$meta}{$after}";
1100
+
1101
return $meta;
1102
}
1103
1116
$retVal[] = $r_pieces;
1117
}
1118
}
1119
+ if ( isset($retVal) && is_array($retVal) )
1120
+ return implode( $glue, $retVal );
1121
1122
+ return false;
1123
+ }
1124
1125
/**
1126
* Set columns. These columns apply either for every post or set by a plugin.
1127
*
1128
* @since 1.0
1129
*/
1130
+ private function filter_preset_columns($columns, $type = 'post')
1131
{
1132
+ $options = get_option('cpac_options_default');
1133
1134
if ( !$options )
1135
return $columns;
1136
1137
// we use the wp default columns for filtering...
1138
+ $stored_wp_default_columns = $options[$type];
1139
1140
// ... the ones that are set by plugins, theme functions and such.
1141
+ $dif_columns = array_diff(array_keys($columns), array_keys($stored_wp_default_columns));
1142
+
1143
// we add those to the columns
1144
$pre_columns = array();
1145
if ( $dif_columns ) {
1149
}
1150
1151
return $pre_columns;
1152
+ }
1153
1154
/**
1155
+ * Get WP default supported admin columns per post type.
1156
*
1157
* @since 1.0
1158
*/
1159
+ private function get_wp_default_posts_columns($post_type = 'post')
1160
{
1161
+ // load dependencies
1162
1163
+ // deprecated as of wp3.3
1164
+ if ( file_exists(ABSPATH . 'wp-admin/includes/template.php') )
1165
+ require_once(ABSPATH . 'wp-admin/includes/template.php');
1166
1167
+ // introduced since wp3.3
1168
+ if ( file_exists(ABSPATH . 'wp-admin/includes/screen.php') )
1169
+ require_once(ABSPATH . 'wp-admin/includes/screen.php');
1170
+
1171
+ // used for getting columns
1172
+ if ( file_exists(ABSPATH . 'wp-admin/includes/class-wp-list-table.php') )
1173
+ require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
1174
+ if ( file_exists(ABSPATH . 'wp-admin/includes/class-wp-posts-list-table.php') )
1175
+ require_once(ABSPATH . 'wp-admin/includes/class-wp-posts-list-table.php');
1176
1177
// we need to change the current screen
1178
global $current_screen;
1184
// ...so we can get its columns
1185
$columns = WP_Posts_List_Table::get_columns();
1186
1187
+ if ( empty ( $columns ) )
1188
+ return false;
1189
+
1190
+ // change to uniform format
1191
+ $posts_columns = $this->get_uniform_format($columns);
1192
+
1193
+ // reset current screen
1194
+ $current_screen = $org_current_screen;
1195
+
1196
+ return $posts_columns;
1197
+ }
1198
+
1199
+ /**
1200
+ * Get WP default users columns per post type.
1201
+ *
1202
+ * @since 1.1
1203
+ */
1204
+ private function get_wp_default_users_columns()
1205
+ {
1206
+ if ( file_exists(ABSPATH . 'wp-admin/includes/class-wp-list-table.php') )
1207
+ require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
1208
+ if ( file_exists(ABSPATH . 'wp-admin/includes/class-wp-users-list-table.php') )
1209
+ require_once(ABSPATH . 'wp-admin/includes/class-wp-users-list-table.php');
1210
+
1211
+ // turn off site users
1212
+ $this->is_site_users = false;
1213
+
1214
+ // get users columns
1215
+ $columns = WP_Users_List_Table::get_columns();
1216
+
1217
+ // change to uniform format
1218
+ $users_columns = $this->get_uniform_format($columns);
1219
+
1220
+ return $users_columns;
1221
+ }
1222
+
1223
+ /**
1224
+ * Build uniform format for all columns
1225
+ *
1226
+ * @since 1.0
1227
+ */
1228
+ private function get_uniform_format($columns)
1229
+ {
1230
// we remove the checkbox column as an option...
1231
+ if ( isset($columns['cb']) )
1232
+ unset($columns['cb']);
1233
1234
// change to uniform format
1235
$uniform_columns = array();
1236
+ foreach ( (array) $columns as $id => $label ) {
1237
$hide_options = false;
1238
$type_label = $label;
1239
1242
$type_label = __('Comments', $this->textdomain);
1243
$hide_options = true;
1244
}
1245
+
1246
+ $uniform_colums[$id] = array(
1247
'label' => $label,
1248
'state' => 'on',
1249
'options' => array(
1253
)
1254
);
1255
}
1256
return $uniform_colums;
1257
}
1258
+
1259
/**
1260
+ * Custom posts columns
1261
*
1262
* @since 1.0
1263
*/
1264
+ private function get_custom_posts_columns($post_type)
1265
{
1266
$custom_columns = array();
1267
1268
// Thumbnail support
1269
if ( post_type_supports($post_type, 'thumbnail') ) {
1270
+ $custom_columns['column-featured_image'] = array(
1271
'label' => __('Featured Image', $this->textdomain),
1272
'options' => array(
1273
'type_label' => __('Image', $this->textdomain)
1274
)
1275
+ );
1276
}
1277
1278
// Excerpt support
1279
if ( post_type_supports($post_type, 'editor') ) {
1280
+ $custom_columns['column-excerpt'] = array(
1281
'label' => __('Excerpt', $this->textdomain),
1282
'options' => array(
1283
'type_label' => __('Excerpt', $this->textdomain)
1284
)
1285
+ );
1286
}
1287
1288
// Sticky support
1289
if ( $post_type == 'post' ) {
1290
+ $custom_columns['column-sticky'] = array(
1291
'label' => __('Sticky', $this->textdomain),
1292
'options' => array(
1293
'type_label' => __('Sticky', $this->textdomain)
1294
)
1295
+ );
1296
}
1297
1298
// Order support
1299
if ( post_type_supports($post_type, 'page-attributes') ) {
1300
+ $custom_columns['column-order'] = array(
1301
+ 'label' => __('Page Order', $this->textdomain),
1302
'options' => array(
1303
+ 'type_label' => __('Order', $this->textdomain),
1304
+ 'sortorder' => 'on',
1305
)
1306
+ );
1307
}
1308
1309
// Page Template
1310
if ( $post_type == 'page' ) {
1311
+ $custom_columns['column-page-template'] = array(
1312
'label' => __('Page Template', $this->textdomain),
1313
'options' => array(
1314
+ 'type_label' => __('Page Template', $this->textdomain),
1315
+ 'sortorder' => 'on',
1316
)
1317
+ );
1318
}
1319
1320
// Post Formats
1321
if ( post_type_supports($post_type, 'post-formats') ) {
1322
+ $custom_columns['column-post_formats'] = array(
1323
'label' => __('Post Format', $this->textdomain),
1324
'options' => array(
1325
'type_label' => __('Post Format', $this->textdomain)
1326
)
1327
+ );
1328
}
1329
1330
// Taxonomy support
1332
if ( $taxonomies ) {
1333
foreach ( $taxonomies as $tax_slug => $tax ) {
1334
if ( $tax_slug != 'post_tag' && $tax_slug != 'category' && $tax_slug != 'post_format' ) {
1335
+ $custom_columns['column-taxonomy-'.$tax->name] = array(
1336
'label' => $tax->label,
1337
'options' => array(
1338
'type_label' => __('Taxonomy', $this->textdomain)
1339
)
1340
+ );
1341
}
1342
}
1343
}
1344
1345
// Post ID support
1346
+ $custom_columns['column-postid'] = array(
1347
+ 'label' => 'ID',
1348
'options' => array(
1349
'type_label' => 'ID',
1350
+ 'sortorder' => 'on',
1351
)
1352
+ );
1353
1354
// Slug support
1355
+ $custom_columns['column-page-slug'] = array(
1356
'label' => __('Slug', $this->textdomain),
1357
'options' => array(
1358
'type_label' => __('Slug', $this->textdomain),
1359
+ 'sortorder' => 'on',
1360
+ )
1361
+ );
1362
+
1363
+ // Word count support
1364
+ $custom_columns['column-word-count'] = array(
1365
+ 'label' => __('Word count', $this->textdomain),
1366
+ 'options' => array(
1367
+ 'type_label' => __('Word count', $this->textdomain),
1368
+ 'sortorder' => 'on'
1369
)
1370
+ );
1371
1372
// Attachment support
1373
+ $custom_columns['column-attachment'] = array(
1374
'label' => __('Attachment', $this->textdomain),
1375
'options' => array(
1376
+ 'type_label' => __('Attachment', $this->textdomain),
1377
+ 'sortorder' => 'on'
1378
+ )
1379
+ );
1380
+
1381
+ // Attachment count support
1382
+ $custom_columns['column-attachment-count'] = array(
1383
+ 'label' => __('No. of Attachments', $this->textdomain),
1384
+ 'options' => array(
1385
+ 'type_label' => __('No. of Attachments', $this->textdomain),
1386
+ 'sortorder' => 'on'
1387
)
1388
+ );
1389
1390
// Custom Field support
1391
+ if ( $this->get_meta_by_type($post_type) ) {
1392
+ $custom_columns['column-meta-1'] = array(
1393
'label' => __('Custom Field', $this->textdomain),
1394
'field' => '',
1395
'field_type' => '',
1396
+ 'before' => '',
1397
+ 'after' => '',
1398
'options' => array(
1399
'type_label' => __('Field', $this->textdomain),
1400
+ 'class' => 'cpac-box-metafield',
1401
+ 'sortorder' => 'on',
1402
)
1403
+ );
1404
}
1405
1406
+ // merge with defaults
1407
+ $custom_columns = $this->parse_defaults($custom_columns);
1408
+
1409
+ return apply_filters('cpac-custom-posts-columns', $custom_columns);
1410
+ }
1411
+
1412
+ /**
1413
+ * Custom users columns
1414
+ *
1415
+ * @since 1.1
1416
+ */
1417
+ private function get_custom_users_columns()
1418
+ {
1419
+