Fill empty user language with bblanguage
#1
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.
Reply
#2
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]);
}
Best regards, Peter.
PHP Developer.


#gitlab #myplugins
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)