Admin Columns - Version 1.4.7

Version Description

  • ready for WP 3.5
  • added support for custom fields for Media
  • added color to the custom field types
  • fixed default sorting for Post(types) and Media
  • fixed problem with different date formats in custom fields. all dates will parsed by strtotime() now.
  • fixed bug which could trigger a conflict when saving the setting on other plugins
  • fixed bug when returning an admin class atrribute
  • improved perfomance on post count on user overview screen
Download this release

Release Info

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

Code changes from version 1.4.6.4 to 1.4.7

assets/css/admin-column.css CHANGED
@@ -214,7 +214,7 @@
214
  }
215
  #general-cpac-settings .cpac-option-list li .cpac-type-inside input,
216
  #general-cpac-settings .cpac-option-list li .cpac-type-inside select {
217
- min-width: 184px;
218
  }
219
  #general-cpac-settings .cpac-option-list li .cpac-type-inside input.input-width {
220
  min-width: 25px;
@@ -301,6 +301,27 @@
301
  border-bottom: none;
302
  border-top: none;
303
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
304
  #cpac-box-plugin_settings table.addons {
305
  /* max-width: 620px; */
306
  }
@@ -362,21 +383,6 @@
362
  float: left;
363
  width: 220px;
364
  }
365
- #cpac-box-plugin_settings table.addons .button {
366
- position: relative;
367
- }
368
- #cpac-box-plugin_settings table.addons .button.loading {
369
- padding-right: 25px;
370
- }
371
- #cpac-box-plugin_settings table.addons .button.loading span {
372
- position: absolute;
373
- top: 2px;
374
- right: 6px;
375
- background: transparent url('../images/loading.gif') no-repeat right 50%;
376
- width: 16px;
377
- height: 16px;
378
- display: inline-block;
379
- }
380
 
381
  /* =Restore settings
382
  -------------------------------------------------------------- */
@@ -405,8 +411,14 @@
405
  -------------------------------------------------------------- */
406
  #addons-cpac-settings {
407
  overflow: hidden;
408
- background-color: #CCFFCC;
409
- background-image: -moz-linear-gradient(center top , #c3f5c2, #CCFFCC );
 
 
 
 
 
 
410
  border-color: green;
411
  }
412
  #addons-cpac-settings h3 {
@@ -501,6 +513,50 @@
501
  padding: 0 6px;
502
  }
503
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
504
  /* =Tooltip
505
  -------------------------------------------------------------- */
506
  .qtip .qtip-tip {
214
  }
215
  #general-cpac-settings .cpac-option-list li .cpac-type-inside input,
216
  #general-cpac-settings .cpac-option-list li .cpac-type-inside select {
217
+ width: 184px;
218
  }
219
  #general-cpac-settings .cpac-option-list li .cpac-type-inside input.input-width {
220
  min-width: 25px;
301
  border-bottom: none;
302
  border-top: none;
303
  }
304
+ #cpac-box-plugin_settings .button {
305
+ position: relative;
306
+ }
307
+ #cpac-box-plugin_settings .button.loading {
308
+ padding-right: 25px;
309
+ }
310
+ #cpac-box-plugin_settings .button.loading span {
311
+ position: absolute;
312
+ top: 2px;
313
+ right: 6px;
314
+ background: transparent url('../images/loading.gif') no-repeat right 50%;
315
+ width: 16px;
316
+ height: 16px;
317
+ display: inline-block;
318
+ }
319
+ #cpac-box-plugin_settings td.first-col {
320
+ width: 18%;
321
+ }
322
+
323
+ /* =Addon settings
324
+ -------------------------------------------------------------- */
325
  #cpac-box-plugin_settings table.addons {
326
  /* max-width: 620px; */
327
  }
383
  float: left;
384
  width: 220px;
385
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
386
 
387
  /* =Restore settings
388
  -------------------------------------------------------------- */
411
  -------------------------------------------------------------- */
412
  #addons-cpac-settings {
413
  overflow: hidden;
414
+ background: #ccffcc;
415
+ background: -moz-linear-gradient(top, #c3f5c2 1%, #ccffcc 100%); /* FF3.6+ */
416
+ background: -webkit-gradient(linear, left top, left bottom, color-stop(1%,#c3f5c2), color-stop(100%,#ccffcc)); /* Chrome,Safari4+ */
417
+ background: -webkit-linear-gradient(top, #c3f5c2 1%,#ccffcc 100%); /* Chrome10+,Safari5.1+ */
418
+ background: -o-linear-gradient(top, #c3f5c2 1%,#ccffcc 100%); /* Opera 11.10+ */
419
+ background: -ms-linear-gradient(top, #c3f5c2 1%,#ccffcc 100%); /* IE10+ */
420
+ background: linear-gradient(to bottom, #c3f5c2 1%,#ccffcc 100%); /* W3C */
421
+ filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#c3f5c2', endColorstr='#ccffcc',GradientType=0 ); /* IE6-9 */
422
  border-color: green;
423
  }
424
  #addons-cpac-settings h3 {
513
  padding: 0 6px;
514
  }
515
 
516
+ /* =Import / Export
517
+ -------------------------------------------------------------- */
518
+ div.cpac_export {
519
+ width: 20%;
520
+ float: left;
521
+ }
522
+ #cpac_export_output {
523
+ width: 80%;
524
+ float: left;
525
+ display: none;
526
+ }
527
+ #cpac_export_output textarea {
528
+ width: 100%;
529
+ height: 80%;
530
+ }
531
+ #cpac_export_submit {
532
+ display: inline-block;
533
+ margin: 10px 0;
534
+ }
535
+ #cpac_import_input {}
536
+ #cpac_import_input textarea {
537
+ width: 100%;
538
+ height: 80%;
539
+ }
540
+ #cpac_import_submit {
541
+ display: inline-block;
542
+ margin: 10px 0;
543
+ }
544
+ .export-message,
545
+ .import-message {
546
+ background-color: #FFFFE0;
547
+ border: 1px solid #E6DB55;
548
+ padding: 4px 6px;
549
+ border-radius: 3px;
550
+ display: none;
551
+ }
552
+
553
+ /* =WP Pointer
554
+ -------------------------------------------------------------- */
555
+ .wp-pointer-content ol {
556
+ margin-left: 1.5em;
557
+ padding: 0 15px;
558
+ }
559
+
560
  /* =Tooltip
561
  -------------------------------------------------------------- */
562
  .qtip .qtip-tip {
assets/css/column.css CHANGED
@@ -14,6 +14,25 @@ span.status-closed {
14
  color: red;
15
  }
16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  /* =Comment Counts column
18
  -------------------------------------------------------------- */
19
  .column-comment-count a.post-com-count {
14
  color: red;
15
  }
16
 
17
+ /* =Color Column
18
+ -------------------------------------------------------------- */
19
+ div.cpac-color {
20
+ line-height: 26px;
21
+ }
22
+ div.cpac-color span {
23
+ border: 1px solid #CCCCCC;
24
+ display: block;
25
+ -webkit-border-radius: 3px;
26
+ border-radius: 3px;
27
+ color: #ffffff;
28
+ float: left;
29
+ height: 16px;
30
+ margin-right: 12px;
31
+ min-width: 30px;
32
+ overflow: hidden;
33
+ padding: 4px 5px;
34
+ }
35
+
36
  /* =Comment Counts column
37
  -------------------------------------------------------------- */
38
  .column-comment-count a.post-com-count {
assets/images/import_export.png ADDED
Binary file
assets/js/admin-column.js CHANGED
@@ -1,424 +1,634 @@
1
- /**
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();
13
- cpac_menu();
14
- cpac_add_custom_column();
15
- cpac_clear_input_defaults();
16
- cpac_tooltips();
17
- cpac_addon_activation();
18
- cpac_width_range();
19
- });
20
-
21
- /**
22
- * sortable
23
- *
24
- */
25
- function cpac_sortable()
26
- {
27
- jQuery('ul.cpac-option-list').sortable({
28
- handle: 'div.cpac-sort-handle',
29
- placeholder: 'cpac-placeholder',
30
- forcePlaceholderSize: true
31
- });
32
- }
33
 
34
- /**
35
- * checked
36
- *
37
- */
38
- function cpac_checked()
39
- {
40
- jQuery('#cpac .cpac-option-list li .cpac-type-options').live({
41
- click: function() {
42
- var li = jQuery(this).closest('li');
43
- var state = jQuery('.cpac-state', li);
44
- var value = state.attr('value');
45
-
46
- // toggle on
47
- if ( value != 'on') {
48
- li.addClass('active');
49
- state.attr('value', 'on');
50
- }
51
-
52
- // toggle off
53
- else {
54
- li.removeClass('active');
55
- state.attr('value', '');
56
- }
57
- }
58
- });
59
- }
60
-
61
- /**
62
- * Open and close box
63
- *
64
- */
65
- function cpac_box_events()
66
- {
67
- // fold in/out
68
- jQuery('#cpac .cpac-option-list .cpac-action').unbind('click').click(function(e){
69
- e.preventDefault();
70
- var li = jQuery(this).closest('li');
71
- li.find('.cpac-type-inside').slideToggle(150, function() {
72
- li.toggleClass('opened');
73
- });
74
- });
75
-
76
- // remove custom field box
77
- jQuery('#cpac .cpac-delete-custom-field-box').unbind('click').click(function(e){
78
- e.preventDefault();
79
- var el = jQuery(this).closest('li');
80
 
81
- el.addClass('deleting').animate({
82
- opacity : 0,
83
- height: 0
84
- }, 350, function() {
85
- el.remove();
86
- });
 
 
 
 
 
 
87
  });
88
- }
89
 
90
- /**
91
- * Menu
92
- *
93
- */
94
- function cpac_menu()
95
- {
96
- // referer
97
- var referer = jQuery("input[type='hidden'][name='_wp_http_referer']");
98
- var referer_value = referer.attr('value');
99
-
100
- // click
101
- jQuery('#cpac .cpac-menu a').click( function(e, el) {
102
- e.preventDefault();
103
- var id = jQuery(this).attr('href');
104
-
105
- if ( id ) {
106
- // remove current
107
- jQuery('#cpac .cpac-menu a').removeClass('current');
108
- jQuery('#cpac .cpac-box-row').hide().removeClass('current');
109
-
110
- // set current
111
- jQuery(this).addClass('current');
112
- jQuery(id).show().addClass('current');
113
-
114
- // set refere
115
- var querystring = '&cpac_type=' + id.replace('#','');
116
- referer.attr('value', referer_value + querystring );
117
- }
118
- });
119
- }
120
 
121
- /**
122
- * add custom columns
123
- *
124
- */
125
- function cpac_add_custom_column()
126
- {
127
- jQuery('.cpac-add-customfield-column').click(function(e){
128
- e.preventDefault();
129
-
130
- var list = jQuery(this).closest('td').find('ul.cpac-option-list');
131
- var metafields = jQuery('li.cpac-box-metafield', list);
132
-
133
- // get unique ID number...
134
- var ids = [];
135
- metafields.each(function(k,v) {
136
- var _class = jQuery(v).attr('class');
137
- var classes = _class.split(' ');
138
- jQuery.each(classes, function(kc,vc){
139
- if ( vc.indexOf('cpac-box-column-meta-') === 0 ) {
140
- var id = vc.replace('cpac-box-column-meta-','');
141
- if ( id )
142
- ids.push(id);
143
- }
144
- });
145
  });
 
146
 
147
- // ...and sort them
148
- ids.sort(sortNumber);
149
-
150
- if ( !ids )
151
- return;
152
-
153
- function sortNumber(a,b) {
154
- return b - a;
155
- }
 
 
 
 
 
156
 
157
- // ID's
158
- var id = parseFloat(ids[0]);
159
- var new_id = id + 1;
 
160
 
161
- // Clone
162
- var clone = jQuery( '.cpac-box-column-meta-' + id, list ).clone();
163
-
164
- // Toggle class
165
- jQuery(clone).removeClass('cpac-box-column-meta-' + id );
166
- jQuery(clone).addClass('cpac-box-column-meta-' + new_id );
167
-
168
- // Replace inputs ID's
169
- var inputs = jQuery(clone).find('input, select');
170
- jQuery(inputs).each(function(ik, iv){
171
- jQuery(iv).attr('name', jQuery(iv).attr('name').replace(id, new_id) );
172
  });
 
 
 
 
 
 
 
 
 
 
 
173
 
174
- // Replace label ID's
175
- var labels = jQuery(clone).find('label');
176
- jQuery(labels).each(function(ik, iv){
177
- var attr_for = jQuery(iv).attr('for');
178
- if ( attr_for ) {
179
- jQuery(iv).attr('for', attr_for.replace(id, new_id) );
180
- }
181
- });
182
-
183
- // remove description
184
- clone.find('.remove-description').remove();
185
-
186
- // change label text
187
- clone.find('label.main-label, .cpac-type-inside input.text').text('Custom Field');
188
- clone.find('.cpac-type-inside input.text').val('Custom Field');
189
-
190
- // add remove button
191
- if ( clone.find('.cpac-delete-custom-field-box').length == 0 ) {
192
- var remove = '<p><a href="javascript:;" class="cpac-delete-custom-field-box">Remove</a>';
193
- clone.find('.cpac-type-inside').append(remove);
194
- }
195
 
196
- // add cloned box to the list
197
- list.append(clone);
198
-
199
- // retrigger click events
200
- cpac_box_events();
201
- });
202
- }
203
 
204
- /**
205
- * Clear Input Defaults
206
- *
207
- */
208
- function cpac_clear_input_defaults()
209
- {
210
- jQuery.fn.cleardefault = function() {
211
- return this.focus(function() {
212
- if( this.value == this.defaultValue ) {
213
- this.value = "";
214
- }
215
- }).blur(function() {
216
- if( !this.value.length ) {
217
- this.value = this.defaultValue;
218
  }
219
  });
220
- };
221
- jQuery("#cpac-box-plugin_settings .addons input").cleardefault();
222
- }
223
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
224
 
225
- /**
226
- * Tooltip
227
- *
228
- */
229
- function cpac_tooltips()
230
- {
231
- jQuery('#cpac .activation_type span').each(function() {
232
- var info = jQuery(this).next('.cpac-tooltip').html();
233
 
234
- if ( ! info )
235
- return;
236
-
237
- jQuery('#cpac .activation_type span').qtip({
238
- content: info,
239
- title: 'title',
240
- style: {
241
- width: 400,
242
- padding: 0,
243
- background: 'transparent',
244
- color: 'black',
245
- textAlign: 'left',
246
- border: {
247
- width: 0,
248
- radius: 0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
249
  },
250
- tip: {
251
- corner: 'topMiddle',
252
- color: '#8cc1e9',
253
- size: {
254
- x: 32,
255
- y : 15
 
256
  }
257
- }
258
- },
259
- position: {
260
- corner: {
261
- target: 'bottomRight'
262
  },
263
- adjust: {
264
- x: -80,
265
- y: 0
 
266
  }
267
- },
268
- hide: {
269
- when: 'mouseout',
270
- fixed: true ,
271
- delay: 100
272
- }
273
- });
274
- });
275
- }
276
 
277
- /**
278
- * Width range
279
- *
280
- */
281
- function cpac_width_range()
282
- {
283
- if ( jQuery('.input-width-range').length == false )
284
- return;
285
-
286
- // loop through all width-range-sliders
287
- jQuery('.input-width-range').each( function(){
288
-
289
- var input = jQuery(this).closest('.cpac-type-inside').find('.input-width');
290
- var descr = jQuery(this).closest('.cpac-type-inside').find('.width-decription');
291
- var input_default = jQuery(input)[0].defaultValue;
292
- var translation_default = descr.attr('title');
293
 
294
- // add slider
295
- jQuery(this).slider({
296
- range: 'min',
297
- value: 1,
298
- min: 0,
299
- max: 100,
300
- value: input_default,
301
- slide: function( event, ui ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
302
 
303
- // set default
304
- var descr_value = ui.value > 0 ? ui.value + '%' : translation_default;
305
 
306
- // set input value
307
- jQuery(input).val( ui.value );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
308
 
309
- // set description
310
- jQuery(descr).text( descr_value );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
311
  }
312
- });
313
- });
314
- }
315
 
316
- /**
317
- * Addon actviate/deactivate
318
- *
319
- */
320
- function cpac_addon_activation()
321
- {
322
- jQuery('#cpac-box-plugin_settings .addons .activation_code a.button').click(function(e) {
323
- e.preventDefault();
324
-
325
- // get input values
326
- var row = jQuery(this).closest('tr');
327
- var type = jQuery(row).attr('id').replace('cpac-activation-','');
328
- var parent_class = jQuery(this).parent('div');
329
- var msg = jQuery(row).find('.activation-error-msg');
330
-
331
- // get translated string
332
- var translations = jQuery('#cpac-box-plugin_settings .addon-translation-string');
333
- var msg_fillin = jQuery('.tstring-fill-in',translations).text();
334
- var msg_unrecognised = jQuery('.tstring-unrecognised',translations).text();
335
-
336
- // reset
337
- jQuery(msg).empty();
338
-
339
- // Activate
340
- if ( parent_class.hasClass('activate') ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
341
 
342
- // get input values
343
- var input = jQuery('.activate input', row);
344
- var button = jQuery('.activate .button', row);
345
- var key = input.val();
346
- var default_val = jQuery(input)[0].defaultValue;
 
347
 
348
- // make sure the input value has changed
349
- if ( key == default_val ) {
350
- jQuery(msg).text(msg_fillin).hide().fadeIn();
351
  return false;
352
- }
353
-
354
- // set loading icon
355
- button.addClass('loading');
356
-
357
- // update key
358
- jQuery.ajax({
359
- url : ajaxurl,
360
- type : 'POST',
361
- dataType : 'json',
362
- data : {
363
- action : 'cpac_addon_activation',
364
- type : 'sortable',
365
- key : key
366
- },
367
- success: function(data) {
368
- if ( data != null ) {
369
- jQuery('div.activate', row).hide(); // hide activation button
370
- jQuery('div.deactivate', row).show(); // show deactivation button
371
- jQuery('div.deactivate span.masked_key', row).text(data); // display the returned masked key
372
- } else {
373
- jQuery(msg).text(msg_unrecognised).hide().fadeIn();
374
- }
375
- },
376
- error: function(xhr, ajaxOptions, thrownError) {
377
- //console.log(xhr);
378
- //console.log(ajaxOptions);
379
- //console.log(thrownError);
380
- jQuery(msg).text(msg_unrecognised).hide().fadeIn();
381
- },
382
- complete: function() {
383
- button.removeClass('loading');
384
- }
385
  });
386
- }
387
-
388
- // Deactivate
389
- if ( parent_class.hasClass('deactivate') ) {
390
 
391
- var button = jQuery('.deactivate .button', row);
392
- var input = jQuery('.activate input', row);
393
-
394
- // set loading icon
395
- button.addClass('loading');
396
-
397
- // update key
398
- jQuery.ajax({
399
- url : ajaxurl,
400
- type : 'POST',
401
- dataType : 'json',
402
- data : {
403
- action : 'cpac_addon_activation',
404
- type : 'sortable',
405
- key : 'remove'
406
- },
407
- success: function(data) {
408
- jQuery('div.activate', row).show(); // show activation button
409
- jQuery('div.deactivate', row).hide(); // hide deactivation button
410
- jQuery('div.deactivate span.masked_key', row).empty(); // remove masked key
411
- input.val('');
412
- },
413
- error: function(xhr, ajaxOptions, thrownError) {
414
- //console.log(xhr);
415
- //console.log(ajaxOptions);
416
- //console.log(thrownError);
417
- },
418
- complete: function() {
419
- button.removeClass('loading');
420
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
421
  });
422
- }
423
- });
424
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (function($){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
+ /**
4
+ * fires when the dom is ready
5
+ *
6
+ */
7
+ $(document).ready(function()
8
+ {
9
+ if ($('#cpac').length == 0)
10
+ return false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
+ cpac_sortable();
13
+ cpac_checked();
14
+ cpac_box_events();
15
+ cpac_menu();
16
+ cpac_add_custom_column();
17
+ cpac_clear_input_defaults();
18
+ cpac_tooltips();
19
+ cpac_addon_activation();
20
+ cpac_width_range();
21
+ cpac_export();
22
+ cpac_import();
23
+ cpac_pointer();
24
  });
 
25
 
26
+ /**
27
+ * sortable
28
+ *
29
+ */
30
+ function cpac_sortable()
31
+ {
32
+ $('ul.cpac-option-list').sortable({
33
+ handle: 'div.cpac-sort-handle',
34
+ placeholder: 'cpac-placeholder',
35
+ forcePlaceholderSize: true
36
+ });
37
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
 
39
+ /**
40
+ * checked
41
+ *
42
+ */
43
+ function cpac_checked()
44
+ {
45
+ $('#cpac .cpac-option-list li .cpac-type-options').live({
46
+ click: function() {
47
+ var li = $(this).closest('li');
48
+ var state = $('.cpac-state', li);
49
+ var value = state.attr('value');
50
+
51
+ // toggle on
52
+ if ( value != 'on') {
53
+ li.addClass('active');
54
+ state.attr('value', 'on');
55
+ }
56
+
57
+ // toggle off
58
+ else {
59
+ li.removeClass('active');
60
+ state.attr('value', '');
61
+ }
62
+ }
63
  });
64
+ }
65
 
66
+ /**
67
+ * Open and close box
68
+ *
69
+ */
70
+ function cpac_box_events()
71
+ {
72
+ // fold in/out
73
+ $('#cpac .cpac-option-list .cpac-action').unbind('click').click(function(e){
74
+ e.preventDefault();
75
+ var li = $(this).closest('li');
76
+ li.find('.cpac-type-inside').slideToggle(150, function() {
77
+ li.toggleClass('opened');
78
+ });
79
+ });
80
 
81
+ // remove custom field box
82
+ $('#cpac .cpac-delete-custom-field-box').unbind('click').click(function(e){
83
+ e.preventDefault();
84
+ var el = $(this).closest('li');
85
 
86
+ el.addClass('deleting').animate({
87
+ opacity : 0,
88
+ height: 0
89
+ }, 350, function() {
90
+ el.remove();
91
+ });
 
 
 
 
 
92
  });
93
+ }
94
+
95
+ /**
96
+ * Menu
97
+ *
98
+ */
99
+ function cpac_menu()
100
+ {
101
+ // referer
102
+ var referer = $("input[type='hidden'][name='_wp_http_referer']");
103
+ var referer_value = referer.attr('value');
104
 
105
+ // click
106
+ $('#cpac .cpac-menu a').click( function(e, el) {
107
+ e.preventDefault();
108
+ var id = $(this).attr('href');
109
+
110
+ if ( id ) {
111
+ // remove current
112
+ $('#cpac .cpac-menu a').removeClass('current');
113
+ $('#cpac .cpac-box-row').hide().removeClass('current');
 
 
 
 
 
 
 
 
 
 
 
 
114
 
115
+ // set current
116
+ $(this).addClass('current');
117
+ $(id).show().addClass('current');
 
 
 
 
118
 
119
+ // set refere
120
+ var querystring = '&cpac_type=' + id.replace('#','');
121
+ referer.attr('value', referer_value + querystring );
 
 
 
 
 
 
 
 
 
 
 
122
  }
123
  });
124
+ }
 
 
125
 
126
+ /**
127
+ * add custom columns
128
+ *
129
+ */
130
+ function cpac_add_custom_column()
131
+ {
132
+ $('.cpac-add-customfield-column').click(function(e){
133
+ e.preventDefault();
134
+
135
+ var list = $(this).closest('td').find('ul.cpac-option-list');
136
+ var metafields = $('li.cpac-box-metafield', list);
137
+
138
+ // get unique ID number...
139
+ var ids = [];
140
+ metafields.each(function(k,v) {
141
+ var _class = $(v).attr('class');
142
+ var classes = _class.split(' ');
143
+ $.each(classes, function(kc,vc){
144
+ if ( vc.indexOf('cpac-box-column-meta-') === 0 ) {
145
+ var id = vc.replace('cpac-box-column-meta-','');
146
+ if ( id )
147
+ ids.push(id);
148
+ }
149
+ });
150
+ });
151
 
152
+ // ...and sort them
153
+ ids.sort(sortNumber);
 
 
 
 
 
 
154
 
155
+ if ( !ids )
156
+ return;
157
+
158
+ function sortNumber(a,b) {
159
+ return b - a;
160
+ }
161
+
162
+ // ID's
163
+ var id = parseFloat(ids[0]);
164
+ var new_id = id + 1;
165
+
166
+ // Clone
167
+ var clone = $( '.cpac-box-column-meta-' + id, list ).clone();
168
+
169
+ // Toggle class
170
+ $(clone).removeClass('cpac-box-column-meta-' + id );
171
+ $(clone).addClass('cpac-box-column-meta-' + new_id );
172
+
173
+ // Replace inputs ID's
174
+ var inputs = $(clone).find('input, select');
175
+ $(inputs).each(function(ik, iv){
176
+ $(iv).attr('name', $(iv).attr('name').replace(id, new_id) );
177
+ });
178
+
179
+ // Replace label ID's
180
+ var labels = $(clone).find('label');
181
+ $(labels).each(function(ik, iv){
182
+ var attr_for = $(iv).attr('for');
183
+ if ( attr_for ) {
184
+ $(iv).attr('for', attr_for.replace(id, new_id) );
185
+ }
186
+ });
187
+
188
+ // remove description
189
+ clone.find('.remove-description').remove();
190
+
191
+ // change label text
192
+ clone.find('label.main-label, .cpac-type-inside input.text').text('Custom Field');
193
+ clone.find('.cpac-type-inside input.text').val('Custom Field');
194
+
195
+ // add remove button
196
+ if ( clone.find('.cpac-delete-custom-field-box').length == 0 ) {
197
+ var remove = '<p><a href="javascript:;" class="cpac-delete-custom-field-box">Remove</a>';
198
+ clone.find('.cpac-type-inside').append(remove);
199
+ }
200
+
201
+ // add cloned box to the list
202
+ list.append(clone);
203
+
204
+ // retrigger click events
205
+ cpac_box_events();
206
+
207
+ // re-init width range slider
208
+ cpac_width_range();
209
+ });
210
+ }
211
+
212
+ /**
213
+ * Clear Input Defaults
214
+ *
215
+ */
216
+ function cpac_clear_input_defaults()
217
+ {
218
+ $.fn.cleardefault = function() {
219
+ return this.focus(function() {
220
+ if( this.value == this.defaultValue ) {
221
+ this.value = "";
222
+ }
223
+ }).blur(function() {
224
+ if( !this.value.length ) {
225
+ this.value = this.defaultValue;
226
+ }
227
+ });
228
+ };
229
+ $("#cpac-box-plugin_settings .addons input").cleardefault();
230
+ }
231
+
232
+
233
+ /**
234
+ * Tooltip
235
+ *
236
+ */
237
+ function cpac_tooltips()
238
+ {
239
+ $('#cpac .activation_type span').each(function() {
240
+ var info = $(this).next('.cpac-tooltip').html();
241
+
242
+ if ( ! info )
243
+ return;
244
+
245
+ $('#cpac .activation_type span').qtip({
246
+ content: info,
247
+ title: 'title',
248
+ style: {
249
+ width: 400,
250
+ padding: 0,
251
+ background: 'transparent',
252
+ color: 'black',
253
+ textAlign: 'left',
254
+ border: {
255
+ width: 0,
256
+ radius: 0
257
+ },
258
+ tip: {
259
+ corner: 'topMiddle',
260
+ color: '#8cc1e9',
261
+ size: {
262
+ x: 32,
263
+ y : 15
264
+ }
265
+ }
266
  },
267
+ position: {
268
+ corner: {
269
+ target: 'bottomRight'
270
+ },
271
+ adjust: {
272
+ x: -80,
273
+ y: 0
274
  }
 
 
 
 
 
275
  },
276
+ hide: {
277
+ when: 'mouseout',
278
+ fixed: true ,
279
+ delay: 100
280
  }
281
+ });
282
+ });
283
+ }
 
 
 
 
 
 
284
 
285
+ /**
286
+ * Width range
287
+ *
288
+ */
289
+ function cpac_width_range()
290
+ {
291
+ if ( $('.input-width-range').length == false )
292
+ return;
 
 
 
 
 
 
 
 
293
 
294
+ // loop through all width-range-sliders
295
+ $('.input-width-range').each( function(){
296
+
297
+ var input = $(this).closest('.cpac-type-inside').find('.input-width');
298
+ var descr = $(this).closest('.cpac-type-inside').find('.width-decription');
299
+ var input_default = $(input)[0].defaultValue;
300
+ var translation_default = descr.attr('title');
301
+
302
+ // add slider
303
+ $(this).slider({
304
+ range: 'min',
305
+ value: 1,
306
+ min: 0,
307
+ max: 100,
308
+ value: input_default,
309
+ slide: function( event, ui ) {
310
+
311
+ // set default
312
+ var descr_value = ui.value > 0 ? ui.value + '%' : translation_default;
313
+
314
+ // set input value
315
+ $(input).val( ui.value );
316
+
317
+ // set description
318
+ $(descr).text( descr_value );
319
+ }
320
+ });
321
+ });
322
+ }
323
+
324
+ /**
325
+ * Addon actviate/deactivate
326
+ *
327
+ */
328
+ function cpac_addon_activation()
329
+ {
330
+ $('#cpac-box-plugin_settings .addons .activation_code a.button').click(function(e) {
331
+ e.preventDefault();
332
+
333
+ // get input values
334
+ var row = $(this).closest('tr');
335
+ var type = $(row).attr('id').replace('cpac-activation-','');
336
+ var parent_class = $(this).parent('div');
337
+ var msg = $(row).find('.activation-error-msg');
338
+
339
+ // get translated string
340
+ var translations = $('#cpac-box-plugin_settings .addon-translation-string');
341
+ var msg_fillin = $('.tstring-fill-in',translations).text();
342
+ var msg_unrecognised = $('.tstring-unrecognised',translations).text();
343
+
344
+ // reset
345
+ $(msg).empty();
346
+
347
+ // Activate
348
+ if ( parent_class.hasClass('activate') ) {
349
+
350
+ // get input values
351
+ var input = $('.activate input', row);
352
+ var button = $('.activate .button', row);
353
+ var key = input.val();
354
+ var default_val = $(input)[0].defaultValue;
355
+
356
+ // make sure the input value has changed
357
+ if ( key == default_val ) {
358
+ $(msg).text(msg_fillin).hide().fadeIn();
359
+ return false;
360
+ }
361
 
362
+ // set loading icon
363
+ button.addClass('loading');
364
 
365
+ // update key
366
+ $.ajax({
367
+ url : ajaxurl,
368
+ type : 'POST',
369
+ dataType : 'json',
370
+ data : {
371
+ action : 'cpac_addon_activation',
372
+ type : 'sortable',
373
+ key : key
374
+ },
375
+ success: function(data) {
376
+ if ( data != null ) {
377
+ $('div.activate', row).hide(); // hide activation button
378
+ $('div.deactivate', row).show(); // show deactivation button
379
+ $('div.deactivate span.masked_key', row).text(data); // display the returned masked key
380
+ } else {
381
+ $(msg).text(msg_unrecognised).hide().fadeIn();
382
+ }
383
+ },
384
+ error: function(xhr, ajaxOptions, thrownError) {
385
+ //console.log(xhr);
386
+ //console.log(ajaxOptions);
387
+ //console.log(thrownError);
388
+ $(msg).text(msg_unrecognised).hide().fadeIn();
389
+ },
390
+ complete: function() {
391
+ button.removeClass('loading');
392
+ }
393
+ });
394
+ }
395
+
396
+ // Deactivate
397
+ if ( parent_class.hasClass('deactivate') ) {
398
+
399
+ var button = $('.deactivate .button', row);
400
+ var input = $('.activate input', row);
401
+
402
+ // set loading icon
403
+ button.addClass('loading');
404
 
405
+ // update key
406
+ $.ajax({
407
+ url : ajaxurl,
408
+ type : 'POST',
409
+ dataType : 'json',
410
+ data : {
411
+ action : 'cpac_addon_activation',
412
+ type : 'sortable',
413
+ key : 'remove'
414
+ },
415
+ success: function(data) {
416
+ $('div.activate', row).show(); // show activation button
417
+ $('div.deactivate', row).hide(); // hide deactivation button
418
+ $('div.deactivate span.masked_key', row).empty(); // remove masked key
419
+ input.val('');
420
+ },
421
+ error: function(xhr, ajaxOptions, thrownError) {
422
+ //console.log(xhr);
423
+ //console.log(ajaxOptions);
424
+ //console.log(thrownError);
425
+ },
426
+ complete: function() {
427
+ button.removeClass('loading');
428
+ }
429
+ });
430
  }
431
+ });
432
+ }
 
433
 
434
+ /**
435
+ * Export Settings
436
+ *
437
+ */
438
+ function cpac_export()
439
+ {
440
+ // Submit Export
441
+ $('#cpac_export_submit').click( function(e){
442
+
443
+ var values = [];
444
+
445
+ // get selected values
446
+ $('#cpac_export_types :selected').each(function(i, selected){
447
+ values[i] = $(selected).val();
448
+ });
449
+
450
+ var btn = $(this);
451
+ var export_container = $('#cpac_export_output');
452
+ var export_textarea = $('textarea', export_container);
453
+ var msg = btn.next('.export-message');
454
+
455
+ // reset
456
+ export_container.hide();
457
+ export_textarea.empty();
458
+ msg.hide();
459
+
460
+ // get export code
461
+ if ( values ) {
462
+
463
+ // set loading icon
464
+ btn.addClass('loading');
465
+
466
+ $.ajax({
467
+ url : ajaxurl,
468
+ type : 'POST',
469
+ dataType : 'json',
470
+ data : {
471
+ action : 'cpac_get_export',
472
+ types : values
473
+ },
474
+ success: function(data) {
475
+ if ( data != null ) {
476
+
477
+ // succes
478
+ if ( 1 == data.status ) {
479
+ export_textarea.text(data.msg);
480
+ export_container.show();
481
+ }
482
+
483
+ // fail
484
+ else if ( data.msg ) {
485
+ msg.text(data.msg).show();
486
+ }
487
+
488
+ } else {
489
+ // error msg
490
+ }
491
+ },
492
+ error: function(xhr, ajaxOptions, thrownError) {},
493
+ complete: function() {
494
+ btn.removeClass('loading');
495
+ }
496
+ });
497
+ }
498
+
499
+ e.preventDefault;
500
+ });
501
 
502
+ // Select Export Code
503
+ $('#cpac_export_output textarea').focus(function() {
504
+ var t = $(this);
505
+ t.select();
506
+
507
+ t.mouseup(function() { // Work around Chrome's little problem
508
 
509
+ t.unbind("mouseup"); // Prevent further mouseup intervention
 
 
510
  return false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
511
  });
512
+ });
513
+ }
 
 
514
 
515
+ /**
516
+ * Import Settings
517
+ *
518
+ */
519
+ function cpac_import()
520
+ {
521
+ $('#cpac_import_submit'). click( function(e){
522
+
523
+ var btn = $(this);
524
+ var import_code = $('#cpac_import_input textarea').val();
525
+ var msg = btn.next('.import-message');
526
+
527
+ btn.addClass('loading');
528
+ msg.hide();
529
+
530
+ if ( import_code ) {
531
+
532
+ $.ajax({
533
+ url : ajaxurl,
534
+ type : 'POST',
535
+ dataType : 'json',
536
+ data : {
537
+ action : 'cpac_import',
538
+ import_code : import_code
539
+ },
540
+ success: function(data) {
541
+ if ( data != null ) {
542
+
543
+ // succes
544
+ if ( 1 == data.status ) {
545
+ msg.html(data.msg).show();
546
+ }
547
+
548
+ // fail
549
+ else if ( data.msg ) {
550
+ msg.text(data.msg).show();
551
+ }
552
+ }
553
+
554
+ else {
555
+ msg.text('error').show();
556
+ }
557
+ },
558
+ error: function(xhr, ajaxOptions, thrownError) {},
559
+ complete: function() {
560
+ btn.removeClass('loading');
561
+ }
562
+ });
563
+ }
564
+
565
+ else {
566
+ btn.removeClass('loading');
567
+ msg.text('empty').show();
568
+ }
569
+
570
+ e.preventDefault;
571
+ });
572
+
573
+ // Select Import Code
574
+ $('#cpac_import_input textarea').focus(function() {
575
+ var t = $(this);
576
+ t.select();
577
+
578
+ t.mouseup(function() { // Work around Chrome's little problem
579
+
580
+ t.unbind("mouseup"); // Prevent further mouseup intervention
581
+ return false;
582
  });
583
+ });
584
+ }
585
+
586
+ /**
587
+ * WP Pointer
588
+ *
589
+ * credits to ACF ( Elliot Condon )
590
+ */
591
+ function cpac_pointer()
592
+ {
593
+ $('a.cpac-pointer').each(function(){
594
+
595
+ // vars
596
+ var a = $(this),
597
+ html = a.attr('rel');
598
+
599
+ // create pointer
600
+ a.pointer({
601
+ content: $('#' + html).html(),
602
+ position: {
603
+ my: 'left bottom',
604
+ at: 'left top',
605
+ edge: 'bottom',
606
+ },
607
+ close: function() {
608
+ a.removeClass('open');
609
+ }
610
+ });
611
+
612
+ // click
613
+ a.click( function() {
614
+ if( a.hasClass('open') ) {
615
+ a.removeClass('open');
616
+ }
617
+ else {
618
+ a.addClass('open');
619
+ }
620
+ });
621
+
622
+ // show on hover
623
+ a.hover( function() {
624
+ $(this).pointer('open');
625
+ }, function() {
626
+ if( ! a.hasClass('open') ) {
627
+ $(this).pointer('close');
628
+ }
629
+
630
+ });
631
+ });
632
+ }
633
+
634
+ })(jQuery);
classes/license.php ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class cpac_licence
4
+ {
5
+ /**
6
+ * The type of licence to check or activate
7
+ *
8
+ * @var string $type
9
+ */
10
+ private $type;
11
+
12
+ public function __construct($type)
13
+ {
14
+ $this->type = $type;
15
+ }
16
+
17
+ /**
18
+ * Unlocks
19
+ *
20
+ * @since 1.3
21
+ */
22
+ public function is_unlocked()
23
+ {
24
+ return preg_match( '/^[a-f0-9]{40}$/i', $this->get_license_key( $this->type ) );
25
+ }
26
+
27
+ /**
28
+ * Check license key with API
29
+ *
30
+ * @since 1.3.3
31
+ */
32
+ private function check_remote_key( $key )
33
+ {
34
+ if ( empty( $key ) ) {
35
+ return false;
36
+ }
37
+
38
+ // check key with remote API
39
+ $response = wp_remote_post( $this->api_url, array(
40
+ 'body' => array(
41
+ 'api' => 'addon',
42
+ 'key' => $key,
43
+ 'type' => $this->type
44
+ )
45
+ ));
46
+
47
+ // license will be valid in case of WP error or succes
48
+ if ( is_wp_error($response) || ( isset($response['body']) && json_decode($response['body']) == 'valid' ) ) {
49
+ return true;
50
+ }
51
+
52
+ return false;
53
+ }
54
+
55
+ /**
56
+ * Set masked license key
57
+ *
58
+ * @since 1.3.1
59
+ */
60
+ public function get_masked_license_key()
61
+ {
62
+ return '**************************'.substr( $this->get_license_key(), -4 );
63
+ }
64
+
65
+ /**
66
+ * Get license key
67
+ *
68
+ * @since 1.3
69
+ */
70
+ private function get_license_key()
71
+ {
72
+ return get_option("cpac_{$this->type}_ac");
73
+ }
74
+
75
+ /**
76
+ * Set license key
77
+ *
78
+ * @since 1.3
79
+ */
80
+ private function set_license_key( $key )
81
+ {
82
+ update_option( "cpac_{$this->type}_ac", trim( $key ) );
83
+ }
84
+
85
+ /**
86
+ * Remove license key
87
+ *
88
+ * @since 1.3.1
89
+ */
90
+ private function remove_license_key()
91
+ {
92
+ delete_option( "cpac_{$this->type}_ac" );
93
+ delete_transient("cpac_{$this->type}_trnsnt");
94
+ }
95
+ }
classes/sortable.php CHANGED
@@ -1,1241 +1,1250 @@
1
- <?php
2
-
3
- /**
4
- * Coderess Sortable Columns Class
5
- *
6
- * @since 1.3
7
- *
8
- */
9
- class Codepress_Sortable_Columns extends Codepress_Admin_Columns
10
- {
11
- private $post_types,
12
- $unlocked,
13
- $show_all_results;
14
-
15
- /**
16
- * Constructor
17
- *
18
- * @since 1.0
19
- */
20
- function __construct()
21
- {
22
- add_action( 'wp_loaded', array( $this, 'init') );
23
- }
24
-
25
- /**
26
- * Initialize
27
- *
28
- * @since 1.0
29
- */
30
- public function init()
31
- {
32
- // vars
33
- $this->unlocked = $this->is_unlocked('sortable');
34
- $this->post_types = Codepress_Admin_Columns::get_post_types();
35
- $this->show_all_results = false;
36
-
37
- // init sorting
38
- add_action( 'admin_init', array( $this, 'register_sortable_columns' ) );
39
-
40
- // init filtering
41
- add_action( 'admin_init', array( $this, 'register_filtering_columns' ) );
42
-
43
- // handle requests for sorting columns
44
- add_filter( 'request', array( $this, 'handle_requests_orderby_column'), 1 );
45
- add_action( 'pre_user_query', array( $this, 'handle_requests_orderby_users_column'), 1 );
46
- add_action( 'admin_init', array( $this, 'handle_requests_orderby_links_column'), 1 );
47
- add_action( 'admin_init', array( $this, 'handle_requests_orderby_comments_column'), 1 );
48
- }
49
-
50
- /**
51
- * Register sortable columns
52
- *
53
- * Hooks into apply_filters( "manage_{$screen->id}_sortable_columns" ) which is found in class-wp-list-table.php
54
- *
55
- * @since 1.0
56
- */
57
- function register_sortable_columns()
58
- {
59
- if ( ! $this->unlocked )
60
- return false;
61
-
62
- /** Posts */
63
- foreach ( $this->post_types as $post_type )
64
- add_filter( "manage_edit-{$post_type}_sortable_columns", array($this, 'callback_add_sortable_posts_column'));
65
-
66
- /** Users */
67
- add_filter( "manage_users_sortable_columns", array($this, 'callback_add_sortable_users_column'));
68
-
69
- /** Media */
70
- add_filter( "manage_upload_sortable_columns", array($this, 'callback_add_sortable_media_column'));
71
-
72
- /** Links */
73
- add_filter( "manage_link-manager_sortable_columns", array($this, 'callback_add_sortable_links_column'));
74
-
75
- /** Comments */
76
- add_filter( "manage_edit-comments_sortable_columns", array($this, 'callback_add_sortable_comments_column'));
77
- }
78
-
79
- /**
80
- * Callback add Posts sortable column
81
- *
82
- * @since 1.0
83
- */
84
- public function callback_add_sortable_posts_column($columns)
85
- {
86
- global $post_type;
87
-
88
- return $this->add_managed_sortable_columns($post_type, $columns);
89
- }
90
-
91
- /**
92
- * Callback add Users sortable column
93
- *
94
- * @since 1.1
95
- */
96
- public function callback_add_sortable_users_column($columns)
97
- {
98
- return $this->add_managed_sortable_columns('wp-users', $columns);
99
- }
100
-
101
- /**
102
- * Callback add Media sortable column
103
- *
104
- * @since 1.3
105
- */
106
- public function callback_add_sortable_media_column($columns)
107
- {
108
- return $this->add_managed_sortable_columns('wp-media', $columns);
109
- }
110
-
111
- /**
112
- * Callback add Links sortable column
113
- *
114
- * @since 1.3.1
115
- */
116
- public function callback_add_sortable_links_column($columns)
117
- {
118
- return $this->add_managed_sortable_columns('wp-links', $columns);
119
- }
120
-
121
- /**
122
- * Callback add Comments sortable column
123
- *
124
- * @since 1.3.1
125
- */
126
- public function callback_add_sortable_comments_column($columns)
127
- {
128
- return $this->add_managed_sortable_columns('wp-comments', $columns);
129
- }
130
-
131
- /**
132
- * Add managed sortable columns by Type
133
- *
134
- * @since 1.1
135
- */
136
- private function add_managed_sortable_columns( $type = 'post', $columns )
137
- {
138
- $display_columns = $this->get_merged_columns($type);
139
-
140
- if ( ! $display_columns )
141
- return $columns;
142
-
143
- foreach ( $display_columns as $id => $vars ) {
144
- if ( isset($vars['options']['sortorder']) && $vars['options']['sortorder'] == 'on' ){
145
-
146
- // register format
147
- $columns[$id] = $this->sanitize_string($vars['label']);
148
- }
149
- }
150
-
151
- return $columns;
152
- }
153
-
154
- /**
155
- * Admin requests for orderby column
156
- *
157
- * Only works for WP_Query objects ( such as posts and media )
158
- *
159
- * @since 1.0
160
- */
161
- public function handle_requests_orderby_column( $vars )
162
- {
163
- /** Users */
164
- // You would expect to see get_orderby_users_vars(), but sorting for
165
- // users is handled through a different filter. Not 'request', but 'pre_user_query'.
166
- // See handle_requests_orderby_users_column().
167
-
168
- /** Media */
169
- if ( $this->request_uri_is('upload') ) {
170
- $vars = $this->get_orderby_media_vars($vars);
171
- }
172
-
173
- /** Posts */
174
- elseif ( !empty($vars['post_type']) ) {
175
- $vars = $this->get_orderby_posts_vars($vars);
176
- }
177
-
178
- return $vars;
179
- }
180
-
181
- /**
182
- * Get the default sorting of the column
183
- *
184
- * The default sorting of the column is saved to it's property default_order.
185
- * We will overwrite the requested 'order' and 'orderby' variables with the default_order.
186
- *
187
- * @since 1.4.5
188
- */
189
- function get_default_sorting_vars( $type, $vars )
190
- {
191
- // retrieve the default_order of this type
192
- $db_columns = Codepress_Admin_Columns::get_stored_columns($type);
193
-
194
- if ( $db_columns ) {
195
- foreach ( $db_columns as $column ) {
196
- if ( empty($column['default_order'] ) )
197
- continue;
198
-
199
- // overwrite with the new defaults
200
- $vars['orderby'] = $this->sanitize_string($column['label']);
201
- $vars['order'] = $column['default_order'];
202
- }
203
- }
204
-
205
- return $vars;
206
- }
207
-
208
- /**
209
- * Orderby Users column
210
- *
211
- * @since 1.3
212
- */
213
- public function handle_requests_orderby_users_column($user_query)
214
- {
215
- // query vars
216
- $vars = $user_query->query_vars;
217
-
218
- // Column
219
- $column = $this->get_orderby_type( $vars['orderby'], 'wp-users' );
220
-
221
- if ( empty($column) )
222
- return $user_query;
223
-
224
- // id
225
- $type = $id = key($column);
226
-
227
- // Check for user custom fields: column-meta-[customfieldname]
228
- if ( Codepress_Admin_Columns::is_column_meta($type) )
229
- $type = 'column-user-meta';
230
-
231
- // Check for post count: column-user_postcount-[posttype]
232
- if ( Codepress_Admin_Columns::get_posttype_by_postcount_column($type) )
233
- $type = 'column-user_postcount';
234
-
235
- // var
236
- $cusers = array();
237
- switch( $type ) :
238
-
239
- case 'column-user_id':
240
- $user_query->query_orderby = "ORDER BY ID {$user_query->query_vars['order']}";
241
- $user_query->query_vars['orderby'] = 'ID';
242
- break;
243
-
244
- case 'column-user_registered':
245
- $user_query->query_orderby = "ORDER BY user_registered {$user_query->query_vars['order']}";
246
- $user_query->query_vars['orderby'] = 'registered';
247
- break;
248
-
249
- case 'column-nickname' :
250
- $sort_flag = SORT_REGULAR;
251
- foreach ( $this->get_users_data() as $u ) {
252
- if ($u->nickname || $this->show_all_results ) {
253
- $cusers[$u->ID] = $this->prepare_sort_string_value($u->nickname);
254
- }
255
- }
256
- break;
257
-
258
- case 'column-first_name' :
259
- $sort_flag = SORT_REGULAR;
260
- foreach ( $this->get_users_data() as $u ) {
261
- if ($u->first_name || $this->show_all_results ) {
262
- $cusers[$u->ID] = $this->prepare_sort_string_value($u->first_name);
263
- }
264
- }
265
- break;
266
-
267
- case 'column-last_name' :
268
- $sort_flag = SORT_REGULAR;
269
- foreach ( $this->get_users_data() as $u ) {
270
- if ($u->last_name || $this->show_all_results ) {
271
- $cusers[$u->ID] = $this->prepare_sort_string_value($u->last_name);
272
- }
273
- }
274
- break;
275
-
276
- case 'column-user_url' :
277
- $sort_flag = SORT_REGULAR;
278
- foreach ( $this->get_users_data() as $u ) {
279
- if ($u->user_url || $this->show_all_results ) {
280
- $cusers[$u->ID] = $this->prepare_sort_string_value($u->user_url);
281
- }
282
- }
283
- break;
284
-
285
- case 'column-user_description' :
286
- $sort_flag = SORT_REGULAR;
287
- foreach ( $this->get_users_data() as $u ) {
288
- if ($u->user_description || $this->show_all_results ) {
289
- $cusers[$u->ID] = $this->prepare_sort_string_value($u->user_description);
290
- }
291
- }
292
- break;
293
-
294
- case 'column-user_postcount' :
295
- $post_type = Codepress_Admin_Columns::get_posttype_by_postcount_column($id);
296
- if ( $post_type ) {
297
- $sort_flag = SORT_REGULAR;
298
- foreach ( $this->get_users_data() as $u ) {
299
- $count = Codepress_Admin_Columns::get_post_count( $post_type, $u->ID );
300
- $cusers[$u->ID] = $this->prepare_sort_string_value($count);
301
- }
302
- }
303
- break;
304
-
305
- case 'column-user-meta' :
306
- $field = $column[$id]['field'];
307
- if ( $field ) {
308
-
309
- // order numeric or string
310
- $sort_flag = SORT_REGULAR;
311
- if ( $column[$id]['field_type'] == 'numeric' || $column[$id]['field_type'] == 'library_id' ) {
312
- $sort_flag = SORT_NUMERIC;
313
- }
314
-
315
- // sort by metavalue
316
- foreach ( $this->get_users_data() as $u ) {
317
- $value = get_metadata('user', $u->ID, $field, true);
318
- $cusers[$u->ID] = $this->prepare_sort_string_value($value);
319
- }
320
- }
321
- break;
322
-
323
- /** native WP columns */
324
-
325
- // role column
326
- case 'role' :
327
- $sort_flag = SORT_REGULAR;
328
- foreach ( $this->get_users_data() as $u ) {
329
- $role = !empty($u->roles[0]) ? $u->roles[0] : '';
330
- if ($role || $this->show_all_results ) {
331
- $cusers[$u->ID] = $this->prepare_sort_string_value($role);
332
- }
333
- }
334
- break;
335
-
336
- endswitch;
337
-
338
- // save the order you last used as the default
339
- // $this->save_sorting_preference( 'wp-users', $type, strtolower($vars['order']) );
340
-
341
- if ( isset($sort_flag) ) {
342
- $user_query = $this->get_users_query_vars( $user_query, $cusers, $sort_flag );
343
- }
344
-
345
- return $user_query;
346
- }
347
-
348
- /**
349
- * Orderby Links column
350
- *
351
- * Makes use of filter 'get_bookmarks' from bookmark.php to change the result set of the links
352
- *
353
- * @since 1.3.1
354
- */
355
- public function handle_requests_orderby_links_column()
356
- {
357
- // fire only when we are in the admins link-manager
358
- if ( $this->request_uri_is('link-manager') )
359
- add_filter( 'get_bookmarks', array( $this, 'callback_requests_orderby_links_column'), 10, 2);
360
- }
361
-
362
- /**
363
- * Orderby Links column
364
- *
365
- * @since 1.3.1
366
- */
367
- public function callback_requests_orderby_links_column($results, $vars)
368
- {
369
- global $wpdb;
370
-
371
- // Column
372
- $column = $this->get_orderby_type( $vars['orderby'], 'wp-links' );
373
-
374
- if ( empty($column) )
375
- return $results;
376
-
377
- // id
378
- $type = $id = key($column);
379
-
380
- // var
381
- $length = '';
382
- switch( $type ) :
383
-
384
- case 'column-link_id':
385
- if ( version_compare( get_bloginfo('version'), '3.2', '>' ) )
386
- $vars['orderby'] = 'link_id';
387
- else
388
- $vars['orderby'] = 'id';
389
- break;
390
-
391
- case 'column-owner':
392
- $vars['orderby'] = 'link_owner';
393
- break;
394
-
395
- case 'column-length':
396
- $vars['orderby'] = 'length';
397
- $length = ", CHAR_LENGTH(link_name) AS length";
398
- break;
399
-
400
- case 'column-target':
401
- $vars['orderby'] = 'link_target';
402
- break;
403
-
404
- case 'column-description':
405
- $vars['orderby'] = 'link_description';
406
- break;
407
-
408
- case 'column-notes':
409
- $vars['orderby'] = 'link_notes';
410
- break;
411
-
412
- case 'column-rss':
413
- $vars['orderby'] = 'link_rss';
414
- break;
415
-
416
- /** native WP columns */
417
-
418
- // Relationship
419
- case 'rel':
420
- $vars['orderby'] = 'link_rel';
421
- break;
422
-
423
- default:
424
- $vars['orderby'] = '';
425
-
426
- endswitch;
427
-
428
- // get bookmarks by orderby vars
429
- if ( $vars['orderby'] ) {
430
- $vars['order'] = mysql_escape_string($vars['order']);
431
- $sql = "SELECT * {$length} FROM {$wpdb->links} WHERE 1=1 ORDER BY {$vars['orderby']} {$vars['order']}";
432
- $results = $wpdb->get_results($sql);
433
-
434
- // check for errors
435
- if( is_wp_error($results) )
436
- return false;
437
- }
438
-
439
- return $results;
440
- }
441
-
442
- /**
443
- * Orderby Comments column
444
- *
445
- * @since 1.3.1
446
- */
447
- public function callback_requests_orderby_comments_column($pieces, $ref_comment)
448
- {
449
- // get query vars
450
- $vars = $ref_comment->query_vars;
451
-
452
- // Column
453
- $column = $this->get_orderby_type( $vars['orderby'], 'wp-comments' );
454
-
455
- if ( empty($column) )
456
- return $pieces;
457
-
458
- // id
459
- $type = $id = key($column);
460
-
461
- // var
462
- switch( $type ) :
463
-
464
- case 'column-comment_id':
465
- $pieces['orderby'] = 'comment_ID';
466
- break;
467
-
468
- case 'column-author_author':
469
- $pieces['orderby'] = 'comment_author';
470
- break;
471
-
472
- case 'column-author_ip':
473
- $pieces['orderby'] = 'comment_author_IP';
474
- break;
475
-
476
- case 'column-author_url':
477
- $pieces['orderby'] = 'comment_author_url';
478
- break;
479
-
480
- case 'column-author_email':
481
- $pieces['orderby'] = 'comment_author_email';
482
- break;
483
-
484
- case 'column-reply_to':
485
- break;
486
-
487
- case 'column-approved':
488
- $pieces['orderby'] = 'comment_approved';
489
- break;
490
-
491
- case 'column-date':
492
- $pieces['orderby'] = 'comment_date';
493
- break;
494
-
495
- case 'column-agent':
496
- $pieces['orderby'] = 'comment_agent';
497
- break;
498
-
499
- case 'column-excerpt':
500
- $pieces['orderby'] = 'comment_content';
501
- break;
502
-
503
- case 'column-date_gmt':
504
- break;
505
-
506
- /** native WP columns */
507
-
508
- // Relationship
509
- case 'comment':
510
- $pieces['orderby'] = 'comment_content';
511
- break;
512
-
513
- default:
514
- $vars['orderby'] = '';
515
-
516
- endswitch;
517
-
518
- return $pieces;
519
- }
520
-
521
- /**
522
- * Orderby Comments column
523
- *
524
- * @since 1.3.1
525
- */
526
- public function handle_requests_orderby_comments_column()
527
- {
528
- // fire only when we are in the admins edit-comments
529
- if ( $this->request_uri_is('edit-comments') ) {
530
- add_filter('comments_clauses', array( $this, 'callback_requests_orderby_comments_column'), 10, 2);
531
- }
532
- }
533
-
534
- /**
535
- * Get sorting vars in User Query Object
536
- *
537
- * @since 1.3
538
- */
539
- private function get_users_query_vars( $user_query, $sortusers, $sort_flags = SORT_REGULAR )
540
- {
541
- global $wpdb;
542
-
543
- // vars
544
- $vars = $user_query->query_vars;
545
-
546
- // sorting
547
- if ( $vars['order'] == 'ASC' )
548
- asort($sortusers, $sort_flags);
549
- else
550
- arsort($sortusers, $sort_flags);
551
-
552
- // alter orderby SQL
553
- if ( ! empty ( $sortusers ) ) {
554
- $ids = implode(',', array_keys($sortusers));
555
- $user_query->query_where .= " AND {$wpdb->prefix}users.ID IN ({$ids})";
556
- $user_query->query_orderby = "ORDER BY FIELD({$wpdb->prefix}users.ID,{$ids})";
557
- }
558
-
559
- // cleanup the vars we dont need
560
- $vars['order'] = '';
561
- $vars['orderby'] = '';
562
-
563
- // set query vars
564
- $user_query->query_vars = $vars;
565
-
566
- return $user_query;
567
- }
568
-
569
- /**
570
- * Orderby Media column
571
- *
572
- * @since 1.3
573
- */
574
- private function get_orderby_media_vars($vars)
575
- {
576
- // apply default sorting when it has been set
577
- if ( empty( $vars['orderby'] ) ) {
578
- $vars = $this->get_default_sorting_vars( 'wp-media', $vars );
579
-
580
- // when sorting still isn't set we will just return the requested vars
581
- if ( empty( $vars['orderby'] ) )
582
- return $vars;
583
- }
584
-
585
- // Column
586
- $column = $this->get_orderby_type( $vars['orderby'], 'wp-media' );
587
-
588
- if ( empty($column) )
589
- return $vars;
590
-
591
- $id = key($column);
592
-
593
- // var
594
- $cposts = array();
595
- switch( $id ) :
596
-
597
- case 'column-mediaid' :
598
- $vars['orderby'] = 'ID';
599
- break;
600
-
601
- case 'column-width' :
602
- $sort_flag = SORT_NUMERIC;
603
- foreach ( $this->get_any_posts_by_posttype('attachment') as $p ) {
604
- $meta = wp_get_attachment_metadata($p->ID);
605
- $width = !empty($meta['width']) ? $meta['width'] : 0;
606
- if ( $width || $this->show_all_results )
607
- $cposts[$p->ID] = $width;
608
- }
609
- break;
610
-
611
- case 'column-height' :
612
- $sort_flag = SORT_NUMERIC;
613
- foreach ( $this->get_any_posts_by_posttype('attachment') as $p ) {
614
- $meta = wp_get_attachment_metadata($p->ID);
615
- $height = !empty($meta['height']) ? $meta['height'] : 0;
616
- if ( $height || $this->show_all_results )
617
- $cposts[$p->ID] = $height;
618
- }
619
- break;
620
-
621
- case 'column-dimensions' :
622
- $sort_flag = SORT_NUMERIC;
623
- foreach ( $this->get_any_posts_by_posttype('attachment') as $p ) {
624
- $meta = wp_get_attachment_metadata($p->ID);
625
- $height = !empty($meta['height']) ? $meta['height'] : 0;
626
- $width = !empty($meta['width']) ? $meta['width'] : 0;
627
- $surface = $height*$width;
628
-
629
- if ( $surface || $this->show_all_results )
630
- $cposts[$p->ID] = $surface;
631
- }
632
- break;
633
-
634
- case 'column-caption' :
635
- $sort_flag = SORT_STRING;
636
- foreach ( $this->get_any_posts_by_posttype('attachment') as $p ) {
637
- if ( $p->post_excerpt || $this->show_all_results ) {
638
- $cposts[$p->ID] = $this->prepare_sort_string_value($p->post_excerpt);
639
- }
640
- }
641
- break;
642
-
643
- case 'column-description' :
644
- $sort_flag = SORT_STRING;
645
- foreach ( $this->get_any_posts_by_posttype('attachment') as $p ) {
646
- if ( $p->post_content || $this->show_all_results ) {
647
- $cposts[$p->ID] = $this->prepare_sort_string_value( $p->post_content );
648
- }
649
- }
650
- break;
651
-
652
- case 'column-mime_type' :
653
- $sort_flag = SORT_STRING;
654
- foreach ( $this->get_any_posts_by_posttype('attachment') as $p ) {
655
- if ( $p->post_mime_type || $this->show_all_results ) {
656
- $cposts[$p->ID] = $this->prepare_sort_string_value( $p->post_mime_type );
657
- }
658
- }
659
- break;
660
-
661
- case 'column-file_name' :
662
- $sort_flag = SORT_STRING;
663
- foreach ( $this->get_any_posts_by_posttype('attachment') as $p ) {
664
- $meta = get_post_meta($p->ID, '_wp_attached_file', true);
665
- $file = !empty($meta) ? basename($meta) : '';
666
- if ( $file || $this->show_all_results ) {
667
- $cposts[$p->ID] = $file;
668
- }
669
- }
670
- break;
671
-
672
- case 'column-alternate_text' :
673
- $sort_flag = SORT_STRING;
674
- foreach ( $this->get_any_posts_by_posttype('attachment') as $p ) {
675
- $alt = get_post_meta($p->ID, '_wp_attachment_image_alt', true);
676
- if ( $alt || $this->show_all_results ) {
677
- $cposts[$p->ID] = $this->prepare_sort_string_value( $alt );
678
- }
679
- }
680
- break;
681
-
682
- case 'column-filesize' :
683
- $sort_flag = SORT_NUMERIC;
684
- foreach ( $this->get_any_posts_by_posttype('attachment') as $p ) {
685
- $file = wp_get_attachment_url($p->ID);
686
- if ( $file || $this->show_all_results ) {
687
- $abs = str_replace( WP_CONTENT_URL, WP_CONTENT_DIR, $file);
688
- $cposts[$p->ID] = $this->prepare_sort_string_value( filesize($abs) );
689
- }
690
- }
691
- break;
692
-
693
- endswitch;
694
-
695
- // save the order you last used as the default
696
- $this->save_sorting_preference( 'wp-media', $id, $vars['order'] );
697
-
698
- // we will add the sorted post ids to vars['post__in'] and remove unused vars
699
- if ( isset($sort_flag) ) {
700
- $vars = $this->get_vars_post__in( $vars, $cposts, $sort_flag );
701
- }
702
-
703
- return $vars;
704
- }
705
-
706
- /**
707
- * Orderby Posts column
708
- *
709
- * @since 1.3
710
- */
711
- private function get_orderby_posts_vars($vars)
712
- {
713
- $post_type = $vars['post_type'];
714
-
715
- // todo: fix default sorting
716
- // apply default sorting when it has been set
717
- if ( empty( $vars['orderby'] ) ) {
718
- $vars = $this->get_default_sorting_vars( $post_type, $vars );
719
-
720
- // when sorting still isn't set we will just return the requested vars
721
- if ( empty( $vars['orderby'] ) )
722
- return $vars;
723
- }
724
-
725
- // Column
726
- $column = $this->get_orderby_type( $vars['orderby'], $post_type );
727
-
728
- if ( empty($column) )
729
- return $vars;
730
-
731
- // id
732
- $type = $id = key($column);
733
-
734
- // Check for taxonomies, such as column-taxonomy-[taxname]
735
- if ( strpos($type, 'column-taxonomy-') !== false )
736
- $type = 'column-taxonomy';
737
-
738
- // custom fields
739
- if ( Codepress_Admin_Columns::is_column_meta($type) )
740
- $type = 'column-post-meta';
741
-
742
- // attachments
743
- if ( $type == 'column-attachment-count' )
744
- $type = 'column-attachment';
745
-
746
- // var
747
- $cposts = array();
748
- switch( $type ) :
749
-
750
- case 'column-postid' :
751
- $vars['orderby'] = 'ID';
752
- break;
753
-
754
- case 'column-order' :
755
- $vars['orderby'] = 'menu_order';
756
- break;
757
-
758
- case 'column-modified' :
759
- $vars['orderby'] = 'modified';
760
- break;
761
-
762
- case 'column-comment-count' :
763
- $vars['orderby'] = 'comment_count';
764
- break;
765
-
766
- case 'column-post-meta' :
767
- $field = $column[$id]['field'];
768
-
769
- // orderby type
770
- $field_type = 'meta_value';
771
- if ( $column[$id]['field_type'] == 'numeric' || $column[$id]['field_type'] == 'library_id' )
772
- $field_type = 'meta_value_num';
773
-
774
- $vars = array_merge($vars, array(
775
- 'meta_key' => $field,
776
- 'orderby' => $field_type
777
- ));
778
- break;
779
-
780
- case 'column-excerpt' :
781
- $sort_flag = SORT_STRING;
782
- foreach ( $this->get_any_posts_by_posttype($post_type) as $p ) {
783
- $cposts[$p->ID] = $this->prepare_sort_string_value($p->post_content);
784
- }
785
- break;
786
-
787
- case 'column-word-count' :
788
- $sort_flag = SORT_NUMERIC;
789
- foreach ( $this->get_any_posts_by_posttype($post_type) as $p ) {
790
- $cposts[$p->ID] = str_word_count( Codepress_Admin_Columns::strip_trim( $p->post_content ) );
791
- }
792
- break;
793
-
794
- case 'column-page-template' :
795
- $sort_flag = SORT_STRING;
796
- $templates = get_page_templates();
797
- foreach ( $this->get_any_posts_by_posttype($post_type) as $p ) {
798
- $page_template = get_post_meta($p->ID, '_wp_page_template', true);
799
- $cposts[$p->ID] = array_search($page_template, $templates);
800
- }
801
- break;
802
-
803
- case 'column-post_formats' :
804
- $sort_flag = SORT_REGULAR;
805
- foreach ( $this->get_any_posts_by_posttype($post_type) as $p ) {
806
- $cposts[$p->ID] = get_post_format($p->ID);
807
- }
808
- break;
809
-
810
- case 'column-attachment' :
811
- $sort_flag = SORT_NUMERIC;
812
- foreach ( $this->get_any_posts_by_posttype($post_type) as $p ) {
813
- $cposts[$p->ID] = count( Codepress_Admin_Columns::get_attachment_ids($p->ID) );
814
- }
815
- break;
816
-
817
- case 'column-page-slug' :
818
- $sort_flag = SORT_REGULAR;
819
- foreach ( $this->get_any_posts_by_posttype($post_type) as $p ) {
820
- $cposts[$p->ID] = $p->post_name;
821
- }
822
- break;
823
-
824
- case 'column-sticky' :
825
- $sort_flag = SORT_REGULAR;
826
- $stickies = get_option('sticky_posts');
827
- foreach ( $this->get_any_posts_by_posttype($post_type) as $p ) {
828
- $cposts[$p->ID] = $p->ID;
829
- if ( !empty($stickies) && in_array($p->ID, $stickies ) ) {
830
- $cposts[$p->ID] = 0;
831
- }
832
- }
833
- break;
834
-
835
- case 'column-featured_image' :
836
- $sort_flag = SORT_REGULAR;
837
- foreach ( $this->get_any_posts_by_posttype($post_type) as $p ) {
838
- $cposts[$p->ID] = $p->ID;
839
- $thumb = get_the_post_thumbnail($p->ID);
840
- if ( !empty($thumb) ) {
841
- $cposts[$p->ID] = 0;
842
- }
843
- }
844
- break;
845
-
846
- case 'column-roles' :
847
- $sort_flag = SORT_STRING;
848
- foreach ( $this->get_any_posts_by_posttype($post_type) as $p ) {
849
- $cposts[$p->ID] = 0;
850
- $userdata = get_userdata($p->post_author);
851
- if ( !empty($userdata->roles[0]) ) {
852
- $cposts[$p->ID] = $userdata->roles[0];
853
- }
854
- }
855
- break;
856
-
857
- case 'column-status' :
858
- $sort_flag = SORT_STRING;
859
- foreach ( $this->get_any_posts_by_posttype($post_type) as $p ) {
860
- $cposts[$p->ID] = $p->post_status.strtotime($p->post_date);
861
- }
862
- break;
863
-
864
- case 'column-comment-status' :
865
- $sort_flag = SORT_STRING;
866
- foreach ( $this->get_any_posts_by_posttype($post_type) as $p ) {
867
- $cposts[$p->ID] = $p->comment_status;
868
- }
869
- break;
870
-
871
- case 'column-ping-status' :
872
- $sort_flag = SORT_STRING;
873
- foreach ( $this->get_any_posts_by_posttype($post_type) as $p ) {
874
- $cposts[$p->ID] = $p->ping_status;
875
- }
876
- break;
877
-
878
- case 'column-taxonomy' :
879
- $sort_flag = SORT_STRING; // needed to sort
880
- $taxonomy = str_replace('column-taxonomy-', '', $id);
881
- $cposts = $this->get_posts_sorted_by_taxonomy($post_type, $taxonomy);
882
- break;
883
-
884
- case 'column-author-name' :
885
- $sort_flag = SORT_STRING;
886
- $display_as = $column[$id]['display_as'];
887
- if( 'userid' == $display_as ) {
888
- $sort_flag = SORT_NUMERIC;
889
- }
890
- foreach ( $this->get_any_posts_by_posttype($post_type) as $p ) {
891
- if ( !empty($p->post_author) ) {
892
- $name = Codepress_Admin_Columns::get_author_field_by_nametype($display_as, $p->post_author);
893
- $cposts[$p->ID] = $name;
894
- }
895
- }
896
- break;
897
-
898
- case 'column-before-moretag' :
899
- $sort_flag = SORT_STRING;
900
- foreach ( $this->get_any_posts_by_posttype($post_type) as $p ) {
901
- $extended = get_extended($p->post_content);
902
- $content = !empty($extended['extended']) ? $extended['main'] : '';
903
- $cposts[$p->ID] = $this->prepare_sort_string_value($content);
904
- }
905
- break;
906
-
907
- /** native WP columns */
908
-
909
- // categories
910
- case 'categories' :
911
- $sort_flag = SORT_STRING; // needed to sort
912
- $cposts = $this->get_posts_sorted_by_taxonomy($post_type, 'category');
913
- break;
914
-
915
- // tags
916
- case 'tags' :
917
- $sort_flag = SORT_STRING; // needed to sort
918
- $cposts = $this->get_posts_sorted_by_taxonomy($post_type, 'post_tag');
919
- break;
920
-
921
- endswitch;
922
-
923
- // save the order you last used as the default
924
- $this->save_sorting_preference( $post_type, $type, $vars['order'] );
925
-
926
- // we will add the sorted post ids to vars['post__in'] and remove unused vars
927
- if ( isset($sort_flag) ) {
928
- $vars = $this->get_vars_post__in( $vars, $cposts, $sort_flag );
929
- }
930
-
931
- return $vars;
932
- }
933
-
934
- /**
935
- * Save sorting preference
936
- *
937
- * after sorting we will save this sorting preference to the column item
938
- * we set the default_order to either asc, desc or empty.
939
- * only ONE column item PER type can have a default_order
940
- *
941
- * @since 1.4.5
942
- */
943
- function save_sorting_preference( $type, $column_type, $order = 'asc' )
944
- {
945
- $options = get_option('cpac_options');
946
- if ( isset($options['columns'][$type][$column_type]) ) {
947
-
948
- // remove the old default_order
949
- foreach ($options['columns'][$type] as $k => $v) {
950
- if ( isset( $options['columns'][$type][$k]['default_order'] ) ) {
951
- unset($options['columns'][$type][$k]['default_order']);
952
- }
953
- }
954
-
955
- // set the new default order
956
- $options['columns'][$type][$column_type]['default_order'] = $order;
957
-
958
- // save to DB
959
- update_option('cpac_options', $options);
960
- }
961
- }
962
-
963
- /**
964
- * Get posts sorted by taxonomy
965
- *
966
- * This will post ID's by the first term in the taxonomy
967
- *
968
- * @since 1.4.5
969
- */
970
- function get_posts_sorted_by_taxonomy($post_type, $taxonomy = 'category')
971
- {
972
- $cposts = array();
973
- foreach ( $this->get_any_posts_by_posttype($post_type) as $p ) {
974
- $cposts[$p->ID] = '';
975
- $terms = get_the_terms($p->ID, $taxonomy);
976
- if ( !is_wp_error($terms) && !empty($terms) ) {
977
- // only use the first term to sort
978
- $term = array_shift(array_values($terms));
979
- if ( isset($term->term_id) ) {
980
- $cposts[$p->ID] = sanitize_term_field('name', $term->name, $term->term_id, $term->taxonomy, 'display');
981
- }
982
- }
983
- }
984
- return $cposts;
985
- }
986
-
987
- /**
988
- * Set post__in for use in WP_Query
989
- *
990
- * This will order the ID's asc or desc and set the appropriate filters.
991
- *
992
- * @since 1.2.1
993
- */
994
- private function get_vars_post__in( &$vars, $sortposts, $sort_flags = SORT_REGULAR )
995
- {
996
- // sort post ids by value
997
- if ( $vars['order'] == 'asc' )
998
- asort($sortposts, $sort_flags);
999
- else
1000
- arsort($sortposts, $sort_flags);
1001
-
1002
- // this will make sure WP_Query will use the order of the ids that we have just set in 'post__in'
1003
- // set priority higher then default to prevent conflicts with 3rd party plugins
1004
- add_filter('posts_orderby', array( $this, 'filter_orderby_post__in'), 10, 2 );
1005
-
1006
- // cleanup the vars we dont need
1007
- $vars['order'] = '';
1008
- $vars['orderby'] = '';
1009
-
1010
- // add the sorted post ids to the query with the use of post__in
1011
- $vars['post__in'] = array_keys($sortposts);
1012
-
1013
- return $vars;
1014
- }
1015
-
1016
- /**
1017
- * Get orderby type
1018
- *
1019
- * @since 1.1
1020
- */
1021
- private function get_orderby_type($orderby, $type)
1022
- {
1023
- $db_columns = Codepress_Admin_Columns::get_stored_columns($type);
1024
-
1025
- if ( $db_columns ) {
1026
- foreach ( $db_columns as $id => $vars ) {
1027
-
1028
- // check which custom column was clicked
1029
- if ( isset( $vars['label'] ) && $orderby == $this->sanitize_string( $vars['label'] ) ) {
1030
- $column[$id] = $vars;
1031
- return $column;
1032
- }
1033
- }
1034
- }
1035
- return false;
1036
- }
1037
-
1038
- /**
1039
- * Maintain order of ids that are set in the post__in var.
1040
- *
1041
- * This will force the returned posts to use the order of the ID's that
1042
- * have been set in post__in. Without this the ID's will be set in numeric order.
1043
- * See the WP_Query object for more info about the use of post__in.
1044
- *
1045
- * @since 1.2.1
1046
- */
1047
- public function filter_orderby_post__in($orderby, $wp)
1048
- {
1049
- global $wpdb;
1050
-
1051
- // we need the query vars
1052
- $vars = $wp->query_vars;
1053
- if ( ! empty ( $vars['post__in'] ) ) {
1054
- // now we can get the ids
1055
- $ids = implode(',', $vars['post__in']);
1056
-
1057
- // by adding FIELD to the SQL query we are forcing the order of the ID's
1058
- return "FIELD({$wpdb->prefix}posts.ID,{$ids})";
1059
- }
1060
- }
1061
-
1062
- /**
1063
- * Get any posts by post_type
1064
- *
1065
- * @since 1.2.1
1066
- */
1067
- private function get_any_posts_by_posttype( $post_type )
1068
- {
1069
- $any_posts = (array) get_posts(array(
1070
- 'numberposts' => -1,
1071
- 'post_status' => 'any',
1072
- 'post_type' => $post_type
1073
- ));
1074
-
1075
- // trash posts are not included in the posts_status 'any' by default
1076
- $trash_posts = (array) get_posts(array(
1077
- 'numberposts' => -1,
1078
- 'post_status' => 'trash',
1079
- 'post_type' => $post_type
1080
- ));
1081
-
1082
- $all_posts = array_merge($any_posts, $trash_posts);
1083
-
1084
- return (array) $all_posts;
1085
- }
1086
-
1087
- /**
1088
- * Request URI is
1089
- *
1090
- * @since 1.3.1
1091
- */
1092
- private function request_uri_is( $screen_id = '' )
1093
- {
1094
- if (strpos( $_SERVER['REQUEST_URI'], "/{$screen_id}.php" ) !== false )
1095
- return true;
1096
-
1097
- return false;
1098
- }
1099
-
1100
- /**
1101
- * Prepare the value for being by sorting
1102
- *
1103
- * @since 1.3
1104
- */
1105
- private function prepare_sort_string_value($string)
1106
- {
1107
- // remove tags and only get the first 20 chars and force lowercase.
1108
- $string = strtolower( substr( Codepress_Admin_Columns::strip_trim($string),0 ,20 ) );
1109
-
1110
- return $string;
1111
- }
1112
-
1113
- /**
1114
- * Get users data
1115
- *
1116
- * @since 1.3
1117
- */
1118
- function get_users_data()
1119
- {
1120
- $userdatas = array();
1121
- $wp_users = get_users( array(
1122
- 'blog_id' => $GLOBALS['blog_id'],
1123
- ));
1124
- foreach ( $wp_users as $u ) {
1125
- $userdatas[$u->ID] = get_userdata($u->ID);
1126
- }
1127
- return $userdatas;
1128
- }
1129
-
1130
- /**
1131
- * Register filtering columns
1132
- *
1133
- * @since 1.4.2
1134
- */
1135
- function register_filtering_columns()
1136
- {
1137
- if ( ! $this->unlocked || apply_filters( 'cpac-remove-filtering-columns', true ) )
1138
- return false;
1139
-
1140
- // hook into wordpress
1141
- add_action('restrict_manage_posts', array($this, 'callback_restrict_posts'));
1142
- }
1143
-
1144
- /**
1145
- * Add taxonomy filters to posts
1146
- *
1147
- * @since 1.4.2
1148
- */
1149
- function callback_restrict_posts()
1150
- {
1151
- global $post_type_object;
1152
-
1153
- if ( !isset($post_type_object->name) )
1154
- return false;
1155
-
1156
- // make a filter foreach taxonomy
1157
- $taxonomies = get_object_taxonomies($post_type_object->name, 'names');
1158
-
1159
- // get stored columns
1160
- $db_columns = Codepress_Admin_Columns::get_stored_columns($post_type_object->name);
1161
-
1162
- if ( $taxonomies ) {
1163
- foreach ( $taxonomies as $tax ) {
1164
-
1165
- // ignore core taxonomies
1166
- if ( in_array($tax, array('post_tag','category','post_format') ) ) {
1167
- continue;
1168
- }
1169
-
1170
- // only display taxonomy that is active as a column
1171
- if ( isset($db_columns['column-taxonomy-'.$tax]) && $db_columns['column-taxonomy-'.$tax]['state'] == 'on' ) {
1172
-
1173
- $terms = get_terms($tax);
1174
- $terms = $this->indent($terms, 0, 'parent', 'term_id');
1175
- $terms = $this->apply_dropdown_markup($terms);
1176
-
1177
- $select = "<option value=''>".__('Show all ', CPAC_TEXTDOMAIN)."{$tax}</option>";
1178
- if (!empty($terms)) {
1179
- foreach( $terms as $term_slug => $term) {
1180
-
1181
- $selected = isset($_GET[$tax]) && $term_slug == $_GET[$tax] ? " selected='selected'" : '';
1182
- $select .= "<option value='{$term_slug}'{$selected}>{$term}</option>";
1183
- }
1184
- echo "<select class='postform' name='{$tax}'>{$select}</select>";
1185
- }
1186
- }
1187
- }
1188
- }
1189
- }
1190
-
1191
- /**
1192
- * Applies dropdown markup for taxonomy dropdown
1193
- *
1194
- * @since 1.4.2
1195
- */
1196
- private function apply_dropdown_markup($array, $level = 0, $output = array())
1197
- {
1198
- foreach($array as $v) {
1199
-
1200
- $prefix = '';
1201
- for($i=0; $i<$level; $i++) {
1202
- $prefix .= '&nbsp;&nbsp;';
1203
- }
1204
-
1205
- $output[$v->slug] = $prefix . $v->name;
1206
-
1207
- if ( !empty($v->children) ) {
1208
- $output = $this->apply_dropdown_markup($v->children, ($level + 1), $output);
1209
- }
1210
- }
1211
-
1212
- return $output;
1213
- }
1214
-
1215
- /**
1216
- * Indents any object as long as it has a unique id and that of its parent.
1217
- *
1218
- * @since 1.4.2
1219
- */
1220
- private function indent($array, $parentId = 0, $parentKey = 'post_parent', $selfKey = 'ID', $childrenKey = 'children')
1221
- {
1222
- $indent = array();
1223
-
1224
- // clean counter
1225
- $i = 0;
1226
-
1227
- foreach($array as $v) {
1228
-
1229
- if ($v->$parentKey == $parentId) {
1230
- $indent[$i] = $v;
1231
- $indent[$i]->$childrenKey = $this->indent($array, $v->$selfKey, $parentKey, $selfKey);
1232
-
1233
- $i++;
1234
- }
1235
- }
1236
-
1237
- return $indent;
1238
- }
1239
- }
1240
-
 
 
 
 
 
 
 
 
 
1241
  ?>
1
+ <?php
2
+
3
+ /**
4
+ * Coderess Sortable Columns Class
5
+ *
6
+ * @since 1.3
7
+ *
8
+ */
9
+ class Codepress_Sortable_Columns extends Codepress_Admin_Columns
10
+ {
11
+ private $post_types,
12
+ $unlocked,
13
+ $show_all_results,
14
+ $current_user_id;
15
+
16
+ /**
17
+ * Constructor
18
+ *
19
+ * @since 1.0
20
+ */
21
+ function __construct()
22
+ {
23
+ add_action( 'wp_loaded', array( $this, 'init') );
24
+ }
25
+
26
+ /**
27
+ * Initialize
28
+ *
29
+ * @since 1.0
30
+ */
31
+ public function init()
32
+ {
33
+ $licence = new cpac_licence('sortable');
34
+
35
+ // vars
36
+ $this->unlocked = $licence->is_unlocked();
37
+ $this->post_types = Codepress_Admin_Columns::get_post_types();
38
+ $this->show_all_results = false;
39
+ $this->current_user_id = get_current_user_id();
40
+
41
+ // init sorting
42
+ add_action( 'admin_init', array( $this, 'register_sortable_columns' ) );
43
+
44
+ // init filtering
45
+ add_action( 'admin_init', array( $this, 'register_filtering_columns' ) );
46
+
47
+ // handle requests for sorting columns
48
+ add_filter( 'request', array( $this, 'handle_requests_orderby_column'), 1 );
49
+ add_action( 'pre_user_query', array( $this, 'handle_requests_orderby_users_column'), 1 );
50
+ add_action( 'admin_init', array( $this, 'handle_requests_orderby_links_column'), 1 );
51
+ add_action( 'admin_init', array( $this, 'handle_requests_orderby_comments_column'), 1 );
52
+ }
53
+
54
+ /**
55
+ * Register sortable columns
56
+ *
57
+ * Hooks into apply_filters( "manage_{$screen->id}_sortable_columns" ) which is found in class-wp-list-table.php
58
+ *
59
+ * @since 1.0
60
+ */
61
+ function register_sortable_columns()
62
+ {
63
+ if ( ! $this->unlocked )
64
+ return false;
65
+
66
+ /** Posts */
67
+ foreach ( $this->post_types as $post_type ) {
68
+ add_filter( "manage_edit-{$post_type}_sortable_columns", array($this, 'callback_add_sortable_posts_column'));
69
+ }
70
+
71
+ /** Users */
72
+ add_filter( "manage_users_sortable_columns", array($this, 'callback_add_sortable_users_column'));
73
+
74
+ /** Media */
75
+ add_filter( "manage_upload_sortable_columns", array($this, 'callback_add_sortable_media_column'));
76
+
77
+ /** Links */
78
+ add_filter( "manage_link-manager_sortable_columns", array($this, 'callback_add_sortable_links_column'));
79
+
80
+ /** Comments */
81
+ add_filter( "manage_edit-comments_sortable_columns", array($this, 'callback_add_sortable_comments_column'));
82
+ }
83
+
84
+ /**
85
+ * Callback add Posts sortable column
86
+ *
87
+ * @since 1.0
88
+ */
89
+ public function callback_add_sortable_posts_column($columns)
90
+ {
91
+ global $post_type;
92
+
93
+ // in some cases post_type is an array ( when clicking a tag inside the overview screen icm CCTM ), then we use this as a fallback so we get a string
94
+ if ( is_array($post_type) )
95
+ $post_type = $_REQUEST['post_type'];
96
+
97
+ return $this->add_managed_sortable_columns($post_type, $columns);
98
+ }
99
+
100
+ /**
101
+ * Callback add Users sortable column
102
+ *
103
+ * @since 1.1
104
+ */
105
+ public function callback_add_sortable_users_column($columns)
106
+ {
107
+ return $this->add_managed_sortable_columns('wp-users', $columns);
108
+ }
109
+
110
+ /**
111
+ * Callback add Media sortable column
112
+ *
113
+ * @since 1.3
114
+ */
115
+ public function callback_add_sortable_media_column($columns)
116
+ {
117
+ return $this->add_managed_sortable_columns('wp-media', $columns);
118
+ }
119
+
120
+ /**
121
+ * Callback add Links sortable column
122
+ *
123
+ * @since 1.3.1
124
+ */
125
+ public function callback_add_sortable_links_column($columns)
126
+ {
127
+ return $this->add_managed_sortable_columns('wp-links', $columns);
128
+ }
129
+
130
+ /**
131
+ * Callback add Comments sortable column
132
+ *
133
+ * @since 1.3.1
134
+ */
135
+ public function callback_add_sortable_comments_column($columns)
136
+ {
137
+ return $this->add_managed_sortable_columns('wp-comments', $columns);
138
+ }
139
+
140
+ /**
141
+ * Add managed sortable columns by Type
142
+ *
143
+ * @since 1.1
144
+ */
145
+ private function add_managed_sortable_columns( $type = 'post', $columns )
146
+ {
147
+ $display_columns = $this->get_merged_columns($type);
148
+
149
+ if ( ! $display_columns )
150
+ return $columns;
151
+
152
+ foreach ( $display_columns as $id => $vars ) {
153
+ if ( isset($vars['options']['sortorder']) && $vars['options']['sortorder'] == 'on' ){
154
+
155
+ // register format
156
+ $columns[$id] = $this->sanitize_string($vars['label']);
157
+ }
158
+ }
159
+
160
+ return $columns;
161
+ }
162
+
163
+ /**
164
+ * Admin requests for orderby column
165
+ *
166
+ * Only works for WP_Query objects ( such as posts and media )
167
+ *
168
+ * @since 1.0
169
+ */
170
+ public function handle_requests_orderby_column( $vars )
171
+ {
172
+ /** Users */
173
+ // You would expect to see get_orderby_users_vars(), but sorting for
174
+ // users is handled through a different filter. Not 'request', but 'pre_user_query'.
175
+ // See handle_requests_orderby_users_column().
176
+
177
+ /** Media */
178
+ if ( $this->request_uri_is('upload') ) {
179
+ $vars = $this->get_orderby_media_vars($vars);
180
+ }
181
+
182
+ /** Posts */
183
+ elseif ( !empty($vars['post_type']) ) {
184
+ $vars = $this->get_orderby_posts_vars($vars);
185
+ }
186
+
187
+ return $vars;
188
+ }
189
+
190
+ /**
191
+ * Orderby Users column
192
+ *
193
+ * @since 1.3
194
+ */
195
+ public function handle_requests_orderby_users_column($user_query)
196
+ {
197
+ // query vars
198
+ $vars = $user_query->query_vars;
199
+
200
+ // Column
201
+ $column = $this->get_orderby_type( $vars['orderby'], 'wp-users' );
202
+
203
+ if ( empty($column) )
204
+ return $user_query;
205
+
206
+ // id
207
+ $type = $id = key($column);
208
+
209
+ // Check for user custom fields: column-meta-[customfieldname]
210
+ if ( Codepress_Admin_Columns::is_column_meta($type) )
211
+ $type = 'column-user-meta';
212
+
213
+ // Check for post count: column-user_postcount-[posttype]
214
+ if ( Codepress_Admin_Columns::get_posttype_by_postcount_column($type) )
215
+ $type = 'column-user_postcount';
216
+
217
+ // var
218
+ $cusers = array();
219
+ switch( $type ) :
220
+
221
+ case 'column-user_id':
222
+ $user_query->query_orderby = "ORDER BY ID {$user_query->query_vars['order']}";
223
+ $user_query->query_vars['orderby'] = 'ID';
224
+ break;
225
+
226
+ case 'column-user_registered':
227
+ $user_query->query_orderby = "ORDER BY user_registered {$user_query->query_vars['order']}";
228
+ $user_query->query_vars['orderby'] = 'registered';
229
+ break;
230
+
231
+ case 'column-nickname' :
232
+ $sort_flag = SORT_REGULAR;
233
+ foreach ( $this->get_users_data() as $u ) {
234
+ if ($u->nickname || $this->show_all_results ) {
235
+ $cusers[$u->ID] = $this->prepare_sort_string_value($u->nickname);
236
+ }
237
+ }
238
+ break;
239
+
240
+ case 'column-first_name' :
241
+ $sort_flag = SORT_REGULAR;
242
+ foreach ( $this->get_users_data() as $u ) {
243
+ if ($u->first_name || $this->show_all_results ) {
244
+ $cusers[$u->ID] = $this->prepare_sort_string_value($u->first_name);
245
+ }
246
+ }
247
+ break;
248
+
249
+ case 'column-last_name' :
250
+ $sort_flag = SORT_REGULAR;
251
+ foreach ( $this->get_users_data() as $u ) {
252
+ if ($u->last_name || $this->show_all_results ) {
253
+ $cusers[$u->ID] = $this->prepare_sort_string_value($u->last_name);
254
+ }
255
+ }
256
+ break;
257
+
258
+ case 'column-user_url' :
259
+ $sort_flag = SORT_REGULAR;
260
+ foreach ( $this->get_users_data() as $u ) {
261
+ if ($u->user_url || $this->show_all_results ) {
262
+ $cusers[$u->ID] = $this->prepare_sort_string_value($u->user_url);
263
+ }
264
+ }
265
+ break;
266
+
267
+ case 'column-user_description' :
268
+ $sort_flag = SORT_REGULAR;
269
+ foreach ( $this->get_users_data() as $u ) {
270
+ if ($u->user_description || $this->show_all_results ) {
271
+ $cusers[$u->ID] = $this->prepare_sort_string_value($u->user_description);
272
+ }
273
+ }
274
+ break;
275
+
276
+ case 'column-user_postcount' :
277
+ $post_type = Codepress_Admin_Columns::get_posttype_by_postcount_column($id);
278
+ if ( $post_type ) {
279
+ $sort_flag = SORT_REGULAR;
280
+ foreach ( $this->get_users_data() as $u ) {
281
+ $count = Codepress_Admin_Columns::get_post_count( $post_type, $u->ID );
282
+ $cusers[$u->ID] = $this->prepare_sort_string_value($count);
283
+ }
284
+ }
285
+ break;
286
+
287
+ case 'column-user-meta' :
288
+ $field = $column[$id]['field'];
289
+ if ( $field ) {
290
+
291
+ // order numeric or string
292
+ $sort_flag = SORT_REGULAR;
293
+ if ( $column[$id]['field_type'] == 'numeric' || $column[$id]['field_type'] == 'library_id' ) {
294
+ $sort_flag = SORT_NUMERIC;
295
+ }
296
+
297
+ // sort by metavalue
298
+ foreach ( $this->get_users_data() as $u ) {
299
+ $value = get_metadata('user', $u->ID, $field, true);
300
+ $cusers[$u->ID] = $this->prepare_sort_string_value($value);
301
+ }
302
+ }
303
+ break;
304
+
305
+ /** native WP columns */
306
+
307
+ // role column
308
+ case 'role' :
309
+ $sort_flag = SORT_REGULAR;
310
+ foreach ( $this->get_users_data() as $u ) {
311
+ $role = !empty($u->roles[0]) ? $u->roles[0] : '';
312
+ if ($role || $this->show_all_results ) {
313
+ $cusers[$u->ID] = $this->prepare_sort_string_value($role);
314
+ }
315
+ }
316
+ break;
317
+
318
+ endswitch;
319
+
320
+ if ( isset($sort_flag) ) {
321
+ $user_query = $this->get_users_query_vars( $user_query, $cusers, $sort_flag );
322
+ }
323
+
324
+ return $user_query;
325
+ }
326
+
327
+ /**
328
+ * Orderby Links column
329
+ *
330
+ * Makes use of filter 'get_bookmarks' from bookmark.php to change the result set of the links
331
+ *
332
+ * @since 1.3.1
333
+ */
334
+ public function handle_requests_orderby_links_column()
335
+ {
336
+ // fire only when we are in the admins link-manager
337
+ if ( $this->request_uri_is('link-manager') )
338
+ add_filter( 'get_bookmarks', array( $this, 'callback_requests_orderby_links_column'), 10, 2);
339
+ }
340
+
341
+ /**
342
+ * Orderby Links column
343
+ *
344
+ * @since 1.3.1
345
+ */
346
+ public function callback_requests_orderby_links_column($results, $vars)
347
+ {
348
+ global $wpdb;
349
+
350
+ // apply sorting preference
351
+ $this->apply_sorting_preference( $vars, 'wp-links' );
352
+
353
+ // Column
354
+ $column = $this->get_orderby_type( $vars['orderby'], 'wp-links' );
355
+
356
+ if ( empty($column) )
357
+ return $results;
358
+
359
+ // id
360
+ $type = $id = key($column);
361
+
362
+ // var
363
+ $length = '';
364
+ switch( $type ) :
365
+
366
+ case 'column-link_id':
367
+ if ( version_compare( get_bloginfo('version'), '3.2', '>' ) )
368
+ $vars['orderby'] = 'link_id';
369
+ else
370
+ $vars['orderby'] = 'id';
371
+ break;
372
+
373
+ case 'column-owner':
374
+ $vars['orderby'] = 'link_owner';
375
+ break;
376
+
377
+ case 'column-length':
378
+ $vars['orderby'] = 'length';
379
+ $length = ", CHAR_LENGTH(link_name) AS length";
380
+ break;
381
+
382
+ case 'column-target':
383
+ $vars['orderby'] = 'link_target';
384
+ break;
385
+
386
+ case 'column-description':
387
+ $vars['orderby'] = 'link_description';
388
+ break;
389
+
390
+ case 'column-notes':
391
+ $vars['orderby'] = 'link_notes';
392
+ break;
393
+
394
+ case 'column-rss':
395
+ $vars['orderby'] = 'link_rss';
396
+ break;
397
+
398
+ /** native WP columns */
399
+
400
+ // Relationship
401
+ case 'rel':
402
+ $vars['orderby'] = 'link_rel';
403
+ break;
404
+
405
+ default:
406
+ $vars['orderby'] = '';
407
+
408
+ endswitch;
409
+
410
+ // get bookmarks by orderby vars
411
+ if ( $vars['orderby'] ) {
412
+ $vars['order'] = mysql_escape_string($vars['order']);
413
+ $sql = "SELECT * {$length} FROM {$wpdb->links} WHERE 1=1 ORDER BY {$vars['orderby']} {$vars['order']}";
414
+ $results = $wpdb->get_results($sql);
415
+
416
+ // check for errors
417
+ if( is_wp_error($results) )
418
+ return false;
419
+ }
420
+
421
+ return $results;
422
+ }
423
+
424
+ /**
425
+ * Orderby Comments column
426
+ *
427
+ * @since 1.3.1
428
+ */
429
+ public function callback_requests_orderby_comments_column($pieces, $ref_comment)
430
+ {
431
+ // get query vars
432
+ $vars = $ref_comment->query_vars;
433
+
434
+ // Column
435
+ $column = $this->get_orderby_type( $vars['orderby'], 'wp-comments' );
436
+
437
+ if ( empty($column) )
438
+ return $pieces;
439
+
440
+ // id
441
+ $type = $id = key($column);
442
+
443
+ // var
444
+ switch( $type ) :
445
+
446
+ case 'column-comment_id':
447
+ $pieces['orderby'] = 'comment_ID';
448
+ break;
449
+
450
+ case 'column-author_author':
451
+ $pieces['orderby'] = 'comment_author';
452
+ break;
453
+
454
+ case 'column-author_ip':
455
+ $pieces['orderby'] = 'comment_author_IP';
456
+ break;
457
+
458
+ case 'column-author_url':
459
+ $pieces['orderby'] = 'comment_author_url';
460
+ break;
461
+
462
+ case 'column-author_email':
463
+ $pieces['orderby'] = 'comment_author_email';
464
+ break;
465
+
466
+ case 'column-reply_to':
467
+ break;
468
+
469
+ case 'column-approved':
470
+ $pieces['orderby'] = 'comment_approved';
471
+ break;
472
+
473
+ case 'column-date':
474
+ $pieces['orderby'] = 'comment_date';
475
+ break;
476
+
477
+ case 'column-agent':
478
+ $pieces['orderby'] = 'comment_agent';
479
+ break;
480
+
481
+ case 'column-excerpt':
482
+ $pieces['orderby'] = 'comment_content';
483
+ break;
484
+
485
+ case 'column-date_gmt':
486
+ break;
487
+
488
+ /** native WP columns */
489
+
490
+ // Relationship
491
+ case 'comment':
492
+ $pieces['orderby'] = 'comment_content';
493
+ break;
494
+
495
+ default:
496
+ $vars['orderby'] = '';
497
+
498
+ endswitch;
499
+
500
+ return $pieces;
501
+ }
502
+
503
+ /**
504
+ * Orderby Comments column
505
+ *
506
+ * @since 1.3.1
507
+ */
508
+ public function handle_requests_orderby_comments_column()
509
+ {
510
+ // fire only when we are in the admins edit-comments
511
+ if ( $this->request_uri_is('edit-comments') ) {
512
+ add_filter('comments_clauses', array( $this, 'callback_requests_orderby_comments_column'), 10, 2);
513
+ }
514
+ }
515
+
516
+ /**
517
+ * Get sorting vars in User Query Object
518
+ *
519
+ * @since 1.3
520
+ */
521
+ private function get_users_query_vars( $user_query, $sortusers, $sort_flags = SORT_REGULAR )
522
+ {
523
+ global $wpdb;
524
+
525
+ // vars
526
+ $vars = $user_query->query_vars;
527
+
528
+ // sorting
529
+ if ( $vars['order'] == 'ASC' )
530
+ asort($sortusers, $sort_flags);
531
+ else
532
+ arsort($sortusers, $sort_flags);
533
+
534
+ // alter orderby SQL
535
+ if ( ! empty ( $sortusers ) ) {
536
+ $ids = implode(',', array_keys($sortusers));
537
+ $user_query->query_where .= " AND {$wpdb->prefix}users.ID IN ({$ids})";
538
+ $user_query->query_orderby = "ORDER BY FIELD({$wpdb->prefix}users.ID,{$ids})";
539
+ }
540
+
541
+ // cleanup the vars we dont need
542
+ $vars['order'] = '';
543
+ $vars['orderby'] = '';
544
+
545
+ // set query vars
546
+ $user_query->query_vars = $vars;
547
+
548
+ return $user_query;
549
+ }
550
+
551
+ /**
552
+ * Orderby Media column
553
+ *
554
+ * @since 1.3
555
+ */
556
+ private function get_orderby_media_vars($vars)
557
+ {
558
+ // apply sorting preference
559
+ $this->apply_sorting_preference( $vars, 'wp-media' );
560
+
561
+ // when sorting still isn't set we will just return the requested vars
562
+ if ( empty( $vars['orderby'] ) )
563
+ return $vars;
564
+
565
+ // Column
566
+ $column = $this->get_orderby_type( $vars['orderby'], 'wp-media' );
567
+
568
+ if ( empty($column) )
569
+ return $vars;
570
+
571
+ $id = key($column);
572
+
573
+ // var
574
+ $cposts = array();
575
+ switch( $id ) :
576
+
577
+ case 'column-mediaid' :
578
+ $vars['orderby'] = 'ID';
579
+ break;
580
+
581
+ case 'column-width' :
582
+ $sort_flag = SORT_NUMERIC;
583
+ foreach ( $this->get_any_posts_by_posttype('attachment') as $p ) {
584
+ $meta = wp_get_attachment_metadata($p->ID);
585
+ $width = !empty($meta['width']) ? $meta['width'] : 0;
586
+ if ( $width || $this->show_all_results )
587
+ $cposts[$p->ID] = $width;
588
+ }
589
+ break;
590
+
591
+ case 'column-height' :
592
+ $sort_flag = SORT_NUMERIC;
593
+ foreach ( $this->get_any_posts_by_posttype('attachment') as $p ) {
594
+ $meta = wp_get_attachment_metadata($p->ID);
595
+ $height = !empty($meta['height']) ? $meta['height'] : 0;
596
+ if ( $height || $this->show_all_results )
597
+ $cposts[$p->ID] = $height;
598
+ }
599
+ break;
600
+
601
+ case 'column-dimensions' :
602
+ $sort_flag = SORT_NUMERIC;
603
+ foreach ( $this->get_any_posts_by_posttype('attachment') as $p ) {
604
+ $meta = wp_get_attachment_metadata($p->ID);
605
+ $height = !empty($meta['height']) ? $meta['height'] : 0;
606
+ $width = !empty($meta['width']) ? $meta['width'] : 0;
607
+ $surface = $height*$width;
608
+
609
+ if ( $surface || $this->show_all_results )
610
+ $cposts[$p->ID] = $surface;
611
+ }
612
+ break;
613
+
614
+ case 'column-caption' :
615
+ $sort_flag = SORT_STRING;
616
+ foreach ( $this->get_any_posts_by_posttype('attachment') as $p ) {
617
+ if ( $p->post_excerpt || $this->show_all_results ) {
618
+ $cposts[$p->ID] = $this->prepare_sort_string_value($p->post_excerpt);
619
+ }
620
+ }
621
+ break;
622
+
623
+ case 'column-description' :
624
+ $sort_flag = SORT_STRING;
625
+ foreach ( $this->get_any_posts_by_posttype('attachment') as $p ) {
626
+ if ( $p->post_content || $this->show_all_results ) {
627
+ $cposts[$p->ID] = $this->prepare_sort_string_value( $p->post_content );
628
+ }
629
+ }
630
+ break;
631
+
632
+ case 'column-mime_type' :
633
+ $sort_flag = SORT_STRING;
634
+ foreach ( $this->get_any_posts_by_posttype('attachment') as $p ) {
635
+ if ( $p->post_mime_type || $this->show_all_results ) {
636
+ $cposts[$p->ID] = $this->prepare_sort_string_value( $p->post_mime_type );
637
+ }
638
+ }
639
+ break;
640
+
641
+ case 'column-file_name' :
642
+ $sort_flag = SORT_STRING;
643
+ foreach ( $this->get_any_posts_by_posttype('attachment') as $p ) {
644
+ $meta = get_post_meta($p->ID, '_wp_attached_file', true);
645
+ $file = !empty($meta) ? basename($meta) : '';
646
+ if ( $file || $this->show_all_results ) {
647
+ $cposts[$p->ID] = $file;
648
+ }
649
+ }
650
+ break;
651
+
652
+ case 'column-alternate_text' :
653
+ $sort_flag = SORT_STRING;
654
+ foreach ( $this->get_any_posts_by_posttype('attachment') as $p ) {
655
+ $alt = get_post_meta($p->ID, '_wp_attachment_image_alt', true);
656
+ if ( $alt || $this->show_all_results ) {
657
+ $cposts[$p->ID] = $this->prepare_sort_string_value( $alt );
658
+ }
659
+ }
660
+ break;
661
+
662
+ case 'column-filesize' :
663
+ $sort_flag = SORT_NUMERIC;
664
+ foreach ( $this->get_any_posts_by_posttype('attachment') as $p ) {
665
+ $file = wp_get_attachment_url($p->ID);
666
+ if ( $file || $this->show_all_results ) {
667
+ $abs = str_replace( WP_CONTENT_URL, WP_CONTENT_DIR, $file);
668
+ $cposts[$p->ID] = $this->prepare_sort_string_value( filesize($abs) );
669
+ }
670
+ }
671
+ break;
672
+
673
+ endswitch;
674
+
675
+ // we will add the sorted post ids to vars['post__in'] and remove unused vars
676
+ if ( isset($sort_flag) ) {
677
+ $vars = $this->get_vars_post__in( $vars, $cposts, $sort_flag );
678
+ }
679
+
680
+ return $vars;
681
+ }
682
+
683
+ /**
684
+ * Orderby Posts column
685
+ *
686
+ * @since 1.3
687
+ */
688
+ private function get_orderby_posts_vars($vars)
689
+ {
690
+ $post_type = $vars['post_type'];
691
+
692
+ // apply sorting preference
693
+ $this->apply_sorting_preference( $vars, $post_type );
694
+
695
+ // no sorting
696
+ if ( empty( $vars['orderby'] ) ) {
697
+ return $vars;
698
+ }
699
+
700
+ // Column
701
+ $column = $this->get_orderby_type( $vars['orderby'], $post_type );
702
+
703
+ if ( empty($column) )
704
+ return $vars;
705
+
706
+ // id
707
+ $type = $id = key($column);
708
+
709
+ // Check for taxonomies, such as column-taxonomy-[taxname]
710
+ if ( strpos($type, 'column-taxonomy-') !== false )
711
+ $type = 'column-taxonomy';
712
+
713
+ // Check for Custom Field
714
+ if ( Codepress_Admin_Columns::is_column_meta($type) )
715
+ $type = 'column-post-meta';
716
+
717
+ // var
718
+ $cposts = array();
719
+ switch( $type ) :
720
+
721
+ case 'column-postid' :
722
+ $vars['orderby'] = 'ID';
723
+ break;
724
+
725
+ case 'column-order' :
726
+ $vars['orderby'] = 'menu_order';
727
+ break;
728
+
729
+ case 'column-modified' :
730
+ $vars['orderby'] = 'modified';
731
+ break;
732
+
733
+ case 'column-comment-count' :
734
+ $vars['orderby'] = 'comment_count';
735
+ break;
736
+
737
+ case 'column-post-meta' :
738
+ $field = $column[$id]['field'];
739
+
740
+ // orderby type
741
+ $field_type = 'meta_value';
742
+ if ( $column[$id]['field_type'] == 'numeric' || $column[$id]['field_type'] == 'library_id' )
743
+ $field_type = 'meta_value_num';
744
+
745
+ $vars = array_merge($vars, array(
746
+ 'meta_key' => $field,
747
+ 'orderby' => $field_type
748
+ ));
749
+ break;
750
+
751
+ case 'column-excerpt' :
752
+ $sort_flag = SORT_STRING;
753
+ foreach ( $this->get_any_posts_by_posttype($post_type) as $p ) {
754
+ $cposts[$p->ID] = $this->prepare_sort_string_value($p->post_content);
755
+ }
756
+ break;
757
+
758
+ case 'column-word-count' :
759
+ $sort_flag = SORT_NUMERIC;
760
+ foreach ( $this->get_any_posts_by_posttype($post_type) as $p ) {
761
+ $cposts[$p->ID] = str_word_count( Codepress_Admin_Columns::strip_trim( $p->post_content ) );
762
+ }
763
+ break;
764
+
765
+ case 'column-page-template' :
766
+ $sort_flag = SORT_STRING;
767
+ $templates = get_page_templates();
768
+ foreach ( $this->get_any_posts_by_posttype($post_type) as $p ) {
769
+ $page_template = get_post_meta($p->ID, '_wp_page_template', true);
770
+ $cposts[$p->ID] = array_search($page_template, $templates);
771
+ }
772
+ break;
773
+
774
+ case 'column-post_formats' :
775
+ $sort_flag = SORT_REGULAR;
776
+ foreach ( $this->get_any_posts_by_posttype($post_type) as $p ) {
777
+ $cposts[$p->ID] = get_post_format($p->ID);
778
+ }
779
+ break;
780
+
781
+ case 'column-attachment' :
782
+ case 'column-attachment-count' :
783
+ $sort_flag = SORT_NUMERIC;
784
+ foreach ( $this->get_any_posts_by_posttype($post_type) as $p ) {
785
+ $cposts[$p->ID] = count( Codepress_Admin_Columns::get_attachment_ids($p->ID) );
786
+ }
787
+ break;
788
+
789
+ case 'column-page-slug' :
790
+ $sort_flag = SORT_REGULAR;
791
+ foreach ( $this->get_any_posts_by_posttype($post_type) as $p ) {
792
+ $cposts[$p->ID] = $p->post_name;
793
+ }
794
+ break;
795
+
796
+ case 'column-sticky' :
797
+ $sort_flag = SORT_REGULAR;
798
+ $stickies = get_option('sticky_posts');
799
+ foreach ( $this->get_any_posts_by_posttype($post_type) as $p ) {
800
+ $cposts[$p->ID] = $p->ID;
801
+ if ( !empty($stickies) && in_array($p->ID, $stickies ) ) {
802
+ $cposts[$p->ID] = 0;
803
+ }
804
+ }
805
+ break;
806
+
807
+ case 'column-featured_image' :
808
+ $sort_flag = SORT_REGULAR;
809
+ foreach ( $this->get_any_posts_by_posttype($post_type) as $p ) {
810
+ $cposts[$p->ID] = $p->ID;
811
+ $thumb = get_the_post_thumbnail($p->ID);
812
+ if ( !empty($thumb) ) {
813
+ $cposts[$p->ID] = 0;
814
+ }
815
+ }
816
+ break;
817
+
818
+ case 'column-roles' :
819
+ $sort_flag = SORT_STRING;
820
+ foreach ( $this->get_any_posts_by_posttype($post_type) as $p ) {
821
+ $cposts[$p->ID] = 0;
822
+ $userdata = get_userdata($p->post_author);
823
+ if ( !empty($userdata->roles[0]) ) {
824
+ $cposts[$p->ID] = $userdata->roles[0];
825
+ }
826
+ }
827
+ break;
828
+
829
+ case 'column-status' :
830
+ $sort_flag = SORT_STRING;
831
+ foreach ( $this->get_any_posts_by_posttype($post_type) as $p ) {
832
+ $cposts[$p->ID] = $p->post_status.strtotime($p->post_date);
833
+ }
834
+ break;
835
+
836
+ case 'column-comment-status' :
837
+ $sort_flag = SORT_STRING;
838
+ foreach ( $this->get_any_posts_by_posttype($post_type) as $p ) {
839
+ $cposts[$p->ID] = $p->comment_status;
840
+ }
841
+ break;
842
+
843
+ case 'column-ping-status' :
844
+ $sort_flag = SORT_STRING;
845
+ foreach ( $this->get_any_posts_by_posttype($post_type) as $p ) {
846
+ $cposts[$p->ID] = $p->ping_status;
847
+ }
848
+ break;
849
+
850
+ case 'column-taxonomy' :
851
+ $sort_flag = SORT_STRING; // needed to sort
852
+ $taxonomy = str_replace('column-taxonomy-', '', $id);
853
+ $cposts = $this->get_posts_sorted_by_taxonomy($post_type, $taxonomy);
854
+ break;
855
+
856
+ case 'column-author-name' :
857
+ $sort_flag = SORT_STRING;
858
+ $display_as = $column[$id]['display_as'];
859
+ if( 'userid' == $display_as ) {
860
+ $sort_flag = SORT_NUMERIC;
861
+ }
862
+ foreach ( $this->get_any_posts_by_posttype($post_type) as $p ) {
863
+ if ( !empty($p->post_author) ) {
864
+ $name = Codepress_Admin_Columns::get_author_field_by_nametype($display_as, $p->post_author);
865
+ $cposts[$p->ID] = $name;
866
+ }
867
+ }
868
+ break;
869
+
870
+ case 'column-before-moretag' :
871
+ $sort_flag = SORT_STRING;
872
+ foreach ( $this->get_any_posts_by_posttype($post_type) as $p ) {
873
+ $extended = get_extended($p->post_content);
874
+ $content = !empty($extended['extended']) ? $extended['main'] : '';
875
+ $cposts[$p->ID] = $this->prepare_sort_string_value($content);
876
+ }
877
+ break;
878
+
879
+ /** native WP columns */
880
+
881
+ // categories
882
+ case 'categories' :
883
+ $sort_flag = SORT_STRING; // needed to sort
884
+ $cposts = $this->get_posts_sorted_by_taxonomy($post_type, 'category');
885
+ break;
886
+
887
+ // tags
888
+ case 'tags' :
889
+ $sort_flag = SORT_STRING; // needed to sort
890
+ $cposts = $this->get_posts_sorted_by_taxonomy($post_type, 'post_tag');
891
+ break;
892
+
893
+ endswitch;
894
+
895
+ // we will add the sorted post ids to vars['post__in'] and remove unused vars
896
+ if ( isset($sort_flag) ) {
897
+ $vars = $this->get_vars_post__in( $vars, $cposts, $sort_flag );
898
+ }
899
+
900
+ return $vars;
901
+ }
902
+
903
+ /**
904
+ * Set sorting preference
905
+ *
906
+ * after sorting we will save this sorting preference to the column item
907
+ * we set the default_order to either asc, desc or empty.
908
+ * only ONE column item PER type can have a default_order
909
+ *
910
+ * @since 1.4.6.5
911
+ */
912
+ function set_sorting_preference( $type, $orderby = '', $order = 'asc' )
913
+ {
914
+ if ( !$orderby )
915
+ return false;
916
+
917
+ $options = get_user_meta( $this->current_user_id, 'cpac_sorting_preference', true );
918
+
919
+ $options[$type] = array(
920
+ 'orderby' => $orderby,
921
+ 'order' => $order
922
+ );
923
+
924
+ update_user_meta( $this->current_user_id, 'cpac_sorting_preference', $options );
925
+ }
926
+
927
+ /**
928
+ * Get sorting preference
929
+ *
930
+ * The default sorting of the column is saved to it's property default_order.
931
+ * Returns the orderby and order value of that column.
932
+ *
933
+ * @since 1.4.6.5
934
+ */
935
+ function get_sorting_preference( $type )
936
+ {
937
+ $options = get_user_meta( $this->current_user_id, 'cpac_sorting_preference', true );
938
+
939
+ if ( empty($options[$type]) )
940
+ return false;
941
+
942
+ return $options[$type];
943
+ }
944
+
945
+ /**
946
+ * Apply sorting preference
947
+ *
948
+ * @since 1.4.6.5
949
+ */
950
+ function apply_sorting_preference( &$vars, $type )
951
+ {
952
+ // user has not sorted
953
+ if ( empty( $vars['orderby'] ) ) {
954
+
955
+ // did the user sorted this column some other time?
956
+ if ( $preference = $this->get_sorting_preference($type) ) {
957
+ $vars['orderby'] = $preference['orderby'];
958
+ $vars['order'] = $preference['order'];
959
+
960
+ // used by active state in column header
961
+ $_GET['orderby'] = $preference['orderby'];
962
+ $_GET['order'] = $preference['order'];
963
+ }
964
+ }
965
+
966
+ // save the order preference
967
+ if ( !empty( $vars['orderby'] ) ) {
968
+ $this->set_sorting_preference( $type, $vars['orderby'], $vars['order'] );
969
+ }
970
+ }
971
+
972
+ /**
973
+ * Get posts sorted by taxonomy
974
+ *
975
+ * This will post ID's by the first term in the taxonomy
976
+ *
977
+ * @since 1.4.5
978
+ */
979
+ function get_posts_sorted_by_taxonomy($post_type, $taxonomy = 'category')
980
+ {
981
+ $cposts = array();
982
+ foreach ( $this->get_any_posts_by_posttype($post_type) as $p ) {
983
+ $cposts[$p->ID] = '';
984
+ $terms = get_the_terms($p->ID, $taxonomy);
985
+ if ( !is_wp_error($terms) && !empty($terms) ) {
986
+ // only use the first term to sort
987
+ $term = array_shift(array_values($terms));
988
+ if ( isset($term->term_id) ) {
989
+ $cposts[$p->ID] = sanitize_term_field('name', $term->name, $term->term_id, $term->taxonomy, 'display');
990
+ }
991
+ }
992
+ }
993
+ return $cposts;
994
+ }
995
+
996
+ /**
997
+ * Set post__in for use in WP_Query
998
+ *
999
+ * This will order the ID's asc or desc and set the appropriate filters.
1000
+ *
1001
+ * @since 1.2.1
1002
+ */
1003
+ private function get_vars_post__in( &$vars, $sortposts, $sort_flags = SORT_REGULAR )
1004
+ {
1005
+ // sort post ids by value
1006
+ if ( $vars['order'] == 'asc' )
1007
+ asort($sortposts, $sort_flags);
1008
+ else
1009
+ arsort($sortposts, $sort_flags);
1010
+
1011
+ // this will make sure WP_Query will use the order of the ids that we have just set in 'post__in'
1012
+ // set priority higher then default to prevent conflicts with 3rd party plugins
1013
+ add_filter('posts_orderby', array( $this, 'filter_orderby_post__in'), 10, 2 );
1014
+
1015
+ // cleanup the vars we dont need
1016
+ $vars['order'] = '';
1017
+ $vars['orderby'] = '';
1018
+
1019
+ // add the sorted post ids to the query with the use of post__in
1020
+ $vars['post__in'] = array_keys($sortposts);
1021
+
1022
+ return $vars;
1023
+ }
1024
+
1025
+ /**
1026
+ * Get orderby type
1027
+ *
1028
+ * @since 1.1
1029
+ */
1030
+ private function get_orderby_type($orderby, $type)
1031
+ {
1032
+ $db_columns = Codepress_Admin_Columns::get_stored_columns($type);
1033
+
1034
+ if ( $db_columns ) {
1035
+ foreach ( $db_columns as $id => $vars ) {
1036
+
1037
+ // check which custom column was clicked
1038
+ if ( isset( $vars['label'] ) && $orderby == $this->sanitize_string( $vars['label'] ) ) {
1039
+ $column[$id] = $vars;
1040
+ return $column;
1041
+ }
1042
+ }
1043
+ }
1044
+ return false;
1045
+ }
1046
+
1047
+ /**
1048
+ * Maintain order of ids that are set in the post__in var.
1049
+ *
1050
+ * This will force the returned posts to use the order of the ID's that
1051
+ * have been set in post__in. Without this the ID's will be set in numeric order.
1052
+ * See the WP_Query object for more info about the use of post__in.
1053
+ *
1054
+ * @since 1.2.1
1055
+ */
1056
+ public function filter_orderby_post__in($orderby, $wp)
1057
+ {
1058
+ global $wpdb;
1059
+
1060
+ // we need the query vars
1061
+ $vars = $wp->query_vars;
1062
+ if ( ! empty ( $vars['post__in'] ) ) {
1063
+ // now we can get the ids
1064
+ $ids = implode(',', $vars['post__in']);
1065
+
1066
+ // by adding FIELD to the SQL query we are forcing the order of the ID's
1067
+ return "FIELD({$wpdb->prefix}posts.ID,{$ids})";
1068
+ }
1069
+ }
1070
+
1071
+ /**
1072
+ * Get any posts by post_type
1073
+ *
1074
+ * @since 1.2.1
1075
+ */
1076
+ private function get_any_posts_by_posttype( $post_type )
1077
+ {
1078
+ $any_posts = (array) get_posts(array(
1079
+ 'numberposts' => -1,
1080
+ 'post_status' => 'any',
1081
+ 'post_type' => $post_type
1082
+ ));
1083
+
1084
+ // trash posts are not included in the posts_status 'any' by default
1085
+ $trash_posts = (array) get_posts(array(
1086
+ 'numberposts' => -1,
1087
+ 'post_status' => 'trash',
1088
+ 'post_type' => $post_type
1089
+ ));
1090
+
1091
+ $all_posts = array_merge($any_posts, $trash_posts);
1092
+
1093
+ return (array) $all_posts;
1094
+ }
1095
+
1096
+ /**
1097
+ * Request URI is
1098
+ *
1099
+ * @since 1.3.1
1100
+ */
1101
+ private function request_uri_is( $screen_id = '' )
1102
+ {
1103
+ if (strpos( $_SERVER['REQUEST_URI'], "/{$screen_id}.php" ) !== false )
1104
+ return true;
1105
+
1106
+ return false;
1107
+ }
1108
+
1109
+ /**
1110
+ * Prepare the value for being by sorting
1111
+ *
1112
+ * @since 1.3
1113
+ */
1114
+ private function prepare_sort_string_value($string)
1115
+ {
1116
+ // remove tags and only get the first 20 chars and force lowercase.
1117
+ $string = strtolower( substr( Codepress_Admin_Columns::strip_trim($string),0 ,20 ) );
1118
+
1119
+ return $string;
1120
+ }
1121
+
1122
+ /**
1123
+ * Get users data
1124
+ *
1125
+ * @since 1.3
1126
+ */
1127
+ function get_users_data()
1128
+ {
1129
+ $userdatas = array();
1130
+ $wp_users = get_users( array(
1131
+ 'blog_id' => $GLOBALS['blog_id'],
1132
+ ));
1133
+ foreach ( $wp_users as $u ) {
1134
+ $userdatas[$u->ID] = get_userdata($u->ID);
1135
+ }
1136
+ return $userdatas;
1137
+ }
1138
+
1139
+ /**
1140
+ * Register filtering columns
1141
+ *
1142
+ * @since 1.4.2
1143
+ */
1144
+ function register_filtering_columns()
1145
+ {
1146
+ if ( ! $this->unlocked || apply_filters( 'cpac-remove-filtering-columns', true ) )
1147
+ return false;
1148
+
1149
+ // hook into wordpress
1150
+ add_action('restrict_manage_posts', array($this, 'callback_restrict_posts'));
1151
+ }
1152
+
1153
+ /**
1154
+ * Add taxonomy filters to posts
1155
+ *
1156
+ * @since 1.4.2
1157
+ */
1158
+ function callback_restrict_posts()
1159
+ {
1160
+ global $post_type_object;
1161
+
1162
+ if ( !isset($post_type_object->name) )
1163
+ return false;
1164
+
1165
+ // make a filter foreach taxonomy
1166
+ $taxonomies = get_object_taxonomies($post_type_object->name, 'names');
1167
+
1168
+ // get stored columns
1169
+ $db_columns = Codepress_Admin_Columns::get_stored_columns($post_type_object->name);
1170
+
1171
+ if ( $taxonomies ) {
1172
+ foreach ( $taxonomies as $tax ) {
1173
+
1174
+ // ignore core taxonomies
1175
+ if ( in_array($tax, array('post_tag','category','post_format') ) ) {
1176
+ continue;
1177
+ }
1178
+
1179
+ // only display taxonomy that is active as a column
1180
+ if ( isset($db_columns['column-taxonomy-'.$tax]) && $db_columns['column-taxonomy-'.$tax]['state'] == 'on' ) {
1181
+
1182
+ $terms = get_terms($tax);
1183
+ $terms = $this->indent($terms, 0, 'parent', 'term_id');
1184
+ $terms = $this->apply_dropdown_markup($terms);
1185
+
1186
+ $select = "<option value=''>".__('Show all ', CPAC_TEXTDOMAIN)."{$tax}</option>";
1187
+ if (!empty($terms)) {
1188
+ foreach( $terms as $term_slug => $term) {
1189
+
1190
+ $selected = isset($_GET[$tax]) && $term_slug == $_GET[$tax] ? " selected='selected'" : '';
1191
+ $select .= "<option value='{$term_slug}'{$selected}>{$term}</option>";
1192
+ }
1193
+ echo "<select class='postform' name='{$tax}'>{$select}</select>";
1194
+ }
1195
+ }
1196
+ }
1197
+ }
1198
+ }
1199
+
1200
+ /**
1201
+ * Applies dropdown markup for taxonomy dropdown
1202
+ *
1203
+ * @since 1.4.2
1204
+ */
1205
+ private function apply_dropdown_markup($array, $level = 0, $output = array())
1206
+ {
1207
+ foreach($array as $v) {
1208
+
1209
+ $prefix = '';
1210
+ for($i=0; $i<$level; $i++) {
1211
+ $prefix .= '&nbsp;&nbsp;';
1212
+ }
1213
+
1214
+ $output[$v->slug] = $prefix . $v->name;
1215
+
1216
+ if ( !empty($v->children) ) {
1217
+ $output = $this->apply_dropdown_markup($v->children, ($level + 1), $output);
1218
+ }
1219
+ }
1220
+
1221
+ return $output;
1222
+ }
1223
+
1224
+ /**
1225
+ * Indents any object as long as it has a unique id and that of its parent.
1226
+ *
1227
+ * @since 1.4.2
1228
+ */
1229
+ private function indent($array, $parentId = 0, $parentKey = 'post_parent', $selfKey = 'ID', $childrenKey = 'children')
1230
+ {
1231
+ $indent = array();
1232
+
1233
+ // clean counter
1234
+ $i = 0;
1235
+
1236
+ foreach($array as $v) {
1237
+
1238
+ if ($v->$parentKey == $parentId) {
1239
+ $indent[$i] = $v;
1240
+ $indent[$i]->$childrenKey = $this->indent($array, $v->$selfKey, $parentKey, $selfKey);
1241
+
1242
+ $i++;
1243
+ }
1244
+ }
1245
+
1246
+ return $indent;
1247
+ }
1248
+ }
1249
+
1250
  ?>
classes/utility.php CHANGED
@@ -1,26 +1,25 @@
1
- <?php
2
-
3
- /**
4
- * Fix for getting the columns loaded by WordPress SEO Yoast
5
- *
6
- * The added columns from WordPress SEO by Yoast weren't available on
7
- * the admin columns settings page. The eason was that class-metabox.php was prevented
8
- * from loading. This fix will also load this class when admin columns is loaded.
9
- *
10
- * @since 1.4.6
11
- */
12
- function pre_load_wordpress_seo_class_metabox()
13
- {
14
- global $pagenow;
15
-
16
- if (
17
- isset($_REQUEST['page']) &&
18
- 'codepress-admin-columns' == $_REQUEST['page'] &&
19
- 'options-general.php' == $pagenow &&
20
- defined('WPSEO_PATH') &&
21
- file_exists(WPSEO_PATH.'admin/class-metabox.php')
22
- ) {
23
- require_once WPSEO_PATH.'admin/class-metabox.php';
24
- }
25
- }
26
  add_action( 'plugins_loaded', 'pre_load_wordpress_seo_class_metabox', 0 );
1
+ <?php
2
+
3
+ /**
4
+ * Fix for getting the columns loaded by WordPress SEO Yoast
5
+ *
6
+ * The added columns from WordPress SEO by Yoast weren't available on
7
+ * the admin columns settings page. The reason was that class-metabox.php was prevented
8
+ * from loading. This fix will also load this class when admin columns is loaded.
9
+ *
10
+ * @since 1.4.6
11
+ */
12
+ function pre_load_wordpress_seo_class_metabox()
13
+ {
14
+ global $pagenow;
15
+
16
+ if (
17
+ isset( $_REQUEST['page'] ) &&
18
+ 'codepress-admin-columns' == $_REQUEST['page'] &&
19
+ 'options-general.php' == $pagenow &&
20
+ defined('WPSEO_PATH') && file_exists(WPSEO_PATH.'admin/class-metabox.php')
21
+ ) {
22
+ require_once WPSEO_PATH.'admin/class-metabox.php';
23
+ }
24
+ }
 
25
  add_action( 'plugins_loaded', 'pre_load_wordpress_seo_class_metabox', 0 );
classes/values.php CHANGED
@@ -1,518 +1,530 @@
1
- <?php
2
-
3
- /**
4
- * CPAC_Values Class
5
- *
6
- * @since 1.4.4
7
- *
8
- */
9
- class CPAC_Values
10
- {
11
- protected $excerpt_length, $thumbnail_size;
12
-
13
- /**
14
- * Constructor
15
- *
16
- * @since 1.0
17
- */
18
- function __construct()
19
- {
20
- // number of words
21
- $this->excerpt_length = 20;
22
- $this->thumbnail_size = apply_filters( 'cpac_thumbnail_size', array(80,80) );
23
- }
24
-
25
- /**
26
- * Admin requests for orderby column
27
- *
28
- * @since 1.0
29
- */
30
- public function get_stored_columns($type)
31
- {
32
- return Codepress_Admin_Columns::get_stored_columns($type);
33
- }
34
-
35
- /**
36
- * Checks if column-meta key exists
37
- *
38
- * @since 1.0
39
- */
40
- public static function is_column_meta( $id = '' )
41
- {
42
- return Codepress_Admin_Columns::is_column_meta( $id );
43
- }
44
-
45
- /**
46
- * Returns excerpt
47
- *
48
- * @since 1.0
49
- */
50
- protected function get_post_excerpt($post_id)
51
- {
52
- global $post;
53
-
54
- $save_post = $post;
55
- $post = get_post($post_id);
56
- $excerpt = get_the_excerpt();
57
- $post = $save_post;
58
-
59
- $output = $this->get_shortened_string($excerpt, $this->excerpt_length );
60
-
61
- return $output;
62
- }
63
-
64
- /**
65
- * Returns shortened string
66
- *
67
- * @since 1.0
68
- */
69
- protected function get_shortened_string($string = '', $num_words = 55, $more = null)
70
- {
71
- if (!$string)
72
- return false;
73
-
74
- return wp_trim_words( $string, $num_words, $more );
75
- }
76
-
77
- /**
78
- * Get image from assets folder
79
- *
80
- * @since 1.3.1
81
- */
82
- protected function get_asset_image($name = '', $title = '')
83
- {
84
- if ( $name )
85
- return sprintf("<img alt='' src='%s' title='%s'/>", CPAC_URL."/assets/images/{$name}", $title);
86
- }
87
-
88
- /**
89
- * Shorten URL
90
- *
91
- * @since 1.3.1
92
- */
93
- protected function get_shorten_url($url = '')
94
- {
95
- if ( !$url )
96
- return false;
97
-
98
- // shorten url
99
- $short_url = url_shorten( $url );
100
-
101
- return "<a title='{$url}' href='{$url}'>{$short_url}</a>";
102
- }
103
-
104
- /**
105
- * Get column value of post attachments
106
- *
107
- * @since 1.0
108
- */
109
- protected function get_column_value_attachments( $post_id )
110
- {
111
- $result = '';
112
- $attachment_ids = $this->get_attachment_ids($post_id);
113
- if ( $attachment_ids ) {
114
- foreach ( $attachment_ids as $attach_id ) {
115
- if ( wp_get_attachment_image($attach_id) )
116
- $result .= wp_get_attachment_image( $attach_id, $this->thumbnail_size, true );
117
- }
118
- }
119
- return $result;
120
- }
121
-
122
- /**
123
- * Get column value of post attachments
124
- *
125
- * @since 1.2.1
126
- */
127
- protected function get_attachment_ids( $post_id )
128
- {
129
- return Codepress_Admin_Columns::get_attachment_ids( $post_id );
130
- }
131
-
132
- /**
133
- * Get a thumbnail
134
- *
135
- * @since 1.0
136
- */
137
- protected function get_thumbnail( $image = '' )
138
- {
139
- if ( empty($image) )
140
- return false;
141
-
142
- // get thumbnail image size
143
- $image_size = $this->thumbnail_size; // w, h
144
-
145
- // incase the thumbnail dimension is set by name
146
- if ( !is_array($image_size) ) {
147
- global $_wp_additional_image_sizes;
148
- if ( isset($_wp_additional_image_sizes[$image_size]) ) {
149
- $_size = $_wp_additional_image_sizes[$image_size];
150
- $image_size = array( $_size['width'], $_size['height'] );
151
- }
152
- }
153
-
154
- // fallback for image size incase the passed size name does not exists
155
- if ( !isset($image_size[0]) || !isset($image_size[1]) ) {
156
- $image_size = array(80, 80);
157
- }
158
-
159
- // get correct image path
160
- $image_path = str_replace( WP_CONTENT_URL, WP_CONTENT_DIR, $image);
161
-
162
- // resize image
163
- if ( file_exists($image_path) && $this->is_image($image_path) ) {
164
- $resized = image_resize( $image_path, $image_size[0], $image_size[1], true);
165
-
166
- // resize worked
167
- if ( ! is_wp_error( $resized ) ) {
168
- $image = str_replace( WP_CONTENT_DIR, WP_CONTENT_URL, $resized);
169
-
170
- return "<img src='{$image}' alt='' width='{$image_size[0]}' height='{$image_size[1]}' />";
171
- }
172
-
173
- // resizing failed so let's return full image with maxed dimensions
174
- else {
175
- return "<img src='{$image}' alt='' style='max-width:{$image_size[0]}px;max-height:{$image_size[1]}px' />";
176
- }
177
- }
178
-
179
- return false;
180
- }
181
-
182
- /**
183
- * Checks an URL for image extension
184
- *
185
- * @since 1.2
186
- */
187
- protected function is_image($url)
188
- {
189
- $validExt = array('.jpg', '.jpeg', '.gif', '.png', '.bmp');
190
- $ext = strrchr($url, '.');
191
-
192
- return in_array($ext, $validExt);
193
- }
194
-
195
- /**
196
- * Get a thumbnail
197
- *
198
- * @since 1.3.1
199
- */
200
- protected function get_media_thumbnails($meta)
201
- {
202
- $meta = $this->strip_trim( str_replace(' ','', $meta) );
203
-
204
- // split media ids
205
- $media_ids = array($meta);
206
- if ( strpos($meta, ',') !== false )
207
- $media_ids = explode(',', $meta);
208
-
209
- // check if media exists
210
- $thumbs = '';
211
- foreach ( $media_ids as $media_id )
212
- if ( is_numeric($media_id) )
213
- $thumbs .= wp_get_attachment_url($media_id) ? "<span class='cpac-column-value-image'>".wp_get_attachment_image( $media_id, array(80,80), true )."</span>" : '';
214
-
215
- return $thumbs;
216
- }
217
-
218
- /**
219
- * Convert file size to readable format
220
- *
221
- * @since 1.4.5
222
- */
223
- function get_readable_filesize($size)
224
- {
225
- $filesizename = array(" Bytes", " KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB");
226
- return $size ? round($size/pow(1024, ($i = floor(log($size, 1024)))), 2) . $filesizename[$i] : '0 Bytes';
227
- }
228
-
229
- /**
230
- * Get column value of Custom Field
231
- *
232
- * @since 1.0
233
- */
234
- protected function get_column_value_custom_field($object_id, $column_name, $meta_type = 'post')
235
- {
236
- /** Users */
237
- if ( $meta_type == 'user' ) {
238
- $type = 'wp-users';
239
- }
240
-
241
- /** Posts */
242
- else {
243
- $type = get_post_type($object_id);
244
- }
245
-
246
- // get column
247
- $columns = $this->get_stored_columns($type);
248
-
249
- // inputs
250
- $field = isset($columns[$column_name]['field']) ? $columns[$column_name]['field'] : '';
251
- $fieldtype = isset($columns[$column_name]['field_type']) ? $columns[$column_name]['field_type'] : '';
252
- $before = isset($columns[$column_name]['before']) ? $columns[$column_name]['before'] : '';
253
- $after = isset($columns[$column_name]['after']) ? $columns[$column_name]['after'] : '';
254
-
255
- // rename hidden custom fields to their original name
256
- $field = substr($field,0,10) == "cpachidden" ? str_replace('cpachidden','',$field) : $field;
257
-
258
- // Get meta field value
259
- $meta = get_metadata($meta_type, $object_id, $field, true);
260
-
261
- // multiple meta values
262
- if ( ( $fieldtype == 'array' && is_array($meta) ) || is_array($meta) ) {
263
- $meta = get_metadata($meta_type, $object_id, $field, true);
264
- $meta = $this->recursive_implode(', ', $meta);
265
- }
266
-
267
- // make sure there are no serialized arrays or null data
268
- if ( !is_string($meta) )
269
- return false;
270
-
271
- // handles each field type differently..
272
- switch ($fieldtype) :
273
-
274
- // Image
275
- case "image" :
276
- $meta = $this->get_thumbnail($meta);
277
- break;
278
-
279
- // Media Library ID
280
- case "library_id" :
281
- $meta = $this->get_media_thumbnails($meta);
282
- break;
283
-
284
- // Excerpt
285
- case "excerpt" :
286
- $meta = $this->get_shortened_string($meta, $this->excerpt_length);
287
- break;
288
-
289
- // Date
290
- case "date" :
291
- $meta = $this->get_date($meta);
292
- break;
293
-
294
- // Post Title
295
- case "title_by_id" :
296
- $titles = $this->get_custom_field_value_title($meta);
297
- if ( $titles )
298
- $meta = $titles;
299
- break;
300
-
301
- // User Name
302
- case "user_by_id" :
303
- $names = $this->get_custom_field_value_user($meta);
304
- if ( $names )
305
- $meta = $names;
306
- break;
307
-
308
- // Checkmark
309
- case "checkmark" :
310
- $checkmark = $this->get_asset_image('checkmark.png');
311
-
312
- if ( empty($meta) || 'false' === $meta || '0' === $meta ) {
313
- $checkmark = '';
314
- }
315
-
316
- $meta = $checkmark;
317
- break;
318
-
319
- endswitch;
320
-
321
- // filter for customization
322
- $meta = apply_filters('cpac_get_column_value_custom_field', $meta, $fieldtype, $field, $type, $object_id );
323
-
324
- // add before and after string
325
- $meta = "{$before}{$meta}{$after}";
326
-
327
- return $meta;
328
- }
329
-
330
- /**
331
- * Get custom field value 'Title by ID'
332
- *
333
- * @since 1.3
334
- */
335
- protected function get_custom_field_value_title($meta)
336
- {
337
- //remove white spaces and strip tags
338
- $meta = $this->strip_trim( str_replace(' ','', $meta) );
339
-
340
- // var
341
- $ids = $titles = array();
342
-
343
- // check for multiple id's
344
- if ( strpos($meta, ',') !== false )
345
- $ids = explode(',',$meta);
346
- elseif ( is_numeric($meta) )
347
- $ids[] = $meta;
348
-
349
- // display title with link
350
- if ( $ids && is_array($ids) ) {
351
- foreach ( $ids as $id ) {
352
- $title = is_numeric($id) ? get_the_title($id) : '';
353
- $link = get_edit_post_link($id);
354
- if ( $title )
355
- $titles[] = $link ? "<a href='{$link}'>{$title}</a>" : $title;
356
- }
357
- }
358
-
359
- return implode('<span class="cpac-divider"></span>', $titles);
360
- }
361
-
362
- /**
363
- * Get custom field value 'User by ID'
364
- *
365
- * @since 1.4.6.3
366
- */
367
- protected function get_custom_field_value_user($meta)
368
- {
369
- //remove white spaces and strip tags
370
- $meta = $this->strip_trim( str_replace(' ','', $meta) );
371
-
372
- // var
373
- $ids = $names = array();
374
-
375
- // check for multiple id's
376
- if ( strpos($meta, ',') !== false )
377
- $ids = explode(',',$meta);
378
- elseif ( is_numeric($meta) )
379
- $ids[] = $meta;
380
-
381
- // display username
382
- if ( $ids && is_array($ids) ) {
383
- foreach ( $ids as $id ) {
384
- if ( !is_numeric($id) )
385
- continue;
386
-
387
- $userdata = get_userdata($id);
388
- if ( is_object($userdata) && !empty( $userdata->display_name ) ) {
389
- $names[] = $userdata->display_name;
390
- }
391
- }
392
- }
393
-
394
- return implode('<span class="cpac-divider"></span>', $names);
395
- }
396
-
397
- /**
398
- * Get column value of Custom Field
399
- *
400
- * @since 1.2
401
- */
402
- protected function get_user_column_value_custom_field($user_id, $id)
403
- {
404
- $columns = $this->get_stored_columns('wp-users');
405
-
406
- // inputs
407
- $field = isset($columns[$id]['field']) ? $columns[$id]['field'] : '';
408
- $fieldtype = isset($columns[$id]['field_type']) ? $columns[$id]['field_type'] : '';
409
- $before = isset($columns[$id]['before']) ? $columns[$id]['before'] : '';
410
- $after = isset($columns[$id]['after']) ? $columns[$id]['after'] : '';
411
-
412
- // Get meta field value
413
- $meta = get_user_meta($user_id, $field, true);
414
-
415
- // multiple meta values
416
- if ( ( $fieldtype == 'array' && is_array($meta) ) || is_array($meta) ) {
417
- $meta = get_user_meta($user_id, $field);
418
- $meta = $this->recursive_implode(', ', $meta);
419
- }
420
-
421
- // make sure there are no serialized arrays or empty meta data
422
- if ( empty($meta) || !is_string($meta) )
423
- return false;
424
-
425
- // handles each field type differently..
426
- switch ($fieldtype) :
427
-
428
- // Image
429
- case "image" :
430
- $meta = $this->get_thumbnail($meta);
431
- break;
432
-
433
- // Media Library ID
434
- case "library_id" :
435
- $meta = $this->get_media_thumbnails($meta);
436
- break;
437
-
438
- // Excerpt
439
- case "excerpt" :
440
- $meta = $this->get_shortened_string($meta, $this->excerpt_length);
441
- break;
442
-
443
- endswitch;
444
-
445
- // filter for customization
446
- $meta = apply_filters('cpac_get_user_column_value_custom_field', $meta, $fieldtype, $field );
447
-
448
- // add before and after string
449
- $meta = "{$before}{$meta}{$after}";
450
-
451
- return $meta;
452
- }
453
-
454
- /**
455
- * Implode for multi dimensional array
456
- *
457
- * @since 1.0
458
- */
459
- protected function recursive_implode( $glue, $pieces )
460
- {
461
- foreach( $pieces as $r_pieces ) {
462
- if( is_array( $r_pieces ) ) {
463
- $retVal[] = $this->recursive_implode( $glue, $r_pieces );
464
- }
465
- else {
466
- $retVal[] = $r_pieces;
467
- }
468
- }
469
- if ( isset($retVal) && is_array($retVal) )
470
- return implode( $glue, $retVal );
471
-
472
- return false;
473
- }
474
-
475
- /**
476
- * Strip tags and trim
477
- *
478
- * @since 1.3
479
- */
480
- protected function strip_trim($string)
481
- {
482
- return Codepress_Admin_Columns::strip_trim($string);
483
- }
484
-
485
- /**
486
- * Get date
487
- *
488
- * @since 1.3.1
489
- */
490
- protected function get_date($date)
491
- {
492
- if ( ! $date )
493
- return false;
494
-
495
- if ( ! is_numeric($date) )
496
- $date = strtotime($date);
497
-
498
- return date_i18n( get_option('date_format'), $date );
499
- }
500
-
501
- /**
502
- * Get time
503
- *
504
- * @since 1.3.1
505
- */
506
- protected function get_time($date)
507
- {
508
- if ( ! $date )
509
- return false;
510
-
511
- if ( ! is_numeric($date) )
512
- $date = strtotime($date);
513
-
514
- return date_i18n( get_option('time_format'), $date );
515
- }
516
- }
517
-
 
 
 
 
 
 
 
 
 
 
 
 
518
  ?>
1
+ <?php
2
+
3
+ /**
4
+ * CPAC_Values Class
5
+ *
6
+ * @since 1.4.4
7
+ *
8
+ */
9
+ class CPAC_Values
10
+ {
11
+ protected $excerpt_length, $thumbnail_size;
12
+
13
+ /**
14
+ * Constructor
15
+ *
16
+ * @since 1.0
17
+ */
18
+ function __construct()
19
+ {
20
+ // number of words
21
+ $this->excerpt_length = 20;
22
+ $this->thumbnail_size = apply_filters( 'cpac_thumbnail_size', array(80,80) );
23
+ }
24
+
25
+ /**
26
+ * Admin requests for orderby column
27
+ *
28
+ * @since 1.0
29
+ */
30
+ public function get_stored_columns($type)
31
+ {
32
+ return Codepress_Admin_Columns::get_stored_columns($type);
33
+ }
34
+
35
+ /**
36
+ * Checks if column-meta key exists
37
+ *
38
+ * @since 1.0
39
+ */
40
+ public static function is_column_meta( $id = '' )
41
+ {
42
+ return Codepress_Admin_Columns::is_column_meta( $id );
43
+ }
44
+
45
+ /**
46
+ * Returns excerpt
47
+ *
48
+ * @since 1.0
49
+ */
50
+ protected function get_post_excerpt($post_id)
51
+ {
52
+ global $post;
53
+
54
+ $save_post = $post;
55
+ $post = get_post($post_id);
56
+ $excerpt = get_the_excerpt();
57
+ $post = $save_post;
58
+
59
+ $output = $this->get_shortened_string($excerpt, $this->excerpt_length );
60
+
61
+ return $output;
62
+ }
63
+
64
+ /**
65
+ * Returns shortened string
66
+ *
67
+ * @since 1.0
68
+ */
69
+ protected function get_shortened_string($string = '', $num_words = 55, $more = null)
70
+ {
71
+ if (!$string)
72
+ return false;
73
+
74
+ return wp_trim_words( $string, $num_words, $more );
75
+ }
76
+
77
+ /**
78
+ * Get image from assets folder
79
+ *
80
+ * @since 1.3.1
81
+ */
82
+ protected function get_asset_image($name = '', $title = '')
83
+ {
84
+ if ( $name )
85
+ return sprintf("<img alt='' src='%s' title='%s'/>", CPAC_URL."/assets/images/{$name}", $title);
86
+ }
87
+
88
+ /**
89
+ * Shorten URL
90
+ *
91
+ * @since 1.3.1
92
+ */
93
+ protected function get_shorten_url($url = '')
94
+ {
95
+ if ( !$url )
96
+ return false;
97
+
98
+ // shorten url
99
+ $short_url = url_shorten( $url );
100
+
101
+ return "<a title='{$url}' href='{$url}'>{$short_url}</a>";
102
+ }
103
+
104
+ /**
105
+ * Get column value of post attachments
106
+ *
107
+ * @since 1.0
108
+ */
109
+ protected function get_column_value_attachments( $post_id )
110
+ {
111
+ $result = '';
112
+ $attachment_ids = $this->get_attachment_ids($post_id);
113
+ if ( $attachment_ids ) {
114
+ foreach ( $attachment_ids as $attach_id ) {
115
+ if ( wp_get_attachment_image($attach_id) )
116
+ $result .= wp_get_attachment_image( $attach_id, $this->thumbnail_size, true );
117
+ }
118
+ }
119
+ return $result;
120
+ }
121
+
122
+ /**
123
+ * Get column value of post attachments
124
+ *
125
+ * @since 1.2.1
126
+ */
127
+ protected function get_attachment_ids( $post_id )
128
+ {
129
+ return Codepress_Admin_Columns::get_attachment_ids( $post_id );
130
+ }
131
+
132
+ /**
133
+ * Get a thumbnail
134
+ *
135
+ * @since 1.0
136
+ */
137
+ protected function get_thumbnail( $image = '' )
138
+ {
139
+ if ( empty($image) )
140
+ return false;
141
+
142
+ // get thumbnail image size
143
+ $image_size = $this->thumbnail_size; // w, h
144
+
145
+ // incase the thumbnail dimension is set by name
146
+ if ( !is_array($image_size) ) {
147
+ global $_wp_additional_image_sizes;
148
+ if ( isset($_wp_additional_image_sizes[$image_size]) ) {
149
+ $_size = $_wp_additional_image_sizes[$image_size];
150
+ $image_size = array( $_size['width'], $_size['height'] );
151
+ }
152
+ }
153
+
154
+ // fallback for image size incase the passed size name does not exists
155
+ if ( !isset($image_size[0]) || !isset($image_size[1]) ) {
156
+ $image_size = array(80, 80);
157
+ }
158
+
159
+ // get correct image path
160
+ $image_path = str_replace( WP_CONTENT_URL, WP_CONTENT_DIR, $image);
161
+
162
+ // resize image
163
+ if ( file_exists($image_path) && $this->is_image($image_path) ) {
164
+ $resized = image_resize( $image_path, $image_size[0], $image_size[1], true);
165
+
166
+ // resize worked
167
+ if ( ! is_wp_error( $resized ) ) {
168
+ $image = str_replace( WP_CONTENT_DIR, WP_CONTENT_URL, $resized);
169
+
170
+ return "<img src='{$image}' alt='' width='{$image_size[0]}' height='{$image_size[1]}' />";
171
+ }
172
+
173
+ // resizing failed so let's return full image with maxed dimensions
174
+ else {
175
+ return "<img src='{$image}' alt='' style='max-width:{$image_size[0]}px;max-height:{$image_size[1]}px' />";
176
+ }
177
+ }
178
+
179
+ return false;
180
+ }
181
+
182
+ /**
183
+ * Checks an URL for image extension
184
+ *
185
+ * @since 1.2
186
+ */
187
+ protected function is_image($url)
188
+ {
189
+ $validExt = array('.jpg', '.jpeg', '.gif', '.png', '.bmp');
190
+ $ext = strrchr($url, '.');
191
+
192
+ return in_array($ext, $validExt);
193
+ }
194
+
195
+ /**
196
+ * Get a thumbnail
197
+ *
198
+ * @since 1.3.1
199
+ */
200
+ protected function get_media_thumbnails($meta)
201
+ {
202
+ $meta = $this->strip_trim( str_replace(' ','', $meta) );
203
+
204
+ // split media ids
205
+ $media_ids = array($meta);
206
+ if ( strpos($meta, ',') !== false )
207
+ $media_ids = explode(',', $meta);
208
+
209
+ // check if media exists
210
+ $thumbs = '';
211
+ foreach ( $media_ids as $media_id )
212
+ if ( is_numeric($media_id) )
213
+ $thumbs .= wp_get_attachment_url($media_id) ? "<span class='cpac-column-value-image'>".wp_get_attachment_image( $media_id, array(80,80), true )."</span>" : '';
214
+
215
+ return $thumbs;
216
+ }
217
+
218
+ /**
219
+ * Convert file size to readable format
220
+ *
221
+ * @since 1.4.5
222
+ */
223
+ function get_readable_filesize($size)
224
+ {
225
+ $filesizename = array(" Bytes", " KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB");
226
+ return $size ? round($size/pow(1024, ($i = floor(log($size, 1024)))), 2) . $filesizename[$i] : '0 Bytes';
227
+ }
228
+
229
+ /**
230
+ * Get column value of Custom Field
231
+ *
232
+ * @since 1.0
233
+ */
234
+ protected function get_column_value_custom_field($object_id, $column_name, $meta_type = 'post')
235
+ {
236
+ /** Users */
237
+ if ( $meta_type == 'user' ) {
238
+ $type = 'wp-users';
239
+ }
240
+
241
+ /** Media */
242
+ if ( $meta_type == 'media' ) {
243
+ $type = 'wp-media';
244
+ $meta_type = 'post';
245
+ }
246
+
247
+ /** Posts */
248
+ else {
249
+ $type = get_post_type($object_id);
250
+ }
251
+
252
+ // get column
253
+ $columns = $this->get_stored_columns($type);
254
+
255
+ // inputs
256
+ $field = isset($columns[$column_name]['field']) ? $columns[$column_name]['field'] : '';
257
+ $fieldtype = isset($columns[$column_name]['field_type']) ? $columns[$column_name]['field_type'] : '';
258
+ $before = isset($columns[$column_name]['before']) ? $columns[$column_name]['before'] : '';
259
+ $after = isset($columns[$column_name]['after']) ? $columns[$column_name]['after'] : '';
260
+
261
+ // rename hidden custom fields to their original name
262
+ $field = substr($field,0,10) == "cpachidden" ? str_replace('cpachidden','',$field) : $field;
263
+
264
+ // Get meta field value
265
+ $meta = get_metadata($meta_type, $object_id, $field, true);
266
+
267
+ // multiple meta values
268
+ if ( ( $fieldtype == 'array' && is_array($meta) ) || is_array($meta) ) {
269
+ $meta = get_metadata($meta_type, $object_id, $field, true);
270
+ $meta = $this->recursive_implode(', ', $meta);
271
+ }
272
+
273
+ // make sure there are no serialized arrays or null data
274
+ if ( !is_string($meta) )
275
+ return false;
276
+
277
+ // handles each field type differently..
278
+ switch ($fieldtype) :
279
+
280
+ // Image
281
+ case "image" :
282
+ $meta = $this->get_thumbnail($meta);
283
+ break;
284
+
285
+ // Media Library ID
286
+ case "library_id" :
287
+ $meta = $this->get_media_thumbnails($meta);
288
+ break;
289
+
290
+ // Excerpt
291
+ case "excerpt" :
292
+ $meta = $this->get_shortened_string($meta, $this->excerpt_length);
293
+ break;
294
+
295
+ // Date
296
+ case "date" :
297
+ $meta = $this->get_date($meta);
298
+ break;
299
+
300
+ // Post Title
301
+ case "title_by_id" :
302
+ $titles = $this->get_custom_field_value_title($meta);
303
+ if ( $titles )
304
+ $meta = $titles;
305
+ break;
306
+
307
+ // User Name
308
+ case "user_by_id" :
309
+ $names = $this->get_custom_field_value_user($meta);
310
+ if ( $names )
311
+ $meta = $names;
312
+ break;
313
+
314
+ // Checkmark
315
+ case "checkmark" :
316
+ $checkmark = $this->get_asset_image('checkmark.png');
317
+
318
+ if ( empty($meta) || 'false' === $meta || '0' === $meta ) {
319
+ $checkmark = '';
320
+ }
321
+
322
+ $meta = $checkmark;
323
+ break;
324
+
325
+ // Color
326
+ case "color" :
327
+ if ( !empty($meta) ) {
328
+ $meta = "<div class='cpac-color'><span style='background-color:{$meta}'></span>{$meta}</div>";
329
+ }
330
+ break;
331
+
332
+ endswitch;
333
+
334
+ // filter for customization
335
+ $meta = apply_filters('cpac_get_column_value_custom_field', $meta, $fieldtype, $field, $type, $object_id );
336
+
337
+ // add before and after string
338
+ if ( $meta ) {
339
+ $meta = "{$before}{$meta}{$after}";
340
+ }
341
+
342
+ return $meta;
343
+ }
344
+
345
+ /**
346
+ * Get custom field value 'Title by ID'
347
+ *
348
+ * @since 1.3
349
+ */
350
+ protected function get_custom_field_value_title($meta)
351
+ {
352
+ //remove white spaces and strip tags
353
+ $meta = $this->strip_trim( str_replace(' ','', $meta) );
354
+
355
+ // var
356
+ $ids = $titles = array();
357
+
358
+ // check for multiple id's
359
+ if ( strpos($meta, ',') !== false )
360
+ $ids = explode(',',$meta);
361
+ elseif ( is_numeric($meta) )
362
+ $ids[] = $meta;
363
+
364
+ // display title with link
365
+ if ( $ids && is_array($ids) ) {
366
+ foreach ( $ids as $id ) {
367
+ $title = is_numeric($id) ? get_the_title($id) : '';
368
+ $link = get_edit_post_link($id);
369
+ if ( $title )
370
+ $titles[] = $link ? "<a href='{$link}'>{$title}</a>" : $title;
371
+ }
372
+ }
373
+
374
+ return implode('<span class="cpac-divider"></span>', $titles);
375
+ }
376
+
377
+ /**
378
+ * Get custom field value 'User by ID'
379
+ *
380
+ * @since 1.4.6.3
381
+ */
382
+ protected function get_custom_field_value_user($meta)
383
+ {
384
+ //remove white spaces and strip tags
385
+ $meta = $this->strip_trim( str_replace(' ','', $meta) );
386
+
387
+ // var
388
+ $ids = $names = array();
389
+
390
+ // check for multiple id's
391
+ if ( strpos($meta, ',') !== false )
392
+ $ids = explode(',',$meta);
393
+ elseif ( is_numeric($meta) )
394
+ $ids[] = $meta;
395
+
396
+ // display username
397
+ if ( $ids && is_array($ids) ) {
398
+ foreach ( $ids as $id ) {
399
+ if ( !is_numeric($id) )
400
+ continue;
401
+
402
+ $userdata = get_userdata($id);
403
+ if ( is_object($userdata) && !empty( $userdata->display_name ) ) {
404
+ $names[] = $userdata->display_name;
405
+ }
406
+ }
407
+ }
408
+
409
+ return implode('<span class="cpac-divider"></span>', $names);
410
+ }
411
+
412
+ /**
413
+ * Get column value of Custom Field
414
+ *
415
+ * @since 1.2
416
+ */
417
+ protected function get_user_column_value_custom_field($user_id, $id)
418
+ {
419
+ $columns = $this->get_stored_columns('wp-users');
420
+
421
+ // inputs
422
+ $field = isset($columns[$id]['field']) ? $columns[$id]['field'] : '';
423
+ $fieldtype = isset($columns[$id]['field_type']) ? $columns[$id]['field_type'] : '';
424
+ $before = isset($columns[$id]['before']) ? $columns[$id]['before'] : '';
425
+ $after = isset($columns[$id]['after']) ? $columns[$id]['after'] : '';
426
+
427
+ // Get meta field value
428
+ $meta = get_user_meta($user_id, $field, true);
429
+
430
+ // multiple meta values
431
+ if ( ( $fieldtype == 'array' && is_array($meta) ) || is_array($meta) ) {
432
+ $meta = get_user_meta($user_id, $field);
433
+ $meta = $this->recursive_implode(', ', $meta);
434
+ }
435
+
436
+ // make sure there are no serialized arrays or empty meta data
437
+ if ( empty($meta) || !is_string($meta) )
438
+ return false;
439
+
440
+ // handles each field type differently..
441
+ switch ($fieldtype) :
442
+
443
+ // Image
444
+ case "image" :
445
+ $meta = $this->get_thumbnail($meta);
446
+ break;
447
+
448
+ // Media Library ID
449
+ case "library_id" :
450
+ $meta = $this->get_media_thumbnails($meta);
451
+ break;
452
+
453
+ // Excerpt
454
+ case "excerpt" :
455
+ $meta = $this->get_shortened_string($meta, $this->excerpt_length);
456
+ break;
457
+
458
+ endswitch;
459
+
460
+ // filter for customization
461
+ $meta = apply_filters('cpac_get_user_column_value_custom_field', $meta, $fieldtype, $field );
462
+
463
+ // add before and after string
464
+ $meta = "{$before}{$meta}{$after}";
465
+
466
+ return $meta;
467
+ }
468
+
469
+ /**
470
+ * Implode for multi dimensional array
471
+ *
472
+ * @since 1.0
473
+ */
474
+ protected function recursive_implode( $glue, $pieces )
475
+ {
476
+ foreach( $pieces as $r_pieces ) {
477
+ if( is_array( $r_pieces ) ) {
478
+ $retVal[] = $this->recursive_implode( $glue, $r_pieces );
479
+ }
480
+ else {
481
+ $retVal[] = $r_pieces;
482
+ }
483
+ }
484
+ if ( isset($retVal) && is_array($retVal) )
485
+ return implode( $glue, $retVal );
486
+
487
+ return false;
488
+ }
489
+
490
+ /**
491
+ * Strip tags and trim
492
+ *
493
+ * @since 1.3
494
+ */
495
+ protected function strip_trim($string)
496
+ {
497
+ return Codepress_Admin_Columns::strip_trim($string);
498
+ }
499
+
500
+ /**
501
+ * Get date
502
+ *
503
+ * @since 1.3.1
504
+ */
505
+ protected function get_date($date)
506
+ {
507
+ if ( ! $date )
508
+ return false;
509
+
510
+ return date_i18n( get_option('date_format'), strtotime($date) );
511
+ }
512
+
513
+ /**
514
+ * Get time
515
+ *
516
+ * @since 1.3.1
517
+ */
518
+ protected function get_time($date)
519
+ {
520
+ if ( ! $date )
521
+ return false;
522
+
523
+ if ( ! is_numeric($date) )
524
+ $date = strtotime($date);
525
+
526
+ return date_i18n( get_option('time_format'), $date );
527
+ }
528
+ }
529
+
530
  ?>
classes/values/comments.php CHANGED
@@ -1,250 +1,250 @@
1
- <?php
2
-
3
- /**
4
- * CPAC_Comments_Values Class
5
- *
6
- * @since 1.4.4
7
- *
8
- */
9
- class CPAC_Comments_Values extends CPAC_Values
10
- {
11
- /**
12
- * Constructor
13
- *
14
- * @since 1.4.4
15
- */
16
- function __construct()
17
- {
18
- parent::__construct();
19
-
20
- add_action( 'manage_comments_custom_column', array( $this, 'manage_comments_column_value'), 10, 2 );
21
- }
22
-
23
- /**
24
- * Manage custom column for Comments
25
- *
26
- * @since 1.3.1
27
- */
28
- public function manage_comments_column_value( $column_name, $comment_id )
29
- {
30
- $type = $column_name;
31
-
32
- // comments object
33
- $comment = get_comment($comment_id);
34
-
35
- // Check for custom fields, such as column-meta-[customfieldname]
36
- if ( $this->is_column_meta($type) )
37
- $type = 'column-comment-meta';
38
-
39
- // Hook
40
- do_action('cpac-manage-comments-column', $type, $column_name, $comment_id);
41
-
42
- $result = '';
43
- switch ($type) :
44
-
45
- // comment id
46
- case "column-comment_id" :
47
- $result = $comment_id;
48
- break;
49
-
50
- // author
51
- case "column-author_author" :
52
- $result = $comment->comment_author;
53
- break;
54
-
55
- // avatar
56
- case "column-author_avatar" :
57
- $result = get_avatar( $comment, 80 );
58
- break;
59
-
60
- // url
61
- case "column-author_url" :
62
- $result = $this->get_shorten_url($comment->comment_author_url);
63
- break;
64
-
65
- // ip
66
- case "column-author_ip" :
67
- $result = $comment->comment_author_IP;
68
- break;
69
-
70
- // email
71
- case "column-author_email" :
72
- $result = $comment->comment_author_email;
73
- break;
74
-
75
- // parent
76
- case "column-reply_to" :
77
- if ( $comment->comment_approved ) {
78
- $parent = get_comment( $comment->comment_parent );
79
- $parent_link = esc_url( get_comment_link( $comment->comment_parent ) );
80
- $name = get_comment_author( $parent->comment_ID );
81
- $result = sprintf( '<a href="%1$s">%2$s</a>', $parent_link, $name );
82
- }
83
- break;
84
-
85
- // approved
86
- case "column-approved" :
87
- $result = $this->get_asset_image('no.png');
88
- if ( $comment->comment_approved )
89
- $result = $this->get_asset_image('checkmark.png');
90
- break;
91
-
92
- // date
93
- case "column-date" :
94
- $comment_url = esc_url( get_comment_link( $comment_id ) );
95
- $result = sprintf( __( 'Submitted on <a href="%1$s">%2$s at %3$s</a>' ),
96
- $comment_url,
97
- $this->get_date($comment->comment_date),
98
- $this->get_time($comment->comment_date)
99
- );
100
- $result = "<div class='submitted-on'>{$result}</div>";
101
- break;
102
-
103
- // date GMT
104
- case "column-date_gmt" :
105
- $comment_url = esc_url( get_comment_link( $comment_id ) );
106
- $result = sprintf( __( 'Submitted on <a href="%1$s">%2$s at %3$s</a>' ),
107
- $comment_url,
108
- $this->get_date($comment->comment_date_gmt),
109
- $this->get_time($comment->comment_date_gmt)
110
- );
111
- $result = "<div class='submitted-on'>{$result}</div>";
112
- break;
113
-
114
- // custom field
115
- case "column-comment-meta" :
116
- $result = $this->get_column_value_custom_field($comment_id, $column_name, 'comment');
117
- break;
118
-
119
- // agent
120
- case "column-agent" :
121
- $result = $comment->comment_agent;
122
- break;
123
-
124
- // excerpt
125
- case "column-excerpt" :
126
- $comment = get_comment($comment_id);
127
- $result = $this->get_shortened_string($comment->comment_content, $this->excerpt_length);
128
- break;
129
-
130
- // actions
131
- case "column-actions" :
132
- $result = $this->get_column_value_actions($comment);
133
- break;
134
-
135
- // word count
136
- case "column-word-count" :
137
- $result = str_word_count( $this->strip_trim( $comment->comment_content ) );
138
- break;
139
-
140
- default :
141
- $result = '';
142
-
143
- endswitch;
144
-
145
- // Filter for customizing the result output
146
- apply_filters('cpac-comments-column-result', $result, $type, $column_name, $comment_id);
147
-
148
- echo $result;
149
- }
150
-
151
- /**
152
- * Get column value of comments actions
153
- *
154
- * This part is copied from the Comments List Table class
155
- *
156
- * @since 1.4.2
157
- */
158
- private function get_column_value_actions( $comment )
159
- {
160
- global $post, $comment_status;
161
-
162
- // set uased vars
163
- $user_can = current_user_can( 'edit_comment', $comment->comment_ID );
164
- $the_comment_status = wp_get_comment_status( $comment->comment_ID );
165
-
166
- if ( $user_can ) {
167
- $del_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "delete-comment_$comment->comment_ID" ) );
168
- $approve_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "approve-comment_$comment->comment_ID" ) );
169
-
170
- $url = "comment.php?c=$comment->comment_ID";
171
-
172
- $approve_url = esc_url( $url . "&action=approvecomment&$approve_nonce" );
173
- $unapprove_url = esc_url( $url . "&action=unapprovecomment&$approve_nonce" );
174
- $spam_url = esc_url( $url . "&action=spamcomment&$del_nonce" );
175
- $unspam_url = esc_url( $url . "&action=unspamcomment&$del_nonce" );
176
- $trash_url = esc_url( $url . "&action=trashcomment&$del_nonce" );
177
- $untrash_url = esc_url( $url . "&action=untrashcomment&$del_nonce" );
178
- $delete_url = esc_url( $url . "&action=deletecomment&$del_nonce" );
179
- }
180
-
181
- /** begin - copied from class-wp-comments-list-table */
182
- if ( $user_can ) {
183
- // preorder it: Approve | Reply | Quick Edit | Edit | Spam | Trash
184
- $actions = array(
185
- 'approve' => '', 'unapprove' => '',
186
- 'reply' => '',
187
- 'quickedit' => '',
188
- 'edit' => '',
189
- 'spam' => '', 'unspam' => '',
190
- 'trash' => '', 'untrash' => '', 'delete' => ''
191
- );
192
-
193
- if ( $comment_status && 'all' != $comment_status ) { // not looking at all comments
194
- if ( 'approved' == $the_comment_status )
195
- $actions['unapprove'] = "<a href='$unapprove_url' class='delete:the-comment-list:comment-$comment->comment_ID:e7e7d3:action=dim-comment&amp;new=unapproved vim-u vim-destructive' title='" . esc_attr__( 'Unapprove this comment' ) . "'>" . __( 'Unapprove' ) . '</a>';
196
- else if ( 'unapproved' == $the_comment_status )
197
- $actions['approve'] = "<a href='$approve_url' class='delete:the-comment-list:comment-$comment->comment_ID:e7e7d3:action=dim-comment&amp;new=approved vim-a vim-destructive' title='" . esc_attr__( 'Approve this comment' ) . "'>" . __( 'Approve' ) . '</a>';
198
- } else {
199
- $actions['approve'] = "<a href='$approve_url' class='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=approved vim-a' title='" . esc_attr__( 'Approve this comment' ) . "'>" . __( 'Approve' ) . '</a>';
200
- $actions['unapprove'] = "<a href='$unapprove_url' class='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=unapproved vim-u' title='" . esc_attr__( 'Unapprove this comment' ) . "'>" . __( 'Unapprove' ) . '</a>';
201
- }
202
-
203
- if ( 'spam' != $the_comment_status && 'trash' != $the_comment_status ) {
204
- $actions['spam'] = "<a href='$spam_url' class='delete:the-comment-list:comment-$comment->comment_ID::spam=1 vim-s vim-destructive' title='" . esc_attr__( 'Mark this comment as spam' ) . "'>" . /* translators: mark as spam link */ _x( 'Spam', 'verb' ) . '</a>';
205
- } elseif ( 'spam' == $the_comment_status ) {
206
- $actions['unspam'] = "<a href='$unspam_url' class='delete:the-comment-list:comment-$comment->comment_ID:66cc66:unspam=1 vim-z vim-destructive'>" . _x( 'Not Spam', 'comment' ) . '</a>';
207
- } elseif ( 'trash' == $the_comment_status ) {
208
- $actions['untrash'] = "<a href='$untrash_url' class='delete:the-comment-list:comment-$comment->comment_ID:66cc66:untrash=1 vim-z vim-destructive'>" . __( 'Restore' ) . '</a>';
209
- }
210
-
211
- if ( 'spam' == $the_comment_status || 'trash' == $the_comment_status || !EMPTY_TRASH_DAYS ) {
212
- $actions['delete'] = "<a href='$delete_url' class='delete:the-comment-list:comment-$comment->comment_ID::delete=1 delete vim-d vim-destructive'>" . __( 'Delete Permanently' ) . '</a>';
213
- } else {
214
- $actions['trash'] = "<a href='$trash_url' class='delete:the-comment-list:comment-$comment->comment_ID::trash=1 delete vim-d vim-destructive' title='" . esc_attr__( 'Move this comment to the trash' ) . "'>" . _x( 'Trash', 'verb' ) . '</a>';
215
- }
216
-
217
- if ( 'spam' != $the_comment_status && 'trash' != $the_comment_status ) {
218
- $actions['edit'] = "<a href='comment.php?action=editcomment&amp;c={$comment->comment_ID}' title='" . esc_attr__( 'Edit comment' ) . "'>". __( 'Edit' ) . '</a>';
219
- $actions['quickedit'] = '<a onclick="commentReply.open( \''.$comment->comment_ID.'\',\''.$post->ID.'\',\'edit\' );return false;" class="vim-q" title="'.esc_attr__( 'Quick Edit' ).'" href="#">' . __( 'Quick&nbsp;Edit' ) . '</a>';
220
- $actions['reply'] = '<a onclick="commentReply.open( \''.$comment->comment_ID.'\',\''.$post->ID.'\' );return false;" class="vim-r" title="'.esc_attr__( 'Reply to this comment' ).'" href="#">' . __( 'Reply' ) . '</a>';
221
- }
222
-
223
- $actions = apply_filters( 'comment_row_actions', array_filter( $actions ), $comment );
224
-
225
- $i = 0;
226
- $result = '<div class="cp-row-actions">';
227
- foreach ( $actions as $action => $link ) {
228
- ++$i;
229
- ( ( ( 'approve' == $action || 'unapprove' == $action ) && 2 === $i ) || 1 === $i ) ? $sep = '' : $sep = ' | ';
230
-
231
- // Reply and quickedit need a hide-if-no-js span when not added with ajax
232
- if ( ( 'reply' == $action || 'quickedit' == $action ) && ! defined('DOING_AJAX') )
233
- $action .= ' hide-if-no-js';
234
- elseif ( ( $action == 'untrash' && $the_comment_status == 'trash' ) || ( $action == 'unspam' && $the_comment_status == 'spam' ) ) {
235
- if ( '1' == get_comment_meta( $comment->comment_ID, '_wp_trash_meta_status', true ) )
236
- $action .= ' approve';
237
- else
238
- $action .= ' unapprove';
239
- }
240
-
241
- $result .= "<span class='$action'>$sep$link</span>";
242
- }
243
- $result .= '</div>';
244
- }
245
- return $result;
246
- // end copied
247
- }
248
- }
249
-
250
  ?>
1
+ <?php
2
+
3
+ /**
4
+ * CPAC_Comments_Values Class
5
+ *
6
+ * @since 1.4.4
7
+ *
8
+ */
9
+ class CPAC_Comments_Values extends CPAC_Values
10
+ {
11
+ /**
12
+ * Constructor
13
+ *
14
+ * @since 1.4.4
15
+ */
16
+ function __construct()
17
+ {
18
+ parent::__construct();
19
+
20
+ add_action( 'manage_comments_custom_column', array( $this, 'manage_comments_column_value'), 10, 2 );
21
+ }
22
+
23
+ /**
24
+ * Manage custom column for Comments
25
+ *
26
+ * @since 1.3.1
27
+ */
28
+ public function manage_comments_column_value( $column_name, $comment_id )
29
+ {
30
+ $type = $column_name;
31
+
32
+ // comments object
33
+ $comment = get_comment($comment_id);
34
+
35
+ // Check for custom fields, such as column-meta-[customfieldname]
36
+ if ( $this->is_column_meta($type) )
37
+ $type = 'column-comment-meta';
38
+
39
+ // Hook
40
+ do_action('cpac-manage-comments-column', $type, $column_name, $comment_id);
41
+
42
+ $result = '';
43
+ switch ($type) :
44
+
45
+ // comment id
46
+ case "column-comment_id" :
47
+ $result = $comment_id;
48
+ break;
49
+
50
+ // author
51
+ case "column-author_author" :
52
+ $result = $comment->comment_author;
53
+ break;
54
+
55
+ // avatar
56
+ case "column-author_avatar" :
57
+ $result = get_avatar( $comment, 80 );
58
+ break;
59
+
60
+ // url
61
+ case "column-author_url" :
62
+ $result = $this->get_shorten_url($comment->comment_author_url);
63
+ break;
64
+
65
+ // ip
66
+ case "column-author_ip" :
67
+ $result = $comment->comment_author_IP;
68
+ break;
69
+
70
+ // email
71
+ case "column-author_email" :
72
+ $result = $comment->comment_author_email;
73
+ break;
74
+
75
+ // parent
76
+ case "column-reply_to" :
77
+ if ( $comment->comment_approved ) {
78
+ $parent = get_comment( $comment->comment_parent );
79
+ $parent_link = esc_url( get_comment_link( $comment->comment_parent ) );
80
+ $name = get_comment_author( $parent->comment_ID );
81
+ $result = sprintf( '<a href="%1$s">%2$s</a>', $parent_link, $name );
82
+ }
83
+ break;
84
+
85
+ // approved
86
+ case "column-approved" :
87
+ $result = $this->get_asset_image('no.png');
88
+ if ( $comment->comment_approved )
89
+ $result = $this->get_asset_image('checkmark.png');
90
+ break;
91
+
92
+ // date
93
+ case "column-date" :
94
+ $comment_url = esc_url( get_comment_link( $comment_id ) );
95
+ $result = sprintf( __( 'Submitted on <a href="%1$s">%2$s at %3$s</a>' ),
96
+ $comment_url,
97
+ $this->get_date($comment->comment_date),
98
+ $this->get_time($comment->comment_date)
99
+ );
100
+ $result = "<div class='submitted-on'>{$result}</div>";
101
+ break;
102
+
103
+ // date GMT
104
+ case "column-date_gmt" :
105
+ $comment_url = esc_url( get_comment_link( $comment_id ) );
106
+ $result = sprintf( __( 'Submitted on <a href="%1$s">%2$s at %3$s</a>' ),
107
+ $comment_url,
108
+ $this->get_date($comment->comment_date_gmt),
109
+ $this->get_time($comment->comment_date_gmt)
110
+ );
111
+ $result = "<div class='submitted-on'>{$result}</div>";
112
+ break;
113
+
114
+ // custom field
115
+ case "column-comment-meta" :
116
+ $result = $this->get_column_value_custom_field($comment_id, $column_name, 'comment');
117
+ break;
118
+
119
+ // agent
120
+ case "column-agent" :
121
+ $result = $comment->comment_agent;
122
+ break;
123
+
124
+ // excerpt
125
+ case "column-excerpt" :
126
+ $comment = get_comment($comment_id);
127
+ $result = $this->get_shortened_string($comment->comment_content, $this->excerpt_length);
128
+ break;
129
+
130
+ // actions
131
+ case "column-actions" :
132
+ $result = $this->get_column_value_actions($comment);
133
+ break;
134
+
135
+ // word count
136
+ case "column-word-count" :
137
+ $result = str_word_count( $this->strip_trim( $comment->comment_content ) );
138
+ break;
139
+
140
+ default :
141
+ $result = '';
142
+
143
+ endswitch;
144
+
145
+ // Filter for customizing the result output
146
+ apply_filters('cpac-comments-column-result', $result, $type, $column_name, $comment_id);
147
+
148
+ echo $result;
149
+ }
150
+
151
+ /**
152
+ * Get column value of comments actions
153
+ *
154
+ * This part is copied from the Comments List Table class
155
+ *
156
+ * @since 1.4.2
157
+ */
158
+ private function get_column_value_actions( $comment )
159
+ {
160
+ global $post, $comment_status;
161
+
162
+ // set uased vars
163
+ $user_can = current_user_can( 'edit_comment', $comment->comment_ID );
164
+ $the_comment_status = wp_get_comment_status( $comment->comment_ID );
165
+
166
+ if ( $user_can ) {
167
+ $del_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "delete-comment_$comment->comment_ID" ) );
168
+ $approve_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "approve-comment_$comment->comment_ID" ) );
169
+
170
+ $url = "comment.php?c=$comment->comment_ID";
171
+
172
+ $approve_url = esc_url( $url . "&action=approvecomment&$approve_nonce" );
173
+ $unapprove_url = esc_url( $url . "&action=unapprovecomment&$approve_nonce" );
174
+ $spam_url = esc_url( $url . "&action=spamcomment&$del_nonce" );
175
+ $unspam_url = esc_url( $url . "&action=unspamcomment&$del_nonce" );
176
+ $trash_url = esc_url( $url . "&action=trashcomment&$del_nonce" );
177
+ $untrash_url = esc_url( $url . "&action=untrashcomment&$del_nonce" );
178
+ $delete_url = esc_url( $url . "&action=deletecomment&$del_nonce" );
179
+ }
180
+
181
+ /** begin - copied from class-wp-comments-list-table */
182
+ if ( $user_can ) {
183
+ // preorder it: Approve | Reply | Quick Edit | Edit | Spam | Trash
184
+ $actions = array(
185
+ 'approve' => '', 'unapprove' => '',
186
+ 'reply' => '',
187
+ 'quickedit' => '',
188
+ 'edit' => '',
189
+ 'spam' => '', 'unspam' => '',
190
+ 'trash' => '', 'untrash' => '', 'delete' => ''
191
+ );
192
+
193
+ if ( $comment_status && 'all' != $comment_status ) { // not looking at all comments
194
+ if ( 'approved' == $the_comment_status )
195
+ $actions['unapprove'] = "<a href='$unapprove_url' class='delete:the-comment-list:comment-$comment->comment_ID:e7e7d3:action=dim-comment&amp;new=unapproved vim-u vim-destructive' title='" . esc_attr__( 'Unapprove this comment' ) . "'>" . __( 'Unapprove' ) . '</a>';
196
+ else if ( 'unapproved' == $the_comment_status )
197
+ $actions['approve'] = "<a href='$approve_url' class='delete:the-comment-list:comment-$comment->comment_ID:e7e7d3:action=dim-comment&amp;new=approved vim-a vim-destructive' title='" . esc_attr__( 'Approve this comment' ) . "'>" . __( 'Approve' ) . '</a>';
198
+ } else {
199
+ $actions['approve'] = "<a href='$approve_url' class='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=approved vim-a' title='" . esc_attr__( 'Approve this comment' ) . "'>" . __( 'Approve' ) . '</a>';
200
+ $actions['unapprove'] = "<a href='$unapprove_url' class='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=unapproved vim-u' title='" . esc_attr__( 'Unapprove this comment' ) . "'>" . __( 'Unapprove' ) . '</a>';
201
+ }
202
+
203
+ if ( 'spam' != $the_comment_status && 'trash' != $the_comment_status ) {
204
+ $actions['spam'] = "<a href='$spam_url' class='delete:the-comment-list:comment-$comment->comment_ID::spam=1 vim-s vim-destructive' title='" . esc_attr__( 'Mark this comment as spam' ) . "'>" . /* translators: mark as spam link */ _x( 'Spam', 'verb' ) . '</a>';
205
+ } elseif ( 'spam' == $the_comment_status ) {
206
+ $actions['unspam'] = "<a href='$unspam_url' class='delete:the-comment-list:comment-$comment->comment_ID:66cc66:unspam=1 vim-z vim-destructive'>" . _x( 'Not Spam', 'comment' ) . '</a>';
207
+ } elseif ( 'trash' == $the_comment_status ) {
208
+ $actions['untrash'] = "<a href='$untrash_url' class='delete:the-comment-list:comment-$comment->comment_ID:66cc66:untrash=1 vim-z vim-destructive'>" . __( 'Restore' ) . '</a>';
209
+ }
210
+
211
+ if ( 'spam' == $the_comment_status || 'trash' == $the_comment_status || !EMPTY_TRASH_DAYS ) {
212
+ $actions['delete'] = "<a href='$delete_url' class='delete:the-comment-list:comment-$comment->comment_ID::delete=1 delete vim-d vim-destructive'>" . __( 'Delete Permanently' ) . '</a>';
213
+ } else {
214
+ $actions['trash'] = "<a href='$trash_url' class='delete:the-comment-list:comment-$comment->comment_ID::trash=1 delete vim-d vim-destructive' title='" . esc_attr__( 'Move this comment to the trash' ) . "'>" . _x( 'Trash', 'verb' ) . '</a>';
215
+ }
216
+
217
+ if ( 'spam' != $the_comment_status && 'trash' != $the_comment_status ) {
218
+ $actions['edit'] = "<a href='comment.php?action=editcomment&amp;c={$comment->comment_ID}' title='" . esc_attr__( 'Edit comment' ) . "'>". __( 'Edit' ) . '</a>';
219
+ $actions['quickedit'] = '<a onclick="commentReply.open( \''.$comment->comment_ID.'\',\''.$post->ID.'\',\'edit\' );return false;" class="vim-q" title="'.esc_attr__( 'Quick Edit' ).'" href="#">' . __( 'Quick&nbsp;Edit' ) . '</a>';
220
+ $actions['reply'] = '<a onclick="commentReply.open( \''.$comment->comment_ID.'\',\''.$post->ID.'\' );return false;" class="vim-r" title="'.esc_attr__( 'Reply to this comment' ).'" href="#">' . __( 'Reply' ) . '</a>';
221
+ }
222
+
223
+ $actions = apply_filters( 'comment_row_actions', array_filter( $actions ), $comment );
224
+
225
+ $i = 0;
226
+ $result = '<div class="cp-row-actions">';
227
+ foreach ( $actions as $action => $link ) {
228
+ ++$i;
229
+ ( ( ( 'approve' == $action || 'unapprove' == $action ) && 2 === $i ) || 1 === $i ) ? $sep = '' : $sep = ' | ';
230
+
231
+ // Reply and quickedit need a hide-if-no-js span when not added with ajax
232
+ if ( ( 'reply' == $action || 'quickedit' == $action ) && ! defined('DOING_AJAX') )
233
+ $action .= ' hide-if-no-js';
234
+ elseif ( ( $action == 'untrash' && $the_comment_status == 'trash' ) || ( $action == 'unspam' && $the_comment_status == 'spam' ) ) {
235
+ if ( '1' == get_comment_meta( $comment->comment_ID, '_wp_trash_meta_status', true ) )
236
+ $action .= ' approve';
237
+ else
238
+ $action .= ' unapprove';
239
+ }
240
+
241
+ $result .= "<span class='$action'>$sep$link</span>";
242
+ }
243
+ $result .= '</div>';
244
+ }
245
+ return $result;
246
+ // end copied
247
+ }
248
+ }
249
+
250
  ?>
classes/values/media.php CHANGED
@@ -1,212 +1,212 @@
1
- <?php
2
-
3
- /**
4
- * CPAC_Media_Values Class
5
- *
6
- * @since 1.4.4
7
- *
8
- */
9
- class CPAC_Media_Values extends CPAC_Values
10
- {
11
- /**
12
- * Constructor
13
- *
14
- * @since 1.4.4
15
- */
16
- function __construct()
17
- {
18
- parent::__construct();
19
-
20
- add_action( 'manage_media_custom_column', array( $this, 'manage_media_column_value'), 10, 2 );
21
- }
22
-
23
- /**
24
- * Manage custom column for Media.
25
- *
26
- * @since 1.3
27
- */
28
- public function manage_media_column_value( $column_name, $media_id )
29
- {
30
- $type = $column_name;
31
-
32
- //$meta = wp_get_attachment_metadata($media_id);
33
- $meta = get_post_meta( $media_id, '_wp_attachment_metadata', true );
34
- $p = get_post($media_id);
35
-
36
- // Check for custom fields, such as column-meta-[customfieldname]
37
- if ( $this->is_column_meta($type) )
38
- $type = 'column-meta';
39
-
40
- // Hook
41
- do_action('cpac-manage-media-column', $type, $column_name, $media_id);
42
-
43
- $result = '';
44
- switch ($type) :
45
-
46
- // media id
47
- case "column-mediaid" :
48
- $result = $media_id;
49
- break;
50
-
51
- // dimensions
52
- case "column-dimensions" :
53
- if ( !empty($meta['width']) && !empty($meta['height']) )
54
- $result = "{$meta['width']} x {$meta['height']}";
55
- break;
56
-
57
- // width
58
- case "column-width" :
59
- $result = !empty($meta['width']) ? $meta['width'] : '';
60
- break;
61
-
62
- // height
63
- case "column-height" :
64
- $result = !empty($meta['height']) ? $meta['height'] : '';
65
- break;
66
-
67
- // description
68
- case "column-description" :
69
- $result = $p->post_content;
70
- break;
71
-
72
- // caption
73
- case "column-caption" :
74
- $result = $p->post_excerpt;
75
- break;
76
-
77
- // alternate text
78
- case "column-alternate_text" :
79
- $alt = get_post_meta($media_id, '_wp_attachment_image_alt', true);
80
- $result = $this->strip_trim($alt);
81
- break;
82
-
83
- // mime type
84
- case "column-mime_type" :
85
- $result = $p->post_mime_type;
86
- break;
87
-
88
- // file name
89
- case "column-file_name" :
90
- $file = wp_get_attachment_url($p->ID);
91
- $filename = basename($file);
92
- $result = "<a title='{$filename}' href='{$file}'>{$filename}</a>";
93
- break;
94
-
95
- // file paths
96
- case "column-file_paths" :
97
- $sizes = get_intermediate_image_sizes();
98
- $url = wp_get_attachment_url($p->ID);
99
- $filename = basename($url);
100
- $paths[] = "<a title='{$filename}' href='{$url}'>" . __('original', CPAC_TEXTDOMAIN) . "</a>";
101
- if ( $sizes ) {
102
- foreach ( $sizes as $size ) {
103
- $src = wp_get_attachment_image_src( $media_id, $size );
104
- if (!empty($src[0])) {
105
- $filename = basename($src[0]);
106
- $paths[] = "<a title='{$filename}' href='{$src[0]}'>{$size}</a>";
107
- }
108
- }
109
- }
110
- $result = implode('<span class="cpac-divider"></span>', $paths);
111
- break;
112
-
113
- case "column-actions" :
114
- $result = $this->get_column_value_actions($media_id);
115
- break;
116
-
117
- case "column-filesize" :
118
- $file = wp_get_attachment_url($p->ID);
119
- $abs = str_replace( WP_CONTENT_URL, WP_CONTENT_DIR, $file);
120
- if ( file_exists($abs) ) {
121
- $result = $this->get_readable_filesize(filesize($abs));
122
- }
123
- break;
124
-
125
- // Custom Field
126
- case "column-meta" :
127
- $result = $this->get_column_value_custom_field($media_id, $column_name, 'post');
128
- break;
129
-
130
- // Image metadata EXIF or IPTC data
131
- case "column-image-aperture" :
132
- $result = !empty( $meta['image_meta']['aperture'] ) ? $meta['image_meta']['aperture'] : '';
133
- break;
134
-
135
- case "column-image-credit" :
136
- $result = !empty( $meta['image_meta']['credit'] ) ? $meta['image_meta']['credit'] : '';
137
- break;
138
-
139
- case "column-image-camera" :
140
- $result = !empty( $meta['image_meta']['camera'] ) ? $meta['image_meta']['camera'] : '';
141
- break;
142
-
143
- case "column-image-caption" :
144
- $result = !empty( $meta['image_meta']['caption'] ) ? $meta['image_meta']['caption'] : '';
145
- break;
146
-
147
- case "column-image-created_timestamp" :
148
- if ( !empty( $meta['image_meta']['created_timestamp'] ) ) {
149
- $result = date_i18n( get_option('date_format') . ' ' . get_option('time_format') , strtotime($meta['image_meta']['created_timestamp']) );
150
- }
151
- break;
152
-
153
- case "column-image-copyright" :
154
- $result = !empty( $meta['image_meta']['copyright'] ) ? $meta['image_meta']['copyright'] : '';
155
- break;
156
-
157
- case "column-image-focal_length" :
158
- $result = !empty( $meta['image_meta']['focal_length'] ) ? $meta['image_meta']['focal_length'] : '';
159
- break;
160
-
161
- case "column-image-iso" :
162
- $result = !empty( $meta['image_meta']['iso'] ) ? $meta['image_meta']['iso'] : '';
163
- break;
164
-
165
- case "column-image-shutter_speed" :
166
- $result = !empty( $meta['image_meta']['shutter_speed'] ) ? $meta['image_meta']['shutter_speed'] : '';
167
- break;
168
-
169
- case "column-image-title" :
170
- $result = !empty( $meta['image_meta']['title'] ) ? $meta['image_meta']['title'] : '';
171
- break;
172
-
173
- default :
174
- $result = '';
175
-
176
- endswitch;
177
-
178
- // Filter for customizing the result output
179
- apply_filters('cpac-media-column-result', $result, $type, $column_name, $media_id);
180
-
181
- echo $result;
182
- }
183
-
184
- /**
185
- * Get column value of media actions
186
- *
187
- * This part is copied from the Media List Table class
188
- *
189
- * @since 1.4.2
190
- */
191
- private function get_column_value_actions( $id )
192
- {
193
- if ( file_exists(ABSPATH . 'wp-admin/includes/class-wp-list-table.php') )
194
- require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
195
- if ( file_exists(ABSPATH . 'wp-admin/includes/class-wp-media-list-table.php') )
196
- require_once(ABSPATH . 'wp-admin/includes/class-wp-media-list-table.php');
197
-
198
- // we need class to get the object actions
199
- $m = new WP_Media_List_Table;
200
-
201
- // prevent php notice
202
- $m->is_trash = isset( $_REQUEST['status'] ) && 'trash' == $_REQUEST['status'];
203
-
204
- // get media actions
205
- $media = get_post($id);
206
- $actions = $m->_get_row_actions( $media, _draft_or_post_title($id) );
207
-
208
- return implode(' | ', $actions);
209
- }
210
- }
211
-
212
  ?>
1
+ <?php
2
+
3
+ /**
4
+ * CPAC_Media_Values Class
5
+ *
6
+ * @since 1.4.4
7
+ *
8
+ */
9
+ class CPAC_Media_Values extends CPAC_Values
10
+ {
11
+ /**
12
+ * Constructor
13
+ *
14
+ * @since 1.4.4
15
+ */
16
+ function __construct()
17
+ {
18
+ parent::__construct();
19
+
20
+ add_action( 'manage_media_custom_column', array( $this, 'manage_media_column_value'), 10, 2 );
21
+ }
22
+
23
+ /**
24
+ * Manage custom column for Media.
25
+ *
26
+ * @since 1.3
27
+ */
28
+ public function manage_media_column_value( $column_name, $media_id )
29
+ {
30
+ $type = $column_name;
31
+
32
+ //$meta = wp_get_attachment_metadata($media_id);
33
+ $meta = get_post_meta( $media_id, '_wp_attachment_metadata', true );
34
+ $p = get_post($media_id);
35
+
36
+ // Check for custom fields, such as column-meta-[customfieldname]
37
+ if ( $this->is_column_meta($type) )
38
+ $type = 'column-meta';
39
+
40
+ // Hook
41
+ do_action('cpac-manage-media-column', $type, $column_name, $media_id);
42
+
43
+ $result = '';
44
+ switch ($type) :
45
+
46
+ // media id
47
+ case "column-mediaid" :
48
+ $result = $media_id;
49
+ break;
50
+
51
+ // dimensions
52
+ case "column-dimensions" :
53
+ if ( !empty($meta['width']) && !empty($meta['height']) )
54
+ $result = "{$meta['width']} x {$meta['height']}";
55
+ break;
56
+
57
+ // width
58
+ case "column-width" :
59
+ $result = !empty($meta['width']) ? $meta['width'] : '';
60
+ break;
61
+
62
+ // height
63
+ case "column-height" :
64
+ $result = !empty($meta['height']) ? $meta['height'] : '';
65
+ break;
66
+
67
+ // description
68
+ case "column-description" :
69
+ $result = $p->post_content;
70
+ break;
71
+
72
+ // caption
73
+ case "column-caption" :
74
+ $result = $p->post_excerpt;
75
+ break;
76
+
77
+ // alternate text
78
+ case "column-alternate_text" :
79
+ $alt = get_post_meta($media_id, '_wp_attachment_image_alt', true);
80
+ $result = $this->strip_trim($alt);
81
+ break;
82
+
83
+ // mime type
84
+ case "column-mime_type" :
85
+ $result = $p->post_mime_type;
86
+ break;
87
+
88
+ // file name
89
+ case "column-file_name" :
90
+ $file = wp_get_attachment_url($p->ID);
91
+ $filename = basename($file);
92
+ $result = "<a title='{$filename}' href='{$file}'>{$filename}</a>";
93
+ break;
94
+
95
+ // file paths
96
+ case "column-file_paths" :
97
+ $sizes = get_intermediate_image_sizes();
98
+ $url = wp_get_attachment_url($p->ID);
99
+ $filename = basename($url);
100
+ $paths[] = "<a title='{$filename}' href='{$url}'>" . __('original', CPAC_TEXTDOMAIN) . "</a>";
101
+ if ( $sizes ) {
102
+ foreach ( $sizes as $size ) {
103
+ $src = wp_get_attachment_image_src( $media_id, $size );
104
+ if (!empty($src[0])) {
105
+ $filename = basename($src[0]);
106
+ $paths[] = "<a title='{$filename}' href='{$src[0]}'>{$size}</a>";
107
+ }
108
+ }
109
+ }
110
+ $result = implode('<span class="cpac-divider"></span>', $paths);
111
+ break;
112
+
113
+ case "column-actions" :
114
+ $result = $this->get_column_value_actions($media_id);
115
+ break;
116
+
117
+ case "column-filesize" :
118
+ $file = wp_get_attachment_url($p->ID);
119
+ $abs = str_replace( WP_CONTENT_URL, WP_CONTENT_DIR, $file);
120
+ if ( file_exists($abs) ) {
121
+ $result = $this->get_readable_filesize(filesize($abs));
122
+ }
123
+ break;
124
+
125
+ // Custom Field
126
+ case "column-meta" :
127
+ $result = $this->get_column_value_custom_field($media_id, $column_name, 'media');
128
+ break;
129
+
130
+ // Image metadata EXIF or IPTC data
131
+ case "column-image-aperture" :
132
+ $result = !empty( $meta['image_meta']['aperture'] ) ? $meta['image_meta']['aperture'] : '';
133
+ break;
134
+
135
+ case "column-image-credit" :
136
+ $result = !empty( $meta['image_meta']['credit'] ) ? $meta['image_meta']['credit'] : '';
137
+ break;
138
+
139
+ case "column-image-camera" :
140
+ $result = !empty( $meta['image_meta']['camera'] ) ? $meta['image_meta']['camera'] : '';
141
+ break;
142
+
143
+ case "column-image-caption" :
144
+ $result = !empty( $meta['image_meta']['caption'] ) ? $meta['image_meta']['caption'] : '';
145
+ break;
146
+
147
+ case "column-image-created_timestamp" :
148
+ if ( !empty( $meta['image_meta']['created_timestamp'] ) ) {
149
+ $result = date_i18n( get_option('date_format') . ' ' . get_option('time_format') , strtotime($meta['image_meta']['created_timestamp']) );
150
+ }
151
+ break;
152
+
153
+ case "column-image-copyright" :
154
+ $result = !empty( $meta['image_meta']['copyright'] ) ? $meta['image_meta']['copyright'] : '';
155
+ break;
156
+
157
+ case "column-image-focal_length" :
158
+ $result = !empty( $meta['image_meta']['focal_length'] ) ? $meta['image_meta']['focal_length'] : '';
159
+ break;
160
+
161
+ case "column-image-iso" :
162
+ $result = !empty( $meta['image_meta']['iso'] ) ? $meta['image_meta']['iso'] : '';
163
+ break;
164
+
165
+ case "column-image-shutter_speed" :
166
+ $result = !empty( $meta['image_meta']['shutter_speed'] ) ? $meta['image_meta']['shutter_speed'] : '';
167
+ break;
168
+
169
+ case "column-image-title" :
170
+ $result = !empty( $meta['image_meta']['title'] ) ? $meta['image_meta']['title'] : '';
171
+ break;
172
+
173
+ default :
174
+ $result = '';
175
+
176
+ endswitch;
177
+
178
+ // Filter for customizing the result output
179
+ apply_filters('cpac-media-column-result', $result, $type, $column_name, $media_id);
180
+
181
+ echo $result;
182
+ }
183
+
184
+ /**
185
+ * Get column value of media actions
186
+ *
187
+ * This part is copied from the Media List Table class
188
+ *
189
+ * @since 1.4.2
190
+ */
191
+ private function get_column_value_actions( $id )
192
+ {
193
+ if ( file_exists(ABSPATH . 'wp-admin/includes/class-wp-list-table.php') )
194
+ require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
195
+ if ( file_exists(ABSPATH . 'wp-admin/includes/class-wp-media-list-table.php') )
196
+ require_once(ABSPATH . 'wp-admin/includes/class-wp-media-list-table.php');
197
+
198
+ // we need class to get the object actions
199
+ $m = new WP_Media_List_Table;
200
+
201
+ // prevent php notice
202
+ $m->is_trash = isset( $_REQUEST['status'] ) && 'trash' == $_REQUEST['status'];
203
+
204
+ // get media actions
205
+ $media = get_post($id);
206
+ $actions = $m->_get_row_actions( $media, _draft_or_post_title($id) );
207
+
208
+ return implode(' | ', $actions);
209
+ }
210
+ }
211
+
212
  ?>
classes/values/posts.php CHANGED
@@ -1,343 +1,343 @@
1
- <?php
2
-
3
- /**
4
- * CPAC_Posts_Values Class
5
- *
6
- * @since 1.4.4
7
- *
8
- */
9
- class CPAC_Posts_Values extends CPAC_Values
10
- {
11
- /**
12
- * Constructor
13
- *
14
- * @since 1.4.4
15
- */
16
- function __construct()
17
- {
18
- parent::__construct();
19
-
20
- add_action( 'manage_pages_custom_column', array( $this, 'manage_posts_column_value'), 10, 2 );
21
- add_action( 'manage_posts_custom_column', array( $this, 'manage_posts_column_value'), 10, 2 );
22
- }
23
-
24
- /**
25
- * Manage custom column for Post Types.
26
- *
27
- * @since 1.0
28
- */
29
- public function manage_posts_column_value($column_name, $post_id)
30
- {
31
- $type = $column_name;
32
-
33
- // Check for taxonomies, such as column-taxonomy-[taxname]
34
- if ( strpos($type, 'column-taxonomy-') !== false )
35
- $type = 'column-taxonomy';
36
-
37
- // Check for custom fields, such as column-meta-[customfieldname]
38
- if ( $this->is_column_meta($type) )
39
- $type = 'column-post-meta';
40
-
41
- // Hook
42
- do_action('cpac-manage-posts-column', $type, $column_name, $post_id);
43
-
44
- // Switch Types
45
- $result = '';
46
- switch ($type) :
47
-
48
- // Post ID
49
- case "column-postid" :
50
- $result = $post_id;
51
- break;
52
-
53
- // Excerpt
54
- case "column-excerpt" :
55
- $result = $this->get_post_excerpt($post_id);
56
- break;
57
-
58
- // Featured Image
59
- case "column-featured_image" :
60
- if ( function_exists('has_post_thumbnail') && has_post_thumbnail($post_id) )
61
- $result = get_the_post_thumbnail($post_id, $this->thumbnail_size);
62
- break;
63
-
64
- // Sticky Post
65
- case "column-sticky" :
66
- if ( is_sticky($post_id) )
67
- $result = $this->get_asset_image('checkmark.png');
68
- break;
69
-
70
- // Order
71
- case "column-order" :
72
- $result = get_post_field('menu_order', $post_id);
73
- break;
74
-
75
- // Post Formats
76
- case "column-post_formats" :
77
- $result = get_post_format($post_id);
78
- break;
79
-
80
- // Page template
81
- case "column-page-template" :
82
- // file name
83
- $page_template = get_post_meta($post_id, '_wp_page_template', true);
84
-
85
- // get template nice name
86
- $result = array_search($page_template, get_page_templates());
87
- break;
88
-
89
- // Slug
90
- case "column-page-slug" :
91
- $result = get_post($post_id)->post_name;
92
- break;
93
-
94
- // Slug
95
- case "column-word-count" :
96
- $result = str_word_count( $this->strip_trim( get_post($post_id)->post_content ) );
97
- break;
98
-
99
- // Taxonomy
100
- case "column-taxonomy" :
101
- $tax = str_replace('column-taxonomy-', '', $column_name);
102
- $tags = get_the_terms($post_id, $tax);
103
- $tarr = array();
104
-
105
- // for post formats we will display standard instead of empty
106
- if ( $tax == 'post_format' && empty($tags) ) {
107
- $result = __('Standard');
108
- }
109
-
110
- // add name with link
111
- elseif ( !empty($tags) ) {
112
- $post_type = get_post_type($post_id);
113
- foreach($tags as $tag) {
114
- // sanatize title
115
- if ( isset($tag->term_id) ) {
116
- $tax_title = esc_html(sanitize_term_field('name', $tag->name, $tag->term_id, $tag->taxonomy, 'edit'));
117
- $tarr[] = "<a href='edit.php?post_type={$post_type}&{$tag->taxonomy}={$tag->slug}'>{$tax_title}</a>";
118
- }
119
- }
120
- $result = implode(', ', $tarr);
121
- }
122
- break;
123
-
124
- // Custom Field
125
- case "column-post-meta" :
126
- $result = $this->get_column_value_custom_field($post_id, $column_name, 'post');
127
- break;
128
-
129
- // Attachment
130
- case "column-attachment" :
131
- $result = $this->get_column_value_attachments($post_id);
132
- break;
133
-
134
- // Attachment count
135
- case "column-attachment-count" :
136
- $result = count($this->get_attachment_ids($post_id));
137
- break;
138
-
139
- // Roles
140
- case "column-roles" :
141
- $user_id = get_post($post_id)->post_author;
142
- $userdata = get_userdata( $user_id );
143
- if ( !empty($userdata->roles[0]) )
144
- $result = implode(', ',$userdata->roles);
145
- break;
146
-
147
- // Post status
148
- case "column-status" :
149
- $p = get_post($post_id);
150
- $result = $this->get_post_status_friendly_name( $p->post_status );
151
- if ( $p->post_status == 'future')
152
- $result = $result . " <p class='description'>" . date_i18n( get_option('date_format') . ' ' . get_option('time_format') , strtotime($p->post_date) ) . "</p>";
153
- break;
154
-
155
- // Post comment status
156
- case "column-comment-status" :
157
- $p = get_post($post_id);
158
- $result = $this->get_asset_image('no.png', $p->comment_status);
159
- if ( $p->comment_status == 'open' )
160
- $result = $this->get_asset_image('checkmark.png', $p->comment_status);
161
- break;
162
-
163
- // Post ping status
164
- case "column-ping-status" :
165
- $p = get_post($post_id);
166
- $result = $this->get_asset_image('no.png', $p->ping_status);
167
- if ( $p->ping_status == 'open' )
168
- $result = $this->get_asset_image('checkmark.png', $p->ping_status);
169
- break;
170
-
171
- // Post actions ( delete, edit etc. )
172
- case "column-actions" :
173
- $result = $this->get_column_value_actions($post_id);
174
- break;
175
-
176
- // Post Last modified
177
- case "column-modified" :
178
- $p = get_post($post_id);
179
- $result = $this->get_date($p->post_modified) . ' ' . $this->get_time($p->post_modified);
180
- break;
181
-
182
- // Post Comment count
183
- case "column-comment-count" :
184
- $result = WP_List_Table::comments_bubble( $post_id, get_pending_comments_num( $post_id ) );
185
- $result .= $this->get_comment_count_details( $post_id );
186
- break;
187
-
188
- // Author Name
189
- case "column-author-name" :
190
- $result = $this->get_column_value_authorname($post_id, $column_name);
191
- break;
192
-
193
- // Before More Tag
194
- case "column-before-moretag" :
195
- $p = get_post($post_id);
196
- $extended = get_extended($p->post_content);
197
-
198
- if ( !empty($extended['extended']) ) {
199
- $result = $this->get_shortened_string($extended['main'], $this->excerpt_length );
200
- }
201
- break;
202
-
203
- default :
204
- $result = '';
205
-
206
- endswitch;
207
-
208
- // Filter for customizing the result output
209
- apply_filters('cpac-posts-column-result', $result, $type, $column_name, $post_id);
210
-
211
- echo $result;
212
- }
213
-
214
- /**
215
- * Returns the friendly name for a given status
216
- *
217
- * @since 1.4.4
218
- */
219
- private function get_post_status_friendly_name( $status )
220
- {
221
- $builtin = array(
222
- 'publish' => __( 'Published', CPAC_TEXTDOMAIN ),
223
- 'draft' => __( 'Draft', CPAC_TEXTDOMAIN ),
224
- 'future' => __( 'Scheduled', CPAC_TEXTDOMAIN ),
225
- 'private' => __( 'Private', CPAC_TEXTDOMAIN ),
226
- 'pending' => __( 'Pending Review', CPAC_TEXTDOMAIN ),
227
- 'trash' => __( 'Trash', CPAC_TEXTDOMAIN )
228
- );
229
-
230
- if ( isset($builtin[$status]) )
231
- $status = $builtin[$status];
232
-
233
- return $status;
234
- }
235
-
236
- /**
237
- * Comment count extended
238
- *
239
- * @since 1.4.4
240
- */
241
- private function get_comment_count_details( $post_id )
242
- {
243
- $c = wp_count_comments($post_id);
244
-
245
- $details = '';
246
- if ( $c->approved ) {
247
- $url = esc_url( add_query_arg( array('p' => $post_id, 'comment_status' => 'approved'), admin_url( 'edit-comments.php' ) ) );
248
- $details .= "<a href='{$url}' class='cp-approved' title='".__('approved', CPAC_TEXTDOMAIN) . "'>{$c->approved}</a>";
249
- }
250
- if ( $c->moderated ) {
251
- $url = esc_url( add_query_arg( array('p' => $post_id, 'comment_status' => 'moderated'), admin_url( 'edit-comments.php' ) ) );
252
- $details .= "<a href='{$url}' class='cp-moderated' title='".__('pending', CPAC_TEXTDOMAIN) . "'>{$c->moderated}</a>";
253
- }
254
- if ( $c->spam ) {
255
- $url = esc_url( add_query_arg( array('p' => $post_id, 'comment_status' => 'spam'), admin_url( 'edit-comments.php' ) ) );
256
- $details .= "<a href='{$url}' class='cp-spam' title='".__('spam', CPAC_TEXTDOMAIN) . "'>{$c->spam}</a>";
257
- }
258
- if ( $c->trash ) {
259
- $url = esc_url( add_query_arg( array('p' => $post_id, 'comment_status' => 'trash'), admin_url( 'edit-comments.php' ) ) );
260
- $details .= "<a href='{$url}' class='cp-trash' title='".__('trash', CPAC_TEXTDOMAIN) . "'>{$c->trash}</a>";
261
- }
262
-
263
- if ( $details )
264
- return "<p class='description row-actions'>{$details}</p>";
265
-
266
- return false;
267
- }
268
-
269
- /**
270
- * Get column value of post actions
271
- *
272
- * This part is copied from the Posts List Table class
273
- *
274
- * @since 1.4.2
275
- */
276
- protected function get_column_value_actions( $post_id )
277
- {
278
- $actions = array();
279
-
280
- $post = get_post($post_id);
281
- $title = _draft_or_post_title();
282
- $post_type_object = get_post_type_object( $post->post_type );
283
- $can_edit_post = current_user_can( $post_type_object->cap->edit_post, $post->ID );
284
-
285
- if ( $can_edit_post && 'trash' != $post->post_status ) {
286
- $actions['edit'] = '<a href="' . get_edit_post_link( $post->ID, true ) . '" title="' . esc_attr( __( 'Edit this item' ) ) . '">' . __( 'Edit' ) . '</a>';
287
- $actions['inline hide-if-no-js'] = '<a href="#" class="editinline" title="' . esc_attr( __( 'Edit this item inline' ) ) . '">' . __( 'Quick&nbsp;Edit' ) . '</a>';
288
- }
289
- if ( current_user_can( $post_type_object->cap->delete_post, $post->ID ) ) {
290
- if ( 'trash' == $post->post_status )
291
- $actions['untrash'] = "<a title='" . esc_attr( __( 'Restore this item from the Trash' ) ) . "' href='" . wp_nonce_url( admin_url( sprintf( $post_type_object->_edit_link . '&amp;action=untrash', $post->ID ) ), 'untrash-' . $post->post_type . '_' . $post->ID ) . "'>" . __( 'Restore' ) . "</a>";
292
- elseif ( EMPTY_TRASH_DAYS )
293
- $actions['trash'] = "<a class='submitdelete' title='" . esc_attr( __( 'Move this item to the Trash' ) ) . "' href='" . get_delete_post_link( $post->ID ) . "'>" . __( 'Trash' ) . "</a>";
294
- if ( 'trash' == $post->post_status || !EMPTY_TRASH_DAYS )
295
- $actions['delete'] = "<a class='submitdelete' title='" . esc_attr( __( 'Delete this item permanently' ) ) . "' href='" . get_delete_post_link( $post->ID, '', true ) . "'>" . __( 'Delete Permanently' ) . "</a>";
296
- }
297
- if ( $post_type_object->public ) {
298
- if ( in_array( $post->post_status, array( 'pending', 'draft', 'future' ) ) ) {
299
- if ( $can_edit_post )
300
- $actions['view'] = '<a href="' . esc_url( add_query_arg( 'preview', 'true', get_permalink( $post->ID ) ) ) . '" title="' . esc_attr( sprintf( __( 'Preview &#8220;%s&#8221;' ), $title ) ) . '" rel="permalink">' . __( 'Preview' ) . '</a>';
301
- } elseif ( 'trash' != $post->post_status ) {
302
- $actions['view'] = '<a href="' . get_permalink( $post->ID ) . '" title="' . esc_attr( sprintf( __( 'View &#8220;%s&#8221;' ), $title ) ) . '" rel="permalink">' . __( 'View' ) . '</a>';
303
- }
304
- }
305
-
306
- return implode(' | ', $actions);
307
- }
308
-
309
- /**
310
- * Get column value of Custom Field
311
- *
312
- * @since 1.4.6.1
313
- */
314
- protected function get_column_value_authorname($post_id, $column_name)
315
- {
316
- $type = get_post_type($post_id);
317
-
318
- // get column
319
- $columns = $this->get_stored_columns($type);
320
-
321
- // get the type of author name
322
- $display_as = isset($columns[$column_name]['display_as']) ? $columns[$column_name]['display_as'] : '';
323
-
324
- // get the author
325
- $post = get_post($post_id);
326
- if ( !isset( $post->post_author) )
327
- return false;
328
-
329
- $name = Codepress_Admin_Columns::get_author_field_by_nametype($display_as, $post->post_author);
330
-
331
- // filter for customization
332
- $name = apply_filters('cpac_get_column_value_authorname', $name, $column_name, $post_id );
333
-
334
- // add link filter
335
- $class = isset( $_GET['author'] ) && $_GET['author'] == $userdata->ID ? ' class="current"' : '';
336
-
337
- $name = "<a href='edit.php?post_type={$type}&author={$post->post_author}'{$class}>{$name}</a>";
338
-
339
- return $name;
340
- }
341
- }
342
-
343
  ?>
1
+ <?php
2
+
3
+ /**
4
+ * CPAC_Posts_Values Class
5
+ *
6
+ * @since 1.4.4
7
+ *
8
+ */
9
+ class CPAC_Posts_Values extends CPAC_Values
10
+ {
11
+ /**
12
+ * Constructor
13
+ *
14
+ * @since 1.4.4
15
+ */
16
+ function __construct()
17
+ {
18
+ parent::__construct();
19
+
20
+ add_action( 'manage_pages_custom_column', array( $this, 'manage_posts_column_value'), 10, 2 );
21
+ add_action( 'manage_posts_custom_column', array( $this, 'manage_posts_column_value'), 10, 2 );
22
+ }
23
+
24
+ /**
25
+ * Manage custom column for Post Types.
26
+ *
27
+ * @since 1.0
28
+ */
29
+ public function manage_posts_column_value($column_name, $post_id)
30
+ {
31
+ $type = $column_name;
32
+
33
+ // Check for taxonomies, such as column-taxonomy-[taxname]
34
+ if ( strpos($type, 'column-taxonomy-') !== false )
35
+ $type = 'column-taxonomy';
36
+
37
+ // Check for custom fields, such as column-meta-[customfieldname]
38
+ if ( $this->is_column_meta($type) )
39
+ $type = 'column-post-meta';
40
+
41
+ // Hook
42
+ do_action('cpac-manage-posts-column', $type, $column_name, $post_id);
43
+
44
+ // Switch Types
45
+ $result = '';
46
+ switch ($type) :
47
+
48
+ // Post ID
49
+ case "column-postid" :
50
+ $result = $post_id;
51
+ break;
52
+
53
+ // Excerpt
54
+ case "column-excerpt" :
55
+ $result = $this->get_post_excerpt($post_id);
56
+ break;
57
+
58
+ // Featured Image
59
+ case "column-featured_image" :
60
+ if ( function_exists('has_post_thumbnail') && has_post_thumbnail($post_id) )
61
+ $result = get_the_post_thumbnail($post_id, $this->thumbnail_size);
62
+ break;
63
+
64
+ // Sticky Post
65
+ case "column-sticky" :
66
+ if ( is_sticky($post_id) )
67
+ $result = $this->get_asset_image('checkmark.png');
68
+ break;
69
+
70
+ // Order
71
+ case "column-order" :
72
+ $result = get_post_field('menu_order', $post_id);
73
+ break;
74
+
75
+ // Post Formats
76
+ case "column-post_formats" :
77
+ $result = get_post_format($post_id);
78
+ break;
79
+
80
+ // Page template
81
+ case "column-page-template" :
82
+ // file name
83
+ $page_template = get_post_meta($post_id, '_wp_page_template', true);
84
+
85
+ // get template nice name
86
+ $result = array_search($page_template, get_page_templates());
87
+ break;
88
+
89
+ // Slug
90
+ case "column-page-slug" :
91
+ $result = get_post($post_id)->post_name;
92
+ break;
93
+
94
+ // Slug
95
+ case "column-word-count" :
96
+ $result = str_word_count( $this->strip_trim( get_post($post_id)->post_content ) );
97
+ break;
98
+
99
+ // Taxonomy
100
+ case "column-taxonomy" :
101
+ $tax = str_replace('column-taxonomy-', '', $column_name);
102
+ $tags = get_the_terms($post_id, $tax);
103
+ $tarr = array();
104
+
105
+ // for post formats we will display standard instead of empty
106
+ if ( $tax == 'post_format' && empty($tags) ) {
107
+ $result = __('Standard');
108
+ }
109
+
110
+ // add name with link
111
+ elseif ( !empty($tags) ) {
112
+ $post_type = get_post_type($post_id);
113
+ foreach($tags as $tag) {
114
+ // sanatize title
115
+ if ( isset($tag->term_id) ) {
116
+ $tax_title = esc_html(sanitize_term_field('name', $tag->name, $tag->term_id, $tag->taxonomy, 'edit'));
117
+ $tarr[] = "<a href='edit.php?post_type={$post_type}&{$tag->taxonomy}={$tag->slug}'>{$tax_title}</a>";
118
+ }
119
+ }
120
+ $result = implode(', ', $tarr);
121
+ }
122
+ break;
123
+
124
+ // Custom Field
125
+ case "column-post-meta" :
126
+ $result = $this->get_column_value_custom_field($post_id, $column_name, 'post');
127
+ break;
128
+
129
+ // Attachment
130
+ case "column-attachment" :
131
+ $result = $this->get_column_value_attachments($post_id);
132
+ break;
133
+
134
+ // Attachment count
135
+ case "column-attachment-count" :
136
+ $result = count($this->get_attachment_ids($post_id));
137
+ break;
138
+
139
+ // Roles
140
+ case "column-roles" :
141
+ $user_id = get_post($post_id)->post_author;
142
+ $userdata = get_userdata( $user_id );
143
+ if ( !empty($userdata->roles[0]) )
144
+ $result = implode(', ',$userdata->roles);
145
+ break;
146
+
147
+ // Post status
148
+ case "column-status" :
149
+ $p = get_post($post_id);
150
+ $result = $this->get_post_status_friendly_name( $p->post_status );
151
+ if ( $p->post_status == 'future')
152
+ $result = $result . " <p class='description'>" . date_i18n( get_option('date_format') . ' ' . get_option('time_format') , strtotime($p->post_date) ) . "</p>";
153
+ break;
154
+
155
+ // Post comment status
156
+ case "column-comment-status" :
157
+ $p = get_post($post_id);
158
+ $result = $this->get_asset_image('no.png', $p->comment_status);
159
+ if ( $p->comment_status == 'open' )
160
+ $result = $this->get_asset_image('checkmark.png', $p->comment_status);
161
+ break;
162
+
163
+ // Post ping status
164
+ case "column-ping-status" :
165
+ $p = get_post($post_id);
166
+ $result = $this->get_asset_image('no.png', $p->ping_status);
167
+ if ( $p->ping_status == 'open' )
168
+ $result = $this->get_asset_image('checkmark.png', $p->ping_status);
169
+ break;
170
+
171
+ // Post actions ( delete, edit etc. )
172
+ case "column-actions" :
173
+ $result = $this->get_column_value_actions($post_id);
174
+ break;
175
+
176
+ // Post Last modified
177
+ case "column-modified" :
178
+ $p = get_post($post_id);
179
+ $result = $this->get_date($p->post_modified) . ' ' . $this->get_time($p->post_modified);
180
+ break;
181
+
182
+ // Post Comment count
183
+ case "column-comment-count" :
184
+ $result = WP_List_Table::comments_bubble( $post_id, get_pending_comments_num( $post_id ) );
185
+ $result .= $this->get_comment_count_details( $post_id );
186
+ break;
187
+
188
+ // Author Name
189
+ case "column-author-name" :
190
+ $result = $this->get_column_value_authorname($post_id, $column_name);
191
+ break;
192
+
193
+ // Before More Tag
194
+ case "column-before-moretag" :
195
+ $p = get_post($post_id);
196
+ $extended = get_extended($p->post_content);
197
+
198
+ if ( !empty($extended['extended']) ) {
199
+ $result = $this->get_shortened_string($extended['main'], $this->excerpt_length );
200
+ }
201
+ break;
202
+
203
+ default :
204
+ $result = '';
205
+
206
+ endswitch;
207
+
208
+ // Filter for customizing the result output
209
+ apply_filters('cpac-posts-column-result', $result, $type, $column_name, $post_id);
210
+
211
+ echo $result;
212
+ }
213
+
214
+ /**
215
+ * Returns the friendly name for a given status
216
+ *
217
+ * @since 1.4.4
218
+ */
219
+ private function get_post_status_friendly_name( $status )
220
+ {
221
+ $builtin = array(
222
+ 'publish' => __( 'Published', CPAC_TEXTDOMAIN ),
223
+ 'draft' => __( 'Draft', CPAC_TEXTDOMAIN ),
224
+ 'future' => __( 'Scheduled', CPAC_TEXTDOMAIN ),
225
+ 'private' => __( 'Private', CPAC_TEXTDOMAIN ),
226
+ 'pending' => __( 'Pending Review', CPAC_TEXTDOMAIN ),
227
+ 'trash' => __( 'Trash', CPAC_TEXTDOMAIN )
228
+ );
229
+
230
+ if ( isset($builtin[$status]) )
231
+ $status = $builtin[$status];
232
+
233
+ return $status;
234
+ }
235
+
236
+ /**
237
+ * Comment count extended
238
+ *
239
+ * @since 1.4.4
240
+ */
241
+ private function get_comment_count_details( $post_id )
242
+ {
243
+ $c = wp_count_comments($post_id);
244
+
245
+ $details = '';
246
+ if ( $c->approved ) {
247
+ $url = esc_url( add_query_arg( array('p' => $post_id, 'comment_status' => 'approved'), admin_url( 'edit-comments.php' ) ) );
248
+ $details .= "<a href='{$url}' class='cp-approved' title='".__('approved', CPAC_TEXTDOMAIN) . "'>{$c->approved}</a>";
249
+ }
250
+ if ( $c->moderated ) {
251
+ $url = esc_url( add_query_arg( array('p' => $post_id, 'comment_status' => 'moderated'), admin_url( 'edit-comments.php' ) ) );
252
+ $details .= "<a href='{$url}' class='cp-moderated' title='".__('pending', CPAC_TEXTDOMAIN) . "'>{$c->moderated}</a>";
253
+ }
254
+ if ( $c->spam ) {
255
+ $url = esc_url( add_query_arg( array('p' => $post_id, 'comment_status' => 'spam'), admin_url( 'edit-comments.php' ) ) );
256
+ $details .= "<a href='{$url}' class='cp-spam' title='".__('spam', CPAC_TEXTDOMAIN) . "'>{$c->spam}</a>";
257
+ }
258
+ if ( $c->trash ) {
259
+ $url = esc_url( add_query_arg( array('p' => $post_id, 'comment_status' => 'trash'), admin_url( 'edit-comments.php' ) ) );
260
+ $details .= "<a href='{$url}' class='cp-trash' title='".__('trash', CPAC_TEXTDOMAIN) . "'>{$c->trash}</a>";
261
+ }
262
+
263
+ if ( $details )
264
+ return "<p class='description row-actions'>{$details}</p>";
265
+
266
+ return false;
267
+ }
268
+
269
+ /**
270
+ * Get column value of post actions
271
+ *
272
+ * This part is copied from the Posts List Table class
273
+ *
274
+ * @since 1.4.2
275
+ */
276
+ protected function get_column_value_actions( $post_id )
277
+ {
278
+ $actions = array();
279
+
280
+ $post = get_post($post_id);
281
+ $title = _draft_or_post_title();
282
+ $post_type_object = get_post_type_object( $post->post_type );
283
+ $can_edit_post = current_user_can( $post_type_object->cap->edit_post, $post->ID );
284
+
285
+ if ( $can_edit_post && 'trash' != $post->post_status ) {
286
+ $actions['edit'] = '<a href="' . get_edit_post_link( $post->ID, true ) . '" title="' . esc_attr( __( 'Edit this item' ) ) . '">' . __( 'Edit' ) . '</a>';
287
+ $actions['inline hide-if-no-js'] = '<a href="#" class="editinline" title="' . esc_attr( __( 'Edit this item inline' ) ) . '">' . __( 'Quick&nbsp;Edit' ) . '</a>';
288
+ }
289
+ if ( current_user_can( $post_type_object->cap->delete_post, $post->ID ) ) {
290
+ if ( 'trash' == $post->post_status )
291
+ $actions['untrash'] = "<a title='" . esc_attr( __( 'Restore this item from the Trash' ) ) . "' href='" . wp_nonce_url( admin_url( sprintf( $post_type_object->_edit_link . '&amp;action=untrash', $post->ID ) ), 'untrash-' . $post->post_type . '_' . $post->ID ) . "'>" . __( 'Restore' ) . "</a>";
292
+ elseif ( EMPTY_TRASH_DAYS )
293
+ $actions['trash'] = "<a class='submitdelete' title='" . esc_attr( __( 'Move this item to the Trash' ) ) . "' href='" . get_delete_post_link( $post->ID ) . "'>" . __( 'Trash' ) . "</a>";
294
+ if ( 'trash' == $post->post_status || !EMPTY_TRASH_DAYS )
295
+ $actions['delete'] = "<a class='submitdelete' title='" . esc_attr( __( 'Delete this item permanently' ) ) . "' href='" . get_delete_post_link( $post->ID, '', true ) . "'>" . __( 'Delete Permanently' ) . "</a>";
296
+ }
297
+ if ( $post_type_object->public ) {
298
+ if ( in_array( $post->post_status, array( 'pending', 'draft', 'future' ) ) ) {
299
+ if ( $can_edit_post )
300
+ $actions['view'] = '<a href="' . esc_url( add_query_arg( 'preview', 'true', get_permalink( $post->ID ) ) ) . '" title="' . esc_attr( sprintf( __( 'Preview &#8220;%s&#8221;' ), $title ) ) . '" rel="permalink">' . __( 'Preview' ) . '</a>';
301
+ } elseif ( 'trash' != $post->post_status ) {
302
+ $actions['view'] = '<a href="' . get_permalink( $post->ID ) . '" title="' . esc_attr( sprintf( __( 'View &#8220;%s&#8221;' ), $title ) ) . '" rel="permalink">' . __( 'View' ) . '</a>';
303
+ }
304
+ }
305
+
306
+ return implode(' | ', $actions);
307
+ }
308
+
309
+ /**
310
+ * Get column value of Custom Field
311
+ *
312
+ * @since 1.4.6.1
313
+ */
314
+ protected function get_column_value_authorname($post_id, $column_name)
315
+ {
316
+ $type = get_post_type($post_id);
317
+
318
+ // get column
319
+ $columns = $this->get_stored_columns($type);
320
+
321
+ // get the type of author name
322
+ $display_as = isset($columns[$column_name]['display_as']) ? $columns[$column_name]['display_as'] : '';
323
+
324
+ // get the author
325
+ $post = get_post($post_id);
326
+ if ( !isset( $post->post_author) )
327
+ return false;
328
+
329
+ $name = Codepress_Admin_Columns::get_author_field_by_nametype($display_as, $post->post_author);
330
+
331
+ // filter for customization
332
+ $name = apply_filters('cpac_get_column_value_authorname', $name, $column_name, $post_id );
333
+
334
+ // add link filter
335
+ $class = isset( $_GET['author'] ) && $_GET['author'] == $userdata->ID ? ' class="current"' : '';
336
+
337
+ $name = "<a href='edit.php?post_type={$type}&author={$post->post_author}'{$class}>{$name}</a>";
338
+
339
+ return $name;
340
+ }
341
+ }
342
+
343
  ?>
classes/values/users.php CHANGED
@@ -1,159 +1,159 @@
1
- <?php
2
-
3
- /**
4
- * CPAC_Users_Values Class
5
- *
6
- * @since 1.4.4
7
- *
8
- */
9
- class CPAC_Users_Values extends CPAC_Values
10
- {
11
- /**
12
- * Constructor
13
- *
14
- * @since 1.4.4
15
- */
16
- function __construct()
17
- {
18
- parent::__construct();
19
-
20
- add_filter( 'manage_users_custom_column', array( $this, 'manage_users_column_value'), 10, 3 );
21
- }
22
-
23
- /**
24
- * Manage custom column for Users.
25
- *
26
- * @since 1.1
27
- */
28
- public function manage_users_column_value( $value, $column_name, $user_id )
29
- {
30
- $type = $column_name;
31
-
32
- $userdata = get_userdata( $user_id );
33
-
34
- if ( ! $userdata )
35
- return false;
36
-
37
- // Check for user custom fields: column-meta-[customfieldname]
38
- if ( $this->is_column_meta($type) )
39
- $type = 'column-user-meta';
40
-
41
- // Check for post count: column-user_postcount-[posttype]
42
- if ( Codepress_Admin_Columns::get_posttype_by_postcount_column($type) )
43
- $type = 'column-user_postcount';
44
-
45
- // Hook
46
- do_action('cpac-manage-users-column', $type, $column_name, $user_id);
47
-
48
- $result = '';
49
- switch ($type) :
50
-
51
- // user id
52
- case "column-user_id" :
53
- $result = $user_id;
54
- break;
55
-
56
- // first name
57
- case "column-nickname" :
58
- $result = $userdata->nickname;
59
- break;
60
-
61
- // first name
62
- case "column-first_name" :
63
- $result = $userdata->first_name;
64
- break;
65
-
66
- // last name
67
- case "column-last_name" :
68
- $result = $userdata->last_name;
69
- break;
70
-
71
- // user url
72
- case "column-user_url" :
73
- $result = $userdata->user_url;
74
- break;
75
-
76
- // user registration date
77
- case "column-user_registered" :
78
- $result = $userdata->user_registered;
79
- break;
80
-
81
- // user description
82
- case "column-user_description" :
83
- $result = $this->get_shortened_string( get_the_author_meta('user_description', $user_id), $this->excerpt_length );
84
- break;
85
-
86
- // user description
87
- case "column-user_postcount" :
88
- $post_type = Codepress_Admin_Columns::get_posttype_by_postcount_column($column_name);
89
-
90
- // get post count
91
- $count = Codepress_Admin_Columns::get_post_count( $post_type, $user_id );
92
-
93
- // set result
94
- $result = $count > 0 ? "<a href='edit.php?post_type={$post_type}&author={$user_id}'>{$count}</a>" : (string) $count;
95
- break;
96
-
97
- // user actions
98
- case "column-actions" :
99
- $result = $this->get_column_value_actions($user_id, 'users');
100
- break;
101
-
102
- // user meta data ( custom field )
103
- case "column-user-meta" :
104
- $result = $this->get_column_value_custom_field($user_id, $column_name, 'user');
105
- break;
106
-
107
- default :
108
- $result = $value;
109
-
110
- endswitch;
111
-
112
- // Filter for customizing the result output
113
- apply_filters('cpac-users-column-result', $result, $type, $column_name, $user_id);
114
-
115
- return $result;
116
- }
117
-
118
- /**
119
- * Get column value of user actions
120
- *
121
- * This part is copied from the Users List Table class
122
- *
123
- * @since 1.4.2
124
- */
125
- private function get_column_value_actions( $id )
126
- {
127
- $actions = array();
128
-
129
- $user_object = new WP_User( $id );
130
- $screen = get_current_screen();
131
-
132
- if ( 'site-users-network' == $screen->id )
133
- $url = "site-users.php?id={$this->site_id}&amp;";
134
- else
135
- $url = 'users.php?';
136
-
137
- if ( get_current_user_id() == $user_object->ID ) {
138
- $edit_link = 'profile.php';
139
- } else {
140
- $edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( stripslashes( $_SERVER['REQUEST_URI'] ) ), "user-edit.php?user_id=$user_object->ID" ) );
141
- }
142
-
143
- if ( current_user_can( 'edit_user', $user_object->ID ) ) {
144
- $edit = "<strong><a href=\"$edit_link\">$user_object->user_login</a></strong><br />";
145
- $actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>';
146
- } else {
147
- $edit = "<strong>$user_object->user_login</strong><br />";
148
- }
149
-
150
- if ( !is_multisite() && get_current_user_id() != $user_object->ID && current_user_can( 'delete_user', $user_object->ID ) )
151
- $actions['delete'] = "<a class='submitdelete' href='" . wp_nonce_url( "users.php?action=delete&amp;user=$user_object->ID", 'bulk-users' ) . "'>" . __( 'Delete' ) . "</a>";
152
- if ( is_multisite() && get_current_user_id() != $user_object->ID && current_user_can( 'remove_user', $user_object->ID ) )
153
- $actions['remove'] = "<a class='submitdelete' href='" . wp_nonce_url( $url."action=remove&amp;user=$user_object->ID", 'bulk-users' ) . "'>" . __( 'Remove' ) . "</a>";
154
-
155
- return implode(' | ', $actions);
156
- }
157
- }
158
-
159
  ?>
1
+ <?php
2
+
3
+ /**
4
+ * CPAC_Users_Values Class
5
+ *
6
+ * @since 1.4.4
7
+ *
8
+ */
9
+ class CPAC_Users_Values extends CPAC_Values
10
+ {
11
+ /**
12
+ * Constructor
13
+ *
14
+ * @since 1.4.4
15
+ */
16
+ function __construct()
17
+ {
18
+ parent::__construct();
19
+
20
+ add_filter( 'manage_users_custom_column', array( $this, 'manage_users_column_value'), 10, 3 );
21
+ }
22
+
23
+ /**
24
+ * Manage custom column for Users.
25
+ *
26
+ * @since 1.1
27
+ */
28
+ public function manage_users_column_value( $value, $column_name, $user_id )
29
+ {
30
+ $type = $column_name;
31
+
32
+ $userdata = get_userdata( $user_id );
33
+
34
+ if ( ! $userdata )
35
+ return false;
36
+
37
+ // Check for user custom fields: column-meta-[customfieldname]
38
+ if ( $this->is_column_meta($type) )
39
+ $type = 'column-user-meta';
40
+
41
+ // Check for post count: column-user_postcount-[posttype]
42
+ if ( Codepress_Admin_Columns::get_posttype_by_postcount_column($type) )
43
+ $type = 'column-user_postcount';
44
+
45
+ // Hook
46
+ do_action('cpac-manage-users-column', $type, $column_name, $user_id);
47
+
48
+ $result = '';
49
+ switch ($type) :
50
+
51
+ // user id
52
+ case "column-user_id" :
53
+ $result = $user_id;
54
+ break;
55
+
56
+ // first name
57
+ case "column-nickname" :
58
+ $result = $userdata->nickname;
59
+ break;
60
+
61
+ // first name
62
+ case "column-first_name" :
63
+ $result = $userdata->first_name;
64
+ break;
65
+
66
+ // last name
67
+ case "column-last_name" :
68
+ $result = $userdata->last_name;
69
+ break;
70
+
71
+ // user url
72
+ case "column-user_url" :
73
+ $result = $userdata->user_url;
74
+ break;
75
+
76
+ // user registration date
77
+ case "column-user_registered" :
78
+ $result = $userdata->user_registered;
79
+ break;
80
+
81
+ // user description
82
+ case "column-user_description" :
83
+ $result = $this->get_shortened_string( get_the_author_meta('user_description', $user_id), $this->excerpt_length );
84
+ break;
85
+
86
+ // user description
87
+ case "column-user_postcount" :
88
+ $post_type = Codepress_Admin_Columns::get_posttype_by_postcount_column($column_name);
89
+
90
+ // get post count
91
+ $count = Codepress_Admin_Columns::get_post_count( $post_type, $user_id );
92
+
93
+ // set result
94
+ $result = $count > 0 ? "<a href='edit.php?post_type={$post_type}&author={$user_id}'>{$count}</a>" : (string) $count;
95
+ break;
96
+
97
+ // user actions
98
+ case "column-actions" :
99
+ $result = $this->get_column_value_actions($user_id, 'users');
100
+ break;
101
+
102
+ // user meta data ( custom field )
103
+ case "column-user-meta" :
104
+ $result = $this->get_column_value_custom_field($user_id, $column_name, 'user');
105
+ break;
106
+
107
+ default :
108
+ $result = $value;
109
+
110
+ endswitch;
111
+
112
+ // Filter for customizing the result output
113
+ apply_filters('cpac-users-column-result', $result, $type, $column_name, $user_id);
114
+
115
+ return $result;
116
+ }
117
+
118
+ /**
119
+ * Get column value of user actions
120
+ *
121
+ * This part is copied from the Users List Table class
122
+ *
123
+ * @since 1.4.2
124
+ */
125
+ private function get_column_value_actions( $id )
126
+ {
127
+ $actions = array();
128
+
129
+ $user_object = new WP_User( $id );
130
+ $screen = get_current_screen();
131
+
132
+ if ( 'site-users-network' == $screen->id )
133
+ $url = "site-users.php?id={$this->site_id}&amp;";
134
+ else
135
+ $url = 'users.php?';
136
+
137
+ if ( get_current_user_id() == $user_object->ID ) {
138
+ $edit_link = 'profile.php';
139
+ } else {
140
+ $edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( stripslashes( $_SERVER['REQUEST_URI'] ) ), "user-edit.php?user_id=$user_object->ID" ) );
141
+ }
142
+
143
+ if ( current_user_can( 'edit_user', $user_object->ID ) ) {
144
+ $edit = "<strong><a href=\"$edit_link\">$user_object->user_login</a></strong><br />";
145
+ $actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>';
146
+ } else {
147
+ $edit = "<strong>$user_object->user_login</strong><br />";
148
+ }
149
+
150
+ if ( !is_multisite() && get_current_user_id() != $user_object->ID && current_user_can( 'delete_user', $user_object->ID ) )
151
+ $actions['delete'] = "<a class='submitdelete' href='" . wp_nonce_url( "users.php?action=delete&amp;user=$user_object->ID", 'bulk-users' ) . "'>" . __( 'Delete' ) . "</a>";
152
+ if ( is_multisite() && get_current_user_id() != $user_object->ID && current_user_can( 'remove_user', $user_object->ID ) )
153
+ $actions['remove'] = "<a class='submitdelete' href='" . wp_nonce_url( $url."action=remove&amp;user=$user_object->ID", 'bulk-users' ) . "'>" . __( 'Remove' ) . "</a>";
154
+
155
+ return implode(' | ', $actions);
156
+ }
157
+ }
158
+
159
  ?>
codepress-admin-columns.php CHANGED
@@ -1,2610 +1,2671 @@
1
- <?php
2
- /*
3
-
4
- Plugin Name: Codepress Admin Columns
5
- Version: 1.4.6.4
6
- Description: Customise columns on the administration screens for post(types), pages, media, comments, links and users with an easy to use drag-and-drop interface.
7
- Author: Codepress
8
- Author URI: http://www.codepress.nl
9
- Plugin URI: http://www.codepress.nl/plugins/codepress-admin-columns/
10
- Text Domain: codepress-admin-columns
11
- Domain Path: /languages
12
- License: GPLv2
13
-
14
- Copyright 2011-2012 Codepress info@codepress.nl
15
-
16
- This program is free software; you can redistribute it and/or modify
17
- it under the terms of the GNU General Public License version 2 as published by
18
- the Free Software Foundation.
19
-
20
- This program is distributed in the hope that it will be useful,
21
- but WITHOUT ANY WARRANTY; without even the implied warranty of
22
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
- GNU General Public License for more details.
24
-
25
- You should have received a copy of the GNU General Public License
26
- along with this program; if not, write to the Free Software
27
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28
- */
29
-
30
- define( 'CPAC_VERSION', '1.4.6.4' );
31
- define( 'CPAC_TEXTDOMAIN', 'codepress-admin-columns' );
32
- define( 'CPAC_SLUG', 'codepress-admin-columns' );
33
- define( 'CPAC_URL', plugins_url('', __FILE__) );
34
-
35
- // only run plugin in the admin interface
36
- if ( !is_admin() )
37
- return false;
38
-
39
- /**
40
- * Dependencies
41
- *
42
- * @since 1.3
43
- */
44
- require_once dirname( __FILE__ ) . '/classes/utility.php';
45
- require_once dirname( __FILE__ ) . '/classes/sortable.php';
46
- require_once dirname( __FILE__ ) . '/classes/values.php';
47
- require_once dirname( __FILE__ ) . '/classes/values/posts.php';
48
- require_once dirname( __FILE__ ) . '/classes/values/users.php';
49
- require_once dirname( __FILE__ ) . '/classes/values/media.php';
50
- require_once dirname( __FILE__ ) . '/classes/values/link.php';
51
- require_once dirname( __FILE__ ) . '/classes/values/comments.php';
52
-
53
- /**
54
- * Codepress Admin Columns Class
55
- *
56
- * @since 1.0
57
- *
58
- */
59
- class Codepress_Admin_Columns
60
- {
61
- private $post_types,
62
- $codepress_url,
63
- $wordpress_url,
64
- $api_url,
65
- $admin_page,
66
- $use_hidden_custom_fields;
67
-
68
- /**
69
- * Constructor
70
- *
71
- * @since 1.0
72
- */
73
- function __construct()
74
- {
75
- $this->api_url = 'http://www.codepress.nl/';
76
-
77
- // wp is loaded
78
- add_action( 'wp_loaded', array( $this, 'init') );
79
- }
80
-
81
- /**
82
- * Initialize plugin.
83
- *
84
- * Loading sequence is determined and intialized.
85
- *
86
- * @since 1.0
87
- */
88
- public function init()
89
- {
90
- // vars
91
- $this->post_types = self::get_post_types();
92
-
93
- // set
94
- $this->codepress_url = 'http://www.codepress.nl/plugins/codepress-admin-columns';
95
- $this->plugins_url = 'http://wordpress.org/extend/plugins/codepress-admin-columns/';
96
- $this->wordpress_url = 'http://wordpress.org/tags/codepress-admin-columns';
97
-
98
- // enable the use of custom hidden fields
99
- $this->use_hidden_custom_fields = apply_filters('cpac_use_hidden_custom_fields', false);
100
-
101
- // translations
102
- load_plugin_textdomain( CPAC_TEXTDOMAIN, false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
103
-
104
- // register settings
105
- add_action( 'admin_menu', array( $this, 'settings_menu') );
106
- add_action( 'admin_init', array( $this, 'register_settings') );
107
-
108
- // styling & scripts
109
- add_action( 'admin_enqueue_scripts' , array( $this, 'column_styles') );
110
- add_filter( 'admin_body_class', array( $this, 'admin_class' ) );
111
- add_action( 'admin_head', array( $this, 'admin_css') );
112
-
113
- // register columns
114
- add_action( 'admin_init', array( $this, 'register_columns_headings' ) );
115
- add_action( 'admin_init', array( $this, 'register_columns_values' ) );
116
-
117
- // action ajax
118
- add_action( 'wp_ajax_cpac_addon_activation', array( $this, 'ajax_activation'));
119
-
120
- // handle requests gets a low priority so it will trigger when all other plugins have loaded their columns
121
- add_action( 'admin_init', array( $this, 'handle_requests' ), 1000 );
122
-
123
- // filters
124
- add_filter( 'plugin_action_links', array( $this, 'add_settings_link'), 1, 2);
125
- }
126
-
127
- /**
128
- * Admin Menu.
129
- *
130
- * Create the admin menu link for the settings page.
131
- *
132
- * @since 1.0
133
- */
134
- public function settings_menu()
135
- {
136
- $page = add_options_page(
137
- // Page title
138
- esc_html__( 'Admin Columns Settings', CPAC_TEXTDOMAIN ),
139
- // Menu Title
140
- esc_html__( 'Admin Columns', CPAC_TEXTDOMAIN ),
141
- // Capability
142
- 'manage_options',
143
- // Menu slug
144
- CPAC_SLUG,
145
- // Callback
146
- array( $this, 'plugin_settings_page')
147
- );
148
-
149
- // set admin page
150
- $this->admin_page = $page;
151
-
152
- // settings page specific styles and scripts
153
- add_action( "admin_print_styles-$page", array( $this, 'admin_styles') );
154
- add_action( "admin_print_scripts-$page", array( $this, 'admin_scripts') );
155
-
156
- // add help tabs
157
- add_action("load-$page", array( $this, 'help_tabs'));
158
- }
159
-
160
- /**
161
- * Add Settings link to plugin page
162
- *
163
- * @since 1.0
164
- */
165
- function add_settings_link( $links, $file )
166
- {
167
- if ( $file != plugin_basename( __FILE__ ))
168
- return $links;
169
-
170
- array_unshift($links, '<a href="' . admin_url("admin.php") . '?page=' . CPAC_SLUG . '">' . __( 'Settings' ) . '</a>');
171
- return $links;
172
- }
173
-
174
- /**
175
- * Register Column Values
176
- *
177
- * initializes each Class per type
178
- *
179
- * @since 1.0
180
- */
181
- public function register_columns_values()
182
- {
183
- new CPAC_Posts_Values();
184
- new CPAC_Link_Values();
185
- new CPAC_Media_Values();
186
- new CPAC_Users_Values();
187
- new CPAC_Comments_Values();
188
- }
189
- /**
190
- * Register Columns Headings
191
- *
192
- * apply_filters location in includes/screen.php
193
- *
194
- * @since 1.0
195
- */
196
- public function register_columns_headings()
197
- {
198
- /** Posts */
199
- foreach ( $this->post_types as $post_type ) {
200
-
201
- // register column per post type
202
- add_filter("manage_edit-{$post_type}_columns", array($this, 'callback_add_posts_column_headings'));
203
- }
204
-
205
- /** Users */
206
- add_filter( "manage_users_columns", array($this, 'callback_add_users_column_headings'), 9);
207
- // give higher priority, so it will load just before other plugins to prevent conflicts
208
-
209
- /** Media */
210
- add_filter( "manage_upload_columns", array($this, 'callback_add_media_column_headings'));
211
-
212
- /** Links */
213
- add_filter( "manage_link-manager_columns", array($this, 'callback_add_links_column_headings'));
214
-
215
- /** Comments */
216
- add_filter( "manage_edit-comments_columns", array($this, 'callback_add_comments_column_headings'));
217
- }
218
-
219
- /**
220
- * Callback add Posts Column
221
- *
222
- * @since 1.0
223
- */
224
- public function callback_add_posts_column_headings($columns)
225
- {
226
- return $this->add_columns_headings( get_post_type(), $columns);
227
- }
228
-
229
- /**
230
- * Callback add Users column
231
- *
232
- * @since 1.1
233
- */
234
- public function callback_add_users_column_headings($columns)
235
- {
236
- return $this->add_columns_headings('wp-users', $columns);
237
- }
238
-
239
- /**
240
- * Callback add Media column
241
- *
242
- * @since 1.3
243
- */
244
- public function callback_add_media_column_headings($columns)
245
- {
246
- return $this->add_columns_headings('wp-media', $columns);
247
- }
248
-
249
- /**
250
- * Callback add Links column
251
- *
252
- * @since 1.3.1
253
- */
254
- public function callback_add_links_column_headings($columns)
255
- {
256
- return $this->add_columns_headings('wp-links', $columns);
257
- }
258
-
259
- /**
260
- * Callback add Comments column
261
- *
262
- * @since 1.3.1
263
- */
264
- public function callback_add_comments_column_headings($columns)
265
- {
266
- return $this->add_columns_headings('wp-comments', $columns);
267
- }
268
-
269
- /**
270
- * Add managed columns by Type
271
- *
272
- * @since 1.1
273
- */
274
- protected function add_columns_headings( $type, $columns )
275
- {
276
- // only get stored columns.. the rest we don't need
277
- $db_columns = self::get_stored_columns($type);
278
-
279
- if ( !$db_columns )
280
- return $columns;
281
-
282
- // filter already loaded columns by plugins
283
- $set_columns = $this->filter_preset_columns( $type, $columns );
284
-
285
- // loop through columns
286
- foreach ( $db_columns as $id => $values ) {
287
- // is active
288
- if ( isset($values['state']) && $values['state'] == 'on' ){
289
-
290
- // register format
291
- $set_columns[$id] = $values['label'];
292
- }
293
- }
294
-
295
- return $set_columns;
296
- }
297
-
298
- /**
299
- * Filter preset columns. These columns apply either for every post or set by a plugin.
300
- *
301
- * @since 1.0
302
- */
303
- private function filter_preset_columns( $type, $columns )
304
- {
305
- $options = get_option('cpac_options_default');
306
-
307
- if ( !$options )
308
- return $columns;
309
-
310
- // we use the wp default columns for filtering...
311
- $stored_wp_default_columns = $options[$type];
312
-
313
- // ... the ones that are set by plugins, theme functions and such.
314
- $dif_columns = array_diff(array_keys($columns), array_keys($stored_wp_default_columns));
315
-
316
- // we add those to the columns
317
- $pre_columns = array();
318
- if ( $dif_columns ) {
319
- foreach ( $dif_columns as $column ) {
320
- $pre_columns[$column] = $columns[$column];
321
- }
322
- }
323
-
324
- return $pre_columns;
325
- }
326
-
327
- /**
328
- * Get a list of Column options per post type
329
- *
330
- * @since 1.0
331
- */
332
- private function get_column_boxes($type)
333
- {
334
- // merge all columns
335
- $display_columns = $this->get_merged_columns($type);
336
-
337
- // define
338
- $list = '';
339
-
340
- // loop throught the active columns
341
- if ( $display_columns ) {
342
- foreach ( $display_columns as $id => $values ) {
343
-
344
- // add items to the list
345
- $list .= $this->get_box($type, $id, $values);
346
-
347
- }
348
- }
349
-
350
- // custom field button
351
- $button_add_column = '';
352
- if ( $this->get_meta_by_type($type) )
353
- $button_add_column = "<a href='javacript:;' class='cpac-add-customfield-column button'>+ " . __('Add Custom Field Column', CPAC_TEXTDOMAIN) . "</a>";
354
-
355
- return "
356
- <div class='cpac-box'>
357
- <ul class='cpac-option-list'>
358
- {$list}
359
- </ul>
360
- {$button_add_column}
361
- <div class='cpac-reorder-msg'>" . __('drag and drop to reorder', CPAC_TEXTDOMAIN) . "</div>
362
- </div>
363
- ";
364
- }
365
-
366
- /**
367
- * Get merged columns
368
- *
369
- * @since 1.0
370
- */
371
- protected function get_merged_columns( $type )
372
- {
373
- /** Comments */
374
- if ( $type == 'wp-comments' ) {
375
- $wp_default_columns = $this->get_wp_default_comments_columns();
376
- $wp_custom_columns = $this->get_custom_comments_columns();
377
- }
378
-
379
- /** Links */
380
- elseif ( $type == 'wp-links' ) {
381
- $wp_default_columns = $this->get_wp_default_links_columns();
382
- $wp_custom_columns = $this->get_custom_links_columns();
383
- }
384
-
385
- /** Users */
386
- elseif ( $type == 'wp-users' ) {
387
- $wp_default_columns = $this->get_wp_default_users_columns();
388
- $wp_custom_columns = $this->get_custom_users_columns();
389
- }
390
-
391
- /** Media */
392
- elseif ( $type == 'wp-media' ) {
393
- $wp_default_columns = $this->get_wp_default_media_columns();
394
- $wp_custom_columns = $this->get_custom_media_columns();
395
- }
396
-
397
- /** Posts */
398
- else {
399
- $wp_default_columns = $this->get_wp_default_posts_columns($type);
400
- $wp_custom_columns = $this->get_custom_posts_columns($type);
401
- }
402
-
403
- // merge columns
404
- $display_columns = $this->parse_columns($wp_custom_columns, $wp_default_columns, $type);
405
-
406
- return $display_columns;
407
- }
408
-
409
- /**
410
- * Merge the default columns (set by WordPress) and the added custom columns (set by plugins, theme etc.)
411
- *
412
- * @since 1.3.3
413
- */
414
- function parse_columns($wp_custom_columns, $wp_default_columns, $type)
415
- {
416
- // merge columns
417
- $default_columns = wp_parse_args($wp_custom_columns, $wp_default_columns);
418
-
419
- //get saved database columns
420
- $db_columns = self::get_stored_columns($type);
421
- if ( $db_columns ) {
422
-
423
- // let's remove any unavailable columns.. such as disabled plugins
424
- $db_columns = $this->remove_unavailable_columns($db_columns, $default_columns);
425
-
426
- // loop throught the active columns
427
- foreach ( $db_columns as $id => $values ) {
428
-
429
- // get column meta options from custom columns
430
- if ( $this->is_column_meta($id) && !empty($wp_custom_columns['column-meta-1']['options']) ) {
431
- $db_columns[$id]['options'] = $wp_custom_columns['column-meta-1']['options'];
432
- }
433
-
434
- // add static options
435
- elseif ( isset($default_columns[$id]['options']) )
436
- $db_columns[$id]['options'] = $default_columns[$id]['options'];
437
-
438
- unset($default_columns[$id]);
439
- }
440
- }
441
-
442
- // merge all
443
- return wp_parse_args($db_columns, $default_columns);
444
- }
445
-
446
- /**
447
- * Remove deactivated (plugin) columns
448
- *
449
- * This will remove any columns that have been stored, but are no longer available. This happends
450
- * when plugins are deactivated or when they are removed from the theme functions.
451
- *
452
- * @since 1.2
453
- */
454
- private function remove_unavailable_columns( array $db_columns, array $default_columns)
455
- {
456
- // check or differences
457
- $diff = array_diff( array_keys($db_columns), array_keys($default_columns) );
458
-
459
- if ( ! empty($diff) && is_array($diff) ) {
460
- foreach ( $diff as $column_name ){
461
- // make an exception for column-meta-xxx
462
- if ( ! $this->is_column_meta($column_name) ) {
463
- unset($db_columns[$column_name]);
464
- }
465
- }
466
- }
467
-
468
- return $db_columns;
469
- }
470
-
471
- /**
472
- * Get checkbox
473
- *
474
- * @since 1.0
475
- */
476
- private function get_box($type, $id, $values)
477
- {
478
- $classes = array();
479
-
480
- // set state
481
- $state = isset($values['state']) ? $values['state'] : '';
482
-
483
- // class
484
- $classes[] = "cpac-box-{$id}";
485
- if ( $state )
486
- $classes[] = 'active';
487
- if ( ! empty($values['options']['class']) )
488
- $classes[] = $values['options']['class'];
489
- $class = implode(' ', $classes);
490
-
491
- // more box options
492
- $more_options = $this->get_additional_box_options($type, $id, $values);
493
- $action = "<a class='cpac-action' href='#open'>open</a>";
494
-
495
- // type label
496
- $type_label = isset($values['options']['type_label']) ? $values['options']['type_label'] : '';
497
-
498
- // label
499
- $label = isset($values['label']) ? str_replace("'", '"', $values['label']) : '';
500
-
501
- // width
502
- $width = isset($values['width']) ? $values['width'] : 0;
503
- $width_descr = isset($values['width']) && $values['width'] > 0 ? $values['width'] . '%' : __('default', CPAC_TEXTDOMAIN);
504
-
505
- // hide box options
506
- $label_hidden = '';
507
- if ( ! empty($values['options']['hide_options']) || strpos($label, '<img') !== false ) {
508
- $label_hidden = ' style="display:none"';
509
- }
510
-
511
- $list = "
512
- <li class='{$class}'>
513
- <div class='cpac-sort-handle'></div>
514
- <div class='cpac-type-options'>
515
- <div class='cpac-checkbox'></div>
516
- <input type='hidden' class='cpac-state' name='cpac_options[columns][{$type}][{$id}][state]' value='{$state}'/>
517
- <label class='main-label'>{$values['label']}</label>
518
- </div>
519
- <div class='cpac-meta-title'>
520
- {$action}
521
- <span>{$type_label}</span>
522
- </div>
523
- <div class='cpac-type-inside'>
524
- <label for='cpac_options-{$type}-{$id}-label'{$label_hidden}>Label: </label>
525
- <input type='text' name='cpac_options[columns][{$type}][{$id}][label]' id='cpac_options-{$type}-{$id}-label' value='{$label}' class='text'{$label_hidden}/>
526
- <label for='cpac_options-{$type}-{$id}-width'>".__('Width', CPAC_TEXTDOMAIN).":</label>
527
- <input type='hidden' maxlength='4' class='input-width' name='cpac_options[columns][{$type}][{$id}][width]' id='cpac_options-{$type}-{$id}-width' value='{$width}' />
528
- <div class='description width-decription' title='".__('default', CPAC_TEXTDOMAIN)."'>{$width_descr}</div>
529
- <div class='input-width-range'></div>
530
- <br/>
531
- {$more_options}
532
- </div>
533
- </li>
534
- ";
535
-
536
- return $list;
537
- }
538
-
539
- /**
540
- * Get additional box option fields
541
- *
542
- * @since 1.0
543
- */
544
- private function get_additional_box_options($type, $id, $values)
545
- {
546
- $fields = '';
547
-
548
- // Custom Fields
549
- if( $this->is_column_meta($id) ) {
550
- $fields = $this->get_box_options_customfields($type, $id, $values);
551
- }
552
-
553
- // Author Fields
554
- if( 'column-author-name' == $id) {
555
- $fields = $this->get_box_options_author($type, $id, $values);
556
- }
557
-
558
- return $fields;
559
- }
560
-
561
- /**
562
- * Box Options: Custom Fields
563
- *
564
- * @since 1.0
565
- */
566
- private function get_box_options_customfields($type, $id, $values)
567
- {
568
- // get post meta fields
569
- $fields = $this->get_meta_by_type($type);
570
-
571
- if ( empty($fields) )
572
- return false;
573
-
574
- // set meta field options
575
- $current = ! empty($values['field']) ? $values['field'] : '' ;
576
- $field_options = '';
577
- foreach ($fields as $field) {
578
-
579
- $field_options .= sprintf
580
- (
581
- '<option value="%s"%s>%s</option>',
582
- $field,
583
- $field == $current? ' selected="selected"':'',
584
-
585
- // change label on hidden fields
586
- substr($field,0,10) == "cpachidden" ? str_replace('cpachidden','',$field) : $field
587
- );
588
- }
589
-
590
- // set meta fieldtype options
591
- $currenttype = ! empty($values['field_type']) ? $values['field_type'] : '' ;
592
- $fieldtype_options = '';
593
- $fieldtypes = array(
594
- '' => __('Default'),
595
- 'image' => __('Image'),
596
- 'library_id' => __('Media Library Icon', CPAC_TEXTDOMAIN),
597
- 'excerpt' => __('Excerpt'),
598
- 'array' => __('Multiple Values', CPAC_TEXTDOMAIN),
599
- 'numeric' => __('Numeric', CPAC_TEXTDOMAIN),
600
- 'date' => __('Date', CPAC_TEXTDOMAIN),
601
- 'title_by_id' => __('Post Title (Post ID\'s)', CPAC_TEXTDOMAIN),
602
- 'user_by_id' => __('Username (User ID\'s)', CPAC_TEXTDOMAIN),
603
- 'checkmark' => __('Checkmark (true/false)', CPAC_TEXTDOMAIN),
604
- );
605
-
606
- // add filter
607
- $fieldtypes = apply_filters('cpac-field-types', $fieldtypes );
608
-
609
- // set select options
610
- foreach ( $fieldtypes as $fkey => $fieldtype ) {
611
- $fieldtype_options .= sprintf
612
- (
613
- '<option value="%s"%s>%s</option>',
614
- $fkey,
615
- $fkey == $currenttype? ' selected="selected"':'',
616
- $fieldtype
617
- );
618
- }
619
-
620
- // before and after string
621
- $before = ! empty($values['before']) ? $values['before'] : '' ;
622
- $after = ! empty($values['after']) ? $values['after'] : '' ;
623
-
624
- if ( empty($field_options) )
625
- return false;
626
-
627
- // add remove button
628
- $remove = '<p class="remove-description description">'.__('This field can not be removed', CPAC_TEXTDOMAIN).'</p>';
629
- if ( $id != 'column-meta-1') {
630
- $remove = "
631
- <p>
632
- <a href='javascript:;' class='cpac-delete-custom-field-box'>".__('Remove')."</a>
633
- </p>
634
- ";
635
- }
636
-
637
- $inside = "
638
- <label for='cpac-{$type}-{$id}-field'>".__('Custom Field', CPAC_TEXTDOMAIN).": </label>
639
- <select name='cpac_options[columns][{$type}][{$id}][field]' id='cpac-{$type}-{$id}-field'>{$field_options}</select>
640
- <br/>
641
- <label for='cpac-{$type}-{$id}-field_type'>".__('Field Type', CPAC_TEXTDOMAIN).": </label>
642
- <select name='cpac_options[columns][{$type}][{$id}][field_type]' id='cpac-{$type}-{$id}-field_type'>{$fieldtype_options}</select>
643
- <br/>
644
- <label for='cpac-{$type}-{$id}-before'>".__('Before', CPAC_TEXTDOMAIN).": </label>
645
- <input type='text' class='cpac-before' name='cpac_options[columns][{$type}][{$id}][before]' id='cpac-{$type}-{$id}-before' value='{$before}'/>
646
- <br/>
647
- <label for='cpac-{$type}-{$id}-after'>".__('After', CPAC_TEXTDOMAIN).": </label>
648
- <input type='text' class='cpac-after' name='cpac_options[columns][{$type}][{$id}][after]' id='cpac-{$type}-{$id}-after' value='{$after}'/>
649
- <br/>
650
- {$remove}
651
- ";
652
-
653
- return $inside;
654
- }
655
-
656
- /**
657
- * Box Options: Custom Fields
658
- *
659
- * @since 1.0
660
- */
661
- private function get_box_options_author($type, $id, $values)
662
- {
663
- $options = '';
664
- $author_types = array(
665
- 'display_name' => __('Display Name', CPAC_TEXTDOMAIN),
666
- 'first_name' => __('First Name', CPAC_TEXTDOMAIN),
667
- 'last_name' => __('Last Name', CPAC_TEXTDOMAIN),
668
- 'first_last_name' => __('First &amp; Last Name', CPAC_TEXTDOMAIN),
669
- 'nickname' => __('Nickname', CPAC_TEXTDOMAIN),
670
- 'username' => __('Username', CPAC_TEXTDOMAIN),
671
- 'email' => __('Email', CPAC_TEXTDOMAIN),
672
- 'userid' => __('User ID', CPAC_TEXTDOMAIN)
673
- );
674
- $currentname = ! empty($values['display_as']) ? $values['display_as'] : '' ;
675
- foreach ( $author_types as $k => $name ) {
676
- $selected = selected( $k, $currentname, false);
677
- $options .= "<option value='{$k}' {$selected}>{$name}</option>";
678
- }
679
-
680
- $inside = "
681
- <label for='cpac-{$type}-{$id}-display_as'>".__('Display name as', CPAC_TEXTDOMAIN).": </label>
682
- <select name='cpac_options[columns][{$type}][{$id}][display_as]' id='cpac-{$type}-{$id}-display_as'>
683
- {$options}
684
- </select>
685
- ";
686
-
687
- return $inside;
688
- }
689
-
690
- /**
691
- * Get post meta fields by type; post(types) or users.
692
- *
693
- * @since 1.0
694
- */
695
- private function get_meta_by_type($type = 'post')
696
- {
697
- global $wpdb;
698
-
699
- /** Comments */
700
- if ( $type == 'wp-comments') {
701
- $sql = "SELECT DISTINCT meta_key FROM {$wpdb->commentmeta} ORDER BY 1";
702
- }
703
-
704
- /** Users */
705
- elseif ( $type == 'wp-users') {
706
- $sql = "SELECT DISTINCT meta_key FROM {$wpdb->usermeta} ORDER BY 1";
707
- }
708
-
709
- /** Media */
710
- elseif ( $type == 'wp-media') {
711
- $sql = $wpdb->prepare( "SELECT DISTINCT meta_key FROM {$wpdb->postmeta} pm JOIN {$wpdb->posts} p ON pm.post_id = p.ID WHERE p.post_type = 'attachment' ORDER BY 1");
712
- }
713
-
714
- /** Posts */
715
- else {
716
- $sql = $wpdb->prepare( "SELECT DISTINCT meta_key FROM {$wpdb->postmeta} pm JOIN {$wpdb->posts} p ON pm.post_id = p.ID WHERE p.post_type = %s ORDER BY 1", $type);
717
- }
718
-
719
- // run sql
720
- $fields = $wpdb->get_results($sql, ARRAY_N);
721
-
722
- // filter out hidden meta fields
723
- $meta_fields = array();
724
- if ( $fields ) {
725
- foreach ($fields as $field) {
726
-
727
- // give hidden fields a prefix for identifaction
728
- if ( $this->use_hidden_custom_fields && substr($field[0],0,1) == "_") {
729
- $meta_fields[] = 'cpachidden'.$field[0];
730
- }
731
-
732
- // non hidden fields are saved as is
733
- elseif ( substr($field[0],0,1) != "_" ) {
734
- $meta_fields[] = $field[0];
735
- }
736
- }
737
- }
738
-
739
- if ( !empty($meta_fields) )
740
- return $meta_fields;
741
-
742
- return false;
743
- }
744
-
745
- /**
746
- * Register admin scripts
747
- *
748
- * @since 1.0
749
- */
750
- public function admin_scripts()
751
- {
752
- wp_enqueue_script( 'jquery-ui-slider' );
753
- wp_enqueue_script( 'cpac-qtip2', CPAC_URL.'/assets/js/jquery.qtip.js', array('jquery'), CPAC_VERSION );
754
- wp_enqueue_script( 'cpac-admin', CPAC_URL.'/assets/js/admin-column.js', array('jquery', 'dashboard', 'jquery-ui-sortable'), CPAC_VERSION );
755
- }
756
-
757
- /**
758
- * Get column types
759
- *
760
- * @since 1.1
761
- */
762
- private function get_types()
763
- {
764
- $types = $this->post_types;
765
- $types['wp-users'] = 'wp-users';
766
- $types['wp-media'] = 'wp-media';
767
- $types['wp-links'] = 'wp-links';
768
- $types['wp-comments'] = 'wp-comments';
769
-
770
- return $types;
771
- }
772
-
773
- /**
774
- * Get post types
775
- *
776
- * @since 1.0
777
- */
778
- public static function get_post_types()
779
- {
780
- $post_types = get_post_types(array(
781
- '_builtin' => false
782
- ));
783
- $post_types['post'] = 'post';
784
- $post_types['page'] = 'page';
785
-
786
- return apply_filters('cpac-get-post-types', $post_types);
787
- }
788
-
789
- /**
790
- * Register admin css
791
- *
792
- * @since 1.0
793
- */
794
- public function admin_styles()
795
- {
796
- wp_enqueue_style( 'jquery-ui-lightness', CPAC_URL.'/assets/ui-theme/jquery-ui-1.8.18.custom.css', array(), CPAC_VERSION, 'all' );
797
- wp_enqueue_style( 'cpac-admin', CPAC_URL.'/assets/css/admin-column.css', array(), CPAC_VERSION, 'all' );
798
- }
799
-
800
- /**
801
- * Register column css
802
- *
803
- * @since 1.0
804
- */
805
- public function column_styles()
806
- {
807
- wp_enqueue_style( 'cpac-columns', CPAC_URL.'/assets/css/column.css', array(), CPAC_VERSION, 'all' );
808
- }
809
-
810
- /**
811
- * Register plugin options
812
- *
813
- * @since 1.0
814
- */
815
- public function register_settings()
816
- {
817
- // If we have no options in the database, let's add them now.
818
- if ( false === get_option('cpac_options') )
819
- add_option( 'cpac_options', array($this, 'get_default_plugin_options') );
820
-
821
- register_setting( 'cpac-settings-group', 'cpac_options', array($this, 'options_callback') );
822
- }
823
-
824
- /**
825
- * Returns the default plugin options.
826
- *
827
- * @since 1.0
828
- */
829
- public function get_default_plugin_options()
830
- {
831
- $default_plugin_options = array(
832
- 'post' => '',
833
- 'page' => ''
834
- );
835
- return apply_filters( 'cpac_default_plugin_options', $default_plugin_options );
836
- }
837
-
838
- /**
839
- * Optional callback.
840
- *
841
- * @since 1.0
842
- */
843
- public function options_callback($options)
844
- {
845
- return $options;
846
- }
847
-
848
- /**
849
- * Handle requests.
850
- *
851
- * @since 1.0
852
- */
853
- public function handle_requests()
854
- {
855
- // settings updated
856
- if ( ! empty($_REQUEST['settings-updated']) )
857
- $this->store_wp_default_columns();
858
-
859
- // restore defaults
860
- if ( ! empty($_REQUEST['cpac-restore-defaults']) )
861
- $this->restore_defaults();
862
-
863
- }
864
-
865
- /**
866
- * Stores WP default columns
867
- *
868
- * This will store columns that are set by WordPress core or theme
869
- *
870
- * @since 1.2
871
- */
872
- private function store_wp_default_columns()
873
- {
874
- // stores the default columns that are set by WP or theme.
875
- $wp_default_columns = array();
876
-
877
- // Posts
878
- foreach ( $this->post_types as $post_type ) {
879
- $wp_default_columns[$post_type] = $this->get_wp_default_posts_columns($post_type);
880
- }
881
-
882
- // Users
883
- $wp_default_columns['wp-users'] = $this->get_wp_default_users_columns();
884
-
885
- // Media
886
- $wp_default_columns['wp-media'] = $this->get_wp_default_media_columns();
887
-
888
- // Links
889
- $wp_default_columns['wp-links'] = $this->get_wp_default_links_columns();
890
-
891
- // Comments
892
- $wp_default_columns['wp-comments'] = $this->get_wp_default_comments_columns();
893
-
894
- update_option( 'cpac_options_default', $wp_default_columns );
895
- }
896
-
897
- /**
898
- * Restore defaults
899
- *
900
- * @since 1.0
901
- */
902
- private function restore_defaults()
903
- {
904
- delete_option( 'cpac_options' );
905
- delete_option( 'cpac_options_default' );
906
- }
907
-
908
- /**
909
- * Get author field by nametype
910
- *
911
- * Used by posts and sortable
912
- *
913
- * @since 1.4.6.1
914
- */
915
- public function get_author_field_by_nametype( $nametype, $user_id)
916
- {
917
- $userdata = get_userdata( $user_id );
918
-
919
- switch ( $nametype ) :
920
-
921
- case "display_name" :
922
- $name = $userdata->display_name;
923
- break;
924
-
925
- case "first_name" :
926
- $name = $userdata->first_name;
927
- break;
928
-
929
- case "last_name" :
930
- $name = $userdata->last_name;
931
- break;
932
-
933
- case "first_last_name" :
934
- $first = !empty($userdata->first_name) ? $userdata->first_name : '';
935
- $last = !empty($userdata->last_name) ? " {$userdata->last_name}" : '';
936
- $name = $first.$last;
937
- break;
938
-
939
- case "nickname" :
940
- $name = $userdata->nickname;
941
- break;
942
-
943
- case "username" :
944
- $name = $userdata->user_login;
945
- break;
946
-
947
- case "email" :
948
- $name = $userdata->user_email;
949
- break;
950
-
951
- case "userid" :
952
- $name = $userdata->ID;
953
- break;
954
-
955
- default :
956
- $name = $userdata->display_name;
957
-
958
- endswitch;
959
-
960
- return $name;
961
- }
962
-
963
- /**
964
- * Get WP default supported admin columns per post type.
965
- *
966
- * @since 1.0
967
- */
968
- private function get_wp_default_posts_columns($post_type = 'post')
969
- {
970
- // some plugins depend on settings the $_GET['post_type'] variable such as ALL in One SEO
971
- $_GET['post_type'] = $post_type;
972
-
973
- // for 3rd party plugin support we will call load-edit.php so all the
974
- // additional columns that are set by them will be avaible for us
975
- do_action('load-edit.php');
976
-
977
- // some plugins directly hook into get_column_headers, such as woocommerce
978
- $columns = get_column_headers( 'edit-'.$post_type );
979
-
980
- // get default columns
981
- if ( empty($columns) ) {
982
-
983
- // deprecated as of wp3.3
984
- if ( file_exists(ABSPATH . 'wp-admin/includes/template.php') )
985
- require_once(ABSPATH . 'wp-admin/includes/template.php');
986
-
987
- // introduced since wp3.3
988
- if ( file_exists(ABSPATH . 'wp-admin/includes/screen.php') )
989
- require_once(ABSPATH . 'wp-admin/includes/screen.php');
990
-
991
- // used for getting columns
992
- if ( file_exists(ABSPATH . 'wp-admin/includes/class-wp-list-table.php') )
993
- require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
994
- if ( file_exists(ABSPATH . 'wp-admin/includes/class-wp-posts-list-table.php') )
995
- require_once(ABSPATH . 'wp-admin/includes/class-wp-posts-list-table.php');
996
-
997
- // we need to change the current screen
998
- global $current_screen;
999
-
1000
- // save original
1001
- $org_current_screen = $current_screen;
1002
-
1003
- // prevent php warning
1004
- if ( !isset($current_screen) ) $current_screen = new stdClass;
1005
-
1006
- // overwrite current_screen global with our post type of choose...
1007
- $current_screen->post_type = $post_type;
1008
-
1009
- // ...so we can get its columns
1010
- $columns = WP_Posts_List_Table::get_columns();
1011
-
1012
- // reset current screen
1013
- $current_screen = $org_current_screen;
1014
-
1015
- }
1016
-
1017
- if ( empty ( $columns ) )
1018
- return false;
1019
-
1020
- // change to uniform format
1021
- $columns = $this->get_uniform_format($columns);
1022
-
1023
- // add sorting to some of the default links columns
1024
- $columns = $this->set_sorting_to_default_posts_columns($columns);
1025
-
1026
- return $columns;
1027
- }
1028
-
1029
- /**
1030
- * Add Sorting to WP default Posts columns
1031
- *
1032
- * @since 1.4.5
1033
- */
1034
- private function set_sorting_to_default_posts_columns($columns)
1035
- {
1036
- // categories
1037
- if ( !empty($columns['categories']) ) {
1038
- $columns['categories']['options']['sortorder'] = 'on';
1039
- }
1040
- // tags
1041
- if ( !empty($columns['tags']) ) {
1042
- $columns['tags']['options']['sortorder'] = 'on';
1043
- }
1044
- return $columns;
1045
- }
1046
-
1047
- /**
1048
- * Get WP default users columns per post type.
1049
- *
1050
- * @since 1.1
1051
- */
1052
- private function get_wp_default_users_columns()
1053
- {
1054
- if ( file_exists(ABSPATH . 'wp-admin/includes/class-wp-list-table.php') )
1055
- require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
1056
- if ( file_exists(ABSPATH . 'wp-admin/includes/class-wp-users-list-table.php') )
1057
- require_once(ABSPATH . 'wp-admin/includes/class-wp-users-list-table.php');
1058
-
1059
- // turn off site users
1060
- $this->is_site_users = false;
1061
-
1062
- // get users columns
1063
- $columns = WP_Users_List_Table::get_columns();
1064
-
1065
- // change to uniform format
1066
- $columns = $this->get_uniform_format($columns);
1067
-
1068
- // add sorting to some of the default users columns
1069
- $columns = $this->set_sorting_to_default_users_columns($columns);
1070
-
1071
- return apply_filters('cpac-default-users-columns', $columns);
1072
- }
1073
-
1074
- /**
1075
- * Add Sorting to WP default Users columns
1076
- *
1077
- * @since 1.4
1078
- */
1079
- private function set_sorting_to_default_users_columns($columns)
1080
- {
1081
- // Comment
1082
- if ( !empty($columns['role']) ) {
1083
- $columns['role']['options']['sortorder'] = 'on';
1084
- }
1085
- return $columns;
1086
- }
1087
-
1088
- /**
1089
- * Get WP default media columns.
1090
- *
1091
- * @since 1.2.1
1092
- */
1093
- private function get_wp_default_media_columns()
1094
- {
1095
- // @todo could use _get_list_table('WP_Media_List_Table') ?
1096
- if ( file_exists(ABSPATH . 'wp-admin/includes/class-wp-list-table.php') )
1097
- require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
1098
- if ( file_exists(ABSPATH . 'wp-admin/includes/class-wp-media-list-table.php') )
1099
- require_once(ABSPATH . 'wp-admin/includes/class-wp-media-list-table.php');
1100
-
1101
- global $current_screen;
1102
-
1103
- // save original
1104
- $org_current_screen = $current_screen;
1105
-
1106
- // prevent php warning
1107
- if ( !isset($current_screen) ) $current_screen = new stdClass;
1108
-
1109
- // overwrite current_screen global with our media id...
1110
- $current_screen->id = 'upload';
1111
-
1112
- // init media class
1113
- $wp_media = new WP_Media_List_Table;
1114
-
1115
- // get media columns
1116
- $columns = $wp_media->get_columns();
1117
-
1118
- // reset current screen
1119
- $current_screen = $org_current_screen;
1120
-
1121
- // change to uniform format
1122
- return $this->get_uniform_format($columns);
1123
- }
1124
-
1125
- /**
1126
- * Get WP default links columns.
1127
- *
1128
- * @since 1.3.1
1129
- */
1130
- private function get_wp_default_links_columns()
1131
- {
1132
- // dependencies
1133
- if ( file_exists(ABSPATH . 'wp-admin/includes/class-wp-list-table.php') )
1134
- require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
1135
- if ( file_exists(ABSPATH . 'wp-admin/includes/class-wp-links-list-table.php') )
1136
- require_once(ABSPATH . 'wp-admin/includes/class-wp-links-list-table.php');
1137
-
1138
- // get links columns
1139
- $columns = WP_Links_List_Table::get_columns();
1140
-
1141
- // change to uniform format
1142
- $columns = $this->get_uniform_format($columns);
1143
-
1144
- // add sorting to some of the default links columns
1145
- $columns = $this->set_sorting_to_default_links_columns($columns);
1146
-
1147
- return apply_filters('cpac-default-links-columns', $columns);
1148
- }
1149
-
1150
- /**
1151
- * Add Sorting to WP default links columns
1152
- *
1153
- * @since 1.4
1154
- */
1155
- private function set_sorting_to_default_links_columns($columns)
1156
- {
1157
- // Relationship
1158
- if ( !empty($columns['rel']) ) {
1159
- $columns['rel']['options']['sortorder'] = 'on';
1160
- }
1161
- return $columns;
1162
- }
1163
-
1164
- /**
1165
- * Get WP default links columns.
1166
- *
1167
- * @since 1.3.1
1168
- */
1169
- private function get_wp_default_comments_columns()
1170
- {
1171
- // dependencies
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-comments-list-table.php') )
1175
- require_once(ABSPATH . 'wp-admin/includes/class-wp-comments-list-table.php');
1176
-
1177
- global $current_screen;
1178
-
1179
- // save original
1180
- $org_current_screen = $current_screen;
1181
-
1182
- // prevent php warning
1183
- if ( !isset($current_screen) ) $current_screen = new stdClass;
1184
-
1185
- // overwrite current_screen global with our media id...
1186
- $current_screen->id = 'edit-comments';
1187
-
1188
- // init table object
1189
- $wp_comment = new WP_Comments_List_Table;
1190
-
1191
- // get comments
1192
- $columns = $wp_comment->get_columns();
1193
-
1194
- // reset current screen
1195
- $current_screen = $org_current_screen;
1196
-
1197
- // change to uniform format
1198
- $columns = $this->get_uniform_format($columns);
1199
-
1200
- // add sorting to some of the default links columns
1201
- $columns = $this->set_sorting_to_default_comments_columns($columns);
1202
-
1203
- return apply_filters('cpac-default-comments-columns', $columns);
1204
- }
1205
-
1206
- /**
1207
- * Add Sorting to WP default comments columns
1208
- *
1209
- * @since 1.4
1210
- */
1211
- private function set_sorting_to_default_comments_columns($columns)
1212
- {
1213
- // Comment
1214
- if ( !empty($columns['comment']) ) {
1215
- $columns['comment']['options']['sortorder'] = 'on';
1216
- }
1217
- return $columns;
1218
- }
1219
-
1220
- /**
1221
- * Build uniform format for all columns
1222
- *
1223
- * @since 1.0
1224
- */
1225
- private function get_uniform_format($columns)
1226
- {
1227
- // we remove the checkbox column as an option...
1228
- if ( isset($columns['cb']) )
1229
- unset($columns['cb']);
1230
-
1231
- // change to uniform format
1232
- $uniform_columns = array();
1233
- foreach ( (array) $columns as $id => $label ) {
1234
- $hide_options = false;
1235
- $type_label = $label;
1236
-
1237
- // comment exception
1238
- if ( strpos( $label, 'comment-grey-bubble.png') ) {
1239
- $type_label = __('Comments', CPAC_TEXTDOMAIN);
1240
- $hide_options = true;
1241
- }
1242
-
1243
- // user icon exception
1244
- if ( $id == 'icon' ) {
1245
- $type_label = __('Icon', CPAC_TEXTDOMAIN);
1246
- }
1247
-
1248
- $uniform_colums[$id] = array(
1249
- 'label' => $label,
1250
- 'state' => 'on',
1251
- 'options' => array(
1252
- 'type_label' => $type_label,
1253
- 'hide_options' => $hide_options,
1254
- 'class' => 'cpac-box-wp-native',
1255
- )
1256
- );
1257
- }
1258
- return $uniform_colums;
1259
- }
1260
-
1261
- /**
1262
- * Custom posts columns
1263
- *
1264
- * @since 1.0
1265
- */
1266
- private function get_custom_posts_columns($post_type)
1267
- {
1268
- $custom_columns = array(
1269
- 'column-featured_image' => array(
1270
- 'label' => __('Featured Image', CPAC_TEXTDOMAIN)
1271
- ),
1272
- 'column-excerpt' => array(
1273
- 'label' => __('Excerpt', CPAC_TEXTDOMAIN)
1274
- ),
1275
- 'column-order' => array(
1276
- 'label' => __('Page Order', CPAC_TEXTDOMAIN)
1277
- ),
1278
- 'column-post_formats' => array(
1279
- 'label' => __('Post Format', CPAC_TEXTDOMAIN)
1280
- ),
1281
- 'column-postid' => array(
1282
- 'label' => __('ID', CPAC_TEXTDOMAIN)
1283
- ),
1284
- 'column-page-slug' => array(
1285
- 'label' => __('Slug', CPAC_TEXTDOMAIN)
1286
- ),
1287
- 'column-attachment' => array(
1288
- 'label' => __('Attachment', CPAC_TEXTDOMAIN)
1289
- ),
1290
- 'column-attachment-count' => array(
1291
- 'label' => __('No. of Attachments', CPAC_TEXTDOMAIN)
1292
- ),
1293
- 'column-roles' => array(
1294
- 'label' => __('Roles', CPAC_TEXTDOMAIN)
1295
- ),
1296
- 'column-status' => array(
1297
- 'label' => __('Status', CPAC_TEXTDOMAIN)
1298
- ),
1299
- 'column-comment-status' => array(
1300
- 'label' => __('Comment status', CPAC_TEXTDOMAIN)
1301
- ),
1302
- 'column-ping-status' => array(
1303
- 'label' => __('Ping status', CPAC_TEXTDOMAIN)
1304
- ),
1305
- 'column-actions' => array(
1306
- 'label' => __('Actions', CPAC_TEXTDOMAIN),
1307
- 'options' => array(
1308
- 'sortorder' => false
1309
- )
1310
- ),
1311
- 'column-modified' => array(
1312
- 'label' => __('Last modified', CPAC_TEXTDOMAIN)
1313
- ),
1314
- 'column-comment-count' => array(
1315
- 'label' => __('Comment count', CPAC_TEXTDOMAIN)
1316
- ),
1317
- 'column-author-name' => array(
1318
- 'label' => __('Display Author As', CPAC_TEXTDOMAIN),
1319
- 'display_as' => ''
1320
- ),
1321
- 'column-before-moretag' => array(
1322
- 'label' => __('Before More Tag', CPAC_TEXTDOMAIN)
1323
- )
1324
- );
1325
-
1326
- // Word count support
1327
- if ( post_type_supports($post_type, 'editor') ) {
1328
- $custom_columns['column-word-count'] = array(
1329
- 'label' => __('Word count', CPAC_TEXTDOMAIN)
1330
- );
1331
- }
1332
-
1333
- // Sticky support
1334
- if ( $post_type == 'post' ) {
1335
- $custom_columns['column-sticky'] = array(
1336
- 'label' => __('Sticky', CPAC_TEXTDOMAIN)
1337
- );
1338
- }
1339
-
1340
- // Order support
1341
- if ( post_type_supports($post_type, 'page-attributes') ) {
1342
- $custom_columns['column-order'] = array(
1343
- 'label' => __('Page Order', CPAC_TEXTDOMAIN),
1344
- 'options' => array(
1345
- 'type_label' => __('Order', CPAC_TEXTDOMAIN)
1346
- )
1347
- );
1348
- }
1349
-
1350
- // Page Template
1351
- if ( $post_type == 'page' ) {
1352
- $custom_columns['column-page-template'] = array(
1353
- 'label' => __('Page Template', CPAC_TEXTDOMAIN)
1354
- );
1355
- }
1356
-
1357
- // Post Formats
1358
- if ( post_type_supports($post_type, 'post-formats') ) {
1359
- $custom_columns['column-post_formats'] = array(
1360
- 'label' => __('Post Format', CPAC_TEXTDOMAIN)
1361
- );
1362
- }
1363
-
1364
- // Taxonomy support
1365
- $taxonomies = get_object_taxonomies($post_type, 'objects');
1366
- if ( $taxonomies ) {
1367
- foreach ( $taxonomies as $tax_slug => $tax ) {
1368
- if ( $tax_slug != 'post_tag' && $tax_slug != 'category' && $tax_slug != 'post_format' ) {
1369
- $custom_columns['column-taxonomy-'.$tax->name] = array(
1370
- 'label' => $tax->label,
1371
- 'show_filter' => true,
1372
- 'options' => array(
1373
- 'type_label' => __('Taxonomy', CPAC_TEXTDOMAIN)
1374
- )
1375
- );
1376
- }
1377
- }
1378
- }
1379
-
1380
- // Custom Field support
1381
- if ( $this->get_meta_by_type($post_type) ) {
1382
- $custom_columns['column-meta-1'] = array(
1383
- 'label' => __('Custom Field', CPAC_TEXTDOMAIN),
1384
- 'field' => '',
1385
- 'field_type' => '',
1386
- 'before' => '',
1387
- 'after' => '',
1388
- 'options' => array(
1389
- 'type_label' => __('Field', CPAC_TEXTDOMAIN),
1390
- 'class' => 'cpac-box-metafield'
1391
- )
1392
- );
1393
- }
1394
-
1395
- // merge with defaults
1396
- $custom_columns = $this->parse_defaults($custom_columns);
1397
-
1398
- return apply_filters('cpac-custom-posts-columns', $custom_columns);
1399
- }
1400
-
1401
- /**
1402
- * Custom users columns
1403
- *
1404
- * @since 1.1
1405
- */
1406
- private function get_custom_users_columns()
1407
- {
1408
- $custom_columns = array(
1409
- 'column-user_id' => array(
1410
- 'label' => __('User ID', CPAC_TEXTDOMAIN)
1411
- ),
1412
- 'column-nickname' => array(
1413
- 'label' => __('Nickname', CPAC_TEXTDOMAIN)
1414
- ),
1415
- 'column-first_name' => array(
1416
- 'label' => __('First name', CPAC_TEXTDOMAIN)
1417
- ),
1418
- 'column-last_name' => array(
1419
- 'label' => __('Last name', CPAC_TEXTDOMAIN)
1420
- ),
1421
- 'column-user_url' => array(
1422
- 'label' => __('Url', CPAC_TEXTDOMAIN)
1423
- ),
1424
- 'column-user_registered' => array(
1425
- 'label' => __('Registered', CPAC_TEXTDOMAIN)
1426
- ),
1427
- 'column-user_description' => array(
1428
- 'label' => __('Description', CPAC_TEXTDOMAIN)
1429
- ),
1430
- 'column-actions' => array(
1431
- 'label' => __('Actions', CPAC_TEXTDOMAIN),
1432
- 'options' => array(
1433
- 'sortorder' => false
1434
- )
1435
- ),
1436
- );
1437
-
1438
- // User total number of posts
1439
- foreach ( self::get_post_types() as $post_type ) {
1440
- $label = $this->get_plural_name($post_type);
1441
- $custom_columns['column-user_postcount-'.$post_type] = array(
1442
- 'label' => __( sprintf('No. of %s',$label), CPAC_TEXTDOMAIN),
1443
- 'options' => array(
1444
- 'type_label' => __('Postcount', CPAC_TEXTDOMAIN)
1445
- )
1446
- );
1447
- }
1448
-
1449
- // Custom Field support
1450
- $custom_columns['column-meta-1'] = array(
1451
- 'label' => __('Custom Field', CPAC_TEXTDOMAIN),
1452
- 'field' => '',
1453
- 'field_type' => '',
1454
- 'before' => '',
1455
- 'after' => '',
1456
- 'options' => array(
1457
- 'type_label' => __('Field', CPAC_TEXTDOMAIN),
1458
- 'class' => 'cpac-box-metafield'
1459
- )
1460
- );
1461
-
1462
- // merge with defaults
1463
- $custom_columns = $this->parse_defaults($custom_columns);
1464
-
1465
- return apply_filters('cpac-custom-users-columns', $custom_columns);
1466
- }
1467
-
1468
- /**
1469
- * Custom media columns
1470
- *
1471
- * @since 1.3
1472
- */
1473
- private function get_custom_media_columns()
1474
- {
1475
- $custom_columns = array(
1476
- 'column-mediaid' => array(
1477
- 'label' => __('ID', CPAC_TEXTDOMAIN)
1478
- ),
1479
- 'column-mime_type' => array(
1480
- 'label' => __('Mime type', CPAC_TEXTDOMAIN)
1481
- ),
1482
- 'column-file_name' => array(
1483
- 'label' => __('File name', CPAC_TEXTDOMAIN)
1484
- ),
1485
- 'column-dimensions' => array(
1486
- 'label' => __('Dimensions', CPAC_TEXTDOMAIN)
1487
- ),
1488
- 'column-height' => array(
1489
- 'label' => __('Height', CPAC_TEXTDOMAIN)
1490
- ),
1491
- 'column-width' => array(
1492
- 'label' => __('Width', CPAC_TEXTDOMAIN)
1493
- ),
1494
- 'column-caption' => array(
1495
- 'label' => __('Caption', CPAC_TEXTDOMAIN)
1496
- ),
1497
- 'column-description' => array(
1498
- 'label' => __('Description', CPAC_TEXTDOMAIN)
1499
- ),
1500
- 'column-alternate_text' => array(
1501
- 'label' => __('Alt', CPAC_TEXTDOMAIN)
1502
- ),
1503
- 'column-file_paths' => array(
1504
- 'label' => __('Upload paths', CPAC_TEXTDOMAIN),
1505
- 'options' => array(
1506
- 'sortorder' => false
1507
- )
1508
- ),
1509
- 'column-actions' => array(
1510
- 'label' => __('Actions', CPAC_TEXTDOMAIN),
1511
- 'options' => array(
1512
- 'sortorder' => false
1513
- )
1514
- ),
1515
- 'column-filesize' => array(
1516
- 'label' => __('File size', CPAC_TEXTDOMAIN)
1517
- )
1518
- );
1519
-
1520
- // Get extended image metadata, exif or iptc as available.
1521
- // uses exif_read_data()
1522
- if ( function_exists('exif_read_data') ) {
1523
- $custom_columns = array_merge( $custom_columns, array(
1524
- 'column-image-aperture' => array(
1525
- 'label' => __('Aperture', CPAC_TEXTDOMAIN),
1526
- 'options' => array(
1527
- 'type_label' => __('Aperture EXIF', CPAC_TEXTDOMAIN)
1528
- )
1529
- ),
1530
- 'column-image-credit' => array(
1531
- 'label' => __('Credit', CPAC_TEXTDOMAIN),
1532
- 'options' => array(
1533
- 'type_label' => __('Credit EXIF', CPAC_TEXTDOMAIN)
1534
- )
1535
- ),
1536
- 'column-image-camera' => array(
1537
- 'label' => __('Camera', CPAC_TEXTDOMAIN),
1538
- 'options' => array(
1539
- 'type_label' => __('Camera EXIF', CPAC_TEXTDOMAIN)
1540
- )
1541
- ),
1542
- 'column-image-caption' => array(
1543
- 'label' => __('Caption', CPAC_TEXTDOMAIN),
1544
- 'options' => array(
1545
- 'type_label' => __('Caption EXIF', CPAC_TEXTDOMAIN)
1546
- )
1547
- ),
1548
- 'column-image-created_timestamp' => array(
1549
- 'label' => __('Timestamp', CPAC_TEXTDOMAIN),
1550
- 'options' => array(
1551
- 'type_label' => __('Timestamp EXIF', CPAC_TEXTDOMAIN)
1552
- )
1553
- ),
1554
- 'column-image-copyright' => array(
1555
- 'label' => __('Copyright', CPAC_TEXTDOMAIN),
1556
- 'options' => array(
1557
- 'type_label' => __('Copyright EXIF', CPAC_TEXTDOMAIN)
1558
- )
1559
- ),
1560
- 'column-image-focal_length' => array(
1561
- 'label' => __('Focal Length', CPAC_TEXTDOMAIN),
1562
- 'options' => array(
1563
- 'type_label' => __('Focal Length EXIF', CPAC_TEXTDOMAIN)
1564
- )
1565
- ),
1566
- 'column-image-iso' => array(
1567
- 'label' => __('ISO', CPAC_TEXTDOMAIN),
1568
- 'options' => array(
1569
- 'type_label' => __('ISO EXIF', CPAC_TEXTDOMAIN)
1570
- )
1571
- ),
1572
- 'column-image-shutter_speed' => array(
1573
- 'label' => __('Shutter Speed', CPAC_TEXTDOMAIN),
1574
- 'options' => array(
1575
- 'type_label' => __('Shutter Speed EXIF', CPAC_TEXTDOMAIN)
1576
- )
1577
- ),
1578
- 'column-image-title' => array(
1579
- 'label' => __('Title', CPAC_TEXTDOMAIN),
1580
- 'options' => array(
1581
- 'type_label' => __('Title EXIF', CPAC_TEXTDOMAIN)
1582
- )
1583
- )
1584
- ));
1585
- }
1586
-
1587
- // Custom Field support
1588
- if ( $this->get_meta_by_type('wp-media') ) {
1589
- $custom_columns['column-meta-1'] = array(
1590
- 'label' => __('Custom Field', CPAC_TEXTDOMAIN),
1591
- 'field' => '',
1592
- 'field_type' => '',
1593
- 'before' => '',
1594
- 'after' => '',
1595
- 'options' => array(
1596
- 'type_label' => __('Field', CPAC_TEXTDOMAIN),
1597
- 'class' => 'cpac-box-metafield'
1598
- )
1599
- );
1600
- }
1601
-
1602
- // merge with defaults
1603
- $custom_columns = $this->parse_defaults($custom_columns);
1604
-
1605
- return apply_filters('cpac-custom-media-columns', $custom_columns);
1606
- }
1607
-
1608
- /**
1609
- * Custom links columns
1610
- *
1611
- * @since 1.3.1
1612
- */
1613
- private function get_custom_links_columns()
1614
- {
1615
- $custom_columns = array(
1616
- 'column-link_id' => array (
1617
- 'label' => __('ID', CPAC_TEXTDOMAIN)
1618
- ),
1619
- 'column-description' => array (
1620
- 'label' => __('Description', CPAC_TEXTDOMAIN)
1621
- ),
1622
- 'column-image' => array(
1623
- 'label' => __('Image', CPAC_TEXTDOMAIN)
1624
- ),
1625
- 'column-target' => array(
1626
- 'label' => __('Target', CPAC_TEXTDOMAIN)
1627
- ),
1628
- 'column-owner' => array(
1629
- 'label' => __('Owner', CPAC_TEXTDOMAIN)
1630
- ),
1631
- 'column-notes' => array(
1632
- 'label' => __('Notes', CPAC_TEXTDOMAIN)
1633
- ),
1634
- 'column-rss' => array(
1635
- 'label' => __('Rss', CPAC_TEXTDOMAIN)
1636
- ),
1637
- 'column-length' => array(
1638
- 'label' => __('Length', CPAC_TEXTDOMAIN)
1639
- ),
1640
- 'column-actions' => array(
1641
- 'label' => __('Actions', CPAC_TEXTDOMAIN),
1642
- 'options' => array(
1643
- 'sortorder' => false
1644
- )
1645
- )
1646
- );
1647
-
1648
- // merge with defaults
1649
- $custom_columns = $this->parse_defaults($custom_columns);
1650
-
1651
- return apply_filters('cpac-custom-links-columns', $custom_columns);
1652
- }
1653
-
1654
- /**
1655
- * Custom comments columns
1656
- *
1657
- * @since 1.3.1
1658
- */
1659
- private function get_custom_comments_columns()
1660
- {
1661
- $custom_columns = array(
1662
- 'column-comment_id' => array(
1663
- 'label' => __('ID', CPAC_TEXTDOMAIN)
1664
- ),
1665
- 'column-author_author' => array(
1666
- 'label' => __('Author Name', CPAC_TEXTDOMAIN)
1667
- ),
1668
- 'column-author_avatar' => array(
1669
- 'label' => __('Avatar', CPAC_TEXTDOMAIN)
1670
- ),
1671
- 'column-author_url' => array(
1672
- 'label' => __('Author url', CPAC_TEXTDOMAIN)
1673
- ),
1674
- 'column-author_ip' => array(
1675
- 'label' => __('Author IP', CPAC_TEXTDOMAIN)
1676
- ),
1677
- 'column-author_email' => array(
1678
- 'label' => __('Author email', CPAC_TEXTDOMAIN)
1679
- ),
1680
- 'column-reply_to' => array(
1681
- 'label' => __('In Reply To', CPAC_TEXTDOMAIN),
1682
- 'options' => array(
1683
- 'sortorder' => false
1684
- )
1685
- ),
1686
- 'column-approved' => array(
1687
- 'label' => __('Approved', CPAC_TEXTDOMAIN)
1688
- ),
1689
- 'column-date' => array(
1690
- 'label' => __('Date', CPAC_TEXTDOMAIN)
1691
- ),
1692
- 'column-date_gmt' => array(
1693
- 'label' => __('Date GMT', CPAC_TEXTDOMAIN)
1694
- ),
1695
- 'column-agent' => array(
1696
- 'label' => __('Agent', CPAC_TEXTDOMAIN)
1697
- ),
1698
- 'column-excerpt' => array(
1699
- 'label' => __('Excerpt', CPAC_TEXTDOMAIN)
1700
- ),
1701
- 'column-actions' => array(
1702
- 'label' => __('Actions', CPAC_TEXTDOMAIN),
1703
- 'options' => array(
1704
- 'sortorder' => false
1705
- )
1706
- ),
1707
- 'column-word-count' => array(
1708
- 'label' => __('Word count', CPAC_TEXTDOMAIN),
1709
- 'options' => array(
1710
- 'sortorder' => false
1711
- )
1712
- )
1713
- );
1714
-
1715
- // Custom Field support
1716
- if ( $this->get_meta_by_type('wp-comments') ) {
1717
- $custom_columns['column-meta-1'] = array(
1718
- 'label' => __('Custom Field', CPAC_TEXTDOMAIN),
1719
- 'field' => '',
1720
- 'field_type' => '',
1721
- 'before' => '',
1722
- 'after' => '',
1723
- 'options' => array(
1724
- 'type_label' => __('Field', CPAC_TEXTDOMAIN),
1725
- 'class' => 'cpac-box-metafield',
1726
- 'sortorder' => false,
1727
- )
1728
- );
1729
- }
1730
-
1731
- // merge with defaults
1732
- $custom_columns = $this->parse_defaults($custom_columns);
1733
-
1734
- return apply_filters('cpac-custom-comments-columns', $custom_columns);
1735
- }
1736
-
1737
- /**
1738
- * Parse defaults
1739
- *
1740
- * @since 1.1
1741
- */
1742
- private function parse_defaults($columns)
1743
- {
1744
- // default arguments
1745
- $defaults = array(
1746
-
1747
- // stored values
1748
- 'label' => '', // custom label
1749
- 'state' => '', // display state
1750
- 'width' => '', // column width
1751
- 'default_order' => '', // set default sorting: asc, desc or empty
1752
-
1753
- // static values
1754
- 'options' => array(
1755
- 'type_label' => __('Custom', CPAC_TEXTDOMAIN),
1756
- 'hide_options' => false,
1757
- 'class' => 'cpac-box-custom',
1758
- 'sortorder' => 'on',
1759
- )
1760
- );
1761
-
1762
- // parse args
1763
- foreach ( $columns as $k => $column ) {
1764
- $c[$k] = wp_parse_args( $column, $defaults);
1765
-
1766
- // parse options args
1767
- if ( isset($column['options']) )
1768
- $c[$k]['options'] = wp_parse_args( $column['options'], $defaults['options']);
1769
-
1770
- // set type label
1771
- if ( empty($column['options']['type_label']) && !empty($column['label']) )
1772
- $c[$k]['options']['type_label'] = $column['label'];
1773
- }
1774
-
1775
- return $c;
1776
- }
1777
-
1778
- /**
1779
- * Admin requests for orderby column
1780
- *
1781
- * @since 1.0
1782
- */
1783
- public static function get_stored_columns($type)
1784
- {
1785
- // get plugin options
1786
- $options = get_option('cpac_options');
1787
-
1788
- // get saved columns
1789
- if ( !empty($options['columns'][$type]) )
1790
- return $options['columns'][$type];
1791
-
1792
- return false;
1793
- }
1794
-
1795
- /**
1796
- * Post Type Menu
1797
- *
1798
- * @since 1.0
1799
- */
1800
- private function get_menu()
1801
- {
1802
- // set
1803
- $menu = '';
1804
- $count = 1;
1805
-
1806
- // referer
1807
- $referer = ! empty($_REQUEST['cpac_type']) ? $_REQUEST['cpac_type'] : '';
1808
-
1809
- // loop
1810
- foreach ( $this->get_types() as $type ) {
1811
- $label = $this->get_singular_name($type);
1812
- $clean_label = $this->sanitize_string($type);
1813
-
1814
- // divider
1815
- $divider = $count++ == 1 ? '' : ' | ';
1816
-
1817
- // current
1818
- $current = '';
1819
- if ( $this->is_menu_type_current($type) )
1820
- $current = ' class="current"';
1821
-
1822
- // menu list
1823
- $menu .= "
1824
- <li>{$divider}<a{$current} href='#cpac-box-{$clean_label}'>{$label}</a></li>
1825
- ";
1826
- }
1827
-
1828
- // settings url
1829
- $class_current_settings = $this->is_menu_type_current('plugin_settings') ? ' current': '';
1830
-
1831
- // options button
1832
- $options_btn = "<a href='#cpac-box-plugin_settings' class='cpac-settings-link{$class_current_settings}'>".__('Addons', CPAC_TEXTDOMAIN)."</a>";
1833
- //$options_btn = '';
1834
-
1835
- return "
1836
- <div class='cpac-menu'>
1837
- <ul class='subsubsub'>
1838
- {$menu}
1839
- </ul>
1840
- {$options_btn}
1841
- </div>
1842
- ";
1843
- }
1844
-
1845
- /**
1846
- * Checks if menu type is currently viewed
1847
- *
1848
- * @since 1.0
1849
- */
1850
- private function is_menu_type_current( $type )
1851
- {
1852
- // referer
1853
- $referer = ! empty($_REQUEST['cpac_type']) ? $_REQUEST['cpac_type'] : '';
1854
-
1855
- // get label
1856
- $clean_label = $this->sanitize_string($type);
1857
-
1858
- // get first element from post-types
1859
- $first = array_shift( array_values($this->post_types) );
1860
-
1861
- // display the page that was being viewed before saving
1862
- if ( $referer ) {
1863
- if ( $referer == 'cpac-box-'.$clean_label ) {
1864
- return true;
1865
- }
1866
-
1867
- // settings page has not yet been saved
1868
- } elseif ( $first == $type ) {
1869
- return true;
1870
- }
1871
-
1872
- return false;
1873
- }
1874
-
1875
- /**
1876
- * Get singular name of post type
1877
- *
1878
- * @since 1.0
1879
- */
1880
- private function get_singular_name( $type )
1881
- {
1882
- // Links
1883
- if ( $type == 'wp-links' )
1884
- $label = __('Links');
1885
-
1886
- // Comments
1887
- elseif ( $type == 'wp-comments' )
1888
- $label = __('Comments');
1889
-
1890
- // Users
1891
- elseif ( $type == 'wp-users' )
1892
- $label = __('Users');
1893
-
1894
- // Media
1895
- elseif ( $type == 'wp-media' )
1896
- $label = __('Media Library');
1897
-
1898
- // Posts
1899
- else {
1900
- $posttype_obj = get_post_type_object($type);
1901
- $label = $posttype_obj->labels->singular_name;
1902
- }
1903
-
1904
- return $label;
1905
- }
1906
-
1907
- /**
1908
- * Get plural name of post type
1909
- *
1910
- * @since 1.3.1
1911
- */
1912
- private function get_plural_name( $type )
1913
- {
1914
- $posttype_obj = get_post_type_object($type);
1915
- if ( $posttype_obj )
1916
- return $posttype_obj->labels->name;
1917
-
1918
- return false;
1919
- }
1920
-
1921
- /**
1922
- * Get screen link to overview screen
1923
- *
1924
- * @since 1.3.1
1925
- */
1926
- private function get_type_screen_link( $type )
1927
- {
1928
- // Links
1929
- if ( $type == 'wp-comments' )
1930
- $link = get_admin_url() . 'edit-comments.php';
1931
-
1932
- // Links
1933
- if ( $type == 'wp-links' )
1934
- $link = get_admin_url() . 'link-manager.php';
1935
-
1936
- // Users
1937
- if ( $type == 'wp-users' )
1938
- $link = get_admin_url() . 'users.php';
1939
-
1940
- // Media
1941
- elseif ( $type == 'wp-media' )
1942
- $link = get_admin_url() . 'upload.php';
1943
-
1944
- // Posts
1945
- else
1946
- $link = get_admin_url() . "edit.php?post_type={$type}";
1947
-
1948
- return $link;
1949
- }
1950
-
1951
- /**
1952
- * Sanitize label
1953
- *
1954
- * Uses intern wordpress function esc_url so it matches the label sorting url.
1955
- *
1956
- * @since 1.0
1957
- */
1958
- protected function sanitize_string($string)
1959
- {
1960
- $string = esc_url($string);
1961
- $string = str_replace('http://','', $string);
1962
- $string = str_replace('https://','', $string);
1963
-
1964
- return $string;
1965
- }
1966
-
1967
- /**
1968
- * Checks if column-meta key exists
1969
- *
1970
- * @since 1.0
1971
- */
1972
- public static function is_column_meta( $id = '' )
1973
- {
1974
- if ( strpos($id, 'column-meta-') !== false )
1975
- return true;
1976
-
1977
- return false;
1978
- }
1979
-
1980
- /**
1981
- * Get the posttype from columnname
1982
- *
1983
- * @since 1.3.1
1984
- */
1985
- public static function get_posttype_by_postcount_column( $id = '' )
1986
- {
1987
- if ( strpos($id, 'column-user_postcount-') !== false )
1988
- return str_replace('column-user_postcount-', '', $id);
1989
-
1990
- return false;
1991
- }
1992
-
1993
- /**
1994
- * Get column value of post attachments
1995
- *
1996
- * @since 1.2.1
1997
- */
1998
- public static function get_attachment_ids( $post_id )
1999
- {
2000
- return get_posts(array(
2001
- 'post_type' => 'attachment',
2002
- 'numberposts' => -1,
2003
- 'post_status' => null,
2004
- 'post_parent' => $post_id,
2005
- 'fields' => 'ids'
2006
- ));
2007
- }
2008
-
2009
- /**
2010
- * Strip tags and trim
2011
- *
2012
- * @since 1.3
2013
- */
2014
- public static function strip_trim($string)
2015
- {
2016
- return trim(strip_tags($string));
2017
- }
2018
-
2019
- /**
2020
- * Admin body class
2021
- *
2022
- * @since 1.4
2023
- */
2024
- function admin_class()
2025
- {
2026
- global $current_screen;
2027
-
2028
- // we dont need the 'edit-' part
2029
- $screen = str_replace('edit-', '', $current_screen->id);
2030
-
2031
- // media library exception
2032
- if ( $current_screen->base == 'upload' && $current_screen->id == 'upload' ) {
2033
- $screen = 'media';
2034
- }
2035
-
2036
- // link exception
2037
- if ( $current_screen->base == 'link-manager' && $current_screen->id == 'link-manager' ) {
2038
- $screen = 'links';
2039
- }
2040
-
2041
- // loop the available types
2042
- foreach ( $this->get_types() as $type => $label ) {
2043
-
2044
- // match against screen or wp-screen
2045
- if ( $type == $screen || $type == "wp-{$screen}" )
2046
- return "cp-{$type}";
2047
- }
2048
- return false;
2049
- }
2050
-
2051
- /**
2052
- * Admin CSS for Column width
2053
- *
2054
- * @since 1.4
2055
- */
2056
- function admin_css()
2057
- {
2058
- $css = '';
2059
-
2060
- // loop throug the available types...
2061
- foreach ( $this->get_types() as $type ) {
2062
- $cols = self::get_stored_columns($type);
2063
- if ( $cols ) {
2064
-
2065
- // loop through each available column...
2066
- foreach ( $cols as $col_name => $col ) {
2067
-
2068
- // and check for stored width and add it to the css
2069
- if (!empty($col['width']) && is_numeric($col['width']) && $col['width'] > 0 ) {
2070
- $css .= ".cp-{$type} .wrap table th.column-{$col_name} { width: {$col['width']}% !important; }";
2071
- }
2072
- }
2073
- }
2074
- }
2075
-
2076
- echo "<style type='text/css'>{$css}</style>";
2077
- }
2078
-
2079
- /**
2080
- * Unlocks
2081
- *
2082
- * @since 1.3
2083
- */
2084
- protected function is_unlocked($type)
2085
- {
2086
- return preg_match('/^[a-f0-9]{40}$/i', $this->get_license_key($type));
2087
- }
2088
-
2089
- /**
2090
- * Check license key with API
2091
- *
2092
- * @since 1.3.3
2093
- */
2094
- private function check_remote_key($type, $key)
2095
- {
2096
- if ( empty($type) || empty($key) )
2097
- return false;
2098
-
2099
- // check key with remote API
2100
- $response = wp_remote_post( $this->api_url, array(
2101
- 'body' => array(
2102
- 'api' => 'addon',
2103
- 'key' => $key,
2104
- 'type' => $type
2105
- )
2106
- ));
2107
-
2108
- // license will be valid in case of WP error or succes
2109
- if ( is_wp_error($response) || ( isset($response['body']) && json_decode($response['body']) == 'valid' ) )
2110
- return true;
2111
-
2112
- return false;
2113
- }
2114
-
2115
- /**
2116
- * Set masked license key
2117
- *
2118
- * @since 1.3.1
2119
- */
2120
- private function get_masked_license_key($type)
2121
- {
2122
- return '**************************'.substr( $this->get_license_key($type), -4 );
2123
- }
2124
-
2125
- /**
2126
- * Ajax activation
2127
- *
2128
- * @since 1.3.1
2129
- */
2130
- public function ajax_activation()
2131
- {
2132
- // keys
2133
- $key = $_POST['key'];
2134
- $type = $_POST['type'];
2135
-
2136
- // update key
2137
- if ( $key == 'remove' ) {
2138
- $this->remove_license_key($type);
2139
- }
2140
-
2141
- // set license key
2142
- elseif ( $this->check_remote_key($type, $key) ) {
2143
-
2144
- // set key
2145
- $this->set_license_key($type, $key);
2146
-
2147
- // returned masked key
2148
- echo json_encode( $this->get_masked_license_key($type) );
2149
- }
2150
-
2151
- exit;
2152
- }
2153
-
2154
- /**
2155
- * Get license key
2156
- *
2157
- * @since 1.3
2158
- */
2159
- private function get_license_key($type)
2160
- {
2161
- return get_option("cpac_{$type}_ac");
2162
- }
2163
-
2164
- /**
2165
- * Set license key
2166
- *
2167
- * @since 1.3
2168
- */
2169
- private function set_license_key($type, $key)
2170
- {
2171
- update_option( "cpac_{$type}_ac", trim($key) );
2172
- }
2173
-
2174
- /**
2175
- * Remove license key
2176
- *
2177
- * @since 1.3.1
2178
- */
2179
- private function remove_license_key($type)
2180
- {
2181
- delete_option( "cpac_{$type}_ac" );
2182
- delete_transient("cpac_{$type}_trnsnt");
2183
- }
2184
-
2185
- /**
2186
- * Add help tabs
2187
- *
2188
- * @since 1.3
2189
- */
2190
- public function help_tabs($page)
2191
- {
2192
- $screen = get_current_screen();
2193
-
2194
- if ( $screen->id != $this->admin_page || ! method_exists($screen,'add_help_tab') )
2195
- return;
2196
-
2197
- $admin_url = get_admin_url();
2198
-
2199
- // add help content
2200
- $tabs = array(
2201
- array(
2202
- 'title' => 'Overview',
2203
- 'content' => "
2204
- <h5>Codepress Admin Columns</h5>
2205
- <p>
2206
- This plugin is for adding and removing additional columns to the administration screens for post(types), pages, media library, comments, links and users. Change the column's label and reorder them.
2207
- </p>
2208
-
2209
- "
2210
- ),
2211
- array(
2212
- 'title' => 'Basics',
2213
- 'content' => "
2214
- <h5>Show / Hide</h5>
2215
- <p>
2216
- You can switch columns on or off by cliking on the checkbox. This will show or hide each column heading.
2217
- </p>
2218
- <h5>Change order</h5>
2219
- <p>
2220
- By dragging the columns you can change the order which they will appear in.
2221
- </p>
2222
- <h5>Change label</h5>
2223
- <p>
2224
- By clicking on the triangle you will see the column options. Here you can change each label of the columns heading.
2225
- </p>
2226
- <h5>Change coluimn width</h5>
2227
- <p>
2228
- By clicking on the triangle you will see the column options. By using the draggable slider yo can set the width of the columns in percentages.
2229
- </p>
2230
- "
2231
- ),
2232
- array(
2233
- 'title' => 'Custom Field',
2234
- 'content' => "
2235
- <h5>'Custom Field' column</h5>
2236
- <p>
2237
- The custom field colum uses the custom fields from posts and users. There are 8 types which you can set.
2238
- </p>
2239
- <ul>
2240
- <li><strong>Default</strong><br/>Value: Can be either a string or array. Arrays will be flattened and values are seperated by a ',' comma.</li>
2241
- <li><strong>Image</strong><br/>Value: should only contain an image URL.</li>
2242
- <li><strong>Media Library Icon</strong><br/>Value: should only contain Attachment IDs ( seperated by ',' ).</li>
2243
- <li><strong>Excerpt</strong><br/>Value: This will show the first 20 words of the Post content.</li>
2244
- <li><strong>Multiple Values</strong><br/>Value: should be an array. This will flatten any ( multi dimensional ) array.</li>
2245
- <li><strong>Numeric</strong><br/>Value: Integers only.<br/>If you have the 'sorting addon' this will be used for sorting, so you can sort your posts on numeric (custom field) values.</li>
2246
- <li><strong>Date</strong><br/>Value: Can be unix time stamp of date format as described in the <a href='http://codex.wordpress.org/Formatting_Date_and_Time'>Codex</a>. You can change the outputted date format at the <a href='{$admin_url}options-general.php'>general settings</a> page.</li>
2247
- <li><strong>Post Titles</strong><br/>Value: can be one or more Post ID's (seperated by ',').</li>
2248
- </ul>
2249
- "
2250
- )
2251
- );
2252
-
2253
- foreach ( $tabs as $k => $tab ) {
2254
- $screen->add_help_tab(array(
2255
- 'id' => 'cpac-tab-'.$k, // unique id
2256
- 'title' => $tab['title'], // label
2257
- 'content' => $tab['content'], // body
2258
- ));
2259
- }
2260
- }
2261
-
2262
- /**
2263
- * Activation settings
2264
- *
2265
- * @since 1.3.1
2266
- */
2267
- private function activation_settings()
2268
- {
2269
- $class_current_settings = $this->is_menu_type_current('plugin_settings') ? ' current' : ' hidden'; '';
2270
-
2271
- /** Sortable */
2272
- $masked_key = '';
2273
- $class_sortorder_activate = '';
2274
- $class_sortorder_deactivate = ' hidden';
2275
-
2276
- // is unlocked
2277
- if ( $this->is_unlocked('sortable') ) {
2278
- $masked_key = $this->get_masked_license_key('sortable');
2279
- $class_sortorder_activate = ' hidden';
2280
- $class_sortorder_deactivate = '';
2281
- }
2282
-
2283
- // find out more
2284
- $find_out_more = "<a href='{$this->codepress_url}/sortorder-addon/' class='button-primary alignright' target='_blank'>".__('find out more', CPAC_TEXTDOMAIN)." &raquo</a>";
2285
-
2286
- // info box
2287
- $sortable_tooltip = "
2288
- <p>".__('This will make all of the new columns support sorting', CPAC_TEXTDOMAIN).".</p>
2289
- <p>".__('By default WordPress let\'s you sort by title, date, comments and author. This will make you be able to <strong>sort by any column of any type!</strong>', CPAC_TEXTDOMAIN)."</p>
2290
- <p>".__('Perfect for sorting your articles, media files, comments, links and users', CPAC_TEXTDOMAIN).".</p>
2291
- <p class='description'>".__('(columns that are added by other plugins are not supported)', CPAC_TEXTDOMAIN).".</p>
2292
- <img src='" . CPAC_URL.'/assets/images/addon_sortable_1.png' . "' alt='' />
2293
- {$find_out_more}
2294
- ";
2295
-
2296
- // markup
2297
- $sortable = "
2298
- <tr id='cpac-activation-sortable' class='last'>
2299
- <td class='activation_type'>
2300
- <span>" . __('Sortorder', CPAC_TEXTDOMAIN) . "</span>
2301
- <div class='cpac-tooltip hidden'>
2302
- <div class='qtip_title'>" . __('Sortorder', CPAC_TEXTDOMAIN) . "</div>
2303
- <div class='qtip_content'>
2304
- <p>" . __($sortable_tooltip, CPAC_TEXTDOMAIN) . "</p>
2305
- </div>
2306
- </div>
2307
- </td>
2308
- <td class='activation_status'>
2309
- <div class='activate{$class_sortorder_activate}'>
2310
- " . __('Inactive', CPAC_TEXTDOMAIN) . "
2311
- </div>
2312
- <div class='deactivate{$class_sortorder_deactivate}'>
2313
- " . __('Active', CPAC_TEXTDOMAIN) . "
2314
- </div>
2315
- </td>
2316
- <td class='activation_code'>
2317
- <div class='activate{$class_sortorder_activate}'>
2318
- <input type='text' value='" . __('Fill in your activation code', CPAC_TEXTDOMAIN) . "' name='cpac-sortable-key'>
2319
- <a href='javascript:;' class='button'>" . __('Activate', CPAC_TEXTDOMAIN) . "<span></span></a>
2320
- </div>
2321
- <div class='deactivate{$class_sortorder_deactivate}'>
2322
- <span class='masked_key'>{$masked_key}</span>
2323
- <a href='javascript:;' class='button'>" . __('Deactivate', CPAC_TEXTDOMAIN) . "<span></span></a>
2324
- </div>
2325
- <div class='activation-error-msg'></div>
2326
- </td>
2327
- <td class='activation_more'>{$find_out_more}</td>
2328
- </tr><!-- #cpac-activation-sortable -->
2329
- ";
2330
-
2331
- // settings
2332
- $row = "
2333
- <tr id='cpac-box-plugin_settings' valign='top' class='cpac-box-row {$class_current_settings}'>
2334
- <td colspan='2'>
2335
- <table class='nopadding'>
2336
- <tr class='last'>
2337
- <td>
2338
- <h2>".__('Activate Add-ons', CPAC_TEXTDOMAIN)."</h2>
2339
- <p>".__('Add-ons can be unlocked by purchasing a license key. Each key can be used on multiple sites', CPAC_TEXTDOMAIN)." <a target='_blank' href='{$this->codepress_url}/sortorder-addon/'>Visit the Plugin Store</a>.</p>
2340
- <table class='widefat addons'>
2341
- <thead>
2342
- <tr>
2343
- <th class='activation_type'>".__('Addon', CPAC_TEXTDOMAIN)."</th>
2344
- <th class='activation_status'>".__('Status', CPAC_TEXTDOMAIN)."</th>
2345
- <th class='activation_code'>".__('Activation Code', CPAC_TEXTDOMAIN)."</th>
2346
- <th class='activation_more'></th>
2347
- </tr>
2348
- </thead>
2349
- <tbody>
2350
- {$sortable}
2351
- </tbody>
2352
- </table>
2353
- <div class='addon-translation-string hidden'>
2354
- <span class='tstring-fill-in'>" . __('Enter your activation code', CPAC_TEXTDOMAIN) . "</span>
2355
- <span class='tstring-unrecognised'>" . __('Activation code unrecognised', CPAC_TEXTDOMAIN) . "</span>
2356
- </div>
2357
- </td>
2358
- </tr>
2359
- <!--
2360
- <tr class='last'>
2361
- <td colspan='2'>
2362
- <h2>Options</h2>
2363
- <ul class='cpac-options'>
2364
- <li>
2365
- <div class='cpac-option-label'>Thumbnail size</div>
2366
- <div class='cpac-option-inputs'>
2367
- <input type='text' id='thumbnail_size_w' class='small-text' name='cpac_options[settings][thumb_width]' value='80'/>
2368
- <label for='thumbnail_size_w'>Width</label>
2369
- <br/>
2370
- <input type='text' id='thumbnail_size_h' class='small-text' name='cpac_options[settings][thumb_height]' value='80'/>
2371
- <label for='thumbnail_size_h'>Height</label>
2372
- </div>
2373
- </li>
2374
- <li>
2375
- <div class='cpac-option-label'>Excerpt length</div>
2376
- <div class='cpac-option-inputs'>
2377
-
2378
- <input type='text' id='excerpt_length' class='small-text' name='cpac_options[settings][excerpt_length]' value='15'/>
2379
- <label for='excerpt_length'>Number of words</label>
2380
- </div>
2381
- </li>
2382
- </ul>
2383
- </td>
2384
- </tr>
2385
- -->
2386
- </table>
2387
- </td>
2388
- </tr><!-- #cpac-box-plugin_settings -->
2389
- ";
2390
-
2391
- return $row;
2392
- }
2393
-
2394
- /**
2395
- * Get post count
2396
- *
2397
- * @since 1.3.1
2398
- */
2399
- public static function get_post_count( $post_type, $user_id )
2400
- {
2401
- if ( ! post_type_exists($post_type) || ! get_userdata($user_id) )
2402
- return false;
2403
-
2404
- $user_posts = get_posts(array(
2405
- 'post_type' => $post_type,
2406
- 'numberposts' => -1,
2407
- 'author' => $user_id,
2408
- 'post_status' => 'publish'
2409
- ));
2410
- return count($user_posts);
2411
- }
2412
-
2413
- /**
2414
- * Settings Page Template.
2415
- *
2416
- * This function in conjunction with others uses the WordPress
2417
- * Settings API to create a settings page where users can adjust
2418
- * the behaviour of this plugin.
2419
- *
2420
- * @since 1.0
2421
- */
2422
- public function plugin_settings_page()
2423
- {
2424
- // loop through post types
2425
- $rows = '';
2426
- foreach ( $this->get_types() as $type ) {
2427
-
2428
- // post type label
2429
- $label = $this->get_singular_name($type);
2430
-
2431
- // screen link
2432
- $screen_link = '';
2433
- //$screen_link = $this->get_type_screen_link($type);
2434
- //$screen_link = "<a href='{$screen_link}' class='go-to-screen'>" . sprintf( __('go to %s screen'), strtolower($label) ) . "</a>";
2435
-
2436
- // id
2437
- $id = $this->sanitize_string($type);
2438
-
2439
- // build draggable boxes
2440
- $boxes = $this->get_column_boxes($type);
2441
-
2442
- // class
2443
- $class = $this->is_menu_type_current($type) ? ' current' : ' hidden';
2444
-
2445
- $rows .= "
2446
- <tr id='cpac-box-{$id}' valign='top' class='cpac-box-row{$class}'>
2447
- <th class='cpac_post_type' scope='row'>
2448
- {$label}{$screen_link}
2449
- </th>
2450
- <td>
2451
- <h3 class='cpac_post_type hidden'>{$label}</h3>
2452
- {$boxes}
2453
- </td>
2454
- </tr>
2455
- ";
2456
- }
2457
-
2458
- // Activation
2459
- $activation_settings = $this->activation_settings();
2460
-
2461
- // Post Type Menu
2462
- $menu = $this->get_menu();
2463
-
2464
- // Help screen message
2465
- $help_text = '';
2466
- if ( version_compare( get_bloginfo('version'), '3.2', '>' ) )
2467
- $help_text = '<p>'.__('You will find a short overview at the <strong>Help</strong> section in the top-right screen.', CPAC_TEXTDOMAIN).'</p>';
2468
-
2469
- // find out more
2470
- $find_out_more = "<a href='{$this->codepress_url}/sortorder-addon/' class='alignright green' target='_blank'>".__('find out more', CPAC_TEXTDOMAIN)." &raquo</a>";
2471
-
2472
- ?>
2473
- <div id="cpac" class="wrap">
2474
- <?php screen_icon(CPAC_SLUG) ?>
2475
- <h2><?php _e('Codepress Admin Columns', CPAC_TEXTDOMAIN); ?></h2>
2476
- <?php echo $menu ?>
2477
-
2478
- <div class="postbox-container cpac-col-right">
2479
- <div class="metabox-holder">
2480
- <div class="meta-box-sortables">
2481
-
2482
- <div id="addons-cpac-settings" class="postbox">
2483
- <div title="Click to toggle" class="handlediv"><br></div>
2484
- <h3 class="hndle">
2485
- <span><?php _e('Get the Addon', CPAC_TEXTDOMAIN) ?></span>
2486
- </h3>
2487
- <div class="inside">
2488
- <p><?php _e('By default WordPress let\'s you only sort by title, date, comments and author.', CPAC_TEXTDOMAIN) ?></p>
2489
- <p><?php _e('Make <strong>all columns</strong> of <strong>all types</strong> within the plugin support sorting &#8212; with the sorting addon.', CPAC_TEXTDOMAIN) ?></p>
2490
- <p class="description"><?php _e('(columns that are added by other plugins are not supported)', CPAC_TEXTDOMAIN) ?>.</p>
2491
- <?php echo $find_out_more ?>
2492
- </div>
2493
- </div><!-- addons-cpac-settings -->
2494
-
2495
- <div id="likethisplugin-cpac-settings" class="postbox">
2496
- <div title="Click to toggle" class="handlediv"><br></div>
2497
- <h3 class="hndle">
2498
- <span><?php _e('Like this plugin?', CPAC_TEXTDOMAIN) ?></span>
2499
- </h3>
2500
- <div class="inside">
2501
- <p><?php _e('Why not do any or all of the following', CPAC_TEXTDOMAIN) ?>:</p>
2502
- <ul>
2503
- <li><a href="<?php echo $this->plugins_url ?>"><?php _e('Give it a 5 star rating on WordPress.org.', CPAC_TEXTDOMAIN) ?></a></li>
2504
- <li><a href="<?php echo $this->codepress_url ?>/"><?php _e('Link to it so other folks can find out about it.', CPAC_TEXTDOMAIN) ?></a></li>
2505
- <li class="donate_link"><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=ZDZRSYLQ4Z76J"><?php _e('Donate a token of your appreciation.', CPAC_TEXTDOMAIN) ?></a></li>
2506
- </ul>
2507
- </div>
2508
- </div><!-- likethisplugin-cpac-settings -->
2509
-
2510
- <div id="latest-news-cpac-settings" class="postbox">
2511
- <div title="Click to toggle" class="handlediv"><br></div>
2512
- <h3 class="hndle">
2513
- <span><?php _e('Follow us', CPAC_TEXTDOMAIN) ?></span>
2514
- </h3>
2515
- <div class="inside">
2516
- <ul>
2517
- <li class="twitter"><a href="http://twitter.com/codepressNL"><?php _e('Follow Codepress on Twitter.', CPAC_TEXTDOMAIN) ?></a></li>
2518
- <li class="facebook"><a href="https://www.facebook.com/codepressNL"><?php _e('Like Codepress on Facebook.', CPAC_TEXTDOMAIN) ?></a></li>
2519
-
2520
- </ul>
2521
- </div>
2522
- </div><!-- latest-news-cpac-settings -->
2523
-
2524
- <div id="side-cpac-settings" class="postbox">
2525
- <div title="Click to toggle" class="handlediv"><br></div>
2526
- <h3 class="hndle">
2527
- <span><?php _e('Need support?', CPAC_TEXTDOMAIN) ?></span>
2528
- </h3>
2529
- <div class="inside">
2530
- <?php echo $help_text ?>
2531
- <p><?php printf(__('If you are having problems with this plugin, please talk about them in the <a href="%s">Support forums</a> or send me an email %s.', CPAC_TEXTDOMAIN), $this->wordpress_url, '<a href="mailto:info@codepress.nl">info@codepress.nl</a>' );?></p>
2532
- <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>.", CPAC_TEXTDOMAIN), "{$this->codepress_url}/feedback");?></p>
2533
- </div>
2534
- </div><!-- side-cpac-settings -->
2535
-
2536
- </div>
2537
- </div>
2538
- </div><!-- .postbox-container -->
2539
-
2540
- <div class="postbox-container cpac-col-left">
2541
- <div class="metabox-holder">
2542
- <div class="meta-box-sortables">
2543
-
2544
- <div id="general-cpac-settings" class="postbox">
2545
- <div title="Click to toggle" class="handlediv"><br></div>
2546
- <h3 class="hndle">
2547
- <span><?php _e('Admin Columns', CPAC_TEXTDOMAIN ); ?></span>
2548
- </h3>
2549
- <div class="inside">
2550
- <form method="post" action="options.php">
2551
-
2552
- <?php settings_fields( 'cpac-settings-group' ); ?>
2553
-
2554
- <table class="form-table">
2555
- <!-- columns -->
2556
- <?php echo $rows; ?>
2557
-
2558
- <!-- activation -->
2559
- <?php echo $activation_settings; ?>
2560
-
2561
- <tr class="bottom" valign="top">
2562
- <th scope="row"></th>
2563
- <td>
2564
- <p class="submit">
2565
- <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
2566
- </p>
2567
- </td>
2568
- </tr>
2569
- </table>
2570
- </form>
2571
- </div>
2572
- </div><!-- general-settings -->
2573
-
2574
- <div id="restore-cpac-settings" class="postbox">
2575
- <div title="Click to toggle" class="handlediv"><br></div>
2576
- <h3 class="hndle">
2577
- <span><?php _e('Restore defaults', CPAC_TEXTDOMAIN) ?></span>
2578
- </h3>
2579
- <div class="inside">
2580
- <form method="post" action="">
2581
- <input type="submit" class="button" name="cpac-restore-defaults" value="<?php _e('Restore default settings', CPAC_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", CPAC_TEXTDOMAIN); ?>');" />
2582
- </form>
2583
- <p class="description"><?php _e('This will delete all column settings and restore the default settings.', CPAC_TEXTDOMAIN); ?></p>
2584
- </div>
2585
- </div><!-- restore-cpac-settings -->
2586
-
2587
- </div>
2588
- </div>
2589
- </div><!-- .postbox-container -->
2590
- </div>
2591
- <?php
2592
- }
2593
- }
2594
-
2595
- /**
2596
- * Init Class Codepress_Admin_Columns
2597
- *
2598
- * @since 1.0
2599
- */
2600
- new Codepress_Admin_Columns();
2601
-
2602
-
2603
- /**
2604
- * Init Class Codepress_Sortable_Columns
2605
- *
2606
- * @since 1.3
2607
- */
2608
- new Codepress_Sortable_Columns();
2609
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2610
  ?>
1
+ <?php
2
+ /*
3
+
4
+ Plugin Name: Codepress Admin Columns
5
+ Version: 1.4.7
6
+ Description: Customise columns on the administration screens for post(types), pages, media, comments, links and users with an easy to use drag-and-drop interface.
7
+ Author: Codepress
8
+ Author URI: http://www.codepress.nl
9
+ Plugin URI: http://www.codepress.nl/plugins/codepress-admin-columns/
10
+ Text Domain: codepress-admin-columns
11
+ Domain Path: /languages
12
+ License: GPLv2
13
+
14
+ Copyright 2011-2012 Codepress info@codepress.nl
15
+
16
+ This program is free software; you can redistribute it and/or modify
17
+ it under the terms of the GNU General Public License version 2 as published by
18
+ the Free Software Foundation.
19
+
20
+ This program is distributed in the hope that it will be useful,
21
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ GNU General Public License for more details.
24
+
25
+ You should have received a copy of the GNU General Public License
26
+ along with this program; if not, write to the Free Software
27
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28
+ */
29
+
30
+ define( 'CPAC_VERSION', '1.4.7' );
31
+ define( 'CPAC_TEXTDOMAIN', 'codepress-admin-columns' );
32
+ define( 'CPAC_SLUG', 'codepress-admin-columns' );
33
+ define( 'CPAC_URL', plugins_url('', __FILE__) );
34
+
35
+ // only run plugin in the admin interface
36
+ if ( !is_admin() )
37
+ return false;
38
+
39
+ /**
40
+ * Dependencies
41
+ *
42
+ * @since 1.3
43
+ */
44
+ require_once dirname( __FILE__ ) . '/classes/utility.php';
45
+ require_once dirname( __FILE__ ) . '/classes/sortable.php';
46
+ require_once dirname( __FILE__ ) . '/classes/values.php';
47
+ require_once dirname( __FILE__ ) . '/classes/values/posts.php';
48
+ require_once dirname( __FILE__ ) . '/classes/values/users.php';
49
+ require_once dirname( __FILE__ ) . '/classes/values/media.php';
50
+ require_once dirname( __FILE__ ) . '/classes/values/link.php';
51
+ require_once dirname( __FILE__ ) . '/classes/values/comments.php';
52
+ require_once dirname( __FILE__ ) . '/classes/license.php';
53
+
54
+ /**
55
+ * Codepress Admin Columns Class
56
+ *
57
+ * @since 1.0
58
+ *
59
+ */
60
+ class Codepress_Admin_Columns
61
+ {
62
+ private $post_types,
63
+ $codepress_url,
64
+ $wordpress_url,
65
+ $api_url,
66
+ $admin_page,
67
+ $use_hidden_custom_fields;
68
+
69
+ /**
70
+ * Constructor
71
+ *
72
+ * @since 1.0
73
+ */
74
+ function __construct()
75
+ {
76
+ $this->api_url = 'http://www.codepress.nl/';
77
+
78
+ // wp is loaded
79
+ add_action( 'wp_loaded', array( $this, 'init') );
80
+ }
81
+
82
+ /**
83
+ * Initialize plugin.
84
+ *
85
+ * Loading sequence is determined and intialized.
86
+ *
87
+ * @since 1.0
88
+ */
89
+ public function init()
90
+ {
91
+ // vars
92
+ $this->post_types = self::get_post_types();
93
+
94
+ // set
95
+ $this->codepress_url = 'http://www.codepress.nl/plugins/codepress-admin-columns';
96
+ $this->plugins_url = 'http://wordpress.org/extend/plugins/codepress-admin-columns/';
97
+ $this->wordpress_url = 'http://wordpress.org/tags/codepress-admin-columns';
98
+
99
+ // enable the use of custom hidden fields
100
+ $this->use_hidden_custom_fields = apply_filters('cpac_use_hidden_custom_fields', false);
101
+
102
+ // translations
103
+ load_plugin_textdomain( CPAC_TEXTDOMAIN, false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
104
+
105
+ // register settings
106
+ add_action( 'admin_menu', array( $this, 'settings_menu') );
107
+ add_action( 'admin_init', array( $this, 'register_settings') );
108
+
109
+ // styling & scripts
110
+ add_action( 'admin_enqueue_scripts' , array( $this, 'column_styles') );
111
+ add_filter( 'admin_body_class', array( $this, 'admin_class' ) );
112
+ add_action( 'admin_head', array( $this, 'admin_css') );
113
+
114
+ // register columns
115
+ add_action( 'admin_init', array( $this, 'register_columns_headings' ) );
116
+ add_action( 'admin_init', array( $this, 'register_columns_values' ) );
117
+
118
+ // action ajax
119
+ add_action( 'wp_ajax_cpac_addon_activation', array( $this, 'ajax_activation'));
120
+
121
+ // handle requests gets a low priority so it will trigger when all other plugins have loaded their columns
122
+ add_action( 'admin_init', array( $this, 'handle_requests' ), 1000 );
123
+
124
+ // filters
125
+ add_filter( 'plugin_action_links', array( $this, 'add_settings_link'), 1, 2);
126
+ }
127
+
128
+ /**
129
+ * Admin Menu.
130
+ *
131
+ * Create the admin menu link for the settings page.
132
+ *
133
+ * @since 1.0
134
+ */
135
+ public function settings_menu()
136
+ {
137
+ $page = add_options_page(
138
+ // Page title
139
+ esc_html__( 'Admin Columns Settings', CPAC_TEXTDOMAIN ),
140
+ // Menu Title
141
+ esc_html__( 'Admin Columns', CPAC_TEXTDOMAIN ),
142
+ // Capability
143
+ 'manage_options',
144
+ // Menu slug
145
+ CPAC_SLUG,
146
+ // Callback
147
+ array( $this, 'plugin_settings_page')
148
+ );
149
+
150
+ // set admin page
151
+ $this->admin_page = $page;
152
+
153
+ // settings page specific styles and scripts
154
+ add_action( "admin_print_styles-$page", array( $this, 'admin_styles') );
155
+ add_action( "admin_print_scripts-$page", array( $this, 'admin_scripts') );
156
+
157
+ // add help tabs
158
+ add_action("load-$page", array( $this, 'help_tabs'));
159
+ }
160
+
161
+ /**
162
+ * Add Settings link to plugin page
163
+ *
164
+ * @since 1.0
165
+ * @param $links string - all settings links
166
+ * @param $file string - plugin filename
167
+ * @return string - link to settings page
168
+ */
169
+ function add_settings_link( $links, $file )
170
+ {
171
+ if ( $file != plugin_basename( __FILE__ ))
172
+ return $links;
173
+
174
+ array_unshift($links, '<a href="' . admin_url("admin.php") . '?page=' . CPAC_SLUG . '">' . __( 'Settings' ) . '</a>');
175
+ return $links;
176
+ }
177
+
178
+ /**
179
+ * Register Column Values
180
+ *
181
+ * initializes each Class per type
182
+ *
183
+ * @since 1.0
184
+ */
185
+ public function register_columns_values()
186
+ {
187
+ new CPAC_Posts_Values();
188
+ new CPAC_Link_Values();
189
+ new CPAC_Media_Values();
190
+ new CPAC_Users_Values();
191
+ new CPAC_Comments_Values();
192
+ }
193
+ /**
194
+ * Register Columns Headings
195
+ *
196
+ * apply_filters location in includes/screen.php
197
+ *
198
+ * @since 1.0
199
+ */
200
+ public function register_columns_headings()
201
+ {
202
+ /** Posts */
203
+ foreach ( $this->post_types as $post_type ) {
204
+
205
+ // register column per post type
206
+ add_filter("manage_edit-{$post_type}_columns", array($this, 'callback_add_posts_column_headings'));
207
+ }
208
+
209
+ /** Users */
210
+ add_filter( "manage_users_columns", array($this, 'callback_add_users_column_headings'), 9);
211
+ // give higher priority, so it will load just before other plugins to prevent conflicts
212
+
213
+ /** Media */
214
+ add_filter( "manage_upload_columns", array($this, 'callback_add_media_column_headings'));
215
+
216
+ /** Links */
217
+ add_filter( "manage_link-manager_columns", array($this, 'callback_add_links_column_headings'));
218
+
219
+ /** Comments */
220
+ add_filter( "manage_edit-comments_columns", array($this, 'callback_add_comments_column_headings'));
221
+ }
222
+
223
+ /**
224
+ * Callback add Posts Column
225
+ *
226
+ * @since 1.0
227
+ */
228
+ public function callback_add_posts_column_headings($columns)
229
+ {
230
+ return $this->add_columns_headings( get_post_type(), $columns);
231
+ }
232
+
233
+ /**
234
+ * Callback add Users column
235
+ *
236
+ * @since 1.1
237
+ */
238
+ public function callback_add_users_column_headings($columns)
239
+ {
240
+ return $this->add_columns_headings('wp-users', $columns);
241
+ }
242
+
243
+ /**
244
+ * Callback add Media column
245
+ *
246
+ * @since 1.3
247
+ */
248
+ public function callback_add_media_column_headings($columns)
249
+ {
250
+ return $this->add_columns_headings('wp-media', $columns);
251
+ }
252
+
253
+ /**
254
+ * Callback add Links column
255
+ *
256
+ * @since 1.3.1
257
+ */
258
+ public function callback_add_links_column_headings($columns)
259
+ {
260
+ return $this->add_columns_headings('wp-links', $columns);
261
+ }
262
+
263
+ /**
264
+ * Callback add Comments column
265
+ *
266
+ * @since 1.3.1
267
+ */
268
+ public function callback_add_comments_column_headings($columns)
269
+ {
270
+ return $this->add_columns_headings('wp-comments', $columns);
271
+ }
272
+
273
+
274
+
275
+ /**
276
+ * Add managed columns by Type
277
+ *
278
+ * @since 1.4.6.5
279
+ */
280
+ private function get_comment_icon()
281
+ {
282
+ return "<span class='vers'><img src='" . trailingslashit( get_admin_url() ) . 'images/comment-grey-bubble.png' . "' alt='Comments'></span>";
283
+ }
284
+
285
+ /**
286
+ * Add managed columns by Type
287
+ *
288
+ * @since 1.1
289
+ */
290
+ protected function add_columns_headings( $type, $columns )
291
+ {
292
+ // only get stored columns.. the rest we don't need
293
+ $db_columns = self::get_stored_columns($type);
294
+
295
+ if ( !$db_columns )
296
+ return $columns;
297
+
298
+ // filter already loaded columns by plugins
299
+ $set_columns = $this->filter_preset_columns( $type, $columns );
300
+
301
+ // loop through columns
302
+ foreach ( $db_columns as $id => $values ) {
303
+ // is active
304
+ if ( isset($values['state']) && $values['state'] == 'on' ){
305
+
306
+ $label = $values['label'];
307
+
308
+ // exception for comments
309
+ if( 'comments' == $id ) {
310
+ $label = $this->get_comment_icon();
311
+ }
312
+
313
+ // register format
314
+ $set_columns[$id] = $label;
315
+ }
316
+ }
317
+
318
+ return $set_columns;
319
+ }
320
+
321
+ /**
322
+ * Filter preset columns. These columns apply either for every post or set by a plugin.
323
+ *
324
+ * @since 1.0
325
+ */
326
+ private function filter_preset_columns( $type, $columns )
327
+ {
328
+ $options = get_option('cpac_options_default');
329
+
330
+ if ( !$options )
331
+ return $columns;
332
+
333
+ // we use the wp default columns for filtering...
334
+ $stored_wp_default_columns = $options[$type];
335
+
336
+ // ... the ones that are set by plugins, theme functions and such.
337
+ $dif_columns = array_diff(array_keys($columns), array_keys($stored_wp_default_columns));
338
+
339
+ // we add those to the columns
340
+ $pre_columns = array();
341
+ if ( $dif_columns ) {
342
+ foreach ( $dif_columns as $column ) {
343
+ $pre_columns[$column] = $columns[$column];
344
+ }
345
+ }
346
+
347
+ return $pre_columns;
348
+ }
349
+
350
+ /**
351
+ * Get a list of Column options per post type
352
+ *
353
+ * @since 1.0
354
+ */
355
+ private function get_column_boxes($type)
356
+ {
357
+ // merge all columns
358
+ $display_columns = $this->get_merged_columns($type);
359
+
360
+ // define
361
+ $list = '';
362
+
363
+ // loop throught the active columns
364
+ if ( $display_columns ) {
365
+ foreach ( $display_columns as $id => $values ) {
366
+
367
+ $classes = array();
368
+
369
+ // set state
370
+ $state = isset($values['state']) ? $values['state'] : '';
371
+
372
+ // class
373
+ $classes[] = "cpac-box-{$id}";
374
+ if ( $state ) {
375
+ $classes[] = 'active';
376
+ }
377
+ if ( ! empty($values['options']['class']) ) {
378
+ $classes[] = $values['options']['class'];
379
+ }
380
+ $class = implode(' ', $classes);
381
+
382
+ // more box options
383
+ $more_options = $this->get_additional_box_options($type, $id, $values);
384
+ $action = "<a class='cpac-action' href='#open'>open</a>";
385
+
386
+ // type label
387
+ $type_label = isset($values['options']['type_label']) ? $values['options']['type_label'] : '';
388
+
389
+ // label
390
+ $label = isset($values['label']) ? str_replace("'", '"', $values['label']) : '';
391
+
392
+ // main label
393
+ $main_label = $values['label'];
394
+
395
+ // main label exception for comments
396
+ if ( 'comments' == $id ) {
397
+ $main_label = $this->get_comment_icon();
398
+ }
399
+
400
+ // width
401
+ $width = isset($values['width']) ? $values['width'] : 0;
402
+ $width_descr = isset($values['width']) && $values['width'] > 0 ? $values['width'] . '%' : __('default', CPAC_TEXTDOMAIN);
403
+
404
+ // hide box options
405
+ $label_hidden = '';
406
+ if ( ! empty($values['options']['hide_options']) || strpos($label, '<img') !== false ) {
407
+ $label_hidden = ' style="display:none"';
408
+ }
409
+
410
+ $list .= "
411
+ <li class='{$class}'>
412
+ <div class='cpac-sort-handle'></div>
413
+ <div class='cpac-type-options'>
414
+ <div class='cpac-checkbox'></div>
415
+ <input type='hidden' class='cpac-state' name='cpac_options[columns][{$type}][{$id}][state]' value='{$state}'/>
416
+ <label class='main-label'>{$main_label}</label>
417
+ </div>
418
+ <div class='cpac-meta-title'>
419
+ {$action}
420
+ <span>{$type_label}</span>
421
+ </div>
422
+ <div class='cpac-type-inside'>
423
+ <label for='cpac_options-{$type}-{$id}-label'{$label_hidden}>Label: </label>
424
+ <input type='text' name='cpac_options[columns][{$type}][{$id}][label]' id='cpac_options-{$type}-{$id}-label' value='{$label}' class='text'{$label_hidden}/>
425
+ <label for='cpac_options-{$type}-{$id}-width'>" . __('Width', CPAC_TEXTDOMAIN) . ":</label>
426
+ <input type='hidden' maxlength='4' class='input-width' name='cpac_options[columns][{$type}][{$id}][width]' id='cpac_options-{$type}-{$id}-width' value='{$width}' />
427
+ <div class='description width-decription' title='" . __('default', CPAC_TEXTDOMAIN) . "'>{$width_descr}</div>
428
+ <div class='input-width-range'></div>
429
+ <br/>
430
+ {$more_options}
431
+ </div>
432
+ </li>
433
+ ";
434
+ }
435
+ }
436
+
437
+ // custom field button
438
+ $button_add_column = '';
439
+ if ( $this->get_meta_by_type($type) )
440
+ $button_add_column = "<a href='javacript:;' class='cpac-add-customfield-column button'>+ " . __('Add Custom Field Column', CPAC_TEXTDOMAIN) . "</a>";
441
+
442
+ return "
443
+ <div class='cpac-box'>
444
+ <ul class='cpac-option-list'>
445
+ {$list}
446
+ </ul>
447
+ {$button_add_column}
448
+ <div class='cpac-reorder-msg'>" . __('drag and drop to reorder', CPAC_TEXTDOMAIN) . "</div>
449
+ </div>
450
+ ";
451
+ }
452
+
453
+ /**
454
+ * Get merged columns
455
+ *
456
+ * @since 1.0
457
+ */
458
+ protected function get_merged_columns( $type )
459
+ {
460
+ /** Comments */
461
+ if ( $type == 'wp-comments' ) {
462
+ $wp_default_columns = $this->get_wp_default_comments_columns();
463
+ $wp_custom_columns = $this->get_custom_comments_columns();
464
+ }
465
+
466
+ /** Links */
467
+ elseif ( $type == 'wp-links' ) {
468
+ $wp_default_columns = $this->get_wp_default_links_columns();
469
+ $wp_custom_columns = $this->get_custom_links_columns();
470
+ }
471
+
472
+ /** Users */
473
+ elseif ( $type == 'wp-users' ) {
474
+ $wp_default_columns = $this->get_wp_default_users_columns();
475
+ $wp_custom_columns = $this->get_custom_users_columns();
476
+ }
477
+
478
+ /** Media */
479
+ elseif ( $type == 'wp-media' ) {
480
+ $wp_default_columns = $this->get_wp_default_media_columns();
481
+ $wp_custom_columns = $this->get_custom_media_columns();
482
+ }
483
+
484
+ /** Posts */
485
+ else {
486
+ $wp_default_columns = $this->get_wp_default_posts_columns($type);
487
+ $wp_custom_columns = $this->get_custom_posts_columns($type);
488
+ }
489
+
490
+ // merge columns
491
+ $display_columns = $this->parse_columns($wp_custom_columns, $wp_default_columns, $type);
492
+
493
+ return $display_columns;
494
+ }
495
+
496
+ /**
497
+ * Merge the default columns (set by WordPress) and the added custom columns (set by plugins, theme etc.)
498
+ *
499
+ * @since 1.3.3
500
+ */
501
+ function parse_columns($wp_custom_columns, $wp_default_columns, $type)
502
+ {
503
+ // merge columns
504
+ $default_columns = wp_parse_args($wp_custom_columns, $wp_default_columns);
505
+
506
+ //get saved database columns
507
+ $db_columns = self::get_stored_columns($type);
508
+ if ( $db_columns ) {
509
+
510
+ // let's remove any unavailable columns.. such as disabled plugins
511
+ $db_columns = $this->remove_unavailable_columns($db_columns, $default_columns);
512
+
513
+ // loop throught the active columns
514
+ foreach ( $db_columns as $id => $values ) {
515
+
516
+ // get column meta options from custom columns
517
+ if ( $this->is_column_meta($id) && !empty($wp_custom_columns['column-meta-1']['options']) ) {
518
+ $db_columns[$id]['options'] = $wp_custom_columns['column-meta-1']['options'];
519
+ }
520
+
521
+ // add static options
522
+ elseif ( isset($default_columns[$id]['options']) )
523
+ $db_columns[$id]['options'] = $default_columns[$id]['options'];
524
+
525
+ unset($default_columns[$id]);
526
+ }
527
+ }
528
+
529
+ // merge all
530
+ return wp_parse_args($db_columns, $default_columns);
531
+ }
532
+
533
+ /**
534
+ * Remove deactivated (plugin) columns
535
+ *
536
+ * This will remove any columns that have been stored, but are no longer available. This happends
537
+ * when plugins are deactivated or when they are removed from the theme functions.
538
+ *
539
+ * @since 1.2
540
+ */
541
+ private function remove_unavailable_columns( array $db_columns, array $default_columns)
542
+ {
543
+ // check or differences
544
+ $diff = array_diff( array_keys($db_columns), array_keys($default_columns) );
545
+
546
+ if ( ! empty($diff) && is_array($diff) ) {
547
+ foreach ( $diff as $column_name ){
548
+ // make an exception for column-meta-xxx
549
+ if ( ! $this->is_column_meta($column_name) ) {
550
+ unset($db_columns[$column_name]);
551
+ }
552
+ }
553
+ }
554
+
555
+ return $db_columns;
556
+ }
557
+
558
+ /**
559
+ * Get checkbox
560
+ *
561
+ * @since 1.0
562
+ */
563
+ private function get_box($type, $id, $values)
564
+ {
565
+ $classes = array();
566
+
567
+ // set state
568
+ $state = isset($values['state']) ? $values['state'] : '';
569
+
570
+ // class
571
+ $classes[] = "cpac-box-{$id}";
572
+ if ( $state ) {
573
+ $classes[] = 'active';
574
+ }
575
+ if ( ! empty($values['options']['class']) ) {
576
+ $classes[] = $values['options']['class'];
577
+ }
578
+ $class = implode(' ', $classes);
579
+
580
+ // more box options
581
+ $more_options = $this->get_additional_box_options($type, $id, $values);
582
+ $action = "<a class='cpac-action' href='#open'>open</a>";
583
+
584
+ // type label
585
+ $type_label = isset($values['options']['type_label']) ? $values['options']['type_label'] : '';
586
+
587
+ // label
588
+ $label = isset($values['label']) ? str_replace("'", '"', $values['label']) : '';
589
+
590
+ // main label
591
+ $main_label = $values['label'];
592
+
593
+ // main label exception for comments
594
+ if ( 'comments' == $id ) {
595
+ $main_label = $this->get_comment_icon();
596
+ }
597
+
598
+ // width
599
+ $width = isset($values['width']) ? $values['width'] : 0;
600
+ $width_descr = isset($values['width']) && $values['width'] > 0 ? $values['width'] . '%' : __('default', CPAC_TEXTDOMAIN);
601
+
602
+ // hide box options
603
+ $label_hidden = '';
604
+ if ( ! empty($values['options']['hide_options']) || strpos($label, '<img') !== false ) {
605
+ $label_hidden = ' style="display:none"';
606
+ }
607
+
608
+ $list = "
609
+ <li class='{$class}'>
610
+ <div class='cpac-sort-handle'></div>
611
+ <div class='cpac-type-options'>
612
+ <div class='cpac-checkbox'></div>
613
+ <input type='hidden' class='cpac-state' name='cpac_options[columns][{$type}][{$id}][state]' value='{$state}'/>
614
+ <label class='main-label'>{$main_label}</label>
615
+ </div>
616
+ <div class='cpac-meta-title'>
617
+ {$action}
618
+ <span>{$type_label}</span>
619
+ </div>
620
+ <div class='cpac-type-inside'>
621
+ <label for='cpac_options-{$type}-{$id}-label'{$label_hidden}>Label: </label>
622
+ <input type='text' name='cpac_options[columns][{$type}][{$id}][label]' id='cpac_options-{$type}-{$id}-label' value='{$label}' class='text'{$label_hidden}/>
623
+ <label for='cpac_options-{$type}-{$id}-width'>" . __('Width', CPAC_TEXTDOMAIN) . ":</label>
624
+ <input type='hidden' maxlength='4' class='input-width' name='cpac_options[columns][{$type}][{$id}][width]' id='cpac_options-{$type}-{$id}-width' value='{$width}' />
625
+ <div class='description width-decription' title='" . __('default', CPAC_TEXTDOMAIN) . "'>{$width_descr}</div>
626
+ <div class='input-width-range'></div>
627
+ <br/>
628
+ {$more_options}
629
+ </div>
630
+ </li>
631
+ ";
632
+
633
+ return $list;
634
+ }
635
+
636
+ /**
637
+ * Get additional box option fields
638
+ *
639
+ * @since 1.0
640
+ */
641
+ private function get_additional_box_options($type, $id, $values)
642
+ {
643
+ $fields = '';
644
+
645
+ // Custom Fields
646
+ if( $this->is_column_meta($id) ) {
647
+ $fields = $this->get_box_options_customfields($type, $id, $values);
648
+ }
649
+
650
+ // Author Fields
651
+ if( 'column-author-name' == $id) {
652
+ $fields = $this->get_box_options_author($type, $id, $values);
653
+ }
654
+
655
+ return $fields;
656
+ }
657
+
658
+ /**
659
+ * Box Options: Custom Fields
660
+ *
661
+ * @since 1.0
662
+ */
663
+ private function get_box_options_customfields($type, $id, $values)
664
+ {
665
+ // get post meta fields
666
+ $fields = $this->get_meta_by_type($type);
667
+
668
+ if ( empty($fields) )
669
+ return false;
670
+
671
+ // set meta field options
672
+ $current = ! empty($values['field']) ? $values['field'] : '' ;
673
+ $field_options = '';
674
+ foreach ($fields as $field) {
675
+
676
+ $field_options .= sprintf
677
+ (
678
+ '<option value="%s"%s>%s</option>',
679
+ $field,
680
+ $field == $current? ' selected="selected"':'',
681
+
682
+ // change label on hidden fields
683
+ substr($field,0,10) == "cpachidden" ? str_replace('cpachidden','',$field) : $field
684
+ );
685
+ }
686
+
687
+ // set meta fieldtype options
688
+ $currenttype = ! empty($values['field_type']) ? $values['field_type'] : '' ;
689
+ $fieldtype_options = '';
690
+ $fieldtypes = array(
691
+ '' => __('Default'),
692
+ 'image' => __('Image'),
693
+ 'library_id' => __('Media Library Icon', CPAC_TEXTDOMAIN),
694
+ 'excerpt' => __('Excerpt'),
695
+ 'array' => __('Multiple Values', CPAC_TEXTDOMAIN),
696
+ 'numeric' => __('Numeric', CPAC_TEXTDOMAIN),
697
+ 'date' => __('Date', CPAC_TEXTDOMAIN),
698
+ 'title_by_id' => __('Post Title (Post ID\'s)', CPAC_TEXTDOMAIN),
699
+ 'user_by_id' => __('Username (User ID\'s)', CPAC_TEXTDOMAIN),
700
+ 'checkmark' => __('Checkmark (true/false)', CPAC_TEXTDOMAIN),
701
+ 'color' => __('Color', CPAC_TEXTDOMAIN),
702
+ );
703
+
704
+ // add filter
705
+ $fieldtypes = apply_filters('cpac-field-types', $fieldtypes );
706
+
707
+ // set select options
708
+ foreach ( $fieldtypes as $fkey => $fieldtype ) {
709
+ $fieldtype_options .= sprintf
710
+ (
711
+ '<option value="%s"%s>%s</option>',
712
+ $fkey,
713
+ $fkey == $currenttype? ' selected="selected"':'',
714
+ $fieldtype
715
+ );
716
+ }
717
+
718
+ // before and after string
719
+ $before = ! empty($values['before']) ? $values['before'] : '' ;
720
+ $after = ! empty($values['after']) ? $values['after'] : '' ;
721
+
722
+ if ( empty($field_options) )
723
+ return false;
724
+
725
+ // add remove button
726
+ $remove = '<p class="remove-description description">'.__('This field can not be removed', CPAC_TEXTDOMAIN).'</p>';
727
+ if ( $id != 'column-meta-1') {
728
+ $remove = "
729
+ <p>
730
+ <a href='javascript:;' class='cpac-delete-custom-field-box'>".__('Remove')."</a>
731
+ </p>
732
+ ";
733
+ }
734
+
735
+ $inside = "
736
+ <label for='cpac-{$type}-{$id}-field'>".__('Custom Field', CPAC_TEXTDOMAIN).": </label>
737
+ <select name='cpac_options[columns][{$type}][{$id}][field]' id='cpac-{$type}-{$id}-field'>{$field_options}</select>
738
+ <br/>
739
+ <label for='cpac-{$type}-{$id}-field_type'>".__('Field Type', CPAC_TEXTDOMAIN).": </label>
740
+ <select name='cpac_options[columns][{$type}][{$id}][field_type]' id='cpac-{$type}-{$id}-field_type'>{$fieldtype_options}</select>
741
+ <br/>
742
+ <label for='cpac-{$type}-{$id}-before'>".__('Before', CPAC_TEXTDOMAIN).": </label>
743
+ <input type='text' class='cpac-before' name='cpac_options[columns][{$type}][{$id}][before]' id='cpac-{$type}-{$id}-before' value='{$before}'/>
744
+ <br/>
745
+ <label for='cpac-{$type}-{$id}-after'>".__('After', CPAC_TEXTDOMAIN).": </label>
746
+ <input type='text' class='cpac-after' name='cpac_options[columns][{$type}][{$id}][after]' id='cpac-{$type}-{$id}-after' value='{$after}'/>
747
+ <br/>
748
+ {$remove}
749
+ ";
750
+
751
+ return $inside;
752
+ }
753
+
754
+ /**
755
+ * Box Options: Custom Fields
756
+ *
757
+ * @since 1.0
758
+ */
759
+ private function get_box_options_author($type, $id, $values)
760
+ {
761
+ $options = '';
762
+ $author_types = array(
763
+ 'display_name' => __('Display Name', CPAC_TEXTDOMAIN),
764
+ 'first_name' => __('First Name', CPAC_TEXTDOMAIN),
765
+ 'last_name' => __('Last Name', CPAC_TEXTDOMAIN),
766
+ 'first_last_name' => __('First &amp; Last Name', CPAC_TEXTDOMAIN),
767
+ 'nickname' => __('Nickname', CPAC_TEXTDOMAIN),
768
+ 'username' => __('Username', CPAC_TEXTDOMAIN),
769
+ 'email' => __('Email', CPAC_TEXTDOMAIN),
770
+ 'userid' => __('User ID', CPAC_TEXTDOMAIN)
771
+ );
772
+ $currentname = ! empty($values['display_as']) ? $values['display_as'] : '' ;
773
+ foreach ( $author_types as $k => $name ) {
774
+ $selected = selected( $k, $currentname, false);
775
+ $options .= "<option value='{$k}' {$selected}>{$name}</option>";
776
+ }
777
+
778
+ $inside = "
779
+ <label for='cpac-{$type}-{$id}-display_as'>".__('Display name as', CPAC_TEXTDOMAIN).": </label>
780
+ <select name='cpac_options[columns][{$type}][{$id}][display_as]' id='cpac-{$type}-{$id}-display_as'>
781
+ {$options}
782
+ </select>
783
+ ";
784
+
785
+ return $inside;
786
+ }
787
+
788
+ /**
789
+ * Get post meta fields by type; post(types) or users.
790
+ *
791
+ * @since 1.0
792
+ */
793
+ private function get_meta_by_type($type = 'post')
794
+ {
795
+ global $wpdb;
796
+
797
+ /** Comments */
798
+ if ( $type == 'wp-comments') {
799
+ $sql = "SELECT DISTINCT meta_key FROM {$wpdb->commentmeta} ORDER BY 1";
800
+ }
801
+
802
+ /** Users */
803
+ elseif ( $type == 'wp-users') {
804
+ $sql = "SELECT DISTINCT meta_key FROM {$wpdb->usermeta} ORDER BY 1";
805
+ }
806
+
807
+ /** Media */
808
+ elseif ( $type == 'wp-media') {
809
+ $sql = "SELECT DISTINCT meta_key FROM {$wpdb->postmeta} pm JOIN {$wpdb->posts} p ON pm.post_id = p.ID WHERE p.post_type = 'attachment' ORDER BY 1";
810
+ }
811
+
812
+ /** Posts */
813
+ else {
814
+ $sql = $wpdb->prepare( "SELECT DISTINCT meta_key FROM {$wpdb->postmeta} pm JOIN {$wpdb->posts} p ON pm.post_id = p.ID WHERE p.post_type = %s ORDER BY 1", $type);
815
+ }
816
+
817
+ // run sql
818
+ $fields = $wpdb->get_results($sql, ARRAY_N);
819
+
820
+ // filter out hidden meta fields
821
+ $meta_fields = array();
822
+ if ( $fields ) {
823
+ foreach ($fields as $field) {
824
+
825
+ // give hidden fields a prefix for identifaction
826
+ if ( $this->use_hidden_custom_fields && substr($field[0],0,1) == "_") {
827
+ $meta_fields[] = 'cpachidden'.$field[0];
828
+ }
829
+
830
+ // non hidden fields are saved as is
831
+ elseif ( substr($field[0],0,1) != "_" ) {
832
+ $meta_fields[] = $field[0];
833
+ }
834
+ }
835
+ }
836
+
837
+ if ( !empty($meta_fields) )
838
+ return $meta_fields;
839
+
840
+ return false;
841
+ }
842
+
843
+ /**
844
+ * Register admin scripts
845
+ *
846
+ * @since 1.0
847
+ */
848
+ public function admin_scripts()
849
+ {
850
+ wp_enqueue_script( 'wp-pointer' );
851
+ wp_enqueue_script( 'jquery-ui-slider' );
852
+ wp_enqueue_script( 'cpac-qtip2', CPAC_URL.'/assets/js/jquery.qtip.js', array('jquery'), CPAC_VERSION );
853
+ wp_enqueue_script( 'cpac-admin', CPAC_URL.'/assets/js/admin-column.js', array('jquery', 'dashboard', 'jquery-ui-sortable'), CPAC_VERSION );
854
+ }
855
+
856
+ /**
857
+ * Get column types
858
+ *
859
+ * @since 1.1
860
+ */
861
+ private function get_types()
862
+ {
863
+ $types = $this->post_types;
864
+ $types['wp-users'] = 'wp-users';
865
+ $types['wp-media'] = 'wp-media';
866
+ $types['wp-links'] = 'wp-links';
867
+ $types['wp-comments'] = 'wp-comments';
868
+
869
+ return $types;
870
+ }
871
+
872
+ /**
873
+ * Get post types
874
+ *
875
+ * @since 1.0
876
+ */
877
+ public static function get_post_types()
878
+ {
879
+ $post_types = get_post_types(array(
880
+ '_builtin' => false
881
+ ));
882
+ $post_types['post'] = 'post';
883
+ $post_types['page'] = 'page';
884
+
885
+ return apply_filters('cpac-get-post-types', $post_types);
886
+ }
887
+
888
+ /**
889
+ * Register admin css
890
+ *
891
+ * @since 1.0
892
+ */
893
+ public function admin_styles()
894
+ {
895
+ wp_enqueue_style( 'wp-pointer' );
896
+ wp_enqueue_style( 'jquery-ui-lightness', CPAC_URL.'/assets/ui-theme/jquery-ui-1.8.18.custom.css', array(), CPAC_VERSION, 'all' );
897
+ wp_enqueue_style( 'cpac-admin', CPAC_URL.'/assets/css/admin-column.css', array(), CPAC_VERSION, 'all' );
898
+ }
899
+
900
+ /**
901
+ * Register column css
902
+ *
903
+ * @since 1.0
904
+ */
905
+ public function column_styles()
906
+ {
907
+ wp_enqueue_style( 'cpac-columns', CPAC_URL.'/assets/css/column.css', array(), CPAC_VERSION, 'all' );
908
+ }
909
+
910
+ /**
911
+ * Register plugin options
912
+ *
913
+ * @since 1.0
914
+ */
915
+ public function register_settings()
916
+ {
917
+ // If we have no options in the database, let's add them now.
918
+ if ( false === get_option('cpac_options') ) {
919
+ add_option( 'cpac_options', $this->get_default_plugin_options() );
920
+ }
921
+
922
+ register_setting( 'cpac-settings-group', 'cpac_options', array($this, 'options_callback') );
923
+ }
924
+
925
+ /**
926
+ * Returns the default plugin options.
927
+ *
928
+ * @since 1.0
929
+ */
930
+ public function get_default_plugin_options()
931
+ {
932
+ return apply_filters( 'cpac_default_plugin_options', array() );
933
+ }
934
+
935
+ /**
936
+ * Optional callback.
937
+ *
938
+ * @since 1.0
939
+ */
940
+ public function options_callback($options)
941
+ {
942
+ return $options;
943
+ }
944
+
945
+ /**
946
+ * Handle requests.
947
+ *
948
+ * @since 1.0
949
+ */
950
+ public function handle_requests()
951
+ {
952
+ // only handle updates from the admin columns page
953
+ if ( isset($_REQUEST['page']) && CPAC_SLUG == $_REQUEST['page'] ) {
954
+
955
+ // settings updated
956
+ if ( ! empty($_REQUEST['settings-updated']) ) {
957
+ $this->store_wp_default_columns();
958
+ }
959
+
960
+ // restore defaults
961
+ if ( ! empty($_REQUEST['cpac-restore-defaults']) ) {
962
+ $this->restore_defaults();
963
+ }
964
+ }
965
+ }
966
+
967
+ /**
968
+ * Stores WP default columns
969
+ *
970
+ * This will store columns that are set by WordPress core or theme
971
+ *
972
+ * @since 1.2
973
+ */
974
+ private function store_wp_default_columns()
975
+ {
976
+ // stores the default columns that are set by WP or theme.
977
+ $wp_default_columns = array();
978
+
979
+ // Posts
980
+ foreach ( $this->post_types as $post_type ) {
981
+ $wp_default_columns[$post_type] = $this->get_wp_default_posts_columns($post_type);
982
+ }
983
+
984
+ // Users
985
+ $wp_default_columns['wp-users'] = $this->get_wp_default_users_columns();
986
+
987
+ // Media
988
+ $wp_default_columns['wp-media'] = $this->get_wp_default_media_columns();
989
+
990
+ // Links
991
+ $wp_default_columns['wp-links'] = $this->get_wp_default_links_columns();
992
+
993
+ // Comments
994
+ $wp_default_columns['wp-comments'] = $this->get_wp_default_comments_columns();
995
+
996
+ update_option( 'cpac_options_default', $wp_default_columns );
997
+ }
998
+
999
+ /**
1000
+ * Restore defaults
1001
+ *
1002
+ * @since 1.0
1003
+ */
1004
+ private function restore_defaults()
1005
+ {
1006
+ delete_option( 'cpac_options' );
1007
+ delete_option( 'cpac_options_default' );
1008
+ }
1009
+
1010
+ /**
1011
+ * Get author field by nametype
1012
+ *
1013
+ * Used by posts and sortable
1014
+ *
1015
+ * @since 1.4.6.1
1016
+ */
1017
+ public function get_author_field_by_nametype( $nametype, $user_id)
1018
+ {
1019
+ $userdata = get_userdata( $user_id );
1020
+
1021
+ switch ( $nametype ) :
1022
+
1023
+ case "display_name" :
1024
+ $name = $userdata->display_name;
1025
+ break;
1026
+
1027
+ case "first_name" :
1028
+ $name = $userdata->first_name;
1029
+ break;
1030
+
1031
+ case "last_name" :
1032
+ $name = $userdata->last_name;
1033
+ break;
1034
+
1035
+ case "first_last_name" :
1036
+ $first = !empty($userdata->first_name) ? $userdata->first_name : '';
1037
+ $last = !empty($userdata->last_name) ? " {$userdata->last_name}" : '';
1038
+ $name = $first.$last;
1039
+ break;
1040
+
1041
+ case "nickname" :
1042
+ $name = $userdata->nickname;
1043
+ break;
1044
+
1045
+ case "username" :
1046
+ $name = $userdata->user_login;
1047
+ break;
1048
+
1049
+ case "email" :
1050
+ $name = $userdata->user_email;
1051
+ break;
1052
+
1053
+ case "userid" :
1054
+ $name = $userdata->ID;
1055
+ break;
1056
+
1057
+ default :
1058
+ $name = $userdata->display_name;
1059
+
1060
+ endswitch;
1061
+
1062
+ return $name;
1063
+ }
1064
+
1065
+ /**
1066
+ * Get WP default supported admin columns per post type.
1067
+ *
1068
+ * @since 1.0
1069
+ */
1070
+ private function get_wp_default_posts_columns($post_type = 'post')
1071
+ {
1072
+ // we need to change the current screen
1073
+ global $current_screen;
1074
+
1075
+ // some plugins depend on settings the $_GET['post_type'] variable such as ALL in One SEO
1076
+ $_GET['post_type'] = $post_type;
1077
+
1078
+ // to prevent possible warning from initializing load-edit.php
1079
+ // we will set a dummy screen object
1080
+ if ( empty($current_screen->post_type) ) {
1081
+ $current_screen = (object) array( 'post_type' => $post_type, 'id' => '', 'base' => '' );
1082
+ }
1083
+
1084
+ // for 3rd party plugin support we will call load-edit.php so all the
1085
+ // additional columns that are set by them will be avaible for us
1086
+ do_action('load-edit.php');
1087
+
1088
+ // some plugins directly hook into get_column_headers, such as woocommerce
1089
+ $columns = get_column_headers( 'edit-'.$post_type );
1090
+
1091
+ // get default columns
1092
+ if ( empty($columns) ) {
1093
+
1094
+ // deprecated as of wp3.3
1095
+ if ( file_exists(ABSPATH . 'wp-admin/includes/template.php') )
1096
+ require_once(ABSPATH . 'wp-admin/includes/template.php');
1097
+
1098
+ // introduced since wp3.3
1099
+ if ( file_exists(ABSPATH . 'wp-admin/includes/screen.php') )
1100
+ require_once(ABSPATH . 'wp-admin/includes/screen.php');
1101
+
1102
+ // used for getting columns
1103
+ if ( file_exists(ABSPATH . 'wp-admin/includes/class-wp-list-table.php') )
1104
+ require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
1105
+ if ( file_exists(ABSPATH . 'wp-admin/includes/class-wp-posts-list-table.php') )
1106
+ require_once(ABSPATH . 'wp-admin/includes/class-wp-posts-list-table.php');
1107
+
1108
+ // As of WP Release 3.5 we can use the following.
1109
+ if ( version_compare( get_bloginfo('version'), '3.4.10', '>=' ) ) {
1110
+
1111
+ $table = new WP_Posts_List_Table( array( 'screen' => $post_type ) );
1112
+ $columns = $table->get_columns();
1113
+ }
1114
+
1115
+ // WP versions older then 3.5
1116
+ // @todo: make this deprecated
1117
+ else {
1118
+
1119
+ // we need to change the current screen... first lets save original
1120
+ $org_current_screen = $current_screen;
1121
+
1122
+ // prevent php warning
1123
+ if ( !isset($current_screen) ) $current_screen = new stdClass;
1124
+
1125
+ // overwrite current_screen global with our post type of choose...
1126
+ $current_screen->post_type = $post_type;
1127
+
1128
+ // ...so we can get its columns
1129
+ $columns = WP_Posts_List_Table::get_columns();
1130
+
1131
+ // reset current screen
1132
+ $current_screen = $org_current_screen;
1133
+ }
1134
+ }
1135
+
1136
+ if ( empty ( $columns ) )
1137
+ return false;
1138
+
1139
+ // change to uniform format
1140
+ $columns = $this->get_uniform_format($columns);
1141
+
1142
+ // add sorting to some of the default links columns
1143
+ $columns = $this->set_sorting_to_default_posts_columns($columns);
1144
+
1145
+ return $columns;
1146
+ }
1147
+
1148
+ /**
1149
+ * Add Sorting to WP default Posts columns
1150
+ *
1151
+ * @since 1.4.5
1152
+ */
1153
+ private function set_sorting_to_default_posts_columns($columns)
1154
+ {
1155
+ // categories
1156
+ if ( !empty($columns['categories']) ) {
1157
+ $columns['categories']['options']['sortorder'] = 'on';
1158
+ }
1159
+ // tags
1160
+ if ( !empty($columns['tags']) ) {
1161
+ $columns['tags']['options']['sortorder'] = 'on';
1162
+ }
1163
+ return $columns;
1164
+ }
1165
+
1166
+ /**
1167
+ * Get WP default users columns per post type.
1168
+ *
1169
+ * @since 1.1
1170
+ */
1171
+ private function get_wp_default_users_columns()
1172
+ {
1173
+ if ( file_exists(ABSPATH . 'wp-admin/includes/class-wp-list-table.php') )
1174
+ require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
1175
+ if ( file_exists(ABSPATH . 'wp-admin/includes/class-wp-users-list-table.php') )
1176
+ require_once(ABSPATH . 'wp-admin/includes/class-wp-users-list-table.php');
1177
+
1178
+ // turn off site users
1179
+ $this->is_site_users = false;
1180
+
1181
+ // get users columns
1182
+ $columns = WP_Users_List_Table::get_columns();
1183
+
1184
+ // change to uniform format
1185
+ $columns = $this->get_uniform_format($columns);
1186
+
1187
+ return apply_filters('cpac-default-users-columns', $columns);
1188
+ }
1189
+
1190
+ /**
1191
+ * Get WP default media columns.
1192
+ *
1193
+ * @since 1.2.1
1194
+ */
1195
+ private function get_wp_default_media_columns()
1196
+ {
1197
+ // @todo could use _get_list_table('WP_Media_List_Table') ?
1198
+ if ( file_exists(ABSPATH . 'wp-admin/includes/class-wp-list-table.php') )
1199
+ require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
1200
+ if ( file_exists(ABSPATH . 'wp-admin/includes/class-wp-media-list-table.php') )
1201
+ require_once(ABSPATH . 'wp-admin/includes/class-wp-media-list-table.php');
1202
+
1203
+ // As of WP Release 3.5 we can use the following.
1204
+ if ( version_compare( get_bloginfo('version'), '3.4.10', '>=' ) ) {
1205
+
1206
+ $table = new WP_Media_List_Table(array( 'screen' => 'upload' ));
1207
+ $columns = $table->get_columns();
1208
+ }
1209
+
1210
+ // WP versions older then 3.5
1211
+ // @todo: make this deprecated
1212
+ else {
1213
+
1214
+ global $current_screen;
1215
+
1216
+ // save original
1217
+ $org_current_screen = $current_screen;
1218
+
1219
+ // prevent php warning
1220
+ if ( !isset($current_screen) ) $current_screen = new stdClass;
1221
+
1222
+ // overwrite current_screen global with our media id...
1223
+ $current_screen->id = 'upload';
1224
+
1225
+ // init media class
1226
+ $wp_media = new WP_Media_List_Table;
1227
+
1228
+ // get media columns
1229
+ $columns = $wp_media->get_columns();
1230
+
1231
+ // reset current screen
1232
+ $current_screen = $org_current_screen;
1233
+ }
1234
+
1235
+ // change to uniform format
1236
+ $columns = $this->get_uniform_format($columns);
1237
+
1238
+ return apply_filters('cpac-default-media-columns', $columns);
1239
+ }
1240
+
1241
+ /**
1242
+ * Get WP default links columns.
1243
+ *
1244
+ * @since 1.3.1
1245
+ */
1246
+ private function get_wp_default_links_columns()
1247
+ {
1248
+ // dependencies
1249
+ if ( file_exists(ABSPATH . 'wp-admin/includes/class-wp-list-table.php') )
1250
+ require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
1251
+ if ( file_exists(ABSPATH . 'wp-admin/includes/class-wp-links-list-table.php') )
1252
+ require_once(ABSPATH . 'wp-admin/includes/class-wp-links-list-table.php');
1253
+
1254
+ // get links columns
1255
+ $columns = WP_Links_List_Table::get_columns();
1256
+
1257
+ // change to uniform format
1258
+ $columns = $this->get_uniform_format($columns);
1259
+
1260
+ // add sorting to some of the default links columns
1261
+ $columns = $this->set_sorting_to_default_links_columns($columns);
1262
+
1263
+ return apply_filters('cpac-default-links-columns', $columns);
1264
+ }
1265
+
1266
+ /**
1267
+ * Add Sorting to WP default links columns
1268
+ *
1269
+ * @since 1.4
1270
+ */
1271
+ private function set_sorting_to_default_links_columns($columns)
1272
+ {
1273
+ // Relationship
1274
+ if ( !empty($columns['rel']) ) {
1275
+ $columns['rel']['options']['sortorder'] = 'on';
1276
+ }
1277
+ return $columns;
1278
+ }
1279
+
1280
+ /**
1281
+ * Get WP default links columns.
1282
+ *
1283
+ * @since 1.3.1
1284
+ */
1285
+ private function get_wp_default_comments_columns()
1286
+ {
1287
+ // dependencies
1288
+ if ( file_exists(ABSPATH . 'wp-admin/includes/class-wp-list-table.php') )
1289
+ require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
1290
+ if ( file_exists(ABSPATH . 'wp-admin/includes/class-wp-comments-list-table.php') )
1291
+ require_once(ABSPATH . 'wp-admin/includes/class-wp-comments-list-table.php');
1292
+
1293
+ // As of WP Release 3.5 we can use the following.
1294
+ if ( version_compare( get_bloginfo('version'), '3.4.10', '>=' ) ) {
1295
+
1296
+ $table = new WP_Comments_List_Table( array( 'screen' => 'edit-comments' ) );
1297
+ $columns = $table->get_columns();
1298
+ }
1299
+
1300
+ // WP versions older then 3.5
1301
+ // @todo: make this deprecated
1302
+ else {
1303
+
1304
+ global $current_screen;
1305
+
1306
+ // save original
1307
+ $org_current_screen = $current_screen;
1308
+
1309
+ // prevent php warning
1310
+ if ( !isset($current_screen) ) $current_screen = new stdClass;
1311
+
1312
+ // overwrite current_screen global with our media id...
1313
+ $current_screen->id = 'edit-comments';
1314
+
1315
+ // init table object
1316
+ $wp_comment = new WP_Comments_List_Table;
1317
+
1318
+ // get comments
1319
+ $columns = $wp_comment->get_columns();
1320
+
1321
+ // reset current screen
1322
+ $current_screen = $org_current_screen;
1323
+ }
1324
+
1325
+ // change to uniform format
1326
+ $columns = $this->get_uniform_format($columns);
1327
+
1328
+ // add sorting to some of the default links columns
1329
+ $columns = $this->set_sorting_to_default_comments_columns($columns);
1330
+
1331
+ return apply_filters('cpac-default-comments-columns', $columns);
1332
+ }
1333
+
1334
+ /**
1335
+ * Add Sorting to WP default comments columns
1336
+ *
1337
+ * @since 1.4
1338
+ */
1339
+ private function set_sorting_to_default_comments_columns($columns)
1340
+ {
1341
+ // Comment
1342
+ if ( !empty($columns['comment']) ) {
1343
+ $columns['comment']['options']['sortorder'] = 'on';
1344
+ }
1345
+ return $columns;
1346
+ }
1347
+
1348
+ /**
1349
+ * Build uniform format for all columns
1350
+ *
1351
+ * @since 1.0
1352
+ */
1353
+ private function get_uniform_format($columns)
1354
+ {
1355
+ // we remove the checkbox column as an option...
1356
+ if ( isset($columns['cb']) )
1357
+ unset($columns['cb']);
1358
+
1359
+ // change to uniform format
1360
+ $uniform_columns = array();
1361
+ foreach ( (array) $columns as $id => $label ) {
1362
+ $hide_options = false;
1363
+ $type_label = $label;
1364
+
1365
+ // comment exception
1366
+ if ( 'comments' == $id ) {
1367
+ $label = '';
1368
+ $type_label = __('Comments', CPAC_TEXTDOMAIN);
1369
+ $hide_options = true;
1370
+ }
1371
+
1372
+ // user icon exception
1373
+ if ( $id == 'icon' ) {
1374
+ $type_label = __('Icon', CPAC_TEXTDOMAIN);
1375
+ }
1376
+
1377
+ $uniform_columns[$id] = array(
1378
+ 'label' => $label,
1379
+ 'state' => 'on',
1380
+ 'options' => array(
1381
+ 'type_label' => $type_label,
1382
+ 'hide_options' => $hide_options,
1383
+ 'class' => 'cpac-box-wp-native',
1384
+ )
1385
+ );
1386
+ }
1387
+ return $uniform_columns;
1388
+ }
1389
+
1390
+ /**
1391
+ * Custom posts columns
1392
+ *
1393
+ * @since 1.0
1394
+ */
1395
+ private function get_custom_posts_columns($post_type)
1396
+ {
1397
+ $custom_columns = array(
1398
+ 'column-featured_image' => array(
1399
+ 'label' => __('Featured Image', CPAC_TEXTDOMAIN)
1400
+ ),
1401
+ 'column-excerpt' => array(
1402
+ 'label' => __('Excerpt', CPAC_TEXTDOMAIN)
1403
+ ),
1404
+ 'column-order' => array(
1405
+ 'label' => __('Page Order', CPAC_TEXTDOMAIN)
1406
+ ),
1407
+ 'column-post_formats' => array(
1408
+ 'label' => __('Post Format', CPAC_TEXTDOMAIN)
1409
+ ),
1410
+ 'column-postid' => array(
1411
+ 'label' => __('ID', CPAC_TEXTDOMAIN)
1412
+ ),
1413
+ 'column-page-slug' => array(
1414
+ 'label' => __('Slug', CPAC_TEXTDOMAIN)
1415
+ ),
1416
+ 'column-attachment' => array(
1417
+ 'label' => __('Attachment', CPAC_TEXTDOMAIN)
1418
+ ),
1419
+ 'column-attachment-count' => array(
1420
+ 'label' => __('No. of Attachments', CPAC_TEXTDOMAIN)
1421
+ ),
1422
+ 'column-roles' => array(
1423
+ 'label' => __('Roles', CPAC_TEXTDOMAIN)
1424
+ ),
1425
+ 'column-status' => array(
1426
+ 'label' => __('Status', CPAC_TEXTDOMAIN)
1427
+ ),
1428
+ 'column-comment-status' => array(
1429
+ 'label' => __('Comment status', CPAC_TEXTDOMAIN)
1430
+ ),
1431
+ 'column-ping-status' => array(
1432
+ 'label' => __('Ping status', CPAC_TEXTDOMAIN)
1433
+ ),
1434
+ 'column-actions' => array(
1435
+ 'label' => __('Actions', CPAC_TEXTDOMAIN),
1436
+ 'options' => array(
1437
+ 'sortorder' => false
1438
+ )
1439
+ ),
1440
+ 'column-modified' => array(
1441
+ 'label' => __('Last modified', CPAC_TEXTDOMAIN)
1442
+ ),
1443
+ 'column-comment-count' => array(
1444
+ 'label' => __('Comment count', CPAC_TEXTDOMAIN)
1445
+ ),
1446
+ 'column-author-name' => array(
1447
+ 'label' => __('Display Author As', CPAC_TEXTDOMAIN),
1448
+ 'display_as' => ''
1449
+ ),
1450
+ 'column-before-moretag' => array(
1451
+ 'label' => __('Before More Tag', CPAC_TEXTDOMAIN)
1452
+ )
1453
+ );
1454
+
1455
+ // Word count support
1456
+ if ( post_type_supports($post_type, 'editor') ) {
1457
+ $custom_columns['column-word-count'] = array(
1458
+ 'label' => __('Word count', CPAC_TEXTDOMAIN)
1459
+ );
1460
+ }
1461
+
1462
+ // Sticky support
1463
+ if ( $post_type == 'post' ) {
1464
+ $custom_columns['column-sticky'] = array(
1465
+ 'label' => __('Sticky', CPAC_TEXTDOMAIN)
1466
+ );
1467
+ }
1468
+
1469
+ // Order support
1470
+ if ( post_type_supports($post_type, 'page-attributes') ) {
1471
+ $custom_columns['column-order'] = array(
1472
+ 'label' => __('Page Order', CPAC_TEXTDOMAIN),
1473
+ 'options' => array(
1474
+ 'type_label' => __('Order', CPAC_TEXTDOMAIN)
1475
+ )
1476
+ );
1477
+ }
1478
+
1479
+ // Page Template
1480
+ if ( $post_type == 'page' ) {
1481
+ $custom_columns['column-page-template'] = array(
1482
+ 'label' => __('Page Template', CPAC_TEXTDOMAIN)
1483
+ );
1484
+ }
1485
+
1486
+ // Post Formats
1487
+ if ( post_type_supports($post_type, 'post-formats') ) {
1488
+ $custom_columns['column-post_formats'] = array(
1489
+ 'label' => __('Post Format', CPAC_TEXTDOMAIN)
1490
+ );
1491
+ }
1492
+
1493
+ // Taxonomy support
1494
+ $taxonomies = get_object_taxonomies($post_type, 'objects');
1495
+ if ( $taxonomies ) {
1496
+ foreach ( $taxonomies as $tax_slug => $tax ) {
1497
+ if ( $tax_slug != 'post_tag' && $tax_slug != 'category' && $tax_slug != 'post_format' ) {
1498
+ $custom_columns['column-taxonomy-'.$tax->name] = array(
1499
+ 'label' => $tax->label,
1500
+ 'show_filter' => true,
1501
+ 'options' => array(
1502
+ 'type_label' => __('Taxonomy', CPAC_TEXTDOMAIN)
1503
+ )
1504
+ );
1505
+ }
1506
+ }
1507
+ }
1508
+
1509
+ // Custom Field support
1510
+ if ( $this->get_meta_by_type($post_type) ) {
1511
+ $custom_columns['column-meta-1'] = array(
1512
+ 'label' => __('Custom Field', CPAC_TEXTDOMAIN),
1513
+ 'field' => '',
1514
+ 'field_type' => '',
1515
+ 'before' => '',
1516
+ 'after' => '',
1517
+ 'options' => array(
1518
+ 'type_label' => __('Field', CPAC_TEXTDOMAIN),
1519
+ 'class' => 'cpac-box-metafield'
1520
+ )
1521
+ );
1522
+ }
1523
+
1524
+ // merge with defaults
1525
+ $custom_columns = $this->parse_defaults($custom_columns);
1526
+
1527
+ return apply_filters('cpac-custom-posts-columns', $custom_columns);
1528
+ }
1529
+
1530
+ /**
1531
+ * Custom users columns
1532
+ *
1533
+ * @since 1.1
1534
+ */
1535
+ private function get_custom_users_columns()
1536
+ {
1537
+ $custom_columns = array(
1538
+ 'column-user_id' => array(
1539
+ 'label' => __('User ID', CPAC_TEXTDOMAIN)
1540
+ ),
1541
+ 'column-nickname' => array(
1542
+ 'label' => __('Nickname', CPAC_TEXTDOMAIN)
1543
+ ),
1544
+ 'column-first_name' => array(
1545
+ 'label' => __('First name', CPAC_TEXTDOMAIN)
1546
+ ),
1547
+ 'column-last_name' => array(
1548
+ 'label' => __('Last name', CPAC_TEXTDOMAIN)
1549
+ ),
1550
+ 'column-user_url' => array(
1551
+ 'label' => __('Url', CPAC_TEXTDOMAIN)
1552
+ ),
1553
+ 'column-user_registered' => array(
1554
+ 'label' => __('Registered', CPAC_TEXTDOMAIN)
1555
+ ),
1556
+ 'column-user_description' => array(
1557
+ 'label' => __('Description', CPAC_TEXTDOMAIN)
1558
+ ),
1559
+ 'column-actions' => array(
1560
+ 'label' => __('Actions', CPAC_TEXTDOMAIN),
1561
+ 'options' => array(
1562
+ 'sortorder' => false
1563
+ )
1564
+ ),
1565
+ );
1566
+
1567
+ // User total number of posts
1568
+ foreach ( self::get_post_types() as $post_type ) {
1569
+ $label = $this->get_plural_name($post_type);
1570
+ $custom_columns['column-user_postcount-'.$post_type] = array(
1571
+ 'label' => __( sprintf('No. of %s',$label), CPAC_TEXTDOMAIN),
1572
+ 'options' => array(
1573
+ 'type_label' => __('Postcount', CPAC_TEXTDOMAIN)
1574
+ )
1575
+ );
1576
+ }
1577
+
1578
+ // Custom Field support
1579
+ $custom_columns['column-meta-1'] = array(
1580
+ 'label' => __('Custom Field', CPAC_TEXTDOMAIN),
1581
+ 'field' => '',
1582
+ 'field_type' => '',
1583
+ 'before' => '',
1584
+ 'after' => '',
1585
+ 'options' => array(
1586
+ 'type_label' => __('Field', CPAC_TEXTDOMAIN),
1587
+ 'class' => 'cpac-box-metafield'
1588
+ )
1589
+ );
1590
+
1591
+ // merge with defaults
1592
+ $custom_columns = $this->parse_defaults($custom_columns);
1593
+
1594
+ return apply_filters('cpac-custom-users-columns', $custom_columns);
1595
+ }
1596
+
1597
+ /**
1598
+ * Custom media columns
1599
+ *
1600
+ * @since 1.3
1601
+ */
1602
+ private function get_custom_media_columns()
1603
+ {
1604
+ $custom_columns = array(
1605
+ 'column-mediaid' => array(
1606
+ 'label' => __('ID', CPAC_TEXTDOMAIN)
1607
+ ),
1608
+ 'column-mime_type' => array(
1609
+ 'label' => __('Mime type', CPAC_TEXTDOMAIN)
1610
+ ),
1611
+ 'column-file_name' => array(
1612
+ 'label' => __('File name', CPAC_TEXTDOMAIN)
1613
+ ),
1614
+ 'column-dimensions' => array(
1615
+ 'label' => __('Dimensions', CPAC_TEXTDOMAIN)
1616
+ ),
1617
+ 'column-height' => array(
1618
+ 'label' => __('Height', CPAC_TEXTDOMAIN)
1619
+ ),
1620
+ 'column-width' => array(
1621
+ 'label' => __('Width', CPAC_TEXTDOMAIN)
1622
+ ),
1623
+ 'column-caption' => array(
1624
+ 'label' => __('Caption', CPAC_TEXTDOMAIN)
1625
+ ),
1626
+ 'column-description' => array(
1627
+ 'label' => __('Description', CPAC_TEXTDOMAIN)
1628
+ ),
1629
+ 'column-alternate_text' => array(
1630
+ 'label' => __('Alt', CPAC_TEXTDOMAIN)
1631
+ ),
1632
+ 'column-file_paths' => array(
1633
+ 'label' => __('Upload paths', CPAC_TEXTDOMAIN),
1634
+ 'options' => array(
1635
+ 'sortorder' => false
1636
+ )
1637
+ ),
1638
+ 'column-actions' => array(
1639
+ 'label' => __('Actions', CPAC_TEXTDOMAIN),
1640
+ 'options' => array(
1641
+ 'sortorder' => false
1642
+ )
1643
+ ),
1644
+ 'column-filesize' => array(
1645
+ 'label' => __('File size', CPAC_TEXTDOMAIN)
1646
+ )
1647
+ );
1648
+
1649
+ // Get extended image metadata, exif or iptc as available.
1650
+ // uses exif_read_data()
1651
+ if ( function_exists('exif_read_data') ) {
1652
+ $custom_columns = array_merge( $custom_columns, array(
1653
+ 'column-image-aperture' => array(
1654
+ 'label' => __('Aperture', CPAC_TEXTDOMAIN),
1655
+ 'options' => array(
1656
+ 'type_label' => __('Aperture EXIF', CPAC_TEXTDOMAIN)
1657
+ )
1658
+ ),
1659
+ 'column-image-credit' => array(
1660
+ 'label' => __('Credit', CPAC_TEXTDOMAIN),
1661
+ 'options' => array(
1662
+ 'type_label' => __('Credit EXIF', CPAC_TEXTDOMAIN)
1663
+ )
1664
+ ),
1665
+ 'column-image-camera' => array(
1666
+ 'label' => __('Camera', CPAC_TEXTDOMAIN),
1667
+ 'options' => array(
1668
+ 'type_label' => __('Camera EXIF', CPAC_TEXTDOMAIN)
1669
+ )
1670
+ ),
1671
+ 'column-image-caption' => array(
1672
+ 'label' => __('Caption', CPAC_TEXTDOMAIN),
1673
+ 'options' => array(
1674
+ 'type_label' => __('Caption EXIF', CPAC_TEXTDOMAIN)
1675
+ )
1676
+ ),
1677
+ 'column-image-created_timestamp' => array(
1678
+ 'label' => __('Timestamp', CPAC_TEXTDOMAIN),
1679
+ 'options' => array(
1680
+ 'type_label' => __('Timestamp EXIF', CPAC_TEXTDOMAIN)
1681
+ )
1682
+ ),
1683
+ 'column-image-copyright' => array(
1684
+ 'label' => __('Copyright', CPAC_TEXTDOMAIN),
1685
+ 'options' => array(
1686
+ 'type_label' => __('Copyright EXIF', CPAC_TEXTDOMAIN)
1687
+ )
1688
+ ),
1689
+ 'column-image-focal_length' => array(
1690
+ 'label' => __('Focal Length', CPAC_TEXTDOMAIN),
1691
+ 'options' => array(
1692
+ 'type_label' => __('Focal Length EXIF', CPAC_TEXTDOMAIN)
1693
+ )
1694
+ ),
1695
+ 'column-image-iso' => array(
1696
+ 'label' => __('ISO', CPAC_TEXTDOMAIN),
1697
+ 'options' => array(
1698
+ 'type_label' => __('ISO EXIF', CPAC_TEXTDOMAIN)
1699
+ )
1700
+ ),
1701
+ 'column-image-shutter_speed' => array(
1702
+ 'label' => __('Shutter Speed', CPAC_TEXTDOMAIN),
1703
+ 'options' => array(
1704
+ 'type_label' => __('Shutter Speed EXIF', CPAC_TEXTDOMAIN)
1705
+ )
1706
+ ),
1707
+ 'column-image-title' => array(
1708
+ 'label' => __('Title', CPAC_TEXTDOMAIN),
1709
+ 'options' => array(
1710
+ 'type_label' => __('Title EXIF', CPAC_TEXTDOMAIN)
1711
+ )
1712
+ )
1713
+ ));
1714
+ }
1715
+
1716
+ // Custom Field support
1717
+ if ( $this->get_meta_by_type('wp-media') ) {
1718
+ $custom_columns['column-meta-1'] = array(
1719
+ 'label' => __('Custom Field', CPAC_TEXTDOMAIN),
1720
+ 'field' => '',
1721
+ 'field_type' => '',
1722
+ 'before' => '',
1723
+ 'after' => '',
1724
+ 'options' => array(
1725
+ 'type_label' => __('Field', CPAC_TEXTDOMAIN),
1726
+ 'class' => 'cpac-box-metafield'
1727
+ )
1728
+ );
1729
+ }
1730
+
1731
+ // merge with defaults
1732
+ $custom_columns = $this->parse_defaults($custom_columns);
1733
+
1734
+ return apply_filters('cpac-custom-media-columns', $custom_columns);
1735
+ }
1736
+
1737
+ /**
1738
+ * Custom links columns
1739
+ *
1740
+ * @since 1.3.1
1741
+ */
1742
+ private function get_custom_links_columns()
1743
+ {
1744
+ $custom_columns = array(
1745
+ 'column-link_id' => array (
1746
+ 'label' => __('ID', CPAC_TEXTDOMAIN)
1747
+ ),
1748
+ 'column-description' => array (
1749
+ 'label' => __('Description', CPAC_TEXTDOMAIN)
1750
+ ),
1751
+ 'column-image' => array(
1752
+ 'label' => __('Image', CPAC_TEXTDOMAIN)
1753
+ ),
1754
+ 'column-target' => array(
1755
+ 'label' => __('Target', CPAC_TEXTDOMAIN)
1756
+ ),
1757
+ 'column-owner' => array(
1758
+ 'label' => __('Owner', CPAC_TEXTDOMAIN)
1759
+ ),
1760
+ 'column-notes' => array(
1761
+ 'label' => __('Notes', CPAC_TEXTDOMAIN)
1762
+ ),
1763
+ 'column-rss' => array(
1764
+ 'label' => __('Rss', CPAC_TEXTDOMAIN)
1765
+ ),
1766
+ 'column-length' => array(
1767
+ 'label' => __('Length', CPAC_TEXTDOMAIN)
1768
+ ),
1769
+ 'column-actions' => array(
1770
+ 'label' => __('Actions', CPAC_TEXTDOMAIN),
1771
+ 'options' => array(
1772
+ 'sortorder' => false
1773
+ )
1774
+ )
1775
+ );
1776
+
1777
+ // merge with defaults
1778
+ $custom_columns = $this->parse_defaults($custom_columns);
1779
+
1780
+ return apply_filters('cpac-custom-links-columns', $custom_columns);
1781
+ }
1782
+
1783
+ /**
1784
+ * Custom comments columns
1785
+ *
1786
+ * @since 1.3.1
1787
+ */
1788
+ private function get_custom_comments_columns()
1789
+ {
1790
+ $custom_columns = array(
1791
+ 'column-comment_id' => array(
1792
+ 'label' => __('ID', CPAC_TEXTDOMAIN)
1793
+ ),
1794
+ 'column-author_author' => array(
1795
+ 'label' => __('Author Name', CPAC_TEXTDOMAIN)
1796
+ ),
1797
+ 'column-author_avatar' => array(
1798
+ 'label' => __('Avatar', CPAC_TEXTDOMAIN)
1799
+ ),
1800
+ 'column-author_url' => array(
1801
+ 'label' => __('Author url', CPAC_TEXTDOMAIN)
1802
+ ),
1803
+ 'column-author_ip' => array(
1804
+ 'label' => __('Author IP', CPAC_TEXTDOMAIN)
1805
+ ),
1806
+ 'column-author_email' => array(
1807
+ 'label' => __('Author email', CPAC_TEXTDOMAIN)
1808
+ ),
1809
+ 'column-reply_to' => array(
1810
+ 'label' => __('In Reply To', CPAC_TEXTDOMAIN),
1811
+ 'options' => array(
1812
+ 'sortorder' => false
1813
+ )
1814
+ ),
1815
+ 'column-approved' => array(
1816
+ 'label' => __('Approved', CPAC_TEXTDOMAIN)
1817
+ ),
1818
+ 'column-date' => array(
1819
+ 'label' => __('Date', CPAC_TEXTDOMAIN)
1820
+ ),
1821
+ 'column-date_gmt' => array(
1822
+ 'label' => __('Date GMT', CPAC_TEXTDOMAIN)
1823
+ ),
1824
+ 'column-agent' => array(
1825
+ 'label' => __('Agent', CPAC_TEXTDOMAIN)
1826
+ ),
1827
+ 'column-excerpt' => array(
1828
+ 'label' => __('Excerpt', CPAC_TEXTDOMAIN)
1829
+ ),
1830
+ 'column-actions' => array(
1831
+ 'label' => __('Actions', CPAC_TEXTDOMAIN),
1832
+ 'options' => array(
1833
+ 'sortorder' => false
1834
+ )
1835
+ ),
1836
+ 'column-word-count' => array(
1837
+ 'label' => __('Word count', CPAC_TEXTDOMAIN),
1838
+ 'options' => array(
1839
+ 'sortorder' => false
1840
+ )
1841
+ )
1842
+ );
1843
+
1844
+ // Custom Field support
1845
+ if ( $this->get_meta_by_type('wp-comments') ) {
1846
+ $custom_columns['column-meta-1'] = array(
1847
+ 'label' => __('Custom Field', CPAC_TEXTDOMAIN),
1848
+ 'field' => '',
1849
+ 'field_type' => '',
1850
+ 'before' => '',
1851
+ 'after' => '',
1852
+ 'options' => array(
1853
+ 'type_label' => __('Field', CPAC_TEXTDOMAIN),
1854
+ 'class' => 'cpac-box-metafield',
1855
+ 'sortorder' => false,
1856
+ )
1857
+ );
1858
+ }
1859
+
1860
+ // merge with defaults
1861
+ $custom_columns = $this->parse_defaults($custom_columns);
1862
+
1863
+ return apply_filters('cpac-custom-comments-columns', $custom_columns);
1864
+ }
1865
+
1866
+ /**
1867
+ * Parse defaults
1868
+ *
1869
+ * @since 1.1
1870
+ */
1871
+ private function parse_defaults($columns)
1872
+ {
1873
+ // default arguments
1874
+ $defaults = array(
1875
+
1876
+ // stored values
1877
+ 'label' => '', // custom label
1878
+ 'state' => '', // display state
1879
+ 'width' => '', // column width
1880
+
1881
+ // static values
1882
+ 'options' => array(
1883
+ 'type_label' => __('Custom', CPAC_TEXTDOMAIN),
1884
+ 'hide_options' => false,
1885
+ 'class' => 'cpac-box-custom',
1886
+ 'sortorder' => 'on',
1887
+ )
1888
+ );
1889
+
1890
+ // parse args
1891
+ foreach ( $columns as $k => $column ) {
1892
+ $c[$k] = wp_parse_args( $column, $defaults);
1893
+
1894
+ // parse options args
1895
+ if ( isset($column['options']) )
1896
+ $c[$k]['options'] = wp_parse_args( $column['options'], $defaults['options']);
1897
+
1898
+ // set type label
1899
+ if ( empty($column['options']['type_label']) && !empty($column['label']) )
1900
+ $c[$k]['options']['type_label'] = $column['label'];
1901
+ }
1902
+
1903
+ return $c;
1904
+ }
1905
+
1906
+ /**
1907
+ * Admin requests for orderby column
1908
+ *
1909
+ * @since 1.0
1910
+ */
1911
+ public static function get_stored_columns($type)
1912
+ {
1913
+ // get plugin options
1914
+ $options = get_option('cpac_options');
1915
+
1916
+ // get saved columns
1917
+ if ( !empty($options['columns'][$type]) )
1918
+ return $options['columns'][$type];
1919
+
1920
+ return false;
1921
+ }
1922
+
1923
+ /**
1924
+ * Post Type Menu
1925
+ *
1926
+ * @since 1.0
1927
+ */
1928
+ private function get_menu()
1929
+ {
1930
+ // set
1931
+ $menu = '';
1932
+ $count = 1;
1933
+
1934
+ // referer
1935
+ $referer = ! empty($_REQUEST['cpac_type']) ? $_REQUEST['cpac_type'] : '';
1936
+
1937
+ // loop
1938
+ foreach ( $this->get_types() as $type ) {
1939
+ $label = $this->get_singular_name($type);
1940
+ $clean_label = $this->sanitize_string($type);
1941
+
1942
+ // divider
1943
+ $divider = $count++ == 1 ? '' : ' | ';
1944
+
1945
+ // current
1946
+ $current = '';
1947
+ if ( $this->is_menu_type_current($type) )
1948
+ $current = ' class="current"';
1949
+
1950
+ // menu list
1951
+ $menu .= "
1952
+ <li>{$divider}<a{$current} href='#cpac-box-{$clean_label}'>{$label}</a></li>
1953
+ ";
1954
+ }
1955
+
1956
+ // settings url
1957
+ $class_current_settings = $this->is_menu_type_current('plugin_settings') ? ' current': '';
1958
+
1959
+ // options button
1960
+ $options_btn = "<a href='#cpac-box-plugin_settings' class='cpac-settings-link{$class_current_settings}'>".__('Addons', CPAC_TEXTDOMAIN)."</a>";
1961
+ //$options_btn = '';
1962
+
1963
+ return "
1964
+ <div class='cpac-menu'>
1965
+ <ul class='subsubsub'>
1966
+ {$menu}
1967
+ </ul>
1968
+ {$options_btn}
1969
+ </div>
1970
+ ";
1971
+ }
1972
+
1973
+ /**
1974
+ * Checks if menu type is currently viewed
1975
+ *
1976
+ * @since 1.0
1977
+ */
1978
+ private function is_menu_type_current( $type )
1979
+ {
1980
+ // referer
1981
+ $referer = ! empty($_REQUEST['cpac_type']) ? $_REQUEST['cpac_type'] : '';
1982
+
1983
+ // get label
1984
+ $clean_label = $this->sanitize_string($type);
1985
+
1986
+ // get first element from post-types
1987
+ $first = array_shift( array_values($this->post_types) );
1988
+
1989
+ // display the page that was being viewed before saving
1990
+ if ( $referer ) {
1991
+ if ( $referer == 'cpac-box-'.$clean_label ) {
1992
+ return true;
1993
+ }
1994
+
1995
+ // settings page has not yet been saved
1996
+ } elseif ( $first == $type ) {
1997
+ return true;
1998
+ }
1999
+
2000
+ return false;
2001
+ }
2002
+
2003
+ /**
2004
+ * Get singular name of post type
2005
+ *
2006
+ * @since 1.0
2007
+ */
2008
+ private function get_singular_name( $type )
2009
+ {
2010
+ // Links
2011
+ if ( $type == 'wp-links' )
2012
+ $label = __('Links');
2013
+
2014
+ // Comments
2015
+ elseif ( $type == 'wp-comments' )
2016
+ $label = __('Comments');
2017
+
2018
+ // Users
2019
+ elseif ( $type == 'wp-users' )
2020
+ $label = __('Users');
2021
+
2022
+ // Media
2023
+ elseif ( $type == 'wp-media' )
2024
+ $label = __('Media Library');
2025
+
2026
+ // Posts
2027
+ else {
2028
+ $posttype_obj = get_post_type_object($type);
2029
+ $label = $posttype_obj->labels->singular_name;
2030
+ }
2031
+
2032
+ return $label;
2033
+ }
2034
+
2035
+ /**
2036
+ * Get plural name of post type
2037
+ *
2038
+ * @since 1.3.1
2039
+ */
2040
+ private function get_plural_name( $type )
2041
+ {
2042
+ $posttype_obj = get_post_type_object($type);
2043
+ if ( $posttype_obj )
2044
+ return $posttype_obj->labels->name;
2045
+
2046
+ return false;
2047
+ }
2048
+
2049
+ /**
2050
+ * Get screen link to overview screen
2051
+ *
2052
+ * @since 1.3.1
2053
+ */
2054
+ private function get_type_screen_link( $type )
2055
+ {
2056
+ // Links
2057
+ if ( $type == 'wp-comments' )
2058
+ $link = get_admin_url() . 'edit-comments.php';
2059
+
2060
+ // Links
2061
+ if ( $type == 'wp-links' )
2062
+ $link = get_admin_url() . 'link-manager.php';
2063
+
2064
+ // Users
2065
+ if ( $type == 'wp-users' )
2066
+ $link = get_admin_url() . 'users.php';
2067
+
2068
+ // Media
2069
+ elseif ( $type == 'wp-media' )
2070
+ $link = get_admin_url() . 'upload.php';
2071
+
2072
+ // Posts
2073
+ else
2074
+ $link = get_admin_url() . "edit.php?post_type={$type}";
2075
+
2076
+ return $link;
2077
+ }
2078
+
2079
+ /**
2080
+ * Sanitize label
2081
+ *
2082
+ * Uses intern wordpress function esc_url so it matches the label sorting url.
2083
+ *
2084
+ * @since 1.0
2085
+ */
2086
+ protected function sanitize_string($string)
2087
+ {
2088
+ $string = esc_url($string);
2089
+ $string = str_replace('http://','', $string);
2090
+ $string = str_replace('https://','', $string);
2091
+
2092
+ return $string;
2093
+ }
2094
+
2095
+ /**
2096
+ * Checks if column-meta key exists
2097
+ *
2098
+ * @since 1.0
2099
+ */
2100
+ public static function is_column_meta( $id = '' )
2101
+ {
2102
+ if ( strpos($id, 'column-meta-') !== false )
2103
+ return true;
2104
+
2105
+ return false;
2106
+ }
2107
+
2108
+ /**
2109
+ * Get the posttype from columnname
2110
+ *
2111
+ * @since 1.3.1
2112
+ */
2113
+ public static function get_posttype_by_postcount_column( $id = '' )
2114
+ {
2115
+ if ( strpos($id, 'column-user_postcount-') !== false )
2116
+ return str_replace('column-user_postcount-', '', $id);
2117
+
2118
+ return false;
2119
+ }
2120
+
2121
+ /**
2122
+ * Get column value of post attachments
2123
+ *
2124
+ * @since 1.2.1
2125
+ */
2126
+ public static function get_attachment_ids( $post_id )
2127
+ {
2128
+ return get_posts(array(
2129
+ 'post_type' => 'attachment',
2130
+ 'numberposts' => -1,
2131
+ 'post_status' => null,
2132
+ 'post_parent' => $post_id,
2133
+ 'fields' => 'ids'
2134
+ ));
2135
+ }
2136
+
2137
+ /**
2138
+ * Strip tags and trim
2139
+ *
2140
+ * @since 1.3
2141
+ */
2142
+ public static function strip_trim($string)
2143
+ {
2144
+ return trim(strip_tags($string));
2145
+ }
2146
+
2147
+ /**
2148
+ * Admin body class
2149
+ *
2150
+ * @since 1.4
2151
+ */
2152
+ function admin_class( $classes )
2153
+ {
2154
+ global $current_screen;
2155
+
2156
+ // we dont need the 'edit-' part
2157
+ $screen = str_replace('edit-', '', $current_screen->id);
2158
+
2159
+ // media library exception
2160
+ if ( $current_screen->base == 'upload' && $current_screen->id == 'upload' ) {
2161
+ $screen = 'media';
2162
+ }
2163
+
2164
+ // link exception
2165
+ if ( $current_screen->base == 'link-manager' && $current_screen->id == 'link-manager' ) {
2166
+ $screen = 'links';
2167
+ }
2168
+
2169
+ // loop the available types
2170
+ foreach ( $this->get_types() as $type => $label ) {
2171
+
2172
+ // match against screen or wp-screen
2173
+ if ( $type == $screen || $type == "wp-{$screen}" )
2174
+ $classes .= " cp-{$type}";
2175
+ }
2176
+
2177
+ return $classes;
2178
+ }
2179
+
2180
+
2181
+ /**
2182
+ * Admin CSS for Column width
2183
+ *
2184
+ * @since 1.4
2185
+ */
2186
+ function admin_css()
2187
+ {
2188
+ $css = '';
2189
+
2190
+ // loop throug the available types...
2191
+ foreach ( $this->get_types() as $type ) {
2192
+ $cols = self::get_stored_columns($type);
2193
+ if ( $cols ) {
2194
+
2195
+ // loop through each available column...
2196
+ foreach ( $cols as $col_name => $col ) {
2197
+
2198
+ // and check for stored width and add it to the css
2199
+ if (!empty($col['width']) && is_numeric($col['width']) && $col['width'] > 0 ) {
2200
+ $css .= ".cp-{$type} .wrap table th.column-{$col_name} { width: {$col['width']}% !important; }";
2201
+ }
2202
+ }
2203
+ }
2204
+ }
2205
+
2206
+ echo "<style type='text/css'>{$css}</style>";
2207
+ }
2208
+
2209
+ /**
2210
+ * Ajax activation
2211
+ *
2212
+ * @since 1.3.1
2213
+ */
2214
+ public function ajax_activation()
2215
+ {
2216
+ // keys
2217
+ $key = $_POST['key'];
2218
+ $type = $_POST['type'];
2219
+
2220
+ $licence = new cpac_licence( $type );
2221
+
2222
+ // update key
2223
+ if ( $key == 'remove' ) {
2224
+ $licence->remove_license_key();
2225
+ }
2226
+
2227
+ // set license key
2228
+ elseif ( $licence->check_remote_key( $key ) ) {
2229
+
2230
+ // set key
2231
+ $licence->set_license_key( $key );
2232
+
2233
+ // returned masked key
2234
+ echo json_encode( $licence->get_masked_license_key() );
2235
+ }
2236
+
2237
+ exit;
2238
+ }
2239
+
2240
+ /**
2241
+ * Add help tabs
2242
+ *
2243
+ * @since 1.3
2244
+ */
2245
+ public function help_tabs($page)
2246
+ {
2247
+ $screen = get_current_screen();
2248
+
2249
+ if ( $screen->id != $this->admin_page || ! method_exists($screen,'add_help_tab') )
2250
+ return;
2251
+
2252
+ $admin_url = get_admin_url();
2253
+
2254
+ // add help content
2255
+ $tabs = array(
2256
+ array(
2257
+ 'title' => 'Overview',
2258
+ 'content' => "
2259
+ <h5>Codepress Admin Columns</h5>
2260
+ <p>
2261
+ This plugin is for adding and removing additional columns to the administration screens for post(types), pages, media library, comments, links and users. Change the column's label and reorder them.
2262
+ </p>
2263
+
2264
+ "
2265
+ ),
2266
+ array(
2267
+ 'title' => 'Basics',
2268
+ 'content' => "
2269
+ <h5>Show / Hide</h5>
2270
+ <p>
2271
+ You can switch columns on or off by cliking on the checkbox. This will show or hide each column heading.
2272
+ </p>
2273
+ <h5>Change order</h5>
2274
+ <p>
2275
+ By dragging the columns you can change the order which they will appear in.
2276
+ </p>
2277
+ <h5>Change label</h5>
2278
+ <p>
2279
+ By clicking on the triangle you will see the column options. Here you can change each label of the columns heading.
2280
+ </p>
2281
+ <h5>Change coluimn width</h5>
2282
+ <p>
2283
+ By clicking on the triangle you will see the column options. By using the draggable slider yo can set the width of the columns in percentages.
2284
+ </p>
2285
+ "
2286
+ ),
2287
+ array(
2288
+ 'title' => 'Custom Field',
2289
+ 'content' => "
2290
+ <h5>'Custom Field' column</h5>
2291
+ <p>
2292
+ The custom field colum uses the custom fields from posts and users. There are 8 types which you can set.
2293
+ </p>
2294
+ <ul>
2295
+ <li><strong>Default</strong><br/>Value: Can be either a string or array. Arrays will be flattened and values are seperated by a ',' comma.</li>
2296
+ <li><strong>Image</strong><br/>Value: should only contain an image URL.</li>
2297
+ <li><strong>Media Library Icon</strong><br/>Value: should only contain Attachment IDs ( seperated by ',' ).</li>
2298
+ <li><strong>Excerpt</strong><br/>Value: This will show the first 20 words of the Post content.</li>
2299
+ <li><strong>Multiple Values</strong><br/>Value: should be an array. This will flatten any ( multi dimensional ) array.</li>
2300
+ <li><strong>Numeric</strong><br/>Value: Integers only.<br/>If you have the 'sorting addon' this will be used for sorting, so you can sort your posts on numeric (custom field) values.</li>
2301
+ <li><strong>Date</strong><br/>Value: Can be unix time stamp of date format as described in the <a href='http://codex.wordpress.org/Formatting_Date_and_Time'>Codex</a>. You can change the outputted date format at the <a href='{$admin_url}options-general.php'>general settings</a> page.</li>
2302
+ <li><strong>Post Titles</strong><br/>Value: can be one or more Post ID's (seperated by ',').</li>
2303
+ </ul>
2304
+ "
2305
+ )
2306
+ );
2307
+
2308
+ foreach ( $tabs as $k => $tab ) {
2309
+ $screen->add_help_tab(array(
2310
+ 'id' => 'cpac-tab-'.$k, // unique id
2311
+ 'title' => $tab['title'], // label
2312
+ 'content' => $tab['content'], // body
2313
+ ));
2314
+ }
2315
+ }
2316
+
2317
+ /**
2318
+ * Plugin Settings
2319
+ *
2320
+ * @since 1.3.1
2321
+ */
2322
+ private function plugin_settings()
2323
+ {
2324
+ $class_current_settings = $this->is_menu_type_current('plugin_settings') ? ' current' : ' hidden'; '';
2325
+
2326
+ /** Sortable */
2327
+ $masked_key = '';
2328
+ $class_sortorder_activate = '';
2329
+ $class_sortorder_deactivate = ' hidden';
2330
+
2331
+ // is unlocked
2332
+ $licence = new cpac_licence('sortable');
2333
+
2334
+ if ( $licence->is_unlocked() ) {
2335
+ $masked_key = $licence->get_masked_license_key('sortable');
2336
+ $class_sortorder_activate = ' hidden';
2337
+ $class_sortorder_deactivate = '';
2338
+ }
2339
+
2340
+ // find out more
2341
+ $find_out_more = "<a href='{$this->codepress_url}/sortorder-addon/' class='button-primary alignright' target='_blank'>".__('find out more', CPAC_TEXTDOMAIN)." &raquo</a>";
2342
+
2343
+ // info box
2344
+ $sortable_tooltip = "
2345
+ <p>".__('This will make all of the new columns support sorting', CPAC_TEXTDOMAIN).".</p>
2346
+ <p>".__('By default WordPress let\'s you sort by title, date, comments and author. This will make you be able to <strong>sort by any column of any type!</strong>', CPAC_TEXTDOMAIN)."</p>
2347
+ <p>".__('Perfect for sorting your articles, media files, comments, links and users', CPAC_TEXTDOMAIN).".</p>
2348
+ <p class='description'>".__('(columns that are added by other plugins are not supported)', CPAC_TEXTDOMAIN).".</p>
2349
+ <img src='" . CPAC_URL.'/assets/images/addon_sortable_1.png' . "' alt='' />
2350
+ {$find_out_more}
2351
+ ";
2352
+
2353
+ // addons
2354
+ $addons = "
2355
+ <tr>
2356
+ <td colspan='2'>
2357
+ <h2>".__('Activate Add-ons', CPAC_TEXTDOMAIN)."</h2>
2358
+ <p>".__('Add-ons can be unlocked by purchasing a license key. Each key can be used on multiple sites', CPAC_TEXTDOMAIN)." <a target='_blank' href='{$this->codepress_url}/sortorder-addon/'>Visit the Plugin Store</a>.</p>
2359
+ <table class='widefat addons'>
2360
+ <thead>
2361
+ <tr>
2362
+ <th class='activation_type'>".__('Addon', CPAC_TEXTDOMAIN)."</th>
2363
+ <th class='activation_status'>".__('Status', CPAC_TEXTDOMAIN)."</th>
2364
+ <th class='activation_code'>".__('Activation Code', CPAC_TEXTDOMAIN)."</th>
2365
+ <th class='activation_more'></th>
2366
+ </tr>
2367
+ </thead>
2368
+ <tbody>
2369
+ <tr id='cpac-activation-sortable' class='last'>
2370
+ <td class='activation_type'>
2371
+ <span>" . __('Sortorder', CPAC_TEXTDOMAIN) . "</span>
2372
+ <div class='cpac-tooltip hidden'>
2373
+ <div class='qtip_title'>" . __('Sortorder', CPAC_TEXTDOMAIN) . "</div>
2374
+ <div class='qtip_content'>
2375
+ <p>" . __($sortable_tooltip, CPAC_TEXTDOMAIN) . "</p>
2376
+ </div>
2377
+ </div>
2378
+ </td>
2379
+ <td class='activation_status'>
2380
+ <div class='activate{$class_sortorder_activate}'>
2381
+ " . __('Inactive', CPAC_TEXTDOMAIN) . "
2382
+ </div>
2383
+ <div class='deactivate{$class_sortorder_deactivate}'>
2384
+ " . __('Active', CPAC_TEXTDOMAIN) . "
2385
+ </div>
2386
+ </td>
2387
+ <td class='activation_code'>
2388
+ <div class='activate{$class_sortorder_activate}'>
2389
+ <input type='text' value='" . __('Fill in your activation code', CPAC_TEXTDOMAIN) . "' name='cpac-sortable-key'>
2390
+ <a href='javascript:;' class='button'>" . __('Activate', CPAC_TEXTDOMAIN) . "<span></span></a>
2391
+ </div>
2392
+ <div class='deactivate{$class_sortorder_deactivate}'>
2393
+ <span class='masked_key'>{$masked_key}</span>
2394
+ <a href='javascript:;' class='button'>" . __('Deactivate', CPAC_TEXTDOMAIN) . "<span></span></a>
2395
+ </div>
2396
+ <div class='activation-error-msg'></div>
2397
+ </td>
2398
+ <td class='activation_more'>{$find_out_more}</td>
2399
+ </tr><!-- #cpac-activation-sortable -->
2400
+ </tbody>
2401
+ </table>
2402
+ <div class='addon-translation-string hidden'>
2403
+ <span class='tstring-fill-in'>" . __('Enter your activation code', CPAC_TEXTDOMAIN) . "</span>
2404
+ <span class='tstring-unrecognised'>" . __('Activation code unrecognised', CPAC_TEXTDOMAIN) . "</span>
2405
+ </div>
2406
+ </td>
2407
+ </tr>
2408
+ ";
2409
+
2410
+ // general options
2411
+ $general_options = "
2412
+ <!--
2413
+ <tr class='last'>
2414
+ <td colspan='2'>
2415
+ <h2>Options</h2>
2416
+ <ul class='cpac-options'>
2417
+ <li>
2418
+ <div class='cpac-option-label'>Thumbnail size</div>
2419
+ <div class='cpac-option-inputs'>
2420
+ <input type='text' id='thumbnail_size_w' class='small-text' name='cpac_options[settings][thumb_width]' value='80'/>
2421
+ <label for='thumbnail_size_w'>Width</label>
2422
+ <br/>
2423
+ <input type='text' id='thumbnail_size_h' class='small-text' name='cpac_options[settings][thumb_height]' value='80'/>
2424
+ <label for='thumbnail_size_h'>Height</label>
2425
+ </div>
2426
+ </li>
2427
+ <li>
2428
+ <div class='cpac-option-label'>Excerpt length</div>
2429
+ <div class='cpac-option-inputs'>
2430
+
2431
+ <input type='text' id='excerpt_length' class='small-text' name='cpac_options[settings][excerpt_length]' value='15'/>
2432
+ <label for='excerpt_length'>Number of words</label>
2433
+ </div>
2434
+ </li>
2435
+ </ul>
2436
+ </td>
2437
+ </tr>
2438
+ -->
2439
+ ";
2440
+
2441
+ // settings
2442
+ $row = "
2443
+ <tr id='cpac-box-plugin_settings' valign='top' class='cpac-box-row {$class_current_settings}'>
2444
+ <td colspan='2'>
2445
+ <table class='nopadding'>
2446
+ {$addons}
2447
+ {$general_options}
2448
+ </table>
2449
+ </td>
2450
+ </tr><!-- #cpac-box-plugin_settings -->
2451
+ ";
2452
+
2453
+ return $row;
2454
+ }
2455
+
2456
+ /**
2457
+ * Get post count
2458
+ *
2459
+ * @since 1.3.1
2460
+ */
2461
+ public static function get_post_count( $post_type, $user_id )
2462
+ {
2463
+ global $wpdb;
2464
+
2465
+ if ( ! post_type_exists($post_type) || empty($user_id) )
2466
+ return false;
2467
+
2468
+ $sql = "
2469
+ SELECT COUNT(ID)
2470
+ FROM {$wpdb->posts}
2471
+ WHERE post_status = 'publish'
2472
+ AND post_author = %d
2473
+ AND post_type = %s
2474
+ ";
2475
+
2476
+ return $wpdb->get_var( $wpdb->prepare($sql, $user_id, $post_type) );
2477
+ }
2478
+
2479
+ /**
2480
+ * Settings Page Template.
2481
+ *
2482
+ * This function in conjunction with others uses the WordPress
2483
+ * Settings API to create a settings page where users can adjust
2484
+ * the behaviour of this plugin.
2485
+ *
2486
+ * @since 1.0
2487
+ */
2488
+ public function plugin_settings_page()
2489
+ {
2490
+ // loop through post types
2491
+ $rows = '';
2492
+ foreach ( $this->get_types() as $type ) {
2493
+
2494
+ // post type label
2495
+ $label = $this->get_singular_name($type);
2496
+
2497
+ // id
2498
+ $id = $this->sanitize_string($type);
2499
+
2500
+ // build draggable boxes
2501
+ $boxes = $this->get_column_boxes($type);
2502
+
2503
+ // class
2504
+ $class = $this->is_menu_type_current($type) ? ' current' : ' hidden';
2505
+
2506
+ $rows .= "
2507
+ <tr id='cpac-box-{$id}' valign='top' class='cpac-box-row{$class}'>
2508
+ <th class='cpac_post_type' scope='row'>
2509
+ {$label}
2510
+ </th>
2511
+ <td>
2512
+ <h3 class='cpac_post_type hidden'>{$label}</h3>
2513
+ {$boxes}
2514
+ </td>
2515
+ </tr>
2516
+ ";
2517
+ }
2518
+
2519
+ // General Setttings
2520
+ $general_settings = $this->plugin_settings();
2521
+
2522
+ // Post Type Menu
2523
+ $menu = $this->get_menu();
2524
+
2525
+ // Help screen message
2526
+ $help_text = '';
2527
+ if ( version_compare( get_bloginfo('version'), '3.2', '>' ) )
2528
+ $help_text = '<p>'.__('You will find a short overview at the <strong>Help</strong> section in the top-right screen.', CPAC_TEXTDOMAIN).'</p>';
2529
+
2530
+ // find out more
2531
+ $find_out_more = "<a href='{$this->codepress_url}/sortorder-addon/' class='alignright green' target='_blank'>".__('find out more', CPAC_TEXTDOMAIN)." &raquo</a>";
2532
+
2533
+ ?>
2534
+ <div id="cpac" class="wrap">
2535
+ <?php screen_icon(CPAC_SLUG) ?>
2536
+ <h2><?php _e('Codepress Admin Columns', CPAC_TEXTDOMAIN); ?></h2>
2537
+ <?php echo $menu ?>
2538
+
2539
+ <div class="postbox-container cpac-col-right">
2540
+ <div class="metabox-holder">
2541
+ <div class="meta-box-sortables">
2542
+
2543
+ <div id="addons-cpac-settings" class="postbox">
2544
+ <div title="Click to toggle" class="handlediv"><br></div>
2545
+ <h3 class="hndle">
2546
+ <span><?php _e('Get the Addon', CPAC_TEXTDOMAIN) ?></span>
2547
+ </h3>
2548
+ <div class="inside">
2549
+ <p><?php _e('By default WordPress let\'s you only sort by title, date, comments and author.', CPAC_TEXTDOMAIN) ?></p>
2550
+ <p><?php _e('Make <strong>all columns</strong> of <strong>all types</strong> within the plugin support sorting &#8212; with the sorting addon.', CPAC_TEXTDOMAIN) ?></p>
2551
+ <p class="description"><?php _e('(columns that are added by other plugins are not supported)', CPAC_TEXTDOMAIN) ?>.</p>
2552
+ <?php echo $find_out_more ?>
2553
+ </div>
2554
+ </div><!-- addons-cpac-settings -->
2555
+
2556
+ <div id="likethisplugin-cpac-settings" class="postbox">
2557
+ <div title="Click to toggle" class="handlediv"><br></div>
2558
+ <h3 class="hndle">
2559
+ <span><?php _e('Like this plugin?', CPAC_TEXTDOMAIN) ?></span>
2560
+ </h3>
2561
+ <div class="inside">
2562
+ <p><?php _e('Why not do any or all of the following', CPAC_TEXTDOMAIN) ?>:</p>
2563
+ <ul>
2564
+ <li><a href="<?php echo $this->plugins_url ?>"><?php _e('Give it a 5 star rating on WordPress.org.', CPAC_TEXTDOMAIN) ?></a></li>
2565
+ <li><a href="<?php echo $this->codepress_url ?>/"><?php _e('Link to it so other folks can find out about it.', CPAC_TEXTDOMAIN) ?></a></li>
2566
+ <li class="donate_link"><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=ZDZRSYLQ4Z76J"><?php _e('Donate a token of your appreciation.', CPAC_TEXTDOMAIN) ?></a></li>
2567
+ </ul>
2568
+ </div>
2569
+ </div><!-- likethisplugin-cpac-settings -->
2570
+
2571
+ <div id="latest-news-cpac-settings" class="postbox">
2572
+ <div title="Click to toggle" class="handlediv"><br></div>
2573
+ <h3 class="hndle">
2574
+ <span><?php _e('Follow us', CPAC_TEXTDOMAIN) ?></span>
2575
+ </h3>
2576
+ <div class="inside">
2577
+ <ul>
2578
+ <li class="twitter"><a href="http://twitter.com/codepressNL"><?php _e('Follow Codepress on Twitter.', CPAC_TEXTDOMAIN) ?></a></li>
2579
+ <li class="facebook"><a href="https://www.facebook.com/codepressNL"><?php _e('Like Codepress on Facebook.', CPAC_TEXTDOMAIN) ?></a></li>
2580
+
2581
+ </ul>
2582
+ </div>
2583
+ </div><!-- latest-news-cpac-settings -->
2584
+
2585
+ <div id="side-cpac-settings" class="postbox">
2586
+ <div title="Click to toggle" class="handlediv"><br></div>
2587
+ <h3 class="hndle">
2588
+ <span><?php _e('Need support?', CPAC_TEXTDOMAIN) ?></span>
2589
+ </h3>
2590
+ <div class="inside">
2591
+ <?php echo $help_text ?>
2592
+ <p><?php printf(__('If you are having problems with this plugin, please talk about them in the <a href="%s">Support forums</a> or send me an email %s.', CPAC_TEXTDOMAIN), $this->wordpress_url, '<a href="mailto:info@codepress.nl">info@codepress.nl</a>' );?></p>
2593
+ <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>.", CPAC_TEXTDOMAIN), "{$this->codepress_url}/feedback");?></p>
2594
+ </div>
2595
+ </div><!-- side-cpac-settings -->
2596
+
2597
+ </div>
2598
+ </div>
2599
+ </div><!-- .postbox-container -->
2600
+
2601
+ <div class="postbox-container cpac-col-left">
2602
+ <div class="metabox-holder">
2603
+ <div class="meta-box-sortables">
2604
+
2605
+ <div id="general-cpac-settings" class="postbox">
2606
+ <div title="Click to toggle" class="handlediv"><br></div>
2607
+ <h3 class="hndle">
2608
+ <span><?php _e('Admin Columns', CPAC_TEXTDOMAIN ); ?></span>
2609
+ </h3>
2610
+ <div class="inside">
2611
+ <form method="post" action="options.php">
2612
+
2613
+ <?php settings_fields( 'cpac-settings-group' ); ?>
2614
+
2615
+ <table class="form-table">
2616
+ <!-- columns -->
2617
+ <?php echo $rows; ?>
2618
+
2619
+ <!-- activation -->
2620
+ <?php echo $general_settings; ?>
2621
+
2622
+ <tr class="bottom" valign="top">
2623
+ <th scope="row"></th>
2624
+ <td>
2625
+ <p class="submit">
2626
+ <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
2627
+ </p>
2628
+ </td>
2629
+ </tr>
2630
+ </table>
2631
+ </form>
2632
+ </div>
2633
+ </div><!-- general-settings -->
2634
+
2635
+ <div id="restore-cpac-settings" class="postbox">
2636
+ <div title="Click to toggle" class="handlediv"><br></div>
2637
+ <h3 class="hndle">
2638
+ <span><?php _e('Restore defaults', CPAC_TEXTDOMAIN) ?></span>
2639
+ </h3>
2640
+ <div class="inside">
2641
+ <form method="post" action="">
2642
+ <input type="submit" class="button" name="cpac-restore-defaults" value="<?php _e('Restore default settings', CPAC_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", CPAC_TEXTDOMAIN); ?>');" />
2643
+ </form>
2644
+ <p class="description"><?php _e('This will delete all column settings and restore the default settings.', CPAC_TEXTDOMAIN); ?></p>
2645
+ </div>
2646
+ </div><!-- restore-cpac-settings -->
2647
+
2648
+ </div>
2649
+ </div>
2650
+ </div><!-- .postbox-container -->
2651
+ </div>
2652
+ <?php
2653
+ }
2654
+ }
2655
+
2656
+ /**
2657
+ * Init Class Codepress_Admin_Columns
2658
+ *
2659
+ * @since 1.0
2660
+ */
2661
+ new Codepress_Admin_Columns();
2662
+
2663
+
2664
+ /**
2665
+ * Init Class Codepress_Sortable_Columns
2666
+ *
2667
+ * @since 1.3
2668
+ */
2669
+ new Codepress_Sortable_Columns();
2670
+
2671
  ?>
readme.txt CHANGED
@@ -1,398 +1,409 @@
1
- === Codepress Admin Columns ===
2
- Contributors: codepress, tschutter, davidmosterd
3
- Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=ZDZRSYLQ4Z76J
4
- Tags: plugins, wordpress, admin, column, columns, custom columns, custom fields, image, dashboard, sortable, filters, posts, media, users, pages, posttypes, manage columns, wp-admin
5
- Requires at least: 3.1
6
- Tested up to: 3.4.2
7
- Stable tag: 1.4.6.4
8
-
9
- Customise columns on the administration screens for post(types), pages, media, comments, links and users with an easy to use drag-and-drop interface.
10
-
11
- == Description ==
12
-
13
- Completely customise the columns on the administration screens with a nice drag and drop interface.
14
-
15
- By default, WordPress only shows a few built-in columns. This plugin will give you many additional columns. You will have full control over all columns for pages, posts, posttypes, media, links, comments and users.
16
-
17
- Add or remove columns, change their label, change their width and reorder them.
18
-
19
- = Post Types Columns =
20
-
21
- The following custom columns are added:
22
-
23
- * Featured Image
24
- * Excerpt
25
- * Post Attachments
26
- * Page Order
27
- * Page Templates
28
- * Post Formats
29
- * Taxonomies
30
- * ID
31
- * Slug
32
- * Sticky
33
- * Word count
34
- * Roles
35
- * Status
36
- * Number of Attachments
37
- * Last Modified
38
- * Comment count
39
- * Before More Tag Content
40
- * Custom Fields
41
-
42
- = User Columns =
43
-
44
- You can also change the User Columns. The following user columns are added:
45
-
46
- * User ID
47
- * First name
48
- * Last name
49
- * Url
50
- * Register date
51
- * Biographical Info ( description )
52
- * Number of Posts Types
53
- * User Custom Fields
54
-
55
- Some of the user custom fields that are included: user level, capabilities, admin color, nickname... many more.
56
-
57
- = Media Columns =
58
-
59
- Customise the Media Library Columns. The following media columns are added:
60
-
61
- * Media ID
62
- * File name
63
- * Height
64
- * Width
65
- * Dimensions ( width x height )
66
- * EXIF and IPTC image data
67
- * Description, Caption and Alternate tekst
68
- * Mime-Type
69
- * Media Custom Fields
70
- * Filesize
71
-
72
- = Comment Columns =
73
-
74
- A lot more comment colums are added, here are a few examples:
75
-
76
- * Avatar
77
- * Author IP
78
- * Agent
79
- * ID
80
- * Comment excerpt
81
- * Comment Meta data
82
-
83
- = Link Columns =
84
-
85
- A few examples of added Link columns:
86
-
87
- * ID
88
- * Target
89
- * Description
90
- * Notes
91
- * Owner
92
-
93
- = Custom Fields =
94
-
95
- With the custom field column you can display any custom field values. It can show its default value but also handle it as an image or icon. Thsese types are added:
96
-
97
- * Image thumbnails
98
- * Icons for Media Library items
99
- * Excerpt
100
- * Multiple Values
101
- * Numeric value ( this also works for sorting by meta_value_num )
102
- * Post Titles
103
- * Usernames
104
- * Checkmark Image ( for true or false values )
105
-
106
- = Sortable Custom Columns for all Screens =
107
-
108
- All of the new columns will have support for sorting with the <a href="http://www.codepress.nl/plugins/codepress-admin-columns/sortorder-addon/">sorting addon</a>.
109
-
110
- By default WordPress let's you only sort by Title, Date, Comments and Author. This will make you be able to <strong>sort by ALL columns of ANY type</strong>. (columns that are added by other plugins are not supported)
111
-
112
- = Third party plugin support =
113
-
114
- It will work nice with other plugins and support their additional custom columns. A few examples of plugins that are supported: WordPress SEO by Yoast (Robots Meta), Post Admin Shortcuts (Pin), WP Show IDs (ID) and User Access Manager (Access), Co-Authors Plus and Advanced Custom Fields.
115
-
116
- = Translations =
117
-
118
- If you like to contrinute a language, please send them to <a href="mailto:info@codepress.nl">info@codepress.nl</a>.
119
-
120
- * Danish (da_DK) - Thanks for contributing the danish language goes to Morten Dalgaard Johansen
121
- * German (de_DE) - Thanks for contributing the german language goes to Uli
122
- * Polish (pl_PL) - Thanks for contributing the polish language goes to Bartosz
123
- * French (fr_FR) - Thanks for contributing the french language goes to Alexandre Girard
124
-
125
- = Upcoming releases =
126
-
127
- * support for default sorting for users, links and comments
128
-
129
- **Feedback**
130
-
131
- You can leave any <a href='http://www.codepress.nl/plugins/codepress-admin-columns/feedback'>requests or feedback</a>.
132
-
133
- **Related Links:**
134
-
135
- * http://www.codepress.nl/plugins/codepress-admin-columns/
136
-
137
- == Installation ==
138
-
139
- 1. Upload codepress-admin-columns to the /wp-content/plugins/ directory
140
- 2. Activate Codepress Admin Columns through the 'Plugins' menu in WordPress
141
- 3. Configure the plugin by going to the Admin Column settings that appears under the Settings menu.
142
-
143
- == Frequently Asked Questions ==
144
-
145
- = I have an idea for a great way to improve this plugin =
146
-
147
- Great! I'd love to hear from you.
148
- Leave your feedback at http://www.codepress.nl/plugins/codepress-admin-columns/feedback.
149
-
150
- = How can I change the thumbnail size of images? =
151
-
152
- You can use the build in filter to set your own thumbnail size. Just add this piece of code to your
153
- theme's functions.php.
154
-
155
- To set a custom size use, for example 194 width by 63 height pixels:
156
-
157
- `
158
- <?php
159
-
160
- // edit here: fill in your thumbnail height and width
161
- $my_height = 63;
162
- $my_width = 194;
163
- // stop editing
164
-
165
- add_image_size( 'admin-columns', $my_width, $my_height, true );
166
- add_filter('cpac_thumbnail_size', function() {
167
- return 'admin-columns';
168
- });
169
- ?>
170
- `
171
-
172
- **my columns thumbnails still have the wrong size**
173
-
174
- If you want your already uploaded images to display the newly added size you will need to regenerate the thumbnail for them. Use this plugin to generate the newly added sized thumbnails: http://wordpress.org/extend/plugins/regenerate-thumbnails/.
175
-
176
- = How can I enable the use of Hidden Custom Fields? =
177
-
178
- I am currently working on settings page where you can enable this feature. In the meanwhile you can enable this by adding
179
- this piece of code to your theme's functions.php:
180
-
181
- `
182
- <?php
183
- add_filter('cpac_use_hidden_custom_fields', '__return_true'); // enables the use hidden custom fields
184
- ?>
185
- `
186
-
187
- Now you can select your HIDDEN custom fields in de dropdown menu under "Custom Field:".
188
-
189
- = How can I add the dropdown menu for taxonomy filtering? =
190
-
191
- This will also be included in the upcoming settings page, in the meanwhile you can enable this by adding
192
- this piece of code to your theme's functions.php:
193
-
194
- `
195
- <?php
196
- add_filter( 'cpac-remove-filtering-columns', '__return_false' ); // add dropdown taxonomy filtering to the overview pages
197
- ?>
198
- `
199
-
200
- = How can I display a custom value in the Custom Fields Column? =
201
-
202
- With this filter 'cpac_get_column_value_custom_field' you can control what the value will be for any Custom Field Column.
203
-
204
- Filter explained:
205
-
206
- * **$value** is the original value which would otherwise be displayed
207
- * **$internal_field_key** is only used internally to store the column
208
- * **$custom_field** is the name of your custom field
209
- * **$type** will return either the posttype or if it is any other type it will return wp-comments, wp-links, wp-users, wp-media.
210
- * **$object_id** will return the ID of the object.
211
-
212
- For example if you have a custom posttype 'Demo' with a custom_field that is called 'city' and the result would be an integer '33'. You can change that integer '33' to Amsterdam.
213
-
214
- `
215
- <?php
216
- function my_custom_field_value( $value, $internal_field_key, $custom_field, $type, $object_id )
217
- {
218
- $my_post_type = 'demo';
219
- $my_field_name = 'city';
220
-
221
- // make sure we have the correct posttype and fieldname
222
- if ( $my_post_type == $type && $my_field_name == $custom_field ) {
223
-
224
- if ( '33' == $value )
225
- $value = 'Amsterdam';
226
-
227
- elseif ( '34' == $value )
228
- $value = 'New York';
229
- }
230
- return $value;
231
- }
232
- add_filter( 'cpac_get_column_value_custom_field', 'my_custom_field_value', 10, 5 );
233
- ?>
234
- `
235
-
236
- == Screenshots ==
237
-
238
- 1. Settings page for Post(type) columns.
239
- 2. Posts Screen with the customized sortable columns.
240
- 3. Settings page for the Media Library columns.
241
- 4. Media Screen with the customized sortable columns.
242
- 5. Settings page for Users columns.
243
- 6. Users Screen with the customized sortable columns.
244
- 7. Settings page showing the different displaying types for custom field.
245
-
246
- == Changelog ==
247
-
248
- = 1.4.6.4 =
249
- * Added 'before more tag' column, which will show the content which is placed before the more-tag
250
- * bug fix: file images will now also be displayed when they can not be resized.
251
- * bug fix: the checkbox disappeared when resetting columns and resaving them.
252
-
253
- = 1.4.6.3 =
254
-
255
- * Added new custom field type: User by User ID
256
- * Added values to filter 'cpac_get_column_value_custom_field' for better control of the output
257
- * Added an example for above filter to FAQ section
258
- * Added fix where trash posts did not show with the sorting addon activated
259
-
260
- = 1.4.6.2 =
261
-
262
- * bug fix with a static function which could cause an error in some cases
263
- * added filter to enable taxonomy filtering. add this to your functions.php to enable taxonomy filtering: `add_filter( 'cpac-remove-filtering-columns', '__return_false' );`
264
-
265
- = 1.4.6.1 =
266
-
267
- * bug fix for possible warning when using Custompress ( props to scottsalisbury for the fix! )
268
- * bug fix for sorting by postcount for users
269
- * added 'Display Author As' column for post(types)
270
- * added sorting support for 'Display Author As' column
271
-
272
- = 1.4.6 =
273
-
274
- * added german language ( thanks to Uli )
275
- * added danish language ( thanks to Morten Dalgaard Johansen )
276
- * added filter for setting thumbnail size ( see FAQ on how to use it )
277
- * added support for hidden custom fields ( see FAQ on how to enable this )
278
- * added fix for WordPress SEO by Yoast Columns
279
-
280
- = 1.4.5.1 =
281
-
282
- * removed taxonomy filtering ( will implement show/hide option )
283
-
284
- = 1.4.5 =
285
-
286
- * added french language ( thanks to Alexandre Girard )
287
- * filtering by taxonomy ( only displays when column is used )
288
- * added compatibility with woocommerce
289
- * fix value media meta column ID
290
- * fixed bug with sorting users by postcount
291
- * added Actions column for Media (delete, view etc.)
292
- * added Actions column for Link (delete, view etc.)
293
- * added Actions column for Comments (delete, view etc.)
294
- * added Wordcount column for Comments
295
- * added Filesize column for Media ( supports sorting )
296
- * added default sorting for posts ( remembers your last sorting, only with addon )
297
- * added default sorting for media ( remembers your last sorting, only with addon )
298
- * added filters to the result output
299
-
300
- = 1.4.4 =
301
-
302
- * added posts columns Last Modified and Comment count
303
- * added media columns for EXIF and IPTC image data
304
- * added custom fields columns to the Media Library
305
- * given column values it's own class
306
- * added bug fix for sorting bookmarks/links
307
- * added fix for possible php warning
308
-
309
- = 1.4.3 =
310
-
311
- * removed taxonomy filtering
312
-
313
- = 1.4.2 =
314
-
315
- * added fix for unexpected output in the column value
316
- * added fix for better 3rd party plugin support
317
- * added column for Comment status
318
- * added column for Ping/Trackback status
319
- * added column for Posts Actions (delete, view etc.)
320
- * added column for Users Actions (delete, view etc.)
321
- * added sorting taxonomies ( only on first one )
322
- * added bug fix for sorting
323
- * added taxonomy filtering
324
-
325
- = 1.4.1 =
326
-
327
- * added polish translation, thanks to Bartosz.
328
- * changed the license key validation proces
329
- * removed non-breaking-space-character from column output
330
-
331
- = 1.4 =
332
-
333
- * added support for comment columns
334
- * added support for link columns
335
- * added links to taxonomies
336
- * added sorting user custom fields
337
- * added sorting to links columns
338
- * added user columns so you can see how many articles an author has published of a certain post type
339
- * added Textual help
340
- * added the option to specify column width
341
- * added role column to all posts screens
342
- * added posts status column to all posts screens
343
- * added image path to media library
344
- * added added apply_filters('cpac-get-post-types', $post_types) to filter out certain post types
345
- * added option to enter license key for activating sorting on ALL columns
346
- * fixed a php5 warning
347
- * fixed a conflict with the Co-Authors plugin
348
-
349
- = 1.3 =
350
-
351
- * added support for Media columns
352
- * added Media columns: filename, width, height, dimensions, description, alt, caption and mime-type
353
- * added date type to posts custom fields
354
- * added title type to posts custom fields
355
- * sorting has changed. when sorting; only results are shown which contain a value
356
- * str_word_count is used for excerpts
357
-
358
- = 1.2.1 =
359
-
360
- * added word count sorting
361
- * added attachment count sorting
362
- * added template name sorting
363
- * minor styling changes
364
- * bug fix with sorting by slug
365
- * bug fix with sorting by attachment
366
-
367
- = 1.2 =
368
-
369
- * added support for third party plugins
370
- * added user custom fields
371
- * added extra image check
372
- * bug fix with javascript (jquery) enqueue
373
-
374
- = 1.1.3 =
375
-
376
- * added bug fix for WP3.3beta ( thanks to raonip and ronbme for pointing this out )
377
-
378
- = 1.1.2 =
379
-
380
- * added dutch translation
381
-
382
- = 1.1.1 =
383
-
384
- * Bug fix: path separator for require_once
385
- * Added word count
386
-
387
- = 1.1 =
388
-
389
- * Added User Columns.
390
- * Added before / after text for custom fields
391
- * Added custom field type 'Numeric'.
392
- * Added custom field sortables.
393
- * Fixed domain path
394
- * Fixed settings link
395
-
396
- = 1.0 =
397
-
 
 
 
 
 
 
 
 
 
 
 
398
  * Initial release.
1
+ === Codepress Admin Columns ===
2
+ Contributors: codepress, tschutter, davidmosterd
3
+ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=ZDZRSYLQ4Z76J
4
+ Tags: plugins, wordpress, admin, column, columns, custom columns, custom fields, image, dashboard, sortable, filters, posts, media, users, pages, posttypes, manage columns, wp-admin
5
+ Requires at least: 3.1
6
+ Tested up to: 3.5
7
+ Stable tag: 1.4.7
8
+
9
+ Customise columns on the administration screens for post(types), pages, media, comments, links and users with an easy to use drag-and-drop interface.
10
+
11
+ == Description ==
12
+
13
+ Completely customise the columns on the administration screens with a nice drag and drop interface.
14
+
15
+ By default, WordPress only shows a few built-in columns. This plugin will give you many additional columns. You will have full control over all columns for pages, posts, posttypes, media, links, comments and users.
16
+
17
+ Add or remove columns, change their label, change their width and reorder them.
18
+
19
+ = Post Types Columns =
20
+
21
+ The following custom columns are added:
22
+
23
+ * Featured Image
24
+ * Excerpt
25
+ * Post Attachments
26
+ * Page Order
27
+ * Page Templates
28
+ * Post Formats
29
+ * Taxonomies
30
+ * ID
31
+ * Slug
32
+ * Sticky
33
+ * Word count
34
+ * Roles
35
+ * Status
36
+ * Number of Attachments
37
+ * Last Modified
38
+ * Comment count
39
+ * Before More Tag Content
40
+ * Custom Fields
41
+
42
+ = User Columns =
43
+
44
+ You can also change the User Columns. The following user columns are added:
45
+
46
+ * User ID
47
+ * First name
48
+ * Last name
49
+ * Url
50
+ * Register date
51
+ * Biographical Info ( description )
52
+ * Number of Posts Types
53
+ * User Custom Fields
54
+
55
+ Some of the user custom fields that are included: user level, capabilities, admin color, nickname... many more.
56
+
57
+ = Media Columns =
58
+
59
+ Customise the Media Library Columns. The following media columns are added:
60
+
61
+ * Media ID
62
+ * File name
63
+ * Height
64
+ * Width
65
+ * Dimensions ( width x height )
66
+ * EXIF and IPTC image data
67
+ * Description, Caption and Alternate tekst
68
+ * Mime-Type
69
+ * Media Custom Fields
70
+ * Filesize
71
+
72
+ = Comment Columns =
73
+
74
+ A lot more comment colums are added, here are a few examples:
75
+
76
+ * Avatar
77
+ * Author IP
78
+ * Agent
79
+ * ID
80
+ * Comment excerpt
81
+ * Comment Meta data
82
+
83
+ = Link Columns =
84
+
85
+ A few examples of added Link columns:
86
+
87
+ * ID
88
+ * Target
89
+ * Description
90
+ * Notes
91
+ * Owner
92
+
93
+ = Custom Fields =
94
+
95
+ With the custom field column you can display any custom field values. It can show its default value but also handle it as an image or icon. Thsese types are added:
96
+
97
+ * Image thumbnails
98
+ * Icons for Media Library items
99
+ * Excerpt
100
+ * Multiple Values
101
+ * Numeric value ( this also works for sorting by meta_value_num )
102
+ * Post Titles
103
+ * Usernames
104
+ * Checkmark Image ( for true or false values )
105
+
106
+ = Sortable Custom Columns for all Screens =
107
+
108
+ All of the new columns will have support for sorting with the <a href="http://www.codepress.nl/plugins/codepress-admin-columns/sortorder-addon/">sorting addon</a>.
109
+
110
+ By default WordPress let's you only sort by Title, Date, Comments and Author. This will make you be able to <strong>sort by ALL columns of ANY type</strong>. (columns that are added by other plugins are not supported)
111
+
112
+ = Third party plugin support =
113
+
114
+ It will work nice with other plugins and support their additional custom columns. A few examples of plugins that are supported: WordPress SEO by Yoast (Robots Meta), Post Admin Shortcuts (Pin), WP Show IDs (ID) and User Access Manager (Access), Co-Authors Plus and Advanced Custom Fields.
115
+
116
+ = Translations =
117
+
118
+ If you like to contrinute a language, please send them to <a href="mailto:info@codepress.nl">info@codepress.nl</a>.
119
+
120
+ * Danish (da_DK) - Thanks for contributing the danish language goes to Morten Dalgaard Johansen
121
+ * German (de_DE) - Thanks for contributing the german language goes to Uli
122
+ * Polish (pl_PL) - Thanks for contributing the polish language goes to Bartosz
123
+ * French (fr_FR) - Thanks for contributing the french language goes to Alexandre Girard
124
+
125
+ = Upcoming releases =
126
+
127
+ * support for default sorting for users, links and comments
128
+
129
+ **Feedback**
130
+
131
+ You can leave any <a href='http://www.codepress.nl/plugins/codepress-admin-columns/feedback'>requests or feedback</a>.
132
+
133
+ **Related Links:**
134
+
135
+ * http://www.codepress.nl/plugins/codepress-admin-columns/
136
+
137
+ == Installation ==
138
+
139
+ 1. Upload codepress-admin-columns to the /wp-content/plugins/ directory
140
+ 2. Activate Codepress Admin Columns through the 'Plugins' menu in WordPress
141
+ 3. Configure the plugin by going to the Admin Column settings that appears under the Settings menu.
142
+
143
+ == Frequently Asked Questions ==
144
+
145
+ = I have an idea for a great way to improve this plugin =
146
+
147
+ Great! I'd love to hear from you.
148
+ Leave your feedback at http://www.codepress.nl/plugins/codepress-admin-columns/feedback.
149
+
150
+ = How can I change the thumbnail size of images? =
151
+
152
+ You can use the build in filter to set your own thumbnail size. Just add this piece of code to your
153
+ theme's functions.php.
154
+
155
+ To set a custom size use, for example 194 width by 63 height pixels:
156
+
157
+ `
158
+ <?php
159
+
160
+ // edit here: fill in your thumbnail height and width
161
+ $my_height = 63;
162
+ $my_width = 194;
163
+ // stop editing
164
+
165
+ add_image_size( 'admin-columns', $my_width, $my_height, true );
166
+ add_filter('cpac_thumbnail_size', 'cb_cpac_thumbnail_size' );
167
+ function cb_cpac_thumbnail_size() {
168
+ return 'admin-columns';
169
+ };
170
+ ?>
171
+ `
172
+
173
+ **my columns thumbnails still have the wrong size**
174
+
175
+ If you want your already uploaded images to display the newly added size you will need to regenerate the thumbnail for them. Use this plugin to generate the newly added sized thumbnails: http://wordpress.org/extend/plugins/regenerate-thumbnails/.
176
+
177
+ = How can I enable the use of Hidden Custom Fields? =
178
+
179
+ I am currently working on settings page where you can enable this feature. In the meanwhile you can enable this by adding
180
+ this piece of code to your theme's functions.php:
181
+
182
+ `
183
+ <?php
184
+ add_filter('cpac_use_hidden_custom_fields', '__return_true'); // enables the use hidden custom fields
185
+ ?>
186
+ `
187
+
188
+ Now you can select your HIDDEN custom fields in de dropdown menu under "Custom Field:".
189
+
190
+ = How can I add the dropdown menu for taxonomy filtering? =
191
+
192
+ This will also be included in the upcoming settings page, in the meanwhile you can enable this by adding
193
+ this piece of code to your theme's functions.php:
194
+
195
+ `
196
+ <?php
197
+ add_filter( 'cpac-remove-filtering-columns', '__return_false' ); // add dropdown taxonomy filtering to the overview pages
198
+ ?>
199
+ `
200
+
201
+ = How can I display a custom value in the Custom Fields Column? =
202
+
203
+ With this filter 'cpac_get_column_value_custom_field' you can control what the value will be for any Custom Field Column.
204
+
205
+ Filter explained:
206
+
207
+ * **$value** is the original value which would otherwise be displayed
208
+ * **$internal_field_key** is only used internally to store the column
209
+ * **$custom_field** is the name of your custom field
210
+ * **$type** will return either the posttype or if it is any other type it will return wp-comments, wp-links, wp-users, wp-media.
211
+ * **$object_id** will return the ID of the object.
212
+
213
+ For example if you have a custom posttype 'Demo' with a custom_field that is called 'city' and the result would be an integer '33'. You can change that integer '33' to Amsterdam.
214
+
215
+ `
216
+ <?php
217
+ function my_custom_field_value( $value, $internal_field_key, $custom_field, $type, $object_id )
218
+ {
219
+ $my_post_type = 'demo';
220
+ $my_field_name = 'city';
221
+
222
+ // make sure we have the correct posttype and fieldname
223
+ if ( $my_post_type == $type && $my_field_name == $custom_field ) {
224
+
225
+ if ( '33' == $value )
226
+ $value = 'Amsterdam';
227
+
228
+ elseif ( '34' == $value )
229
+ $value = 'New York';
230
+ }
231
+ return $value;
232
+ }
233
+ add_filter( 'cpac_get_column_value_custom_field', 'my_custom_field_value', 10, 5 );
234
+ ?>
235
+ `
236
+
237
+ == Screenshots ==
238
+
239
+ 1. Settings page for Post(type) columns.
240
+ 2. Posts Screen with the customized sortable columns.
241
+ 3. Settings page for the Media Library columns.
242
+ 4. Media Screen with the customized sortable columns.
243
+ 5. Settings page for Users columns.
244
+ 6. Users Screen with the customized sortable columns.
245
+ 7. Settings page showing the different displaying types for custom field.
246
+
247
+ == Changelog ==
248
+
249
+ = 1.4.7 =
250
+ * ready for WP 3.5
251
+ * added support for custom fields for Media
252
+ * added color to the custom field types
253
+ * fixed default sorting for Post(types) and Media
254
+ * fixed problem with different date formats in custom fields. all dates will parsed by strtotime() now.
255
+ * fixed bug which could trigger a conflict when saving the setting on other plugins
256
+ * fixed bug when returning an admin class atrribute
257
+ * improved perfomance on post count on user overview screen
258
+
259
+ = 1.4.6.4 =
260
+ * Added 'before more tag' column, which will show the content which is placed before the more-tag
261
+ * bug fix: file images will now also be displayed when they can not be resized.
262
+ * bug fix: the checkbox disappeared when resetting columns and resaving them.
263
+
264
+ = 1.4.6.3 =
265
+
266
+ * Added new custom field type: User by User ID
267
+ * Added values to filter 'cpac_get_column_value_custom_field' for better control of the output
268
+ * Added an example for above filter to FAQ section
269
+ * Added fix where trash posts did not show with the sorting addon activated
270
+
271
+ = 1.4.6.2 =
272
+
273
+ * bug fix with a static function which could cause an error in some cases
274
+ * added filter to enable taxonomy filtering. add this to your functions.php to enable taxonomy filtering: `add_filter( 'cpac-remove-filtering-columns', '__return_false' );`
275
+
276
+ = 1.4.6.1 =
277
+
278
+ * bug fix for possible warning when using Custompress ( props to scottsalisbury for the fix! )
279
+ * bug fix for sorting by postcount for users
280
+ * added 'Display Author As' column for post(types)
281
+ * added sorting support for 'Display Author As' column
282
+
283
+ = 1.4.6 =
284
+
285
+ * added german language ( thanks to Uli )
286
+ * added danish language ( thanks to Morten Dalgaard Johansen )
287
+ * added filter for setting thumbnail size ( see FAQ on how to use it )
288
+ * added support for hidden custom fields ( see FAQ on how to enable this )
289
+ * added fix for WordPress SEO by Yoast Columns
290
+
291
+ = 1.4.5.1 =
292
+
293
+ * removed taxonomy filtering ( will implement show/hide option )
294
+
295
+ = 1.4.5 =
296
+
297
+ * added french language ( thanks to Alexandre Girard )
298
+ * filtering by taxonomy ( only displays when column is used )
299
+ * added compatibility with woocommerce
300
+ * fix value media meta column ID
301
+ * fixed bug with sorting users by postcount
302
+ * added Actions column for Media (delete, view etc.)
303
+ * added Actions column for Link (delete, view etc.)
304
+ * added Actions column for Comments (delete, view etc.)
305
+ * added Wordcount column for Comments
306
+ * added Filesize column for Media ( supports sorting )
307
+ * added default sorting for posts ( remembers your last sorting, only with addon )
308
+ * added default sorting for media ( remembers your last sorting, only with addon )
309
+ * added filters to the result output
310
+
311
+ = 1.4.4 =
312
+
313
+ * added posts columns Last Modified and Comment count
314
+ * added media columns for EXIF and IPTC image data
315
+ * added custom fields columns to the Media Library
316
+ * given column values it's own class
317
+ * added bug fix for sorting bookmarks/links
318
+ * added fix for possible php warning
319
+
320
+ = 1.4.3 =
321
+
322
+ * removed taxonomy filtering
323
+
324
+ = 1.4.2 =
325
+
326
+ * added fix for unexpected output in the column value
327
+ * added fix for better 3rd party plugin support
328
+ * added column for Comment status
329
+ * added column for Ping/Trackback status
330
+ * added column for Posts Actions (delete, view etc.)
331
+ * added column for Users Actions (delete, view etc.)
332
+ * added sorting taxonomies ( only on first one )
333
+ * added bug fix for sorting
334
+ * added taxonomy filtering
335
+
336
+ = 1.4.1 =
337
+
338
+ * added polish translation, thanks to Bartosz.
339
+ * changed the license key validation proces
340
+ * removed non-breaking-space-character from column output
341
+
342
+ = 1.4 =
343
+
344
+ * added support for comment columns
345
+ * added support for link columns
346
+ * added links to taxonomies
347
+ * added sorting user custom fields
348
+ * added sorting to links columns
349
+ * added user columns so you can see how many articles an author has published of a certain post type
350
+ * added Textual help
351
+ * added the option to specify column width
352
+ * added role column to all posts screens
353
+ * added posts status column to all posts screens
354
+ * added image path to media library
355
+ * added added apply_filters('cpac-get-post-types', $post_types) to filter out certain post types
356
+ * added option to enter license key for activating sorting on ALL columns
357
+ * fixed a php5 warning
358
+ * fixed a conflict with the Co-Authors plugin
359
+
360
+ = 1.3 =
361
+
362
+ * added support for Media columns
363
+ * added Media columns: filename, width, height, dimensions, description, alt, caption and mime-type
364
+ * added date type to posts custom fields
365
+ * added title type to posts custom fields
366
+ * sorting has changed. when sorting; only results are shown which contain a value
367
+ * str_word_count is used for excerpts
368
+
369
+ = 1.2.1 =
370
+
371
+ * added word count sorting
372
+ * added attachment count sorting
373
+ * added template name sorting
374
+ * minor styling changes
375
+ * bug fix with sorting by slug
376
+ * bug fix with sorting by attachment
377
+
378
+ = 1.2 =
379
+
380
+ * added support for third party plugins
381
+ * added user custom fields
382
+ * added extra image check
383
+ * bug fix with javascript (jquery) enqueue
384
+
385
+ = 1.1.3 =
386
+
387
+ * added bug fix for WP3.3beta ( thanks to raonip and ronbme for pointing this out )
388
+
389
+ = 1.1.2 =
390
+
391
+ * added dutch translation
392
+
393
+ = 1.1.1 =
394
+
395
+ * Bug fix: path separator for require_once
396
+ * Added word count
397
+
398
+ = 1.1 =
399
+
400
+ * Added User Columns.
401
+ * Added before / after text for custom fields
402
+ * Added custom field type 'Numeric'.
403
+ * Added custom field sortables.
404
+ * Fixed domain path
405
+ * Fixed settings link
406
+
407
+ = 1.0 =
408
+
409
  * Initial release.