BP_Admin_Types::add_form_fields( string $taxonomy = '', null|object $type = null )

Outputs the BP type add form.


Parameters Parameters

$taxonomy

(string) (Optional) The type taxonomy name.

Default value: ''

$type

(null|object) (Optional) The type object, null if not passed to the method.

Default value: null


Source Source

File: bp-core/classes/class-bp-admin-types.php

	public function add_form_fields( $taxonomy = '', $type = null ) {
		$taxonomy_object = get_taxonomy( $taxonomy );
		$labels          = get_taxonomy_labels( $taxonomy_object );

		// Default values for the Type ID field.
		$type_id_label   = __( 'Type ID', 'buddypress' );
		$type_id_desc    = __( 'Enter a lower-case string without spaces or special characters (used internally to identify the type).', 'buddypress' );

		if ( isset( $labels->bp_type_id_label ) && $labels->bp_type_id_label ) {
			$type_id_label = $labels->bp_type_id_label;
		}

		if ( isset( $labels->bp_type_id_description ) && $labels->bp_type_id_description ) {
			$type_id_desc = $labels->bp_type_id_description;
		}

		// Outputs the Type ID field.
		if ( isset( $type->name ) ) {
			printf(
				'<tr class="form-field bp-types-form form-required term-bp_type_id-wrap">
					<th scope="row"><label for="bp_type_id">%1$s</label></th>
					<td>
						<input name="bp_type_id" id="bp_type_id" type="text" value="%2$s" size="40" disabled="disabled">
					</td>
				</tr>',
				esc_html( $type_id_label ),
				esc_attr( $type->name ),
				esc_html( $type_id_desc )
			);
		} else {
			printf(
				'<div class="form-field bp-types-form form-required term-bp_type_id-wrap">
					<label for="bp_type_id">%1$s</label>
					<input name="bp_type_id" id="bp_type_id" type="text" value="" size="40" aria-required="true">
					<p>%2$s</p>
				</div>',
				esc_html( $type_id_label ),
				esc_html( $type_id_desc )
			);
		}

		// Gets the Type's metadata.
		$metafields = get_registered_meta_keys( 'term', $taxonomy );

		foreach ( $metafields as $meta_key => $meta_schema ) {
			if ( ! isset( $labels->{ $meta_key } ) || ! $labels->{ $meta_key } ) {
				_doing_it_wrong(
					__METHOD__,
					__( 'Type metadata labels need to be set into the labels argument when registering your taxonomy using the meta key as the label’s key.', 'buddypress' )
					. ' ' .
					sprintf(
						/* translators: %s is the name of the Type meta key */
						__( 'As a result, the form elements for the "%s" meta key cannot be displayed', 'buddypress' ), $meta_key ),
					'7.0.0'
				);
				continue;
			}

			$type_key = str_replace( 'bp_type_', '', $meta_key );

			if ( 'string' === $meta_schema['type'] ) {
				if ( isset( $type->name ) ) {
					$type_prop_value = null;
					if ( in_array( $type_key, array( 'name', 'singular_name' ), true ) ) {
						if ( isset( $type->labels[ $type_key ] ) ) {
							$type_prop_value = $type->labels[ $type_key ];
						}

					} elseif ( isset( $type->{$type_key} ) ) {
						$type_prop_value = $type->{$type_key};
					}

					printf(
						'<tr class="form-field bp-types-form form-required term-%1$s-wrap">
							<th scope="row"><label for="%1$s">%2$s</label></th>
							<td>
								<input name="%1$s" id="%1$s" type="text" value="%3$s" size="40" aria-required="true">
								<p class="description">%4$s</p>
							</td>
						</tr>',
						esc_attr( $meta_key ),
						esc_html( $labels->{ $meta_key } ),
						esc_attr( $type_prop_value ),
						esc_html( $meta_schema['description'] )
					);

				} else {
					printf(
						'<div class="form-field bp-types-form form-required term-%1$s-wrap">
							<label for="%1$s">%2$s</label>
							<input name="%1$s" id="%1$s" type="text" value="" size="40">
							<p>%3$s</p>
						</div>',
						esc_attr( $meta_key ),
						esc_html( $labels->{ $meta_key } ),
						esc_html( $meta_schema['description'] )
					);
				}
			} else {
				if ( isset( $type->name ) ) {
					$checked = '';
					if ( isset( $type->{$type_key} ) && true === (bool) $type->{$type_key} ) {
						$checked = ' checked="checked"';
					}

					printf(
						'<tr class="form-field bp-types-form term-%1$s-wrap">
							<th scope="row"><label for="%1$s">%2$s</label></th>
							<td>
								<input name="%1$s" id="%1$s" type="checkbox" value="1"%3$s> %4$s
								<p class="description">%5$s</p>
							</td>
						</tr>',
						esc_attr( $meta_key ),
						esc_html( $labels->{ $meta_key } ),
						$checked,
						esc_html__( 'Yes', 'buddypress' ),
						esc_html( $meta_schema['description'] )
					);
				} else {
					printf(
						'<div class="form-field bp-types-form term-%1$s-wrap">
							<label for="%1$s">
								<input name="%1$s" id="%1$s" type="checkbox" value="1"> %2$s
							</label>
							<p>%3$s</p>
						</div>',
						esc_attr( $meta_key ),
						esc_html( $labels->{ $meta_key } ),
						esc_html( $meta_schema['description'] )
					);
				}
			}
		}
	}


Top ↑

Changelog Changelog

Changelog
Version Description
7.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.