Skip to:
Content

BuddyPress.org

Ticket #8410: 8410.diff

File 8410.diff, 2.1 KB (added by Jean-David, 4 years ago)

As the names are just metadatas, I needed a way to distinguish between the types of the field. I refactored the code into a private function, which is called twice : one before the slug field, and the other after, allowing to filter the field between the "name ones" and the "not name ones"

  • src/bp-core/classes/class-bp-admin-types.php

    diff --git src/bp-core/classes/class-bp-admin-types.php src/bp-core/classes/class-bp-admin-types.php
    index 0ef4201ea..440f212f6 100644
    class BP_Admin_Types { 
    316316                $taxonomy_object = get_taxonomy( $taxonomy );
    317317                $labels          = get_taxonomy_labels( $taxonomy_object );
    318318
     319                // Gets the Type's metadata.
     320                $metafields = get_registered_meta_keys( 'term', $taxonomy );
     321
     322                $this->display_meta_fields($metafields, $type, $labels, true);
     323
    319324                // Default values for the Type ID field.
    320325                $type_id_label   = __( 'Type ID', 'buddypress' );
    321326                $type_id_desc    = __( 'Enter a lower-case string without spaces or special characters (used internally to identify the type).', 'buddypress' );
    class BP_Admin_Types { 
    353358                        );
    354359                }
    355360
    356                 // Gets the Type's metadata.
    357                 $metafields = get_registered_meta_keys( 'term', $taxonomy );
     361                $this->display_meta_fields($metafields, $type, $labels, false);
     362        }
    358363
     364        /**
     365         * Output the additional BP type's meta fields
     366         *
     367         * @param string[]    $metafields List of registered meta keys.
     368         * @param null|object $type       The type object, `null` if not passed to the method.
     369         * @param object      $labels     Taxonomy labels object
     370         * @param bool        $is_name    Is the meta field the singular/plurals name or another meta field ?
     371         */
     372        private function display_meta_fields($metafields, $type, $labels, $is_name){
    359373                foreach ( $metafields as $meta_key => $meta_schema ) {
    360374                        if ( ! isset( $labels->{ $meta_key } ) || ! $labels->{ $meta_key } ) {
    361375                                _doing_it_wrong(
    class BP_Admin_Types { 
    371385                        }
    372386
    373387                        $type_key = str_replace( 'bp_type_', '', $meta_key );
     388                        $is_name_meta_key = $is_name && ! in_array( $type_key, array( 'name', 'singular_name' ), true );
     389                        $is_not_name_meta_key = ! $is_name && in_array( $type_key, array( 'name', 'singular_name' ), true ) ;
     390
     391                        if( $is_name_meta_key || $is_not_name_meta_key ) {
     392                                continue;
     393                        }
    374394
    375395                        if ( 'string' === $meta_schema['type'] ) {
    376396                                if ( isset( $type->name ) ) {