This section contains detailed articles elaborating on some of the common issues phpBB users encounter while using the product. Articles submitted by members of the community are checked for accuracy by the relevant phpBB Team. If you do not find the answer to your question here, we recommend looking through the Support Section as well as using the Site Wide Search.

Changing user options defaults and values

Description: This article tells you how to change the default for various user options for new users, and how to change the existing options for existing users.

In Categories:

Link to this article: Select All
[url=https://www.phpbb.com/support/docs/en/3.0/kb/article/changing-user-options-defaults-and-values/]Knowledge Base - Changing user options defaults and values[/url]

Introduction

Users can set various options in their User Control Panels. Each of these options has a default value for new users, and each has a chosen value for existing users, which may or may not be the default value. This article tells you how to change the default options for new users and how to change the chosen value for existing users. Note that users are still free to change the default values or to change their chosen values back to whatever they choose. This article does NOT cover how to force an option change on a user permanently.

User options that users can set in the User Control Panel (assuming permission to do so) are controlled in one of two ways in phpBB.

Some options have their own dedicated field in the users table. Other options are the result of a total of bitsums in the user_options field of the users table.

The method used to change each type is different, as explained below.

What you need to know to get started

1. Whenever you run a database query, first make a backup of the affected tables. In this article, all the queries are run on the users table, so that is the one to back up.

2. When editing phpBB files, always use a "good" text editor that can save files as utf8 w/o BOM. A list of "good" editors is HERE

3. The queries below assume your table prefix is phpbb_. If it is not, you must change the phpbb_ in the example queries to whatever your table prefix is. The table prefix can be seen in phpMyAdmin, or by looking at the value of $table_prefix in your config.php file.

4. If you do not know how to run database queries, see Executing SQL Queries in phpMyAdmin KB

5. The condition WHERE user_type <> 2 in the sample queries excludes Bots and the Anonymous user from the operation of the query.

Changing options that have their own field

Certain user options that users can set (those defined in includes/functions_user.php) have their own fields in the users table in the database, and are set by those values. These are:

Code: Select all

   
      'user_notify'        => 0,
      'user_notify_pm'     => 1,
      'user_notify_type'      => NOTIFY_EMAIL,
      'user_allow_pm'         => 1,
      'user_allow_viewonline' => 1,
      'user_allow_viewemail'  => 1,
      'user_allow_massemail'  => 1,


"0" means that the option is OFF and "1" means that the option is ON, by default. To change the default for new users, you would edit the includes/functions_user.php file to change the 0(s) to 1(s) or vice-versa. To change these options for existing users you would run a query like this:

Code: Select all

UPDATE phpbb_users SET user_notify = 1 WHERE user_type <> 2;


However, the user_notify_type option is different from the other options, in that it has three possible values in that file, and one of three possible corresponding numeric values in the database field. If you wanted to change the user_notify_type option for new users, you would edit that file to change NOTIFY_EMAIL (value 0) to either NOTIFY_IM (value 1) or NOTIFY_BOTH (value 2) as desired.

To change the user_notify_type option for existing users from NOTIFY _EMAIL to NOTIFY_IM, you would run a query like this:

Code: Select all

UPDATE phpbb_users SET user_notify_type = 1 WHERE user_type <> 2;


That last query would change the default NOTIFY_EMAIL whose value is 0, to NOTIFY_IM whose value is 1.

Note that that query changes ALL users to NOTFY_IM, even those who have chosen NOTIFY_BOTH (value 2). If you wanted to exclude the users who have chosen NOTIFY_BOTH and only affect the users who have the default NOTIFY_EMAIL, then the query would be like this:

Code: Select all

UPDATE phpbb_users SET user_notify_type = 1 WHERE user_type <> 2 AND user_notify_type != 2;


Changing options that are stored in the value of the user_options field

Certain user options that users can set are the result of a sum of the values of powers of two, and are stored as a single integer in the user_options field of the users table. These are:

Code: Select all

      'viewimg'      => array('bit' => 0, 'default' => 1),
      'viewflash'    => array('bit' => 1, 'default' => 1),
      'viewsmilies'  => array('bit' => 2, 'default' => 1),
      'viewsigs'     => array('bit' => 3, 'default' => 1),
      'viewavatars'  => array('bit' => 4, 'default' => 1),
      'viewcensors'  => array('bit' => 5, 'default' => 1),
      'attachsig'    => array('bit' => 6, 'default' => 1),
      'bbcode'    => array('bit' => 8, 'default' => 1),
      'smilies'      => array('bit' => 9, 'default' => 1),
      'popuppm'      => array('bit' => 10, 'default' => 0),
      'sig_bbcode'   => array('bit' => 15, 'default' => 1),
      'sig_smilies'  => array('bit' => 16, 'default' => 1),
      'sig_links'    => array('bit' => 17, 'default' => 1),


These defaults produce a total value of the various powers of 2 of 230271, which is contained in includes/functions_user.php, here:

Code: Select all

'user_options'    => 230271,


To change the default for new users, you would modify the value of 230271 in includes/functions_user.php as appropriate.

For example, if you wanted the default for viewsigs to be Off (0) and that for viewimg to be On (1), you would SUBTRACT 8 (2^3), because the bit value (power of 2) for viewsigs is 3, and you would ADD 1 (2^0) because the bit value for viewimg is 0.

Therefore, you would edit includes/functions_user.php so 230271 would become 230264 (230271 -8 +1).

For your convenience, a table of the powers of two for the bit values for the various user options is included at the end of this article.

To change an option's value from 0 to 1 for existing users, you would use a query using the bitwise OR operator (|) produced by the bit or bits to the user_options field in the database. In other words, calculate the value of 2 raised to the power of the bit assigned to each option. That value for viewimg would be 1, because its bit is 0 and 2^0 is 1.

For example, this would change viewimg from Off to On by adding the appropriate value if it is NOT already included in the total value of user_options for each user:

Code: Select all

UPDATE phpbb_users set user_options = user_options | 1 WHERE user_type <> 2;


To change the option's value from 1 to 0 for existing users, you would use a query using the bitwise XOR operator (^) and the bitwise AND operator (&) produced by the bit or bits to the user_options field in the database. This will subtract the appropriate value, if it IS already included in the total value of user_options for each user.

For example, this would change viewsigs from On to Off. It uses the value 8 because the bit for viewsigs is 3 and 2^3 = 8.

Code: Select all

UPDATE phpbb_users set user_options = (user_options & 8) ^ user_options WHERE user_type <> 2;


Changing options for particular groups or users

Note that you can also change the options for particular users or users in particular groups. However, you can only do that for existing members, not for future members (without some sort of MOD).

For example, this query would change user_allow_pm from On to Off for people currently in the Newly Registered Users group. This assumes the group_id of the Newly Registered Users group is 7 (the default) and will work whether the Newly Registered Users group is the member's default group, or not:

Code: Select all

UPDATE phpbb_users SET user_allow_pm = 0 WHERE user_id IN(SELECT user_id FROM phpbb_user_group WHERE group_id = 7);


This query would change the viewflash option from On to Off for existing members who have no signature:

Code: Select all

UPDATE phpbb_users set user_options = (user_options & 2) ^ user_options WHERE user_sig = '';


Powers of 2

2^0 = 1
2^1 = 2
2^2 = 4
2^3 = 8
2^4 = 16
2^5 = 32
2^6 = 64
2^7 = 128
2^8 = 256
2^9 = 512
2^10 = 1024
2^15 = 32768
2^16 = 65536
2^17 = 131072


Credit to HGN for correcting some of the queries