phpwordpresswordpress-theming

What is the difference between get_option and get_user_option in WordPress plugin?


Looking for the differences between using get_option/update_option versus get_user_option/update_user_option

I am creating a new plugin for Wordpress and am not sure if I should be using the user_option or just plain option for the settings page.

What scenarios should I use one, versus the other.

Thanks


Solution

  • As I read thru the descriptions of each of these, this is my take on it:

    https://codex.wordpress.org/Function_Reference/get_option

    https://codex.wordpress.org/Function_Reference/get_user_option

    get_option seems to be a global option that is set once, and all users would always get the same value back for it. It would probably be set by an admin and users would not ability to change the setting themselves.

    get_user_option is a user specific value, so if one user sets it, it will not be set for another user. Each user will set their own unique value for it.

    So most likely you want to use get_option and update_option for a general setting that affects all users the same, and that each user can NOT set for themselves personally.