Set Default value in Timezone Component

Balamurali Govindan Posted in Component Development 3 years ago

I would like to default the timezone to a specific standard time for all the users on registration and remove the timezone mandatory field from the "Registration Page". Please help. Thanks.

Replies
Portuguese Erwin Maas Replied 7 months ago

Thank you very much, this is perfect, exactly what I meant: no timezone-field in registration screen but only adjustable in user-profile!

Great piece of software by the way, I use it for less than 2 weeks now, still solving some issues on the host-side and adjusting the software here and there.

I am planning to rewrite the whole Dutch translation file and I have some ideas for developing components and themes in the future, but I have to study the code and the architecture a bit first and get everything in order on the host-side.

I'll definitely will be back to try and help you out!

Indonesian Arsalan Shah Replied 7 months ago

Sorry my code had issue you need to replace the original function in your timezone ossn_com;php file

function time_zone_init(){
            if(ossn_isLoggedin()){
                $user = ossn_loggedin_user();
                if(isset($user->timezone)){
                        date_default_timezone_set($user->timezone); 
                }
                 ossn_add_hook('user', 'default:fields', 'time_zone_only_loggedin');
            }
}
Portuguese Erwin Maas Replied 7 months ago

Thank you

-I have first flushed and switched off cache, left the website and cleaned browser-cache (Edge)
-Then I added your code and switched off the original code with /* ... */ but the timezonefield was still there
-Then I switched off the last else in your code and the field is gone, the page is working fine

Will that switching off the last else have any consequences for the functionality of the timezone-component? I mean, will I still be able to use it's values in another script later? Or does it break the plugin completely? (I have looked at my user-profiles' settings-page but with or without the else there's no timezone-field there)

The site is here

Indonesian Arsalan Shah Replied 7 months ago

There are two ways one way to remove is to not to add for non-loggedin users

function time_zone_init(){
        if(ossn_isLoggedin()){
            $user = ossn_loggedin_user();
            if(isset($user->timezone)){
                    date_default_timezone_set($user->timezone); 
            }
        } else   {
                       ossn_add_hook('user', 'default:fields', 'time_zone_only_loggedin');
       }
}

.

Portuguese Erwin Maas Replied 7 months ago

I have implemented the code Arsalan gave, but it doesn't remove the timezone-field from the registration page.

I have had several requests to make this easier for people on mobile phones, it's a huge list with large font-size and finding your right timezone is difficult for a lot of people because it is not sorted on timezone but on time.

Is there a way to A: either remove the whole field from the registration-page or B: sort the list on:
1. Continent
2. City
?

Thanks in advance!

in Balamurali Govindan Replied 3 years ago

Awesome. It worked well. Thank You Arsalan.

Indonesian Arsalan Shah Replied 3 years ago

Edit components/TimeZone/ossn.com.php

Around 79 to 86 edit

    $extrafield =   array(
        'class' => 'timezone-dropdown',
        'name' => 'timezone',
        'label' => $label,
        'placeholder' => $placeholder,
        'display_on_about_page' => false,
        'options' => $zones,
        'value' => 'Your Value from https://www.php.net/manual/en/timezones.php'
    );