BP_XProfile_Field_Type_Checkbox_Acceptance::edit_field_options_html( array $args = array() )

Profile edit/register options html.


Parameters Parameters

$args

(array) (Optional) args.

Default value: array()


Source Source

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

	public function edit_field_options_html( array $args = array() ) {
		$field_id            = (int) $this->field_obj->id;
		$params              = wp_parse_args( $args, array( 'user_id' => bp_displayed_user_id() ) );
		$checkbox_acceptance = (int) maybe_unserialize( \BP_XProfile_ProfileData::get_value_byid( $field_id, $params['user_id'] ) );

		if ( ! empty( $_POST[ 'field_' . $field_id ] ) ) {
			$new_checkbox_acceptance = (int) wp_unslash( $_POST[ 'field_' . $field_id ] );

			if ( $checkbox_acceptance !== $new_checkbox_acceptance ) {
				$checkbox_acceptance = $new_checkbox_acceptance;
			}
		}

		$r = array(
			'type'     => 'checkbox',
			'name'     => bp_get_the_profile_field_input_name(),
			'id'       => bp_get_the_profile_field_input_name(),
			'value'    => 1,
			'class'    => 'checkbox-acceptance',
		);

		if ( bp_get_the_profile_field_is_required() ) {
			$r['required'] = 'required'; // HTML5 required attribute.
		}

		if ( 1 === $checkbox_acceptance ) {
			$r['checked']  = 'checked';
			$r['readonly'] = 'readonly';
			$r['onclick']  = 'return false;';
		}

		$page_id = bp_xprofile_get_meta( $field_id, 'field', 'bp_xprofile_checkbox_acceptance_page', true );
		$page    = null;
		$html    = '';

		if ( $page_id ) {
			$page = get_post( $page_id );
		}

		if ( $page instanceof WP_Post ) {
			$html = sprintf(
				'<div class="bp-xprofile-checkbox-acceptance-field"><input %1$s />%2$s</div>',
				$this->get_edit_field_html_elements( $r ),
				sprintf(
					/* translators: %s: link to the page the user needs to accept the terms of. */
					esc_html__( 'I agree to %s.', 'buddypress' ),
					'<a href="' . esc_url( get_permalink( $page ) ) . '">' . esc_html( get_the_title( $page ) ) . '</a>'
				)
			);
		}

		/**
		 * Filter here to edit the HTML output.
		 *
		 * @since 8.0.0
		 *
		 * @param string $html                The HTML output.
		 * @param int    $field_id            The field ID.
		 * @param array  $r                   The edit field HTML elements data.
		 * @param int    $checkbox_acceptance The field value.
		 */
		echo apply_filters( 'bp_get_the_profile_field_checkbox_acceptance', $html, $field_id, $checkbox_acceptance );
	}


Top ↑

Changelog Changelog

Changelog
Version Description
8.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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