Skip to content

Commit 83e6f0c

Browse files
committed
resolves Add role selector to custom field permission tab #232
1 parent 1498653 commit 83e6f0c

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

includes/abstracts/abstract-wpum-field-type.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ protected function get_default_editor_settings() {
229229
'label' => esc_html__( 'Roles', 'wp-user-manager' ),
230230
'model' => 'roles',
231231
'default' => array(),
232-
'options' => wpum_get_roles( true ),
232+
'options' => wpum_get_roles( true, true ),
233233
'multiple' => true,
234234
'hint' => esc_html__( 'Show the fields only for selected users', 'wp-user-manager' )
235235
)

includes/wpum-forms/class-wpum-form-profile.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ private function get_account_fields() {
187187
'value' => $this->get_user_field_value( $this->user, $field ),
188188
'priority' => $priority,
189189
'template' => $field->get_parent_type(),
190+
'roles' => $field->get_meta( 'roles' )
190191
);
191192

192193
$data = array_merge( $data, $field->get_field_data() );

templates/forms/form-account.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@
4444

4545
<?php foreach ( $data->fields as $key => $field ) : ?>
4646

47+
<?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+
}
55+
?>
56+
4757
<?php
4858
// Parent field should handle the child field rendering
4959
if( in_array( $field['type'], wpum_get_registered_parent_field_types() ) ){

0 commit comments

Comments
 (0)