comment
10 years ago
link
10 years ago
media
10 years ago
post
10 years ago
user
10 years ago
acf-placeholder.php
10 years ago
actions.php
10 years ago
custom-field.php
10 years ago
default.php
10 years ago
taxonomy.php
10 years ago
used-by-menu.php
10 years ago
wc-placeholder.php
10 years ago
taxonomy.php
95 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Taxonomy column, displaying terms from a taxonomy for any object type (i.e. posts) |
| 4 | * supporting WordPress' native way of handling terms. |
| 5 | * |
| 6 | * @since 2.0 |
| 7 | */ |
| 8 | class CPAC_Column_Taxonomy extends CPAC_Column { |
| 9 | |
| 10 | /** |
| 11 | * @see CPAC_Column::init() |
| 12 | * @since 2.2.1 |
| 13 | */ |
| 14 | public function init() { |
| 15 | |
| 16 | parent::init(); |
| 17 | |
| 18 | // Properties |
| 19 | $this->properties['type'] = 'column-taxonomy'; |
| 20 | $this->properties['label'] = __( 'Taxonomy', 'codepress-admin-columns' ); |
| 21 | $this->properties['is_cloneable'] = true; |
| 22 | |
| 23 | // Options |
| 24 | $this->options['taxonomy'] = ''; // Taxonomy slug |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * @see CPAC_Column::get_value() |
| 29 | * @since 2.0 |
| 30 | */ |
| 31 | public function get_value( $post_id ) { |
| 32 | $term_ids = $this->get_raw_value( $post_id ); |
| 33 | return $this->get_terms_for_display( $term_ids, $this->options->taxonomy ); |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * @see CPAC_Column::get_raw_value() |
| 38 | * @since 2.0.3 |
| 39 | */ |
| 40 | public function get_raw_value( $post_id ) { |
| 41 | return wp_get_post_terms( $post_id, $this->options->taxonomy, array( 'fields' => 'ids' ) ); |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * @see CPAC_Column::get_value() |
| 46 | * @since 2.3.4 |
| 47 | */ |
| 48 | public function get_taxonomy() { |
| 49 | return $this->options->taxonomy; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * @see CPAC_Column::apply_conditional() |
| 54 | * @since 2.0 |
| 55 | */ |
| 56 | public function apply_conditional() { |
| 57 | $post_type = $this->get_post_type(); |
| 58 | if ( ! $post_type || ! get_object_taxonomies( $post_type ) ) { |
| 59 | return false; |
| 60 | } |
| 61 | |
| 62 | return true; |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Display Settings |
| 67 | * |
| 68 | * @see CPAC_Column::display_settings() |
| 69 | * @since 2.0 |
| 70 | */ |
| 71 | public function display_settings() { |
| 72 | |
| 73 | $taxonomies = get_object_taxonomies( $this->get_post_type(), 'objects' ); |
| 74 | |
| 75 | foreach ( $taxonomies as $index => $taxonomy ) { |
| 76 | if ( $taxonomy->name == 'post_format' ) { |
| 77 | unset( $taxonomies[ $index ] ); |
| 78 | } |
| 79 | } |
| 80 | ?> |
| 81 | |
| 82 | <tr class="column_taxonomy"> |
| 83 | <?php $this->label_view( __( "Taxonomy", 'codepress-admin-columns' ), '', 'taxonomy' ); ?> |
| 84 | <td class="input"> |
| 85 | <select name="<?php $this->attr_name( 'taxonomy' ); ?>" id="<?php $this->attr_id( 'taxonomy' ); ?>"> |
| 86 | <?php foreach ( $taxonomies as $taxonomy ) : ?> |
| 87 | <option value="<?php echo $taxonomy->name; ?>"<?php selected( $taxonomy->name, $this->options->taxonomy ) ?>><?php echo $taxonomy->label; ?></option> |
| 88 | <?php endforeach; ?> |
| 89 | </select> |
| 90 | </td> |
| 91 | </tr> |
| 92 | |
| 93 | <?php |
| 94 | } |
| 95 | } |