Hi, thanks for the kinds words. It is possible to do with the use of (code) a filter hook. You’ll need to create your own plugin, mu-plugin or put it in your theme (which is advised against generally anyway).
Check out the wiki on GitHub for more info: https://github.com/danieltj27/Dark-Mode/wiki/Filter:-not_using_dark_mode
This should do the trick:
function dtj_dark_mode_user_default( $user_id ) {
// Get the user's Dark Mode preference.
$user_pref = get_user_meta( $user_id, 'dark_mode', true );
/**
* Does the user not have a value set?
*
* If 'false' is returned by 'get_user_meta' then that
* means that the user has not saved their preference yet
* so set the default value instead. This applies to all users.
*
* You can do a further check on the '$user_id' to only limit
* this to a certain subset of user's on the website.
*/
if ( ! $user_pref ) {
// This is the default value when no preference is set.
return true;
}
return false;
}
add_filter( 'not_using_dark_mode', 'dtj_dark_mode_user_default', 10, 1 );
I’ve not tested this properly, so you might need to pay around with it to get it to do exactly what you’re after.
-
This reply was modified 5 years, 8 months ago by danieltj.
-
This reply was modified 5 years, 8 months ago by danieltj. Reason: Fix code formatting