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}#x2F;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;