BP_XProfile_Field_Type_Datebox::admin_new_field_html( BP_XProfile_Field $current_field, string $control_type = '' )

Generate the settings markup for Date fields.


Parameters Parameters

$current_field

(BP_XProfile_Field) (Required) The current profile field on the add/edit screen.

$control_type

(string) (Optional) HTML input type used to render the current field's child options.

Default value: ''


Source Source

File: bp-xprofile/classes/class-bp-xprofile-field-type-datebox.php

	public function admin_new_field_html( BP_XProfile_Field $current_field, $control_type = '' ) {
		$type = array_search( get_class( $this ), bp_xprofile_get_field_types() );

		if ( false === $type ) {
			return;
		}

		$class = $current_field->type != $type ? 'display: none;' : '';

		$settings = self::get_field_settings( $current_field->id );
		?>

<div id="<?php echo esc_attr( $type ); ?>" class="postbox bp-options-box" style="<?php echo esc_attr( $class ); ?> margin-top: 15px;">
	<table class="form-table bp-date-options">
		<tr>
			<th scope="row">
				<?php esc_html_e( 'Date format', 'buddypress' ); ?>
			</th>

			<td>
				<fieldset>
					<legend class="screen-reader-text">
						<?php esc_html_e( 'Date format', 'buddypress' ); ?>
					</legend>

					<?php foreach ( $this->get_date_formats() as $format ): ?>
						<div class="bp-date-format-option">
							<label for="date-format-<?php echo esc_attr( $format ); ?>">
								<input type="radio" name="field-settings[date_format]" id="date-format-<?php echo esc_attr( $format ); ?>" value="<?php echo esc_attr( $format ); ?>" <?php checked( $format, $settings['date_format'] ); ?> />
								<span class="date-format-label"><?php echo date_i18n( $format ); ?></span>
								<code><?php echo esc_html( $format ); ?></code>
							</label>
						</div>
					<?php endforeach;?>

					<div class="bp-date-format-option">
						<label for="date-format-elapsed">
							<input type="radio" name="field-settings[date_format]" id="date-format-elapsed" <?php checked( 'elapsed', $settings['date_format'] ); ?> value="elapsed" aria-describedby="date-format-elapsed-setting" />
							<span class="date-format-label" id="date-format-elapsed-setting"><?php esc_html_e( 'Time elapsed', 'buddypress' ); ?></span> <?php printf( '<code>%1$s</code>, <code>%2$s</code>', esc_html__( '4 years ago', 'buddypress' ), esc_html__( '4 years from now', 'buddypress' ) ); ?>
						</label>
					</div>

					<div class="bp-date-format-option">
						<label for="date-format-age">
							<input type="radio" name="field-settings[date_format]" id="date-format-age" <?php checked( 'age', $settings['date_format'] ); ?> value="age" aria-describedby="date-format-age-setting" />
							<span class="date-format-label" id="date-format-age-setting"><?php esc_html_e( 'Age', 'buddypress' ); ?></span> <?php printf( '<code>%s</code>', esc_html__( '20 years old', 'buddypress' ) ); ?>
						</label>
					</div>

					<div class="bp-date-format-option">
						<label for="date-format-custom">
							<input type="radio" name="field-settings[date_format]" id="date-format-custom" <?php checked( 'custom', $settings['date_format'] ); ?> value="custom" />
							<span class="date-format-label"><?php esc_html_e( 'Custom:', 'buddypress' ); ?></span>
						</label>
						<label for="date-format-custom-value" class="screen-reader-text"><?php esc_html_e( 'Enter custom time format', 'buddypress' ); ?></label>
						<input type="text" name="field-settings[date_format_custom]" id="date-format-custom-value" class="date-format-custom-value" value="<?php echo esc_attr( $settings['date_format_custom'] ); ?>" aria-describedby="date-format-custom-example" /> <span class="screen-reader-text"><?php esc_html_e( 'Example:', 'buddypress' ); ?></span><span class="date-format-custom-example" id="date-format-custom-sample"><?php if ( $settings['date_format_custom'] ) : ?><?php echo esc_html( date_i18n( $settings['date_format_custom'] ) ); endif; ?></span><span class="spinner" id="date-format-custom-spinner" aria-hidden="true"></span>

						<p><a href="https://codex.wordpress.org/Formatting_Date_and_Time"><?php esc_html_e( 'Documentation on date and time formatting', 'buddypress' ); ?></a></p>
					</div>

				</fieldset>
			</td>
		</tr>

		<tr>
			<th scope="row">
				<?php esc_html_e( 'Range', 'buddypress' ); ?>
			</th>

			<td>
				<fieldset class="bp-range-types">
					<legend class="screen-reader-text">
						<?php esc_html_e( 'Range', 'buddypress' ); ?>
					</legend>

					<div class="bp-date-format-option">
						<div class="bp-date-range-type-label">
							<label for="range_type_absolute">
								<input type="radio" name="field-settings[range_type]" id="range_type_absolute" value="absolute" <?php checked( 'absolute', $settings['range_type'] ); ?> />
								<?php esc_html_e( 'Absolute', 'buddypress' ); ?>
							</label>
						</div>

						<div class="bp-date-range-type-values">
							<label for="field-settings[range_absolute_start]" aria-label="Year"><?php esc_html_e( 'Start:', 'buddypress' ); ?></label>
							<?php printf( '<input class="date-range-numeric" type="text" name="field-settings[range_absolute_start]" id="field-settings[range_absolute_start]" value="%s" />', esc_attr( $settings['range_absolute_start'] ) ); ?>
							<label for="field-settings[range_absolute_end]" aria-label="Year"><?php esc_html_e( 'End:', 'buddypress' ); ?></label>
							<?php printf( '<input class="date-range-numeric" type="text" name="field-settings[range_absolute_end]" id="field-settings[range_absolute_end]" value="%s" />', esc_attr( $settings['range_absolute_end'] ) ); ?>
						</div>
					</div>

					<div class="bp-date-format-option">
						<div class="bp-date-range-type-label">
							<label for="range_type_relative">
								<input type="radio" name="field-settings[range_type]" id="range_type_relative" value="relative" <?php checked( 'relative', $settings['range_type'] ); ?> />
								<?php esc_html_e( 'Relative', 'buddypress' ); ?>
							</label>
						</div>

						<div class="bp-date-range-type-values">
							<label for="field-settings[range_relative_start]"><?php esc_html_e( 'Start:', 'buddypress' ); ?></label>
							<?php printf( '<input type="text" class="date-range-numeric" name="field-settings[range_relative_start]" id="field-settings[range_relative_start]" value="%s" />',
								esc_attr( abs( $settings['range_relative_start'] ) )
								);
							?>

							<label class="screen-reader-text" for="field-settings[range_relative_start_type]"><?php esc_html_e( 'Select range', 'buddypress' ); ?></label>
							<?php printf( '<select name="field-settings[range_relative_start_type]" id="field-settings[range_relative_start_type]"><option value="past" %s>%s</option><option value="future" %s>%s</option></select>',
								selected( true, $settings['range_relative_start'] <= 0, false ),
								esc_attr__( 'years ago', 'buddypress' ),
								selected( true, $settings['range_relative_start'] > 0, false ),
								esc_attr__( 'years from now', 'buddypress' )
								);
							?>

							<label for="field-settings[range_relative_end]"><?php esc_html_e( 'End:', 'buddypress' ); ?></label>
							<?php printf( '<input type="text" class="date-range-numeric" name="field-settings[range_relative_end]" id="field-settings[range_relative_end]" value="%s" />',
								esc_attr( abs( $settings['range_relative_end'] ) )
								);
							?>
							<label class="screen-reader-text" for="field-settings[range_relative_end_type]"><?php esc_html_e( 'Select range', 'buddypress' ); ?></label>
							<?php printf( '<select name="field-settings[range_relative_end_type]" id="field-settings[range_relative_end_type]"><option value="past" %s>%s</option><option value="future" %s>%s</option></select>',
									selected( true, $settings['range_relative_end'] <= 0, false ),
									esc_attr__( 'years ago', 'buddypress' ),
									selected( true, $settings['range_relative_end'] > 0, false ),
									esc_attr__( 'years from now', 'buddypress' )
								);
							?>
						</div>
					</div>

				</fieldset>
			</td>
		</tr>
	</table>
</div>
		<?php
	}


Top ↑

Changelog Changelog

Changelog
Version Description
2.7.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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