Plugin Directory

Changeset 2993916


Ignore:
Timestamp:
11/10/2023 12:43:11 PM (2 years ago)
Author:
flei
Message:

version 0.2.1

Location:
admin-columns-for-acf-fields
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • admin-columns-for-acf-fields/trunk/acf_admin_columns.php

    r2975646 r2993916  
    44 * Plugin URI: https://wordpress.org/plugins/acf-admin-columns/
    55 * Description: Add columns for your ACF fields to post and taxonomy index pages in the WP backend.
    6  * Version: 0.2.0
     6 * Version: 0.2.1
    77 * Author: Florian Eickhorst
    88 * Author URI: http://www.fleimedia.com/
     
    115115                }
    116116
    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'])))) {
    118118                    continue;
    119119                }
     
    179179                }
    180180
    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);
    182182
    183183                $query->set('orderby', $order_type);
     
    378378        $preview_item_count = 1;
    379379        $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);
    381381
    382382        if (empty($field_value) && !empty($field_properties['default_value'])) {
     
    467467                    }
    468468                    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                    }
    469483                case 'number':
    470484                case 'true_false':
    471485                case 'text':
    472486                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                     }
    481487                case 'range':
    482488                case 'email':
     
    506512
    507513        // 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') {
    509515            $render_output = apply_filters('acf/admin_columns/no_value_placeholder', '—', $field_properties, $field_value, $post_id);
    510516        }
     
    547553
    548554        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'] : '';
    550556            acf_render_field_setting($field, $settings_args, false);
    551557        }
    552558
    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));
    558559    }
    559560
     
    571572
    572573        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';
    576577
    577578            if ($this->screen_is_post_type_index || $this->screen_is_taxonomy_index || $this->screen_is_user_index) {
     
    601602    private function get_clean_column($dirty_column)
    602603    {
    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;
    606643    }
    607644
  • admin-columns-for-acf-fields/trunk/readme.txt

    r2975646 r2993916  
    55Requires at least: 4.6
    66Tested up to: 6.3.1
    7 Stable tag: 0.2.0
     7Stable tag: 0.2.1
    88Requires PHP: 5.2.4
    99License: GPLv2 or later
    1010License URI: https://www.gnu.org/licenses/gpl-2.0.html
    11 Date: 06.10.2023
    12 Version: 0.2.0
     11Date: 10.11.2023
     12Version: 0.2.1
    1313
    1414
     
    1717== Description ==
    1818
    19 Use this plugin to show ACF fields in the "All Posts" table view in the Wordpress admin backend.
     19Use this plugin to show ACF fields in the "All Posts", Taxonomy or User table view in the Wordpress admin backend.
    2020
    2121Simply 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").
     
    41413. Open any field for editing (see exceptions below).
    42424. 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.
     435. 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.
    4544
    4645== Advanced Usage ==
     
    7574
    7675= "acf/admin_columns/sortable_columns" =
    77 Change which columns should be sortable. By default every column is sortable.
     76Change which columns should be sortable. By default, every column is sortable.
    7877
    7978**Parameters**
     
    8483
    8584**Parameters**
    86 $field_value - The field value   
     85$field_value - The field value
     86
     87= "acf/admin_columns/exclude_field_types" =
     88Change 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" =
     102Change 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" =
     116Allows for manipulation of the url of the preview image.
     117
     118**Parameters**
     119$preview_image_url - string with image url
     120
    87121
    88122== Installation ==
     
    96130== Frequently Asked Questions ==
    97131
    98 None yet, feel free to ask.
     132=== How can I change the preview image size of image and gallery fields? ===
     133
     134Use the filter "acf/admin_columns/preview_image_size" to change the preview image size. See "Filters" section above for details.
    99135
    100136== Changelog ==
    101137
     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
    102144= 0.2.0 =
    103145*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)
    105155
    106156= 0.1.2 =
Note: See TracChangeset for help on using the changeset viewer.