Skip to content

Commit b3c118f

Browse files
authored
Reset health circle option icon when alternate set (#2913)
* Reset health circle unused icon when alternate updated * Custom fields: Use null when restoring field icon default Ensures that restoring a custom field icon sets the value to null instead of an empty string, improving compatibility with icon existence checks.
1 parent 9500957 commit b3c118f

2 files changed

Lines changed: 28 additions & 23 deletions

File tree

dt-core/admin/admin-settings-endpoints.php

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -975,14 +975,14 @@ public static function new_field_option( WP_REST_Request $request ) {
975975
'description' => $new_field_option_description,
976976
];
977977

978-
if ( $field_option_icon ){
978+
if ( $field_option_icon ) {
979979
$field_option_icon = strtolower( trim( $field_option_icon ) );
980980
$icon_key = ( strpos( $field_option_icon, 'mdi' ) !== 0 ) ? 'icon' : 'font-icon';
981-
$custom_field_options[$post_type][$field_key]['default'][$new_field_option_key][$icon_key] = $field_option_icon;
981+
$null_icon_key = ( $icon_key === 'font-icon' ) ? 'icon' : 'font-icon';
982982

983-
if ( $icon_key == 'font-icon' ){
984-
$custom_field_options[$post_type][$field_key]['default'][$new_field_option_key]['icon'] = '';
985-
}
983+
// reset unused icon key
984+
$custom_field_options[ $post_type ][ $field_key ]['default'][ $new_field_option_key ][ $icon_key ] = $field_option_icon;
985+
$custom_field_options[ $post_type ][ $field_key ]['default'][ $new_field_option_key ][ $null_icon_key ] = null;
986986
}
987987

988988
update_option( 'dt_field_customizations', $custom_field_options );
@@ -1021,17 +1021,14 @@ public static function edit_field_option( WP_REST_Request $request ) {
10211021
$custom_field_option['description'] = $new_field_option_description;
10221022
}
10231023

1024-
if ( $field_option_icon && strpos( $field_option_icon, 'undefined' ) === false ){
1024+
if ( $field_option_icon && strpos( $field_option_icon, 'undefined' ) === false ) {
10251025
$field_option_icon = strtolower( trim( $field_option_icon ) );
10261026
$icon_key = ( strpos( $field_option_icon, 'mdi' ) !== 0 ) ? 'icon' : 'font-icon';
1027+
$null_icon_key = ( $icon_key === 'font-icon' ) ? 'icon' : 'font-icon';
10271028

1028-
if ( $field_option_icon !== $field_option[$icon_key] ){
1029-
$custom_field_option[$icon_key] = $field_option_icon;
1030-
}
1031-
1032-
if ( $icon_key == 'font-icon' ){
1033-
$custom_field_option['icon'] = '';
1034-
}
1029+
// reset unused icon key
1030+
$custom_field_option[ $icon_key ] = $field_option_icon;
1031+
$custom_field_option[ $null_icon_key ] = null;
10351032
}
10361033

10371034
// Create default_name to store the default field option label if it changed

dt-core/admin/menu/tabs/tab-custom-fields.php

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,8 @@ private function process_edit_field( $post_submission ){
10361036
//restore field icon
10371037
if ( isset( $post_submission['restore_field_icon'] ) ) {
10381038
$restore_icon_defaults = apply_filters( 'dt_custom_fields_settings', [], $post_type );
1039-
$custom_field['icon'] = $restore_icon_defaults[ $field_key ]['icon'];
1039+
$custom_field['icon'] = $restore_icon_defaults[ $field_key ]['icon'] ?? null;
1040+
$custom_field['font-icon'] = $restore_icon_defaults[ $field_key ]['font-icon'] ?? null;
10401041
}
10411042

10421043
// number field options
@@ -1138,10 +1139,8 @@ private function process_edit_field( $post_submission ){
11381139
$null_icon_key = ( $icon_key === 'font-icon' ) ? 'icon' : 'font-icon';
11391140

11401141
// Update icon accordingly and nullify alternative
1141-
if ( ! isset( $field_options[ $option_key ][ $icon_key ] ) || $field_options[ $option_key ][ $icon_key ] != $val ) {
1142-
$custom_field['default'][ $option_key ][ $icon_key ] = $val;
1143-
$custom_field['default'][ $option_key ][ $null_icon_key ] = null;
1144-
}
1142+
$custom_field['default'][ $option_key ][ $icon_key ] = $val;
1143+
$custom_field['default'][ $option_key ][ $null_icon_key ] = null;
11451144
$field_options[ $option_key ][ $icon_key ] = $val;
11461145
}
11471146
} else {
@@ -1179,14 +1178,23 @@ private function process_edit_field( $post_submission ){
11791178
}
11801179
//delete icon
11811180
if ( isset( $post_submission['delete_icon'] ) ) {
1182-
$custom_field['default'][ $post_submission['delete_icon'] ]['icon'] = '';
1183-
$field_options[ $post_submission['delete_icon'] ]['icon'] = '';
1181+
$option_key = $post_submission['delete_icon'];
1182+
$custom_field['default'][ $option_key ]['icon'] = null;
1183+
$custom_field['default'][ $option_key ]['font-icon'] = null;
1184+
$field_options[ $option_key ]['icon'] = null;
1185+
$field_options[ $option_key ]['font-icon'] = null;
11841186
}
11851187
//restore icon
11861188
if ( isset( $post_submission['restore_icon'] ) ) {
1187-
$restore_icon_defaults = apply_filters( 'dt_custom_fields_settings', [], $post_type );
1188-
$custom_field['default'][ $post_submission['restore_icon'] ]['icon'] = $restore_icon_defaults[ $field_key ]['default'][ $post_submission['restore_icon'] ]['icon'];
1189-
$field_options[ $post_submission['restore_icon'] ]['icon'] = $restore_icon_defaults[ $field_key ]['default'][ $post_submission['restore_icon'] ]['icon'];
1189+
$option_key = $post_submission['restore_icon'];
1190+
$restore_icon_defaults = apply_filters( 'dt_custom_fields_settings', [], $post_type );
1191+
$default_icon = $restore_icon_defaults[ $field_key ]['default'][ $option_key ]['icon'] ?? '';
1192+
$default_font_icon = $restore_icon_defaults[ $field_key ]['default'][ $option_key ]['font-icon'] ?? null;
1193+
1194+
$custom_field['default'][ $option_key ]['icon'] = $default_icon;
1195+
$custom_field['default'][ $option_key ]['font-icon'] = $default_font_icon;
1196+
$field_options[ $option_key ]['icon'] = $default_icon;
1197+
$field_options[ $option_key ]['font-icon'] = $default_font_icon;
11901198
}
11911199
//delete option
11921200
if ( isset( $post_submission['delete_option'] ) ){

0 commit comments

Comments
 (0)