Version Description
Download this release
Release Info
Developer | codepress |
Plugin | Admin Columns |
Version | 1.4.9 |
Comparing to | |
See all releases |
Code changes from version 1.4.8 to 1.4.9
- classes/license.php +21 -21
- classes/sortable.php +297 -297
- classes/{utility.php → third_party.php} +26 -12
- classes/values.php +147 -138
- classes/values/comments.php +45 -45
- classes/values/link.php +123 -123
- classes/values/media.php +61 -61
- classes/values/posts.php +82 -82
- classes/values/users.php +35 -35
- codepress-admin-columns.php +543 -544
- readme.txt +14 -11
classes/license.php
CHANGED
@@ -4,16 +4,16 @@ class cpac_licence
|
|
4 |
{
|
5 |
/**
|
6 |
* The type of licence to check or activate
|
7 |
-
*
|
8 |
* @var string $type
|
9 |
*/
|
10 |
public $type;
|
11 |
-
|
12 |
-
public function __construct($type)
|
13 |
{
|
14 |
$this->type = $type;
|
15 |
}
|
16 |
-
|
17 |
/**
|
18 |
* Unlocks
|
19 |
*
|
@@ -22,25 +22,25 @@ class cpac_licence
|
|
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 |
public 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( 'http://www.codepress.nl/', array(
|
40 |
'body' => array(
|
41 |
'api' => 'addon',
|
42 |
'key' => $key,
|
43 |
-
'type' => $this->type
|
44 |
)
|
45 |
));
|
46 |
|
@@ -48,20 +48,20 @@ class cpac_licence
|
|
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 |
*
|
@@ -71,17 +71,17 @@ class cpac_licence
|
|
71 |
{
|
72 |
return get_option("cpac_{$this->type}_ac");
|
73 |
}
|
74 |
-
|
75 |
/**
|
76 |
* Set license key
|
77 |
*
|
78 |
* @since 1.3
|
79 |
*/
|
80 |
public function set_license_key( $key )
|
81 |
-
{
|
82 |
update_option( "cpac_{$this->type}_ac", trim( $key ) );
|
83 |
}
|
84 |
-
|
85 |
/**
|
86 |
* Remove license key
|
87 |
*
|
@@ -91,5 +91,5 @@ class cpac_licence
|
|
91 |
{
|
92 |
delete_option( "cpac_{$this->type}_ac" );
|
93 |
delete_transient("cpac_{$this->type}_trnsnt");
|
94 |
-
}
|
95 |
}
|
4 |
{
|
5 |
/**
|
6 |
* The type of licence to check or activate
|
7 |
+
*
|
8 |
* @var string $type
|
9 |
*/
|
10 |
public $type;
|
11 |
+
|
12 |
+
public function __construct($type)
|
13 |
{
|
14 |
$this->type = $type;
|
15 |
}
|
16 |
+
|
17 |
/**
|
18 |
* Unlocks
|
19 |
*
|
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 |
public 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( 'http://www.codepress.nl/', array(
|
40 |
'body' => array(
|
41 |
'api' => 'addon',
|
42 |
'key' => $key,
|
43 |
+
'type' => $this->type
|
44 |
)
|
45 |
));
|
46 |
|
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 |
*
|
71 |
{
|
72 |
return get_option("cpac_{$this->type}_ac");
|
73 |
}
|
74 |
+
|
75 |
/**
|
76 |
* Set license key
|
77 |
*
|
78 |
* @since 1.3
|
79 |
*/
|
80 |
public function set_license_key( $key )
|
81 |
+
{
|
82 |
update_option( "cpac_{$this->type}_ac", trim( $key ) );
|
83 |
}
|
84 |
+
|
85 |
/**
|
86 |
* Remove license key
|
87 |
*
|
91 |
{
|
92 |
delete_option( "cpac_{$this->type}_ac" );
|
93 |
delete_transient("cpac_{$this->type}_trnsnt");
|
94 |
+
}
|
95 |
}
|
classes/sortable.php
CHANGED
@@ -7,12 +7,12 @@
|
|
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 |
*
|
@@ -22,7 +22,7 @@ class Codepress_Sortable_Columns extends Codepress_Admin_Columns
|
|
22 |
{
|
23 |
add_action( 'wp_loaded', array( $this, 'init') );
|
24 |
}
|
25 |
-
|
26 |
/**
|
27 |
* Initialize
|
28 |
*
|
@@ -31,26 +31,26 @@ class Codepress_Sortable_Columns extends Codepress_Admin_Columns
|
|
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 |
*
|
@@ -62,38 +62,38 @@ class Codepress_Sortable_Columns extends Codepress_Admin_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 |
|
@@ -102,64 +102,64 @@ class Codepress_Sortable_Columns extends Codepress_Admin_Columns
|
|
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 |
*
|
@@ -167,143 +167,143 @@ class Codepress_Sortable_Columns extends Codepress_Admin_Columns
|
|
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;
|
@@ -313,21 +313,21 @@ class Codepress_Sortable_Columns extends Codepress_Admin_Columns
|
|
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 |
*/
|
@@ -336,83 +336,83 @@ class Codepress_Sortable_Columns extends Codepress_Admin_Columns
|
|
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;
|
@@ -420,108 +420,108 @@ class Codepress_Sortable_Columns extends Codepress_Admin_Columns
|
|
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 |
|
@@ -531,53 +531,53 @@ class Codepress_Sortable_Columns extends Codepress_Admin_Columns
|
|
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 ) {
|
@@ -587,7 +587,7 @@ class Codepress_Sortable_Columns extends Codepress_Admin_Columns
|
|
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 ) {
|
@@ -597,7 +597,7 @@ class Codepress_Sortable_Columns extends Codepress_Admin_Columns
|
|
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 ) {
|
@@ -605,12 +605,12 @@ class Codepress_Sortable_Columns extends Codepress_Admin_Columns
|
|
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 ) {
|
@@ -619,7 +619,7 @@ class Codepress_Sortable_Columns extends Codepress_Admin_Columns
|
|
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 ) {
|
@@ -628,25 +628,25 @@ class Codepress_Sortable_Columns extends Codepress_Admin_Columns
|
|
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' :
|
@@ -658,20 +658,20 @@ class Codepress_Sortable_Columns extends Codepress_Admin_Columns
|
|
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 );
|
@@ -679,7 +679,7 @@ class Codepress_Sortable_Columns extends Codepress_Admin_Columns
|
|
679 |
|
680 |
return $vars;
|
681 |
}
|
682 |
-
|
683 |
/**
|
684 |
* Orderby Posts column
|
685 |
*
|
@@ -688,55 +688,55 @@ class Codepress_Sortable_Columns extends Codepress_Admin_Columns
|
|
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' )
|
@@ -747,52 +747,52 @@ class Codepress_Sortable_Columns extends Codepress_Admin_Columns
|
|
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');
|
@@ -803,7 +803,7 @@ class Codepress_Sortable_Columns extends Codepress_Admin_Columns
|
|
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 ) {
|
@@ -814,7 +814,7 @@ class Codepress_Sortable_Columns extends Codepress_Admin_Columns
|
|
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 ) {
|
@@ -825,34 +825,34 @@ class Codepress_Sortable_Columns extends Codepress_Admin_Columns
|
|
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'];
|
@@ -861,37 +861,37 @@ class Codepress_Sortable_Columns extends Codepress_Admin_Columns
|
|
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 );
|
@@ -899,12 +899,12 @@ class Codepress_Sortable_Columns extends Codepress_Admin_Columns
|
|
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
|
@@ -913,17 +913,17 @@ class Codepress_Sortable_Columns extends Codepress_Admin_Columns
|
|
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 |
*
|
@@ -935,13 +935,13 @@ class Codepress_Sortable_Columns extends Codepress_Admin_Columns
|
|
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 |
*
|
@@ -951,12 +951,12 @@ class Codepress_Sortable_Columns extends Codepress_Admin_Columns
|
|
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'];
|
@@ -968,7 +968,7 @@ class Codepress_Sortable_Columns extends Codepress_Admin_Columns
|
|
968 |
$this->set_sorting_preference( $type, $vars['orderby'], $vars['order'] );
|
969 |
}
|
970 |
}
|
971 |
-
|
972 |
/**
|
973 |
* Get posts sorted by taxonomy
|
974 |
*
|
@@ -976,23 +976,23 @@ class Codepress_Sortable_Columns extends Codepress_Admin_Columns
|
|
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 |
*
|
@@ -1015,59 +1015,59 @@ class Codepress_Sortable_Columns extends Codepress_Admin_Columns
|
|
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 |
*
|
@@ -1080,19 +1080,19 @@ class Codepress_Sortable_Columns extends Codepress_Admin_Columns
|
|
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 |
*
|
@@ -1100,12 +1100,12 @@ class Codepress_Sortable_Columns extends Codepress_Admin_Columns
|
|
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 |
*
|
@@ -1115,27 +1115,27 @@ class Codepress_Sortable_Columns extends Codepress_Admin_Columns
|
|
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 |
*
|
@@ -1145,11 +1145,11 @@ class Codepress_Sortable_Columns extends Codepress_Admin_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 |
*
|
@@ -1158,87 +1158,87 @@ class Codepress_Sortable_Columns extends Codepress_Admin_Columns
|
|
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 .= ' ';
|
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 |
}
|
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 |
*
|
22 |
{
|
23 |
add_action( 'wp_loaded', array( $this, 'init') );
|
24 |
}
|
25 |
+
|
26 |
/**
|
27 |
* Initialize
|
28 |
*
|
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 |
*
|
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 |
|
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 |
*
|
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;
|
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 |
*/
|
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;
|
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 |
|
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 ) {
|
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 ) {
|
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 ) {
|
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 ) {
|
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 ) {
|
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' :
|
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 );
|
679 |
|
680 |
return $vars;
|
681 |
}
|
682 |
+
|
683 |
/**
|
684 |
* Orderby Posts column
|
685 |
*
|
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' )
|
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');
|
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 ) {
|
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 ) {
|
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'];
|
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 );
|
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
|
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 |
*
|
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 |
*
|
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'];
|
968 |
$this->set_sorting_preference( $type, $vars['orderby'], $vars['order'] );
|
969 |
}
|
970 |
}
|
971 |
+
|
972 |
/**
|
973 |
* Get posts sorted by taxonomy
|
974 |
*
|
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 |
*
|
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 apply_filters( 'cpac-get-orderby-type', $column, $orderby, $type );
|
1041 |
}
|
1042 |
}
|
1043 |
}
|
1044 |
+
return apply_filters( 'cpac-get-orderby-type', false, $orderby, $type );
|
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 |
*
|
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 |
*
|
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 |
*
|
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 |
*
|
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 |
*
|
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 .= ' ';
|
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 |
}
|
classes/{utility.php → third_party.php}
RENAMED
@@ -13,11 +13,12 @@ function pre_load_wordpress_seo_class_metabox()
|
|
13 |
{
|
14 |
global $pagenow;
|
15 |
|
16 |
-
if (
|
17 |
-
isset(
|
18 |
-
'codepress-admin-columns' == $_REQUEST['page'] &&
|
19 |
-
'options-general.php' == $pagenow &&
|
20 |
-
defined('WPSEO_PATH') &&
|
|
|
21 |
) {
|
22 |
require_once WPSEO_PATH.'admin/class-metabox.php';
|
23 |
}
|
@@ -27,14 +28,14 @@ add_action( 'plugins_loaded', 'pre_load_wordpress_seo_class_metabox', 0 );
|
|
27 |
/**
|
28 |
* Fix which remove the Advanced Custom Fields Type (acf) from the admin columns settings page
|
29 |
*
|
30 |
-
* @since
|
31 |
*/
|
32 |
function remove_acf_from_cpac_post_types( $post_types )
|
33 |
{
|
34 |
-
if ( class_exists('Acf') ) {
|
35 |
unset( $post_types['acf'] );
|
36 |
}
|
37 |
-
|
38 |
return $post_types;
|
39 |
}
|
40 |
add_filter( 'cpac-get-post-types', 'remove_acf_from_cpac_post_types' );
|
@@ -42,16 +43,29 @@ add_filter( 'cpac-get-post-types', 'remove_acf_from_cpac_post_types' );
|
|
42 |
/**
|
43 |
* Fix which removes bbPress Posttypes ( forum, reply and topic ) from the admin columns settings page
|
44 |
*
|
45 |
-
* @since
|
46 |
*/
|
47 |
function remove_bbpress_from_cpac_post_types( $post_types )
|
48 |
{
|
49 |
-
if ( class_exists('bbPress') ) {
|
50 |
unset( $post_types['topic'] );
|
51 |
unset( $post_types['reply'] );
|
52 |
unset( $post_types['forum'] );
|
53 |
}
|
54 |
-
|
55 |
return $post_types;
|
56 |
}
|
57 |
-
add_filter( 'cpac-get-post-types', 'remove_bbpress_from_cpac_post_types' );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
}
|
28 |
/**
|
29 |
* Fix which remove the Advanced Custom Fields Type (acf) from the admin columns settings page
|
30 |
*
|
31 |
+
* @since 1.5
|
32 |
*/
|
33 |
function remove_acf_from_cpac_post_types( $post_types )
|
34 |
{
|
35 |
+
if ( class_exists('Acf') ) {
|
36 |
unset( $post_types['acf'] );
|
37 |
}
|
38 |
+
|
39 |
return $post_types;
|
40 |
}
|
41 |
add_filter( 'cpac-get-post-types', 'remove_acf_from_cpac_post_types' );
|
43 |
/**
|
44 |
* Fix which removes bbPress Posttypes ( forum, reply and topic ) from the admin columns settings page
|
45 |
*
|
46 |
+
* @since 1.5
|
47 |
*/
|
48 |
function remove_bbpress_from_cpac_post_types( $post_types )
|
49 |
{
|
50 |
+
if ( class_exists('bbPress') ) {
|
51 |
unset( $post_types['topic'] );
|
52 |
unset( $post_types['reply'] );
|
53 |
unset( $post_types['forum'] );
|
54 |
}
|
55 |
+
|
56 |
return $post_types;
|
57 |
}
|
58 |
+
add_filter( 'cpac-get-post-types', 'remove_bbpress_from_cpac_post_types' );
|
59 |
+
|
60 |
+
/**
|
61 |
+
* Add support for All in SEO columns
|
62 |
+
*
|
63 |
+
* @since 1.5
|
64 |
+
*/
|
65 |
+
function cpac_load_aioseop_addmycolumns()
|
66 |
+
{
|
67 |
+
if ( function_exists('aioseop_addmycolumns') ) {
|
68 |
+
aioseop_addmycolumns();
|
69 |
+
}
|
70 |
+
}
|
71 |
+
add_action( 'cpac-get-default-columns-posts', 'cpac_load_aioseop_addmycolumns' );
|
classes/values.php
CHANGED
@@ -7,70 +7,70 @@
|
|
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 |
|
@@ -83,8 +83,8 @@ class CPAC_Values
|
|
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 |
*
|
@@ -94,19 +94,19 @@ class CPAC_Values
|
|
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);
|
@@ -118,30 +118,30 @@ class CPAC_Values
|
|
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;
|
@@ -150,71 +150,71 @@ class CPAC_Values
|
|
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 |
*
|
@@ -225,244 +225,244 @@ class CPAC_Values
|
|
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 (
|
238 |
$type = 'wp-users';
|
239 |
}
|
240 |
-
|
241 |
/** Media */
|
242 |
-
|
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 |
|
@@ -471,7 +471,7 @@ class CPAC_Values
|
|
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 ) ) {
|
@@ -483,46 +483,55 @@ class CPAC_Values
|
|
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 (
|
508 |
return false;
|
509 |
-
|
510 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
}
|
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 |
|
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 |
*
|
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);
|
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;
|
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 |
*
|
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 ( 'user' == $meta_type ) {
|
238 |
$type = 'wp-users';
|
239 |
}
|
240 |
+
|
241 |
/** Media */
|
242 |
+
elseif ( 'media' == $meta_type ) {
|
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 |
|
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 ) ) {
|
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 ( empty( $date ) || in_array( $date, array( '0000-00-00 00:00:00', '0000-00-00', '00:00:00' ) ) )
|
508 |
return false;
|
509 |
+
|
510 |
+
// Parse with strtotime if it's:
|
511 |
+
// - not numeric ( like a unixtimestamp )
|
512 |
+
// - date format: yyyymmdd ( format used by ACF ) must start with 19xx or 20xx and is 8 long
|
513 |
+
|
514 |
+
// @todo: in theory a numeric string of 8 can also be a unixtimestamp.
|
515 |
+
// we need to replace this with an option to mark a date as unixtimestamp.
|
516 |
+
if ( ! is_numeric($date) || ( is_numeric( $date ) && strlen( trim($date) ) == 8 && ( strpos( $date, '20' ) === 0 || strpos( $date, '19' ) === 0 ) ) )
|
517 |
+
$date = strtotime($date);
|
518 |
+
|
519 |
+
return date_i18n( get_option('date_format'), $date );
|
520 |
}
|
521 |
+
|
522 |
/**
|
523 |
* Get time
|
524 |
*
|
525 |
* @since 1.3.1
|
526 |
*/
|
527 |
+
protected function get_time($date)
|
528 |
{
|
529 |
if ( ! $date )
|
530 |
return false;
|
531 |
+
|
532 |
if ( ! is_numeric($date) )
|
533 |
$date = strtotime($date);
|
534 |
+
|
535 |
return date_i18n( get_option('time_format'), $date );
|
536 |
}
|
537 |
}
|
classes/values/comments.php
CHANGED
@@ -7,7 +7,7 @@
|
|
7 |
*
|
8 |
*/
|
9 |
class CPAC_Comments_Values extends CPAC_Values
|
10 |
-
{
|
11 |
/**
|
12 |
* Constructor
|
13 |
*
|
@@ -16,10 +16,10 @@ class CPAC_Comments_Values extends CPAC_Values
|
|
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 |
*
|
@@ -28,126 +28,126 @@ class CPAC_Comments_Values extends CPAC_Values
|
|
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 |
*
|
@@ -155,14 +155,14 @@ class CPAC_Comments_Values extends CPAC_Values
|
|
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" ) );
|
@@ -177,7 +177,7 @@ class CPAC_Comments_Values extends CPAC_Values
|
|
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
|
7 |
*
|
8 |
*/
|
9 |
class CPAC_Comments_Values extends CPAC_Values
|
10 |
+
{
|
11 |
/**
|
12 |
* Constructor
|
13 |
*
|
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 |
*
|
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 |
*
|
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" ) );
|
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
|
classes/values/link.php
CHANGED
@@ -1,124 +1,124 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* CPAC_Link_Values Class
|
5 |
-
*
|
6 |
-
* @since 1.4.4
|
7 |
-
*
|
8 |
-
*/
|
9 |
-
class CPAC_Link_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_link_custom_column', array( $this, 'manage_link_column_value'), 10, 2 );
|
21 |
-
}
|
22 |
-
|
23 |
-
/**
|
24 |
-
* Manage custom column for Links
|
25 |
-
*
|
26 |
-
* @since 1.3.1
|
27 |
-
*/
|
28 |
-
public function manage_link_column_value( $column_name, $link_id )
|
29 |
-
{
|
30 |
-
$type = $column_name;
|
31 |
-
|
32 |
-
// links object... called bookmark
|
33 |
-
$bookmark = get_bookmark($link_id);
|
34 |
-
|
35 |
-
// Hook
|
36 |
-
do_action('cpac-manage-link-column', $type, $column_name, $link_id);
|
37 |
-
|
38 |
-
$result = '';
|
39 |
-
switch ($type) :
|
40 |
-
|
41 |
-
// link id
|
42 |
-
case "column-link_id" :
|
43 |
-
$result = $link_id;
|
44 |
-
break;
|
45 |
-
|
46 |
-
// description
|
47 |
-
case "column-description" :
|
48 |
-
$result = $bookmark->link_description;
|
49 |
-
break;
|
50 |
-
|
51 |
-
// target
|
52 |
-
case "column-target" :
|
53 |
-
$result = $bookmark->link_target;
|
54 |
-
break;
|
55 |
-
|
56 |
-
// notes
|
57 |
-
case "column-notes" :
|
58 |
-
$result = $this->get_shortened_string($bookmark->link_notes, $this->excerpt_length);
|
59 |
-
break;
|
60 |
-
|
61 |
-
// rss
|
62 |
-
case "column-rss" :
|
63 |
-
$result = $this->get_shorten_url($bookmark->link_rss);
|
64 |
-
break;
|
65 |
-
|
66 |
-
// image
|
67 |
-
case "column-image" :
|
68 |
-
$result = $this->get_thumbnail($bookmark->link_image);
|
69 |
-
break;
|
70 |
-
|
71 |
-
// name length
|
72 |
-
case "column-length" :
|
73 |
-
$result = strlen($bookmark->link_name);
|
74 |
-
break;
|
75 |
-
|
76 |
-
// owner
|
77 |
-
case "column-owner" :
|
78 |
-
$result = $bookmark->link_owner;
|
79 |
-
|
80 |
-
// add user link
|
81 |
-
$userdata = get_userdata( $bookmark->link_owner );
|
82 |
-
if (!empty($userdata->data)) {
|
83 |
-
$result = $userdata->data->user_nicename;
|
84 |
-
//$result = "<a href='user-edit.php?user_id={$bookmark->link_owner}'>{$result}</a>";
|
85 |
-
}
|
86 |
-
break;
|
87 |
-
|
88 |
-
// link actions
|
89 |
-
case "column-actions" :
|
90 |
-
$result = $this->get_column_value_actions($bookmark);
|
91 |
-
break;
|
92 |
-
|
93 |
-
default :
|
94 |
-
$result = '';
|
95 |
-
|
96 |
-
endswitch;
|
97 |
-
|
98 |
-
// Filter for customizing the result output
|
99 |
-
apply_filters('cpac-link-column-result', $result, $type, $column_name, $link_id);
|
100 |
-
|
101 |
-
echo $result;
|
102 |
-
}
|
103 |
-
|
104 |
-
/**
|
105 |
-
* Get column value of link actions
|
106 |
-
*
|
107 |
-
* This part is copied from the Link List Table class
|
108 |
-
*
|
109 |
-
* @since 1.4.2
|
110 |
-
*/
|
111 |
-
private function get_column_value_actions( $link )
|
112 |
-
{
|
113 |
-
$actions = array();
|
114 |
-
|
115 |
-
$edit_link = get_edit_bookmark_link( $link );
|
116 |
-
|
117 |
-
$actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>';
|
118 |
-
$actions['delete'] = "<a class='submitdelete' href='" . wp_nonce_url( "link.php?action=delete&link_id=$link->link_id", 'delete-bookmark_' . $link->link_id ) . "' onclick=\"if ( confirm( '" . esc_js( sprintf( __( "You are about to delete this link '%s'\n 'Cancel' to stop, 'OK' to delete." ), $link->link_name ) ) . "' ) ) { return true;}return false;\">" . __( 'Delete' ) . "</a>";
|
119 |
-
|
120 |
-
return implode(' | ', $actions);
|
121 |
-
}
|
122 |
-
}
|
123 |
-
|
124 |
?>
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* CPAC_Link_Values Class
|
5 |
+
*
|
6 |
+
* @since 1.4.4
|
7 |
+
*
|
8 |
+
*/
|
9 |
+
class CPAC_Link_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_link_custom_column', array( $this, 'manage_link_column_value'), 10, 2 );
|
21 |
+
}
|
22 |
+
|
23 |
+
/**
|
24 |
+
* Manage custom column for Links
|
25 |
+
*
|
26 |
+
* @since 1.3.1
|
27 |
+
*/
|
28 |
+
public function manage_link_column_value( $column_name, $link_id )
|
29 |
+
{
|
30 |
+
$type = $column_name;
|
31 |
+
|
32 |
+
// links object... called bookmark
|
33 |
+
$bookmark = get_bookmark($link_id);
|
34 |
+
|
35 |
+
// Hook
|
36 |
+
do_action('cpac-manage-link-column', $type, $column_name, $link_id);
|
37 |
+
|
38 |
+
$result = '';
|
39 |
+
switch ($type) :
|
40 |
+
|
41 |
+
// link id
|
42 |
+
case "column-link_id" :
|
43 |
+
$result = $link_id;
|
44 |
+
break;
|
45 |
+
|
46 |
+
// description
|
47 |
+
case "column-description" :
|
48 |
+
$result = $bookmark->link_description;
|
49 |
+
break;
|
50 |
+
|
51 |
+
// target
|
52 |
+
case "column-target" :
|
53 |
+
$result = $bookmark->link_target;
|
54 |
+
break;
|
55 |
+
|
56 |
+
// notes
|
57 |
+
case "column-notes" :
|
58 |
+
$result = $this->get_shortened_string($bookmark->link_notes, $this->excerpt_length);
|
59 |
+
break;
|
60 |
+
|
61 |
+
// rss
|
62 |
+
case "column-rss" :
|
63 |
+
$result = $this->get_shorten_url($bookmark->link_rss);
|
64 |
+
break;
|
65 |
+
|
66 |
+
// image
|
67 |
+
case "column-image" :
|
68 |
+
$result = $this->get_thumbnail($bookmark->link_image);
|
69 |
+
break;
|
70 |
+
|
71 |
+
// name length
|
72 |
+
case "column-length" :
|
73 |
+
$result = strlen($bookmark->link_name);
|
74 |
+
break;
|
75 |
+
|
76 |
+
// owner
|
77 |
+
case "column-owner" :
|
78 |
+
$result = $bookmark->link_owner;
|
79 |
+
|
80 |
+
// add user link
|
81 |
+
$userdata = get_userdata( $bookmark->link_owner );
|
82 |
+
if (!empty($userdata->data)) {
|
83 |
+
$result = $userdata->data->user_nicename;
|
84 |
+
//$result = "<a href='user-edit.php?user_id={$bookmark->link_owner}'>{$result}</a>";
|
85 |
+
}
|
86 |
+
break;
|
87 |
+
|
88 |
+
// link actions
|
89 |
+
case "column-actions" :
|
90 |
+
$result = $this->get_column_value_actions($bookmark);
|
91 |
+
break;
|
92 |
+
|
93 |
+
default :
|
94 |
+
$result = '';
|
95 |
+
|
96 |
+
endswitch;
|
97 |
+
|
98 |
+
// Filter for customizing the result output
|
99 |
+
apply_filters('cpac-link-column-result', $result, $type, $column_name, $link_id);
|
100 |
+
|
101 |
+
echo $result;
|
102 |
+
}
|
103 |
+
|
104 |
+
/**
|
105 |
+
* Get column value of link actions
|
106 |
+
*
|
107 |
+
* This part is copied from the Link List Table class
|
108 |
+
*
|
109 |
+
* @since 1.4.2
|
110 |
+
*/
|
111 |
+
private function get_column_value_actions( $link )
|
112 |
+
{
|
113 |
+
$actions = array();
|
114 |
+
|
115 |
+
$edit_link = get_edit_bookmark_link( $link );
|
116 |
+
|
117 |
+
$actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>';
|
118 |
+
$actions['delete'] = "<a class='submitdelete' href='" . wp_nonce_url( "link.php?action=delete&link_id=$link->link_id", 'delete-bookmark_' . $link->link_id ) . "' onclick=\"if ( confirm( '" . esc_js( sprintf( __( "You are about to delete this link '%s'\n 'Cancel' to stop, 'OK' to delete." ), $link->link_name ) ) . "' ) ) { return true;}return false;\">" . __( 'Delete' ) . "</a>";
|
119 |
+
|
120 |
+
return implode(' | ', $actions);
|
121 |
+
}
|
122 |
+
}
|
123 |
+
|
124 |
?>
|
classes/values/media.php
CHANGED
@@ -7,7 +7,7 @@
|
|
7 |
*
|
8 |
*/
|
9 |
class CPAC_Media_Values extends CPAC_Values
|
10 |
-
{
|
11 |
/**
|
12 |
* Constructor
|
13 |
*
|
@@ -16,10 +16,10 @@ class CPAC_Media_Values extends CPAC_Values
|
|
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 |
*
|
@@ -28,92 +28,92 @@ class CPAC_Media_Values extends CPAC_Values
|
|
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);
|
@@ -121,66 +121,66 @@ class CPAC_Media_Values extends CPAC_Values
|
|
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 |
*
|
@@ -188,23 +188,23 @@ class CPAC_Media_Values extends CPAC_Values
|
|
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 |
}
|
7 |
*
|
8 |
*/
|
9 |
class CPAC_Media_Values extends CPAC_Values
|
10 |
+
{
|
11 |
/**
|
12 |
* Constructor
|
13 |
*
|
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 |
*
|
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);
|
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 |
*
|
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 |
}
|
classes/values/posts.php
CHANGED
@@ -7,108 +7,108 @@
|
|
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
|
@@ -118,24 +118,24 @@ class CPAC_Posts_Values extends CPAC_Values
|
|
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;
|
@@ -143,7 +143,7 @@ class CPAC_Posts_Values extends CPAC_Values
|
|
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);
|
@@ -151,7 +151,7 @@ class CPAC_Posts_Values extends CPAC_Values
|
|
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);
|
@@ -159,7 +159,7 @@ class CPAC_Posts_Values extends CPAC_Values
|
|
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);
|
@@ -167,56 +167,56 @@ class CPAC_Posts_Values extends CPAC_Values
|
|
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 ),
|
@@ -226,13 +226,13 @@ class CPAC_Posts_Values extends CPAC_Values
|
|
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 |
*
|
@@ -259,13 +259,13 @@ class CPAC_Posts_Values extends CPAC_Values
|
|
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 |
*
|
@@ -273,15 +273,15 @@ class CPAC_Posts_Values extends CPAC_Values
|
|
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 Edit' ) . '</a>';
|
@@ -301,41 +301,41 @@ class CPAC_Posts_Values extends CPAC_Values
|
|
301 |
} elseif ( 'trash' != $post->post_status ) {
|
302 |
$actions['view'] = '<a href="' . get_permalink( $post->ID ) . '" title="' . esc_attr( sprintf( __( 'View “%s”' ), $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 |
}
|
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
|
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;
|
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);
|
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);
|
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);
|
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 ),
|
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 |
*
|
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 |
*
|
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 Edit' ) . '</a>';
|
301 |
} elseif ( 'trash' != $post->post_status ) {
|
302 |
$actions['view'] = '<a href="' . get_permalink( $post->ID ) . '" title="' . esc_attr( sprintf( __( 'View “%s”' ), $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 |
}
|
classes/values/users.php
CHANGED
@@ -7,7 +7,7 @@
|
|
7 |
*
|
8 |
*/
|
9 |
class CPAC_Users_Values extends CPAC_Values
|
10 |
-
{
|
11 |
/**
|
12 |
* Constructor
|
13 |
*
|
@@ -16,10 +16,10 @@ class CPAC_Users_Values extends CPAC_Values
|
|
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 |
*
|
@@ -28,93 +28,93 @@ class CPAC_Users_Values extends CPAC_Values
|
|
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 |
*
|
@@ -122,24 +122,24 @@ class CPAC_Users_Values extends CPAC_Values
|
|
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}&";
|
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>';
|
@@ -151,7 +151,7 @@ class CPAC_Users_Values extends CPAC_Values
|
|
151 |
$actions['delete'] = "<a class='submitdelete' href='" . wp_nonce_url( "users.php?action=delete&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&user=$user_object->ID", 'bulk-users' ) . "'>" . __( 'Remove' ) . "</a>";
|
154 |
-
|
155 |
return implode(' | ', $actions);
|
156 |
}
|
157 |
}
|
7 |
*
|
8 |
*/
|
9 |
class CPAC_Users_Values extends CPAC_Values
|
10 |
+
{
|
11 |
/**
|
12 |
* Constructor
|
13 |
*
|
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 |
*
|
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 |
*
|
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}&";
|
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>';
|
151 |
$actions['delete'] = "<a class='submitdelete' href='" . wp_nonce_url( "users.php?action=delete&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&user=$user_object->ID", 'bulk-users' ) . "'>" . __( 'Remove' ) . "</a>";
|
154 |
+
|
155 |
return implode(' | ', $actions);
|
156 |
}
|
157 |
}
|
codepress-admin-columns.php
CHANGED
@@ -2,8 +2,8 @@
|
|
2 |
/*
|
3 |
|
4 |
Plugin Name: Codepress Admin Columns
|
5 |
-
Version: 1.4.
|
6 |
-
Description:
|
7 |
Author: Codepress
|
8 |
Author URI: http://www.codepress.nl
|
9 |
Plugin URI: http://www.codepress.nl/plugins/codepress-admin-columns/
|
@@ -27,7 +27,7 @@ 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.
|
31 |
define( 'CPAC_TEXTDOMAIN', 'codepress-admin-columns' );
|
32 |
define( 'CPAC_SLUG', 'codepress-admin-columns' );
|
33 |
define( 'CPAC_URL', plugins_url('', __FILE__) );
|
@@ -41,15 +41,15 @@ if ( !is_admin() )
|
|
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
|
@@ -57,25 +57,25 @@ require_once dirname( __FILE__ ) . '/classes/license.php';
|
|
57 |
* @since 1.0
|
58 |
*
|
59 |
*/
|
60 |
-
class Codepress_Admin_Columns
|
61 |
-
{
|
62 |
private $post_types,
|
63 |
$codepress_url,
|
64 |
$wordpress_url,
|
65 |
$admin_page,
|
66 |
$use_hidden_custom_fields;
|
67 |
-
|
68 |
/**
|
69 |
* Constructor
|
70 |
*
|
71 |
* @since 1.0
|
72 |
*/
|
73 |
function __construct()
|
74 |
-
{
|
75 |
// wp is loaded
|
76 |
add_action( 'wp_loaded', array( $this, 'init') );
|
77 |
}
|
78 |
-
|
79 |
/**
|
80 |
* Initialize plugin.
|
81 |
*
|
@@ -90,37 +90,37 @@ class Codepress_Admin_Columns
|
|
90 |
|
91 |
// set
|
92 |
$this->codepress_url = 'http://www.codepress.nl/plugins/codepress-admin-columns';
|
93 |
-
$this->plugins_url = 'http://wordpress.org/extend/plugins/codepress-admin-columns/';
|
94 |
-
$this->wordpress_url = 'http://wordpress.org/tags/codepress-admin-columns';
|
95 |
-
|
96 |
// enable the use of custom hidden fields
|
97 |
$this->use_hidden_custom_fields = apply_filters('cpac_use_hidden_custom_fields', false);
|
98 |
-
|
99 |
// translations
|
100 |
load_plugin_textdomain( CPAC_TEXTDOMAIN, false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
|
101 |
-
|
102 |
// register settings
|
103 |
-
add_action( 'admin_menu', array( $this, 'settings_menu') );
|
104 |
add_action( 'admin_init', array( $this, 'register_settings') );
|
105 |
|
106 |
// styling & scripts
|
107 |
add_action( 'admin_enqueue_scripts' , array( $this, 'column_styles') );
|
108 |
add_filter( 'admin_body_class', array( $this, 'admin_class' ) );
|
109 |
add_action( 'admin_head', array( $this, 'admin_css') );
|
110 |
-
|
111 |
// register columns
|
112 |
add_action( 'admin_init', array( $this, 'register_columns_headings' ) );
|
113 |
-
add_action( 'admin_init', array( $this, 'register_columns_values' ) );
|
114 |
-
|
115 |
// action ajax
|
116 |
add_action( 'wp_ajax_cpac_addon_activation', array( $this, 'ajax_activation'));
|
117 |
-
|
118 |
// handle requests gets a low priority so it will trigger when all other plugins have loaded their columns
|
119 |
-
add_action( 'admin_init', array( $this, 'handle_requests' ), 1000 );
|
120 |
-
|
121 |
// filters
|
122 |
-
add_filter( 'plugin_action_links', array( $this, 'add_settings_link'), 1, 2);
|
123 |
-
}
|
124 |
|
125 |
/**
|
126 |
* Admin Menu.
|
@@ -129,32 +129,32 @@ class Codepress_Admin_Columns
|
|
129 |
*
|
130 |
* @since 1.0
|
131 |
*/
|
132 |
-
public function settings_menu()
|
133 |
{
|
134 |
$page = add_options_page(
|
135 |
// Page title
|
136 |
-
esc_html__( 'Admin Columns Settings', CPAC_TEXTDOMAIN ),
|
137 |
// Menu Title
|
138 |
-
esc_html__( 'Admin Columns', CPAC_TEXTDOMAIN ),
|
139 |
// Capability
|
140 |
'manage_options',
|
141 |
// Menu slug
|
142 |
CPAC_SLUG,
|
143 |
// Callback
|
144 |
array( $this, 'plugin_settings_page')
|
145 |
-
);
|
146 |
|
147 |
// set admin page
|
148 |
$this->admin_page = $page;
|
149 |
-
|
150 |
// settings page specific styles and scripts
|
151 |
add_action( "admin_print_styles-$page", array( $this, 'admin_styles') );
|
152 |
add_action( "admin_print_scripts-$page", array( $this, 'admin_scripts') );
|
153 |
-
|
154 |
// add help tabs
|
155 |
add_action("load-$page", array( $this, 'help_tabs'));
|
156 |
}
|
157 |
-
|
158 |
/**
|
159 |
* Add Settings link to plugin page
|
160 |
*
|
@@ -163,17 +163,17 @@ class Codepress_Admin_Columns
|
|
163 |
* @param $file string - plugin filename
|
164 |
* @return string - link to settings page
|
165 |
*/
|
166 |
-
function add_settings_link( $links, $file )
|
167 |
{
|
168 |
if ( $file != plugin_basename( __FILE__ ))
|
169 |
return $links;
|
170 |
|
171 |
array_unshift($links, '<a href="' . admin_url("admin.php") . '?page=' . CPAC_SLUG . '">' . __( 'Settings' ) . '</a>');
|
172 |
return $links;
|
173 |
-
}
|
174 |
-
|
175 |
/**
|
176 |
-
* Register Column Values
|
177 |
*
|
178 |
* initializes each Class per type
|
179 |
*
|
@@ -195,144 +195,144 @@ class Codepress_Admin_Columns
|
|
195 |
* @since 1.0
|
196 |
*/
|
197 |
public function register_columns_headings()
|
198 |
-
{
|
199 |
-
/** Posts */
|
200 |
foreach ( $this->post_types as $post_type ) {
|
201 |
|
202 |
// register column per post type
|
203 |
add_filter("manage_edit-{$post_type}_columns", array($this, 'callback_add_posts_column_headings'));
|
204 |
-
}
|
205 |
-
|
206 |
/** Users */
|
207 |
-
add_filter( "manage_users_columns", array($this, 'callback_add_users_column_headings'), 9);
|
208 |
// give higher priority, so it will load just before other plugins to prevent conflicts
|
209 |
-
|
210 |
/** Media */
|
211 |
add_filter( "manage_upload_columns", array($this, 'callback_add_media_column_headings'));
|
212 |
-
|
213 |
/** Links */
|
214 |
add_filter( "manage_link-manager_columns", array($this, 'callback_add_links_column_headings'));
|
215 |
-
|
216 |
/** Comments */
|
217 |
add_filter( "manage_edit-comments_columns", array($this, 'callback_add_comments_column_headings'));
|
218 |
}
|
219 |
-
|
220 |
/**
|
221 |
* Callback add Posts Column
|
222 |
*
|
223 |
* @since 1.0
|
224 |
*/
|
225 |
-
public function callback_add_posts_column_headings($columns)
|
226 |
{
|
227 |
-
return $this->add_columns_headings( get_post_type(), $columns);
|
228 |
}
|
229 |
-
|
230 |
/**
|
231 |
* Callback add Users column
|
232 |
*
|
233 |
* @since 1.1
|
234 |
*/
|
235 |
-
public function callback_add_users_column_headings($columns)
|
236 |
{
|
237 |
return $this->add_columns_headings('wp-users', $columns);
|
238 |
}
|
239 |
-
|
240 |
/**
|
241 |
* Callback add Media column
|
242 |
*
|
243 |
* @since 1.3
|
244 |
*/
|
245 |
-
public function callback_add_media_column_headings($columns)
|
246 |
{
|
247 |
return $this->add_columns_headings('wp-media', $columns);
|
248 |
}
|
249 |
-
|
250 |
/**
|
251 |
* Callback add Links column
|
252 |
*
|
253 |
* @since 1.3.1
|
254 |
*/
|
255 |
-
public function callback_add_links_column_headings($columns)
|
256 |
{
|
257 |
return $this->add_columns_headings('wp-links', $columns);
|
258 |
}
|
259 |
-
|
260 |
/**
|
261 |
* Callback add Comments column
|
262 |
*
|
263 |
* @since 1.3.1
|
264 |
*/
|
265 |
-
public function callback_add_comments_column_headings($columns)
|
266 |
{
|
267 |
return $this->add_columns_headings('wp-comments', $columns);
|
268 |
}
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
/**
|
273 |
* Add managed columns by Type
|
274 |
*
|
275 |
* @since 1.4.6.5
|
276 |
*/
|
277 |
-
private function get_comment_icon()
|
278 |
{
|
279 |
return "<span class='vers'><img src='" . trailingslashit( get_admin_url() ) . 'images/comment-grey-bubble.png' . "' alt='Comments'></span>";
|
280 |
}
|
281 |
-
|
282 |
/**
|
283 |
* Add managed columns by Type
|
284 |
*
|
285 |
* @since 1.1
|
286 |
*/
|
287 |
-
protected function add_columns_headings( $type, $columns )
|
288 |
{
|
289 |
// only get stored columns.. the rest we don't need
|
290 |
$db_columns = self::get_stored_columns($type);
|
291 |
|
292 |
if ( !$db_columns )
|
293 |
return $columns;
|
294 |
-
|
295 |
// filter already loaded columns by plugins
|
296 |
$set_columns = $this->filter_preset_columns( $type, $columns );
|
297 |
|
298 |
// loop through columns
|
299 |
-
foreach ( $db_columns as $id => $values ) {
|
300 |
// is active
|
301 |
-
if ( isset($values['state']) && $values['state'] == 'on' ){
|
302 |
-
|
303 |
$label = $values['label'];
|
304 |
-
|
305 |
// exception for comments
|
306 |
if( 'comments' == $id ) {
|
307 |
$label = $this->get_comment_icon();
|
308 |
}
|
309 |
-
|
310 |
// register format
|
311 |
$set_columns[$id] = $label;
|
312 |
}
|
313 |
}
|
314 |
-
|
315 |
return $set_columns;
|
316 |
}
|
317 |
-
|
318 |
/**
|
319 |
* Filter preset columns. These columns apply either for every post or set by a plugin.
|
320 |
*
|
321 |
* @since 1.0
|
322 |
*/
|
323 |
-
private function filter_preset_columns( $type, $columns )
|
324 |
{
|
325 |
$options = get_option('cpac_options_default');
|
326 |
-
|
327 |
if ( !$options )
|
328 |
return $columns;
|
329 |
-
|
330 |
// we use the wp default columns for filtering...
|
331 |
$stored_wp_default_columns = $options[$type];
|
332 |
|
333 |
// ... the ones that are set by plugins, theme functions and such.
|
334 |
$dif_columns = array_diff(array_keys($columns), array_keys($stored_wp_default_columns));
|
335 |
-
|
336 |
// we add those to the columns
|
337 |
$pre_columns = array();
|
338 |
if ( $dif_columns ) {
|
@@ -340,32 +340,32 @@ class Codepress_Admin_Columns
|
|
340 |
$pre_columns[$column] = $columns[$column];
|
341 |
}
|
342 |
}
|
343 |
-
|
344 |
return $pre_columns;
|
345 |
}
|
346 |
-
|
347 |
/**
|
348 |
* Get a list of Column options per post type
|
349 |
*
|
350 |
* @since 1.0
|
351 |
*/
|
352 |
-
private function get_column_boxes($type)
|
353 |
-
{
|
354 |
// merge all columns
|
355 |
$display_columns = $this->get_merged_columns($type);
|
356 |
-
|
357 |
// define
|
358 |
-
$list = '';
|
359 |
-
|
360 |
// loop throught the active columns
|
361 |
if ( $display_columns ) {
|
362 |
-
foreach ( $display_columns as $id => $values ) {
|
363 |
-
|
364 |
$classes = array();
|
365 |
|
366 |
// set state
|
367 |
$state = isset($values['state']) ? $values['state'] : '';
|
368 |
-
|
369 |
// class
|
370 |
$classes[] = "cpac-box-{$id}";
|
371 |
if ( $state ) {
|
@@ -375,39 +375,39 @@ class Codepress_Admin_Columns
|
|
375 |
$classes[] = $values['options']['class'];
|
376 |
}
|
377 |
$class = implode(' ', $classes);
|
378 |
-
|
379 |
-
// more box options
|
380 |
$more_options = $this->get_additional_box_options($type, $id, $values);
|
381 |
$action = "<a class='cpac-action' href='#open'>open</a>";
|
382 |
-
|
383 |
// type label
|
384 |
$type_label = isset($values['options']['type_label']) ? $values['options']['type_label'] : '';
|
385 |
-
|
386 |
// label
|
387 |
$label = isset($values['label']) ? str_replace("'", '"', $values['label']) : '';
|
388 |
-
|
389 |
// main label
|
390 |
-
$main_label = $values['label'];
|
391 |
-
|
392 |
// main label exception for comments
|
393 |
if ( 'comments' == $id ) {
|
394 |
$main_label = $this->get_comment_icon();
|
395 |
}
|
396 |
-
|
397 |
// width
|
398 |
$width = isset($values['width']) ? $values['width'] : 0;
|
399 |
$width_descr = isset($values['width']) && $values['width'] > 0 ? $values['width'] . '%' : __('default', CPAC_TEXTDOMAIN);
|
400 |
-
|
401 |
// hide box options
|
402 |
$label_hidden = '';
|
403 |
if ( ! empty($values['options']['hide_options']) || strpos($label, '<img') !== false ) {
|
404 |
$label_hidden = ' style="display:none"';
|
405 |
}
|
406 |
-
|
407 |
$list .= "
|
408 |
<li class='{$class}'>
|
409 |
<div class='cpac-sort-handle'></div>
|
410 |
-
<div class='cpac-type-options'>
|
411 |
<div class='cpac-checkbox'></div>
|
412 |
<input type='hidden' class='cpac-state' name='cpac_options[columns][{$type}][{$id}][state]' value='{$state}'/>
|
413 |
<label class='main-label'>{$main_label}</label>
|
@@ -416,10 +416,10 @@ class Codepress_Admin_Columns
|
|
416 |
{$action}
|
417 |
<span>{$type_label}</span>
|
418 |
</div>
|
419 |
-
<div class='cpac-type-inside'>
|
420 |
<label for='cpac_options-{$type}-{$id}-label'{$label_hidden}>Label: </label>
|
421 |
<input type='text' name='cpac_options[columns][{$type}][{$id}][label]' id='cpac_options-{$type}-{$id}-label' value='{$label}' class='text'{$label_hidden}/>
|
422 |
-
<label for='cpac_options-{$type}-{$id}-width'>" . __('Width', CPAC_TEXTDOMAIN) . ":</label>
|
423 |
<input type='hidden' maxlength='4' class='input-width' name='cpac_options[columns][{$type}][{$id}][width]' id='cpac_options-{$type}-{$id}-width' value='{$width}' />
|
424 |
<div class='description width-decription' title='" . __('default', CPAC_TEXTDOMAIN) . "'>{$width_descr}</div>
|
425 |
<div class='input-width-range'></div>
|
@@ -427,22 +427,22 @@ class Codepress_Admin_Columns
|
|
427 |
{$more_options}
|
428 |
</div>
|
429 |
</li>
|
430 |
-
";
|
431 |
}
|
432 |
}
|
433 |
-
|
434 |
// custom field button
|
435 |
$button_add_column = '';
|
436 |
if ( $this->get_meta_by_type($type) )
|
437 |
$button_add_column = "<a href='javacript:;' class='cpac-add-customfield-column button'>+ " . __('Add Custom Field Column', CPAC_TEXTDOMAIN) . "</a>";
|
438 |
-
|
439 |
return "
|
440 |
<div class='cpac-box'>
|
441 |
<ul class='cpac-option-list'>
|
442 |
-
{$list}
|
443 |
</ul>
|
444 |
{$button_add_column}
|
445 |
-
<div class='cpac-reorder-msg'>" . __('drag and drop to reorder', CPAC_TEXTDOMAIN) . "</div>
|
446 |
</div>
|
447 |
";
|
448 |
}
|
@@ -452,81 +452,81 @@ class Codepress_Admin_Columns
|
|
452 |
*
|
453 |
* @since 1.0
|
454 |
*/
|
455 |
-
protected function get_merged_columns( $type )
|
456 |
{
|
457 |
/** Comments */
|
458 |
if ( $type == 'wp-comments' ) {
|
459 |
$wp_default_columns = $this->get_wp_default_comments_columns();
|
460 |
$wp_custom_columns = $this->get_custom_comments_columns();
|
461 |
}
|
462 |
-
|
463 |
/** Links */
|
464 |
elseif ( $type == 'wp-links' ) {
|
465 |
$wp_default_columns = $this->get_wp_default_links_columns();
|
466 |
$wp_custom_columns = $this->get_custom_links_columns();
|
467 |
}
|
468 |
-
|
469 |
/** Users */
|
470 |
elseif ( $type == 'wp-users' ) {
|
471 |
$wp_default_columns = $this->get_wp_default_users_columns();
|
472 |
$wp_custom_columns = $this->get_custom_users_columns();
|
473 |
}
|
474 |
-
|
475 |
/** Media */
|
476 |
elseif ( $type == 'wp-media' ) {
|
477 |
$wp_default_columns = $this->get_wp_default_media_columns();
|
478 |
$wp_custom_columns = $this->get_custom_media_columns();
|
479 |
}
|
480 |
-
|
481 |
/** Posts */
|
482 |
else {
|
483 |
$wp_default_columns = $this->get_wp_default_posts_columns($type);
|
484 |
$wp_custom_columns = $this->get_custom_posts_columns($type);
|
485 |
}
|
486 |
-
|
487 |
// merge columns
|
488 |
$display_columns = $this->parse_columns($wp_custom_columns, $wp_default_columns, $type);
|
489 |
-
|
490 |
-
return $display_columns;
|
491 |
}
|
492 |
-
|
493 |
/**
|
494 |
* Merge the default columns (set by WordPress) and the added custom columns (set by plugins, theme etc.)
|
495 |
*
|
496 |
* @since 1.3.3
|
497 |
*/
|
498 |
-
function parse_columns($wp_custom_columns, $wp_default_columns, $type)
|
499 |
{
|
500 |
// merge columns
|
501 |
$default_columns = wp_parse_args($wp_custom_columns, $wp_default_columns);
|
502 |
-
|
503 |
//get saved database columns
|
504 |
$db_columns = self::get_stored_columns($type);
|
505 |
if ( $db_columns ) {
|
506 |
-
|
507 |
// let's remove any unavailable columns.. such as disabled plugins
|
508 |
$db_columns = $this->remove_unavailable_columns($db_columns, $default_columns);
|
509 |
-
|
510 |
// loop throught the active columns
|
511 |
foreach ( $db_columns as $id => $values ) {
|
512 |
-
|
513 |
// get column meta options from custom columns
|
514 |
-
if ( $this->is_column_meta($id) && !empty($wp_custom_columns['column-meta-1']['options']) ) {
|
515 |
-
$db_columns[$id]['options'] = $wp_custom_columns['column-meta-1']['options'];
|
516 |
}
|
517 |
-
|
518 |
// add static options
|
519 |
elseif ( isset($default_columns[$id]['options']) )
|
520 |
$db_columns[$id]['options'] = $default_columns[$id]['options'];
|
521 |
-
|
522 |
-
unset($default_columns[$id]);
|
523 |
}
|
524 |
-
}
|
525 |
-
|
526 |
// merge all
|
527 |
return wp_parse_args($db_columns, $default_columns);
|
528 |
}
|
529 |
-
|
530 |
/**
|
531 |
* Remove deactivated (plugin) columns
|
532 |
*
|
@@ -539,31 +539,31 @@ class Codepress_Admin_Columns
|
|
539 |
{
|
540 |
// check or differences
|
541 |
$diff = array_diff( array_keys($db_columns), array_keys($default_columns) );
|
542 |
-
|
543 |
-
if ( ! empty($diff) && is_array($diff) ) {
|
544 |
-
foreach ( $diff as $column_name ){
|
545 |
// make an exception for column-meta-xxx
|
546 |
if ( ! $this->is_column_meta($column_name) ) {
|
547 |
unset($db_columns[$column_name]);
|
548 |
}
|
549 |
}
|
550 |
}
|
551 |
-
|
552 |
return $db_columns;
|
553 |
}
|
554 |
-
|
555 |
/**
|
556 |
* Get checkbox
|
557 |
*
|
558 |
* @since 1.0
|
559 |
*/
|
560 |
-
private function get_box($type, $id, $values)
|
561 |
{
|
562 |
$classes = array();
|
563 |
|
564 |
// set state
|
565 |
$state = isset($values['state']) ? $values['state'] : '';
|
566 |
-
|
567 |
// class
|
568 |
$classes[] = "cpac-box-{$id}";
|
569 |
if ( $state ) {
|
@@ -573,39 +573,39 @@ class Codepress_Admin_Columns
|
|
573 |
$classes[] = $values['options']['class'];
|
574 |
}
|
575 |
$class = implode(' ', $classes);
|
576 |
-
|
577 |
-
// more box options
|
578 |
$more_options = $this->get_additional_box_options($type, $id, $values);
|
579 |
$action = "<a class='cpac-action' href='#open'>open</a>";
|
580 |
-
|
581 |
// type label
|
582 |
$type_label = isset($values['options']['type_label']) ? $values['options']['type_label'] : '';
|
583 |
-
|
584 |
// label
|
585 |
$label = isset($values['label']) ? str_replace("'", '"', $values['label']) : '';
|
586 |
-
|
587 |
// main label
|
588 |
-
$main_label = $values['label'];
|
589 |
-
|
590 |
// main label exception for comments
|
591 |
if ( 'comments' == $id ) {
|
592 |
$main_label = $this->get_comment_icon();
|
593 |
}
|
594 |
-
|
595 |
// width
|
596 |
$width = isset($values['width']) ? $values['width'] : 0;
|
597 |
$width_descr = isset($values['width']) && $values['width'] > 0 ? $values['width'] . '%' : __('default', CPAC_TEXTDOMAIN);
|
598 |
-
|
599 |
// hide box options
|
600 |
$label_hidden = '';
|
601 |
if ( ! empty($values['options']['hide_options']) || strpos($label, '<img') !== false ) {
|
602 |
$label_hidden = ' style="display:none"';
|
603 |
}
|
604 |
-
|
605 |
$list = "
|
606 |
<li class='{$class}'>
|
607 |
<div class='cpac-sort-handle'></div>
|
608 |
-
<div class='cpac-type-options'>
|
609 |
<div class='cpac-checkbox'></div>
|
610 |
<input type='hidden' class='cpac-state' name='cpac_options[columns][{$type}][{$id}][state]' value='{$state}'/>
|
611 |
<label class='main-label'>{$main_label}</label>
|
@@ -614,10 +614,10 @@ class Codepress_Admin_Columns
|
|
614 |
{$action}
|
615 |
<span>{$type_label}</span>
|
616 |
</div>
|
617 |
-
<div class='cpac-type-inside'>
|
618 |
<label for='cpac_options-{$type}-{$id}-label'{$label_hidden}>Label: </label>
|
619 |
<input type='text' name='cpac_options[columns][{$type}][{$id}][label]' id='cpac_options-{$type}-{$id}-label' value='{$label}' class='text'{$label_hidden}/>
|
620 |
-
<label for='cpac_options-{$type}-{$id}-width'>" . __('Width', CPAC_TEXTDOMAIN) . ":</label>
|
621 |
<input type='hidden' maxlength='4' class='input-width' name='cpac_options[columns][{$type}][{$id}][width]' id='cpac_options-{$type}-{$id}-width' value='{$width}' />
|
622 |
<div class='description width-decription' title='" . __('default', CPAC_TEXTDOMAIN) . "'>{$width_descr}</div>
|
623 |
<div class='input-width-range'></div>
|
@@ -626,7 +626,7 @@ class Codepress_Admin_Columns
|
|
626 |
</div>
|
627 |
</li>
|
628 |
";
|
629 |
-
|
630 |
return $list;
|
631 |
}
|
632 |
|
@@ -635,20 +635,20 @@ class Codepress_Admin_Columns
|
|
635 |
*
|
636 |
* @since 1.0
|
637 |
*/
|
638 |
-
private function get_additional_box_options($type, $id, $values)
|
639 |
{
|
640 |
$fields = '';
|
641 |
-
|
642 |
// Custom Fields
|
643 |
if( $this->is_column_meta($id) ) {
|
644 |
$fields = $this->get_box_options_customfields($type, $id, $values);
|
645 |
}
|
646 |
-
|
647 |
// Author Fields
|
648 |
if( 'column-author-name' == $id) {
|
649 |
$fields = $this->get_box_options_author($type, $id, $values);
|
650 |
}
|
651 |
-
|
652 |
return $fields;
|
653 |
}
|
654 |
|
@@ -657,30 +657,30 @@ class Codepress_Admin_Columns
|
|
657 |
*
|
658 |
* @since 1.0
|
659 |
*/
|
660 |
-
private function get_box_options_customfields($type, $id, $values)
|
661 |
{
|
662 |
-
// get post meta fields
|
663 |
$fields = $this->get_meta_by_type($type);
|
664 |
-
|
665 |
-
if ( empty($fields) )
|
666 |
return false;
|
667 |
-
|
668 |
// set meta field options
|
669 |
$current = ! empty($values['field']) ? $values['field'] : '' ;
|
670 |
$field_options = '';
|
671 |
foreach ($fields as $field) {
|
672 |
-
|
673 |
$field_options .= sprintf
|
674 |
(
|
675 |
'<option value="%s"%s>%s</option>',
|
676 |
$field,
|
677 |
$field == $current? ' selected="selected"':'',
|
678 |
-
|
679 |
// change label on hidden fields
|
680 |
-
substr($field,0,10) == "cpachidden" ? str_replace('cpachidden','',$field) : $field
|
681 |
-
);
|
682 |
}
|
683 |
-
|
684 |
// set meta fieldtype options
|
685 |
$currenttype = ! empty($values['field_type']) ? $values['field_type'] : '' ;
|
686 |
$fieldtype_options = '';
|
@@ -697,10 +697,10 @@ class Codepress_Admin_Columns
|
|
697 |
'checkmark' => __('Checkmark (true/false)', CPAC_TEXTDOMAIN),
|
698 |
'color' => __('Color', CPAC_TEXTDOMAIN),
|
699 |
);
|
700 |
-
|
701 |
// add filter
|
702 |
$fieldtypes = apply_filters('cpac-field-types', $fieldtypes );
|
703 |
-
|
704 |
// set select options
|
705 |
foreach ( $fieldtypes as $fkey => $fieldtype ) {
|
706 |
$fieldtype_options .= sprintf
|
@@ -711,14 +711,14 @@ class Codepress_Admin_Columns
|
|
711 |
$fieldtype
|
712 |
);
|
713 |
}
|
714 |
-
|
715 |
// before and after string
|
716 |
$before = ! empty($values['before']) ? $values['before'] : '' ;
|
717 |
$after = ! empty($values['after']) ? $values['after'] : '' ;
|
718 |
-
|
719 |
if ( empty($field_options) )
|
720 |
return false;
|
721 |
-
|
722 |
// add remove button
|
723 |
$remove = '<p class="remove-description description">'.__('This field can not be removed', CPAC_TEXTDOMAIN).'</p>';
|
724 |
if ( $id != 'column-meta-1') {
|
@@ -728,7 +728,7 @@ class Codepress_Admin_Columns
|
|
728 |
</p>
|
729 |
";
|
730 |
}
|
731 |
-
|
732 |
$inside = "
|
733 |
<label for='cpac-{$type}-{$id}-field'>".__('Custom Field', CPAC_TEXTDOMAIN).": </label>
|
734 |
<select name='cpac_options[columns][{$type}][{$id}][field]' id='cpac-{$type}-{$id}-field'>{$field_options}</select>
|
@@ -737,23 +737,23 @@ class Codepress_Admin_Columns
|
|
737 |
<select name='cpac_options[columns][{$type}][{$id}][field_type]' id='cpac-{$type}-{$id}-field_type'>{$fieldtype_options}</select>
|
738 |
<br/>
|
739 |
<label for='cpac-{$type}-{$id}-before'>".__('Before', CPAC_TEXTDOMAIN).": </label>
|
740 |
-
<input type='text' class='cpac-before' name='cpac_options[columns][{$type}][{$id}][before]' id='cpac-{$type}-{$id}-before' value='{$before}'/>
|
741 |
-
<br/>
|
742 |
<label for='cpac-{$type}-{$id}-after'>".__('After', CPAC_TEXTDOMAIN).": </label>
|
743 |
-
<input type='text' class='cpac-after' name='cpac_options[columns][{$type}][{$id}][after]' id='cpac-{$type}-{$id}-after' value='{$after}'/>
|
744 |
-
<br/>
|
745 |
{$remove}
|
746 |
";
|
747 |
-
|
748 |
return $inside;
|
749 |
}
|
750 |
-
|
751 |
/**
|
752 |
* Box Options: Custom Fields
|
753 |
*
|
754 |
* @since 1.0
|
755 |
*/
|
756 |
-
private function get_box_options_author($type, $id, $values)
|
757 |
{
|
758 |
$options = '';
|
759 |
$author_types = array(
|
@@ -771,14 +771,14 @@ class Codepress_Admin_Columns
|
|
771 |
$selected = selected( $k, $currentname, false);
|
772 |
$options .= "<option value='{$k}' {$selected}>{$name}</option>";
|
773 |
}
|
774 |
-
|
775 |
$inside = "
|
776 |
<label for='cpac-{$type}-{$id}-display_as'>".__('Display name as', CPAC_TEXTDOMAIN).": </label>
|
777 |
<select name='cpac_options[columns][{$type}][{$id}][display_as]' id='cpac-{$type}-{$id}-display_as'>
|
778 |
{$options}
|
779 |
-
</select>
|
780 |
";
|
781 |
-
|
782 |
return $inside;
|
783 |
}
|
784 |
|
@@ -787,7 +787,7 @@ class Codepress_Admin_Columns
|
|
787 |
*
|
788 |
* @since 1.0
|
789 |
*/
|
790 |
-
private function get_meta_by_type($type = 'post')
|
791 |
{
|
792 |
global $wpdb;
|
793 |
|
@@ -795,46 +795,46 @@ class Codepress_Admin_Columns
|
|
795 |
if ( $type == 'wp-comments') {
|
796 |
$sql = "SELECT DISTINCT meta_key FROM {$wpdb->commentmeta} ORDER BY 1";
|
797 |
}
|
798 |
-
|
799 |
/** Users */
|
800 |
elseif ( $type == 'wp-users') {
|
801 |
$sql = "SELECT DISTINCT meta_key FROM {$wpdb->usermeta} ORDER BY 1";
|
802 |
}
|
803 |
-
|
804 |
/** Media */
|
805 |
elseif ( $type == 'wp-media') {
|
806 |
$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";
|
807 |
}
|
808 |
-
|
809 |
/** Posts */
|
810 |
else {
|
811 |
$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);
|
812 |
}
|
813 |
-
|
814 |
// run sql
|
815 |
$fields = $wpdb->get_results($sql, ARRAY_N);
|
816 |
-
|
817 |
// filter out hidden meta fields
|
818 |
$meta_fields = array();
|
819 |
-
if ( $fields ) {
|
820 |
foreach ($fields as $field) {
|
821 |
-
|
822 |
// give hidden fields a prefix for identifaction
|
823 |
if ( $this->use_hidden_custom_fields && substr($field[0],0,1) == "_") {
|
824 |
$meta_fields[] = 'cpachidden'.$field[0];
|
825 |
}
|
826 |
-
|
827 |
// non hidden fields are saved as is
|
828 |
elseif ( substr($field[0],0,1) != "_" ) {
|
829 |
$meta_fields[] = $field[0];
|
830 |
-
}
|
831 |
-
}
|
832 |
}
|
833 |
-
|
834 |
-
if (
|
835 |
-
|
836 |
-
|
837 |
-
return
|
838 |
}
|
839 |
|
840 |
/**
|
@@ -842,14 +842,14 @@ class Codepress_Admin_Columns
|
|
842 |
*
|
843 |
* @since 1.0
|
844 |
*/
|
845 |
-
public function admin_scripts()
|
846 |
{
|
847 |
wp_enqueue_script( 'wp-pointer' );
|
848 |
-
wp_enqueue_script( 'jquery-ui-slider' );
|
849 |
wp_enqueue_script( 'cpac-qtip2', CPAC_URL.'/assets/js/jquery.qtip.js', array('jquery'), CPAC_VERSION );
|
850 |
wp_enqueue_script( 'cpac-admin', CPAC_URL.'/assets/js/admin-column.js', array('jquery', 'dashboard', 'jquery-ui-sortable'), CPAC_VERSION );
|
851 |
-
}
|
852 |
-
|
853 |
/**
|
854 |
* Get column types
|
855 |
*
|
@@ -862,10 +862,10 @@ class Codepress_Admin_Columns
|
|
862 |
$types['wp-media'] = 'wp-media';
|
863 |
$types['wp-links'] = 'wp-links';
|
864 |
$types['wp-comments'] = 'wp-comments';
|
865 |
-
|
866 |
return $types;
|
867 |
}
|
868 |
-
|
869 |
/**
|
870 |
* Get post types
|
871 |
*
|
@@ -878,7 +878,7 @@ class Codepress_Admin_Columns
|
|
878 |
));
|
879 |
$post_types['post'] = 'post';
|
880 |
$post_types['page'] = 'page';
|
881 |
-
|
882 |
return apply_filters('cpac-get-post-types', $post_types);
|
883 |
}
|
884 |
|
@@ -890,10 +890,10 @@ class Codepress_Admin_Columns
|
|
890 |
public function admin_styles()
|
891 |
{
|
892 |
wp_enqueue_style( 'wp-pointer' );
|
893 |
-
wp_enqueue_style( 'jquery-ui-lightness', CPAC_URL.'/assets/ui-theme/jquery-ui-1.8.18.custom.css', array(), CPAC_VERSION, 'all' );
|
894 |
-
wp_enqueue_style( 'cpac-admin', CPAC_URL.'/assets/css/admin-column.css', array(), CPAC_VERSION, 'all' );
|
895 |
}
|
896 |
-
|
897 |
/**
|
898 |
* Register column css
|
899 |
*
|
@@ -901,7 +901,7 @@ class Codepress_Admin_Columns
|
|
901 |
*/
|
902 |
public function column_styles()
|
903 |
{
|
904 |
-
wp_enqueue_style( 'cpac-columns', CPAC_URL.'/assets/css/column.css', array(), CPAC_VERSION, 'all' );
|
905 |
}
|
906 |
|
907 |
/**
|
@@ -909,22 +909,22 @@ class Codepress_Admin_Columns
|
|
909 |
*
|
910 |
* @since 1.0
|
911 |
*/
|
912 |
-
public function register_settings()
|
913 |
{
|
914 |
// If we have no options in the database, let's add them now.
|
915 |
if ( false === get_option('cpac_options') ) {
|
916 |
add_option( 'cpac_options', $this->get_default_plugin_options() );
|
917 |
}
|
918 |
-
|
919 |
register_setting( 'cpac-settings-group', 'cpac_options', array($this, 'options_callback') );
|
920 |
-
}
|
921 |
|
922 |
/**
|
923 |
* Returns the default plugin options.
|
924 |
*
|
925 |
* @since 1.0
|
926 |
*/
|
927 |
-
public function get_default_plugin_options()
|
928 |
{
|
929 |
return apply_filters( 'cpac_default_plugin_options', array() );
|
930 |
}
|
@@ -935,7 +935,7 @@ class Codepress_Admin_Columns
|
|
935 |
* @since 1.0
|
936 |
*/
|
937 |
public function options_callback($options)
|
938 |
-
{
|
939 |
return $options;
|
940 |
}
|
941 |
|
@@ -944,23 +944,23 @@ class Codepress_Admin_Columns
|
|
944 |
*
|
945 |
* @since 1.0
|
946 |
*/
|
947 |
-
public function handle_requests()
|
948 |
{
|
949 |
// only handle updates from the admin columns page
|
950 |
if ( isset($_REQUEST['page']) && CPAC_SLUG == $_REQUEST['page'] ) {
|
951 |
-
|
952 |
// settings updated
|
953 |
if ( ! empty($_REQUEST['settings-updated']) ) {
|
954 |
$this->store_wp_default_columns();
|
955 |
}
|
956 |
-
|
957 |
-
// restore defaults
|
958 |
if ( ! empty($_REQUEST['cpac-restore-defaults']) ) {
|
959 |
$this->restore_defaults();
|
960 |
}
|
961 |
}
|
962 |
}
|
963 |
-
|
964 |
/**
|
965 |
* Stores WP default columns
|
966 |
*
|
@@ -968,28 +968,28 @@ class Codepress_Admin_Columns
|
|
968 |
*
|
969 |
* @since 1.2
|
970 |
*/
|
971 |
-
private function store_wp_default_columns()
|
972 |
-
{
|
973 |
// stores the default columns that are set by WP or theme.
|
974 |
$wp_default_columns = array();
|
975 |
-
|
976 |
// Posts
|
977 |
foreach ( $this->post_types as $post_type ) {
|
978 |
$wp_default_columns[$post_type] = $this->get_wp_default_posts_columns($post_type);
|
979 |
}
|
980 |
-
|
981 |
// Users
|
982 |
$wp_default_columns['wp-users'] = $this->get_wp_default_users_columns();
|
983 |
-
|
984 |
// Media
|
985 |
$wp_default_columns['wp-media'] = $this->get_wp_default_media_columns();
|
986 |
-
|
987 |
// Links
|
988 |
$wp_default_columns['wp-links'] = $this->get_wp_default_links_columns();
|
989 |
-
|
990 |
// Comments
|
991 |
-
$wp_default_columns['wp-comments'] = $this->get_wp_default_comments_columns();
|
992 |
-
|
993 |
update_option( 'cpac_options_default', $wp_default_columns );
|
994 |
}
|
995 |
|
@@ -998,12 +998,12 @@ class Codepress_Admin_Columns
|
|
998 |
*
|
999 |
* @since 1.0
|
1000 |
*/
|
1001 |
-
private function restore_defaults()
|
1002 |
-
{
|
1003 |
delete_option( 'cpac_options' );
|
1004 |
-
delete_option( 'cpac_options_default' );
|
1005 |
-
}
|
1006 |
-
|
1007 |
/**
|
1008 |
* Get author field by nametype
|
1009 |
*
|
@@ -1014,141 +1014,128 @@ class Codepress_Admin_Columns
|
|
1014 |
public function get_author_field_by_nametype( $nametype, $user_id)
|
1015 |
{
|
1016 |
$userdata = get_userdata( $user_id );
|
1017 |
-
|
1018 |
switch ( $nametype ) :
|
1019 |
-
|
1020 |
case "display_name" :
|
1021 |
$name = $userdata->display_name;
|
1022 |
break;
|
1023 |
-
|
1024 |
case "first_name" :
|
1025 |
$name = $userdata->first_name;
|
1026 |
-
break;
|
1027 |
-
|
1028 |
case "last_name" :
|
1029 |
$name = $userdata->last_name;
|
1030 |
break;
|
1031 |
-
|
1032 |
case "first_last_name" :
|
1033 |
$first = !empty($userdata->first_name) ? $userdata->first_name : '';
|
1034 |
$last = !empty($userdata->last_name) ? " {$userdata->last_name}" : '';
|
1035 |
$name = $first.$last;
|
1036 |
break;
|
1037 |
-
|
1038 |
case "nickname" :
|
1039 |
$name = $userdata->nickname;
|
1040 |
-
break;
|
1041 |
-
|
1042 |
case "username" :
|
1043 |
$name = $userdata->user_login;
|
1044 |
break;
|
1045 |
-
|
1046 |
case "email" :
|
1047 |
$name = $userdata->user_email;
|
1048 |
break;
|
1049 |
-
|
1050 |
case "userid" :
|
1051 |
$name = $userdata->ID;
|
1052 |
break;
|
1053 |
-
|
1054 |
default :
|
1055 |
$name = $userdata->display_name;
|
1056 |
-
|
1057 |
endswitch;
|
1058 |
-
|
1059 |
return $name;
|
1060 |
}
|
1061 |
-
|
1062 |
/**
|
1063 |
* Get WP default supported admin columns per post type.
|
1064 |
*
|
1065 |
* @since 1.0
|
1066 |
*/
|
1067 |
-
private function get_wp_default_posts_columns($post_type = 'post')
|
1068 |
{
|
1069 |
-
//
|
1070 |
-
|
1071 |
-
|
1072 |
-
// some plugins depend on settings the $_GET['post_type'] variable such as ALL in One SEO
|
1073 |
-
$_GET['post_type'] = $post_type;
|
1074 |
-
|
1075 |
-
// to prevent possible warning from initializing load-edit.php
|
1076 |
-
// we will set a dummy screen object
|
1077 |
-
if ( empty($current_screen->post_type) ) {
|
1078 |
-
$current_screen = (object) array( 'post_type' => $post_type, 'id' => '', 'base' => '' );
|
1079 |
-
}
|
1080 |
-
|
1081 |
-
// for 3rd party plugin support we will call load-edit.php so all the
|
1082 |
-
// additional columns that are set by them will be avaible for us
|
1083 |
-
do_action('load-edit.php');
|
1084 |
-
|
1085 |
// some plugins directly hook into get_column_headers, such as woocommerce
|
1086 |
$columns = get_column_headers( 'edit-'.$post_type );
|
1087 |
-
|
1088 |
-
// get default columns
|
1089 |
-
if ( empty($columns) ) {
|
1090 |
-
|
1091 |
// deprecated as of wp3.3
|
1092 |
if ( file_exists(ABSPATH . 'wp-admin/includes/template.php') )
|
1093 |
require_once(ABSPATH . 'wp-admin/includes/template.php');
|
1094 |
-
|
1095 |
// introduced since wp3.3
|
1096 |
if ( file_exists(ABSPATH . 'wp-admin/includes/screen.php') )
|
1097 |
require_once(ABSPATH . 'wp-admin/includes/screen.php');
|
1098 |
-
|
1099 |
// used for getting columns
|
1100 |
if ( file_exists(ABSPATH . 'wp-admin/includes/class-wp-list-table.php') )
|
1101 |
require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
|
1102 |
if ( file_exists(ABSPATH . 'wp-admin/includes/class-wp-posts-list-table.php') )
|
1103 |
require_once(ABSPATH . 'wp-admin/includes/class-wp-posts-list-table.php');
|
1104 |
-
|
1105 |
// As of WP Release 3.5 we can use the following.
|
1106 |
if ( version_compare( get_bloginfo('version'), '3.4.10', '>=' ) ) {
|
1107 |
-
|
1108 |
$table = new WP_Posts_List_Table( array( 'screen' => $post_type ) );
|
1109 |
$columns = $table->get_columns();
|
1110 |
}
|
1111 |
-
|
1112 |
// WP versions older then 3.5
|
1113 |
// @todo: make this deprecated
|
1114 |
-
else {
|
1115 |
-
|
1116 |
// we need to change the current screen... first lets save original
|
1117 |
$org_current_screen = $current_screen;
|
1118 |
-
|
1119 |
-
// prevent php warning
|
1120 |
if ( !isset($current_screen) ) $current_screen = new stdClass;
|
1121 |
-
|
1122 |
// overwrite current_screen global with our post type of choose...
|
1123 |
$current_screen->post_type = $post_type;
|
1124 |
-
|
1125 |
-
// ...so we can get its columns
|
1126 |
-
$columns = WP_Posts_List_Table::get_columns();
|
1127 |
-
|
1128 |
// reset current screen
|
1129 |
$current_screen = $org_current_screen;
|
1130 |
}
|
1131 |
}
|
1132 |
-
|
1133 |
if ( empty ( $columns ) )
|
1134 |
return false;
|
1135 |
-
|
1136 |
// change to uniform format
|
1137 |
-
$columns = $this->get_uniform_format($columns);
|
1138 |
|
1139 |
// add sorting to some of the default links columns
|
1140 |
$columns = $this->set_sorting_to_default_posts_columns($columns);
|
1141 |
-
|
1142 |
return $columns;
|
1143 |
}
|
1144 |
-
|
1145 |
/**
|
1146 |
* Add Sorting to WP default Posts columns
|
1147 |
*
|
1148 |
* @since 1.4.5
|
1149 |
*/
|
1150 |
private function set_sorting_to_default_posts_columns($columns)
|
1151 |
-
{
|
1152 |
// categories
|
1153 |
if ( !empty($columns['categories']) ) {
|
1154 |
$columns['categories']['options']['sortorder'] = 'on';
|
@@ -1159,7 +1146,7 @@ class Codepress_Admin_Columns
|
|
1159 |
}
|
1160 |
return $columns;
|
1161 |
}
|
1162 |
-
|
1163 |
/**
|
1164 |
* Get WP default users columns per post type.
|
1165 |
*
|
@@ -1167,74 +1154,80 @@ class Codepress_Admin_Columns
|
|
1167 |
*/
|
1168 |
private function get_wp_default_users_columns()
|
1169 |
{
|
|
|
|
|
|
|
1170 |
if ( file_exists(ABSPATH . 'wp-admin/includes/class-wp-list-table.php') )
|
1171 |
require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
|
1172 |
if ( file_exists(ABSPATH . 'wp-admin/includes/class-wp-users-list-table.php') )
|
1173 |
require_once(ABSPATH . 'wp-admin/includes/class-wp-users-list-table.php');
|
1174 |
-
|
1175 |
// turn off site users
|
1176 |
$this->is_site_users = false;
|
1177 |
-
|
1178 |
// get users columns
|
1179 |
$columns = WP_Users_List_Table::get_columns();
|
1180 |
-
|
1181 |
// change to uniform format
|
1182 |
$columns = $this->get_uniform_format($columns);
|
1183 |
|
1184 |
return apply_filters('cpac-default-users-columns', $columns);
|
1185 |
}
|
1186 |
-
|
1187 |
/**
|
1188 |
* Get WP default media columns.
|
1189 |
*
|
1190 |
* @since 1.2.1
|
1191 |
*/
|
1192 |
private function get_wp_default_media_columns()
|
1193 |
-
{
|
|
|
|
|
|
|
1194 |
// @todo could use _get_list_table('WP_Media_List_Table') ?
|
1195 |
if ( file_exists(ABSPATH . 'wp-admin/includes/class-wp-list-table.php') )
|
1196 |
require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
|
1197 |
if ( file_exists(ABSPATH . 'wp-admin/includes/class-wp-media-list-table.php') )
|
1198 |
require_once(ABSPATH . 'wp-admin/includes/class-wp-media-list-table.php');
|
1199 |
-
|
1200 |
// As of WP Release 3.5 we can use the following.
|
1201 |
if ( version_compare( get_bloginfo('version'), '3.4.10', '>=' ) ) {
|
1202 |
-
|
1203 |
$table = new WP_Media_List_Table(array( 'screen' => 'upload' ));
|
1204 |
$columns = $table->get_columns();
|
1205 |
}
|
1206 |
-
|
1207 |
// WP versions older then 3.5
|
1208 |
// @todo: make this deprecated
|
1209 |
-
else {
|
1210 |
-
|
1211 |
global $current_screen;
|
1212 |
|
1213 |
// save original
|
1214 |
$org_current_screen = $current_screen;
|
1215 |
-
|
1216 |
-
// prevent php warning
|
1217 |
if ( !isset($current_screen) ) $current_screen = new stdClass;
|
1218 |
-
|
1219 |
// overwrite current_screen global with our media id...
|
1220 |
$current_screen->id = 'upload';
|
1221 |
-
|
1222 |
// init media class
|
1223 |
$wp_media = new WP_Media_List_Table;
|
1224 |
-
|
1225 |
-
// get media columns
|
1226 |
$columns = $wp_media->get_columns();
|
1227 |
-
|
1228 |
// reset current screen
|
1229 |
$current_screen = $org_current_screen;
|
1230 |
}
|
1231 |
-
|
1232 |
// change to uniform format
|
1233 |
$columns = $this->get_uniform_format($columns);
|
1234 |
-
|
1235 |
return apply_filters('cpac-default-media-columns', $columns);
|
1236 |
}
|
1237 |
-
|
1238 |
/**
|
1239 |
* Get WP default links columns.
|
1240 |
*
|
@@ -1242,24 +1235,27 @@ class Codepress_Admin_Columns
|
|
1242 |
*/
|
1243 |
private function get_wp_default_links_columns()
|
1244 |
{
|
|
|
|
|
|
|
1245 |
// dependencies
|
1246 |
if ( file_exists(ABSPATH . 'wp-admin/includes/class-wp-list-table.php') )
|
1247 |
require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
|
1248 |
if ( file_exists(ABSPATH . 'wp-admin/includes/class-wp-links-list-table.php') )
|
1249 |
require_once(ABSPATH . 'wp-admin/includes/class-wp-links-list-table.php');
|
1250 |
-
|
1251 |
// get links columns
|
1252 |
$columns = WP_Links_List_Table::get_columns();
|
1253 |
|
1254 |
// change to uniform format
|
1255 |
$columns = $this->get_uniform_format($columns);
|
1256 |
-
|
1257 |
// add sorting to some of the default links columns
|
1258 |
$columns = $this->set_sorting_to_default_links_columns($columns);
|
1259 |
-
|
1260 |
return apply_filters('cpac-default-links-columns', $columns);
|
1261 |
}
|
1262 |
-
|
1263 |
/**
|
1264 |
* Add Sorting to WP default links columns
|
1265 |
*
|
@@ -1273,61 +1269,64 @@ class Codepress_Admin_Columns
|
|
1273 |
}
|
1274 |
return $columns;
|
1275 |
}
|
1276 |
-
|
1277 |
/**
|
1278 |
* Get WP default links columns.
|
1279 |
*
|
1280 |
* @since 1.3.1
|
1281 |
*/
|
1282 |
private function get_wp_default_comments_columns()
|
1283 |
-
{
|
|
|
|
|
|
|
1284 |
// dependencies
|
1285 |
if ( file_exists(ABSPATH . 'wp-admin/includes/class-wp-list-table.php') )
|
1286 |
require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
|
1287 |
if ( file_exists(ABSPATH . 'wp-admin/includes/class-wp-comments-list-table.php') )
|
1288 |
require_once(ABSPATH . 'wp-admin/includes/class-wp-comments-list-table.php');
|
1289 |
-
|
1290 |
// As of WP Release 3.5 we can use the following.
|
1291 |
if ( version_compare( get_bloginfo('version'), '3.4.10', '>=' ) ) {
|
1292 |
-
|
1293 |
$table = new WP_Comments_List_Table( array( 'screen' => 'edit-comments' ) );
|
1294 |
$columns = $table->get_columns();
|
1295 |
}
|
1296 |
-
|
1297 |
// WP versions older then 3.5
|
1298 |
// @todo: make this deprecated
|
1299 |
else {
|
1300 |
-
|
1301 |
global $current_screen;
|
1302 |
|
1303 |
-
// save original
|
1304 |
$org_current_screen = $current_screen;
|
1305 |
-
|
1306 |
-
// prevent php warning
|
1307 |
if ( !isset($current_screen) ) $current_screen = new stdClass;
|
1308 |
-
|
1309 |
// overwrite current_screen global with our media id...
|
1310 |
$current_screen->id = 'edit-comments';
|
1311 |
-
|
1312 |
// init table object
|
1313 |
-
$wp_comment = new WP_Comments_List_Table;
|
1314 |
-
|
1315 |
// get comments
|
1316 |
$columns = $wp_comment->get_columns();
|
1317 |
-
|
1318 |
// reset current screen
|
1319 |
$current_screen = $org_current_screen;
|
1320 |
}
|
1321 |
-
|
1322 |
// change to uniform format
|
1323 |
$columns = $this->get_uniform_format($columns);
|
1324 |
-
|
1325 |
// add sorting to some of the default links columns
|
1326 |
$columns = $this->set_sorting_to_default_comments_columns($columns);
|
1327 |
-
|
1328 |
return apply_filters('cpac-default-comments-columns', $columns);
|
1329 |
}
|
1330 |
-
|
1331 |
/**
|
1332 |
* Add Sorting to WP default comments columns
|
1333 |
*
|
@@ -1347,30 +1346,30 @@ class Codepress_Admin_Columns
|
|
1347 |
*
|
1348 |
* @since 1.0
|
1349 |
*/
|
1350 |
-
private function get_uniform_format($columns)
|
1351 |
{
|
1352 |
-
// we remove the checkbox column as an option...
|
1353 |
if ( isset($columns['cb']) )
|
1354 |
unset($columns['cb']);
|
1355 |
-
|
1356 |
// change to uniform format
|
1357 |
$uniform_columns = array();
|
1358 |
foreach ( (array) $columns as $id => $label ) {
|
1359 |
$hide_options = false;
|
1360 |
$type_label = $label;
|
1361 |
-
|
1362 |
-
// comment exception
|
1363 |
-
if ( 'comments' == $id ) {
|
1364 |
$label = '';
|
1365 |
$type_label = __('Comments', CPAC_TEXTDOMAIN);
|
1366 |
$hide_options = true;
|
1367 |
}
|
1368 |
-
|
1369 |
// user icon exception
|
1370 |
if ( $id == 'icon' ) {
|
1371 |
$type_label = __('Icon', CPAC_TEXTDOMAIN);
|
1372 |
}
|
1373 |
-
|
1374 |
$uniform_columns[$id] = array(
|
1375 |
'label' => $label,
|
1376 |
'state' => 'on',
|
@@ -1383,13 +1382,13 @@ class Codepress_Admin_Columns
|
|
1383 |
}
|
1384 |
return $uniform_columns;
|
1385 |
}
|
1386 |
-
|
1387 |
/**
|
1388 |
* Custom posts columns
|
1389 |
*
|
1390 |
* @since 1.0
|
1391 |
*/
|
1392 |
-
private function get_custom_posts_columns($post_type)
|
1393 |
{
|
1394 |
$custom_columns = array(
|
1395 |
'column-featured_image' => array(
|
@@ -1445,48 +1444,48 @@ class Codepress_Admin_Columns
|
|
1445 |
'display_as' => ''
|
1446 |
),
|
1447 |
'column-before-moretag' => array(
|
1448 |
-
'label' => __('Before More Tag', CPAC_TEXTDOMAIN)
|
1449 |
)
|
1450 |
);
|
1451 |
-
|
1452 |
// Word count support
|
1453 |
if ( post_type_supports($post_type, 'editor') ) {
|
1454 |
$custom_columns['column-word-count'] = array(
|
1455 |
'label' => __('Word count', CPAC_TEXTDOMAIN)
|
1456 |
);
|
1457 |
}
|
1458 |
-
|
1459 |
// Sticky support
|
1460 |
-
if ( $post_type == 'post' ) {
|
1461 |
$custom_columns['column-sticky'] = array(
|
1462 |
'label' => __('Sticky', CPAC_TEXTDOMAIN)
|
1463 |
);
|
1464 |
}
|
1465 |
-
|
1466 |
// Order support
|
1467 |
if ( post_type_supports($post_type, 'page-attributes') ) {
|
1468 |
$custom_columns['column-order'] = array(
|
1469 |
-
'label' => __('Page Order', CPAC_TEXTDOMAIN),
|
1470 |
'options' => array(
|
1471 |
'type_label' => __('Order', CPAC_TEXTDOMAIN)
|
1472 |
-
)
|
1473 |
);
|
1474 |
}
|
1475 |
-
|
1476 |
// Page Template
|
1477 |
-
if ( $post_type == 'page' ) {
|
1478 |
$custom_columns['column-page-template'] = array(
|
1479 |
'label' => __('Page Template', CPAC_TEXTDOMAIN)
|
1480 |
-
);
|
1481 |
}
|
1482 |
-
|
1483 |
// Post Formats
|
1484 |
if ( post_type_supports($post_type, 'post-formats') ) {
|
1485 |
$custom_columns['column-post_formats'] = array(
|
1486 |
'label' => __('Post Format', CPAC_TEXTDOMAIN)
|
1487 |
);
|
1488 |
}
|
1489 |
-
|
1490 |
// Taxonomy support
|
1491 |
$taxonomies = get_object_taxonomies($post_type, 'objects');
|
1492 |
if ( $taxonomies ) {
|
@@ -1498,11 +1497,11 @@ class Codepress_Admin_Columns
|
|
1498 |
'options' => array(
|
1499 |
'type_label' => __('Taxonomy', CPAC_TEXTDOMAIN)
|
1500 |
)
|
1501 |
-
);
|
1502 |
}
|
1503 |
}
|
1504 |
}
|
1505 |
-
|
1506 |
// Custom Field support
|
1507 |
if ( $this->get_meta_by_type($post_type) ) {
|
1508 |
$custom_columns['column-meta-1'] = array(
|
@@ -1514,22 +1513,22 @@ class Codepress_Admin_Columns
|
|
1514 |
'options' => array(
|
1515 |
'type_label' => __('Field', CPAC_TEXTDOMAIN),
|
1516 |
'class' => 'cpac-box-metafield'
|
1517 |
-
)
|
1518 |
);
|
1519 |
-
}
|
1520 |
-
|
1521 |
// merge with defaults
|
1522 |
$custom_columns = $this->parse_defaults($custom_columns);
|
1523 |
-
|
1524 |
return apply_filters('cpac-custom-posts-columns', $custom_columns);
|
1525 |
}
|
1526 |
-
|
1527 |
/**
|
1528 |
* Custom users columns
|
1529 |
*
|
1530 |
* @since 1.1
|
1531 |
*/
|
1532 |
-
private function get_custom_users_columns()
|
1533 |
{
|
1534 |
$custom_columns = array(
|
1535 |
'column-user_id' => array(
|
@@ -1560,7 +1559,7 @@ class Codepress_Admin_Columns
|
|
1560 |
)
|
1561 |
),
|
1562 |
);
|
1563 |
-
|
1564 |
// User total number of posts
|
1565 |
foreach ( self::get_post_types() as $post_type ) {
|
1566 |
$label = $this->get_plural_name($post_type);
|
@@ -1571,7 +1570,7 @@ class Codepress_Admin_Columns
|
|
1571 |
)
|
1572 |
);
|
1573 |
}
|
1574 |
-
|
1575 |
// Custom Field support
|
1576 |
$custom_columns['column-meta-1'] = array(
|
1577 |
'label' => __('Custom Field', CPAC_TEXTDOMAIN),
|
@@ -1583,20 +1582,20 @@ class Codepress_Admin_Columns
|
|
1583 |
'type_label' => __('Field', CPAC_TEXTDOMAIN),
|
1584 |
'class' => 'cpac-box-metafield'
|
1585 |
)
|
1586 |
-
);
|
1587 |
-
|
1588 |
// merge with defaults
|
1589 |
$custom_columns = $this->parse_defaults($custom_columns);
|
1590 |
-
|
1591 |
return apply_filters('cpac-custom-users-columns', $custom_columns);
|
1592 |
}
|
1593 |
-
|
1594 |
/**
|
1595 |
* Custom media columns
|
1596 |
*
|
1597 |
* @since 1.3
|
1598 |
*/
|
1599 |
-
private function get_custom_media_columns()
|
1600 |
{
|
1601 |
$custom_columns = array(
|
1602 |
'column-mediaid' => array(
|
@@ -1640,9 +1639,9 @@ class Codepress_Admin_Columns
|
|
1640 |
),
|
1641 |
'column-filesize' => array(
|
1642 |
'label' => __('File size', CPAC_TEXTDOMAIN)
|
1643 |
-
)
|
1644 |
);
|
1645 |
-
|
1646 |
// Get extended image metadata, exif or iptc as available.
|
1647 |
// uses exif_read_data()
|
1648 |
if ( function_exists('exif_read_data') ) {
|
@@ -1709,7 +1708,7 @@ class Codepress_Admin_Columns
|
|
1709 |
)
|
1710 |
));
|
1711 |
}
|
1712 |
-
|
1713 |
// Custom Field support
|
1714 |
if ( $this->get_meta_by_type('wp-media') ) {
|
1715 |
$custom_columns['column-meta-1'] = array(
|
@@ -1724,19 +1723,19 @@ class Codepress_Admin_Columns
|
|
1724 |
)
|
1725 |
);
|
1726 |
}
|
1727 |
-
|
1728 |
// merge with defaults
|
1729 |
$custom_columns = $this->parse_defaults($custom_columns);
|
1730 |
-
|
1731 |
return apply_filters('cpac-custom-media-columns', $custom_columns);
|
1732 |
}
|
1733 |
-
|
1734 |
/**
|
1735 |
* Custom links columns
|
1736 |
*
|
1737 |
* @since 1.3.1
|
1738 |
*/
|
1739 |
-
private function get_custom_links_columns()
|
1740 |
{
|
1741 |
$custom_columns = array(
|
1742 |
'column-link_id' => array (
|
@@ -1768,21 +1767,21 @@ class Codepress_Admin_Columns
|
|
1768 |
'options' => array(
|
1769 |
'sortorder' => false
|
1770 |
)
|
1771 |
-
)
|
1772 |
-
);
|
1773 |
-
|
1774 |
// merge with defaults
|
1775 |
$custom_columns = $this->parse_defaults($custom_columns);
|
1776 |
-
|
1777 |
return apply_filters('cpac-custom-links-columns', $custom_columns);
|
1778 |
}
|
1779 |
-
|
1780 |
/**
|
1781 |
* Custom comments columns
|
1782 |
*
|
1783 |
* @since 1.3.1
|
1784 |
*/
|
1785 |
-
private function get_custom_comments_columns()
|
1786 |
{
|
1787 |
$custom_columns = array(
|
1788 |
'column-comment_id' => array(
|
@@ -1804,8 +1803,8 @@ class Codepress_Admin_Columns
|
|
1804 |
'label' => __('Author email', CPAC_TEXTDOMAIN)
|
1805 |
),
|
1806 |
'column-reply_to' => array(
|
1807 |
-
'label' => __('In Reply To', CPAC_TEXTDOMAIN),
|
1808 |
-
'options' => array(
|
1809 |
'sortorder' => false
|
1810 |
)
|
1811 |
),
|
@@ -1836,8 +1835,8 @@ class Codepress_Admin_Columns
|
|
1836 |
'sortorder' => false
|
1837 |
)
|
1838 |
)
|
1839 |
-
);
|
1840 |
-
|
1841 |
// Custom Field support
|
1842 |
if ( $this->get_meta_by_type('wp-comments') ) {
|
1843 |
$custom_columns['column-meta-1'] = array(
|
@@ -1852,51 +1851,51 @@ class Codepress_Admin_Columns
|
|
1852 |
'sortorder' => false,
|
1853 |
)
|
1854 |
);
|
1855 |
-
}
|
1856 |
-
|
1857 |
// merge with defaults
|
1858 |
$custom_columns = $this->parse_defaults($custom_columns);
|
1859 |
-
|
1860 |
return apply_filters('cpac-custom-comments-columns', $custom_columns);
|
1861 |
}
|
1862 |
-
|
1863 |
/**
|
1864 |
* Parse defaults
|
1865 |
*
|
1866 |
* @since 1.1
|
1867 |
*/
|
1868 |
-
private function parse_defaults($columns)
|
1869 |
{
|
1870 |
// default arguments
|
1871 |
-
$defaults = array(
|
1872 |
-
|
1873 |
// stored values
|
1874 |
'label' => '', // custom label
|
1875 |
'state' => '', // display state
|
1876 |
-
'width' => '', // column width
|
1877 |
-
|
1878 |
// static values
|
1879 |
-
'options' => array(
|
1880 |
'type_label' => __('Custom', CPAC_TEXTDOMAIN),
|
1881 |
'hide_options' => false,
|
1882 |
'class' => 'cpac-box-custom',
|
1883 |
'sortorder' => 'on',
|
1884 |
)
|
1885 |
);
|
1886 |
-
|
1887 |
// parse args
|
1888 |
foreach ( $columns as $k => $column ) {
|
1889 |
$c[$k] = wp_parse_args( $column, $defaults);
|
1890 |
-
|
1891 |
// parse options args
|
1892 |
if ( isset($column['options']) )
|
1893 |
$c[$k]['options'] = wp_parse_args( $column['options'], $defaults['options']);
|
1894 |
-
|
1895 |
// set type label
|
1896 |
if ( empty($column['options']['type_label']) && !empty($column['label']) )
|
1897 |
$c[$k]['options']['type_label'] = $column['label'];
|
1898 |
}
|
1899 |
-
|
1900 |
return $c;
|
1901 |
}
|
1902 |
|
@@ -1906,14 +1905,14 @@ class Codepress_Admin_Columns
|
|
1906 |
* @since 1.0
|
1907 |
*/
|
1908 |
public static function get_stored_columns($type)
|
1909 |
-
{
|
1910 |
// get plugin options
|
1911 |
$options = get_option('cpac_options');
|
1912 |
|
1913 |
// get saved columns
|
1914 |
if ( !empty($options['columns'][$type]) )
|
1915 |
return $options['columns'][$type];
|
1916 |
-
|
1917 |
return false;
|
1918 |
}
|
1919 |
|
@@ -1922,41 +1921,41 @@ class Codepress_Admin_Columns
|
|
1922 |
*
|
1923 |
* @since 1.0
|
1924 |
*/
|
1925 |
-
private function get_menu()
|
1926 |
{
|
1927 |
// set
|
1928 |
$menu = '';
|
1929 |
$count = 1;
|
1930 |
-
|
1931 |
// referer
|
1932 |
$referer = ! empty($_REQUEST['cpac_type']) ? $_REQUEST['cpac_type'] : '';
|
1933 |
-
|
1934 |
// loop
|
1935 |
foreach ( $this->get_types() as $type ) {
|
1936 |
$label = $this->get_singular_name($type);
|
1937 |
$clean_label = $this->sanitize_string($type);
|
1938 |
-
|
1939 |
// divider
|
1940 |
$divider = $count++ == 1 ? '' : ' | ';
|
1941 |
-
|
1942 |
-
// current
|
1943 |
$current = '';
|
1944 |
if ( $this->is_menu_type_current($type) )
|
1945 |
$current = ' class="current"';
|
1946 |
-
|
1947 |
// menu list
|
1948 |
$menu .= "
|
1949 |
<li>{$divider}<a{$current} href='#cpac-box-{$clean_label}'>{$label}</a></li>
|
1950 |
";
|
1951 |
}
|
1952 |
-
|
1953 |
// settings url
|
1954 |
$class_current_settings = $this->is_menu_type_current('plugin_settings') ? ' current': '';
|
1955 |
-
|
1956 |
// options button
|
1957 |
$options_btn = "<a href='#cpac-box-plugin_settings' class='cpac-settings-link{$class_current_settings}'>".__('Addons', CPAC_TEXTDOMAIN)."</a>";
|
1958 |
//$options_btn = '';
|
1959 |
-
|
1960 |
return "
|
1961 |
<div class='cpac-menu'>
|
1962 |
<ul class='subsubsub'>
|
@@ -1972,29 +1971,29 @@ class Codepress_Admin_Columns
|
|
1972 |
*
|
1973 |
* @since 1.0
|
1974 |
*/
|
1975 |
-
private function is_menu_type_current( $type )
|
1976 |
-
{
|
1977 |
// referer
|
1978 |
$referer = ! empty($_REQUEST['cpac_type']) ? $_REQUEST['cpac_type'] : '';
|
1979 |
-
|
1980 |
// get label
|
1981 |
$clean_label = $this->sanitize_string($type);
|
1982 |
-
|
1983 |
// get first element from post-types
|
1984 |
$first = array_shift( array_values($this->post_types) );
|
1985 |
-
|
1986 |
// display the page that was being viewed before saving
|
1987 |
if ( $referer ) {
|
1988 |
if ( $referer == 'cpac-box-'.$clean_label ) {
|
1989 |
return true;
|
1990 |
}
|
1991 |
-
|
1992 |
// settings page has not yet been saved
|
1993 |
} elseif ( $first == $type ) {
|
1994 |
return true;
|
1995 |
}
|
1996 |
-
|
1997 |
-
return false;
|
1998 |
}
|
1999 |
|
2000 |
/**
|
@@ -2002,74 +2001,74 @@ class Codepress_Admin_Columns
|
|
2002 |
*
|
2003 |
* @since 1.0
|
2004 |
*/
|
2005 |
-
private function get_singular_name( $type )
|
2006 |
{
|
2007 |
// Links
|
2008 |
if ( $type == 'wp-links' )
|
2009 |
$label = __('Links');
|
2010 |
-
|
2011 |
// Comments
|
2012 |
elseif ( $type == 'wp-comments' )
|
2013 |
$label = __('Comments');
|
2014 |
-
|
2015 |
// Users
|
2016 |
elseif ( $type == 'wp-users' )
|
2017 |
$label = __('Users');
|
2018 |
-
|
2019 |
// Media
|
2020 |
elseif ( $type == 'wp-media' )
|
2021 |
$label = __('Media Library');
|
2022 |
-
|
2023 |
// Posts
|
2024 |
else {
|
2025 |
$posttype_obj = get_post_type_object($type);
|
2026 |
$label = $posttype_obj->labels->singular_name;
|
2027 |
}
|
2028 |
-
|
2029 |
return $label;
|
2030 |
}
|
2031 |
-
|
2032 |
/**
|
2033 |
* Get plural name of post type
|
2034 |
*
|
2035 |
* @since 1.3.1
|
2036 |
*/
|
2037 |
-
private function get_plural_name( $type )
|
2038 |
{
|
2039 |
$posttype_obj = get_post_type_object($type);
|
2040 |
if ( $posttype_obj )
|
2041 |
return $posttype_obj->labels->name;
|
2042 |
-
|
2043 |
return false;
|
2044 |
}
|
2045 |
-
|
2046 |
/**
|
2047 |
* Get screen link to overview screen
|
2048 |
*
|
2049 |
* @since 1.3.1
|
2050 |
*/
|
2051 |
-
private function get_type_screen_link( $type )
|
2052 |
-
{
|
2053 |
// Links
|
2054 |
if ( $type == 'wp-comments' )
|
2055 |
$link = get_admin_url() . 'edit-comments.php';
|
2056 |
-
|
2057 |
// Links
|
2058 |
if ( $type == 'wp-links' )
|
2059 |
$link = get_admin_url() . 'link-manager.php';
|
2060 |
-
|
2061 |
// Users
|
2062 |
if ( $type == 'wp-users' )
|
2063 |
$link = get_admin_url() . 'users.php';
|
2064 |
-
|
2065 |
// Media
|
2066 |
elseif ( $type == 'wp-media' )
|
2067 |
$link = get_admin_url() . 'upload.php';
|
2068 |
-
|
2069 |
// Posts
|
2070 |
-
else
|
2071 |
-
$link = get_admin_url() . "edit.php?post_type={$type}";
|
2072 |
-
|
2073 |
return $link;
|
2074 |
}
|
2075 |
|
@@ -2080,47 +2079,47 @@ class Codepress_Admin_Columns
|
|
2080 |
*
|
2081 |
* @since 1.0
|
2082 |
*/
|
2083 |
-
protected function sanitize_string($string)
|
2084 |
-
{
|
2085 |
$string = esc_url($string);
|
2086 |
$string = str_replace('http://','', $string);
|
2087 |
$string = str_replace('https://','', $string);
|
2088 |
-
|
2089 |
return $string;
|
2090 |
}
|
2091 |
-
|
2092 |
/**
|
2093 |
* Checks if column-meta key exists
|
2094 |
*
|
2095 |
* @since 1.0
|
2096 |
*/
|
2097 |
-
public static function is_column_meta( $id = '' )
|
2098 |
{
|
2099 |
if ( strpos($id, 'column-meta-') !== false )
|
2100 |
return true;
|
2101 |
-
|
2102 |
return false;
|
2103 |
}
|
2104 |
-
|
2105 |
/**
|
2106 |
* Get the posttype from columnname
|
2107 |
*
|
2108 |
* @since 1.3.1
|
2109 |
*/
|
2110 |
-
public static function get_posttype_by_postcount_column( $id = '' )
|
2111 |
{
|
2112 |
-
if ( strpos($id, 'column-user_postcount-') !== false )
|
2113 |
return str_replace('column-user_postcount-', '', $id);
|
2114 |
-
|
2115 |
return false;
|
2116 |
}
|
2117 |
-
|
2118 |
/**
|
2119 |
* Get column value of post attachments
|
2120 |
*
|
2121 |
* @since 1.2.1
|
2122 |
*/
|
2123 |
-
public static function get_attachment_ids( $post_id )
|
2124 |
{
|
2125 |
return get_posts(array(
|
2126 |
'post_type' => 'attachment',
|
@@ -2130,42 +2129,42 @@ class Codepress_Admin_Columns
|
|
2130 |
'fields' => 'ids'
|
2131 |
));
|
2132 |
}
|
2133 |
-
|
2134 |
/**
|
2135 |
* Strip tags and trim
|
2136 |
*
|
2137 |
* @since 1.3
|
2138 |
*/
|
2139 |
-
public static function strip_trim($string)
|
2140 |
{
|
2141 |
return trim(strip_tags($string));
|
2142 |
}
|
2143 |
-
|
2144 |
/**
|
2145 |
* Admin body class
|
2146 |
*
|
2147 |
* @since 1.4
|
2148 |
*/
|
2149 |
-
function admin_class( $classes )
|
2150 |
-
{
|
2151 |
global $current_screen;
|
2152 |
-
|
2153 |
// we dont need the 'edit-' part
|
2154 |
$screen = str_replace('edit-', '', $current_screen->id);
|
2155 |
-
|
2156 |
// media library exception
|
2157 |
if ( $current_screen->base == 'upload' && $current_screen->id == 'upload' ) {
|
2158 |
$screen = 'media';
|
2159 |
}
|
2160 |
-
|
2161 |
// link exception
|
2162 |
if ( $current_screen->base == 'link-manager' && $current_screen->id == 'link-manager' ) {
|
2163 |
$screen = 'links';
|
2164 |
}
|
2165 |
|
2166 |
// loop the available types
|
2167 |
-
foreach ( $this->get_types() as $type => $label ) {
|
2168 |
-
|
2169 |
// match against screen or wp-screen
|
2170 |
if ( $type == $screen || $type == "wp-{$screen}" )
|
2171 |
$classes .= " cp-{$type}";
|
@@ -2174,24 +2173,24 @@ class Codepress_Admin_Columns
|
|
2174 |
return $classes;
|
2175 |
}
|
2176 |
|
2177 |
-
|
2178 |
/**
|
2179 |
* Admin CSS for Column width
|
2180 |
*
|
2181 |
* @since 1.4
|
2182 |
*/
|
2183 |
-
function admin_css()
|
2184 |
-
{
|
2185 |
$css = '';
|
2186 |
-
|
2187 |
// loop throug the available types...
|
2188 |
foreach ( $this->get_types() as $type ) {
|
2189 |
-
$cols = self::get_stored_columns($type);
|
2190 |
if ( $cols ) {
|
2191 |
-
|
2192 |
// loop through each available column...
|
2193 |
foreach ( $cols as $col_name => $col ) {
|
2194 |
-
|
2195 |
// and check for stored width and add it to the css
|
2196 |
if (!empty($col['width']) && is_numeric($col['width']) && $col['width'] > 0 ) {
|
2197 |
$css .= ".cp-{$type} .wrap table th.column-{$col_name} { width: {$col['width']}% !important; }";
|
@@ -2199,10 +2198,10 @@ class Codepress_Admin_Columns
|
|
2199 |
}
|
2200 |
}
|
2201 |
}
|
2202 |
-
|
2203 |
echo "<style type='text/css'>{$css}</style>";
|
2204 |
}
|
2205 |
-
|
2206 |
/**
|
2207 |
* Ajax activation
|
2208 |
*
|
@@ -2213,41 +2212,41 @@ class Codepress_Admin_Columns
|
|
2213 |
// keys
|
2214 |
$key = $_POST['key'];
|
2215 |
$type = $_POST['type'];
|
2216 |
-
|
2217 |
$licence = new cpac_licence( $type );
|
2218 |
-
|
2219 |
// update key
|
2220 |
if ( $key == 'remove' ) {
|
2221 |
$licence->remove_license_key();
|
2222 |
}
|
2223 |
-
|
2224 |
// set license key
|
2225 |
elseif ( $licence->check_remote_key( $key ) ) {
|
2226 |
-
|
2227 |
// set key
|
2228 |
$licence->set_license_key( $key );
|
2229 |
-
|
2230 |
// returned masked key
|
2231 |
echo json_encode( $licence->get_masked_license_key() );
|
2232 |
}
|
2233 |
|
2234 |
exit;
|
2235 |
}
|
2236 |
-
|
2237 |
/**
|
2238 |
* Add help tabs
|
2239 |
*
|
2240 |
* @since 1.3
|
2241 |
*/
|
2242 |
-
public function help_tabs($page)
|
2243 |
-
{
|
2244 |
$screen = get_current_screen();
|
2245 |
|
2246 |
if ( $screen->id != $this->admin_page || ! method_exists($screen,'add_help_tab') )
|
2247 |
return;
|
2248 |
-
|
2249 |
$admin_url = get_admin_url();
|
2250 |
-
|
2251 |
// add help content
|
2252 |
$tabs = array(
|
2253 |
array(
|
@@ -2256,8 +2255,8 @@ class Codepress_Admin_Columns
|
|
2256 |
<h5>Codepress Admin Columns</h5>
|
2257 |
<p>
|
2258 |
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.
|
2259 |
-
</p>
|
2260 |
-
|
2261 |
"
|
2262 |
),
|
2263 |
array(
|
@@ -2299,55 +2298,55 @@ class Codepress_Admin_Columns
|
|
2299 |
<li><strong>Post Titles</strong><br/>Value: can be one or more Post ID's (seperated by ',').</li>
|
2300 |
</ul>
|
2301 |
"
|
2302 |
-
)
|
2303 |
);
|
2304 |
-
|
2305 |
foreach ( $tabs as $k => $tab ) {
|
2306 |
-
$screen->add_help_tab(array(
|
2307 |
'id' => 'cpac-tab-'.$k, // unique id
|
2308 |
'title' => $tab['title'], // label
|
2309 |
'content' => $tab['content'], // body
|
2310 |
));
|
2311 |
}
|
2312 |
}
|
2313 |
-
|
2314 |
/**
|
2315 |
* Plugin Settings
|
2316 |
*
|
2317 |
* @since 1.3.1
|
2318 |
*/
|
2319 |
-
private function plugin_settings()
|
2320 |
{
|
2321 |
$class_current_settings = $this->is_menu_type_current('plugin_settings') ? ' current' : ' hidden'; '';
|
2322 |
-
|
2323 |
/** Sortable */
|
2324 |
$masked_key = '';
|
2325 |
$class_sortorder_activate = '';
|
2326 |
$class_sortorder_deactivate = ' hidden';
|
2327 |
-
|
2328 |
// is unlocked
|
2329 |
$licence = new cpac_licence('sortable');
|
2330 |
-
|
2331 |
if ( $licence->is_unlocked() ) {
|
2332 |
$masked_key = $licence->get_masked_license_key('sortable');
|
2333 |
$class_sortorder_activate = ' hidden';
|
2334 |
$class_sortorder_deactivate = '';
|
2335 |
}
|
2336 |
-
|
2337 |
// find out more
|
2338 |
$find_out_more = "<a href='{$this->codepress_url}/sortorder-addon/' class='button-primary alignright' target='_blank'>".__('find out more', CPAC_TEXTDOMAIN)." »</a>";
|
2339 |
-
|
2340 |
// info box
|
2341 |
$sortable_tooltip = "
|
2342 |
<p>".__('This will make all of the new columns support sorting', CPAC_TEXTDOMAIN).".</p>
|
2343 |
<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>
|
2344 |
<p>".__('Perfect for sorting your articles, media files, comments, links and users', CPAC_TEXTDOMAIN).".</p>
|
2345 |
-
<p class='description'>".__('(columns that are added by other plugins are not supported)', CPAC_TEXTDOMAIN).".</p>
|
2346 |
<img src='" . CPAC_URL.'/assets/images/addon_sortable_1.png' . "' alt='' />
|
2347 |
{$find_out_more}
|
2348 |
";
|
2349 |
-
|
2350 |
-
// addons
|
2351 |
$addons = "
|
2352 |
<tr>
|
2353 |
<td colspan='2'>
|
@@ -2394,7 +2393,7 @@ class Codepress_Admin_Columns
|
|
2394 |
</td>
|
2395 |
<td class='activation_more'>{$find_out_more}</td>
|
2396 |
</tr><!-- #cpac-activation-sortable -->
|
2397 |
-
</tbody>
|
2398 |
</table>
|
2399 |
<div class='addon-translation-string hidden'>
|
2400 |
<span class='tstring-fill-in'>" . __('Enter your activation code', CPAC_TEXTDOMAIN) . "</span>
|
@@ -2403,7 +2402,7 @@ class Codepress_Admin_Columns
|
|
2403 |
</td>
|
2404 |
</tr>
|
2405 |
";
|
2406 |
-
|
2407 |
// general options
|
2408 |
$general_options = "
|
2409 |
<!--
|
@@ -2413,43 +2412,43 @@ class Codepress_Admin_Columns
|
|
2413 |
<ul class='cpac-options'>
|
2414 |
<li>
|
2415 |
<div class='cpac-option-label'>Thumbnail size</div>
|
2416 |
-
<div class='cpac-option-inputs'>
|
2417 |
<input type='text' id='thumbnail_size_w' class='small-text' name='cpac_options[settings][thumb_width]' value='80'/>
|
2418 |
<label for='thumbnail_size_w'>Width</label>
|
2419 |
-
<br/>
|
2420 |
<input type='text' id='thumbnail_size_h' class='small-text' name='cpac_options[settings][thumb_height]' value='80'/>
|
2421 |
<label for='thumbnail_size_h'>Height</label>
|
2422 |
</div>
|
2423 |
</li>
|
2424 |
<li>
|
2425 |
<div class='cpac-option-label'>Excerpt length</div>
|
2426 |
-
<div class='cpac-option-inputs'>
|
2427 |
-
|
2428 |
<input type='text' id='excerpt_length' class='small-text' name='cpac_options[settings][excerpt_length]' value='15'/>
|
2429 |
<label for='excerpt_length'>Number of words</label>
|
2430 |
</div>
|
2431 |
</li>
|
2432 |
-
</ul>
|
2433 |
</td>
|
2434 |
</tr>
|
2435 |
-->
|
2436 |
";
|
2437 |
-
|
2438 |
// settings
|
2439 |
$row = "
|
2440 |
<tr id='cpac-box-plugin_settings' valign='top' class='cpac-box-row {$class_current_settings}'>
|
2441 |
<td colspan='2'>
|
2442 |
<table class='nopadding'>
|
2443 |
-
{$addons}
|
2444 |
{$general_options}
|
2445 |
</table>
|
2446 |
</td>
|
2447 |
</tr><!-- #cpac-box-plugin_settings -->
|
2448 |
";
|
2449 |
-
|
2450 |
return $row;
|
2451 |
}
|
2452 |
-
|
2453 |
/**
|
2454 |
* Get post count
|
2455 |
*
|
@@ -2458,10 +2457,10 @@ class Codepress_Admin_Columns
|
|
2458 |
public static function get_post_count( $post_type, $user_id )
|
2459 |
{
|
2460 |
global $wpdb;
|
2461 |
-
|
2462 |
if ( ! post_type_exists($post_type) || empty($user_id) )
|
2463 |
return false;
|
2464 |
-
|
2465 |
$sql = "
|
2466 |
SELECT COUNT(ID)
|
2467 |
FROM {$wpdb->posts}
|
@@ -2469,37 +2468,37 @@ class Codepress_Admin_Columns
|
|
2469 |
AND post_author = %d
|
2470 |
AND post_type = %s
|
2471 |
";
|
2472 |
-
|
2473 |
return $wpdb->get_var( $wpdb->prepare($sql, $user_id, $post_type) );
|
2474 |
}
|
2475 |
-
|
2476 |
/**
|
2477 |
* Settings Page Template.
|
2478 |
*
|
2479 |
* This function in conjunction with others uses the WordPress
|
2480 |
* Settings API to create a settings page where users can adjust
|
2481 |
-
* the behaviour of this plugin.
|
2482 |
*
|
2483 |
* @since 1.0
|
2484 |
*/
|
2485 |
-
public function plugin_settings_page()
|
2486 |
{
|
2487 |
// loop through post types
|
2488 |
$rows = '';
|
2489 |
foreach ( $this->get_types() as $type ) {
|
2490 |
-
|
2491 |
// post type label
|
2492 |
$label = $this->get_singular_name($type);
|
2493 |
-
|
2494 |
// id
|
2495 |
-
$id = $this->sanitize_string($type);
|
2496 |
-
|
2497 |
// build draggable boxes
|
2498 |
$boxes = $this->get_column_boxes($type);
|
2499 |
|
2500 |
// class
|
2501 |
$class = $this->is_menu_type_current($type) ? ' current' : ' hidden';
|
2502 |
-
|
2503 |
$rows .= "
|
2504 |
<tr id='cpac-box-{$id}' valign='top' class='cpac-box-row{$class}'>
|
2505 |
<th class='cpac_post_type' scope='row'>
|
@@ -2507,36 +2506,36 @@ class Codepress_Admin_Columns
|
|
2507 |
</th>
|
2508 |
<td>
|
2509 |
<h3 class='cpac_post_type hidden'>{$label}</h3>
|
2510 |
-
{$boxes}
|
2511 |
</td>
|
2512 |
</tr>
|
2513 |
";
|
2514 |
}
|
2515 |
-
|
2516 |
// General Setttings
|
2517 |
$general_settings = $this->plugin_settings();
|
2518 |
-
|
2519 |
// Post Type Menu
|
2520 |
$menu = $this->get_menu();
|
2521 |
-
|
2522 |
// Help screen message
|
2523 |
$help_text = '';
|
2524 |
if ( version_compare( get_bloginfo('version'), '3.2', '>' ) )
|
2525 |
$help_text = '<p>'.__('You will find a short overview at the <strong>Help</strong> section in the top-right screen.', CPAC_TEXTDOMAIN).'</p>';
|
2526 |
-
|
2527 |
// find out more
|
2528 |
$find_out_more = "<a href='{$this->codepress_url}/sortorder-addon/' class='alignright green' target='_blank'>".__('find out more', CPAC_TEXTDOMAIN)." »</a>";
|
2529 |
-
|
2530 |
?>
|
2531 |
<div id="cpac" class="wrap">
|
2532 |
<?php screen_icon(CPAC_SLUG) ?>
|
2533 |
<h2><?php _e('Codepress Admin Columns', CPAC_TEXTDOMAIN); ?></h2>
|
2534 |
<?php echo $menu ?>
|
2535 |
-
|
2536 |
<div class="postbox-container cpac-col-right">
|
2537 |
-
<div class="metabox-holder">
|
2538 |
-
<div class="meta-box-sortables">
|
2539 |
-
|
2540 |
<div id="addons-cpac-settings" class="postbox">
|
2541 |
<div title="Click to toggle" class="handlediv"><br></div>
|
2542 |
<h3 class="hndle">
|
@@ -2549,7 +2548,7 @@ class Codepress_Admin_Columns
|
|
2549 |
<?php echo $find_out_more ?>
|
2550 |
</div>
|
2551 |
</div><!-- addons-cpac-settings -->
|
2552 |
-
|
2553 |
<div id="likethisplugin-cpac-settings" class="postbox">
|
2554 |
<div title="Click to toggle" class="handlediv"><br></div>
|
2555 |
<h3 class="hndle">
|
@@ -2559,46 +2558,46 @@ class Codepress_Admin_Columns
|
|
2559 |
<p><?php _e('Why not do any or all of the following', CPAC_TEXTDOMAIN) ?>:</p>
|
2560 |
<ul>
|
2561 |
<li><a href="<?php echo $this->plugins_url ?>"><?php _e('Give it a 5 star rating on WordPress.org.', CPAC_TEXTDOMAIN) ?></a></li>
|
2562 |
-
<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>
|
2563 |
<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>
|
2564 |
-
</ul>
|
2565 |
</div>
|
2566 |
</div><!-- likethisplugin-cpac-settings -->
|
2567 |
-
|
2568 |
<div id="latest-news-cpac-settings" class="postbox">
|
2569 |
<div title="Click to toggle" class="handlediv"><br></div>
|
2570 |
<h3 class="hndle">
|
2571 |
<span><?php _e('Follow us', CPAC_TEXTDOMAIN) ?></span>
|
2572 |
</h3>
|
2573 |
-
<div class="inside">
|
2574 |
<ul>
|
2575 |
<li class="twitter"><a href="http://twitter.com/codepressNL"><?php _e('Follow Codepress on Twitter.', CPAC_TEXTDOMAIN) ?></a></li>
|
2576 |
<li class="facebook"><a href="https://www.facebook.com/codepressNL"><?php _e('Like Codepress on Facebook.', CPAC_TEXTDOMAIN) ?></a></li>
|
2577 |
-
|
2578 |
-
</ul>
|
2579 |
</div>
|
2580 |
</div><!-- latest-news-cpac-settings -->
|
2581 |
-
|
2582 |
<div id="side-cpac-settings" class="postbox">
|
2583 |
<div title="Click to toggle" class="handlediv"><br></div>
|
2584 |
<h3 class="hndle">
|
2585 |
<span><?php _e('Need support?', CPAC_TEXTDOMAIN) ?></span>
|
2586 |
</h3>
|
2587 |
-
<div class="inside">
|
2588 |
<?php echo $help_text ?>
|
2589 |
<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>
|
2590 |
<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>
|
2591 |
</div>
|
2592 |
</div><!-- side-cpac-settings -->
|
2593 |
-
|
2594 |
</div>
|
2595 |
</div>
|
2596 |
</div><!-- .postbox-container -->
|
2597 |
-
|
2598 |
<div class="postbox-container cpac-col-left">
|
2599 |
-
<div class="metabox-holder">
|
2600 |
<div class="meta-box-sortables">
|
2601 |
-
|
2602 |
<div id="general-cpac-settings" class="postbox">
|
2603 |
<div title="Click to toggle" class="handlediv"><br></div>
|
2604 |
<h3 class="hndle">
|
@@ -2606,16 +2605,16 @@ class Codepress_Admin_Columns
|
|
2606 |
</h3>
|
2607 |
<div class="inside">
|
2608 |
<form method="post" action="options.php">
|
2609 |
-
|
2610 |
<?php settings_fields( 'cpac-settings-group' ); ?>
|
2611 |
-
|
2612 |
<table class="form-table">
|
2613 |
<!-- columns -->
|
2614 |
-
<?php echo $rows; ?>
|
2615 |
-
|
2616 |
<!-- activation -->
|
2617 |
<?php echo $general_settings; ?>
|
2618 |
-
|
2619 |
<tr class="bottom" valign="top">
|
2620 |
<th scope="row"></th>
|
2621 |
<td>
|
@@ -2623,28 +2622,28 @@ class Codepress_Admin_Columns
|
|
2623 |
<input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
|
2624 |
</p>
|
2625 |
</td>
|
2626 |
-
</tr>
|
2627 |
-
</table>
|
2628 |
-
</form>
|
2629 |
-
</div>
|
2630 |
</div><!-- general-settings -->
|
2631 |
-
|
2632 |
<div id="restore-cpac-settings" class="postbox">
|
2633 |
<div title="Click to toggle" class="handlediv"><br></div>
|
2634 |
<h3 class="hndle">
|
2635 |
<span><?php _e('Restore defaults', CPAC_TEXTDOMAIN) ?></span>
|
2636 |
</h3>
|
2637 |
<div class="inside">
|
2638 |
-
<form method="post" action="">
|
2639 |
<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); ?>');" />
|
2640 |
</form>
|
2641 |
<p class="description"><?php _e('This will delete all column settings and restore the default settings.', CPAC_TEXTDOMAIN); ?></p>
|
2642 |
</div>
|
2643 |
</div><!-- restore-cpac-settings -->
|
2644 |
-
|
2645 |
</div>
|
2646 |
</div>
|
2647 |
-
</div><!-- .postbox-container -->
|
2648 |
</div>
|
2649 |
<?php
|
2650 |
}
|
2 |
/*
|
3 |
|
4 |
Plugin Name: Codepress Admin Columns
|
5 |
+
Version: 1.4.9
|
6 |
+
Description: Customize 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/
|
27 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
28 |
*/
|
29 |
|
30 |
+
define( 'CPAC_VERSION', '1.4.9' );
|
31 |
define( 'CPAC_TEXTDOMAIN', 'codepress-admin-columns' );
|
32 |
define( 'CPAC_SLUG', 'codepress-admin-columns' );
|
33 |
define( 'CPAC_URL', plugins_url('', __FILE__) );
|
41 |
*
|
42 |
* @since 1.3
|
43 |
*/
|
|
|
44 |
require_once dirname( __FILE__ ) . '/classes/sortable.php';
|
45 |
+
require_once dirname( __FILE__ ) . '/classes/values.php';
|
46 |
require_once dirname( __FILE__ ) . '/classes/values/posts.php';
|
47 |
require_once dirname( __FILE__ ) . '/classes/values/users.php';
|
48 |
require_once dirname( __FILE__ ) . '/classes/values/media.php';
|
49 |
require_once dirname( __FILE__ ) . '/classes/values/link.php';
|
50 |
require_once dirname( __FILE__ ) . '/classes/values/comments.php';
|
51 |
require_once dirname( __FILE__ ) . '/classes/license.php';
|
52 |
+
require_once dirname( __FILE__ ) . '/classes/third_party.php';
|
53 |
|
54 |
/**
|
55 |
* Codepress Admin Columns Class
|
57 |
* @since 1.0
|
58 |
*
|
59 |
*/
|
60 |
+
class Codepress_Admin_Columns
|
61 |
+
{
|
62 |
private $post_types,
|
63 |
$codepress_url,
|
64 |
$wordpress_url,
|
65 |
$admin_page,
|
66 |
$use_hidden_custom_fields;
|
67 |
+
|
68 |
/**
|
69 |
* Constructor
|
70 |
*
|
71 |
* @since 1.0
|
72 |
*/
|
73 |
function __construct()
|
74 |
+
{
|
75 |
// wp is loaded
|
76 |
add_action( 'wp_loaded', array( $this, 'init') );
|
77 |
}
|
78 |
+
|
79 |
/**
|
80 |
* Initialize plugin.
|
81 |
*
|
90 |
|
91 |
// set
|
92 |
$this->codepress_url = 'http://www.codepress.nl/plugins/codepress-admin-columns';
|
93 |
+
$this->plugins_url = 'http://wordpress.org/extend/plugins/codepress-admin-columns/';
|
94 |
+
$this->wordpress_url = 'http://wordpress.org/tags/codepress-admin-columns';
|
95 |
+
|
96 |
// enable the use of custom hidden fields
|
97 |
$this->use_hidden_custom_fields = apply_filters('cpac_use_hidden_custom_fields', false);
|
98 |
+
|
99 |
// translations
|
100 |
load_plugin_textdomain( CPAC_TEXTDOMAIN, false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
|
101 |
+
|
102 |
// register settings
|
103 |
+
add_action( 'admin_menu', array( $this, 'settings_menu') );
|
104 |
add_action( 'admin_init', array( $this, 'register_settings') );
|
105 |
|
106 |
// styling & scripts
|
107 |
add_action( 'admin_enqueue_scripts' , array( $this, 'column_styles') );
|
108 |
add_filter( 'admin_body_class', array( $this, 'admin_class' ) );
|
109 |
add_action( 'admin_head', array( $this, 'admin_css') );
|
110 |
+
|
111 |
// register columns
|
112 |
add_action( 'admin_init', array( $this, 'register_columns_headings' ) );
|
113 |
+
add_action( 'admin_init', array( $this, 'register_columns_values' ) );
|
114 |
+
|
115 |
// action ajax
|
116 |
add_action( 'wp_ajax_cpac_addon_activation', array( $this, 'ajax_activation'));
|
117 |
+
|
118 |
// handle requests gets a low priority so it will trigger when all other plugins have loaded their columns
|
119 |
+
add_action( 'admin_init', array( $this, 'handle_requests' ), 1000 );
|
120 |
+
|
121 |
// filters
|
122 |
+
add_filter( 'plugin_action_links', array( $this, 'add_settings_link'), 1, 2);
|
123 |
+
}
|
124 |
|
125 |
/**
|
126 |
* Admin Menu.
|
129 |
*
|
130 |
* @since 1.0
|
131 |
*/
|
132 |
+
public function settings_menu()
|
133 |
{
|
134 |
$page = add_options_page(
|
135 |
// Page title
|
136 |
+
esc_html__( 'Admin Columns Settings', CPAC_TEXTDOMAIN ),
|
137 |
// Menu Title
|
138 |
+
esc_html__( 'Admin Columns', CPAC_TEXTDOMAIN ),
|
139 |
// Capability
|
140 |
'manage_options',
|
141 |
// Menu slug
|
142 |
CPAC_SLUG,
|
143 |
// Callback
|
144 |
array( $this, 'plugin_settings_page')
|
145 |
+
);
|
146 |
|
147 |
// set admin page
|
148 |
$this->admin_page = $page;
|
149 |
+
|
150 |
// settings page specific styles and scripts
|
151 |
add_action( "admin_print_styles-$page", array( $this, 'admin_styles') );
|
152 |
add_action( "admin_print_scripts-$page", array( $this, 'admin_scripts') );
|
153 |
+
|
154 |
// add help tabs
|
155 |
add_action("load-$page", array( $this, 'help_tabs'));
|
156 |
}
|
157 |
+
|
158 |
/**
|
159 |
* Add Settings link to plugin page
|
160 |
*
|
163 |
* @param $file string - plugin filename
|
164 |
* @return string - link to settings page
|
165 |
*/
|
166 |
+
function add_settings_link( $links, $file )
|
167 |
{
|
168 |
if ( $file != plugin_basename( __FILE__ ))
|
169 |
return $links;
|
170 |
|
171 |
array_unshift($links, '<a href="' . admin_url("admin.php") . '?page=' . CPAC_SLUG . '">' . __( 'Settings' ) . '</a>');
|
172 |
return $links;
|
173 |
+
}
|
174 |
+
|
175 |
/**
|
176 |
+
* Register Column Values
|
177 |
*
|
178 |
* initializes each Class per type
|
179 |
*
|
195 |
* @since 1.0
|
196 |
*/
|
197 |
public function register_columns_headings()
|
198 |
+
{
|
199 |
+
/** Posts */
|
200 |
foreach ( $this->post_types as $post_type ) {
|
201 |
|
202 |
// register column per post type
|
203 |
add_filter("manage_edit-{$post_type}_columns", array($this, 'callback_add_posts_column_headings'));
|
204 |
+
}
|
205 |
+
|
206 |
/** Users */
|
207 |
+
add_filter( "manage_users_columns", array($this, 'callback_add_users_column_headings'), 9);
|
208 |
// give higher priority, so it will load just before other plugins to prevent conflicts
|
209 |
+
|
210 |
/** Media */
|
211 |
add_filter( "manage_upload_columns", array($this, 'callback_add_media_column_headings'));
|
212 |
+
|
213 |
/** Links */
|
214 |
add_filter( "manage_link-manager_columns", array($this, 'callback_add_links_column_headings'));
|
215 |
+
|
216 |
/** Comments */
|
217 |
add_filter( "manage_edit-comments_columns", array($this, 'callback_add_comments_column_headings'));
|
218 |
}
|
219 |
+
|
220 |
/**
|
221 |
* Callback add Posts Column
|
222 |
*
|
223 |
* @since 1.0
|
224 |
*/
|
225 |
+
public function callback_add_posts_column_headings($columns)
|
226 |
{
|
227 |
+
return $this->add_columns_headings( get_post_type(), $columns);
|
228 |
}
|
229 |
+
|
230 |
/**
|
231 |
* Callback add Users column
|
232 |
*
|
233 |
* @since 1.1
|
234 |
*/
|
235 |
+
public function callback_add_users_column_headings($columns)
|
236 |
{
|
237 |
return $this->add_columns_headings('wp-users', $columns);
|
238 |
}
|
239 |
+
|
240 |
/**
|
241 |
* Callback add Media column
|
242 |
*
|
243 |
* @since 1.3
|
244 |
*/
|
245 |
+
public function callback_add_media_column_headings($columns)
|
246 |
{
|
247 |
return $this->add_columns_headings('wp-media', $columns);
|
248 |
}
|
249 |
+
|
250 |
/**
|
251 |
* Callback add Links column
|
252 |
*
|
253 |
* @since 1.3.1
|
254 |
*/
|
255 |
+
public function callback_add_links_column_headings($columns)
|
256 |
{
|
257 |
return $this->add_columns_headings('wp-links', $columns);
|
258 |
}
|
259 |
+
|
260 |
/**
|
261 |
* Callback add Comments column
|
262 |
*
|
263 |
* @since 1.3.1
|
264 |
*/
|
265 |
+
public function callback_add_comments_column_headings($columns)
|
266 |
{
|
267 |
return $this->add_columns_headings('wp-comments', $columns);
|
268 |
}
|
269 |
+
|
270 |
+
|
271 |
+
|
272 |
/**
|
273 |
* Add managed columns by Type
|
274 |
*
|
275 |
* @since 1.4.6.5
|
276 |
*/
|
277 |
+
private function get_comment_icon()
|
278 |
{
|
279 |
return "<span class='vers'><img src='" . trailingslashit( get_admin_url() ) . 'images/comment-grey-bubble.png' . "' alt='Comments'></span>";
|
280 |
}
|
281 |
+
|
282 |
/**
|
283 |
* Add managed columns by Type
|
284 |
*
|
285 |
* @since 1.1
|
286 |
*/
|
287 |
+
protected function add_columns_headings( $type, $columns )
|
288 |
{
|
289 |
// only get stored columns.. the rest we don't need
|
290 |
$db_columns = self::get_stored_columns($type);
|
291 |
|
292 |
if ( !$db_columns )
|
293 |
return $columns;
|
294 |
+
|
295 |
// filter already loaded columns by plugins
|
296 |
$set_columns = $this->filter_preset_columns( $type, $columns );
|
297 |
|
298 |
// loop through columns
|
299 |
+
foreach ( $db_columns as $id => $values ) {
|
300 |
// is active
|
301 |
+
if ( isset($values['state']) && $values['state'] == 'on' ){
|
302 |
+
|
303 |
$label = $values['label'];
|
304 |
+
|
305 |
// exception for comments
|
306 |
if( 'comments' == $id ) {
|
307 |
$label = $this->get_comment_icon();
|
308 |
}
|
309 |
+
|
310 |
// register format
|
311 |
$set_columns[$id] = $label;
|
312 |
}
|
313 |
}
|
314 |
+
|
315 |
return $set_columns;
|
316 |
}
|
317 |
+
|
318 |
/**
|
319 |
* Filter preset columns. These columns apply either for every post or set by a plugin.
|
320 |
*
|
321 |
* @since 1.0
|
322 |
*/
|
323 |
+
private function filter_preset_columns( $type, $columns )
|
324 |
{
|
325 |
$options = get_option('cpac_options_default');
|
326 |
+
|
327 |
if ( !$options )
|
328 |
return $columns;
|
329 |
+
|
330 |
// we use the wp default columns for filtering...
|
331 |
$stored_wp_default_columns = $options[$type];
|
332 |
|
333 |
// ... the ones that are set by plugins, theme functions and such.
|
334 |
$dif_columns = array_diff(array_keys($columns), array_keys($stored_wp_default_columns));
|
335 |
+
|
336 |
// we add those to the columns
|
337 |
$pre_columns = array();
|
338 |
if ( $dif_columns ) {
|
340 |
$pre_columns[$column] = $columns[$column];
|
341 |
}
|
342 |
}
|
343 |
+
|
344 |
return $pre_columns;
|
345 |
}
|
346 |
+
|
347 |
/**
|
348 |
* Get a list of Column options per post type
|
349 |
*
|
350 |
* @since 1.0
|
351 |
*/
|
352 |
+
private function get_column_boxes($type)
|
353 |
+
{
|
354 |
// merge all columns
|
355 |
$display_columns = $this->get_merged_columns($type);
|
356 |
+
|
357 |
// define
|
358 |
+
$list = '';
|
359 |
+
|
360 |
// loop throught the active columns
|
361 |
if ( $display_columns ) {
|
362 |
+
foreach ( $display_columns as $id => $values ) {
|
363 |
+
|
364 |
$classes = array();
|
365 |
|
366 |
// set state
|
367 |
$state = isset($values['state']) ? $values['state'] : '';
|
368 |
+
|
369 |
// class
|
370 |
$classes[] = "cpac-box-{$id}";
|
371 |
if ( $state ) {
|
375 |
$classes[] = $values['options']['class'];
|
376 |
}
|
377 |
$class = implode(' ', $classes);
|
378 |
+
|
379 |
+
// more box options
|
380 |
$more_options = $this->get_additional_box_options($type, $id, $values);
|
381 |
$action = "<a class='cpac-action' href='#open'>open</a>";
|
382 |
+
|
383 |
// type label
|
384 |
$type_label = isset($values['options']['type_label']) ? $values['options']['type_label'] : '';
|
385 |
+
|
386 |
// label
|
387 |
$label = isset($values['label']) ? str_replace("'", '"', $values['label']) : '';
|
388 |
+
|
389 |
// main label
|
390 |
+
$main_label = $values['label'];
|
391 |
+
|
392 |
// main label exception for comments
|
393 |
if ( 'comments' == $id ) {
|
394 |
$main_label = $this->get_comment_icon();
|
395 |
}
|
396 |
+
|
397 |
// width
|
398 |
$width = isset($values['width']) ? $values['width'] : 0;
|
399 |
$width_descr = isset($values['width']) && $values['width'] > 0 ? $values['width'] . '%' : __('default', CPAC_TEXTDOMAIN);
|
400 |
+
|
401 |
// hide box options
|
402 |
$label_hidden = '';
|
403 |
if ( ! empty($values['options']['hide_options']) || strpos($label, '<img') !== false ) {
|
404 |
$label_hidden = ' style="display:none"';
|
405 |
}
|
406 |
+
|
407 |
$list .= "
|
408 |
<li class='{$class}'>
|
409 |
<div class='cpac-sort-handle'></div>
|
410 |
+
<div class='cpac-type-options'>
|
411 |
<div class='cpac-checkbox'></div>
|
412 |
<input type='hidden' class='cpac-state' name='cpac_options[columns][{$type}][{$id}][state]' value='{$state}'/>
|
413 |
<label class='main-label'>{$main_label}</label>
|
416 |
{$action}
|
417 |
<span>{$type_label}</span>
|
418 |
</div>
|
419 |
+
<div class='cpac-type-inside'>
|
420 |
<label for='cpac_options-{$type}-{$id}-label'{$label_hidden}>Label: </label>
|
421 |
<input type='text' name='cpac_options[columns][{$type}][{$id}][label]' id='cpac_options-{$type}-{$id}-label' value='{$label}' class='text'{$label_hidden}/>
|
422 |
+
<label for='cpac_options-{$type}-{$id}-width'>" . __('Width', CPAC_TEXTDOMAIN) . ":</label>
|
423 |
<input type='hidden' maxlength='4' class='input-width' name='cpac_options[columns][{$type}][{$id}][width]' id='cpac_options-{$type}-{$id}-width' value='{$width}' />
|
424 |
<div class='description width-decription' title='" . __('default', CPAC_TEXTDOMAIN) . "'>{$width_descr}</div>
|
425 |
<div class='input-width-range'></div>
|
427 |
{$more_options}
|
428 |
</div>
|
429 |
</li>
|
430 |
+
";
|
431 |
}
|
432 |
}
|
433 |
+
|
434 |
// custom field button
|
435 |
$button_add_column = '';
|
436 |
if ( $this->get_meta_by_type($type) )
|
437 |
$button_add_column = "<a href='javacript:;' class='cpac-add-customfield-column button'>+ " . __('Add Custom Field Column', CPAC_TEXTDOMAIN) . "</a>";
|
438 |
+
|
439 |
return "
|
440 |
<div class='cpac-box'>
|
441 |
<ul class='cpac-option-list'>
|
442 |
+
{$list}
|
443 |
</ul>
|
444 |
{$button_add_column}
|
445 |
+
<div class='cpac-reorder-msg'>" . __('drag and drop to reorder', CPAC_TEXTDOMAIN) . "</div>
|
446 |
</div>
|
447 |
";
|
448 |
}
|
452 |
*
|
453 |
* @since 1.0
|
454 |
*/
|
455 |
+
protected function get_merged_columns( $type )
|
456 |
{
|
457 |
/** Comments */
|
458 |
if ( $type == 'wp-comments' ) {
|
459 |
$wp_default_columns = $this->get_wp_default_comments_columns();
|
460 |
$wp_custom_columns = $this->get_custom_comments_columns();
|
461 |
}
|
462 |
+
|
463 |
/** Links */
|
464 |
elseif ( $type == 'wp-links' ) {
|
465 |
$wp_default_columns = $this->get_wp_default_links_columns();
|
466 |
$wp_custom_columns = $this->get_custom_links_columns();
|
467 |
}
|
468 |
+
|
469 |
/** Users */
|
470 |
elseif ( $type == 'wp-users' ) {
|
471 |
$wp_default_columns = $this->get_wp_default_users_columns();
|
472 |
$wp_custom_columns = $this->get_custom_users_columns();
|
473 |
}
|
474 |
+
|
475 |
/** Media */
|
476 |
elseif ( $type == 'wp-media' ) {
|
477 |
$wp_default_columns = $this->get_wp_default_media_columns();
|
478 |
$wp_custom_columns = $this->get_custom_media_columns();
|
479 |
}
|
480 |
+
|
481 |
/** Posts */
|
482 |
else {
|
483 |
$wp_default_columns = $this->get_wp_default_posts_columns($type);
|
484 |
$wp_custom_columns = $this->get_custom_posts_columns($type);
|
485 |
}
|
486 |
+
|
487 |
// merge columns
|
488 |
$display_columns = $this->parse_columns($wp_custom_columns, $wp_default_columns, $type);
|
489 |
+
|
490 |
+
return $display_columns;
|
491 |
}
|
492 |
+
|
493 |
/**
|
494 |
* Merge the default columns (set by WordPress) and the added custom columns (set by plugins, theme etc.)
|
495 |
*
|
496 |
* @since 1.3.3
|
497 |
*/
|
498 |
+
function parse_columns($wp_custom_columns, $wp_default_columns, $type)
|
499 |
{
|
500 |
// merge columns
|
501 |
$default_columns = wp_parse_args($wp_custom_columns, $wp_default_columns);
|
502 |
+
|
503 |
//get saved database columns
|
504 |
$db_columns = self::get_stored_columns($type);
|
505 |
if ( $db_columns ) {
|
506 |
+
|
507 |
// let's remove any unavailable columns.. such as disabled plugins
|
508 |
$db_columns = $this->remove_unavailable_columns($db_columns, $default_columns);
|
509 |
+
|
510 |
// loop throught the active columns
|
511 |
foreach ( $db_columns as $id => $values ) {
|
512 |
+
|
513 |
// get column meta options from custom columns
|
514 |
+
if ( $this->is_column_meta($id) && !empty($wp_custom_columns['column-meta-1']['options']) ) {
|
515 |
+
$db_columns[$id]['options'] = $wp_custom_columns['column-meta-1']['options'];
|
516 |
}
|
517 |
+
|
518 |
// add static options
|
519 |
elseif ( isset($default_columns[$id]['options']) )
|
520 |
$db_columns[$id]['options'] = $default_columns[$id]['options'];
|
521 |
+
|
522 |
+
unset($default_columns[$id]);
|
523 |
}
|
524 |
+
}
|
525 |
+
|
526 |
// merge all
|
527 |
return wp_parse_args($db_columns, $default_columns);
|
528 |
}
|
529 |
+
|
530 |
/**
|
531 |
* Remove deactivated (plugin) columns
|
532 |
*
|
539 |
{
|
540 |
// check or differences
|
541 |
$diff = array_diff( array_keys($db_columns), array_keys($default_columns) );
|
542 |
+
|
543 |
+
if ( ! empty($diff) && is_array($diff) ) {
|
544 |
+
foreach ( $diff as $column_name ){
|
545 |
// make an exception for column-meta-xxx
|
546 |
if ( ! $this->is_column_meta($column_name) ) {
|
547 |
unset($db_columns[$column_name]);
|
548 |
}
|
549 |
}
|
550 |
}
|
551 |
+
|
552 |
return $db_columns;
|
553 |
}
|
554 |
+
|
555 |
/**
|
556 |
* Get checkbox
|
557 |
*
|
558 |
* @since 1.0
|
559 |
*/
|
560 |
+
private function get_box($type, $id, $values)
|
561 |
{
|
562 |
$classes = array();
|
563 |
|
564 |
// set state
|
565 |
$state = isset($values['state']) ? $values['state'] : '';
|
566 |
+
|
567 |
// class
|
568 |
$classes[] = "cpac-box-{$id}";
|
569 |
if ( $state ) {
|
573 |
$classes[] = $values['options']['class'];
|
574 |
}
|
575 |
$class = implode(' ', $classes);
|
576 |
+
|
577 |
+
// more box options
|
578 |
$more_options = $this->get_additional_box_options($type, $id, $values);
|
579 |
$action = "<a class='cpac-action' href='#open'>open</a>";
|
580 |
+
|
581 |
// type label
|
582 |
$type_label = isset($values['options']['type_label']) ? $values['options']['type_label'] : '';
|
583 |
+
|
584 |
// label
|
585 |
$label = isset($values['label']) ? str_replace("'", '"', $values['label']) : '';
|
586 |
+
|
587 |
// main label
|
588 |
+
$main_label = $values['label'];
|
589 |
+
|
590 |
// main label exception for comments
|
591 |
if ( 'comments' == $id ) {
|
592 |
$main_label = $this->get_comment_icon();
|
593 |
}
|
594 |
+
|
595 |
// width
|
596 |
$width = isset($values['width']) ? $values['width'] : 0;
|
597 |
$width_descr = isset($values['width']) && $values['width'] > 0 ? $values['width'] . '%' : __('default', CPAC_TEXTDOMAIN);
|
598 |
+
|
599 |
// hide box options
|
600 |
$label_hidden = '';
|
601 |
if ( ! empty($values['options']['hide_options']) || strpos($label, '<img') !== false ) {
|
602 |
$label_hidden = ' style="display:none"';
|
603 |
}
|
604 |
+
|
605 |
$list = "
|
606 |
<li class='{$class}'>
|
607 |
<div class='cpac-sort-handle'></div>
|
608 |
+
<div class='cpac-type-options'>
|
609 |
<div class='cpac-checkbox'></div>
|
610 |
<input type='hidden' class='cpac-state' name='cpac_options[columns][{$type}][{$id}][state]' value='{$state}'/>
|
611 |
<label class='main-label'>{$main_label}</label>
|
614 |
{$action}
|
615 |
<span>{$type_label}</span>
|
616 |
</div>
|
617 |
+
<div class='cpac-type-inside'>
|
618 |
<label for='cpac_options-{$type}-{$id}-label'{$label_hidden}>Label: </label>
|
619 |
<input type='text' name='cpac_options[columns][{$type}][{$id}][label]' id='cpac_options-{$type}-{$id}-label' value='{$label}' class='text'{$label_hidden}/>
|
620 |
+
<label for='cpac_options-{$type}-{$id}-width'>" . __('Width', CPAC_TEXTDOMAIN) . ":</label>
|
621 |
<input type='hidden' maxlength='4' class='input-width' name='cpac_options[columns][{$type}][{$id}][width]' id='cpac_options-{$type}-{$id}-width' value='{$width}' />
|
622 |
<div class='description width-decription' title='" . __('default', CPAC_TEXTDOMAIN) . "'>{$width_descr}</div>
|
623 |
<div class='input-width-range'></div>
|
626 |
</div>
|
627 |
</li>
|
628 |
";
|
629 |
+
|
630 |
return $list;
|
631 |
}
|
632 |
|
635 |
*
|
636 |
* @since 1.0
|
637 |
*/
|
638 |
+
private function get_additional_box_options($type, $id, $values)
|
639 |
{
|
640 |
$fields = '';
|
641 |
+
|
642 |
// Custom Fields
|
643 |
if( $this->is_column_meta($id) ) {
|
644 |
$fields = $this->get_box_options_customfields($type, $id, $values);
|
645 |
}
|
646 |
+
|
647 |
// Author Fields
|
648 |
if( 'column-author-name' == $id) {
|
649 |
$fields = $this->get_box_options_author($type, $id, $values);
|
650 |
}
|
651 |
+
|
652 |
return $fields;
|
653 |
}
|
654 |
|
657 |
*
|
658 |
* @since 1.0
|
659 |
*/
|
660 |
+
private function get_box_options_customfields($type, $id, $values)
|
661 |
{
|
662 |
+
// get post meta fields
|
663 |
$fields = $this->get_meta_by_type($type);
|
664 |
+
|
665 |
+
if ( empty($fields) )
|
666 |
return false;
|
667 |
+
|
668 |
// set meta field options
|
669 |
$current = ! empty($values['field']) ? $values['field'] : '' ;
|
670 |
$field_options = '';
|
671 |
foreach ($fields as $field) {
|
672 |
+
|
673 |
$field_options .= sprintf
|
674 |
(
|
675 |
'<option value="%s"%s>%s</option>',
|
676 |
$field,
|
677 |
$field == $current? ' selected="selected"':'',
|
678 |
+
|
679 |
// change label on hidden fields
|
680 |
+
substr($field,0,10) == "cpachidden" ? str_replace('cpachidden','',$field) : $field
|
681 |
+
);
|
682 |
}
|
683 |
+
|
684 |
// set meta fieldtype options
|
685 |
$currenttype = ! empty($values['field_type']) ? $values['field_type'] : '' ;
|
686 |
$fieldtype_options = '';
|
697 |
'checkmark' => __('Checkmark (true/false)', CPAC_TEXTDOMAIN),
|
698 |
'color' => __('Color', CPAC_TEXTDOMAIN),
|
699 |
);
|
700 |
+
|
701 |
// add filter
|
702 |
$fieldtypes = apply_filters('cpac-field-types', $fieldtypes );
|
703 |
+
|
704 |
// set select options
|
705 |
foreach ( $fieldtypes as $fkey => $fieldtype ) {
|
706 |
$fieldtype_options .= sprintf
|
711 |
$fieldtype
|
712 |
);
|
713 |
}
|
714 |
+
|
715 |
// before and after string
|
716 |
$before = ! empty($values['before']) ? $values['before'] : '' ;
|
717 |
$after = ! empty($values['after']) ? $values['after'] : '' ;
|
718 |
+
|
719 |
if ( empty($field_options) )
|
720 |
return false;
|
721 |
+
|
722 |
// add remove button
|
723 |
$remove = '<p class="remove-description description">'.__('This field can not be removed', CPAC_TEXTDOMAIN).'</p>';
|
724 |
if ( $id != 'column-meta-1') {
|
728 |
</p>
|
729 |
";
|
730 |
}
|
731 |
+
|
732 |
$inside = "
|
733 |
<label for='cpac-{$type}-{$id}-field'>".__('Custom Field', CPAC_TEXTDOMAIN).": </label>
|
734 |
<select name='cpac_options[columns][{$type}][{$id}][field]' id='cpac-{$type}-{$id}-field'>{$field_options}</select>
|
737 |
<select name='cpac_options[columns][{$type}][{$id}][field_type]' id='cpac-{$type}-{$id}-field_type'>{$fieldtype_options}</select>
|
738 |
<br/>
|
739 |
<label for='cpac-{$type}-{$id}-before'>".__('Before', CPAC_TEXTDOMAIN).": </label>
|
740 |
+
<input type='text' class='cpac-before' name='cpac_options[columns][{$type}][{$id}][before]' id='cpac-{$type}-{$id}-before' value='{$before}'/>
|
741 |
+
<br/>
|
742 |
<label for='cpac-{$type}-{$id}-after'>".__('After', CPAC_TEXTDOMAIN).": </label>
|
743 |
+
<input type='text' class='cpac-after' name='cpac_options[columns][{$type}][{$id}][after]' id='cpac-{$type}-{$id}-after' value='{$after}'/>
|
744 |
+
<br/>
|
745 |
{$remove}
|
746 |
";
|
747 |
+
|
748 |
return $inside;
|
749 |
}
|
750 |
+
|
751 |
/**
|
752 |
* Box Options: Custom Fields
|
753 |
*
|
754 |
* @since 1.0
|
755 |
*/
|
756 |
+
private function get_box_options_author($type, $id, $values)
|
757 |
{
|
758 |
$options = '';
|
759 |
$author_types = array(
|
771 |
$selected = selected( $k, $currentname, false);
|
772 |
$options .= "<option value='{$k}' {$selected}>{$name}</option>";
|
773 |
}
|
774 |
+
|
775 |
$inside = "
|
776 |
<label for='cpac-{$type}-{$id}-display_as'>".__('Display name as', CPAC_TEXTDOMAIN).": </label>
|
777 |
<select name='cpac_options[columns][{$type}][{$id}][display_as]' id='cpac-{$type}-{$id}-display_as'>
|
778 |
{$options}
|
779 |
+
</select>
|
780 |
";
|
781 |
+
|
782 |
return $inside;
|
783 |
}
|
784 |
|
787 |
*
|
788 |
* @since 1.0
|
789 |
*/
|
790 |
+
private function get_meta_by_type($type = 'post')
|
791 |
{
|
792 |
global $wpdb;
|
793 |
|
795 |
if ( $type == 'wp-comments') {
|
796 |
$sql = "SELECT DISTINCT meta_key FROM {$wpdb->commentmeta} ORDER BY 1";
|
797 |
}
|
798 |
+
|
799 |
/** Users */
|
800 |
elseif ( $type == 'wp-users') {
|
801 |
$sql = "SELECT DISTINCT meta_key FROM {$wpdb->usermeta} ORDER BY 1";
|
802 |
}
|
803 |
+
|
804 |
/** Media */
|
805 |
elseif ( $type == 'wp-media') {
|
806 |
$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";
|
807 |
}
|
808 |
+
|
809 |
/** Posts */
|
810 |
else {
|
811 |
$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);
|
812 |
}
|
813 |
+
|
814 |
// run sql
|
815 |
$fields = $wpdb->get_results($sql, ARRAY_N);
|
816 |
+
|
817 |
// filter out hidden meta fields
|
818 |
$meta_fields = array();
|
819 |
+
if ( $fields ) {
|
820 |
foreach ($fields as $field) {
|
821 |
+
|
822 |
// give hidden fields a prefix for identifaction
|
823 |
if ( $this->use_hidden_custom_fields && substr($field[0],0,1) == "_") {
|
824 |
$meta_fields[] = 'cpachidden'.$field[0];
|
825 |
}
|
826 |
+
|
827 |
// non hidden fields are saved as is
|
828 |
elseif ( substr($field[0],0,1) != "_" ) {
|
829 |
$meta_fields[] = $field[0];
|
830 |
+
}
|
831 |
+
}
|
832 |
}
|
833 |
+
|
834 |
+
if ( empty($meta_fields) )
|
835 |
+
$meta_fields = false;
|
836 |
+
|
837 |
+
return apply_filters( 'cpac-get-meta-by-type', $meta_fields, $type );
|
838 |
}
|
839 |
|
840 |
/**
|
842 |
*
|
843 |
* @since 1.0
|
844 |
*/
|
845 |
+
public function admin_scripts()
|
846 |
{
|
847 |
wp_enqueue_script( 'wp-pointer' );
|
848 |
+
wp_enqueue_script( 'jquery-ui-slider' );
|
849 |
wp_enqueue_script( 'cpac-qtip2', CPAC_URL.'/assets/js/jquery.qtip.js', array('jquery'), CPAC_VERSION );
|
850 |
wp_enqueue_script( 'cpac-admin', CPAC_URL.'/assets/js/admin-column.js', array('jquery', 'dashboard', 'jquery-ui-sortable'), CPAC_VERSION );
|
851 |
+
}
|
852 |
+
|
853 |
/**
|
854 |
* Get column types
|
855 |
*
|
862 |
$types['wp-media'] = 'wp-media';
|
863 |
$types['wp-links'] = 'wp-links';
|
864 |
$types['wp-comments'] = 'wp-comments';
|
865 |
+
|
866 |
return $types;
|
867 |
}
|
868 |
+
|
869 |
/**
|
870 |
* Get post types
|
871 |
*
|
878 |
));
|
879 |
$post_types['post'] = 'post';
|
880 |
$post_types['page'] = 'page';
|
881 |
+
|
882 |
return apply_filters('cpac-get-post-types', $post_types);
|
883 |
}
|
884 |
|
890 |
public function admin_styles()
|
891 |
{
|
892 |
wp_enqueue_style( 'wp-pointer' );
|
893 |
+
wp_enqueue_style( 'jquery-ui-lightness', CPAC_URL.'/assets/ui-theme/jquery-ui-1.8.18.custom.css', array(), CPAC_VERSION, 'all' );
|
894 |
+
wp_enqueue_style( 'cpac-admin', CPAC_URL.'/assets/css/admin-column.css', array(), CPAC_VERSION, 'all' );
|
895 |
}
|
896 |
+
|
897 |
/**
|
898 |
* Register column css
|
899 |
*
|
901 |
*/
|
902 |
public function column_styles()
|
903 |
{
|
904 |
+
wp_enqueue_style( 'cpac-columns', CPAC_URL.'/assets/css/column.css', array(), CPAC_VERSION, 'all' );
|
905 |
}
|
906 |
|
907 |
/**
|
909 |
*
|
910 |
* @since 1.0
|
911 |
*/
|
912 |
+
public function register_settings()
|
913 |
{
|
914 |
// If we have no options in the database, let's add them now.
|
915 |
if ( false === get_option('cpac_options') ) {
|
916 |
add_option( 'cpac_options', $this->get_default_plugin_options() );
|
917 |
}
|
918 |
+
|
919 |
register_setting( 'cpac-settings-group', 'cpac_options', array($this, 'options_callback') );
|
920 |
+
}
|
921 |
|
922 |
/**
|
923 |
* Returns the default plugin options.
|
924 |
*
|
925 |
* @since 1.0
|
926 |
*/
|
927 |
+
public function get_default_plugin_options()
|
928 |
{
|
929 |
return apply_filters( 'cpac_default_plugin_options', array() );
|
930 |
}
|
935 |
* @since 1.0
|
936 |
*/
|
937 |
public function options_callback($options)
|
938 |
+
{
|
939 |
return $options;
|
940 |
}
|
941 |
|
944 |
*
|
945 |
* @since 1.0
|
946 |
*/
|
947 |
+
public function handle_requests()
|
948 |
{
|
949 |
// only handle updates from the admin columns page
|
950 |
if ( isset($_REQUEST['page']) && CPAC_SLUG == $_REQUEST['page'] ) {
|
951 |
+
|
952 |
// settings updated
|
953 |
if ( ! empty($_REQUEST['settings-updated']) ) {
|
954 |
$this->store_wp_default_columns();
|
955 |
}
|
956 |
+
|
957 |
+
// restore defaults
|
958 |
if ( ! empty($_REQUEST['cpac-restore-defaults']) ) {
|
959 |
$this->restore_defaults();
|
960 |
}
|
961 |
}
|
962 |
}
|
963 |
+
|
964 |
/**
|
965 |
* Stores WP default columns
|
966 |
*
|
968 |
*
|
969 |
* @since 1.2
|
970 |
*/
|
971 |
+
private function store_wp_default_columns()
|
972 |
+
{
|
973 |
// stores the default columns that are set by WP or theme.
|
974 |
$wp_default_columns = array();
|
975 |
+
|
976 |
// Posts
|
977 |
foreach ( $this->post_types as $post_type ) {
|
978 |
$wp_default_columns[$post_type] = $this->get_wp_default_posts_columns($post_type);
|
979 |
}
|
980 |
+
|
981 |
// Users
|
982 |
$wp_default_columns['wp-users'] = $this->get_wp_default_users_columns();
|
983 |
+
|
984 |
// Media
|
985 |
$wp_default_columns['wp-media'] = $this->get_wp_default_media_columns();
|
986 |
+
|
987 |
// Links
|
988 |
$wp_default_columns['wp-links'] = $this->get_wp_default_links_columns();
|
989 |
+
|
990 |
// Comments
|
991 |
+
$wp_default_columns['wp-comments'] = $this->get_wp_default_comments_columns();
|
992 |
+
|
993 |
update_option( 'cpac_options_default', $wp_default_columns );
|
994 |
}
|
995 |
|
998 |
*
|
999 |
* @since 1.0
|
1000 |
*/
|
1001 |
+
private function restore_defaults()
|
1002 |
+
{
|
1003 |
delete_option( 'cpac_options' );
|
1004 |
+
delete_option( 'cpac_options_default' );
|
1005 |
+
}
|
1006 |
+
|
1007 |
/**
|
1008 |
* Get author field by nametype
|
1009 |
*
|
1014 |
public function get_author_field_by_nametype( $nametype, $user_id)
|
1015 |
{
|
1016 |
$userdata = get_userdata( $user_id );
|
1017 |
+
|
1018 |
switch ( $nametype ) :
|
1019 |
+
|
1020 |
case "display_name" :
|
1021 |
$name = $userdata->display_name;
|
1022 |
break;
|
1023 |
+
|
1024 |
case "first_name" :
|
1025 |
$name = $userdata->first_name;
|
1026 |
+
break;
|
1027 |
+
|
1028 |
case "last_name" :
|
1029 |
$name = $userdata->last_name;
|
1030 |
break;
|
1031 |
+
|
1032 |
case "first_last_name" :
|
1033 |
$first = !empty($userdata->first_name) ? $userdata->first_name : '';
|
1034 |
$last = !empty($userdata->last_name) ? " {$userdata->last_name}" : '';
|
1035 |
$name = $first.$last;
|
1036 |
break;
|
1037 |
+
|
1038 |
case "nickname" :
|
1039 |
$name = $userdata->nickname;
|
1040 |
+
break;
|
1041 |
+
|
1042 |
case "username" :
|
1043 |
$name = $userdata->user_login;
|
1044 |
break;
|
1045 |
+
|
1046 |
case "email" :
|
1047 |
$name = $userdata->user_email;
|
1048 |
break;
|
1049 |
+
|
1050 |
case "userid" :
|
1051 |
$name = $userdata->ID;
|
1052 |
break;
|
1053 |
+
|
1054 |
default :
|
1055 |
$name = $userdata->display_name;
|
1056 |
+
|
1057 |
endswitch;
|
1058 |
+
|
1059 |
return $name;
|
1060 |
}
|
1061 |
+
|
1062 |
/**
|
1063 |
* Get WP default supported admin columns per post type.
|
1064 |
*
|
1065 |
* @since 1.0
|
1066 |
*/
|
1067 |
+
private function get_wp_default_posts_columns($post_type = 'post')
|
1068 |
{
|
1069 |
+
// You can use this filter to add thirdparty columns by hooking into this. See classes/third_party.php for an example.
|
1070 |
+
do_action( 'cpac-get-default-columns-posts', $post_type );
|
1071 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1072 |
// some plugins directly hook into get_column_headers, such as woocommerce
|
1073 |
$columns = get_column_headers( 'edit-'.$post_type );
|
1074 |
+
|
1075 |
+
// get default columns
|
1076 |
+
if ( empty($columns) ) {
|
1077 |
+
|
1078 |
// deprecated as of wp3.3
|
1079 |
if ( file_exists(ABSPATH . 'wp-admin/includes/template.php') )
|
1080 |
require_once(ABSPATH . 'wp-admin/includes/template.php');
|
1081 |
+
|
1082 |
// introduced since wp3.3
|
1083 |
if ( file_exists(ABSPATH . 'wp-admin/includes/screen.php') )
|
1084 |
require_once(ABSPATH . 'wp-admin/includes/screen.php');
|
1085 |
+
|
1086 |
// used for getting columns
|
1087 |
if ( file_exists(ABSPATH . 'wp-admin/includes/class-wp-list-table.php') )
|
1088 |
require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
|
1089 |
if ( file_exists(ABSPATH . 'wp-admin/includes/class-wp-posts-list-table.php') )
|
1090 |
require_once(ABSPATH . 'wp-admin/includes/class-wp-posts-list-table.php');
|
1091 |
+
|
1092 |
// As of WP Release 3.5 we can use the following.
|
1093 |
if ( version_compare( get_bloginfo('version'), '3.4.10', '>=' ) ) {
|
1094 |
+
|
1095 |
$table = new WP_Posts_List_Table( array( 'screen' => $post_type ) );
|
1096 |
$columns = $table->get_columns();
|
1097 |
}
|
1098 |
+
|
1099 |
// WP versions older then 3.5
|
1100 |
// @todo: make this deprecated
|
1101 |
+
else {
|
1102 |
+
|
1103 |
// we need to change the current screen... first lets 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 post type of choose...
|
1110 |
$current_screen->post_type = $post_type;
|
1111 |
+
|
1112 |
+
// ...so we can get its columns
|
1113 |
+
$columns = WP_Posts_List_Table::get_columns();
|
1114 |
+
|
1115 |
// reset current screen
|
1116 |
$current_screen = $org_current_screen;
|
1117 |
}
|
1118 |
}
|
1119 |
+
|
1120 |
if ( empty ( $columns ) )
|
1121 |
return false;
|
1122 |
+
|
1123 |
// change to uniform format
|
1124 |
+
$columns = $this->get_uniform_format($columns);
|
1125 |
|
1126 |
// add sorting to some of the default links columns
|
1127 |
$columns = $this->set_sorting_to_default_posts_columns($columns);
|
1128 |
+
|
1129 |
return $columns;
|
1130 |
}
|
1131 |
+
|
1132 |
/**
|
1133 |
* Add Sorting to WP default Posts columns
|
1134 |
*
|
1135 |
* @since 1.4.5
|
1136 |
*/
|
1137 |
private function set_sorting_to_default_posts_columns($columns)
|
1138 |
+
{
|
1139 |
// categories
|
1140 |
if ( !empty($columns['categories']) ) {
|
1141 |
$columns['categories']['options']['sortorder'] = 'on';
|
1146 |
}
|
1147 |
return $columns;
|
1148 |
}
|
1149 |
+
|
1150 |
/**
|
1151 |
* Get WP default users columns per post type.
|
1152 |
*
|
1154 |
*/
|
1155 |
private function get_wp_default_users_columns()
|
1156 |
{
|
1157 |
+
// You can use this filter to add third_party columns by hooking into this.
|
1158 |
+
do_action( 'cpac-get-default-columns-users' );
|
1159 |
+
|
1160 |
if ( file_exists(ABSPATH . 'wp-admin/includes/class-wp-list-table.php') )
|
1161 |
require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
|
1162 |
if ( file_exists(ABSPATH . 'wp-admin/includes/class-wp-users-list-table.php') )
|
1163 |
require_once(ABSPATH . 'wp-admin/includes/class-wp-users-list-table.php');
|
1164 |
+
|
1165 |
// turn off site users
|
1166 |
$this->is_site_users = false;
|
1167 |
+
|
1168 |
// get users columns
|
1169 |
$columns = WP_Users_List_Table::get_columns();
|
1170 |
+
|
1171 |
// change to uniform format
|
1172 |
$columns = $this->get_uniform_format($columns);
|
1173 |
|
1174 |
return apply_filters('cpac-default-users-columns', $columns);
|
1175 |
}
|
1176 |
+
|
1177 |
/**
|
1178 |
* Get WP default media columns.
|
1179 |
*
|
1180 |
* @since 1.2.1
|
1181 |
*/
|
1182 |
private function get_wp_default_media_columns()
|
1183 |
+
{
|
1184 |
+
// You can use this filter to add third_party columns by hooking into this.
|
1185 |
+
do_action( 'cpac-get-default-columns-media' );
|
1186 |
+
|
1187 |
// @todo could use _get_list_table('WP_Media_List_Table') ?
|
1188 |
if ( file_exists(ABSPATH . 'wp-admin/includes/class-wp-list-table.php') )
|
1189 |
require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
|
1190 |
if ( file_exists(ABSPATH . 'wp-admin/includes/class-wp-media-list-table.php') )
|
1191 |
require_once(ABSPATH . 'wp-admin/includes/class-wp-media-list-table.php');
|
1192 |
+
|
1193 |
// As of WP Release 3.5 we can use the following.
|
1194 |
if ( version_compare( get_bloginfo('version'), '3.4.10', '>=' ) ) {
|
1195 |
+
|
1196 |
$table = new WP_Media_List_Table(array( 'screen' => 'upload' ));
|
1197 |
$columns = $table->get_columns();
|
1198 |
}
|
1199 |
+
|
1200 |
// WP versions older then 3.5
|
1201 |
// @todo: make this deprecated
|
1202 |
+
else {
|
1203 |
+
|
1204 |
global $current_screen;
|
1205 |
|
1206 |
// save original
|
1207 |
$org_current_screen = $current_screen;
|
1208 |
+
|
1209 |
+
// prevent php warning
|
1210 |
if ( !isset($current_screen) ) $current_screen = new stdClass;
|
1211 |
+
|
1212 |
// overwrite current_screen global with our media id...
|
1213 |
$current_screen->id = 'upload';
|
1214 |
+
|
1215 |
// init media class
|
1216 |
$wp_media = new WP_Media_List_Table;
|
1217 |
+
|
1218 |
+
// get media columns
|
1219 |
$columns = $wp_media->get_columns();
|
1220 |
+
|
1221 |
// reset current screen
|
1222 |
$current_screen = $org_current_screen;
|
1223 |
}
|
1224 |
+
|
1225 |
// change to uniform format
|
1226 |
$columns = $this->get_uniform_format($columns);
|
1227 |
+
|
1228 |
return apply_filters('cpac-default-media-columns', $columns);
|
1229 |
}
|
1230 |
+
|
1231 |
/**
|
1232 |
* Get WP default links columns.
|
1233 |
*
|
1235 |
*/
|
1236 |
private function get_wp_default_links_columns()
|
1237 |
{
|
1238 |
+
// You can use this filter to add third_party columns by hooking into this.
|
1239 |
+
do_action( 'cpac-get-default-columns-links' );
|
1240 |
+
|
1241 |
// dependencies
|
1242 |
if ( file_exists(ABSPATH . 'wp-admin/includes/class-wp-list-table.php') )
|
1243 |
require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
|
1244 |
if ( file_exists(ABSPATH . 'wp-admin/includes/class-wp-links-list-table.php') )
|
1245 |
require_once(ABSPATH . 'wp-admin/includes/class-wp-links-list-table.php');
|
1246 |
+
|
1247 |
// get links columns
|
1248 |
$columns = WP_Links_List_Table::get_columns();
|
1249 |
|
1250 |
// change to uniform format
|
1251 |
$columns = $this->get_uniform_format($columns);
|
1252 |
+
|
1253 |
// add sorting to some of the default links columns
|
1254 |
$columns = $this->set_sorting_to_default_links_columns($columns);
|
1255 |
+
|
1256 |
return apply_filters('cpac-default-links-columns', $columns);
|
1257 |
}
|
1258 |
+
|
1259 |
/**
|
1260 |
* Add Sorting to WP default links columns
|
1261 |
*
|
1269 |
}
|
1270 |
return $columns;
|
1271 |
}
|
1272 |
+
|
1273 |
/**
|
1274 |
* Get WP default links columns.
|
1275 |
*
|
1276 |
* @since 1.3.1
|
1277 |
*/
|
1278 |
private function get_wp_default_comments_columns()
|
1279 |
+
{
|
1280 |
+
// You can use this filter to add third_party columns by hooking into this.
|
1281 |
+
do_action( 'cpac-get-default-columns-comments' );
|
1282 |
+
|
1283 |
// dependencies
|
1284 |
if ( file_exists(ABSPATH . 'wp-admin/includes/class-wp-list-table.php') )
|
1285 |
require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
|
1286 |
if ( file_exists(ABSPATH . 'wp-admin/includes/class-wp-comments-list-table.php') )
|
1287 |
require_once(ABSPATH . 'wp-admin/includes/class-wp-comments-list-table.php');
|
1288 |
+
|
1289 |
// As of WP Release 3.5 we can use the following.
|
1290 |
if ( version_compare( get_bloginfo('version'), '3.4.10', '>=' ) ) {
|
1291 |
+
|
1292 |
$table = new WP_Comments_List_Table( array( 'screen' => 'edit-comments' ) );
|
1293 |
$columns = $table->get_columns();
|
1294 |
}
|
1295 |
+
|
1296 |
// WP versions older then 3.5
|
1297 |
// @todo: make this deprecated
|
1298 |
else {
|
1299 |
+
|
1300 |
global $current_screen;
|
1301 |
|
1302 |
+
// save original
|
1303 |
$org_current_screen = $current_screen;
|
1304 |
+
|
1305 |
+
// prevent php warning
|
1306 |
if ( !isset($current_screen) ) $current_screen = new stdClass;
|
1307 |
+
|
1308 |
// overwrite current_screen global with our media id...
|
1309 |
$current_screen->id = 'edit-comments';
|
1310 |
+
|
1311 |
// init table object
|
1312 |
+
$wp_comment = new WP_Comments_List_Table;
|
1313 |
+
|
1314 |
// get comments
|
1315 |
$columns = $wp_comment->get_columns();
|
1316 |
+
|
1317 |
// reset current screen
|
1318 |
$current_screen = $org_current_screen;
|
1319 |
}
|
1320 |
+
|
1321 |
// change to uniform format
|
1322 |
$columns = $this->get_uniform_format($columns);
|
1323 |
+
|
1324 |
// add sorting to some of the default links columns
|
1325 |
$columns = $this->set_sorting_to_default_comments_columns($columns);
|
1326 |
+
|
1327 |
return apply_filters('cpac-default-comments-columns', $columns);
|
1328 |
}
|
1329 |
+
|
1330 |
/**
|
1331 |
* Add Sorting to WP default comments columns
|
1332 |
*
|
1346 |
*
|
1347 |
* @since 1.0
|
1348 |
*/
|
1349 |
+
private function get_uniform_format($columns)
|
1350 |
{
|
1351 |
+
// we remove the checkbox column as an option...
|
1352 |
if ( isset($columns['cb']) )
|
1353 |
unset($columns['cb']);
|
1354 |
+
|
1355 |
// change to uniform format
|
1356 |
$uniform_columns = array();
|
1357 |
foreach ( (array) $columns as $id => $label ) {
|
1358 |
$hide_options = false;
|
1359 |
$type_label = $label;
|
1360 |
+
|
1361 |
+
// comment exception
|
1362 |
+
if ( 'comments' == $id ) {
|
1363 |
$label = '';
|
1364 |
$type_label = __('Comments', CPAC_TEXTDOMAIN);
|
1365 |
$hide_options = true;
|
1366 |
}
|
1367 |
+
|
1368 |
// user icon exception
|
1369 |
if ( $id == 'icon' ) {
|
1370 |
$type_label = __('Icon', CPAC_TEXTDOMAIN);
|
1371 |
}
|
1372 |
+
|
1373 |
$uniform_columns[$id] = array(
|
1374 |
'label' => $label,
|
1375 |
'state' => 'on',
|
1382 |
}
|
1383 |
return $uniform_columns;
|
1384 |
}
|
1385 |
+
|
1386 |
/**
|
1387 |
* Custom posts columns
|
1388 |
*
|
1389 |
* @since 1.0
|
1390 |
*/
|
1391 |
+
private function get_custom_posts_columns($post_type)
|
1392 |
{
|
1393 |
$custom_columns = array(
|
1394 |
'column-featured_image' => array(
|
1444 |
'display_as' => ''
|
1445 |
),
|
1446 |
'column-before-moretag' => array(
|
1447 |
+
'label' => __('Before More Tag', CPAC_TEXTDOMAIN)
|
1448 |
)
|
1449 |
);
|
1450 |
+
|
1451 |
// Word count support
|
1452 |
if ( post_type_supports($post_type, 'editor') ) {
|
1453 |
$custom_columns['column-word-count'] = array(
|
1454 |
'label' => __('Word count', CPAC_TEXTDOMAIN)
|
1455 |
);
|
1456 |
}
|
1457 |
+
|
1458 |
// Sticky support
|
1459 |
+
if ( $post_type == 'post' ) {
|
1460 |
$custom_columns['column-sticky'] = array(
|
1461 |
'label' => __('Sticky', CPAC_TEXTDOMAIN)
|
1462 |
);
|
1463 |
}
|
1464 |
+
|
1465 |
// Order support
|
1466 |
if ( post_type_supports($post_type, 'page-attributes') ) {
|
1467 |
$custom_columns['column-order'] = array(
|
1468 |
+
'label' => __('Page Order', CPAC_TEXTDOMAIN),
|
1469 |
'options' => array(
|
1470 |
'type_label' => __('Order', CPAC_TEXTDOMAIN)
|
1471 |
+
)
|
1472 |
);
|
1473 |
}
|
1474 |
+
|
1475 |
// Page Template
|
1476 |
+
if ( $post_type == 'page' ) {
|
1477 |
$custom_columns['column-page-template'] = array(
|
1478 |
'label' => __('Page Template', CPAC_TEXTDOMAIN)
|
1479 |
+
);
|
1480 |
}
|
1481 |
+
|
1482 |
// Post Formats
|
1483 |
if ( post_type_supports($post_type, 'post-formats') ) {
|
1484 |
$custom_columns['column-post_formats'] = array(
|
1485 |
'label' => __('Post Format', CPAC_TEXTDOMAIN)
|
1486 |
);
|
1487 |
}
|
1488 |
+
|
1489 |
// Taxonomy support
|
1490 |
$taxonomies = get_object_taxonomies($post_type, 'objects');
|
1491 |
if ( $taxonomies ) {
|
1497 |
'options' => array(
|
1498 |
'type_label' => __('Taxonomy', CPAC_TEXTDOMAIN)
|
1499 |
)
|
1500 |
+
);
|
1501 |
}
|
1502 |
}
|
1503 |
}
|
1504 |
+
|
1505 |
// Custom Field support
|
1506 |
if ( $this->get_meta_by_type($post_type) ) {
|
1507 |
$custom_columns['column-meta-1'] = array(
|
1513 |
'options' => array(
|
1514 |
'type_label' => __('Field', CPAC_TEXTDOMAIN),
|
1515 |
'class' => 'cpac-box-metafield'
|
1516 |
+
)
|
1517 |
);
|
1518 |
+
}
|
1519 |
+
|
1520 |
// merge with defaults
|
1521 |
$custom_columns = $this->parse_defaults($custom_columns);
|
1522 |
+
|
1523 |
return apply_filters('cpac-custom-posts-columns', $custom_columns);
|
1524 |
}
|
1525 |
+
|
1526 |
/**
|
1527 |
* Custom users columns
|
1528 |
*
|
1529 |
* @since 1.1
|
1530 |
*/
|
1531 |
+
private function get_custom_users_columns()
|
1532 |
{
|
1533 |
$custom_columns = array(
|
1534 |
'column-user_id' => array(
|
1559 |
)
|
1560 |
),
|
1561 |
);
|
1562 |
+
|
1563 |
// User total number of posts
|
1564 |
foreach ( self::get_post_types() as $post_type ) {
|
1565 |
$label = $this->get_plural_name($post_type);
|
1570 |
)
|
1571 |
);
|
1572 |
}
|
1573 |
+
|
1574 |
// Custom Field support
|
1575 |
$custom_columns['column-meta-1'] = array(
|
1576 |
'label' => __('Custom Field', CPAC_TEXTDOMAIN),
|
1582 |
'type_label' => __('Field', CPAC_TEXTDOMAIN),
|
1583 |
'class' => 'cpac-box-metafield'
|
1584 |
)
|
1585 |
+
);
|
1586 |
+
|
1587 |
// merge with defaults
|
1588 |
$custom_columns = $this->parse_defaults($custom_columns);
|
1589 |
+
|
1590 |
return apply_filters('cpac-custom-users-columns', $custom_columns);
|
1591 |
}
|
1592 |
+
|
1593 |
/**
|
1594 |
* Custom media columns
|
1595 |
*
|
1596 |
* @since 1.3
|
1597 |
*/
|
1598 |
+
private function get_custom_media_columns()
|
1599 |
{
|
1600 |
$custom_columns = array(
|
1601 |
'column-mediaid' => array(
|
1639 |
),
|
1640 |
'column-filesize' => array(
|
1641 |
'label' => __('File size', CPAC_TEXTDOMAIN)
|
1642 |
+
)
|
1643 |
);
|
1644 |
+
|
1645 |
// Get extended image metadata, exif or iptc as available.
|
1646 |
// uses exif_read_data()
|
1647 |
if ( function_exists('exif_read_data') ) {
|
1708 |
)
|
1709 |
));
|
1710 |
}
|
1711 |
+
|
1712 |
// Custom Field support
|
1713 |
if ( $this->get_meta_by_type('wp-media') ) {
|
1714 |
$custom_columns['column-meta-1'] = array(
|
1723 |
)
|
1724 |
);
|
1725 |
}
|
1726 |
+
|
1727 |
// merge with defaults
|
1728 |
$custom_columns = $this->parse_defaults($custom_columns);
|
1729 |
+
|
1730 |
return apply_filters('cpac-custom-media-columns', $custom_columns);
|
1731 |
}
|
1732 |
+
|
1733 |
/**
|
1734 |
* Custom links columns
|
1735 |
*
|
1736 |
* @since 1.3.1
|
1737 |
*/
|
1738 |
+
private function get_custom_links_columns()
|
1739 |
{
|
1740 |
$custom_columns = array(
|
1741 |
'column-link_id' => array (
|
1767 |
'options' => array(
|
1768 |
'sortorder' => false
|
1769 |
)
|
1770 |
+
)
|
1771 |
+
);
|
1772 |
+
|
1773 |
// merge with defaults
|
1774 |
$custom_columns = $this->parse_defaults($custom_columns);
|
1775 |
+
|
1776 |
return apply_filters('cpac-custom-links-columns', $custom_columns);
|
1777 |
}
|
1778 |
+
|
1779 |
/**
|
1780 |
* Custom comments columns
|
1781 |
*
|
1782 |
* @since 1.3.1
|
1783 |
*/
|
1784 |
+
private function get_custom_comments_columns()
|
1785 |
{
|
1786 |
$custom_columns = array(
|
1787 |
'column-comment_id' => array(
|
1803 |
'label' => __('Author email', CPAC_TEXTDOMAIN)
|
1804 |
),
|
1805 |
'column-reply_to' => array(
|
1806 |
+
'label' => __('In Reply To', CPAC_TEXTDOMAIN),
|
1807 |
+
'options' => array(
|
1808 |
'sortorder' => false
|
1809 |
)
|
1810 |
),
|
1835 |
'sortorder' => false
|
1836 |
)
|
1837 |
)
|
1838 |
+
);
|
1839 |
+
|
1840 |
// Custom Field support
|
1841 |
if ( $this->get_meta_by_type('wp-comments') ) {
|
1842 |
$custom_columns['column-meta-1'] = array(
|
1851 |
'sortorder' => false,
|
1852 |
)
|
1853 |
);
|
1854 |
+
}
|
1855 |
+
|
1856 |
// merge with defaults
|
1857 |
$custom_columns = $this->parse_defaults($custom_columns);
|
1858 |
+
|
1859 |
return apply_filters('cpac-custom-comments-columns', $custom_columns);
|
1860 |
}
|
1861 |
+
|
1862 |
/**
|
1863 |
* Parse defaults
|
1864 |
*
|
1865 |
* @since 1.1
|
1866 |
*/
|
1867 |
+
private function parse_defaults($columns)
|
1868 |
{
|
1869 |
// default arguments
|
1870 |
+
$defaults = array(
|
1871 |
+
|
1872 |
// stored values
|
1873 |
'label' => '', // custom label
|
1874 |
'state' => '', // display state
|
1875 |
+
'width' => '', // column width
|
1876 |
+
|
1877 |
// static values
|
1878 |
+
'options' => array(
|
1879 |
'type_label' => __('Custom', CPAC_TEXTDOMAIN),
|
1880 |
'hide_options' => false,
|
1881 |
'class' => 'cpac-box-custom',
|
1882 |
'sortorder' => 'on',
|
1883 |
)
|
1884 |
);
|
1885 |
+
|
1886 |
// parse args
|
1887 |
foreach ( $columns as $k => $column ) {
|
1888 |
$c[$k] = wp_parse_args( $column, $defaults);
|
1889 |
+
|
1890 |
// parse options args
|
1891 |
if ( isset($column['options']) )
|
1892 |
$c[$k]['options'] = wp_parse_args( $column['options'], $defaults['options']);
|
1893 |
+
|
1894 |
// set type label
|
1895 |
if ( empty($column['options']['type_label']) && !empty($column['label']) )
|
1896 |
$c[$k]['options']['type_label'] = $column['label'];
|
1897 |
}
|
1898 |
+
|
1899 |
return $c;
|
1900 |
}
|
1901 |
|
1905 |
* @since 1.0
|
1906 |
*/
|
1907 |
public static function get_stored_columns($type)
|
1908 |
+
{
|
1909 |
// get plugin options
|
1910 |
$options = get_option('cpac_options');
|
1911 |
|
1912 |
// get saved columns
|
1913 |
if ( !empty($options['columns'][$type]) )
|
1914 |
return $options['columns'][$type];
|
1915 |
+
|
1916 |
return false;
|
1917 |
}
|
1918 |
|
1921 |
*
|
1922 |
* @since 1.0
|
1923 |
*/
|
1924 |
+
private function get_menu()
|
1925 |
{
|
1926 |
// set
|
1927 |
$menu = '';
|
1928 |
$count = 1;
|
1929 |
+
|
1930 |
// referer
|
1931 |
$referer = ! empty($_REQUEST['cpac_type']) ? $_REQUEST['cpac_type'] : '';
|
1932 |
+
|
1933 |
// loop
|
1934 |
foreach ( $this->get_types() as $type ) {
|
1935 |
$label = $this->get_singular_name($type);
|
1936 |
$clean_label = $this->sanitize_string($type);
|
1937 |
+
|
1938 |
// divider
|
1939 |
$divider = $count++ == 1 ? '' : ' | ';
|
1940 |
+
|
1941 |
+
// current
|
1942 |
$current = '';
|
1943 |
if ( $this->is_menu_type_current($type) )
|
1944 |
$current = ' class="current"';
|
1945 |
+
|
1946 |
// menu list
|
1947 |
$menu .= "
|
1948 |
<li>{$divider}<a{$current} href='#cpac-box-{$clean_label}'>{$label}</a></li>
|
1949 |
";
|
1950 |
}
|
1951 |
+
|
1952 |
// settings url
|
1953 |
$class_current_settings = $this->is_menu_type_current('plugin_settings') ? ' current': '';
|
1954 |
+
|
1955 |
// options button
|
1956 |
$options_btn = "<a href='#cpac-box-plugin_settings' class='cpac-settings-link{$class_current_settings}'>".__('Addons', CPAC_TEXTDOMAIN)."</a>";
|
1957 |
//$options_btn = '';
|
1958 |
+
|
1959 |
return "
|
1960 |
<div class='cpac-menu'>
|
1961 |
<ul class='subsubsub'>
|
1971 |
*
|
1972 |
* @since 1.0
|
1973 |
*/
|
1974 |
+
private function is_menu_type_current( $type )
|
1975 |
+
{
|
1976 |
// referer
|
1977 |
$referer = ! empty($_REQUEST['cpac_type']) ? $_REQUEST['cpac_type'] : '';
|
1978 |
+
|
1979 |
// get label
|
1980 |
$clean_label = $this->sanitize_string($type);
|
1981 |
+
|
1982 |
// get first element from post-types
|
1983 |
$first = array_shift( array_values($this->post_types) );
|
1984 |
+
|
1985 |
// display the page that was being viewed before saving
|
1986 |
if ( $referer ) {
|
1987 |
if ( $referer == 'cpac-box-'.$clean_label ) {
|
1988 |
return true;
|
1989 |
}
|
1990 |
+
|
1991 |
// settings page has not yet been saved
|
1992 |
} elseif ( $first == $type ) {
|
1993 |
return true;
|
1994 |
}
|
1995 |
+
|
1996 |
+
return false;
|
1997 |
}
|
1998 |
|
1999 |
/**
|
2001 |
*
|
2002 |
* @since 1.0
|
2003 |
*/
|
2004 |
+
private function get_singular_name( $type )
|
2005 |
{
|
2006 |
// Links
|
2007 |
if ( $type == 'wp-links' )
|
2008 |
$label = __('Links');
|
2009 |
+
|
2010 |
// Comments
|
2011 |
elseif ( $type == 'wp-comments' )
|
2012 |
$label = __('Comments');
|
2013 |
+
|
2014 |
// Users
|
2015 |
elseif ( $type == 'wp-users' )
|
2016 |
$label = __('Users');
|
2017 |
+
|
2018 |
// Media
|
2019 |
elseif ( $type == 'wp-media' )
|
2020 |
$label = __('Media Library');
|
2021 |
+
|
2022 |
// Posts
|
2023 |
else {
|
2024 |
$posttype_obj = get_post_type_object($type);
|
2025 |
$label = $posttype_obj->labels->singular_name;
|
2026 |
}
|
2027 |
+
|
2028 |
return $label;
|
2029 |
}
|
2030 |
+
|
2031 |
/**
|
2032 |
* Get plural name of post type
|
2033 |
*
|
2034 |
* @since 1.3.1
|
2035 |
*/
|
2036 |
+
private function get_plural_name( $type )
|
2037 |
{
|
2038 |
$posttype_obj = get_post_type_object($type);
|
2039 |
if ( $posttype_obj )
|
2040 |
return $posttype_obj->labels->name;
|
2041 |
+
|
2042 |
return false;
|
2043 |
}
|
2044 |
+
|
2045 |
/**
|
2046 |
* Get screen link to overview screen
|
2047 |
*
|
2048 |
* @since 1.3.1
|
2049 |
*/
|
2050 |
+
private function get_type_screen_link( $type )
|
2051 |
+
{
|
2052 |
// Links
|
2053 |
if ( $type == 'wp-comments' )
|
2054 |
$link = get_admin_url() . 'edit-comments.php';
|
2055 |
+
|
2056 |
// Links
|
2057 |
if ( $type == 'wp-links' )
|
2058 |
$link = get_admin_url() . 'link-manager.php';
|
2059 |
+
|
2060 |
// Users
|
2061 |
if ( $type == 'wp-users' )
|
2062 |
$link = get_admin_url() . 'users.php';
|
2063 |
+
|
2064 |
// Media
|
2065 |
elseif ( $type == 'wp-media' )
|
2066 |
$link = get_admin_url() . 'upload.php';
|
2067 |
+
|
2068 |
// Posts
|
2069 |
+
else
|
2070 |
+
$link = get_admin_url() . "edit.php?post_type={$type}";
|
2071 |
+
|
2072 |
return $link;
|
2073 |
}
|
2074 |
|
2079 |
*
|
2080 |
* @since 1.0
|
2081 |
*/
|
2082 |
+
protected function sanitize_string($string)
|
2083 |
+
{
|
2084 |
$string = esc_url($string);
|
2085 |
$string = str_replace('http://','', $string);
|
2086 |
$string = str_replace('https://','', $string);
|
2087 |
+
|
2088 |
return $string;
|
2089 |
}
|
2090 |
+
|
2091 |
/**
|
2092 |
* Checks if column-meta key exists
|
2093 |
*
|
2094 |
* @since 1.0
|
2095 |
*/
|
2096 |
+
public static function is_column_meta( $id = '' )
|
2097 |
{
|
2098 |
if ( strpos($id, 'column-meta-') !== false )
|
2099 |
return true;
|
2100 |
+
|
2101 |
return false;
|
2102 |
}
|
2103 |
+
|
2104 |
/**
|
2105 |
* Get the posttype from columnname
|
2106 |
*
|
2107 |
* @since 1.3.1
|
2108 |
*/
|
2109 |
+
public static function get_posttype_by_postcount_column( $id = '' )
|
2110 |
{
|
2111 |
+
if ( strpos($id, 'column-user_postcount-') !== false )
|
2112 |
return str_replace('column-user_postcount-', '', $id);
|
2113 |
+
|
2114 |
return false;
|
2115 |
}
|
2116 |
+
|
2117 |
/**
|
2118 |
* Get column value of post attachments
|
2119 |
*
|
2120 |
* @since 1.2.1
|
2121 |
*/
|
2122 |
+
public static function get_attachment_ids( $post_id )
|
2123 |
{
|
2124 |
return get_posts(array(
|
2125 |
'post_type' => 'attachment',
|
2129 |
'fields' => 'ids'
|
2130 |
));
|
2131 |
}
|
2132 |
+
|
2133 |
/**
|
2134 |
* Strip tags and trim
|
2135 |
*
|
2136 |
* @since 1.3
|
2137 |
*/
|
2138 |
+
public static function strip_trim($string)
|
2139 |
{
|
2140 |
return trim(strip_tags($string));
|
2141 |
}
|
2142 |
+
|
2143 |
/**
|
2144 |
* Admin body class
|
2145 |
*
|
2146 |
* @since 1.4
|
2147 |
*/
|
2148 |
+
function admin_class( $classes )
|
2149 |
+
{
|
2150 |
global $current_screen;
|
2151 |
+
|
2152 |
// we dont need the 'edit-' part
|
2153 |
$screen = str_replace('edit-', '', $current_screen->id);
|
2154 |
+
|
2155 |
// media library exception
|
2156 |
if ( $current_screen->base == 'upload' && $current_screen->id == 'upload' ) {
|
2157 |
$screen = 'media';
|
2158 |
}
|
2159 |
+
|
2160 |
// link exception
|
2161 |
if ( $current_screen->base == 'link-manager' && $current_screen->id == 'link-manager' ) {
|
2162 |
$screen = 'links';
|
2163 |
}
|
2164 |
|
2165 |
// loop the available types
|
2166 |
+
foreach ( $this->get_types() as $type => $label ) {
|
2167 |
+
|
2168 |
// match against screen or wp-screen
|
2169 |
if ( $type == $screen || $type == "wp-{$screen}" )
|
2170 |
$classes .= " cp-{$type}";
|
2173 |
return $classes;
|
2174 |
}
|
2175 |
|
2176 |
+
|
2177 |
/**
|
2178 |
* Admin CSS for Column width
|
2179 |
*
|
2180 |
* @since 1.4
|
2181 |
*/
|
2182 |
+
function admin_css()
|
2183 |
+
{
|
2184 |
$css = '';
|
2185 |
+
|
2186 |
// loop throug the available types...
|
2187 |
foreach ( $this->get_types() as $type ) {
|
2188 |
+
$cols = self::get_stored_columns($type);
|
2189 |
if ( $cols ) {
|
2190 |
+
|
2191 |
// loop through each available column...
|
2192 |
foreach ( $cols as $col_name => $col ) {
|
2193 |
+
|
2194 |
// and check for stored width and add it to the css
|
2195 |
if (!empty($col['width']) && is_numeric($col['width']) && $col['width'] > 0 ) {
|
2196 |
$css .= ".cp-{$type} .wrap table th.column-{$col_name} { width: {$col['width']}% !important; }";
|
2198 |
}
|
2199 |
}
|
2200 |
}
|
2201 |
+
|
2202 |
echo "<style type='text/css'>{$css}</style>";
|
2203 |
}
|
2204 |
+
|
2205 |
/**
|
2206 |
* Ajax activation
|
2207 |
*
|
2212 |
// keys
|
2213 |
$key = $_POST['key'];
|
2214 |
$type = $_POST['type'];
|
2215 |
+
|
2216 |
$licence = new cpac_licence( $type );
|
2217 |
+
|
2218 |
// update key
|
2219 |
if ( $key == 'remove' ) {
|
2220 |
$licence->remove_license_key();
|
2221 |
}
|
2222 |
+
|
2223 |
// set license key
|
2224 |
elseif ( $licence->check_remote_key( $key ) ) {
|
2225 |
+
|
2226 |
// set key
|
2227 |
$licence->set_license_key( $key );
|
2228 |
+
|
2229 |
// returned masked key
|
2230 |
echo json_encode( $licence->get_masked_license_key() );
|
2231 |
}
|
2232 |
|
2233 |
exit;
|
2234 |
}
|
2235 |
+
|
2236 |
/**
|
2237 |
* Add help tabs
|
2238 |
*
|
2239 |
* @since 1.3
|
2240 |
*/
|
2241 |
+
public function help_tabs($page)
|
2242 |
+
{
|
2243 |
$screen = get_current_screen();
|
2244 |
|
2245 |
if ( $screen->id != $this->admin_page || ! method_exists($screen,'add_help_tab') )
|
2246 |
return;
|
2247 |
+
|
2248 |
$admin_url = get_admin_url();
|
2249 |
+
|
2250 |
// add help content
|
2251 |
$tabs = array(
|
2252 |
array(
|
2255 |
<h5>Codepress Admin Columns</h5>
|
2256 |
<p>
|
2257 |
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.
|
2258 |
+
</p>
|
2259 |
+
|
2260 |
"
|
2261 |
),
|
2262 |
array(
|
2298 |
<li><strong>Post Titles</strong><br/>Value: can be one or more Post ID's (seperated by ',').</li>
|
2299 |
</ul>
|
2300 |
"
|
2301 |
+
)
|
2302 |
);
|
2303 |
+
|
2304 |
foreach ( $tabs as $k => $tab ) {
|
2305 |
+
$screen->add_help_tab(array(
|
2306 |
'id' => 'cpac-tab-'.$k, // unique id
|
2307 |
'title' => $tab['title'], // label
|
2308 |
'content' => $tab['content'], // body
|
2309 |
));
|
2310 |
}
|
2311 |
}
|
2312 |
+
|
2313 |
/**
|
2314 |
* Plugin Settings
|
2315 |
*
|
2316 |
* @since 1.3.1
|
2317 |
*/
|
2318 |
+
private function plugin_settings()
|
2319 |
{
|
2320 |
$class_current_settings = $this->is_menu_type_current('plugin_settings') ? ' current' : ' hidden'; '';
|
2321 |
+
|
2322 |
/** Sortable */
|
2323 |
$masked_key = '';
|
2324 |
$class_sortorder_activate = '';
|
2325 |
$class_sortorder_deactivate = ' hidden';
|
2326 |
+
|
2327 |
// is unlocked
|
2328 |
$licence = new cpac_licence('sortable');
|
2329 |
+
|
2330 |
if ( $licence->is_unlocked() ) {
|
2331 |
$masked_key = $licence->get_masked_license_key('sortable');
|
2332 |
$class_sortorder_activate = ' hidden';
|
2333 |
$class_sortorder_deactivate = '';
|
2334 |
}
|
2335 |
+
|
2336 |
// find out more
|
2337 |
$find_out_more = "<a href='{$this->codepress_url}/sortorder-addon/' class='button-primary alignright' target='_blank'>".__('find out more', CPAC_TEXTDOMAIN)." »</a>";
|
2338 |
+
|
2339 |
// info box
|
2340 |
$sortable_tooltip = "
|
2341 |
<p>".__('This will make all of the new columns support sorting', CPAC_TEXTDOMAIN).".</p>
|
2342 |
<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>
|
2343 |
<p>".__('Perfect for sorting your articles, media files, comments, links and users', CPAC_TEXTDOMAIN).".</p>
|
2344 |
+
<p class='description'>".__('(columns that are added by other plugins are not supported)', CPAC_TEXTDOMAIN).".</p>
|
2345 |
<img src='" . CPAC_URL.'/assets/images/addon_sortable_1.png' . "' alt='' />
|
2346 |
{$find_out_more}
|
2347 |
";
|
2348 |
+
|
2349 |
+
// addons
|
2350 |
$addons = "
|
2351 |
<tr>
|
2352 |
<td colspan='2'>
|
2393 |
</td>
|
2394 |
<td class='activation_more'>{$find_out_more}</td>
|
2395 |
</tr><!-- #cpac-activation-sortable -->
|
2396 |
+
</tbody>
|
2397 |
</table>
|
2398 |
<div class='addon-translation-string hidden'>
|
2399 |
<span class='tstring-fill-in'>" . __('Enter your activation code', CPAC_TEXTDOMAIN) . "</span>
|
2402 |
</td>
|
2403 |
</tr>
|
2404 |
";
|
2405 |
+
|
2406 |
// general options
|
2407 |
$general_options = "
|
2408 |
<!--
|
2412 |
<ul class='cpac-options'>
|
2413 |
<li>
|
2414 |
<div class='cpac-option-label'>Thumbnail size</div>
|
2415 |
+
<div class='cpac-option-inputs'>
|
2416 |
<input type='text' id='thumbnail_size_w' class='small-text' name='cpac_options[settings][thumb_width]' value='80'/>
|
2417 |
<label for='thumbnail_size_w'>Width</label>
|
2418 |
+
<br/>
|
2419 |
<input type='text' id='thumbnail_size_h' class='small-text' name='cpac_options[settings][thumb_height]' value='80'/>
|
2420 |
<label for='thumbnail_size_h'>Height</label>
|
2421 |
</div>
|
2422 |
</li>
|
2423 |
<li>
|
2424 |
<div class='cpac-option-label'>Excerpt length</div>
|
2425 |
+
<div class='cpac-option-inputs'>
|
2426 |
+
|
2427 |
<input type='text' id='excerpt_length' class='small-text' name='cpac_options[settings][excerpt_length]' value='15'/>
|
2428 |
<label for='excerpt_length'>Number of words</label>
|
2429 |
</div>
|
2430 |
</li>
|
2431 |
+
</ul>
|
2432 |
</td>
|
2433 |
</tr>
|
2434 |
-->
|
2435 |
";
|
2436 |
+
|
2437 |
// settings
|
2438 |
$row = "
|
2439 |
<tr id='cpac-box-plugin_settings' valign='top' class='cpac-box-row {$class_current_settings}'>
|
2440 |
<td colspan='2'>
|
2441 |
<table class='nopadding'>
|
2442 |
+
{$addons}
|
2443 |
{$general_options}
|
2444 |
</table>
|
2445 |
</td>
|
2446 |
</tr><!-- #cpac-box-plugin_settings -->
|
2447 |
";
|
2448 |
+
|
2449 |
return $row;
|
2450 |
}
|
2451 |
+
|
2452 |
/**
|
2453 |
* Get post count
|
2454 |
*
|
2457 |
public static function get_post_count( $post_type, $user_id )
|
2458 |
{
|
2459 |
global $wpdb;
|
2460 |
+
|
2461 |
if ( ! post_type_exists($post_type) || empty($user_id) )
|
2462 |
return false;
|
2463 |
+
|
2464 |
$sql = "
|
2465 |
SELECT COUNT(ID)
|
2466 |
FROM {$wpdb->posts}
|
2468 |
AND post_author = %d
|
2469 |
AND post_type = %s
|
2470 |
";
|
2471 |
+
|
2472 |
return $wpdb->get_var( $wpdb->prepare($sql, $user_id, $post_type) );
|
2473 |
}
|
2474 |
+
|
2475 |
/**
|
2476 |
* Settings Page Template.
|
2477 |
*
|
2478 |
* This function in conjunction with others uses the WordPress
|
2479 |
* Settings API to create a settings page where users can adjust
|
2480 |
+
* the behaviour of this plugin.
|
2481 |
*
|
2482 |
* @since 1.0
|
2483 |
*/
|
2484 |
+
public function plugin_settings_page()
|
2485 |
{
|
2486 |
// loop through post types
|
2487 |
$rows = '';
|
2488 |
foreach ( $this->get_types() as $type ) {
|
2489 |
+
|
2490 |
// post type label
|
2491 |
$label = $this->get_singular_name($type);
|
2492 |
+
|
2493 |
// id
|
2494 |
+
$id = $this->sanitize_string($type);
|
2495 |
+
|
2496 |
// build draggable boxes
|
2497 |
$boxes = $this->get_column_boxes($type);
|
2498 |
|
2499 |
// class
|
2500 |
$class = $this->is_menu_type_current($type) ? ' current' : ' hidden';
|
2501 |
+
|
2502 |
$rows .= "
|
2503 |
<tr id='cpac-box-{$id}' valign='top' class='cpac-box-row{$class}'>
|
2504 |
<th class='cpac_post_type' scope='row'>
|
2506 |
</th>
|
2507 |
<td>
|
2508 |
<h3 class='cpac_post_type hidden'>{$label}</h3>
|
2509 |
+
{$boxes}
|
2510 |
</td>
|
2511 |
</tr>
|
2512 |
";
|
2513 |
}
|
2514 |
+
|
2515 |
// General Setttings
|
2516 |
$general_settings = $this->plugin_settings();
|
2517 |
+
|
2518 |
// Post Type Menu
|
2519 |
$menu = $this->get_menu();
|
2520 |
+
|
2521 |
// Help screen message
|
2522 |
$help_text = '';
|
2523 |
if ( version_compare( get_bloginfo('version'), '3.2', '>' ) )
|
2524 |
$help_text = '<p>'.__('You will find a short overview at the <strong>Help</strong> section in the top-right screen.', CPAC_TEXTDOMAIN).'</p>';
|
2525 |
+
|
2526 |
// find out more
|
2527 |
$find_out_more = "<a href='{$this->codepress_url}/sortorder-addon/' class='alignright green' target='_blank'>".__('find out more', CPAC_TEXTDOMAIN)." »</a>";
|
2528 |
+
|
2529 |
?>
|
2530 |
<div id="cpac" class="wrap">
|
2531 |
<?php screen_icon(CPAC_SLUG) ?>
|
2532 |
<h2><?php _e('Codepress Admin Columns', CPAC_TEXTDOMAIN); ?></h2>
|
2533 |
<?php echo $menu ?>
|
2534 |
+
|
2535 |
<div class="postbox-container cpac-col-right">
|
2536 |
+
<div class="metabox-holder">
|
2537 |
+
<div class="meta-box-sortables">
|
2538 |
+
|
2539 |
<div id="addons-cpac-settings" class="postbox">
|
2540 |
<div title="Click to toggle" class="handlediv"><br></div>
|
2541 |
<h3 class="hndle">
|
2548 |
<?php echo $find_out_more ?>
|
2549 |
</div>
|
2550 |
</div><!-- addons-cpac-settings -->
|
2551 |
+
|
2552 |
<div id="likethisplugin-cpac-settings" class="postbox">
|
2553 |
<div title="Click to toggle" class="handlediv"><br></div>
|
2554 |
<h3 class="hndle">
|
2558 |
<p><?php _e('Why not do any or all of the following', CPAC_TEXTDOMAIN) ?>:</p>
|
2559 |
<ul>
|
2560 |
<li><a href="<?php echo $this->plugins_url ?>"><?php _e('Give it a 5 star rating on WordPress.org.', CPAC_TEXTDOMAIN) ?></a></li>
|
2561 |
+
<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>
|
2562 |
<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>
|
2563 |
+
</ul>
|
2564 |
</div>
|
2565 |
</div><!-- likethisplugin-cpac-settings -->
|
2566 |
+
|
2567 |
<div id="latest-news-cpac-settings" class="postbox">
|
2568 |
<div title="Click to toggle" class="handlediv"><br></div>
|
2569 |
<h3 class="hndle">
|
2570 |
<span><?php _e('Follow us', CPAC_TEXTDOMAIN) ?></span>
|
2571 |
</h3>
|
2572 |
+
<div class="inside">
|
2573 |
<ul>
|
2574 |
<li class="twitter"><a href="http://twitter.com/codepressNL"><?php _e('Follow Codepress on Twitter.', CPAC_TEXTDOMAIN) ?></a></li>
|
2575 |
<li class="facebook"><a href="https://www.facebook.com/codepressNL"><?php _e('Like Codepress on Facebook.', CPAC_TEXTDOMAIN) ?></a></li>
|
2576 |
+
|
2577 |
+
</ul>
|
2578 |
</div>
|
2579 |
</div><!-- latest-news-cpac-settings -->
|
2580 |
+
|
2581 |
<div id="side-cpac-settings" class="postbox">
|
2582 |
<div title="Click to toggle" class="handlediv"><br></div>
|
2583 |
<h3 class="hndle">
|
2584 |
<span><?php _e('Need support?', CPAC_TEXTDOMAIN) ?></span>
|
2585 |
</h3>
|
2586 |
+
<div class="inside">
|
2587 |
<?php echo $help_text ?>
|
2588 |
<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>
|
2589 |
<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>
|
2590 |
</div>
|
2591 |
</div><!-- side-cpac-settings -->
|
2592 |
+
|
2593 |
</div>
|
2594 |
</div>
|
2595 |
</div><!-- .postbox-container -->
|
2596 |
+
|
2597 |
<div class="postbox-container cpac-col-left">
|
2598 |
+
<div class="metabox-holder">
|
2599 |
<div class="meta-box-sortables">
|
2600 |
+
|
2601 |
<div id="general-cpac-settings" class="postbox">
|
2602 |
<div title="Click to toggle" class="handlediv"><br></div>
|
2603 |
<h3 class="hndle">
|
2605 |
</h3>
|
2606 |
<div class="inside">
|
2607 |
<form method="post" action="options.php">
|
2608 |
+
|
2609 |
<?php settings_fields( 'cpac-settings-group' ); ?>
|
2610 |
+
|
2611 |
<table class="form-table">
|
2612 |
<!-- columns -->
|
2613 |
+
<?php echo $rows; ?>
|
2614 |
+
|
2615 |
<!-- activation -->
|
2616 |
<?php echo $general_settings; ?>
|
2617 |
+
|
2618 |
<tr class="bottom" valign="top">
|
2619 |
<th scope="row"></th>
|
2620 |
<td>
|
2622 |
<input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
|
2623 |
</p>
|
2624 |
</td>
|
2625 |
+
</tr>
|
2626 |
+
</table>
|
2627 |
+
</form>
|
2628 |
+
</div>
|
2629 |
</div><!-- general-settings -->
|
2630 |
+
|
2631 |
<div id="restore-cpac-settings" class="postbox">
|
2632 |
<div title="Click to toggle" class="handlediv"><br></div>
|
2633 |
<h3 class="hndle">
|
2634 |
<span><?php _e('Restore defaults', CPAC_TEXTDOMAIN) ?></span>
|
2635 |
</h3>
|
2636 |
<div class="inside">
|
2637 |
+
<form method="post" action="">
|
2638 |
<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); ?>');" />
|
2639 |
</form>
|
2640 |
<p class="description"><?php _e('This will delete all column settings and restore the default settings.', CPAC_TEXTDOMAIN); ?></p>
|
2641 |
</div>
|
2642 |
</div><!-- restore-cpac-settings -->
|
2643 |
+
|
2644 |
</div>
|
2645 |
</div>
|
2646 |
+
</div><!-- .postbox-container -->
|
2647 |
</div>
|
2648 |
<?php
|
2649 |
}
|
readme.txt
CHANGED
@@ -4,15 +4,15 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
|
|
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.
|
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 |
|
@@ -34,7 +34,7 @@ The following custom columns are added:
|
|
34 |
* Roles
|
35 |
* Status
|
36 |
* Number of Attachments
|
37 |
-
* Last Modified
|
38 |
* Comment count
|
39 |
* Before More Tag Content
|
40 |
* Custom Fields
|
@@ -113,7 +113,7 @@ By default WordPress let's you only sort by Title, Date, Comments and Author. Th
|
|
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 |
|
@@ -164,7 +164,7 @@ $my_width = 194;
|
|
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 |
?>
|
@@ -218,17 +218,17 @@ function my_custom_field_value( $value, $internal_field_key, $custom_field, $typ
|
|
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 |
?>
|
@@ -246,6 +246,9 @@ add_filter( 'cpac_get_column_value_custom_field', 'my_custom_field_value', 10, 5
|
|
246 |
|
247 |
== Changelog ==
|
248 |
|
|
|
|
|
|
|
249 |
= 1.4.8 =
|
250 |
* fixed bug: removed acf posttype placed by Advaced Custom Fields from settings menu
|
251 |
* fixed bug: removed bbPress posttypes topic, forum and reply from admin columns settings menu
|
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.9
|
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 |
|
34 |
* Roles
|
35 |
* Status
|
36 |
* Number of Attachments
|
37 |
+
* Last Modified
|
38 |
* Comment count
|
39 |
* Before More Tag Content
|
40 |
* Custom Fields
|
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 |
|
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 |
?>
|
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 |
?>
|
246 |
|
247 |
== Changelog ==
|
248 |
|
249 |
+
= 1.4.9
|
250 |
+
* fixed bug: thirdparty columns that were previous loaded through load-edit.php will now use do_action( 'cpac-get-default-columns-{$type}' )
|
251 |
+
|
252 |
= 1.4.8 =
|
253 |
* fixed bug: removed acf posttype placed by Advaced Custom Fields from settings menu
|
254 |
* fixed bug: removed bbPress posttypes topic, forum and reply from admin columns settings menu
|