strangerstudios/pmpro-register-helper

Bug: Value attribute doesn't work when registering a field

Opened this issue · 1 comments

Describe the bug
When registering a field and setting the value for that field, this is no longer getting carried through and doesn't show in the field.

To Reproduce
Steps to reproduce the behavior:

  1. Use this recipe:
function hide_from_directory_by_default_example() {
	// don't break if Register Helper is not loaded
	if ( ! function_exists( 'pmprorh_add_registration_field' ) || is_admin() ) {
		return false;
	}
	// define the fields
	$fields = array();
	$fields[] = new PMProRH_Field(
		'pmpromd_hide_directory',
		'hidden',
		array(
			'showmainlabel' => false,
			// 'profile' => 'admin',
			'value'   => '1',
		)
	);
	foreach ( $fields as $field ) {
		pmprorh_add_registration_field(
			'checkout_boxes', // location on checkout page
			$field            // PMProRH_Field object
		);
	}
	// that's it. see the PMPro Register Helper readme for more information and examples.
}
add_action( 'init', 'hide_from_directory_by_default_example' );
  1. View page source. Search for pmpromd_hide_directory. The value will be empty. It should have a value of 1

Screenshots
image

Expected behavior
A value of 1 should be available in that field

Isolating the problem (mark completed items with an [x]):

  • I have deactivated other plugins and confirmed this bug occurs when only Paid Memberships Pro plugin is active.
  • This bug happens with a default WordPress theme active, or Memberlite.
  • I can reproduce this bug consistently using the steps above.

WordPress Environment
WP 5.5.1
PMPro 2.4.4
Register Helper 1.7

Further testing has found that this works when you're a visitor. Doesn't work when you're logged in.

Reference to where the logic for this happens:

} elseif ( ! empty( $current_user->ID ) ) {
$userdata = get_userdata( $current_user->ID );
if ( ! empty( $userdata->{$this->name} ) ) {
$value = $userdata->{$this->name};
} else {
$value = '';
}
}
elseif(!empty($this->value))
$value = $this->value;