Changeset 2993916
- Timestamp:
- 11/10/2023 12:43:11 PM (2 years ago)
- Location:
- admin-columns-for-acf-fields
- Files:
-
- 3 edited
-
assets/screenshot-2.png (modified) (previous)
-
trunk/acf_admin_columns.php (modified) (9 diffs)
-
trunk/readme.txt (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
admin-columns-for-acf-fields/trunk/acf_admin_columns.php
r2975646 r2993916 4 4 * Plugin URI: https://wordpress.org/plugins/acf-admin-columns/ 5 5 * Description: Add columns for your ACF fields to post and taxonomy index pages in the WP backend. 6 * Version: 0.2. 06 * Version: 0.2.1 7 7 * Author: Florian Eickhorst 8 8 * Author URI: http://www.fleimedia.com/ … … 115 115 } 116 116 117 if ($this->screen_is_taxonomy_index && (!isset($field[self::ACF_SETTING_NAME . '_taxonomies']) || (is_array($field[self::ACF_SETTING_NAME . '_taxonomies']) && array_search($screen->taxonomy, $field[self::ACF_SETTING_NAME . '_taxonomies']) === false))) {117 if ($this->screen_is_taxonomy_index && (!isset($field[self::ACF_SETTING_NAME . '_taxonomies']) || (is_array($field[self::ACF_SETTING_NAME . '_taxonomies']) && !in_array($screen->taxonomy, $field[self::ACF_SETTING_NAME . '_taxonomies'])))) { 118 118 continue; 119 119 } … … 179 179 } 180 180 181 $order_type = apply_filters('acf/admin_columns/sort_order_type', $order_type, $orderby );181 $order_type = apply_filters('acf/admin_columns/sort_order_type', $order_type, $orderby, $field_properties); 182 182 183 183 $query->set('orderby', $order_type); … … 378 378 $preview_item_count = 1; 379 379 $remaining_items_count = 0; 380 $render_raw = apply_filters('acf/admin_columns/column/' . $clean_column . '/render_raw', false, $field_properties, $field_value, $post_id);380 $render_raw = apply_filters('acf/admin_columns/column/' . $clean_column . '/render_raw', false, $field_properties, $field_value, $post_id); 381 381 382 382 if (empty($field_value) && !empty($field_properties['default_value'])) { … … 467 467 } 468 468 break; 469 case 'radio': 470 case 'checkbox': 471 case 'select': 472 if (!empty($field_value) && isset($field_properties['return_format'])) { 473 if ($field_properties['type'] === 'checkbox' || (!empty($field_properties['multiple']))) { 474 $render_output = array(); 475 foreach ($field_value as $field_value_item) { 476 $render_output[] = $this->render_value_label_field($field_properties['return_format'], $field_properties['choices'], $field_value_item); 477 } 478 } else { 479 $render_output = $this->render_value_label_field($field_properties['return_format'], $field_properties['choices'], $field_value); 480 } 481 break; 482 } 469 483 case 'number': 470 484 case 'true_false': 471 485 case 'text': 472 486 case 'textarea': 473 $render_raw = true;474 case 'checkbox':475 case 'radio':476 case 'select':477 if (!empty($field_properties['choices'][$field_value])) {478 $render_output = $field_properties['choices'][$field_value] . ' (' . $field_value . ')';479 break;480 }481 487 case 'range': 482 488 case 'email': … … 506 512 507 513 // default "no value" or "empty" output 508 if (empty($render_output) && !$render_raw && $field_properties['type'] !== 'true_false' ) {514 if (empty($render_output) && !$render_raw && $field_properties['type'] !== 'true_false') { 509 515 $render_output = apply_filters('acf/admin_columns/no_value_placeholder', '—', $field_properties, $field_value, $post_id); 510 516 } … … 547 553 548 554 foreach ($field_settings as $settings_args) { 549 $settings_args['class'] = isset($settings_args['class']) ? $settings_args['class'] .' aac-field-settings-' . $settings_args['name'] : '';555 $settings_args['class'] = isset($settings_args['class']) ? $settings_args['class'] . ' aac-field-settings-' . $settings_args['name'] : ''; 550 556 acf_render_field_setting($field, $settings_args, false); 551 557 } 552 558 553 }554 555 private function get_supported_post_types()556 {557 return $post_types = get_post_types(array('show_ui' => true, 'show_in_menu' => true));558 559 } 559 560 … … 571 572 572 573 if (function_exists('get_current_screen') && $screen = get_current_screen()) { 573 $this->screen_is_post_type_index = $screen->base == 'edit' && $screen->post_type;574 $this->screen_is_taxonomy_index = $screen->base == 'edit-tags' && $screen->taxonomy;575 $this->screen_is_user_index = $screen->base == 'users';574 $this->screen_is_post_type_index = $screen->base === 'edit' && $screen->post_type; 575 $this->screen_is_taxonomy_index = $screen->base === 'edit-tags' && $screen->taxonomy; 576 $this->screen_is_user_index = $screen->base === 'users'; 576 577 577 578 if ($this->screen_is_post_type_index || $this->screen_is_taxonomy_index || $this->screen_is_user_index) { … … 601 602 private function get_clean_column($dirty_column) 602 603 { 603 $clean_column = str_replace(self::COLUMN_NAME_PREFIX, '', $dirty_column); 604 605 return $clean_column; 604 return str_replace(self::COLUMN_NAME_PREFIX, '', $dirty_column); 605 } 606 607 /** 608 * Renders the value of a select, radio or checkbox field based on the return format 609 * 610 * @param $return_format 611 * @param $choices 612 * @param $field_value 613 * @return mixed|string 614 */ 615 private function render_value_label_field($return_format, $choices, $field_value) 616 { 617 if (empty($field_value)) { 618 return $field_value; 619 } 620 $render_output = $field_value; 621 $value = ''; 622 $label = ''; 623 624 if ($return_format === 'value' && !empty($choices[$field_value])) { 625 $value = $field_value; 626 $label = $choices[$field_value]; 627 } else if ($return_format === 'label' && array_search($field_value, $choices)) { 628 $value = array_search($field_value, $choices); 629 $label = $field_value; 630 } else if ($return_format === 'array' && is_array($field_value) && array_key_exists('value', $field_value) && array_key_exists('label', $field_value)) { 631 $value = $field_value['value']; 632 $label = $field_value['label']; 633 } 634 635 if (!empty($value) && !empty($label)) { 636 $render_output = $value; 637 if ($value !== $label) { 638 $render_output .= ' (' . $label . ')'; 639 } 640 } 641 642 return $render_output; 606 643 } 607 644 -
admin-columns-for-acf-fields/trunk/readme.txt
r2975646 r2993916 5 5 Requires at least: 4.6 6 6 Tested up to: 6.3.1 7 Stable tag: 0.2. 07 Stable tag: 0.2.1 8 8 Requires PHP: 5.2.4 9 9 License: GPLv2 or later 10 10 License URI: https://www.gnu.org/licenses/gpl-2.0.html 11 Date: 06.10.202312 Version: 0.2. 011 Date: 10.11.2023 12 Version: 0.2.1 13 13 14 14 … … 17 17 == Description == 18 18 19 Use this plugin to show ACF fields in the "All Posts" table view in the Wordpress admin backend.19 Use this plugin to show ACF fields in the "All Posts", Taxonomy or User table view in the Wordpress admin backend. 20 20 21 21 Simply enable the new option "Admin Column" in your ACF field settings for any regular field (see exceptions below). Now there will be an extra column for your field shown in any overview of posts, pages, taxonomies or your custom post types or taxonomies (e.g. "All Pages"). … … 41 41 3. Open any field for editing (see exceptions below). 42 42 4. Enable the "Admin Column" option in the field settings. 43 5. Enable post types and/or taxonomies for which the column should be shown. 44 6. Save the field group and go to the overview page of the post type or taxonomy (e.g. "Posts > All Posts", or "Pages > All Pages") that you noted above and notice the newly added column for your field. 43 5. Save the field group and go to the "All posts" view of the post type or taxonomy (e.g. "Posts > All Posts", or "Pages > All Pages") and notice the newly added column for your field. 45 44 46 45 == Advanced Usage == … … 75 74 76 75 = "acf/admin_columns/sortable_columns" = 77 Change which columns should be sortable. By default every column is sortable.76 Change which columns should be sortable. By default, every column is sortable. 78 77 79 78 **Parameters** … … 84 83 85 84 **Parameters** 86 $field_value - The field value 85 $field_value - The field value 86 87 = "acf/admin_columns/exclude_field_types" = 88 Change which field types should not have the admin column option in the field settings. 89 90 **Parameters** 91 $excluded_field_types - array of excluded_field_types 92 93 **Example: disable the admin column option for TEXT fields** 94 95 function my_exclude_field_types($excluded_field_types) { 96 $excluded_field_types[] = 'text'; 97 return $excluded_field_types; 98 } 99 add_filter('acf/admin_columns/exclude_field_types','my_exclude_field_types'); 100 101 = "acf/admin_columns/preview_image_size" = 102 Change the preview image size for image or gallery fields. 103 104 **Parameters** 105 $preview_image_size - string with image size name 106 107 **Example: change preview image size to "medium"** 108 109 function my_preview_image_size($preview_image_size) { 110 return 'medium'; 111 } 112 add_filter('acf/admin_columns/preview_image_size','my_preview_image_size'); 113 114 115 = "acf/admin_columns/preview_image_url" = 116 Allows for manipulation of the url of the preview image. 117 118 **Parameters** 119 $preview_image_url - string with image url 120 87 121 88 122 == Installation == … … 96 130 == Frequently Asked Questions == 97 131 98 None yet, feel free to ask. 132 === How can I change the preview image size of image and gallery fields? === 133 134 Use the filter "acf/admin_columns/preview_image_size" to change the preview image size. See "Filters" section above for details. 99 135 100 136 == Changelog == 101 137 138 = 0.2.1 = 139 *Release date: 10.11.2023* 140 141 * added compatibility with PHP 8.2 142 * select, radio & checkbox fields: improved handling of return formats 143 102 144 = 0.2.0 = 103 145 *Release date: 06.10.2023* 104 * Many improvements, details to follow 146 147 * New feature: searchable columns for post archives. Searching columns in taxonomies and users will follow. 148 * Removed the field settings for the location where the column should be rendered (post type, taxonomy, user). A field column will be rendered according to the "location rules" in the ACF field group settings. 149 * Default values are now shown in the column if the field is empty. 150 * Fix: numeric sorting for 'number' field instead of string sorting 151 * New filter: 'acf/admin_columns/preview_image_size' - set preview size for image or gallery fields 152 * New filter: 'acf/admin_columns/preview_image_url' - allows for manipulation of the preview_image_url in image or gallery fields 153 * New filter: 'acf/admin_columns/link_wrap_url' - automatically wrap url in link to that url 154 * New filter: 'acf/admin_columns/render_raw' - set to true to render raw field value (e.g. for image fields) 105 155 106 156 = 0.1.2 =
Note: See TracChangeset
for help on using the changeset viewer.