Changeset 638877
- Timestamp:
- 12/13/2012 10:25:08 PM (13 years ago)
- Location:
- codepress-admin-columns
- Files:
-
- 78 added
- 1 deleted
- 10 edited
-
tags/1.4.9 (added)
-
tags/1.4.9/assets (added)
-
tags/1.4.9/assets/css (added)
-
tags/1.4.9/assets/css/admin-column.css (added)
-
tags/1.4.9/assets/css/column.css (added)
-
tags/1.4.9/assets/images (added)
-
tags/1.4.9/assets/images/addon_sortable_1.png (added)
-
tags/1.4.9/assets/images/arrows.png (added)
-
tags/1.4.9/assets/images/checkbox.png (added)
-
tags/1.4.9/assets/images/checkmark.png (added)
-
tags/1.4.9/assets/images/checkmark_single.png (added)
-
tags/1.4.9/assets/images/comment_edit.png (added)
-
tags/1.4.9/assets/images/cross.png (added)
-
tags/1.4.9/assets/images/facebook.png (added)
-
tags/1.4.9/assets/images/icon.png (added)
-
tags/1.4.9/assets/images/import_export.png (added)
-
tags/1.4.9/assets/images/information.png (added)
-
tags/1.4.9/assets/images/loading.gif (added)
-
tags/1.4.9/assets/images/no.png (added)
-
tags/1.4.9/assets/images/reorder.png (added)
-
tags/1.4.9/assets/images/reorder_arrow.png (added)
-
tags/1.4.9/assets/images/settings.png (added)
-
tags/1.4.9/assets/images/sort.png (added)
-
tags/1.4.9/assets/images/square.png (added)
-
tags/1.4.9/assets/images/trash.png (added)
-
tags/1.4.9/assets/images/twitter.png (added)
-
tags/1.4.9/assets/js (added)
-
tags/1.4.9/assets/js/admin-column.js (added)
-
tags/1.4.9/assets/js/jquery.qtip.js (added)
-
tags/1.4.9/assets/ui-theme (added)
-
tags/1.4.9/assets/ui-theme/images (added)
-
tags/1.4.9/assets/ui-theme/images/ui-bg_flat_0_aaaaaa_40x100.png (added)
-
tags/1.4.9/assets/ui-theme/images/ui-bg_flat_75_ffffff_40x100.png (added)
-
tags/1.4.9/assets/ui-theme/images/ui-bg_glass_55_fbf9ee_1x400.png (added)
-
tags/1.4.9/assets/ui-theme/images/ui-bg_glass_65_ffffff_1x400.png (added)
-
tags/1.4.9/assets/ui-theme/images/ui-bg_glass_75_dadada_1x400.png (added)
-
tags/1.4.9/assets/ui-theme/images/ui-bg_glass_75_e6e6e6_1x400.png (added)
-
tags/1.4.9/assets/ui-theme/images/ui-bg_glass_95_fef1ec_1x400.png (added)
-
tags/1.4.9/assets/ui-theme/images/ui-bg_highlight-soft_75_cccccc_1x100.png (added)
-
tags/1.4.9/assets/ui-theme/images/ui-icons_222222_256x240.png (added)
-
tags/1.4.9/assets/ui-theme/images/ui-icons_2e83ff_256x240.png (added)
-
tags/1.4.9/assets/ui-theme/images/ui-icons_454545_256x240.png (added)
-
tags/1.4.9/assets/ui-theme/images/ui-icons_888888_256x240.png (added)
-
tags/1.4.9/assets/ui-theme/images/ui-icons_cd0a0a_256x240.png (added)
-
tags/1.4.9/assets/ui-theme/jquery-ui-1.8.18.custom.css (added)
-
tags/1.4.9/classes (added)
-
tags/1.4.9/classes/license.php (added)
-
tags/1.4.9/classes/sortable.php (added)
-
tags/1.4.9/classes/third_party.php (added)
-
tags/1.4.9/classes/values (added)
-
tags/1.4.9/classes/values.php (added)
-
tags/1.4.9/classes/values/comments.php (added)
-
tags/1.4.9/classes/values/link.php (added)
-
tags/1.4.9/classes/values/media.php (added)
-
tags/1.4.9/classes/values/posts.php (added)
-
tags/1.4.9/classes/values/users.php (added)
-
tags/1.4.9/codepress-admin-columns.php (added)
-
tags/1.4.9/languages (added)
-
tags/1.4.9/languages/codepress-admin-columns-da_DK.mo (added)
-
tags/1.4.9/languages/codepress-admin-columns-da_DK.po (added)
-
tags/1.4.9/languages/codepress-admin-columns-de_DE.mo (added)
-
tags/1.4.9/languages/codepress-admin-columns-de_DE.po (added)
-
tags/1.4.9/languages/codepress-admin-columns-fr_FR.mo (added)
-
tags/1.4.9/languages/codepress-admin-columns-fr_FR.po (added)
-
tags/1.4.9/languages/codepress-admin-columns-nl_NL.mo (added)
-
tags/1.4.9/languages/codepress-admin-columns-nl_NL.po (added)
-
tags/1.4.9/languages/codepress-admin-columns-pl_PL.mo (added)
-
tags/1.4.9/languages/codepress-admin-columns-pl_PL.po (added)
-
tags/1.4.9/languages/codepress-admin-columns.po (added)
-
tags/1.4.9/readme.txt (added)
-
tags/1.4.9/screenshot-1.png (added)
-
tags/1.4.9/screenshot-2.png (added)
-
tags/1.4.9/screenshot-3.png (added)
-
tags/1.4.9/screenshot-4.png (added)
-
tags/1.4.9/screenshot-5.png (added)
-
tags/1.4.9/screenshot-6.png (added)
-
tags/1.4.9/screenshot-7.png (added)
-
trunk/classes/license.php (modified) (8 diffs)
-
trunk/classes/sortable.php (modified) (76 diffs)
-
trunk/classes/third_party.php (added)
-
trunk/classes/utility.php (deleted)
-
trunk/classes/values.php (modified) (31 diffs)
-
trunk/classes/values/comments.php (modified) (9 diffs)
-
trunk/classes/values/link.php (modified) (5 diffs)
-
trunk/classes/values/media.php (modified) (9 diffs)
-
trunk/classes/values/posts.php (modified) (16 diffs)
-
trunk/classes/values/users.php (modified) (6 diffs)
-
trunk/codepress-admin-columns.php (modified) (161 diffs)
-
trunk/readme.txt (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
codepress-admin-columns/trunk/classes/license.php
r637684 r638877 5 5 /** 6 6 * The type of licence to check or activate 7 * 7 * 8 8 * @var string $type 9 9 */ 10 10 public $type; 11 12 public function __construct($type) 11 12 public function __construct($type) 13 13 { 14 14 $this->type = $type; 15 15 } 16 16 17 17 /** 18 18 * Unlocks … … 23 23 { 24 24 return preg_match( '/^[a-f0-9]{40}$/i', $this->get_license_key( $this->type ) ); 25 } 26 25 } 26 27 27 /** 28 28 * Check license key with API … … 31 31 */ 32 32 public function check_remote_key( $key ) 33 { 33 { 34 34 if ( empty( $key ) ) { 35 35 return false; 36 36 } 37 38 // check key with remote API 39 $response = wp_remote_post( 'http://www.codepress.nl/', array( 37 38 // check key with remote API 39 $response = wp_remote_post( 'http://www.codepress.nl/', array( 40 40 'body' => array( 41 41 'api' => 'addon', 42 42 'key' => $key, 43 'type' => $this->type 43 'type' => $this->type 44 44 ) 45 45 )); … … 49 49 return true; 50 50 } 51 51 52 52 return false; 53 53 } 54 54 55 55 /** 56 56 * Set masked license key … … 58 58 * @since 1.3.1 59 59 */ 60 public function get_masked_license_key() 60 public function get_masked_license_key() 61 61 { 62 return '**************************'.substr( $this->get_license_key(), -4 ); 63 } 64 62 return '**************************'.substr( $this->get_license_key(), -4 ); 63 } 64 65 65 /** 66 66 * Get license key … … 72 72 return get_option("cpac_{$this->type}_ac"); 73 73 } 74 74 75 75 /** 76 76 * Set license key … … 79 79 */ 80 80 public function set_license_key( $key ) 81 { 81 { 82 82 update_option( "cpac_{$this->type}_ac", trim( $key ) ); 83 83 } 84 84 85 85 /** 86 86 * Remove license key … … 92 92 delete_option( "cpac_{$this->type}_ac" ); 93 93 delete_transient("cpac_{$this->type}_trnsnt"); 94 } 94 } 95 95 } -
codepress-admin-columns/trunk/classes/sortable.php
r637026 r638877 8 8 */ 9 9 class Codepress_Sortable_Columns extends Codepress_Admin_Columns 10 { 11 private $post_types, 12 $unlocked, 10 { 11 private $post_types, 12 $unlocked, 13 13 $show_all_results, 14 14 $current_user_id; 15 15 16 16 /** 17 17 * Constructor … … 23 23 add_action( 'wp_loaded', array( $this, 'init') ); 24 24 } 25 25 26 26 /** 27 27 * Initialize … … 32 32 { 33 33 $licence = new cpac_licence('sortable'); 34 34 35 35 // vars 36 36 $this->unlocked = $licence->is_unlocked(); … … 38 38 $this->show_all_results = false; 39 39 $this->current_user_id = get_current_user_id(); 40 40 41 41 // init sorting 42 42 add_action( 'admin_init', array( $this, 'register_sortable_columns' ) ); 43 43 44 44 // init filtering 45 45 add_action( 'admin_init', array( $this, 'register_filtering_columns' ) ); 46 46 47 47 // handle requests for sorting columns 48 48 add_filter( 'request', array( $this, 'handle_requests_orderby_column'), 1 ); … … 50 50 add_action( 'admin_init', array( $this, 'handle_requests_orderby_links_column'), 1 ); 51 51 add_action( 'admin_init', array( $this, 'handle_requests_orderby_comments_column'), 1 ); 52 } 53 52 } 53 54 54 /** 55 55 * Register sortable columns … … 63 63 if ( ! $this->unlocked ) 64 64 return false; 65 65 66 66 /** Posts */ 67 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 68 add_filter( "manage_edit-{$post_type}_sortable_columns", array($this, 'callback_add_sortable_posts_column')); 69 } 70 71 71 /** Users */ 72 72 add_filter( "manage_users_sortable_columns", array($this, 'callback_add_sortable_users_column')); 73 73 74 74 /** Media */ 75 75 add_filter( "manage_upload_sortable_columns", array($this, 'callback_add_sortable_media_column')); 76 76 77 77 /** Links */ 78 78 add_filter( "manage_link-manager_sortable_columns", array($this, 'callback_add_sortable_links_column')); 79 79 80 80 /** Comments */ 81 81 add_filter( "manage_edit-comments_sortable_columns", array($this, 'callback_add_sortable_comments_column')); 82 82 } 83 83 84 84 /** 85 85 * Callback add Posts sortable column … … 87 87 * @since 1.0 88 88 */ 89 public function callback_add_sortable_posts_column($columns) 89 public function callback_add_sortable_posts_column($columns) 90 90 { 91 91 global $post_type; 92 92 93 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 94 if ( is_array($post_type) ) 95 95 $post_type = $_REQUEST['post_type']; 96 96 97 97 return $this->add_managed_sortable_columns($post_type, $columns); 98 98 } … … 103 103 * @since 1.1 104 104 */ 105 public function callback_add_sortable_users_column($columns) 105 public function callback_add_sortable_users_column($columns) 106 106 { 107 107 return $this->add_managed_sortable_columns('wp-users', $columns); 108 108 } 109 109 110 110 /** 111 111 * Callback add Media sortable column … … 113 113 * @since 1.3 114 114 */ 115 public function callback_add_sortable_media_column($columns) 115 public function callback_add_sortable_media_column($columns) 116 116 { 117 117 return $this->add_managed_sortable_columns('wp-media', $columns); 118 118 } 119 119 120 120 /** 121 121 * Callback add Links sortable column … … 123 123 * @since 1.3.1 124 124 */ 125 public function callback_add_sortable_links_column($columns) 125 public function callback_add_sortable_links_column($columns) 126 126 { 127 127 return $this->add_managed_sortable_columns('wp-links', $columns); 128 128 } 129 129 130 130 /** 131 131 * Callback add Comments sortable column … … 133 133 * @since 1.3.1 134 134 */ 135 public function callback_add_sortable_comments_column($columns) 135 public function callback_add_sortable_comments_column($columns) 136 136 { 137 137 return $this->add_managed_sortable_columns('wp-comments', $columns); 138 138 } 139 139 140 140 /** 141 141 * Add managed sortable columns by Type … … 143 143 * @since 1.1 144 144 */ 145 private function add_managed_sortable_columns( $type = 'post', $columns ) 146 { 145 private function add_managed_sortable_columns( $type = 'post', $columns ) 146 { 147 147 $display_columns = $this->get_merged_columns($type); 148 148 149 149 if ( ! $display_columns ) 150 150 return $columns; 151 151 152 152 foreach ( $display_columns as $id => $vars ) { 153 if ( isset($vars['options']['sortorder']) && $vars['options']['sortorder'] == 'on' ){ 154 153 if ( isset($vars['options']['sortorder']) && $vars['options']['sortorder'] == 'on' ){ 154 155 155 // register format 156 $columns[$id] = $this->sanitize_string($vars['label']); 156 $columns[$id] = $this->sanitize_string($vars['label']); 157 157 } 158 } 158 } 159 159 160 160 return $columns; 161 161 } 162 162 163 163 /** 164 164 * Admin requests for orderby column … … 168 168 * @since 1.0 169 169 */ 170 public function handle_requests_orderby_column( $vars ) 170 public function handle_requests_orderby_column( $vars ) 171 171 { 172 172 /** Users */ 173 // You would expect to see get_orderby_users_vars(), but sorting for 173 // You would expect to see get_orderby_users_vars(), but sorting for 174 174 // users is handled through a different filter. Not 'request', but 'pre_user_query'. 175 175 // See handle_requests_orderby_users_column(). 176 176 177 177 /** Media */ 178 178 if ( $this->request_uri_is('upload') ) { 179 179 $vars = $this->get_orderby_media_vars($vars); 180 180 } 181 181 182 182 /** Posts */ 183 183 elseif ( !empty($vars['post_type']) ) { 184 $vars = $this->get_orderby_posts_vars($vars); 185 } 186 184 $vars = $this->get_orderby_posts_vars($vars); 185 } 186 187 187 return $vars; 188 } 189 188 } 189 190 190 /** 191 191 * Orderby Users column … … 194 194 */ 195 195 public function handle_requests_orderby_users_column($user_query) 196 { 196 { 197 197 // query vars 198 $vars = $user_query->query_vars; 199 198 $vars = $user_query->query_vars; 199 200 200 // Column 201 201 $column = $this->get_orderby_type( $vars['orderby'], 'wp-users' ); 202 202 203 203 if ( empty($column) ) 204 return $user_query; 205 204 return $user_query; 205 206 206 // id 207 207 $type = $id = key($column); 208 208 209 209 // Check for user custom fields: column-meta-[customfieldname] 210 210 if ( Codepress_Admin_Columns::is_column_meta($type) ) 211 211 $type = 'column-user-meta'; 212 212 213 213 // Check for post count: column-user_postcount-[posttype] 214 214 if ( Codepress_Admin_Columns::get_posttype_by_postcount_column($type) ) 215 215 $type = 'column-user_postcount'; 216 216 217 217 // var 218 $cusers = array(); 218 $cusers = array(); 219 219 switch( $type ) : 220 220 221 221 case 'column-user_id': 222 222 $user_query->query_orderby = "ORDER BY ID {$user_query->query_vars['order']}"; 223 223 $user_query->query_vars['orderby'] = 'ID'; 224 224 break; 225 226 case 'column-user_registered': 225 226 case 'column-user_registered': 227 227 $user_query->query_orderby = "ORDER BY user_registered {$user_query->query_vars['order']}"; 228 228 $user_query->query_vars['orderby'] = 'registered'; 229 229 break; 230 230 231 231 case 'column-nickname' : 232 232 $sort_flag = SORT_REGULAR; … … 235 235 $cusers[$u->ID] = $this->prepare_sort_string_value($u->nickname); 236 236 } 237 } 238 break; 239 237 } 238 break; 239 240 240 case 'column-first_name' : 241 241 $sort_flag = SORT_REGULAR; … … 244 244 $cusers[$u->ID] = $this->prepare_sort_string_value($u->first_name); 245 245 } 246 } 247 break; 248 246 } 247 break; 248 249 249 case 'column-last_name' : 250 250 $sort_flag = SORT_REGULAR; … … 253 253 $cusers[$u->ID] = $this->prepare_sort_string_value($u->last_name); 254 254 } 255 } 256 break; 257 255 } 256 break; 257 258 258 case 'column-user_url' : 259 259 $sort_flag = SORT_REGULAR; … … 262 262 $cusers[$u->ID] = $this->prepare_sort_string_value($u->user_url); 263 263 } 264 } 265 break; 266 264 } 265 break; 266 267 267 case 'column-user_description' : 268 268 $sort_flag = SORT_REGULAR; … … 271 271 $cusers[$u->ID] = $this->prepare_sort_string_value($u->user_description); 272 272 } 273 } 274 break; 275 276 case 'column-user_postcount' : 273 } 274 break; 275 276 case 'column-user_postcount' : 277 277 $post_type = Codepress_Admin_Columns::get_posttype_by_postcount_column($id); 278 278 if ( $post_type ) { … … 281 281 $count = Codepress_Admin_Columns::get_post_count( $post_type, $u->ID ); 282 282 $cusers[$u->ID] = $this->prepare_sort_string_value($count); 283 } 284 } 285 break; 286 287 case 'column-user-meta' : 283 } 284 } 285 break; 286 287 case 'column-user-meta' : 288 288 $field = $column[$id]['field']; 289 289 if ( $field ) { 290 290 291 291 // order numeric or string 292 292 $sort_flag = SORT_REGULAR; … … 294 294 $sort_flag = SORT_NUMERIC; 295 295 } 296 296 297 297 // sort by metavalue 298 298 foreach ( $this->get_users_data() as $u ) { 299 299 $value = get_metadata('user', $u->ID, $field, true); 300 300 $cusers[$u->ID] = $this->prepare_sort_string_value($value); 301 } 302 } 303 break; 304 301 } 302 } 303 break; 304 305 305 /** native WP columns */ 306 306 307 307 // role column 308 308 case 'role' : … … 314 314 } 315 315 } 316 break; 317 318 endswitch; 319 316 break; 317 318 endswitch; 319 320 320 if ( isset($sort_flag) ) { 321 321 $user_query = $this->get_users_query_vars( $user_query, $cusers, $sort_flag ); 322 322 } 323 323 324 324 return $user_query; 325 325 } 326 326 327 327 /** 328 328 * Orderby Links column 329 329 * 330 * Makes use of filter 'get_bookmarks' from bookmark.php to change the result set of the links 330 * Makes use of filter 'get_bookmarks' from bookmark.php to change the result set of the links 331 331 * 332 332 * @since 1.3.1 … … 337 337 if ( $this->request_uri_is('link-manager') ) 338 338 add_filter( 'get_bookmarks', array( $this, 'callback_requests_orderby_links_column'), 10, 2); 339 } 340 339 } 340 341 341 /** 342 342 * Orderby Links column 343 * 343 * 344 344 * @since 1.3.1 345 345 */ 346 public function callback_requests_orderby_links_column($results, $vars) 347 { 348 global $wpdb; 349 346 public function callback_requests_orderby_links_column($results, $vars) 347 { 348 global $wpdb; 349 350 350 // apply sorting preference 351 351 $this->apply_sorting_preference( $vars, 'wp-links' ); 352 352 353 353 // Column 354 354 $column = $this->get_orderby_type( $vars['orderby'], 'wp-links' ); 355 355 356 356 if ( empty($column) ) 357 return $results; 358 357 return $results; 358 359 359 // id 360 360 $type = $id = key($column); 361 361 362 362 // var 363 $length = ''; 363 $length = ''; 364 364 switch( $type ) : 365 365 366 366 case 'column-link_id': 367 367 if ( version_compare( get_bloginfo('version'), '3.2', '>' ) ) … … 370 370 $vars['orderby'] = 'id'; 371 371 break; 372 372 373 373 case 'column-owner': 374 374 $vars['orderby'] = 'link_owner'; 375 375 break; 376 376 377 377 case 'column-length': 378 378 $vars['orderby'] = 'length'; 379 379 $length = ", CHAR_LENGTH(link_name) AS length"; 380 380 break; 381 381 382 382 case 'column-target': 383 383 $vars['orderby'] = 'link_target'; 384 384 break; 385 385 386 386 case 'column-description': 387 387 $vars['orderby'] = 'link_description'; 388 388 break; 389 389 390 390 case 'column-notes': 391 391 $vars['orderby'] = 'link_notes'; 392 392 break; 393 393 394 394 case 'column-rss': 395 395 $vars['orderby'] = 'link_rss'; 396 396 break; 397 397 398 398 /** native WP columns */ 399 399 400 400 // Relationship 401 case 'rel': 401 case 'rel': 402 402 $vars['orderby'] = 'link_rel'; 403 403 break; 404 404 405 405 default: 406 $vars['orderby'] = ''; 407 406 $vars['orderby'] = ''; 407 408 408 endswitch; 409 409 410 410 // get bookmarks by orderby vars 411 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']}"; 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 414 $results = $wpdb->get_results($sql); 415 415 416 416 // check for errors 417 417 if( is_wp_error($results) ) … … 421 421 return $results; 422 422 } 423 423 424 424 /** 425 425 * Orderby Comments column 426 * 426 * 427 427 * @since 1.3.1 428 428 */ 429 public function callback_requests_orderby_comments_column($pieces, $ref_comment) 430 { 431 // get query vars 429 public function callback_requests_orderby_comments_column($pieces, $ref_comment) 430 { 431 // get query vars 432 432 $vars = $ref_comment->query_vars; 433 433 434 434 // Column 435 435 $column = $this->get_orderby_type( $vars['orderby'], 'wp-comments' ); 436 436 437 437 if ( empty($column) ) 438 return $pieces; 439 438 return $pieces; 439 440 440 // id 441 441 $type = $id = key($column); 442 442 443 // var 443 // var 444 444 switch( $type ) : 445 445 446 446 case 'column-comment_id': 447 447 $pieces['orderby'] = 'comment_ID'; 448 448 break; 449 449 450 450 case 'column-author_author': 451 451 $pieces['orderby'] = 'comment_author'; 452 452 break; 453 453 454 454 case 'column-author_ip': 455 455 $pieces['orderby'] = 'comment_author_IP'; 456 456 break; 457 457 458 458 case 'column-author_url': 459 459 $pieces['orderby'] = 'comment_author_url'; 460 460 break; 461 461 462 462 case 'column-author_email': 463 463 $pieces['orderby'] = 'comment_author_email'; 464 464 break; 465 465 466 466 case 'column-reply_to': 467 467 break; 468 468 469 469 case 'column-approved': 470 470 $pieces['orderby'] = 'comment_approved'; 471 471 break; 472 472 473 473 case 'column-date': 474 474 $pieces['orderby'] = 'comment_date'; 475 475 break; 476 476 477 477 case 'column-agent': 478 478 $pieces['orderby'] = 'comment_agent'; 479 479 break; 480 480 481 481 case 'column-excerpt': 482 482 $pieces['orderby'] = 'comment_content'; 483 483 break; 484 484 485 485 case 'column-date_gmt': 486 486 break; 487 487 488 488 /** native WP columns */ 489 489 490 490 // Relationship 491 case 'comment': 491 case 'comment': 492 492 $pieces['orderby'] = 'comment_content'; 493 493 break; 494 494 495 495 default: 496 $vars['orderby'] = ''; 497 496 $vars['orderby'] = ''; 497 498 498 endswitch; 499 499 500 500 return $pieces; 501 501 } 502 502 503 503 /** 504 504 * Orderby Comments column … … 507 507 */ 508 508 public function handle_requests_orderby_comments_column() 509 { 509 { 510 510 // fire only when we are in the admins edit-comments 511 511 if ( $this->request_uri_is('edit-comments') ) { … … 513 513 } 514 514 } 515 515 516 516 /** 517 517 * Get sorting vars in User Query Object … … 520 520 */ 521 521 private function get_users_query_vars( $user_query, $sortusers, $sort_flags = SORT_REGULAR ) 522 { 522 { 523 523 global $wpdb; 524 524 525 525 // vars 526 526 $vars = $user_query->query_vars; … … 532 532 arsort($sortusers, $sort_flags); 533 533 534 // alter orderby SQL 535 if ( ! empty ( $sortusers ) ) { 534 // alter orderby SQL 535 if ( ! empty ( $sortusers ) ) { 536 536 $ids = implode(',', array_keys($sortusers)); 537 537 $user_query->query_where .= " AND {$wpdb->prefix}users.ID IN ({$ids})"; 538 538 $user_query->query_orderby = "ORDER BY FIELD({$wpdb->prefix}users.ID,{$ids})"; 539 539 } 540 540 541 541 // cleanup the vars we dont need 542 542 $vars['order'] = ''; 543 543 $vars['orderby'] = ''; 544 544 545 545 // set query vars 546 546 $user_query->query_vars = $vars; 547 547 548 548 return $user_query; 549 } 550 549 } 550 551 551 /** 552 552 * Orderby Media column … … 555 555 */ 556 556 private function get_orderby_media_vars($vars) 557 { 557 { 558 558 // apply sorting preference 559 559 $this->apply_sorting_preference( $vars, 'wp-media' ); 560 560 561 561 // when sorting still isn't set we will just return the requested vars 562 562 if ( empty( $vars['orderby'] ) ) 563 563 return $vars; 564 564 565 565 // Column 566 $column = $this->get_orderby_type( $vars['orderby'], 'wp-media' ); 566 $column = $this->get_orderby_type( $vars['orderby'], 'wp-media' ); 567 567 568 568 if ( empty($column) ) 569 569 return $vars; 570 570 571 571 $id = key($column); 572 572 573 573 // var 574 $cposts = array(); 574 $cposts = array(); 575 575 switch( $id ) : 576 576 577 577 case 'column-mediaid' : 578 578 $vars['orderby'] = 'ID'; 579 579 break; 580 580 581 581 case 'column-width' : 582 582 $sort_flag = SORT_NUMERIC; … … 588 588 } 589 589 break; 590 590 591 591 case 'column-height' : 592 592 $sort_flag = SORT_NUMERIC; … … 598 598 } 599 599 break; 600 600 601 601 case 'column-dimensions' : 602 602 $sort_flag = SORT_NUMERIC; … … 606 606 $width = !empty($meta['width']) ? $meta['width'] : 0; 607 607 $surface = $height*$width; 608 608 609 609 if ( $surface || $this->show_all_results ) 610 610 $cposts[$p->ID] = $surface; 611 611 } 612 612 break; 613 613 614 614 case 'column-caption' : 615 615 $sort_flag = SORT_STRING; … … 620 620 } 621 621 break; 622 622 623 623 case 'column-description' : 624 624 $sort_flag = SORT_STRING; … … 629 629 } 630 630 break; 631 631 632 632 case 'column-mime_type' : 633 633 $sort_flag = SORT_STRING; … … 636 636 $cposts[$p->ID] = $this->prepare_sort_string_value( $p->post_mime_type ); 637 637 } 638 } 639 break; 640 638 } 639 break; 640 641 641 case 'column-file_name' : 642 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); 643 foreach ( $this->get_any_posts_by_posttype('attachment') as $p ) { 644 $meta = get_post_meta($p->ID, '_wp_attached_file', true); 645 645 $file = !empty($meta) ? basename($meta) : ''; 646 646 if ( $file || $this->show_all_results ) { 647 647 $cposts[$p->ID] = $file; 648 648 } 649 } 649 } 650 650 break; 651 651 … … 659 659 } 660 660 break; 661 661 662 662 case 'column-filesize' : 663 663 $sort_flag = SORT_NUMERIC; 664 664 foreach ( $this->get_any_posts_by_posttype('attachment') as $p ) { 665 $file = wp_get_attachment_url($p->ID); 665 $file = wp_get_attachment_url($p->ID); 666 666 if ( $file || $this->show_all_results ) { 667 667 $abs = str_replace( WP_CONTENT_URL, WP_CONTENT_DIR, $file); … … 670 670 } 671 671 break; 672 672 673 673 endswitch; 674 674 675 675 // we will add the sorted post ids to vars['post__in'] and remove unused vars 676 676 if ( isset($sort_flag) ) { … … 680 680 return $vars; 681 681 } 682 682 683 683 /** 684 684 * Orderby Posts column … … 689 689 { 690 690 $post_type = $vars['post_type']; 691 691 692 692 // apply sorting preference 693 693 $this->apply_sorting_preference( $vars, $post_type ); 694 694 695 695 // no sorting 696 if ( empty( $vars['orderby'] ) ) { 697 return $vars; 698 } 699 696 if ( empty( $vars['orderby'] ) ) { 697 return $vars; 698 } 699 700 700 // Column 701 $column = $this->get_orderby_type( $vars['orderby'], $post_type ); 701 $column = $this->get_orderby_type( $vars['orderby'], $post_type ); 702 702 703 703 if ( empty($column) ) 704 704 return $vars; 705 705 706 706 // id 707 707 $type = $id = key($column); 708 709 // Check for taxonomies, such as column-taxonomy-[taxname] 708 709 // Check for taxonomies, such as column-taxonomy-[taxname] 710 710 if ( strpos($type, 'column-taxonomy-') !== false ) 711 711 $type = 'column-taxonomy'; 712 712 713 713 // Check for Custom Field 714 714 if ( Codepress_Admin_Columns::is_column_meta($type) ) … … 716 716 717 717 // var 718 $cposts = array(); 718 $cposts = array(); 719 719 switch( $type ) : 720 720 721 721 case 'column-postid' : 722 722 $vars['orderby'] = 'ID'; 723 723 break; 724 725 case 'column-order' : 724 725 case 'column-order' : 726 726 $vars['orderby'] = 'menu_order'; 727 727 break; 728 729 case 'column-modified' : 728 729 case 'column-modified' : 730 730 $vars['orderby'] = 'modified'; 731 731 break; 732 733 case 'column-comment-count' : 732 733 case 'column-comment-count' : 734 734 $vars['orderby'] = 'comment_count'; 735 735 break; 736 737 case 'column-post-meta' : 738 $field = $column[$id]['field']; 739 736 737 case 'column-post-meta' : 738 $field = $column[$id]['field']; 739 740 740 // orderby type 741 741 $field_type = 'meta_value'; … … 748 748 )); 749 749 break; 750 750 751 751 case 'column-excerpt' : 752 752 $sort_flag = SORT_STRING; 753 753 foreach ( $this->get_any_posts_by_posttype($post_type) as $p ) { 754 754 $cposts[$p->ID] = $this->prepare_sort_string_value($p->post_content); 755 } 756 break; 757 755 } 756 break; 757 758 758 case 'column-word-count' : 759 759 $sort_flag = SORT_NUMERIC; 760 foreach ( $this->get_any_posts_by_posttype($post_type) as $p ) { 760 foreach ( $this->get_any_posts_by_posttype($post_type) as $p ) { 761 761 $cposts[$p->ID] = str_word_count( Codepress_Admin_Columns::strip_trim( $p->post_content ) ); 762 762 } 763 763 break; 764 764 765 765 case 'column-page-template' : 766 766 $sort_flag = SORT_STRING; 767 767 $templates = get_page_templates(); 768 foreach ( $this->get_any_posts_by_posttype($post_type) as $p ) { 768 foreach ( $this->get_any_posts_by_posttype($post_type) as $p ) { 769 769 $page_template = get_post_meta($p->ID, '_wp_page_template', true); 770 770 $cposts[$p->ID] = array_search($page_template, $templates); 771 } 772 break; 773 771 } 772 break; 773 774 774 case 'column-post_formats' : 775 775 $sort_flag = SORT_REGULAR; 776 foreach ( $this->get_any_posts_by_posttype($post_type) as $p ) { 776 foreach ( $this->get_any_posts_by_posttype($post_type) as $p ) { 777 777 $cposts[$p->ID] = get_post_format($p->ID); 778 778 } 779 779 break; 780 780 781 781 case 'column-attachment' : 782 782 case 'column-attachment-count' : … … 785 785 $cposts[$p->ID] = count( Codepress_Admin_Columns::get_attachment_ids($p->ID) ); 786 786 } 787 break; 788 787 break; 788 789 789 case 'column-page-slug' : 790 790 $sort_flag = SORT_REGULAR; 791 791 foreach ( $this->get_any_posts_by_posttype($post_type) as $p ) { 792 792 $cposts[$p->ID] = $p->post_name; 793 } 794 break; 795 793 } 794 break; 795 796 796 case 'column-sticky' : 797 797 $sort_flag = SORT_REGULAR; … … 804 804 } 805 805 break; 806 806 807 807 case 'column-featured_image' : 808 808 $sort_flag = SORT_REGULAR; … … 815 815 } 816 816 break; 817 817 818 818 case 'column-roles' : 819 819 $sort_flag = SORT_STRING; … … 826 826 } 827 827 break; 828 828 829 829 case 'column-status' : 830 830 $sort_flag = SORT_STRING; … … 833 833 } 834 834 break; 835 836 case 'column-comment-status' : 835 836 case 'column-comment-status' : 837 837 $sort_flag = SORT_STRING; 838 838 foreach ( $this->get_any_posts_by_posttype($post_type) as $p ) { … … 840 840 } 841 841 break; 842 843 case 'column-ping-status' : 842 843 case 'column-ping-status' : 844 844 $sort_flag = SORT_STRING; 845 845 foreach ( $this->get_any_posts_by_posttype($post_type) as $p ) { … … 847 847 } 848 848 break; 849 849 850 850 case 'column-taxonomy' : 851 851 $sort_flag = SORT_STRING; // needed to sort … … 853 853 $cposts = $this->get_posts_sorted_by_taxonomy($post_type, $taxonomy); 854 854 break; 855 855 856 856 case 'column-author-name' : 857 857 $sort_flag = SORT_STRING; … … 862 862 foreach ( $this->get_any_posts_by_posttype($post_type) as $p ) { 863 863 if ( !empty($p->post_author) ) { 864 $name = Codepress_Admin_Columns::get_author_field_by_nametype($display_as, $p->post_author); 864 $name = Codepress_Admin_Columns::get_author_field_by_nametype($display_as, $p->post_author); 865 865 $cposts[$p->ID] = $name; 866 866 } 867 867 } 868 868 break; 869 869 870 870 case 'column-before-moretag' : 871 871 $sort_flag = SORT_STRING; 872 872 foreach ( $this->get_any_posts_by_posttype($post_type) as $p ) { 873 873 $extended = get_extended($p->post_content); 874 $content = !empty($extended['extended']) ? $extended['main'] : ''; 874 $content = !empty($extended['extended']) ? $extended['main'] : ''; 875 875 $cposts[$p->ID] = $this->prepare_sort_string_value($content); 876 876 } 877 877 break; 878 878 879 879 /** native WP columns */ 880 880 881 881 // categories 882 882 case 'categories' : … … 884 884 $cposts = $this->get_posts_sorted_by_taxonomy($post_type, 'category'); 885 885 break; 886 886 887 887 // tags 888 888 case 'tags' : … … 890 890 $cposts = $this->get_posts_sorted_by_taxonomy($post_type, 'post_tag'); 891 891 break; 892 893 endswitch; 894 892 893 endswitch; 894 895 895 // we will add the sorted post ids to vars['post__in'] and remove unused vars 896 896 if ( isset($sort_flag) ) { … … 900 900 return $vars; 901 901 } 902 902 903 903 /** 904 904 * Set sorting preference 905 905 * 906 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. 907 * we set the default_order to either asc, desc or empty. 908 908 * only ONE column item PER type can have a default_order 909 909 * … … 914 914 if ( !$orderby ) 915 915 return false; 916 916 917 917 $options = get_user_meta( $this->current_user_id, 'cpac_sorting_preference', true ); 918 918 919 919 $options[$type] = array( 920 920 'orderby' => $orderby, 921 921 'order' => $order 922 922 ); 923 923 924 924 update_user_meta( $this->current_user_id, 'cpac_sorting_preference', $options ); 925 925 } 926 926 927 927 /** 928 928 * Get sorting preference … … 936 936 { 937 937 $options = get_user_meta( $this->current_user_id, 'cpac_sorting_preference', true ); 938 939 if ( empty($options[$type]) ) 938 939 if ( empty($options[$type]) ) 940 940 return false; 941 941 942 942 return $options[$type]; 943 943 } 944 944 945 945 /** 946 946 * Apply sorting preference … … 952 952 // user has not sorted 953 953 if ( empty( $vars['orderby'] ) ) { 954 954 955 955 // did the user sorted this column some other time? 956 956 if ( $preference = $this->get_sorting_preference($type) ) { 957 957 $vars['orderby'] = $preference['orderby']; 958 958 $vars['order'] = $preference['order']; 959 959 960 960 // used by active state in column header 961 961 $_GET['orderby'] = $preference['orderby']; … … 969 969 } 970 970 } 971 971 972 972 /** 973 973 * Get posts sorted by taxonomy … … 977 977 * @since 1.4.5 978 978 */ 979 function get_posts_sorted_by_taxonomy($post_type, $taxonomy = 'category') 979 function get_posts_sorted_by_taxonomy($post_type, $taxonomy = 'category') 980 980 { 981 981 $cposts = array(); 982 982 foreach ( $this->get_any_posts_by_posttype($post_type) as $p ) { 983 $cposts[$p->ID] = ''; 983 $cposts[$p->ID] = ''; 984 984 $terms = get_the_terms($p->ID, $taxonomy); 985 985 if ( !is_wp_error($terms) && !empty($terms) ) { … … 988 988 if ( isset($term->term_id) ) { 989 989 $cposts[$p->ID] = sanitize_term_field('name', $term->name, $term->term_id, $term->taxonomy, 'display'); 990 } 990 } 991 991 } 992 992 } 993 993 return $cposts; 994 994 } 995 995 996 996 /** 997 997 * Set post__in for use in WP_Query … … 1016 1016 $vars['order'] = ''; 1017 1017 $vars['orderby'] = ''; 1018 1018 1019 1019 // add the sorted post ids to the query with the use of post__in 1020 1020 $vars['post__in'] = array_keys($sortposts); 1021 1021 1022 1022 return $vars; 1023 1023 } 1024 1024 1025 1025 /** 1026 1026 * Get orderby type … … 1029 1029 */ 1030 1030 private function get_orderby_type($orderby, $type) 1031 { 1031 { 1032 1032 $db_columns = Codepress_Admin_Columns::get_stored_columns($type); 1033 1033 1034 1034 if ( $db_columns ) { 1035 1035 foreach ( $db_columns as $id => $vars ) { 1036 1036 1037 1037 // check which custom column was clicked 1038 1038 if ( isset( $vars['label'] ) && $orderby == $this->sanitize_string( $vars['label'] ) ) { 1039 1039 $column[$id] = $vars; 1040 return $column;1040 return apply_filters( 'cpac-get-orderby-type', $column, $orderby, $type ); 1041 1041 } 1042 1042 } 1043 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 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 1051 * have been set in post__in. Without this the ID's will be set in numeric order. 1052 1052 * See the WP_Query object for more info about the use of post__in. … … 1054 1054 * @since 1.2.1 1055 1055 */ 1056 public function filter_orderby_post__in($orderby, $wp) 1056 public function filter_orderby_post__in($orderby, $wp) 1057 1057 { 1058 1058 global $wpdb; 1059 1059 1060 1060 // we need the query vars 1061 $vars = $wp->query_vars; 1062 if ( ! empty ( $vars['post__in'] ) ) { 1061 $vars = $wp->query_vars; 1062 if ( ! empty ( $vars['post__in'] ) ) { 1063 1063 // now we can get the ids 1064 1064 $ids = implode(',', $vars['post__in']); 1065 1065 1066 1066 // by adding FIELD to the SQL query we are forcing the order of the ID's 1067 1067 return "FIELD({$wpdb->prefix}posts.ID,{$ids})"; 1068 1068 } 1069 1069 } 1070 1070 1071 1071 /** 1072 1072 * Get any posts by post_type … … 1081 1081 'post_type' => $post_type 1082 1082 )); 1083 1083 1084 1084 // trash posts are not included in the posts_status 'any' by default 1085 1085 $trash_posts = (array) get_posts(array( … … 1087 1087 'post_status' => 'trash', 1088 1088 'post_type' => $post_type 1089 )); 1090 1089 )); 1090 1091 1091 $all_posts = array_merge($any_posts, $trash_posts); 1092 1093 return (array) $all_posts; 1094 } 1095 1092 1093 return (array) $all_posts; 1094 } 1095 1096 1096 /** 1097 1097 * Request URI is … … 1101 1101 private function request_uri_is( $screen_id = '' ) 1102 1102 { 1103 if (strpos( $_SERVER['REQUEST_URI'], "/{$screen_id}.php" ) !== false ) 1103 if (strpos( $_SERVER['REQUEST_URI'], "/{$screen_id}.php" ) !== false ) 1104 1104 return true; 1105 1105 1106 1106 return false; 1107 1107 } 1108 1108 1109 1109 /** 1110 1110 * Prepare the value for being by sorting … … 1116 1116 // remove tags and only get the first 20 chars and force lowercase. 1117 1117 $string = strtolower( substr( Codepress_Admin_Columns::strip_trim($string),0 ,20 ) ); 1118 1118 1119 1119 return $string; 1120 1120 } 1121 1121 1122 1122 /** 1123 1123 * Get users data … … 1125 1125 * @since 1.3 1126 1126 */ 1127 function get_users_data() 1127 function get_users_data() 1128 1128 { 1129 1129 $userdatas = array(); 1130 1130 $wp_users = get_users( array( 1131 'blog_id' => $GLOBALS['blog_id'], 1131 'blog_id' => $GLOBALS['blog_id'], 1132 1132 )); 1133 1133 foreach ( $wp_users as $u ) { … … 1136 1136 return $userdatas; 1137 1137 } 1138 1138 1139 1139 /** 1140 1140 * Register filtering columns … … 1146 1146 if ( ! $this->unlocked || apply_filters( 'cpac-remove-filtering-columns', true ) ) 1147 1147 return false; 1148 1148 1149 1149 // hook into wordpress 1150 1150 add_action('restrict_manage_posts', array($this, 'callback_restrict_posts')); 1151 1151 } 1152 1152 1153 1153 /** 1154 1154 * Add taxonomy filters to posts … … 1159 1159 { 1160 1160 global $post_type_object; 1161 1161 1162 1162 if ( !isset($post_type_object->name) ) 1163 1163 return false; … … 1165 1165 // make a filter foreach taxonomy 1166 1166 $taxonomies = get_object_taxonomies($post_type_object->name, 'names'); 1167 1167 1168 1168 // get stored columns 1169 1169 $db_columns = Codepress_Admin_Columns::get_stored_columns($post_type_object->name); … … 1171 1171 if ( $taxonomies ) { 1172 1172 foreach ( $taxonomies as $tax ) { 1173 1173 1174 1174 // ignore core taxonomies 1175 1175 if ( in_array($tax, array('post_tag','category','post_format') ) ) { 1176 1176 continue; 1177 1177 } 1178 1178 1179 1179 // only display taxonomy that is active as a column 1180 1180 if ( isset($db_columns['column-taxonomy-'.$tax]) && $db_columns['column-taxonomy-'.$tax]['state'] == 'on' ) { 1181 1181 1182 1182 $terms = get_terms($tax); 1183 1183 $terms = $this->indent($terms, 0, 'parent', 'term_id'); 1184 1184 $terms = $this->apply_dropdown_markup($terms); 1185 1185 1186 1186 $select = "<option value=''>".__('Show all ', CPAC_TEXTDOMAIN)."{$tax}</option>"; 1187 1187 if (!empty($terms)) { 1188 1188 foreach( $terms as $term_slug => $term) { 1189 1189 1190 1190 $selected = isset($_GET[$tax]) && $term_slug == $_GET[$tax] ? " selected='selected'" : ''; 1191 1191 $select .= "<option value='{$term_slug}'{$selected}>{$term}</option>"; 1192 1192 } 1193 1193 echo "<select class='postform' name='{$tax}'>{$select}</select>"; 1194 } 1194 } 1195 1195 } 1196 1196 } 1197 1197 } 1198 1198 } 1199 1199 1200 1200 /** 1201 1201 * Applies dropdown markup for taxonomy dropdown … … 1204 1204 */ 1205 1205 private function apply_dropdown_markup($array, $level = 0, $output = array()) 1206 { 1206 { 1207 1207 foreach($array as $v) { 1208 1209 $prefix = ''; 1208 1209 $prefix = ''; 1210 1210 for($i=0; $i<$level; $i++) { 1211 $prefix .= ' '; 1211 $prefix .= ' '; 1212 1212 } 1213 1213 1214 1214 $output[$v->slug] = $prefix . $v->name; 1215 1215 1216 1216 if ( !empty($v->children) ) { 1217 1217 $output = $this->apply_dropdown_markup($v->children, ($level + 1), $output); 1218 1218 } 1219 1219 } 1220 1220 1221 1221 return $output; 1222 1222 } 1223 1223 1224 1224 /** 1225 1225 * Indents any object as long as it has a unique id and that of its parent. … … 1227 1227 * @since 1.4.2 1228 1228 */ 1229 private function indent($array, $parentId = 0, $parentKey = 'post_parent', $selfKey = 'ID', $childrenKey = 'children') 1229 private function indent($array, $parentId = 0, $parentKey = 'post_parent', $selfKey = 'ID', $childrenKey = 'children') 1230 1230 { 1231 1231 $indent = array(); 1232 1232 1233 1233 // clean counter 1234 1234 $i = 0; 1235 1235 1236 1236 foreach($array as $v) { 1237 1237 … … 1239 1239 $indent[$i] = $v; 1240 1240 $indent[$i]->$childrenKey = $this->indent($array, $v->$selfKey, $parentKey, $selfKey); 1241 1241 1242 1242 $i++; 1243 1243 } -
codepress-admin-columns/trunk/classes/values.php
r637026 r638877 8 8 */ 9 9 class CPAC_Values 10 { 10 { 11 11 protected $excerpt_length, $thumbnail_size; 12 12 13 13 /** 14 14 * Constructor … … 17 17 */ 18 18 function __construct() 19 { 19 { 20 20 // number of words 21 $this->excerpt_length = 20; 21 $this->excerpt_length = 20; 22 22 $this->thumbnail_size = apply_filters( 'cpac_thumbnail_size', array(80,80) ); 23 23 } 24 24 25 25 /** 26 26 * Admin requests for orderby column … … 29 29 */ 30 30 public function get_stored_columns($type) 31 { 31 { 32 32 return Codepress_Admin_Columns::get_stored_columns($type); 33 33 } 34 34 35 35 /** 36 36 * Checks if column-meta key exists … … 38 38 * @since 1.0 39 39 */ 40 public static function is_column_meta( $id = '' ) 40 public static function is_column_meta( $id = '' ) 41 41 { 42 42 return Codepress_Admin_Columns::is_column_meta( $id ); 43 43 } 44 44 45 45 /** 46 46 * Returns excerpt … … 48 48 * @since 1.0 49 49 */ 50 protected function get_post_excerpt($post_id) 50 protected function get_post_excerpt($post_id) 51 51 { 52 52 global $post; 53 53 54 54 $save_post = $post; 55 55 $post = get_post($post_id); 56 56 $excerpt = get_the_excerpt(); 57 57 $post = $save_post; 58 59 $output = $this->get_shortened_string($excerpt, $this->excerpt_length ); 60 58 59 $output = $this->get_shortened_string($excerpt, $this->excerpt_length ); 60 61 61 return $output; 62 62 } 63 63 64 64 /** 65 65 * Returns shortened string … … 67 67 * @since 1.0 68 68 */ 69 protected function get_shortened_string($string = '', $num_words = 55, $more = null) 69 protected function get_shortened_string($string = '', $num_words = 55, $more = null) 70 70 { 71 71 if (!$string) 72 72 return false; 73 73 74 74 return wp_trim_words( $string, $num_words, $more ); 75 75 } … … 84 84 if ( $name ) 85 85 return sprintf("<img alt='' src='%s' title='%s'/>", CPAC_URL."/assets/images/{$name}", $title); 86 } 87 86 } 87 88 88 /** 89 89 * Shorten URL … … 95 95 if ( !$url ) 96 96 return false; 97 97 98 98 // shorten url 99 99 $short_url = url_shorten( $url ); 100 101 return "<a title='{$url}' href='{$url}'>{$short_url}</a>"; 102 } 103 100 101 return "<a title='{$url}' href='{$url}'>{$short_url}</a>"; 102 } 103 104 104 /** 105 105 * Get column value of post attachments … … 107 107 * @since 1.0 108 108 */ 109 protected function get_column_value_attachments( $post_id ) 109 protected function get_column_value_attachments( $post_id ) 110 110 { 111 111 $result = ''; … … 119 119 return $result; 120 120 } 121 121 122 122 /** 123 123 * Get column value of post attachments … … 125 125 * @since 1.2.1 126 126 */ 127 protected function get_attachment_ids( $post_id ) 127 protected function get_attachment_ids( $post_id ) 128 128 { 129 129 return Codepress_Admin_Columns::get_attachment_ids( $post_id ); 130 130 } 131 131 132 132 /** 133 133 * Get a thumbnail … … 135 135 * @since 1.0 136 136 */ 137 protected function get_thumbnail( $image = '' ) 138 { 137 protected function get_thumbnail( $image = '' ) 138 { 139 139 if ( empty($image) ) 140 140 return false; 141 141 142 142 // get thumbnail image size 143 143 $image_size = $this->thumbnail_size; // w, h 144 144 145 145 // incase the thumbnail dimension is set by name 146 146 if ( !is_array($image_size) ) { … … 151 151 } 152 152 } 153 153 154 154 // fallback for image size incase the passed size name does not exists 155 155 if ( !isset($image_size[0]) || !isset($image_size[1]) ) { 156 156 $image_size = array(80, 80); 157 157 } 158 158 159 159 // get correct image path 160 160 $image_path = str_replace( WP_CONTENT_URL, WP_CONTENT_DIR, $image); 161 162 // resize image 161 162 // resize image 163 163 if ( file_exists($image_path) && $this->is_image($image_path) ) { 164 164 $resized = image_resize( $image_path, $image_size[0], $image_size[1], true); 165 165 166 166 // resize worked 167 167 if ( ! is_wp_error( $resized ) ) { 168 168 $image = str_replace( WP_CONTENT_DIR, WP_CONTENT_URL, $resized); 169 169 170 170 return "<img src='{$image}' alt='' width='{$image_size[0]}' height='{$image_size[1]}' />"; 171 171 } 172 172 173 173 // resizing failed so let's return full image with maxed dimensions 174 174 else { 175 return "<img src='{$image}' alt='' style='max-width:{$image_size[0]}px;max-height:{$image_size[1]}px' />"; 176 } 177 } 178 175 return "<img src='{$image}' alt='' style='max-width:{$image_size[0]}px;max-height:{$image_size[1]}px' />"; 176 } 177 } 178 179 179 return false; 180 180 } 181 181 182 182 /** 183 183 * Checks an URL for image extension … … 185 185 * @since 1.2 186 186 */ 187 protected function is_image($url) 187 protected function is_image($url) 188 188 { 189 189 $validExt = array('.jpg', '.jpeg', '.gif', '.png', '.bmp'); 190 190 $ext = strrchr($url, '.'); 191 191 192 192 return in_array($ext, $validExt); 193 } 194 193 } 194 195 195 /** 196 196 * Get a thumbnail … … 198 198 * @since 1.3.1 199 199 */ 200 protected function get_media_thumbnails($meta) 200 protected function get_media_thumbnails($meta) 201 201 { 202 202 $meta = $this->strip_trim( str_replace(' ','', $meta) ); 203 203 204 204 // split media ids 205 205 $media_ids = array($meta); 206 if ( strpos($meta, ',') !== false ) 206 if ( strpos($meta, ',') !== false ) 207 207 $media_ids = explode(',', $meta); 208 208 209 209 // check if media exists 210 210 $thumbs = ''; … … 212 212 if ( is_numeric($media_id) ) 213 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 214 215 return $thumbs; 216 } 217 218 218 /** 219 219 * Convert file size to readable format … … 226 226 return $size ? round($size/pow(1024, ($i = floor(log($size, 1024)))), 2) . $filesizename[$i] : '0 Bytes'; 227 227 } 228 228 229 229 /** 230 230 * Get column value of Custom Field 231 231 * 232 232 * @since 1.0 233 */ 234 protected function get_column_value_custom_field($object_id, $column_name, $meta_type = 'post') 233 */ 234 protected function get_column_value_custom_field($object_id, $column_name, $meta_type = 'post') 235 235 { 236 236 /** Users */ 237 if ( $meta_type == 'user') {237 if ( 'user' == $meta_type ) { 238 238 $type = 'wp-users'; 239 239 } 240 240 241 241 /** Media */ 242 if ( $meta_type == 'media') {242 elseif ( 'media' == $meta_type ) { 243 243 $type = 'wp-media'; 244 244 $meta_type = 'post'; 245 245 } 246 246 247 247 /** Posts */ 248 248 else { 249 249 $type = get_post_type($object_id); 250 250 } 251 251 252 252 // get column 253 253 $columns = $this->get_stored_columns($type); 254 254 255 255 // inputs 256 256 $field = isset($columns[$column_name]['field']) ? $columns[$column_name]['field'] : ''; … … 258 258 $before = isset($columns[$column_name]['before']) ? $columns[$column_name]['before'] : ''; 259 259 $after = isset($columns[$column_name]['after']) ? $columns[$column_name]['after'] : ''; 260 260 261 261 // rename hidden custom fields to their original name 262 262 $field = substr($field,0,10) == "cpachidden" ? str_replace('cpachidden','',$field) : $field; 263 263 264 264 // Get meta field value 265 265 $meta = get_metadata($meta_type, $object_id, $field, true); 266 266 267 267 // multiple meta values 268 if ( ( $fieldtype == 'array' && is_array($meta) ) || is_array($meta) ) { 268 if ( ( $fieldtype == 'array' && is_array($meta) ) || is_array($meta) ) { 269 269 $meta = get_metadata($meta_type, $object_id, $field, true); 270 270 $meta = $this->recursive_implode(', ', $meta); … … 272 272 273 273 // make sure there are no serialized arrays or null data 274 if ( !is_string($meta) ) 275 return false; 276 274 if ( !is_string($meta) ) 275 return false; 276 277 277 // handles each field type differently.. 278 switch ($fieldtype) : 279 278 switch ($fieldtype) : 279 280 280 // Image 281 281 case "image" : 282 282 $meta = $this->get_thumbnail($meta); 283 283 break; 284 284 285 285 // Media Library ID 286 286 case "library_id" : 287 $meta = $this->get_media_thumbnails($meta); 288 break; 289 287 $meta = $this->get_media_thumbnails($meta); 288 break; 289 290 290 // Excerpt 291 291 case "excerpt" : 292 292 $meta = $this->get_shortened_string($meta, $this->excerpt_length); 293 293 break; 294 294 295 295 // Date 296 296 case "date" : 297 297 $meta = $this->get_date($meta); 298 298 break; 299 299 300 300 // Post Title 301 301 case "title_by_id" : … … 304 304 $meta = $titles; 305 305 break; 306 306 307 307 // User Name 308 308 case "user_by_id" : 309 309 $names = $this->get_custom_field_value_user($meta); 310 310 if ( $names ) 311 $meta = $names; 312 break; 313 311 $meta = $names; 312 break; 313 314 314 // Checkmark 315 315 case "checkmark" : 316 316 $checkmark = $this->get_asset_image('checkmark.png'); 317 317 318 318 if ( empty($meta) || 'false' === $meta || '0' === $meta ) { 319 319 $checkmark = ''; 320 320 } 321 322 $meta = $checkmark; 323 break; 324 321 322 $meta = $checkmark; 323 break; 324 325 325 // Color 326 326 case "color" : … … 329 329 } 330 330 break; 331 332 endswitch; 331 332 endswitch; 333 333 334 334 // filter for customization 335 335 $meta = apply_filters('cpac_get_column_value_custom_field', $meta, $fieldtype, $field, $type, $object_id ); 336 336 337 337 // add before and after string 338 338 if ( $meta ) { 339 339 $meta = "{$before}{$meta}{$after}"; 340 340 } 341 341 342 342 return $meta; 343 343 } 344 344 345 345 /** 346 346 * Get custom field value 'Title by ID' … … 348 348 * @since 1.3 349 349 */ 350 protected function get_custom_field_value_title($meta) 350 protected function get_custom_field_value_title($meta) 351 351 { 352 352 //remove white spaces and strip tags 353 353 $meta = $this->strip_trim( str_replace(' ','', $meta) ); 354 354 355 355 // var 356 356 $ids = $titles = array(); 357 357 358 358 // check for multiple id's 359 359 if ( strpos($meta, ',') !== false ) 360 $ids = explode(',',$meta); 360 $ids = explode(',',$meta); 361 361 elseif ( is_numeric($meta) ) 362 $ids[] = $meta; 363 362 $ids[] = $meta; 363 364 364 // display title with link 365 365 if ( $ids && is_array($ids) ) { 366 foreach ( $ids as $id ) { 366 foreach ( $ids as $id ) { 367 367 $title = is_numeric($id) ? get_the_title($id) : ''; 368 368 $link = get_edit_post_link($id); … … 371 371 } 372 372 } 373 373 374 374 return implode('<span class="cpac-divider"></span>', $titles); 375 375 } 376 376 377 377 /** 378 378 * Get custom field value 'User by ID' … … 380 380 * @since 1.4.6.3 381 381 */ 382 protected function get_custom_field_value_user($meta) 382 protected function get_custom_field_value_user($meta) 383 383 { 384 384 //remove white spaces and strip tags 385 385 $meta = $this->strip_trim( str_replace(' ','', $meta) ); 386 386 387 387 // var 388 388 $ids = $names = array(); 389 389 390 390 // check for multiple id's 391 391 if ( strpos($meta, ',') !== false ) 392 392 $ids = explode(',',$meta); 393 393 elseif ( is_numeric($meta) ) 394 $ids[] = $meta; 395 394 $ids[] = $meta; 395 396 396 // display username 397 397 if ( $ids && is_array($ids) ) { … … 399 399 if ( !is_numeric($id) ) 400 400 continue; 401 401 402 402 $userdata = get_userdata($id); 403 403 if ( is_object($userdata) && !empty( $userdata->display_name ) ) { 404 404 $names[] = $userdata->display_name; 405 } 406 } 407 } 408 405 } 406 } 407 } 408 409 409 return implode('<span class="cpac-divider"></span>', $names); 410 410 } 411 411 412 412 /** 413 413 * Get column value of Custom Field … … 415 415 * @since 1.2 416 416 */ 417 protected function get_user_column_value_custom_field($user_id, $id) 418 { 417 protected function get_user_column_value_custom_field($user_id, $id) 418 { 419 419 $columns = $this->get_stored_columns('wp-users'); 420 420 421 421 // inputs 422 422 $field = isset($columns[$id]['field']) ? $columns[$id]['field'] : ''; … … 424 424 $before = isset($columns[$id]['before']) ? $columns[$id]['before'] : ''; 425 425 $after = isset($columns[$id]['after']) ? $columns[$id]['after'] : ''; 426 426 427 427 // Get meta field value 428 428 $meta = get_user_meta($user_id, $field, true); 429 429 430 430 // multiple meta values 431 if ( ( $fieldtype == 'array' && is_array($meta) ) || is_array($meta) ) { 431 if ( ( $fieldtype == 'array' && is_array($meta) ) || is_array($meta) ) { 432 432 $meta = get_user_meta($user_id, $field); 433 433 $meta = $this->recursive_implode(', ', $meta); 434 434 } 435 435 436 436 // make sure there are no serialized arrays or empty meta data 437 if ( empty($meta) || !is_string($meta) ) 438 return false; 439 437 if ( empty($meta) || !is_string($meta) ) 438 return false; 439 440 440 // handles each field type differently.. 441 switch ($fieldtype) : 442 441 switch ($fieldtype) : 442 443 443 // Image 444 case "image" : 444 case "image" : 445 445 $meta = $this->get_thumbnail($meta); 446 446 break; 447 447 448 448 // Media Library ID 449 449 case "library_id" : 450 450 $meta = $this->get_media_thumbnails($meta); 451 451 break; 452 452 453 453 // Excerpt 454 454 case "excerpt" : 455 455 $meta = $this->get_shortened_string($meta, $this->excerpt_length); 456 456 break; 457 458 endswitch; 459 457 458 endswitch; 459 460 460 // filter for customization 461 461 $meta = apply_filters('cpac_get_user_column_value_custom_field', $meta, $fieldtype, $field ); 462 462 463 463 // add before and after string 464 464 $meta = "{$before}{$meta}{$after}"; 465 465 466 466 return $meta; 467 467 } … … 472 472 * @since 1.0 473 473 */ 474 protected function recursive_implode( $glue, $pieces ) 474 protected function recursive_implode( $glue, $pieces ) 475 475 { 476 476 foreach( $pieces as $r_pieces ) { … … 484 484 if ( isset($retVal) && is_array($retVal) ) 485 485 return implode( $glue, $retVal ); 486 486 487 487 return false; 488 488 } 489 489 490 490 /** 491 491 * Strip tags and trim … … 493 493 * @since 1.3 494 494 */ 495 protected function strip_trim($string) 495 protected function strip_trim($string) 496 496 { 497 497 return Codepress_Admin_Columns::strip_trim($string); 498 498 } 499 499 500 500 /** 501 501 * Get date … … 503 503 * @since 1.3.1 504 504 */ 505 protected function get_date($date) 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 return date_i18n( get_option('date_format'), strtotime($date) ); 511 } 512 513 /** 514 * Get time 515 * 516 * @since 1.3.1 517 */ 518 protected function get_time($date) 506 519 { 507 520 if ( ! $date ) 508 521 return false; 509 510 return date_i18n( get_option('date_format'), strtotime($date) ); 511 } 512 513 /** 514 * Get time 515 * 516 * @since 1.3.1 517 */ 518 protected function get_time($date) 519 { 520 if ( ! $date ) 521 return false; 522 522 523 523 if ( ! is_numeric($date) ) 524 524 $date = strtotime($date); 525 525 526 526 return date_i18n( get_option('time_format'), $date ); 527 527 } -
codepress-admin-columns/trunk/classes/values/comments.php
r637026 r638877 8 8 */ 9 9 class CPAC_Comments_Values extends CPAC_Values 10 { 10 { 11 11 /** 12 12 * Constructor … … 17 17 { 18 18 parent::__construct(); 19 19 20 20 add_action( 'manage_comments_custom_column', array( $this, 'manage_comments_column_value'), 10, 2 ); 21 21 } 22 22 23 23 /** 24 24 * Manage custom column for Comments … … 29 29 { 30 30 $type = $column_name; 31 31 32 32 // comments object 33 33 $comment = get_comment($comment_id); 34 34 35 35 // Check for custom fields, such as column-meta-[customfieldname] 36 36 if ( $this->is_column_meta($type) ) 37 37 $type = 'column-comment-meta'; 38 39 // Hook 38 39 // Hook 40 40 do_action('cpac-manage-comments-column', $type, $column_name, $comment_id); 41 41 42 42 $result = ''; 43 switch ($type) : 44 43 switch ($type) : 44 45 45 // comment id 46 46 case "column-comment_id" : 47 47 $result = $comment_id; 48 48 break; 49 49 50 50 // author 51 51 case "column-author_author" : 52 52 $result = $comment->comment_author; 53 53 break; 54 54 55 55 // avatar 56 56 case "column-author_avatar" : 57 $result = get_avatar( $comment, 80 ); 58 break; 59 57 $result = get_avatar( $comment, 80 ); 58 break; 59 60 60 // url 61 case "column-author_url" : 62 $result = $this->get_shorten_url($comment->comment_author_url); 63 break; 64 61 case "column-author_url" : 62 $result = $this->get_shorten_url($comment->comment_author_url); 63 break; 64 65 65 // ip 66 66 case "column-author_ip" : 67 67 $result = $comment->comment_author_IP; 68 68 break; 69 69 70 70 // email 71 71 case "column-author_email" : 72 72 $result = $comment->comment_author_email; 73 73 break; 74 74 75 75 // parent 76 76 case "column-reply_to" : 77 if ( $comment->comment_approved ) { 77 if ( $comment->comment_approved ) { 78 78 $parent = get_comment( $comment->comment_parent ); 79 79 $parent_link = esc_url( get_comment_link( $comment->comment_parent ) ); … … 81 81 $result = sprintf( '<a href="%1$s">%2$s</a>', $parent_link, $name ); 82 82 } 83 break; 84 83 break; 84 85 85 // approved 86 86 case "column-approved" : … … 89 89 $result = $this->get_asset_image('checkmark.png'); 90 90 break; 91 91 92 92 // date 93 93 case "column-date" : 94 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>' ), 95 $result = sprintf( __( 'Submitted on <a href="%1$s">%2$s at %3$s</a>' ), 96 96 $comment_url, 97 97 $this->get_date($comment->comment_date), … … 100 100 $result = "<div class='submitted-on'>{$result}</div>"; 101 101 break; 102 102 103 103 // date GMT 104 104 case "column-date_gmt" : 105 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>' ), 106 $result = sprintf( __( 'Submitted on <a href="%1$s">%2$s at %3$s</a>' ), 107 107 $comment_url, 108 108 $this->get_date($comment->comment_date_gmt), … … 111 111 $result = "<div class='submitted-on'>{$result}</div>"; 112 112 break; 113 113 114 114 // custom field 115 115 case "column-comment-meta" : 116 $result = $this->get_column_value_custom_field($comment_id, $column_name, 'comment'); 117 break; 118 116 $result = $this->get_column_value_custom_field($comment_id, $column_name, 'comment'); 117 break; 118 119 119 // agent 120 120 case "column-agent" : 121 $result = $comment->comment_agent; 122 break; 123 121 $result = $comment->comment_agent; 122 break; 123 124 124 // excerpt 125 125 case "column-excerpt" : 126 126 $comment = get_comment($comment_id); 127 127 $result = $this->get_shortened_string($comment->comment_content, $this->excerpt_length); 128 break; 129 128 break; 129 130 130 // actions 131 131 case "column-actions" : 132 132 $result = $this->get_column_value_actions($comment); 133 133 break; 134 134 135 135 // word count 136 136 case "column-word-count" : 137 137 $result = str_word_count( $this->strip_trim( $comment->comment_content ) ); 138 138 break; 139 139 140 140 default : 141 141 $result = ''; 142 142 143 143 endswitch; 144 144 145 145 // Filter for customizing the result output 146 146 apply_filters('cpac-comments-column-result', $result, $type, $column_name, $comment_id); 147 147 148 148 echo $result; 149 149 } 150 150 151 151 /** 152 152 * Get column value of comments actions … … 156 156 * @since 1.4.2 157 157 */ 158 private function get_column_value_actions( $comment ) 159 { 158 private function get_column_value_actions( $comment ) 159 { 160 160 global $post, $comment_status; 161 161 162 162 // set uased vars 163 163 $user_can = current_user_can( 'edit_comment', $comment->comment_ID ); 164 164 $the_comment_status = wp_get_comment_status( $comment->comment_ID ); 165 165 166 166 if ( $user_can ) { 167 167 $del_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "delete-comment_$comment->comment_ID" ) ); … … 178 178 $delete_url = esc_url( $url . "&action=deletecomment&$del_nonce" ); 179 179 } 180 180 181 181 /** begin - copied from class-wp-comments-list-table */ 182 182 if ( $user_can ) { -
codepress-admin-columns/trunk/classes/values/link.php
r564496 r638877 8 8 */ 9 9 class CPAC_Link_Values extends CPAC_Values 10 { 10 { 11 11 /** 12 12 * Constructor … … 17 17 { 18 18 parent::__construct(); 19 19 20 20 add_action( 'manage_link_custom_column', array( $this, 'manage_link_column_value'), 10, 2 ); 21 21 } 22 22 23 23 /** 24 24 * Manage custom column for Links … … 29 29 { 30 30 $type = $column_name; 31 31 32 32 // links object... called bookmark 33 33 $bookmark = get_bookmark($link_id); 34 34 35 // Hook 35 // Hook 36 36 do_action('cpac-manage-link-column', $type, $column_name, $link_id); 37 37 38 38 $result = ''; 39 switch ($type) : 40 39 switch ($type) : 40 41 41 // link id 42 42 case "column-link_id" : 43 43 $result = $link_id; 44 44 break; 45 45 46 46 // description 47 47 case "column-description" : 48 48 $result = $bookmark->link_description; 49 49 break; 50 50 51 51 // target 52 52 case "column-target" : 53 53 $result = $bookmark->link_target; 54 54 break; 55 55 56 56 // notes 57 57 case "column-notes" : 58 58 $result = $this->get_shortened_string($bookmark->link_notes, $this->excerpt_length); 59 59 break; 60 60 61 61 // rss 62 62 case "column-rss" : 63 63 $result = $this->get_shorten_url($bookmark->link_rss); 64 64 break; 65 65 66 66 // image 67 67 case "column-image" : 68 68 $result = $this->get_thumbnail($bookmark->link_image); 69 69 break; 70 70 71 71 // name length 72 case "column-length" : 72 case "column-length" : 73 73 $result = strlen($bookmark->link_name); 74 74 break; 75 75 76 76 // owner 77 77 case "column-owner" : 78 78 $result = $bookmark->link_owner; 79 79 80 80 // add user link 81 $userdata = get_userdata( $bookmark->link_owner ); 81 $userdata = get_userdata( $bookmark->link_owner ); 82 82 if (!empty($userdata->data)) { 83 83 $result = $userdata->data->user_nicename; … … 85 85 } 86 86 break; 87 87 88 88 // link actions 89 89 case "column-actions" : 90 90 $result = $this->get_column_value_actions($bookmark); 91 91 break; 92 92 93 93 default : 94 94 $result = ''; 95 95 96 96 endswitch; 97 97 98 98 // Filter for customizing the result output 99 99 apply_filters('cpac-link-column-result', $result, $type, $column_name, $link_id); 100 100 101 101 echo $result; 102 102 } 103 103 104 104 /** 105 105 * Get column value of link actions … … 109 109 * @since 1.4.2 110 110 */ 111 private function get_column_value_actions( $link ) 111 private function get_column_value_actions( $link ) 112 112 { 113 113 $actions = array(); 114 114 115 115 $edit_link = get_edit_bookmark_link( $link ); 116 116 117 117 $actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>'; 118 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 119 120 120 return implode(' | ', $actions); 121 121 } -
codepress-admin-columns/trunk/classes/values/media.php
r637026 r638877 8 8 */ 9 9 class CPAC_Media_Values extends CPAC_Values 10 { 10 { 11 11 /** 12 12 * Constructor … … 17 17 { 18 18 parent::__construct(); 19 20 add_action( 'manage_media_custom_column', array( $this, 'manage_media_column_value'), 10, 2 ); 19 20 add_action( 'manage_media_custom_column', array( $this, 'manage_media_column_value'), 10, 2 ); 21 21 } 22 22 23 23 /** 24 24 * Manage custom column for Media. … … 29 29 { 30 30 $type = $column_name; 31 31 32 32 //$meta = wp_get_attachment_metadata($media_id); 33 33 $meta = get_post_meta( $media_id, '_wp_attachment_metadata', true ); 34 34 $p = get_post($media_id); 35 35 36 36 // Check for custom fields, such as column-meta-[customfieldname] 37 37 if ( $this->is_column_meta($type) ) 38 38 $type = 'column-meta'; 39 40 // Hook 39 40 // Hook 41 41 do_action('cpac-manage-media-column', $type, $column_name, $media_id); 42 42 43 43 $result = ''; 44 switch ($type) : 45 44 switch ($type) : 45 46 46 // media id 47 47 case "column-mediaid" : 48 48 $result = $media_id; 49 break; 50 49 break; 50 51 51 // dimensions 52 52 case "column-dimensions" : … … 54 54 $result = "{$meta['width']} x {$meta['height']}"; 55 55 break; 56 56 57 57 // width 58 58 case "column-width" : 59 59 $result = !empty($meta['width']) ? $meta['width'] : ''; 60 60 break; 61 61 62 62 // height 63 63 case "column-height" : 64 64 $result = !empty($meta['height']) ? $meta['height'] : ''; 65 65 break; 66 66 67 67 // description 68 68 case "column-description" : 69 69 $result = $p->post_content; 70 70 break; 71 71 72 72 // caption 73 73 case "column-caption" : 74 74 $result = $p->post_excerpt; 75 75 break; 76 76 77 77 // alternate text 78 78 case "column-alternate_text" : … … 80 80 $result = $this->strip_trim($alt); 81 81 break; 82 82 83 83 // mime type 84 case "column-mime_type" : 84 case "column-mime_type" : 85 85 $result = $p->post_mime_type; 86 86 break; 87 87 88 88 // file name 89 89 case "column-file_name" : … … 92 92 $result = "<a title='{$filename}' href='{$file}'>{$filename}</a>"; 93 93 break; 94 94 95 95 // file paths 96 96 case "column-file_paths" : 97 97 $sizes = get_intermediate_image_sizes(); 98 98 $url = wp_get_attachment_url($p->ID); 99 $filename = basename($url); 99 $filename = basename($url); 100 100 $paths[] = "<a title='{$filename}' href='{$url}'>" . __('original', CPAC_TEXTDOMAIN) . "</a>"; 101 101 if ( $sizes ) { 102 102 foreach ( $sizes as $size ) { 103 $src = wp_get_attachment_image_src( $media_id, $size ); 103 $src = wp_get_attachment_image_src( $media_id, $size ); 104 104 if (!empty($src[0])) { 105 105 $filename = basename($src[0]); … … 107 107 } 108 108 } 109 } 109 } 110 110 $result = implode('<span class="cpac-divider"></span>', $paths); 111 111 break; 112 112 113 113 case "column-actions" : 114 114 $result = $this->get_column_value_actions($media_id); 115 115 break; 116 116 117 117 case "column-filesize" : 118 118 $file = wp_get_attachment_url($p->ID); … … 122 122 } 123 123 break; 124 124 125 125 // Custom Field 126 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 127 $result = $this->get_column_value_custom_field($media_id, $column_name, 'media'); 128 break; 129 130 // Image metadata EXIF or IPTC data 131 131 case "column-image-aperture" : 132 $result = !empty( $meta['image_meta']['aperture'] ) ? $meta['image_meta']['aperture'] : ''; 133 break; 134 132 $result = !empty( $meta['image_meta']['aperture'] ) ? $meta['image_meta']['aperture'] : ''; 133 break; 134 135 135 case "column-image-credit" : 136 $result = !empty( $meta['image_meta']['credit'] ) ? $meta['image_meta']['credit'] : ''; 137 break; 138 136 $result = !empty( $meta['image_meta']['credit'] ) ? $meta['image_meta']['credit'] : ''; 137 break; 138 139 139 case "column-image-camera" : 140 $result = !empty( $meta['image_meta']['camera'] ) ? $meta['image_meta']['camera'] : ''; 141 break; 142 140 $result = !empty( $meta['image_meta']['camera'] ) ? $meta['image_meta']['camera'] : ''; 141 break; 142 143 143 case "column-image-caption" : 144 $result = !empty( $meta['image_meta']['caption'] ) ? $meta['image_meta']['caption'] : ''; 145 break; 146 144 $result = !empty( $meta['image_meta']['caption'] ) ? $meta['image_meta']['caption'] : ''; 145 break; 146 147 147 case "column-image-created_timestamp" : 148 148 if ( !empty( $meta['image_meta']['created_timestamp'] ) ) { 149 149 $result = date_i18n( get_option('date_format') . ' ' . get_option('time_format') , strtotime($meta['image_meta']['created_timestamp']) ); 150 } 151 break; 152 150 } 151 break; 152 153 153 case "column-image-copyright" : 154 $result = !empty( $meta['image_meta']['copyright'] ) ? $meta['image_meta']['copyright'] : ''; 155 break; 156 154 $result = !empty( $meta['image_meta']['copyright'] ) ? $meta['image_meta']['copyright'] : ''; 155 break; 156 157 157 case "column-image-focal_length" : 158 $result = !empty( $meta['image_meta']['focal_length'] ) ? $meta['image_meta']['focal_length'] : ''; 159 break; 160 158 $result = !empty( $meta['image_meta']['focal_length'] ) ? $meta['image_meta']['focal_length'] : ''; 159 break; 160 161 161 case "column-image-iso" : 162 $result = !empty( $meta['image_meta']['iso'] ) ? $meta['image_meta']['iso'] : ''; 163 break; 164 162 $result = !empty( $meta['image_meta']['iso'] ) ? $meta['image_meta']['iso'] : ''; 163 break; 164 165 165 case "column-image-shutter_speed" : 166 $result = !empty( $meta['image_meta']['shutter_speed'] ) ? $meta['image_meta']['shutter_speed'] : ''; 167 break; 168 166 $result = !empty( $meta['image_meta']['shutter_speed'] ) ? $meta['image_meta']['shutter_speed'] : ''; 167 break; 168 169 169 case "column-image-title" : 170 $result = !empty( $meta['image_meta']['title'] ) ? $meta['image_meta']['title'] : ''; 171 break; 172 170 $result = !empty( $meta['image_meta']['title'] ) ? $meta['image_meta']['title'] : ''; 171 break; 172 173 173 default : 174 174 $result = ''; 175 175 176 176 endswitch; 177 177 178 178 // Filter for customizing the result output 179 179 apply_filters('cpac-media-column-result', $result, $type, $column_name, $media_id); 180 180 181 181 echo $result; 182 182 } 183 183 184 184 /** 185 185 * Get column value of media actions … … 189 189 * @since 1.4.2 190 190 */ 191 private function get_column_value_actions( $id ) 192 { 191 private function get_column_value_actions( $id ) 192 { 193 193 if ( file_exists(ABSPATH . 'wp-admin/includes/class-wp-list-table.php') ) 194 194 require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php'); 195 195 if ( file_exists(ABSPATH . 'wp-admin/includes/class-wp-media-list-table.php') ) 196 196 require_once(ABSPATH . 'wp-admin/includes/class-wp-media-list-table.php'); 197 197 198 198 // we need class to get the object actions 199 199 $m = new WP_Media_List_Table; 200 200 201 201 // prevent php notice 202 202 $m->is_trash = isset( $_REQUEST['status'] ) && 'trash' == $_REQUEST['status']; 203 203 204 204 // get media actions 205 205 $media = get_post($id); 206 206 $actions = $m->_get_row_actions( $media, _draft_or_post_title($id) ); 207 207 208 208 return implode(' | ', $actions); 209 209 } -
codepress-admin-columns/trunk/classes/values/posts.php
r637026 r638877 8 8 */ 9 9 class CPAC_Posts_Values extends CPAC_Values 10 { 10 { 11 11 /** 12 12 * Constructor … … 15 15 */ 16 16 function __construct() 17 { 17 { 18 18 parent::__construct(); 19 20 add_action( 'manage_pages_custom_column', array( $this, 'manage_posts_column_value'), 10, 2 ); 19 20 add_action( 'manage_pages_custom_column', array( $this, 'manage_posts_column_value'), 10, 2 ); 21 21 add_action( 'manage_posts_custom_column', array( $this, 'manage_posts_column_value'), 10, 2 ); 22 22 } 23 23 24 24 /** 25 25 * Manage custom column for Post Types. … … 27 27 * @since 1.0 28 28 */ 29 public function manage_posts_column_value($column_name, $post_id) 29 public function manage_posts_column_value($column_name, $post_id) 30 30 { 31 31 $type = $column_name; 32 32 33 // Check for taxonomies, such as column-taxonomy-[taxname] 33 // Check for taxonomies, such as column-taxonomy-[taxname] 34 34 if ( strpos($type, 'column-taxonomy-') !== false ) 35 35 $type = 'column-taxonomy'; 36 36 37 37 // Check for custom fields, such as column-meta-[customfieldname] 38 38 if ( $this->is_column_meta($type) ) 39 39 $type = 'column-post-meta'; 40 41 // Hook 40 41 // Hook 42 42 do_action('cpac-manage-posts-column', $type, $column_name, $post_id); 43 43 44 44 // Switch Types 45 45 $result = ''; 46 switch ($type) : 47 46 switch ($type) : 47 48 48 // Post ID 49 49 case "column-postid" : 50 50 $result = $post_id; 51 51 break; 52 52 53 53 // Excerpt 54 54 case "column-excerpt" : 55 55 $result = $this->get_post_excerpt($post_id); 56 56 break; 57 57 58 58 // Featured Image 59 59 case "column-featured_image" : … … 61 61 $result = get_the_post_thumbnail($post_id, $this->thumbnail_size); 62 62 break; 63 63 64 64 // Sticky Post 65 65 case "column-sticky" : 66 if ( is_sticky($post_id) ) 66 if ( is_sticky($post_id) ) 67 67 $result = $this->get_asset_image('checkmark.png'); 68 68 break; 69 69 70 70 // Order 71 71 case "column-order" : 72 $result = get_post_field('menu_order', $post_id); 73 break; 74 72 $result = get_post_field('menu_order', $post_id); 73 break; 74 75 75 // Post Formats 76 76 case "column-post_formats" : 77 $result = get_post_format($post_id); 78 break; 79 77 $result = get_post_format($post_id); 78 break; 79 80 80 // Page template 81 81 case "column-page-template" : 82 82 // file name 83 $page_template = get_post_meta($post_id, '_wp_page_template', true); 83 $page_template = get_post_meta($post_id, '_wp_page_template', true); 84 84 85 85 // get template nice name 86 $result = array_search($page_template, get_page_templates()); 87 break; 88 86 $result = array_search($page_template, get_page_templates()); 87 break; 88 89 89 // Slug 90 90 case "column-page-slug" : 91 91 $result = get_post($post_id)->post_name; 92 92 break; 93 93 94 94 // Slug 95 95 case "column-word-count" : 96 96 $result = str_word_count( $this->strip_trim( get_post($post_id)->post_content ) ); 97 97 break; 98 98 99 99 // Taxonomy 100 100 case "column-taxonomy" : … … 102 102 $tags = get_the_terms($post_id, $tax); 103 103 $tarr = array(); 104 104 105 105 // for post formats we will display standard instead of empty 106 106 if ( $tax == 'post_format' && empty($tags) ) { 107 107 $result = __('Standard'); 108 108 } 109 109 110 110 // add name with link 111 elseif ( !empty($tags) ) { 111 elseif ( !empty($tags) ) { 112 112 $post_type = get_post_type($post_id); 113 113 foreach($tags as $tag) { … … 119 119 } 120 120 $result = implode(', ', $tarr); 121 } 122 break; 123 121 } 122 break; 123 124 124 // Custom Field 125 125 case "column-post-meta" : 126 $result = $this->get_column_value_custom_field($post_id, $column_name, 'post'); 127 break; 128 126 $result = $this->get_column_value_custom_field($post_id, $column_name, 'post'); 127 break; 128 129 129 // Attachment 130 130 case "column-attachment" : 131 131 $result = $this->get_column_value_attachments($post_id); 132 132 break; 133 133 134 134 // Attachment count 135 135 case "column-attachment-count" : 136 136 $result = count($this->get_attachment_ids($post_id)); 137 137 break; 138 138 139 139 // Roles 140 140 case "column-roles" : … … 144 144 $result = implode(', ',$userdata->roles); 145 145 break; 146 146 147 147 // Post status 148 148 case "column-status" : … … 152 152 $result = $result . " <p class='description'>" . date_i18n( get_option('date_format') . ' ' . get_option('time_format') , strtotime($p->post_date) ) . "</p>"; 153 153 break; 154 154 155 155 // Post comment status 156 156 case "column-comment-status" : … … 160 160 $result = $this->get_asset_image('checkmark.png', $p->comment_status); 161 161 break; 162 162 163 163 // Post ping status 164 164 case "column-ping-status" : … … 168 168 $result = $this->get_asset_image('checkmark.png', $p->ping_status); 169 169 break; 170 170 171 171 // Post actions ( delete, edit etc. ) 172 172 case "column-actions" : 173 173 $result = $this->get_column_value_actions($post_id); 174 174 break; 175 175 176 176 // Post Last modified 177 177 case "column-modified" : … … 179 179 $result = $this->get_date($p->post_modified) . ' ' . $this->get_time($p->post_modified); 180 180 break; 181 181 182 182 // Post Comment count 183 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 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 188 // Author Name 189 189 case "column-author-name" : 190 $result = $this->get_column_value_authorname($post_id, $column_name); 191 break; 192 190 $result = $this->get_column_value_authorname($post_id, $column_name); 191 break; 192 193 193 // Before More Tag 194 194 case "column-before-moretag" : 195 195 $p = get_post($post_id); 196 196 $extended = get_extended($p->post_content); 197 197 198 198 if ( !empty($extended['extended']) ) { 199 199 $result = $this->get_shortened_string($extended['main'], $this->excerpt_length ); 200 200 } 201 201 break; 202 202 203 203 default : 204 204 $result = ''; 205 205 206 206 endswitch; 207 207 208 208 // Filter for customizing the result output 209 209 apply_filters('cpac-posts-column-result', $result, $type, $column_name, $post_id); 210 211 echo $result; 212 } 213 210 211 echo $result; 212 } 213 214 214 /** 215 215 * Returns the friendly name for a given status … … 217 217 * @since 1.4.4 218 218 */ 219 private function get_post_status_friendly_name( $status ) 219 private function get_post_status_friendly_name( $status ) 220 220 { 221 221 $builtin = array( … … 227 227 'trash' => __( 'Trash', CPAC_TEXTDOMAIN ) 228 228 ); 229 229 230 230 if ( isset($builtin[$status]) ) 231 231 $status = $builtin[$status]; 232 233 return $status; 234 } 235 232 233 return $status; 234 } 235 236 236 /** 237 237 * Comment count extended … … 260 260 $details .= "<a href='{$url}' class='cp-trash' title='".__('trash', CPAC_TEXTDOMAIN) . "'>{$c->trash}</a>"; 261 261 } 262 263 if ( $details ) 262 263 if ( $details ) 264 264 return "<p class='description row-actions'>{$details}</p>"; 265 265 266 266 return false; 267 267 } 268 268 269 269 /** 270 270 * Get column value of post actions … … 274 274 * @since 1.4.2 275 275 */ 276 protected function get_column_value_actions( $post_id ) 277 { 276 protected function get_column_value_actions( $post_id ) 277 { 278 278 $actions = array(); 279 279 280 280 $post = get_post($post_id); 281 281 $title = _draft_or_post_title(); 282 282 $post_type_object = get_post_type_object( $post->post_type ); 283 283 $can_edit_post = current_user_can( $post_type_object->cap->edit_post, $post->ID ); 284 284 285 285 if ( $can_edit_post && 'trash' != $post->post_status ) { 286 286 $actions['edit'] = '<a href="' . get_edit_post_link( $post->ID, true ) . '" title="' . esc_attr( __( 'Edit this item' ) ) . '">' . __( 'Edit' ) . '</a>'; … … 302 302 $actions['view'] = '<a href="' . get_permalink( $post->ID ) . '" title="' . esc_attr( sprintf( __( 'View “%s”' ), $title ) ) . '" rel="permalink">' . __( 'View' ) . '</a>'; 303 303 } 304 } 305 304 } 305 306 306 return implode(' | ', $actions); 307 307 } 308 308 309 309 /** 310 310 * Get column value of Custom Field 311 311 * 312 312 * @since 1.4.6.1 313 */ 314 protected function get_column_value_authorname($post_id, $column_name) 315 { 313 */ 314 protected function get_column_value_authorname($post_id, $column_name) 315 { 316 316 $type = get_post_type($post_id); 317 317 318 318 // get column 319 319 $columns = $this->get_stored_columns($type); 320 320 321 321 // get the type of author name 322 322 $display_as = isset($columns[$column_name]['display_as']) ? $columns[$column_name]['display_as'] : ''; 323 323 324 324 // get the author 325 325 $post = get_post($post_id); 326 326 if ( !isset( $post->post_author) ) 327 327 return false; 328 328 329 329 $name = Codepress_Admin_Columns::get_author_field_by_nametype($display_as, $post->post_author); 330 330 331 331 // filter for customization 332 332 $name = apply_filters('cpac_get_column_value_authorname', $name, $column_name, $post_id ); 333 333 334 334 // add link filter 335 335 $class = isset( $_GET['author'] ) && $_GET['author'] == $userdata->ID ? ' class="current"' : ''; 336 336 337 337 $name = "<a href='edit.php?post_type={$type}&author={$post->post_author}'{$class}>{$name}</a>"; 338 338 339 339 return $name; 340 340 } -
codepress-admin-columns/trunk/classes/values/users.php
r637026 r638877 8 8 */ 9 9 class CPAC_Users_Values extends CPAC_Values 10 { 10 { 11 11 /** 12 12 * Constructor … … 17 17 { 18 18 parent::__construct(); 19 19 20 20 add_filter( 'manage_users_custom_column', array( $this, 'manage_users_column_value'), 10, 3 ); 21 21 } 22 22 23 23 /** 24 24 * Manage custom column for Users. … … 29 29 { 30 30 $type = $column_name; 31 31 32 32 $userdata = get_userdata( $user_id ); 33 33 34 34 if ( ! $userdata ) 35 35 return false; 36 36 37 37 // Check for user custom fields: column-meta-[customfieldname] 38 38 if ( $this->is_column_meta($type) ) 39 39 $type = 'column-user-meta'; 40 40 41 41 // Check for post count: column-user_postcount-[posttype] 42 42 if ( Codepress_Admin_Columns::get_posttype_by_postcount_column($type) ) 43 43 $type = 'column-user_postcount'; 44 45 // Hook 44 45 // Hook 46 46 do_action('cpac-manage-users-column', $type, $column_name, $user_id); 47 47 48 48 $result = ''; 49 switch ($type) : 50 49 switch ($type) : 50 51 51 // user id 52 52 case "column-user_id" : 53 53 $result = $user_id; 54 54 break; 55 55 56 56 // first name 57 57 case "column-nickname" : 58 58 $result = $userdata->nickname; 59 59 break; 60 60 61 61 // first name 62 62 case "column-first_name" : 63 63 $result = $userdata->first_name; 64 64 break; 65 65 66 66 // last name 67 67 case "column-last_name" : 68 68 $result = $userdata->last_name; 69 69 break; 70 70 71 71 // user url 72 72 case "column-user_url" : 73 73 $result = $userdata->user_url; 74 74 break; 75 75 76 76 // user registration date 77 77 case "column-user_registered" : 78 78 $result = $userdata->user_registered; 79 79 break; 80 80 81 81 // user description 82 82 case "column-user_description" : 83 83 $result = $this->get_shortened_string( get_the_author_meta('user_description', $user_id), $this->excerpt_length ); 84 84 break; 85 85 86 86 // user description 87 87 case "column-user_postcount" : 88 88 $post_type = Codepress_Admin_Columns::get_posttype_by_postcount_column($column_name); 89 89 90 90 // get post count 91 91 $count = Codepress_Admin_Columns::get_post_count( $post_type, $user_id ); 92 92 93 93 // set result 94 94 $result = $count > 0 ? "<a href='edit.php?post_type={$post_type}&author={$user_id}'>{$count}</a>" : (string) $count; 95 break; 96 95 break; 96 97 97 // user actions 98 98 case "column-actions" : 99 99 $result = $this->get_column_value_actions($user_id, 'users'); 100 100 break; 101 101 102 102 // user meta data ( custom field ) 103 103 case "column-user-meta" : 104 104 $result = $this->get_column_value_custom_field($user_id, $column_name, 'user'); 105 105 break; 106 106 107 107 default : 108 108 $result = $value; 109 109 110 110 endswitch; 111 111 112 112 // Filter for customizing the result output 113 113 apply_filters('cpac-users-column-result', $result, $type, $column_name, $user_id); 114 114 115 115 return $result; 116 116 } 117 117 118 118 /** 119 119 * Get column value of user actions … … 123 123 * @since 1.4.2 124 124 */ 125 private function get_column_value_actions( $id ) 126 { 125 private function get_column_value_actions( $id ) 126 { 127 127 $actions = array(); 128 128 129 129 $user_object = new WP_User( $id ); 130 130 $screen = get_current_screen(); 131 131 132 132 if ( 'site-users-network' == $screen->id ) 133 133 $url = "site-users.php?id={$this->site_id}&"; 134 134 else 135 135 $url = 'users.php?'; 136 136 137 137 if ( get_current_user_id() == $user_object->ID ) { 138 138 $edit_link = 'profile.php'; … … 140 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 141 } 142 142 143 143 if ( current_user_can( 'edit_user', $user_object->ID ) ) { 144 144 $edit = "<strong><a href=\"$edit_link\">$user_object->user_login</a></strong><br />"; … … 152 152 if ( is_multisite() && get_current_user_id() != $user_object->ID && current_user_can( 'remove_user', $user_object->ID ) ) 153 153 $actions['remove'] = "<a class='submitdelete' href='" . wp_nonce_url( $url."action=remove&user=$user_object->ID", 'bulk-users' ) . "'>" . __( 'Remove' ) . "</a>"; 154 154 155 155 return implode(' | ', $actions); 156 156 } -
codepress-admin-columns/trunk/codepress-admin-columns.php
r637684 r638877 3 3 4 4 Plugin Name: Codepress Admin Columns 5 Version: 1.4. 85 Version: 1.4.9 6 6 Description: Customise columns on the administration screens for post(types), pages, media, comments, links and users with an easy to use drag-and-drop interface. 7 7 Author: Codepress … … 28 28 */ 29 29 30 define( 'CPAC_VERSION', '1.4. 8' );30 define( 'CPAC_VERSION', '1.4.9' ); 31 31 define( 'CPAC_TEXTDOMAIN', 'codepress-admin-columns' ); 32 32 define( 'CPAC_SLUG', 'codepress-admin-columns' ); … … 42 42 * @since 1.3 43 43 */ 44 require_once dirname( __FILE__ ) . '/classes/utility.php';45 44 require_once dirname( __FILE__ ) . '/classes/sortable.php'; 46 require_once dirname( __FILE__ ) . '/classes/values.php'; 45 require_once dirname( __FILE__ ) . '/classes/values.php'; 47 46 require_once dirname( __FILE__ ) . '/classes/values/posts.php'; 48 47 require_once dirname( __FILE__ ) . '/classes/values/users.php'; … … 51 50 require_once dirname( __FILE__ ) . '/classes/values/comments.php'; 52 51 require_once dirname( __FILE__ ) . '/classes/license.php'; 52 require_once dirname( __FILE__ ) . '/classes/third_party.php'; 53 53 54 54 /** … … 58 58 * 59 59 */ 60 class Codepress_Admin_Columns 61 { 60 class Codepress_Admin_Columns 61 { 62 62 private $post_types, 63 63 $codepress_url, … … 65 65 $admin_page, 66 66 $use_hidden_custom_fields; 67 67 68 68 /** 69 69 * Constructor … … 72 72 */ 73 73 function __construct() 74 { 74 { 75 75 // wp is loaded 76 76 add_action( 'wp_loaded', array( $this, 'init') ); 77 77 } 78 78 79 79 /** 80 80 * Initialize plugin. … … 91 91 // set 92 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 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 96 // enable the use of custom hidden fields 97 97 $this->use_hidden_custom_fields = apply_filters('cpac_use_hidden_custom_fields', false); 98 98 99 99 // translations 100 100 load_plugin_textdomain( CPAC_TEXTDOMAIN, false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); 101 101 102 102 // register settings 103 add_action( 'admin_menu', array( $this, 'settings_menu') ); 103 add_action( 'admin_menu', array( $this, 'settings_menu') ); 104 104 add_action( 'admin_init', array( $this, 'register_settings') ); 105 105 … … 108 108 add_filter( 'admin_body_class', array( $this, 'admin_class' ) ); 109 109 add_action( 'admin_head', array( $this, 'admin_css') ); 110 110 111 111 // register columns 112 112 add_action( 'admin_init', array( $this, 'register_columns_headings' ) ); 113 add_action( 'admin_init', array( $this, 'register_columns_values' ) ); 114 113 add_action( 'admin_init', array( $this, 'register_columns_values' ) ); 114 115 115 // action ajax 116 116 add_action( 'wp_ajax_cpac_addon_activation', array( $this, 'ajax_activation')); 117 117 118 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 119 add_action( 'admin_init', array( $this, 'handle_requests' ), 1000 ); 120 121 121 // filters 122 add_filter( 'plugin_action_links', array( $this, 'add_settings_link'), 1, 2); 123 } 122 add_filter( 'plugin_action_links', array( $this, 'add_settings_link'), 1, 2); 123 } 124 124 125 125 /** … … 130 130 * @since 1.0 131 131 */ 132 public function settings_menu() 132 public function settings_menu() 133 133 { 134 134 $page = add_options_page( 135 135 // Page title 136 esc_html__( 'Admin Columns Settings', CPAC_TEXTDOMAIN ), 136 esc_html__( 'Admin Columns Settings', CPAC_TEXTDOMAIN ), 137 137 // Menu Title 138 esc_html__( 'Admin Columns', CPAC_TEXTDOMAIN ), 138 esc_html__( 'Admin Columns', CPAC_TEXTDOMAIN ), 139 139 // Capability 140 140 'manage_options', … … 143 143 // Callback 144 144 array( $this, 'plugin_settings_page') 145 ); 145 ); 146 146 147 147 // set admin page 148 148 $this->admin_page = $page; 149 149 150 150 // settings page specific styles and scripts 151 151 add_action( "admin_print_styles-$page", array( $this, 'admin_styles') ); 152 152 add_action( "admin_print_scripts-$page", array( $this, 'admin_scripts') ); 153 153 154 154 // add help tabs 155 155 add_action("load-$page", array( $this, 'help_tabs')); 156 156 } 157 157 158 158 /** 159 159 * Add Settings link to plugin page … … 164 164 * @return string - link to settings page 165 165 */ 166 function add_settings_link( $links, $file ) 166 function add_settings_link( $links, $file ) 167 167 { 168 168 if ( $file != plugin_basename( __FILE__ )) … … 171 171 array_unshift($links, '<a href="' . admin_url("admin.php") . '?page=' . CPAC_SLUG . '">' . __( 'Settings' ) . '</a>'); 172 172 return $links; 173 } 174 175 /** 176 * Register Column Values 173 } 174 175 /** 176 * Register Column Values 177 177 * 178 178 * initializes each Class per type … … 196 196 */ 197 197 public function register_columns_headings() 198 { 199 /** Posts */ 198 { 199 /** Posts */ 200 200 foreach ( $this->post_types as $post_type ) { 201 201 202 202 // register column per post type 203 203 add_filter("manage_edit-{$post_type}_columns", array($this, 'callback_add_posts_column_headings')); 204 } 205 204 } 205 206 206 /** Users */ 207 add_filter( "manage_users_columns", array($this, 'callback_add_users_column_headings'), 9); 207 add_filter( "manage_users_columns", array($this, 'callback_add_users_column_headings'), 9); 208 208 // give higher priority, so it will load just before other plugins to prevent conflicts 209 209 210 210 /** Media */ 211 211 add_filter( "manage_upload_columns", array($this, 'callback_add_media_column_headings')); 212 212 213 213 /** Links */ 214 214 add_filter( "manage_link-manager_columns", array($this, 'callback_add_links_column_headings')); 215 215 216 216 /** Comments */ 217 217 add_filter( "manage_edit-comments_columns", array($this, 'callback_add_comments_column_headings')); 218 218 } 219 219 220 220 /** 221 221 * Callback add Posts Column … … 223 223 * @since 1.0 224 224 */ 225 public function callback_add_posts_column_headings($columns) 226 { 227 return $this->add_columns_headings( get_post_type(), $columns); 228 } 229 225 public function callback_add_posts_column_headings($columns) 226 { 227 return $this->add_columns_headings( get_post_type(), $columns); 228 } 229 230 230 /** 231 231 * Callback add Users column … … 233 233 * @since 1.1 234 234 */ 235 public function callback_add_users_column_headings($columns) 235 public function callback_add_users_column_headings($columns) 236 236 { 237 237 return $this->add_columns_headings('wp-users', $columns); 238 238 } 239 239 240 240 /** 241 241 * Callback add Media column … … 243 243 * @since 1.3 244 244 */ 245 public function callback_add_media_column_headings($columns) 245 public function callback_add_media_column_headings($columns) 246 246 { 247 247 return $this->add_columns_headings('wp-media', $columns); 248 248 } 249 249 250 250 /** 251 251 * Callback add Links column … … 253 253 * @since 1.3.1 254 254 */ 255 public function callback_add_links_column_headings($columns) 255 public function callback_add_links_column_headings($columns) 256 256 { 257 257 return $this->add_columns_headings('wp-links', $columns); 258 258 } 259 259 260 260 /** 261 261 * Callback add Comments column … … 263 263 * @since 1.3.1 264 264 */ 265 public function callback_add_comments_column_headings($columns) 265 public function callback_add_comments_column_headings($columns) 266 266 { 267 267 return $this->add_columns_headings('wp-comments', $columns); 268 268 } 269 270 271 269 270 271 272 272 /** 273 273 * Add managed columns by Type … … 275 275 * @since 1.4.6.5 276 276 */ 277 private function get_comment_icon() 277 private function get_comment_icon() 278 278 { 279 279 return "<span class='vers'><img src='" . trailingslashit( get_admin_url() ) . 'images/comment-grey-bubble.png' . "' alt='Comments'></span>"; 280 280 } 281 281 282 282 /** 283 283 * Add managed columns by Type … … 285 285 * @since 1.1 286 286 */ 287 protected function add_columns_headings( $type, $columns ) 287 protected function add_columns_headings( $type, $columns ) 288 288 { 289 289 // only get stored columns.. the rest we don't need … … 292 292 if ( !$db_columns ) 293 293 return $columns; 294 294 295 295 // filter already loaded columns by plugins 296 296 $set_columns = $this->filter_preset_columns( $type, $columns ); 297 297 298 298 // loop through columns 299 foreach ( $db_columns as $id => $values ) { 299 foreach ( $db_columns as $id => $values ) { 300 300 // is active 301 if ( isset($values['state']) && $values['state'] == 'on' ){ 302 301 if ( isset($values['state']) && $values['state'] == 'on' ){ 302 303 303 $label = $values['label']; 304 304 305 305 // exception for comments 306 306 if( 'comments' == $id ) { 307 307 $label = $this->get_comment_icon(); 308 308 } 309 309 310 310 // register format 311 311 $set_columns[$id] = $label; 312 312 } 313 313 } 314 314 315 315 return $set_columns; 316 316 } 317 317 318 318 /** 319 319 * Filter preset columns. These columns apply either for every post or set by a plugin. … … 321 321 * @since 1.0 322 322 */ 323 private function filter_preset_columns( $type, $columns ) 323 private function filter_preset_columns( $type, $columns ) 324 324 { 325 325 $options = get_option('cpac_options_default'); 326 326 327 327 if ( !$options ) 328 328 return $columns; 329 329 330 330 // we use the wp default columns for filtering... 331 331 $stored_wp_default_columns = $options[$type]; … … 333 333 // ... the ones that are set by plugins, theme functions and such. 334 334 $dif_columns = array_diff(array_keys($columns), array_keys($stored_wp_default_columns)); 335 335 336 336 // we add those to the columns 337 337 $pre_columns = array(); … … 341 341 } 342 342 } 343 343 344 344 return $pre_columns; 345 345 } 346 346 347 347 /** 348 348 * Get a list of Column options per post type … … 350 350 * @since 1.0 351 351 */ 352 private function get_column_boxes($type) 353 { 352 private function get_column_boxes($type) 353 { 354 354 // merge all columns 355 355 $display_columns = $this->get_merged_columns($type); 356 356 357 357 // define 358 $list = ''; 359 358 $list = ''; 359 360 360 // loop throught the active columns 361 361 if ( $display_columns ) { 362 foreach ( $display_columns as $id => $values ) { 363 362 foreach ( $display_columns as $id => $values ) { 363 364 364 $classes = array(); 365 365 366 366 // set state 367 367 $state = isset($values['state']) ? $values['state'] : ''; 368 368 369 369 // class 370 370 $classes[] = "cpac-box-{$id}"; … … 376 376 } 377 377 $class = implode(' ', $classes); 378 379 // more box options 378 379 // more box options 380 380 $more_options = $this->get_additional_box_options($type, $id, $values); 381 381 $action = "<a class='cpac-action' href='#open'>open</a>"; 382 382 383 383 // type label 384 384 $type_label = isset($values['options']['type_label']) ? $values['options']['type_label'] : ''; 385 385 386 386 // label 387 387 $label = isset($values['label']) ? str_replace("'", '"', $values['label']) : ''; 388 388 389 389 // main label 390 $main_label = $values['label']; 391 390 $main_label = $values['label']; 391 392 392 // main label exception for comments 393 393 if ( 'comments' == $id ) { 394 394 $main_label = $this->get_comment_icon(); 395 395 } 396 396 397 397 // width 398 398 $width = isset($values['width']) ? $values['width'] : 0; 399 399 $width_descr = isset($values['width']) && $values['width'] > 0 ? $values['width'] . '%' : __('default', CPAC_TEXTDOMAIN); 400 400 401 401 // hide box options 402 402 $label_hidden = ''; … … 404 404 $label_hidden = ' style="display:none"'; 405 405 } 406 406 407 407 $list .= " 408 408 <li class='{$class}'> 409 409 <div class='cpac-sort-handle'></div> 410 <div class='cpac-type-options'> 410 <div class='cpac-type-options'> 411 411 <div class='cpac-checkbox'></div> 412 412 <input type='hidden' class='cpac-state' name='cpac_options[columns][{$type}][{$id}][state]' value='{$state}'/> … … 417 417 <span>{$type_label}</span> 418 418 </div> 419 <div class='cpac-type-inside'> 419 <div class='cpac-type-inside'> 420 420 <label for='cpac_options-{$type}-{$id}-label'{$label_hidden}>Label: </label> 421 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> 422 <label for='cpac_options-{$type}-{$id}-width'>" . __('Width', CPAC_TEXTDOMAIN) . ":</label> 423 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 424 <div class='description width-decription' title='" . __('default', CPAC_TEXTDOMAIN) . "'>{$width_descr}</div> … … 428 428 </div> 429 429 </li> 430 "; 430 "; 431 431 } 432 432 } 433 433 434 434 // custom field button 435 435 $button_add_column = ''; 436 436 if ( $this->get_meta_by_type($type) ) 437 437 $button_add_column = "<a href='javacript:;' class='cpac-add-customfield-column button'>+ " . __('Add Custom Field Column', CPAC_TEXTDOMAIN) . "</a>"; 438 438 439 439 return " 440 440 <div class='cpac-box'> 441 441 <ul class='cpac-option-list'> 442 {$list} 442 {$list} 443 443 </ul> 444 444 {$button_add_column} 445 <div class='cpac-reorder-msg'>" . __('drag and drop to reorder', CPAC_TEXTDOMAIN) . "</div> 445 <div class='cpac-reorder-msg'>" . __('drag and drop to reorder', CPAC_TEXTDOMAIN) . "</div> 446 446 </div> 447 447 "; … … 453 453 * @since 1.0 454 454 */ 455 protected function get_merged_columns( $type ) 455 protected function get_merged_columns( $type ) 456 456 { 457 457 /** Comments */ … … 460 460 $wp_custom_columns = $this->get_custom_comments_columns(); 461 461 } 462 462 463 463 /** Links */ 464 464 elseif ( $type == 'wp-links' ) { … … 466 466 $wp_custom_columns = $this->get_custom_links_columns(); 467 467 } 468 468 469 469 /** Users */ 470 470 elseif ( $type == 'wp-users' ) { … … 472 472 $wp_custom_columns = $this->get_custom_users_columns(); 473 473 } 474 474 475 475 /** Media */ 476 476 elseif ( $type == 'wp-media' ) { … … 478 478 $wp_custom_columns = $this->get_custom_media_columns(); 479 479 } 480 480 481 481 /** Posts */ 482 482 else { … … 484 484 $wp_custom_columns = $this->get_custom_posts_columns($type); 485 485 } 486 486 487 487 // merge columns 488 488 $display_columns = $this->parse_columns($wp_custom_columns, $wp_default_columns, $type); 489 490 return $display_columns; 491 } 492 489 490 return $display_columns; 491 } 492 493 493 /** 494 494 * Merge the default columns (set by WordPress) and the added custom columns (set by plugins, theme etc.) … … 496 496 * @since 1.3.3 497 497 */ 498 function parse_columns($wp_custom_columns, $wp_default_columns, $type) 498 function parse_columns($wp_custom_columns, $wp_default_columns, $type) 499 499 { 500 500 // merge columns 501 501 $default_columns = wp_parse_args($wp_custom_columns, $wp_default_columns); 502 502 503 503 //get saved database columns 504 504 $db_columns = self::get_stored_columns($type); 505 505 if ( $db_columns ) { 506 506 507 507 // let's remove any unavailable columns.. such as disabled plugins 508 508 $db_columns = $this->remove_unavailable_columns($db_columns, $default_columns); 509 509 510 510 // loop throught the active columns 511 511 foreach ( $db_columns as $id => $values ) { 512 512 513 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']; 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 516 } 517 517 518 518 // add static options 519 519 elseif ( isset($default_columns[$id]['options']) ) 520 520 $db_columns[$id]['options'] = $default_columns[$id]['options']; 521 522 unset($default_columns[$id]); 521 522 unset($default_columns[$id]); 523 523 } 524 } 525 524 } 525 526 526 // merge all 527 527 return wp_parse_args($db_columns, $default_columns); 528 528 } 529 529 530 530 /** 531 531 * Remove deactivated (plugin) columns … … 540 540 // check or differences 541 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 ){ 542 543 if ( ! empty($diff) && is_array($diff) ) { 544 foreach ( $diff as $column_name ){ 545 545 // make an exception for column-meta-xxx 546 546 if ( ! $this->is_column_meta($column_name) ) { … … 549 549 } 550 550 } 551 551 552 552 return $db_columns; 553 553 } 554 554 555 555 /** 556 556 * Get checkbox … … 558 558 * @since 1.0 559 559 */ 560 private function get_box($type, $id, $values) 560 private function get_box($type, $id, $values) 561 561 { 562 562 $classes = array(); … … 564 564 // set state 565 565 $state = isset($values['state']) ? $values['state'] : ''; 566 566 567 567 // class 568 568 $classes[] = "cpac-box-{$id}"; … … 574 574 } 575 575 $class = implode(' ', $classes); 576 577 // more box options 576 577 // more box options 578 578 $more_options = $this->get_additional_box_options($type, $id, $values); 579 579 $action = "<a class='cpac-action' href='#open'>open</a>"; 580 580 581 581 // type label 582 582 $type_label = isset($values['options']['type_label']) ? $values['options']['type_label'] : ''; 583 583 584 584 // label 585 585 $label = isset($values['label']) ? str_replace("'", '"', $values['label']) : ''; 586 586 587 587 // main label 588 $main_label = $values['label']; 589 588 $main_label = $values['label']; 589 590 590 // main label exception for comments 591 591 if ( 'comments' == $id ) { 592 592 $main_label = $this->get_comment_icon(); 593 593 } 594 594 595 595 // width 596 596 $width = isset($values['width']) ? $values['width'] : 0; 597 597 $width_descr = isset($values['width']) && $values['width'] > 0 ? $values['width'] . '%' : __('default', CPAC_TEXTDOMAIN); 598 598 599 599 // hide box options 600 600 $label_hidden = ''; … … 602 602 $label_hidden = ' style="display:none"'; 603 603 } 604 604 605 605 $list = " 606 606 <li class='{$class}'> 607 607 <div class='cpac-sort-handle'></div> 608 <div class='cpac-type-options'> 608 <div class='cpac-type-options'> 609 609 <div class='cpac-checkbox'></div> 610 610 <input type='hidden' class='cpac-state' name='cpac_options[columns][{$type}][{$id}][state]' value='{$state}'/> … … 615 615 <span>{$type_label}</span> 616 616 </div> 617 <div class='cpac-type-inside'> 617 <div class='cpac-type-inside'> 618 618 <label for='cpac_options-{$type}-{$id}-label'{$label_hidden}>Label: </label> 619 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> 620 <label for='cpac_options-{$type}-{$id}-width'>" . __('Width', CPAC_TEXTDOMAIN) . ":</label> 621 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 622 <div class='description width-decription' title='" . __('default', CPAC_TEXTDOMAIN) . "'>{$width_descr}</div> … … 627 627 </li> 628 628 "; 629 629 630 630 return $list; 631 631 } … … 636 636 * @since 1.0 637 637 */ 638 private function get_additional_box_options($type, $id, $values) 638 private function get_additional_box_options($type, $id, $values) 639 639 { 640 640 $fields = ''; 641 641 642 642 // Custom Fields 643 643 if( $this->is_column_meta($id) ) { 644 644 $fields = $this->get_box_options_customfields($type, $id, $values); 645 645 } 646 646 647 647 // Author Fields 648 648 if( 'column-author-name' == $id) { 649 649 $fields = $this->get_box_options_author($type, $id, $values); 650 650 } 651 651 652 652 return $fields; 653 653 } … … 658 658 * @since 1.0 659 659 */ 660 private function get_box_options_customfields($type, $id, $values) 661 { 662 // get post meta fields 660 private function get_box_options_customfields($type, $id, $values) 661 { 662 // get post meta fields 663 663 $fields = $this->get_meta_by_type($type); 664 665 if ( empty($fields) ) 664 665 if ( empty($fields) ) 666 666 return false; 667 667 668 668 // set meta field options 669 669 $current = ! empty($values['field']) ? $values['field'] : '' ; 670 670 $field_options = ''; 671 671 foreach ($fields as $field) { 672 672 673 673 $field_options .= sprintf 674 674 ( … … 676 676 $field, 677 677 $field == $current? ' selected="selected"':'', 678 678 679 679 // change label on hidden fields 680 substr($field,0,10) == "cpachidden" ? str_replace('cpachidden','',$field) : $field 681 ); 682 } 683 680 substr($field,0,10) == "cpachidden" ? str_replace('cpachidden','',$field) : $field 681 ); 682 } 683 684 684 // set meta fieldtype options 685 685 $currenttype = ! empty($values['field_type']) ? $values['field_type'] : '' ; … … 698 698 'color' => __('Color', CPAC_TEXTDOMAIN), 699 699 ); 700 700 701 701 // add filter 702 702 $fieldtypes = apply_filters('cpac-field-types', $fieldtypes ); 703 703 704 704 // set select options 705 705 foreach ( $fieldtypes as $fkey => $fieldtype ) { … … 712 712 ); 713 713 } 714 714 715 715 // before and after string 716 716 $before = ! empty($values['before']) ? $values['before'] : '' ; 717 717 $after = ! empty($values['after']) ? $values['after'] : '' ; 718 718 719 719 if ( empty($field_options) ) 720 720 return false; 721 721 722 722 // add remove button 723 723 $remove = '<p class="remove-description description">'.__('This field can not be removed', CPAC_TEXTDOMAIN).'</p>'; … … 729 729 "; 730 730 } 731 731 732 732 $inside = " 733 733 <label for='cpac-{$type}-{$id}-field'>".__('Custom Field', CPAC_TEXTDOMAIN).": </label> … … 738 738 <br/> 739 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/> 740 <input type='text' class='cpac-before' name='cpac_options[columns][{$type}][{$id}][before]' id='cpac-{$type}-{$id}-before' value='{$before}'/> 741 <br/> 742 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/> 743 <input type='text' class='cpac-after' name='cpac_options[columns][{$type}][{$id}][after]' id='cpac-{$type}-{$id}-after' value='{$after}'/> 744 <br/> 745 745 {$remove} 746 746 "; 747 747 748 748 return $inside; 749 749 } 750 750 751 751 /** 752 752 * Box Options: Custom Fields … … 754 754 * @since 1.0 755 755 */ 756 private function get_box_options_author($type, $id, $values) 756 private function get_box_options_author($type, $id, $values) 757 757 { 758 758 $options = ''; … … 772 772 $options .= "<option value='{$k}' {$selected}>{$name}</option>"; 773 773 } 774 774 775 775 $inside = " 776 776 <label for='cpac-{$type}-{$id}-display_as'>".__('Display name as', CPAC_TEXTDOMAIN).": </label> 777 777 <select name='cpac_options[columns][{$type}][{$id}][display_as]' id='cpac-{$type}-{$id}-display_as'> 778 778 {$options} 779 </select> 779 </select> 780 780 "; 781 781 782 782 return $inside; 783 783 } … … 788 788 * @since 1.0 789 789 */ 790 private function get_meta_by_type($type = 'post') 790 private function get_meta_by_type($type = 'post') 791 791 { 792 792 global $wpdb; … … 796 796 $sql = "SELECT DISTINCT meta_key FROM {$wpdb->commentmeta} ORDER BY 1"; 797 797 } 798 798 799 799 /** Users */ 800 800 elseif ( $type == 'wp-users') { 801 801 $sql = "SELECT DISTINCT meta_key FROM {$wpdb->usermeta} ORDER BY 1"; 802 802 } 803 803 804 804 /** Media */ 805 805 elseif ( $type == 'wp-media') { 806 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 807 } 808 808 809 809 /** Posts */ 810 810 else { 811 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 812 } 813 813 814 814 // run sql 815 815 $fields = $wpdb->get_results($sql, ARRAY_N); 816 816 817 817 // filter out hidden meta fields 818 818 $meta_fields = array(); 819 if ( $fields ) { 819 if ( $fields ) { 820 820 foreach ($fields as $field) { 821 821 822 822 // give hidden fields a prefix for identifaction 823 823 if ( $this->use_hidden_custom_fields && substr($field[0],0,1) == "_") { 824 824 $meta_fields[] = 'cpachidden'.$field[0]; 825 825 } 826 826 827 827 // non hidden fields are saved as is 828 828 elseif ( substr($field[0],0,1) != "_" ) { 829 829 $meta_fields[] = $field[0]; 830 } 831 } 832 } 833 834 if ( !empty($meta_fields) )835 return $meta_fields;836 837 return false;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 838 } 839 839 … … 843 843 * @since 1.0 844 844 */ 845 public function admin_scripts() 845 public function admin_scripts() 846 846 { 847 847 wp_enqueue_script( 'wp-pointer' ); 848 wp_enqueue_script( 'jquery-ui-slider' ); 848 wp_enqueue_script( 'jquery-ui-slider' ); 849 849 wp_enqueue_script( 'cpac-qtip2', CPAC_URL.'/assets/js/jquery.qtip.js', array('jquery'), CPAC_VERSION ); 850 850 wp_enqueue_script( 'cpac-admin', CPAC_URL.'/assets/js/admin-column.js', array('jquery', 'dashboard', 'jquery-ui-sortable'), CPAC_VERSION ); 851 } 852 851 } 852 853 853 /** 854 854 * Get column types … … 863 863 $types['wp-links'] = 'wp-links'; 864 864 $types['wp-comments'] = 'wp-comments'; 865 865 866 866 return $types; 867 867 } 868 868 869 869 /** 870 870 * Get post types … … 879 879 $post_types['post'] = 'post'; 880 880 $post_types['page'] = 'page'; 881 881 882 882 return apply_filters('cpac-get-post-types', $post_types); 883 883 } … … 891 891 { 892 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 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 897 /** 898 898 * Register column css … … 902 902 public function column_styles() 903 903 { 904 wp_enqueue_style( 'cpac-columns', CPAC_URL.'/assets/css/column.css', array(), CPAC_VERSION, 'all' ); 904 wp_enqueue_style( 'cpac-columns', CPAC_URL.'/assets/css/column.css', array(), CPAC_VERSION, 'all' ); 905 905 } 906 906 … … 910 910 * @since 1.0 911 911 */ 912 public function register_settings() 912 public function register_settings() 913 913 { 914 914 // If we have no options in the database, let's add them now. … … 916 916 add_option( 'cpac_options', $this->get_default_plugin_options() ); 917 917 } 918 918 919 919 register_setting( 'cpac-settings-group', 'cpac_options', array($this, 'options_callback') ); 920 } 920 } 921 921 922 922 /** … … 925 925 * @since 1.0 926 926 */ 927 public function get_default_plugin_options() 927 public function get_default_plugin_options() 928 928 { 929 929 return apply_filters( 'cpac_default_plugin_options', array() ); … … 936 936 */ 937 937 public function options_callback($options) 938 { 938 { 939 939 return $options; 940 940 } … … 945 945 * @since 1.0 946 946 */ 947 public function handle_requests() 947 public function handle_requests() 948 948 { 949 949 // only handle updates from the admin columns page 950 950 if ( isset($_REQUEST['page']) && CPAC_SLUG == $_REQUEST['page'] ) { 951 951 952 952 // settings updated 953 953 if ( ! empty($_REQUEST['settings-updated']) ) { 954 954 $this->store_wp_default_columns(); 955 955 } 956 957 // restore defaults 956 957 // restore defaults 958 958 if ( ! empty($_REQUEST['cpac-restore-defaults']) ) { 959 959 $this->restore_defaults(); … … 961 961 } 962 962 } 963 963 964 964 /** 965 965 * Stores WP default columns … … 969 969 * @since 1.2 970 970 */ 971 private function store_wp_default_columns() 972 { 971 private function store_wp_default_columns() 972 { 973 973 // stores the default columns that are set by WP or theme. 974 974 $wp_default_columns = array(); 975 975 976 976 // Posts 977 977 foreach ( $this->post_types as $post_type ) { 978 978 $wp_default_columns[$post_type] = $this->get_wp_default_posts_columns($post_type); 979 979 } 980 980 981 981 // Users 982 982 $wp_default_columns['wp-users'] = $this->get_wp_default_users_columns(); 983 983 984 984 // Media 985 985 $wp_default_columns['wp-media'] = $this->get_wp_default_media_columns(); 986 986 987 987 // Links 988 988 $wp_default_columns['wp-links'] = $this->get_wp_default_links_columns(); 989 989 990 990 // Comments 991 $wp_default_columns['wp-comments'] = $this->get_wp_default_comments_columns(); 992 991 $wp_default_columns['wp-comments'] = $this->get_wp_default_comments_columns(); 992 993 993 update_option( 'cpac_options_default', $wp_default_columns ); 994 994 } … … 999 999 * @since 1.0 1000 1000 */ 1001 private function restore_defaults() 1002 { 1001 private function restore_defaults() 1002 { 1003 1003 delete_option( 'cpac_options' ); 1004 delete_option( 'cpac_options_default' ); 1005 } 1006 1004 delete_option( 'cpac_options_default' ); 1005 } 1006 1007 1007 /** 1008 1008 * Get author field by nametype … … 1015 1015 { 1016 1016 $userdata = get_userdata( $user_id ); 1017 1017 1018 1018 switch ( $nametype ) : 1019 1019 1020 1020 case "display_name" : 1021 1021 $name = $userdata->display_name; 1022 1022 break; 1023 1023 1024 1024 case "first_name" : 1025 1025 $name = $userdata->first_name; 1026 break; 1027 1026 break; 1027 1028 1028 case "last_name" : 1029 1029 $name = $userdata->last_name; 1030 1030 break; 1031 1031 1032 1032 case "first_last_name" : 1033 1033 $first = !empty($userdata->first_name) ? $userdata->first_name : ''; … … 1035 1035 $name = $first.$last; 1036 1036 break; 1037 1037 1038 1038 case "nickname" : 1039 1039 $name = $userdata->nickname; 1040 break; 1041 1040 break; 1041 1042 1042 case "username" : 1043 1043 $name = $userdata->user_login; 1044 1044 break; 1045 1045 1046 1046 case "email" : 1047 1047 $name = $userdata->user_email; 1048 1048 break; 1049 1049 1050 1050 case "userid" : 1051 1051 $name = $userdata->ID; 1052 1052 break; 1053 1053 1054 1054 default : 1055 1055 $name = $userdata->display_name; 1056 1056 1057 1057 endswitch; 1058 1058 1059 1059 return $name; 1060 1060 } 1061 1061 1062 1062 /** 1063 1063 * Get WP default supported admin columns per post type. … … 1065 1065 * @since 1.0 1066 1066 */ 1067 private function get_wp_default_posts_columns($post_type = 'post') 1068 { 1069 // we need to change the current screen 1070 global $current_screen; 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 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 1085 1072 // some plugins directly hook into get_column_headers, such as woocommerce 1086 1073 $columns = get_column_headers( 'edit-'.$post_type ); 1087 1088 // get default columns 1089 if ( empty($columns) ) { 1090 1074 1075 // get default columns 1076 if ( empty($columns) ) { 1077 1091 1078 // deprecated as of wp3.3 1092 1079 if ( file_exists(ABSPATH . 'wp-admin/includes/template.php') ) 1093 1080 require_once(ABSPATH . 'wp-admin/includes/template.php'); 1094 1081 1095 1082 // introduced since wp3.3 1096 1083 if ( file_exists(ABSPATH . 'wp-admin/includes/screen.php') ) 1097 1084 require_once(ABSPATH . 'wp-admin/includes/screen.php'); 1098 1085 1099 1086 // used for getting columns 1100 1087 if ( file_exists(ABSPATH . 'wp-admin/includes/class-wp-list-table.php') ) … … 1102 1089 if ( file_exists(ABSPATH . 'wp-admin/includes/class-wp-posts-list-table.php') ) 1103 1090 require_once(ABSPATH . 'wp-admin/includes/class-wp-posts-list-table.php'); 1104 1091 1105 1092 // As of WP Release 3.5 we can use the following. 1106 1093 if ( version_compare( get_bloginfo('version'), '3.4.10', '>=' ) ) { 1107 1094 1108 1095 $table = new WP_Posts_List_Table( array( 'screen' => $post_type ) ); 1109 1096 $columns = $table->get_columns(); 1110 1097 } 1111 1098 1112 1099 // WP versions older then 3.5 1113 1100 // @todo: make this deprecated 1114 else { 1115 1101 else { 1102 1116 1103 // we need to change the current screen... first lets save original 1117 1104 $org_current_screen = $current_screen; 1118 1119 // prevent php warning 1105 1106 // prevent php warning 1120 1107 if ( !isset($current_screen) ) $current_screen = new stdClass; 1121 1108 1122 1109 // overwrite current_screen global with our post type of choose... 1123 1110 $current_screen->post_type = $post_type; 1124 1125 // ...so we can get its columns 1126 $columns = WP_Posts_List_Table::get_columns(); 1127 1111 1112 // ...so we can get its columns 1113 $columns = WP_Posts_List_Table::get_columns(); 1114 1128 1115 // reset current screen 1129 1116 $current_screen = $org_current_screen; 1130 1117 } 1131 1118 } 1132 1119 1133 1120 if ( empty ( $columns ) ) 1134 1121 return false; 1135 1122 1136 1123 // change to uniform format 1137 $columns = $this->get_uniform_format($columns); 1124 $columns = $this->get_uniform_format($columns); 1138 1125 1139 1126 // add sorting to some of the default links columns 1140 1127 $columns = $this->set_sorting_to_default_posts_columns($columns); 1141 1128 1142 1129 return $columns; 1143 1130 } 1144 1131 1145 1132 /** 1146 1133 * Add Sorting to WP default Posts columns … … 1149 1136 */ 1150 1137 private function set_sorting_to_default_posts_columns($columns) 1151 { 1138 { 1152 1139 // categories 1153 1140 if ( !empty($columns['categories']) ) { … … 1160 1147 return $columns; 1161 1148 } 1162 1149 1163 1150 /** 1164 1151 * Get WP default users columns per post type. … … 1168 1155 private function get_wp_default_users_columns() 1169 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 1170 1160 if ( file_exists(ABSPATH . 'wp-admin/includes/class-wp-list-table.php') ) 1171 1161 require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php'); 1172 1162 if ( file_exists(ABSPATH . 'wp-admin/includes/class-wp-users-list-table.php') ) 1173 1163 require_once(ABSPATH . 'wp-admin/includes/class-wp-users-list-table.php'); 1174 1164 1175 1165 // turn off site users 1176 1166 $this->is_site_users = false; 1177 1167 1178 1168 // get users columns 1179 1169 $columns = WP_Users_List_Table::get_columns(); 1180 1170 1181 1171 // change to uniform format 1182 1172 $columns = $this->get_uniform_format($columns); … … 1184 1174 return apply_filters('cpac-default-users-columns', $columns); 1185 1175 } 1186 1176 1187 1177 /** 1188 1178 * Get WP default media columns. … … 1191 1181 */ 1192 1182 private function get_wp_default_media_columns() 1193 { 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 1194 1187 // @todo could use _get_list_table('WP_Media_List_Table') ? 1195 1188 if ( file_exists(ABSPATH . 'wp-admin/includes/class-wp-list-table.php') ) … … 1197 1190 if ( file_exists(ABSPATH . 'wp-admin/includes/class-wp-media-list-table.php') ) 1198 1191 require_once(ABSPATH . 'wp-admin/includes/class-wp-media-list-table.php'); 1199 1192 1200 1193 // As of WP Release 3.5 we can use the following. 1201 1194 if ( version_compare( get_bloginfo('version'), '3.4.10', '>=' ) ) { 1202 1195 1203 1196 $table = new WP_Media_List_Table(array( 'screen' => 'upload' )); 1204 1197 $columns = $table->get_columns(); 1205 1198 } 1206 1199 1207 1200 // WP versions older then 3.5 1208 1201 // @todo: make this deprecated 1209 else { 1210 1202 else { 1203 1211 1204 global $current_screen; 1212 1205 1213 1206 // save original 1214 1207 $org_current_screen = $current_screen; 1215 1216 // prevent php warning 1208 1209 // prevent php warning 1217 1210 if ( !isset($current_screen) ) $current_screen = new stdClass; 1218 1211 1219 1212 // overwrite current_screen global with our media id... 1220 1213 $current_screen->id = 'upload'; 1221 1214 1222 1215 // init media class 1223 1216 $wp_media = new WP_Media_List_Table; 1224 1225 // get media columns 1217 1218 // get media columns 1226 1219 $columns = $wp_media->get_columns(); 1227 1220 1228 1221 // reset current screen 1229 1222 $current_screen = $org_current_screen; 1230 1223 } 1231 1224 1232 1225 // change to uniform format 1233 1226 $columns = $this->get_uniform_format($columns); 1234 1227 1235 1228 return apply_filters('cpac-default-media-columns', $columns); 1236 1229 } 1237 1230 1238 1231 /** 1239 1232 * Get WP default links columns. … … 1243 1236 private function get_wp_default_links_columns() 1244 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 1245 1241 // dependencies 1246 1242 if ( file_exists(ABSPATH . 'wp-admin/includes/class-wp-list-table.php') ) … … 1248 1244 if ( file_exists(ABSPATH . 'wp-admin/includes/class-wp-links-list-table.php') ) 1249 1245 require_once(ABSPATH . 'wp-admin/includes/class-wp-links-list-table.php'); 1250 1246 1251 1247 // get links columns 1252 1248 $columns = WP_Links_List_Table::get_columns(); … … 1254 1250 // change to uniform format 1255 1251 $columns = $this->get_uniform_format($columns); 1256 1252 1257 1253 // add sorting to some of the default links columns 1258 1254 $columns = $this->set_sorting_to_default_links_columns($columns); 1259 1255 1260 1256 return apply_filters('cpac-default-links-columns', $columns); 1261 1257 } 1262 1258 1263 1259 /** 1264 1260 * Add Sorting to WP default links columns … … 1274 1270 return $columns; 1275 1271 } 1276 1272 1277 1273 /** 1278 1274 * Get WP default links columns. … … 1281 1277 */ 1282 1278 private function get_wp_default_comments_columns() 1283 { 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 1284 1283 // dependencies 1285 1284 if ( file_exists(ABSPATH . 'wp-admin/includes/class-wp-list-table.php') ) … … 1287 1286 if ( file_exists(ABSPATH . 'wp-admin/includes/class-wp-comments-list-table.php') ) 1288 1287 require_once(ABSPATH . 'wp-admin/includes/class-wp-comments-list-table.php'); 1289 1288 1290 1289 // As of WP Release 3.5 we can use the following. 1291 1290 if ( version_compare( get_bloginfo('version'), '3.4.10', '>=' ) ) { 1292 1291 1293 1292 $table = new WP_Comments_List_Table( array( 'screen' => 'edit-comments' ) ); 1294 1293 $columns = $table->get_columns(); 1295 1294 } 1296 1295 1297 1296 // WP versions older then 3.5 1298 1297 // @todo: make this deprecated 1299 1298 else { 1300 1299 1301 1300 global $current_screen; 1302 1301 1303 // save original 1302 // save original 1304 1303 $org_current_screen = $current_screen; 1305 1306 // prevent php warning 1304 1305 // prevent php warning 1307 1306 if ( !isset($current_screen) ) $current_screen = new stdClass; 1308 1307 1309 1308 // overwrite current_screen global with our media id... 1310 1309 $current_screen->id = 'edit-comments'; 1311 1310 1312 1311 // init table object 1313 $wp_comment = new WP_Comments_List_Table; 1314 1312 $wp_comment = new WP_Comments_List_Table; 1313 1315 1314 // get comments 1316 1315 $columns = $wp_comment->get_columns(); 1317 1316 1318 1317 // reset current screen 1319 1318 $current_screen = $org_current_screen; 1320 1319 } 1321 1320 1322 1321 // change to uniform format 1323 1322 $columns = $this->get_uniform_format($columns); 1324 1323 1325 1324 // add sorting to some of the default links columns 1326 1325 $columns = $this->set_sorting_to_default_comments_columns($columns); 1327 1326 1328 1327 return apply_filters('cpac-default-comments-columns', $columns); 1329 1328 } 1330 1329 1331 1330 /** 1332 1331 * Add Sorting to WP default comments columns … … 1348 1347 * @since 1.0 1349 1348 */ 1350 private function get_uniform_format($columns) 1351 { 1352 // we remove the checkbox column as an option... 1349 private function get_uniform_format($columns) 1350 { 1351 // we remove the checkbox column as an option... 1353 1352 if ( isset($columns['cb']) ) 1354 1353 unset($columns['cb']); 1355 1354 1356 1355 // change to uniform format 1357 1356 $uniform_columns = array(); … … 1359 1358 $hide_options = false; 1360 1359 $type_label = $label; 1361 1362 // comment exception 1363 if ( 'comments' == $id ) { 1360 1361 // comment exception 1362 if ( 'comments' == $id ) { 1364 1363 $label = ''; 1365 1364 $type_label = __('Comments', CPAC_TEXTDOMAIN); 1366 1365 $hide_options = true; 1367 1366 } 1368 1367 1369 1368 // user icon exception 1370 1369 if ( $id == 'icon' ) { 1371 1370 $type_label = __('Icon', CPAC_TEXTDOMAIN); 1372 1371 } 1373 1372 1374 1373 $uniform_columns[$id] = array( 1375 1374 'label' => $label, … … 1384 1383 return $uniform_columns; 1385 1384 } 1386 1385 1387 1386 /** 1388 1387 * Custom posts columns … … 1390 1389 * @since 1.0 1391 1390 */ 1392 private function get_custom_posts_columns($post_type) 1391 private function get_custom_posts_columns($post_type) 1393 1392 { 1394 1393 $custom_columns = array( … … 1446 1445 ), 1447 1446 'column-before-moretag' => array( 1448 'label' => __('Before More Tag', CPAC_TEXTDOMAIN) 1447 'label' => __('Before More Tag', CPAC_TEXTDOMAIN) 1449 1448 ) 1450 1449 ); 1451 1450 1452 1451 // Word count support 1453 1452 if ( post_type_supports($post_type, 'editor') ) { … … 1456 1455 ); 1457 1456 } 1458 1457 1459 1458 // Sticky support 1460 if ( $post_type == 'post' ) { 1459 if ( $post_type == 'post' ) { 1461 1460 $custom_columns['column-sticky'] = array( 1462 1461 'label' => __('Sticky', CPAC_TEXTDOMAIN) 1463 1462 ); 1464 1463 } 1465 1464 1466 1465 // Order support 1467 1466 if ( post_type_supports($post_type, 'page-attributes') ) { 1468 1467 $custom_columns['column-order'] = array( 1469 'label' => __('Page Order', CPAC_TEXTDOMAIN), 1468 'label' => __('Page Order', CPAC_TEXTDOMAIN), 1470 1469 'options' => array( 1471 1470 'type_label' => __('Order', CPAC_TEXTDOMAIN) 1472 ) 1471 ) 1473 1472 ); 1474 1473 } 1475 1474 1476 1475 // Page Template 1477 if ( $post_type == 'page' ) { 1476 if ( $post_type == 'page' ) { 1478 1477 $custom_columns['column-page-template'] = array( 1479 1478 'label' => __('Page Template', CPAC_TEXTDOMAIN) 1480 ); 1481 } 1482 1479 ); 1480 } 1481 1483 1482 // Post Formats 1484 1483 if ( post_type_supports($post_type, 'post-formats') ) { … … 1487 1486 ); 1488 1487 } 1489 1488 1490 1489 // Taxonomy support 1491 1490 $taxonomies = get_object_taxonomies($post_type, 'objects'); … … 1499 1498 'type_label' => __('Taxonomy', CPAC_TEXTDOMAIN) 1500 1499 ) 1501 ); 1500 ); 1502 1501 } 1503 1502 } 1504 1503 } 1505 1504 1506 1505 // Custom Field support 1507 1506 if ( $this->get_meta_by_type($post_type) ) { … … 1515 1514 'type_label' => __('Field', CPAC_TEXTDOMAIN), 1516 1515 'class' => 'cpac-box-metafield' 1517 ) 1516 ) 1518 1517 ); 1519 } 1520 1518 } 1519 1521 1520 // merge with defaults 1522 1521 $custom_columns = $this->parse_defaults($custom_columns); 1523 1522 1524 1523 return apply_filters('cpac-custom-posts-columns', $custom_columns); 1525 1524 } 1526 1525 1527 1526 /** 1528 1527 * Custom users columns … … 1530 1529 * @since 1.1 1531 1530 */ 1532 private function get_custom_users_columns() 1531 private function get_custom_users_columns() 1533 1532 { 1534 1533 $custom_columns = array( … … 1561 1560 ), 1562 1561 ); 1563 1562 1564 1563 // User total number of posts 1565 1564 foreach ( self::get_post_types() as $post_type ) { … … 1572 1571 ); 1573 1572 } 1574 1573 1575 1574 // Custom Field support 1576 1575 $custom_columns['column-meta-1'] = array( … … 1584 1583 'class' => 'cpac-box-metafield' 1585 1584 ) 1586 ); 1587 1585 ); 1586 1588 1587 // merge with defaults 1589 1588 $custom_columns = $this->parse_defaults($custom_columns); 1590 1589 1591 1590 return apply_filters('cpac-custom-users-columns', $custom_columns); 1592 1591 } 1593 1592 1594 1593 /** 1595 1594 * Custom media columns … … 1597 1596 * @since 1.3 1598 1597 */ 1599 private function get_custom_media_columns() 1598 private function get_custom_media_columns() 1600 1599 { 1601 1600 $custom_columns = array( … … 1641 1640 'column-filesize' => array( 1642 1641 'label' => __('File size', CPAC_TEXTDOMAIN) 1643 ) 1642 ) 1644 1643 ); 1645 1644 1646 1645 // Get extended image metadata, exif or iptc as available. 1647 1646 // uses exif_read_data() … … 1710 1709 )); 1711 1710 } 1712 1711 1713 1712 // Custom Field support 1714 1713 if ( $this->get_meta_by_type('wp-media') ) { … … 1725 1724 ); 1726 1725 } 1727 1726 1728 1727 // merge with defaults 1729 1728 $custom_columns = $this->parse_defaults($custom_columns); 1730 1729 1731 1730 return apply_filters('cpac-custom-media-columns', $custom_columns); 1732 1731 } 1733 1732 1734 1733 /** 1735 1734 * Custom links columns … … 1737 1736 * @since 1.3.1 1738 1737 */ 1739 private function get_custom_links_columns() 1738 private function get_custom_links_columns() 1740 1739 { 1741 1740 $custom_columns = array( … … 1769 1768 'sortorder' => false 1770 1769 ) 1771 ) 1772 ); 1773 1770 ) 1771 ); 1772 1774 1773 // merge with defaults 1775 1774 $custom_columns = $this->parse_defaults($custom_columns); 1776 1775 1777 1776 return apply_filters('cpac-custom-links-columns', $custom_columns); 1778 1777 } 1779 1778 1780 1779 /** 1781 1780 * Custom comments columns … … 1783 1782 * @since 1.3.1 1784 1783 */ 1785 private function get_custom_comments_columns() 1784 private function get_custom_comments_columns() 1786 1785 { 1787 1786 $custom_columns = array( … … 1805 1804 ), 1806 1805 'column-reply_to' => array( 1807 'label' => __('In Reply To', CPAC_TEXTDOMAIN), 1808 'options' => array( 1806 'label' => __('In Reply To', CPAC_TEXTDOMAIN), 1807 'options' => array( 1809 1808 'sortorder' => false 1810 1809 ) … … 1837 1836 ) 1838 1837 ) 1839 ); 1840 1838 ); 1839 1841 1840 // Custom Field support 1842 1841 if ( $this->get_meta_by_type('wp-comments') ) { … … 1853 1852 ) 1854 1853 ); 1855 } 1856 1854 } 1855 1857 1856 // merge with defaults 1858 1857 $custom_columns = $this->parse_defaults($custom_columns); 1859 1858 1860 1859 return apply_filters('cpac-custom-comments-columns', $custom_columns); 1861 1860 } 1862 1861 1863 1862 /** 1864 1863 * Parse defaults … … 1866 1865 * @since 1.1 1867 1866 */ 1868 private function parse_defaults($columns) 1867 private function parse_defaults($columns) 1869 1868 { 1870 1869 // default arguments 1871 $defaults = array( 1872 1870 $defaults = array( 1871 1873 1872 // stored values 1874 1873 'label' => '', // custom label 1875 1874 'state' => '', // display state 1876 'width' => '', // column width 1877 1875 'width' => '', // column width 1876 1878 1877 // static values 1879 'options' => array( 1878 'options' => array( 1880 1879 'type_label' => __('Custom', CPAC_TEXTDOMAIN), 1881 1880 'hide_options' => false, … … 1884 1883 ) 1885 1884 ); 1886 1885 1887 1886 // parse args 1888 1887 foreach ( $columns as $k => $column ) { 1889 1888 $c[$k] = wp_parse_args( $column, $defaults); 1890 1889 1891 1890 // parse options args 1892 1891 if ( isset($column['options']) ) 1893 1892 $c[$k]['options'] = wp_parse_args( $column['options'], $defaults['options']); 1894 1893 1895 1894 // set type label 1896 1895 if ( empty($column['options']['type_label']) && !empty($column['label']) ) 1897 1896 $c[$k]['options']['type_label'] = $column['label']; 1898 1897 } 1899 1898 1900 1899 return $c; 1901 1900 } … … 1907 1906 */ 1908 1907 public static function get_stored_columns($type) 1909 { 1908 { 1910 1909 // get plugin options 1911 1910 $options = get_option('cpac_options'); … … 1914 1913 if ( !empty($options['columns'][$type]) ) 1915 1914 return $options['columns'][$type]; 1916 1915 1917 1916 return false; 1918 1917 } … … 1923 1922 * @since 1.0 1924 1923 */ 1925 private function get_menu() 1924 private function get_menu() 1926 1925 { 1927 1926 // set 1928 1927 $menu = ''; 1929 1928 $count = 1; 1930 1929 1931 1930 // referer 1932 1931 $referer = ! empty($_REQUEST['cpac_type']) ? $_REQUEST['cpac_type'] : ''; 1933 1932 1934 1933 // loop 1935 1934 foreach ( $this->get_types() as $type ) { 1936 1935 $label = $this->get_singular_name($type); 1937 1936 $clean_label = $this->sanitize_string($type); 1938 1937 1939 1938 // divider 1940 1939 $divider = $count++ == 1 ? '' : ' | '; 1941 1942 // current 1940 1941 // current 1943 1942 $current = ''; 1944 1943 if ( $this->is_menu_type_current($type) ) 1945 1944 $current = ' class="current"'; 1946 1945 1947 1946 // menu list 1948 1947 $menu .= " … … 1950 1949 "; 1951 1950 } 1952 1951 1953 1952 // settings url 1954 1953 $class_current_settings = $this->is_menu_type_current('plugin_settings') ? ' current': ''; 1955 1954 1956 1955 // options button 1957 1956 $options_btn = "<a href='#cpac-box-plugin_settings' class='cpac-settings-link{$class_current_settings}'>".__('Addons', CPAC_TEXTDOMAIN)."</a>"; 1958 1957 //$options_btn = ''; 1959 1958 1960 1959 return " 1961 1960 <div class='cpac-menu'> … … 1973 1972 * @since 1.0 1974 1973 */ 1975 private function is_menu_type_current( $type ) 1976 { 1974 private function is_menu_type_current( $type ) 1975 { 1977 1976 // referer 1978 1977 $referer = ! empty($_REQUEST['cpac_type']) ? $_REQUEST['cpac_type'] : ''; 1979 1978 1980 1979 // get label 1981 1980 $clean_label = $this->sanitize_string($type); 1982 1981 1983 1982 // get first element from post-types 1984 1983 $first = array_shift( array_values($this->post_types) ); 1985 1984 1986 1985 // display the page that was being viewed before saving 1987 1986 if ( $referer ) { … … 1989 1988 return true; 1990 1989 } 1991 1990 1992 1991 // settings page has not yet been saved 1993 1992 } elseif ( $first == $type ) { 1994 1993 return true; 1995 1994 } 1996 1997 return false; 1995 1996 return false; 1998 1997 } 1999 1998 … … 2003 2002 * @since 1.0 2004 2003 */ 2005 private function get_singular_name( $type ) 2004 private function get_singular_name( $type ) 2006 2005 { 2007 2006 // Links 2008 2007 if ( $type == 'wp-links' ) 2009 2008 $label = __('Links'); 2010 2009 2011 2010 // Comments 2012 2011 elseif ( $type == 'wp-comments' ) 2013 2012 $label = __('Comments'); 2014 2013 2015 2014 // Users 2016 2015 elseif ( $type == 'wp-users' ) 2017 2016 $label = __('Users'); 2018 2017 2019 2018 // Media 2020 2019 elseif ( $type == 'wp-media' ) 2021 2020 $label = __('Media Library'); 2022 2021 2023 2022 // Posts 2024 2023 else { … … 2026 2025 $label = $posttype_obj->labels->singular_name; 2027 2026 } 2028 2027 2029 2028 return $label; 2030 2029 } 2031 2030 2032 2031 /** 2033 2032 * Get plural name of post type … … 2035 2034 * @since 1.3.1 2036 2035 */ 2037 private function get_plural_name( $type ) 2036 private function get_plural_name( $type ) 2038 2037 { 2039 2038 $posttype_obj = get_post_type_object($type); 2040 2039 if ( $posttype_obj ) 2041 2040 return $posttype_obj->labels->name; 2042 2041 2043 2042 return false; 2044 2043 } 2045 2044 2046 2045 /** 2047 2046 * Get screen link to overview screen … … 2049 2048 * @since 1.3.1 2050 2049 */ 2051 private function get_type_screen_link( $type ) 2052 { 2050 private function get_type_screen_link( $type ) 2051 { 2053 2052 // Links 2054 2053 if ( $type == 'wp-comments' ) 2055 2054 $link = get_admin_url() . 'edit-comments.php'; 2056 2055 2057 2056 // Links 2058 2057 if ( $type == 'wp-links' ) 2059 2058 $link = get_admin_url() . 'link-manager.php'; 2060 2059 2061 2060 // Users 2062 2061 if ( $type == 'wp-users' ) 2063 2062 $link = get_admin_url() . 'users.php'; 2064 2063 2065 2064 // Media 2066 2065 elseif ( $type == 'wp-media' ) 2067 2066 $link = get_admin_url() . 'upload.php'; 2068 2067 2069 2068 // Posts 2070 else 2071 $link = get_admin_url() . "edit.php?post_type={$type}"; 2072 2069 else 2070 $link = get_admin_url() . "edit.php?post_type={$type}"; 2071 2073 2072 return $link; 2074 2073 } … … 2081 2080 * @since 1.0 2082 2081 */ 2083 protected function sanitize_string($string) 2084 { 2082 protected function sanitize_string($string) 2083 { 2085 2084 $string = esc_url($string); 2086 2085 $string = str_replace('http://','', $string); 2087 2086 $string = str_replace('https://','', $string); 2088 2087 2089 2088 return $string; 2090 2089 } 2091 2090 2092 2091 /** 2093 2092 * Checks if column-meta key exists … … 2095 2094 * @since 1.0 2096 2095 */ 2097 public static function is_column_meta( $id = '' ) 2096 public static function is_column_meta( $id = '' ) 2098 2097 { 2099 2098 if ( strpos($id, 'column-meta-') !== false ) 2100 2099 return true; 2101 2100 2102 2101 return false; 2103 2102 } 2104 2103 2105 2104 /** 2106 2105 * Get the posttype from columnname … … 2108 2107 * @since 1.3.1 2109 2108 */ 2110 public static function get_posttype_by_postcount_column( $id = '' ) 2111 { 2112 if ( strpos($id, 'column-user_postcount-') !== false ) 2109 public static function get_posttype_by_postcount_column( $id = '' ) 2110 { 2111 if ( strpos($id, 'column-user_postcount-') !== false ) 2113 2112 return str_replace('column-user_postcount-', '', $id); 2114 2113 2115 2114 return false; 2116 2115 } 2117 2116 2118 2117 /** 2119 2118 * Get column value of post attachments … … 2121 2120 * @since 1.2.1 2122 2121 */ 2123 public static function get_attachment_ids( $post_id ) 2122 public static function get_attachment_ids( $post_id ) 2124 2123 { 2125 2124 return get_posts(array( … … 2131 2130 )); 2132 2131 } 2133 2132 2134 2133 /** 2135 2134 * Strip tags and trim … … 2137 2136 * @since 1.3 2138 2137 */ 2139 public static function strip_trim($string) 2138 public static function strip_trim($string) 2140 2139 { 2141 2140 return trim(strip_tags($string)); 2142 2141 } 2143 2142 2144 2143 /** 2145 2144 * Admin body class … … 2147 2146 * @since 1.4 2148 2147 */ 2149 function admin_class( $classes ) 2150 { 2148 function admin_class( $classes ) 2149 { 2151 2150 global $current_screen; 2152 2151 2153 2152 // we dont need the 'edit-' part 2154 2153 $screen = str_replace('edit-', '', $current_screen->id); 2155 2154 2156 2155 // media library exception 2157 2156 if ( $current_screen->base == 'upload' && $current_screen->id == 'upload' ) { 2158 2157 $screen = 'media'; 2159 2158 } 2160 2159 2161 2160 // link exception 2162 2161 if ( $current_screen->base == 'link-manager' && $current_screen->id == 'link-manager' ) { … … 2165 2164 2166 2165 // loop the available types 2167 foreach ( $this->get_types() as $type => $label ) { 2168 2166 foreach ( $this->get_types() as $type => $label ) { 2167 2169 2168 // match against screen or wp-screen 2170 2169 if ( $type == $screen || $type == "wp-{$screen}" ) … … 2175 2174 } 2176 2175 2177 2176 2178 2177 /** 2179 2178 * Admin CSS for Column width … … 2181 2180 * @since 1.4 2182 2181 */ 2183 function admin_css() 2184 { 2182 function admin_css() 2183 { 2185 2184 $css = ''; 2186 2185 2187 2186 // loop throug the available types... 2188 2187 foreach ( $this->get_types() as $type ) { 2189 $cols = self::get_stored_columns($type); 2188 $cols = self::get_stored_columns($type); 2190 2189 if ( $cols ) { 2191 2190 2192 2191 // loop through each available column... 2193 2192 foreach ( $cols as $col_name => $col ) { 2194 2193 2195 2194 // and check for stored width and add it to the css 2196 2195 if (!empty($col['width']) && is_numeric($col['width']) && $col['width'] > 0 ) { … … 2200 2199 } 2201 2200 } 2202 2201 2203 2202 echo "<style type='text/css'>{$css}</style>"; 2204 2203 } 2205 2204 2206 2205 /** 2207 2206 * Ajax activation … … 2214 2213 $key = $_POST['key']; 2215 2214 $type = $_POST['type']; 2216 2215 2217 2216 $licence = new cpac_licence( $type ); 2218 2217 2219 2218 // update key 2220 2219 if ( $key == 'remove' ) { 2221 2220 $licence->remove_license_key(); 2222 2221 } 2223 2222 2224 2223 // set license key 2225 2224 elseif ( $licence->check_remote_key( $key ) ) { 2226 2225 2227 2226 // set key 2228 2227 $licence->set_license_key( $key ); 2229 2228 2230 2229 // returned masked key 2231 2230 echo json_encode( $licence->get_masked_license_key() ); … … 2234 2233 exit; 2235 2234 } 2236 2235 2237 2236 /** 2238 2237 * Add help tabs … … 2240 2239 * @since 1.3 2241 2240 */ 2242 public function help_tabs($page) 2243 { 2241 public function help_tabs($page) 2242 { 2244 2243 $screen = get_current_screen(); 2245 2244 2246 2245 if ( $screen->id != $this->admin_page || ! method_exists($screen,'add_help_tab') ) 2247 2246 return; 2248 2247 2249 2248 $admin_url = get_admin_url(); 2250 2249 2251 2250 // add help content 2252 2251 $tabs = array( … … 2257 2256 <p> 2258 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. 2259 </p> 2260 2258 </p> 2259 2261 2260 " 2262 2261 ), … … 2300 2299 </ul> 2301 2300 " 2302 ) 2301 ) 2303 2302 ); 2304 2303 2305 2304 foreach ( $tabs as $k => $tab ) { 2306 $screen->add_help_tab(array( 2305 $screen->add_help_tab(array( 2307 2306 'id' => 'cpac-tab-'.$k, // unique id 2308 2307 'title' => $tab['title'], // label … … 2311 2310 } 2312 2311 } 2313 2312 2314 2313 /** 2315 2314 * Plugin Settings … … 2317 2316 * @since 1.3.1 2318 2317 */ 2319 private function plugin_settings() 2318 private function plugin_settings() 2320 2319 { 2321 2320 $class_current_settings = $this->is_menu_type_current('plugin_settings') ? ' current' : ' hidden'; ''; 2322 2321 2323 2322 /** Sortable */ 2324 2323 $masked_key = ''; 2325 2324 $class_sortorder_activate = ''; 2326 2325 $class_sortorder_deactivate = ' hidden'; 2327 2326 2328 2327 // is unlocked 2329 2328 $licence = new cpac_licence('sortable'); 2330 2329 2331 2330 if ( $licence->is_unlocked() ) { 2332 2331 $masked_key = $licence->get_masked_license_key('sortable'); … … 2334 2333 $class_sortorder_deactivate = ''; 2335 2334 } 2336 2335 2337 2336 // find out more 2338 2337 $find_out_more = "<a href='{$this->codepress_url}/sortorder-addon/' class='button-primary alignright' target='_blank'>".__('find out more', CPAC_TEXTDOMAIN)." »</a>"; 2339 2338 2340 2339 // info box 2341 2340 $sortable_tooltip = " … … 2343 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> 2344 2343 <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> 2344 <p class='description'>".__('(columns that are added by other plugins are not supported)', CPAC_TEXTDOMAIN).".</p> 2346 2345 <img src='" . CPAC_URL.'/assets/images/addon_sortable_1.png' . "' alt='' /> 2347 2346 {$find_out_more} 2348 2347 "; 2349 2350 // addons 2348 2349 // addons 2351 2350 $addons = " 2352 2351 <tr> … … 2395 2394 <td class='activation_more'>{$find_out_more}</td> 2396 2395 </tr><!-- #cpac-activation-sortable --> 2397 </tbody> 2396 </tbody> 2398 2397 </table> 2399 2398 <div class='addon-translation-string hidden'> … … 2404 2403 </tr> 2405 2404 "; 2406 2405 2407 2406 // general options 2408 2407 $general_options = " … … 2414 2413 <li> 2415 2414 <div class='cpac-option-label'>Thumbnail size</div> 2416 <div class='cpac-option-inputs'> 2415 <div class='cpac-option-inputs'> 2417 2416 <input type='text' id='thumbnail_size_w' class='small-text' name='cpac_options[settings][thumb_width]' value='80'/> 2418 2417 <label for='thumbnail_size_w'>Width</label> 2419 <br/> 2418 <br/> 2420 2419 <input type='text' id='thumbnail_size_h' class='small-text' name='cpac_options[settings][thumb_height]' value='80'/> 2421 2420 <label for='thumbnail_size_h'>Height</label> … … 2424 2423 <li> 2425 2424 <div class='cpac-option-label'>Excerpt length</div> 2426 <div class='cpac-option-inputs'> 2427 2425 <div class='cpac-option-inputs'> 2426 2428 2427 <input type='text' id='excerpt_length' class='small-text' name='cpac_options[settings][excerpt_length]' value='15'/> 2429 2428 <label for='excerpt_length'>Number of words</label> 2430 2429 </div> 2431 2430 </li> 2432 </ul> 2431 </ul> 2433 2432 </td> 2434 2433 </tr> 2435 2434 --> 2436 2435 "; 2437 2436 2438 2437 // settings 2439 2438 $row = " … … 2441 2440 <td colspan='2'> 2442 2441 <table class='nopadding'> 2443 {$addons} 2442 {$addons} 2444 2443 {$general_options} 2445 2444 </table> … … 2447 2446 </tr><!-- #cpac-box-plugin_settings --> 2448 2447 "; 2449 2448 2450 2449 return $row; 2451 2450 } 2452 2451 2453 2452 /** 2454 2453 * Get post count … … 2459 2458 { 2460 2459 global $wpdb; 2461 2460 2462 2461 if ( ! post_type_exists($post_type) || empty($user_id) ) 2463 2462 return false; 2464 2463 2465 2464 $sql = " 2466 2465 SELECT COUNT(ID) … … 2470 2469 AND post_type = %s 2471 2470 "; 2472 2471 2473 2472 return $wpdb->get_var( $wpdb->prepare($sql, $user_id, $post_type) ); 2474 2473 } 2475 2474 2476 2475 /** 2477 2476 * Settings Page Template. … … 2479 2478 * This function in conjunction with others uses the WordPress 2480 2479 * 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() 2480 * the behaviour of this plugin. 2481 * 2482 * @since 1.0 2483 */ 2484 public function plugin_settings_page() 2486 2485 { 2487 2486 // loop through post types 2488 2487 $rows = ''; 2489 2488 foreach ( $this->get_types() as $type ) { 2490 2489 2491 2490 // post type label 2492 2491 $label = $this->get_singular_name($type); 2493 2492 2494 2493 // id 2495 $id = $this->sanitize_string($type); 2496 2494 $id = $this->sanitize_string($type); 2495 2497 2496 // build draggable boxes 2498 2497 $boxes = $this->get_column_boxes($type); … … 2500 2499 // class 2501 2500 $class = $this->is_menu_type_current($type) ? ' current' : ' hidden'; 2502 2501 2503 2502 $rows .= " 2504 2503 <tr id='cpac-box-{$id}' valign='top' class='cpac-box-row{$class}'> … … 2508 2507 <td> 2509 2508 <h3 class='cpac_post_type hidden'>{$label}</h3> 2510 {$boxes} 2509 {$boxes} 2511 2510 </td> 2512 2511 </tr> 2513 2512 "; 2514 2513 } 2515 2514 2516 2515 // General Setttings 2517 2516 $general_settings = $this->plugin_settings(); 2518 2517 2519 2518 // Post Type Menu 2520 2519 $menu = $this->get_menu(); 2521 2520 2522 2521 // Help screen message 2523 2522 $help_text = ''; 2524 2523 if ( version_compare( get_bloginfo('version'), '3.2', '>' ) ) 2525 2524 $help_text = '<p>'.__('You will find a short overview at the <strong>Help</strong> section in the top-right screen.', CPAC_TEXTDOMAIN).'</p>'; 2526 2525 2527 2526 // find out more 2528 2527 $find_out_more = "<a href='{$this->codepress_url}/sortorder-addon/' class='alignright green' target='_blank'>".__('find out more', CPAC_TEXTDOMAIN)." »</a>"; 2529 2528 2530 2529 ?> 2531 2530 <div id="cpac" class="wrap"> … … 2533 2532 <h2><?php _e('Codepress Admin Columns', CPAC_TEXTDOMAIN); ?></h2> 2534 2533 <?php echo $menu ?> 2535 2534 2536 2535 <div class="postbox-container cpac-col-right"> 2537 <div class="metabox-holder"> 2538 <div class="meta-box-sortables"> 2539 2536 <div class="metabox-holder"> 2537 <div class="meta-box-sortables"> 2538 2540 2539 <div id="addons-cpac-settings" class="postbox"> 2541 2540 <div title="Click to toggle" class="handlediv"><br></div> … … 2550 2549 </div> 2551 2550 </div><!-- addons-cpac-settings --> 2552 2551 2553 2552 <div id="likethisplugin-cpac-settings" class="postbox"> 2554 2553 <div title="Click to toggle" class="handlediv"><br></div> … … 2560 2559 <ul> 2561 2560 <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> 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> 2563 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> 2564 </ul> 2563 </ul> 2565 2564 </div> 2566 2565 </div><!-- likethisplugin-cpac-settings --> 2567 2566 2568 2567 <div id="latest-news-cpac-settings" class="postbox"> 2569 2568 <div title="Click to toggle" class="handlediv"><br></div> … … 2571 2570 <span><?php _e('Follow us', CPAC_TEXTDOMAIN) ?></span> 2572 2571 </h3> 2573 <div class="inside"> 2572 <div class="inside"> 2574 2573 <ul> 2575 2574 <li class="twitter"><a href="http://twitter.com/codepressNL"><?php _e('Follow Codepress on Twitter.', CPAC_TEXTDOMAIN) ?></a></li> 2576 2575 <li class="facebook"><a href="https://www.facebook.com/codepressNL"><?php _e('Like Codepress on Facebook.', CPAC_TEXTDOMAIN) ?></a></li> 2577 2578 </ul> 2576 2577 </ul> 2579 2578 </div> 2580 2579 </div><!-- latest-news-cpac-settings --> 2581 2580 2582 2581 <div id="side-cpac-settings" class="postbox"> 2583 2582 <div title="Click to toggle" class="handlediv"><br></div> … … 2585 2584 <span><?php _e('Need support?', CPAC_TEXTDOMAIN) ?></span> 2586 2585 </h3> 2587 <div class="inside"> 2586 <div class="inside"> 2588 2587 <?php echo $help_text ?> 2589 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:[email protected]">[email protected]</a>' );?></p> … … 2591 2590 </div> 2592 2591 </div><!-- side-cpac-settings --> 2593 2592 2594 2593 </div> 2595 2594 </div> 2596 2595 </div><!-- .postbox-container --> 2597 2596 2598 2597 <div class="postbox-container cpac-col-left"> 2599 <div class="metabox-holder"> 2598 <div class="metabox-holder"> 2600 2599 <div class="meta-box-sortables"> 2601 2600 2602 2601 <div id="general-cpac-settings" class="postbox"> 2603 2602 <div title="Click to toggle" class="handlediv"><br></div> … … 2607 2606 <div class="inside"> 2608 2607 <form method="post" action="options.php"> 2609 2608 2610 2609 <?php settings_fields( 'cpac-settings-group' ); ?> 2611 2610 2612 2611 <table class="form-table"> 2613 2612 <!-- columns --> 2614 <?php echo $rows; ?> 2615 2613 <?php echo $rows; ?> 2614 2616 2615 <!-- activation --> 2617 2616 <?php echo $general_settings; ?> 2618 2617 2619 2618 <tr class="bottom" valign="top"> 2620 2619 <th scope="row"></th> … … 2624 2623 </p> 2625 2624 </td> 2626 </tr> 2627 </table> 2628 </form> 2629 </div> 2625 </tr> 2626 </table> 2627 </form> 2628 </div> 2630 2629 </div><!-- general-settings --> 2631 2630 2632 2631 <div id="restore-cpac-settings" class="postbox"> 2633 2632 <div title="Click to toggle" class="handlediv"><br></div> … … 2636 2635 </h3> 2637 2636 <div class="inside"> 2638 <form method="post" action=""> 2637 <form method="post" action=""> 2639 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); ?>');" /> 2640 2639 </form> … … 2642 2641 </div> 2643 2642 </div><!-- restore-cpac-settings --> 2644 2643 2645 2644 </div> 2646 2645 </div> 2647 </div><!-- .postbox-container --> 2646 </div><!-- .postbox-container --> 2648 2647 </div> 2649 2648 <?php -
codepress-admin-columns/trunk/readme.txt
r637684 r638877 5 5 Requires at least: 3.1 6 6 Tested up to: 3.5 7 Stable tag: 1.4. 87 Stable tag: 1.4.9 8 8 9 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. … … 11 11 == Description == 12 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. 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 16 17 17 Add or remove columns, change their label, change their width and reorder them. … … 35 35 * Status 36 36 * Number of Attachments 37 * Last Modified 37 * Last Modified 38 38 * Comment count 39 39 * Before More Tag Content … … 114 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 115 116 = Translations = 116 = Translations = 117 117 118 118 If you like to contrinute a language, please send them to <a href="mailto:[email protected]">[email protected]</a>. … … 165 165 add_image_size( 'admin-columns', $my_width, $my_height, true ); 166 166 add_filter('cpac_thumbnail_size', 'cb_cpac_thumbnail_size' ); 167 function cb_cpac_thumbnail_size() { 167 function cb_cpac_thumbnail_size() { 168 168 return 'admin-columns'; 169 169 }; … … 219 219 $my_post_type = 'demo'; 220 220 $my_field_name = 'city'; 221 221 222 222 // make sure we have the correct posttype and fieldname 223 223 if ( $my_post_type == $type && $my_field_name == $custom_field ) { 224 224 225 225 if ( '33' == $value ) 226 226 $value = 'Amsterdam'; 227 227 228 228 elseif ( '34' == $value ) 229 $value = 'New York'; 229 $value = 'New York'; 230 230 } 231 return $value; 231 return $value; 232 232 } 233 233 add_filter( 'cpac_get_column_value_custom_field', 'my_custom_field_value', 10, 5 ); … … 246 246 247 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}' ) 248 251 249 252 = 1.4.8 =
Note: See TracChangeset
for help on using the changeset viewer.