admin管理员组

文章数量:1122846

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?

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?

Share Improve this question edited Dec 26, 2013 at 15:18 Denis Lam asked Dec 21, 2013 at 12:55 Denis LamDenis Lam 711 silver badge6 bronze badges 8
  • 1 the answer is yes. – Mark Kaplun Commented Dec 21, 2013 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 Commented Dec 22, 2013 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 Commented Dec 22, 2013 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 Commented Dec 23, 2013 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 Commented Dec 24, 2013 at 4:55
 |  Show 3 more comments

1 Answer 1

Reset to default 1

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.

本文标签: multisitePossible to set new user39s site time zone at user creation using Gravity Forms