- fixed roles field, which isn't customized;

This commit is contained in:
nikitasinelnikov
2020-09-22 14:30:25 +03:00
parent aeb0d7005a
commit 4ac6071aa2
3 changed files with 31 additions and 37 deletions
+5 -5
View File
@@ -3690,11 +3690,11 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
//fix when customers change options for role (radio/dropdown) fields
$intersected_options = array();
foreach ( $options as $option ) {
if ( false !== $search_key = array_search( $option, $roles ) ) {
$intersected_options[ $search_key ] = $option;
} else {
$intersected_options[] = $option;
foreach ( $options as $key => $title ) {
if ( false !== $search_key = array_search( $title, $roles ) ) {
$intersected_options[ $search_key ] = $title;
} elseif ( isset( $roles[ $key ] ) ) {
$intersected_options[ $key ] = $title;
}
}
+10 -15
View File
@@ -587,7 +587,6 @@ if ( ! class_exists( 'um\core\Form' ) ) {
function custom_field_roles( $custom_fields ) {
$fields = maybe_unserialize( $custom_fields );
if ( ! is_array( $fields ) ) {
return false;
}
@@ -606,22 +605,18 @@ if ( ! class_exists( 'um\core\Form' ) ) {
foreach ( $fields as $field_key => $field_settings ) {
if ( strstr( $field_key , 'role_' ) ) {
if ( is_array( $field_settings['options'] ) ) {
//$option_pairs = apply_filters( 'um_select_options_pair', null, $field_settings );
$intersected_options = array();
foreach ( $field_settings['options'] as $option ) {
if ( false !== $search_key = array_search( $option, $roles ) ) {
$intersected_options[ $search_key ] = $option;
} else {
$intersected_options[] = $option;
}
if ( strstr( $field_key, 'role_' ) && is_array( $field_settings['options'] ) ) {
$intersected_options = array();
foreach ( $field_settings['options'] as $key => $title ) {
if ( false !== $search_key = array_search( $title, $roles ) ) {
$intersected_options[ $search_key ] = $title;
} elseif ( isset( $roles[ $key ] ) ) {
$intersected_options[ $key ] = $title;
}
//return ! empty( $option_pairs ) ? array_keys( $field_settings['options'] ) : array_values( $field_settings['options'] );
return array_keys( $intersected_options );
}
// getting roles only from the first role fields
return array_keys( $intersected_options );
}
}
+16 -17
View File
@@ -920,9 +920,9 @@ if ( ! class_exists( 'um\core\Shortcodes' ) ) {
*
* @return mixed|string
*/
function get_template_name($file) {
$file = basename($file);
$file = preg_replace('/\\.[^.\\s]{3,4}$/', '', $file);
function get_template_name( $file ) {
$file = basename( $file );
$file = preg_replace( '/\\.[^.\\s]{3,4}$/', '', $file );
return $file;
}
@@ -934,32 +934,32 @@ if ( ! class_exists( 'um\core\Shortcodes' ) ) {
*
* @return mixed
*/
function get_templates($excluded = null) {
function get_templates( $excluded = null ) {
if ($excluded) {
$array[$excluded] = __('Default Template', 'ultimate-member');
if ( $excluded ) {
$array[ $excluded ] = __( 'Default Template', 'ultimate-member' );
}
$paths[] = glob(um_path . 'templates/' . '*.php');
$paths[] = glob( um_path . 'templates/' . '*.php' );
if (file_exists(get_stylesheet_directory() . '/ultimate-member/templates/')) {
$paths[] = glob(get_stylesheet_directory() . '/ultimate-member/templates/' . '*.php');
if ( file_exists( get_stylesheet_directory() . '/ultimate-member/templates/' ) ) {
$paths[] = glob( get_stylesheet_directory() . '/ultimate-member/templates/' . '*.php' );
}
if( isset( $paths ) && ! empty( $paths ) ){
if ( isset( $paths ) && ! empty( $paths ) ) {
foreach ($paths as $k => $files) {
foreach ( $paths as $k => $files ) {
if( isset( $files ) && ! empty( $files ) ){
if ( isset( $files ) && ! empty( $files ) ) {
foreach ($files as $file) {
foreach ( $files as $file ) {
$clean_filename = $this->get_template_name( $file );
if ( 0 === strpos( $clean_filename, $excluded ) ) {
$source = file_get_contents( $file );
$tokens = token_get_all( $source );
$tokens = @\token_get_all( $source );
$comment = array(
T_COMMENT, // All comments since PHP5
T_DOC_COMMENT, // PHPDoc comments
@@ -967,8 +967,8 @@ if ( ! class_exists( 'um\core\Shortcodes' ) ) {
foreach ( $tokens as $token ) {
if ( in_array( $token[0], $comment ) && strstr( $token[1], '/* Template:' ) && $clean_filename != $excluded ) {
$txt = $token[1];
$txt = str_replace('/* Template: ', '', $txt );
$txt = str_replace(' */', '', $txt );
$txt = str_replace( '/* Template: ', '', $txt );
$txt = str_replace( ' */', '', $txt );
$array[ $clean_filename ] = $txt;
}
}
@@ -984,7 +984,6 @@ if ( ! class_exists( 'um\core\Shortcodes' ) ) {
}
return $array;
}