0

Let's say I have a multisite network running with Buddypress and has Gravity Forms installed with the GF User Registration addon. During new user/site registration, is there ANY way I can have the user set their time zone by selecting from a Gravity Form drop down menu the timezone they want?

Basically, I don't want the user to have to login to WP and then go to General settings to change their time zones. Is there any way of achieving this without having to edit any core WP code?

  • 1
    the answer is yes. – Mark Kaplun Dec 21 '13 at 15:16
  • Would you be able to elaborate on what code I should use to accomplish this or at least point me in the right direction? Thank you in advance. – Denis Lam Dec 22 '13 at 15:37
  • what do you have working, what is the difficulty you are facing? you will rarely get answers here if you don't show any attempt at doing things yourself. – Mark Kaplun Dec 22 '13 at 15:52
  • I have searched Wordpress API and cannot find any function that allows me to change the time zone for a specific user. I only found functions that allow me to display the set time such as: codex.wordpress.org/Function_Reference/current_time On the other hand there is a PHP function I can use: date_default_timezone_set('America/Los_Angeles'); However, I do not want a global timezone change for the network, I want it to be specific per user. Any pointers would be appreciated. Thank you in advance! – Denis Lam Dec 23 '13 at 21:38
  • There is no such thing in wordpress as a "per user time zone" what do you mean in that? what is the effect you are trying to create? – Mark Kaplun Dec 24 '13 at 4:55
0

Quoting from How to get WordPress Time Zone setting? you can set the option 'gmt_offset' with the appropriate offset from UTC.

You should add the option to control it only in you site creation form. If you put it also on user which registers to an existing site (like the main site) users will be able to change the setting on creation, something that only the admin should be able to do.

If your form calls wpmu_new_blog() you can set that option on blog creation from the data given in the form.

function wpse_127265_timezone( $blog_id )
{
    switch_to_blog( $blog_id );
    update_option('gmt_offset',$_POST['gmt_offset']);
    restore_current_blog();
}

add_action( 'wpmu_new_blog', 'wpse_127265_timezone' );

If that data is part of the registration form (meaning that the site is created only after the user activated it) then things get a little more complex and you need to store the data at some other place until the activation is done.

  • Thank you for your help Mark. Just wanted to clarify some things after checking out your link. These only displays the set time zone: <?php echo get_option('gmt_offset'); ?> and <?php echo get_option('timezone_string'); ?>. How can you "set" the option 'gmt_offset'? Right now I'm thinking you are you referring to using date_default_timezone_set. An example's given here: wordpress.stackexchange.com/a/8414/26952 Thanks once again. – Denis Lam Dec 28 '13 at 0:06
  • added some more explanation and some code. – Mark Kaplun Dec 28 '13 at 5:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.