Fix setting default values

This commit is contained in:
Justin Shreve 2019-01-18 12:10:25 -05:00
parent bd54541ca0
commit b8d25c3073
2 changed files with 13 additions and 24 deletions

View File

@ -166,7 +166,19 @@ export default compose(
isReportItemsRequesting,
} = select( 'wc-api' );
const userData = getCurrentUserData();
const userPrefs = userData.dashboard_performance_indicators;
let userPrefs = userData.dashboard_performance_indicators;
// Set default values for user preferences if none is set.
// These columns are HIDDEN by default.
if ( ! userPrefs ) {
userPrefs = [
'coupons/orders_count',
'taxes/total_tax',
'taxes/order_tax',
'taxes/shipping_tax',
'downloads/download_count',
];
}
const datesFromQuery = getCurrentDates( query );
const endPrimary = datesFromQuery.primary.before;

View File

@ -173,8 +173,6 @@ function wc_admin_print_script_settings() {
$current_user_data[ $user_field ] = json_decode( get_user_meta( get_current_user_id(), 'wc_admin_' . $user_field, true ) );
}
$current_user_data = wc_admin_get_user_defaults( $current_user_data );
/**
* TODO: On merge, once plugin images are added to core WooCommerce, `wcAdminAssetUrl` can be retired, and
* `wcAssetUrl` can be used in its place throughout the codebase.
@ -214,27 +212,6 @@ function wc_admin_print_script_settings() {
}
add_action( 'admin_print_footer_scripts', 'wc_admin_print_script_settings', 1 );
/**
* Sets default values for user preferences.
*
* @param array $user_data Array of user data.
* @return array Filtered array of user data.
*/
function wc_admin_get_user_defaults( $user_data ) {
// If no settings for performance indicators are stored, these are the defaults to disable.
if ( ! is_array( $user_data['dashboard_performance_indicators'] ) ) {
$user_data['dashboard_performance_indicators'] = array(
'coupons/orders_count',
'taxes/total_tax',
'taxes/order_tax',
'taxes/shipping_tax',
'downloads/download_count',
);
}
return $user_data;
}
/**
* Load plugin text domain for translations.
*/