MyBB Community Forums

Full Version: Fill empty user language with bblanguage
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Task definition:
For a plugin project according to DSGVO only the "empty" user language ($mybb->users['language'] must be filled with the bblanguage ($mybb->settings['bblanguage'] in the database.

With:
PHP-Code:
$query_bblanguage = $db->simple_select("settings", "value", "name='bblanguage'");
$bblanguage = $db->fetch_field($query_bblanguage, "value");
if(empty($mybb->users['language'])) {
   $db->update_query("users", array("language" => ($bblanguage)));
} 
the column "langauge" is filled with "bblanguage" for all users, no matter if something else is already contained in the column or not.

But the column "langauge" should only be filled with "bblanguage" if the column "langauge" is empty

If i use:
PHP-Code:
if(!empty($mybb->users['language'])) { 
the empty columns are not filled! The columns which already contain something remain untouched.

What is wrong with the "IF definition"? Could someone tell me the correct code to reach my goal?

Unfortunately, I am not a programming professional and therefore I would like to thank you in advance for any assistance.
Hi. Try to change the condition:
if(empty($mybb->users['language'])) {
    $db->update_query("users", array("language" => ($bblanguage)));
} 

To this:
$language = $mybb->users['language'] ?? '';

if ($language === '') {
    $db->update_query('users', ['language' => $bblanguage]);
}