comment.php
12 years ago
link.php
12 years ago
media.php
12 years ago
post.php
12 years ago
user.php
12 years ago
media.php
80 lines
| 1 | <?php |
| 2 | |
| 3 | class CPAC_Storage_Model_Media extends CPAC_Storage_Model { |
| 4 | |
| 5 | /** |
| 6 | * Constructor |
| 7 | * |
| 8 | * @since 2.0.0 |
| 9 | */ |
| 10 | function __construct() { |
| 11 | |
| 12 | $this->key = 'wp-media'; |
| 13 | $this->label = __( 'Media Library' ); |
| 14 | $this->type = 'media'; |
| 15 | $this->page = 'upload'; |
| 16 | |
| 17 | $this->set_custom_columns(); |
| 18 | |
| 19 | // headings |
| 20 | add_filter( "manage_{$this->page}_columns", array( $this, 'add_headings' ) ); |
| 21 | |
| 22 | // values |
| 23 | add_action( 'manage_media_custom_column', array( $this, 'manage_value' ), 10, 2 ); |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * Get WP default supported admin columns per post type. |
| 28 | * |
| 29 | * @since 1.0.0 |
| 30 | * |
| 31 | * @return array |
| 32 | */ |
| 33 | public function get_default_columns() { |
| 34 | |
| 35 | // You can use this filter to add thirdparty columns by hooking into this. |
| 36 | // See classes/third_party.php for an example. |
| 37 | do_action( "cac/columns/default/storage_key={$this->key}" ); |
| 38 | |
| 39 | // get columns |
| 40 | $table = _get_list_table( 'WP_Media_List_Table', array( 'screen' => 'upload' ) ); |
| 41 | $columns = $table->get_columns(); |
| 42 | |
| 43 | return $columns; |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Get Meta |
| 48 | * |
| 49 | * @since 2.0.0 |
| 50 | * |
| 51 | * @return array |
| 52 | */ |
| 53 | public function get_meta() { |
| 54 | global $wpdb; |
| 55 | |
| 56 | return $wpdb->get_results( "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", ARRAY_N ); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Manage value |
| 61 | * |
| 62 | * @since 2.0.0 |
| 63 | * |
| 64 | * @param string $column_name |
| 65 | * @param int $post_id |
| 66 | */ |
| 67 | public function manage_value( $column_name, $media_id ) { |
| 68 | |
| 69 | $value = ''; |
| 70 | |
| 71 | // get column instance |
| 72 | if ( $column = $this->get_column_by_name( $column_name ) ) { |
| 73 | $value = $column->get_value( $media_id ); |
| 74 | } |
| 75 | |
| 76 | // add hook |
| 77 | echo apply_filters( "cac/column/value/type={$this->key}", $value, $column ); |
| 78 | } |
| 79 | |
| 80 | } |