Skip to content

Commit 7b20619

Browse files
committed
added: profile field restriction
1 parent 83e6f0c commit 7b20619

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

includes/wpum-fields/wpum-fields-functions.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,20 @@ function wpum_is_field_required() {
527527
return apply_filters( 'wpum_is_field_required', $wpum_field->is_required(), $wpum_field->get_ID() );
528528
}
529529

530+
/**
531+
* Verify if the field has correct user role permission.
532+
*
533+
* @return bool
534+
*/
535+
function wpum_field_has_user_role_permission( $field_id = null ) {
536+
global $wpum_field;
537+
538+
$field = $field_id ? new WPUM_Field( $field_id ) : $wpum_field;
539+
$field_roles = $field->get_meta( 'roles' );
540+
541+
return ! ( is_array( $field_roles ) && count( $field_roles ) && !count( array_intersect( wp_get_current_user()->roles, $field_roles ) ) );
542+
}
543+
530544
/**
531545
* Retrieve the current field type within a loop.
532546
*

templates/forms/form-account.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,10 @@
4545
<?php foreach ( $data->fields as $key => $field ) : ?>
4646

4747
<?php
48-
// Check if user has atleast one selected role
49-
$user = wp_get_current_user();
50-
$is_renderable = ! ( is_array( $field['roles'] ) && count( $field['roles'] ) && !count( array_intersect( $user->roles, $field['roles'] ) ) );
51-
52-
if( ! apply_filters( 'wpum_account_form_field_can_render', $is_renderable, $field, $data ) ){
53-
continue;
54-
}
48+
//Checks user has role perimission
49+
if( ! apply_filters( 'wpum_account_form_field_can_render', wpum_field_has_user_role_permission( $field['id'] ), $field, $data ) ){
50+
continue;
51+
}
5552
?>
5653

5754
<?php

templates/profiles/about.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
<table class="profile-fields-table">
3838
<tbody>
3939
<?php while ( wpum_profile_fields() ) : wpum_the_profile_field(); ?>
40-
<?php if ( wpum_field_has_data() ) : ?>
40+
<?php if ( wpum_field_has_data() && apply_filters( 'wpum_about_field_can_render', wpum_field_has_user_role_permission() ) ) : ?>
4141
<tr class="<?php wpum_the_field_css_class(); ?>">
4242
<td class="label"><?php wpum_the_field_name(); ?></td>
4343
<td class="data"><?php wpum_the_field_value(); ?></td>

0 commit comments

Comments
 (0)