false, 'required' => true, 'do_autolink' => false, 'allow_custom_visibility' => false, 'member_types' => false, ); /** * Constructor for the Checkbox Acceptance field type. * * @since 8.0.0 */ public function __construct() { parent::__construct(); $this->name = _x( 'Checkbox Acceptance', 'xprofile field type', 'buddypress' ); $this->category = _x( 'Single Fields', 'xprofile field type category', 'buddypress' ); $this->supports_options = false; $this->do_settings_section = true; $this->accepts_null_value = false; $this->set_format( '/^.+$/', 'replace' ); /** * Fires inside __construct() method for bp_xprofile_field_type_checkbox_acceptance class. * * @since 8.0.0 * * @param BP_XProfile_Field_Type_Checkbox_Acceptance $this Current instance of the Checkbox Acceptance field type. */ do_action( 'bp_xprofile_field_type_checkbox_acceptance', $this ); // Make sure it's not possible to edit an accepted Checkbox Acceptance field. add_filter( 'bp_xprofile_set_field_data_pre_validate', array( $this, 'enforce_field_value' ), 10, 2 ); } /** * Output the edit field HTML for this field type. * * Must be used inside the {@link bp_profile_fields()} template loop. * * @since 8.0.0 * * @param array $raw_properties Optional key/value array of * {@link http://dev.w3.org/html5/markup/textarea.html permitted attributes} * that you want to add. */ public function edit_field_html( array $raw_properties = array() ) { $user_id = bp_displayed_user_id(); $required = false; $default_r = array(); if ( isset( $raw_properties['user_id'] ) ) { $user_id = (int) $raw_properties['user_id']; unset( $raw_properties['user_id'] ); } if ( bp_get_the_profile_field_is_required() ) { $default_r['required'] = 'required'; // HTML5 required attribute. $required = true; } $r = bp_parse_args( $raw_properties, $default_r, 'checkbox_acceptance' ); ?>
User->Profile Fields screen. * * @since 8.0.0 * * @param array $raw_properties properties. */ public function admin_field_html( array $raw_properties = array() ) { $page_id = bp_xprofile_get_meta( bp_get_the_profile_field_id(), 'field', 'bp_xprofile_checkbox_acceptance_page', true ); $page = null; $default_r = array( 'type' => 'checkbox' ); if ( bp_get_the_profile_field_is_required() ) { $default_r['required'] = 'required'; // HTML5 required attribute. } $r = bp_parse_args( $raw_properties, $default_r, 'checkbox_acceptance' ); if ( $page_id ) { $page = get_post( $page_id ); } ?> type != $type ? 'display: none;' : ''; $page_id = bp_xprofile_get_meta( $current_field->id, 'field', 'bp_xprofile_checkbox_acceptance_page', true ); ?> field_obj->id; $params = bp_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( '