Skip to content

Commit

Permalink
🐛 Fix privacy checkbox not apearing when profile addon is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel-James committed Apr 1, 2019
1 parent ac005fd commit 48d3b49
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
3 changes: 1 addition & 2 deletions app/view/shortcode/class-ms-view-shortcode-registeruser.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,7 @@ static public function add_scripts() {
'equalTo' => '.ms-form-element #password',
),
'privacy_check' => array(
'required' => true,
'equalTo' => '.ms-form-element #privacy_check',
'required' => true
),
);

Expand Down
28 changes: 17 additions & 11 deletions premium/addon/profilefields/class-ms-addon-profilefields.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class MS_Addon_Profilefields extends MS_Addon {
* @since 1.0.1.0
* @return bool
*/
static public function is_active() {
public static function is_active() {
return MS_Model_Addon::is_enabled( self::ID );
}

Expand Down Expand Up @@ -184,7 +184,7 @@ public function manage_render_callback( $callback, $tab, $data ) {
* @since 1.0.1.0
* @return array
*/
static public function list_fields() {
public static function list_fields() {
static $Profile_Fields = null;

if ( null === $Profile_Fields ) {
Expand Down Expand Up @@ -385,6 +385,12 @@ public function customize_register_form( $fields, $view ) {

$custom_fields = $this->customize_form( $custom_fields, $data, $config );

// allways add privary field if exist
// admin can disable this field by leave blank in privacy setting page
if( isset( $fields['privacy_check'] ) ){
$custom_fields[] = $fields['privacy_check'];
}

return $custom_fields;
}

Expand All @@ -410,23 +416,18 @@ public function required_fields( $fields ) {
$key = 'field_' . substr( $field, 9 );
}

if ( 'required' == $setting ) {

if ( 'required' == $setting && isset( $all_fields[ $field ] ) ) {
if( 'datebox' == $all_fields[$field]['type'] && 0 === strpos( $field, 'xprofile_' ) ){

if( function_exists( 'xprofile_get_field' ) ){

$xfield_id = substr( $field, 9 );
$xfield = xprofile_get_field( $xfield_id );

$required[$key . '_day'] = $all_fields[$field]['label'];
$required[$key . '_month'] = $all_fields[$field]['label'];
$required[$key . '_year'] = $all_fields[$field]['label'];

}

}
else{
}
} else {
$required[$key] = $all_fields[$field]['label'];
}

Expand Down Expand Up @@ -555,7 +556,12 @@ protected function customize_form( $fields, $data, $config ) {
*/
public function register_rules( $rules ) {
$settings = MS_Plugin::instance()->settings;
$config = $settings->get_custom_setting( 'profilefields', 'register' );
$config = (array) $settings->get_custom_setting( 'profilefields', 'register' );

// Make sure privacy field is required.
if( isset( $rules['privacy_check'] ) ){
$config['privacy_check'] = 'required';
}

return $this->validation_rules( $config );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ public function prepare_fields() {
$profile_fields = MS_Addon_Profilefields::list_fields();

$reg_config = $settings->get_custom_setting( 'profilefields', 'register' );
$reg_config = mslib3()->array->get($reg_config);
$edit_config = $settings->get_custom_setting( 'profilefields', 'profile' );
$edit_config = mslib3()->array->get($edit_config);
$was_initialized = false;

$registration_options = array(
Expand Down

0 comments on commit 48d3b49

Please sign in to comment.