Allow some multisite illegal username characters and error get_results() on string

Post a reply


This question is a means of preventing automated form submissions by spambots.
Smilies
:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :arrow: :| :mrgreen: :geek: :ugeek:

BBCode is ON
[img] is ON
[url] is ON
Smilies are ON

Topic review
   

If you wish to attach one or more files enter the details below.

Maximum filesize per attachment: 1 MiB.

Expand view Topic review: Allow some multisite illegal username characters and error get_results() on string

Re: Allow some multisite illegal username characters and error get_results() on string

by axew3 » Fri May 10, 2024 6:42 am

Hi! :D wow... OK! Let explain (but you already know the reason why it happen).
I will go deep on explain btw, and 2.8.5 will be released this night if possible, so to fix this, and two more secondary issues (one is about login on frontend pages, when with some plugin, the user seem to be logged out because the presented page is the login page after the login redirect, but in true the user is logged in (would be necessary to click into any link to see that it is in these cases).

About this error when on wp multisite and deleting an user (maybe it happen into more situations and it require to be definitively fixed):
Fatal error: Uncaught Error: Call to a member function get_results() on string
I assumed it was resolved, because the reason of this error, come out due to the (it is assumed) reset of all vars that are initialized when the plugin is parsed: on wp_w3all.php file, between all others, it is initialized the global var $w3all_phpbb_connection that contain as array the connection values for the phpBB db.
What it happen when we get
Fatal error: Uncaught Error: Call to a member function get_results() on string
??
the global var $w3all_phpbb_connection is somewhere overwritten and reset to be empty.
When the wp_w3all_get_phpbb_user_info_by_email($email) function is called it so return the error, because

Code: Select all

private static function w3all_db_connect(){
 global $w3all_phpbb_connection,$w3all_config_db,$w3all_config;
get an empty $w3all_phpbb_connection.

Solutions:

include a phpBB config file as it was on first plugin versions, right on the connection function, i applied it last time but after switched to the solution that get values from the db when the $w3all_phpbb_connection result to be empty:
So, into actual 2.8.4 file /class.wp.w3all-phpbb.php there this code added

Code: Select all

# get the phpBB connections values using a direct wpdb call
private static function get_w3all_config_db_if_empty(){
   global $wpdb;
   $wpdb_opt = (is_multisite()) ? WPW3ALL_MAIN_DBPREFIX . 'options' : $wpdb->prefix . 'options';
   $w3all_config_db = $wpdb->get_row("SELECT * FROM $wpdb_opt WHERE option_name = 'w3all_phpbb_dbconn'",ARRAY_A);
  if(!empty($w3all_config_db['option_value'])){
     $r = unserialize($w3all_config_db['option_value']);
   return $r;
  }
  return false;
}
and really should be not possible reason that the connection values are lost along the way. The unique reason of this, could be that not only the $w3all_phpbb_connection result to be empty at the time it is invoked, but also the $wpdb, that's very strange.
As seen by me last time into a wpms, it was empty because get_option was returning an empty value, the reason of this, into this specific configuration is still obscure to me and since it was an hard customized WP i not followed looking it.

I will test it again, and at the end a phpBB config file option can be provided.

In fact to test that it is the problem, if you change this part into actual code, on file /class.wp.w3all-phpbb.php

Code: Select all

   $w3all_config_db["dbhost"] = $dbc["w3all_phpbb_dbhost"];
   $w3all_config_db["dbport"] = $dbc["w3all_phpbb_dbport"];
   $w3all_config_db["dbname"] = $dbc["w3all_phpbb_dbname"];
   $w3all_config_db["dbuser"] = $dbc["w3all_phpbb_dbuser"];
   $w3all_config_db["dbpasswd"] = $dbc["w3all_phpbb_dbpasswd"];
   $w3all_config_db["table_prefix"] = $dbc["w3all_phpbb_dbtableprefix"];
assigning connection values manually, like so $w3all_config_db["dbname"] = 'my_db_name';
you'll see that the problem on deleting users on scenarios like your where i know the same happen (i've see the same into another mums) should result to be fixed.
See you later

Re: Allow some multisite illegal username characters

by pennymachines » Thu May 09, 2024 9:20 pm

I return... :)
but sorry to report, now running 2.8.4 but still getting the error when I delete users:

Fatal error: Uncaught Error: Call to a member function get_results() on string in /home/www/mysite.com/wordpress/wp-content/plugins/wp-w3all-phpbb-integration/class.wp.w3all-phpbb.php:2067 Stack trace: #0 /home/www/mysite.com/wordpress/wp-content/plugins/wp-w3all-phpbb-integration/class.wp.w3all-phpbb.php(2114): WP_w3all_phpbb::wp_w3all_get_phpbb_user_info_by_email() #1 /home/www/mysite.com/wordpress/wp-content/plugins/wp-w3all-phpbb-integration/wp_w3all.php(1536): WP_w3all_phpbb::wp_w3all_phpbb_delete_user_signup() #2 /home/www/mysite.com/wordpress/wp-includes/class-wp-hook.php(326): w3all_remove_user_from_blog() #3 /home/www/mysite.com/wordpress/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters() #4 /home/www/mysite.com/wordpress/wp-includes/plugin.php(517): WP_Hook->do_action() #5 /home/www/mysite.com/wordpress/wp-includes/ms-functions.php(246): do_action() #6 /home/www/mysite.com/wordpress/wp-admin/network/users.php(173): remove_user_from_blog() #7 {main} thrown in /home/www/mysite.com/wordpress/wp-content/plugins/wp-w3all-phpbb-integration/class.wp.w3all-phpbb.php on line 2067

Re: Allow some multisite illegal username characters

by axew3 » Tue Apr 02, 2024 9:27 pm

Ah wow... just realized that instead to include an external config file, would be sufficient to get the connection values stored as WP option, using $wpdb default/direct wp query call and NOT using the wp get_option function (that return an empty string).
So in case that the global var $w3all_config_db will result to be empty, required db connection values will be retrieved by the query.
Will be fixed on 2.8.3

Re: Allow some multisite illegal username characters

by axew3 » Tue Apr 02, 2024 9:00 pm

Finally have come out again ... ok

So, just tested, and i cannot reproduce into my mums localhost, but yes into a site i follow, so the query that fail based into your report is this:

Code: Select all

    $phpbb_user_data = $w3all_phpbb_connection->get_results("SELECT *
    FROM ". $w3all_config["table_prefix"] ."groups
    JOIN ". $w3all_config["table_prefix"] ."users ON LOWER(". $w3all_config["table_prefix"] ."users.user_email) = '".$email."'
    AND ". $w3all_config["table_prefix"] ."users.group_id = ". $w3all_config["table_prefix"] ."groups.group_id");
the problem is that you could check and change the query to be this instead:

Code: Select all

    $phpbb_user_data = $w3all_phpbb_connection->get_results("SELECT *
    FROM ". $w3all_config["table_prefix"] ."groups
    JOIN ". $w3all_config["table_prefix"] ."users ON LOWER(". $w3all_config["table_prefix"] ."users.user_email) = '$email'
    AND ". $w3all_config["table_prefix"] ."users.group_id = ". $w3all_config["table_prefix"] ."groups.group_id");
but the result will not change, you'll get anyway
Fatal error: Uncaught Error: Call to a member function get_results() on string
the reason of this, i discovered into another mums installation, is that at some point, and for different functions, the value of the var $w3all_config_db become empty, so the

Code: Select all

private static function w3all_db_connect(){
on file
class.wp.w3all-phpbb.php lead to the subsequent
Error: Call to a member function get_results() on string

To fix the issue, into a site i follow, i had to do this:
on file
class.wp.w3all-phpbb.php
into function

Code: Select all

private static function w3all_db_connect(){

Code: Select all

else
     {
       $w3all_config_db["dbhost"] = empty($w3all_config_db["dbport"]) ? $w3all_config_db["dbhost"] : $w3all_config_db["dbhost"] . ':' . $w3all_config_db["dbport"];
       $w3all_phpbb_connection = new wpdb($w3all_config_db["dbuser"], $w3all_config_db["dbpasswd"], $w3all_config_db["dbname"], $w3all_config_db["dbhost"]);
      }
change into:

Code: Select all

else
     {
       $w3all_config_db["dbhost"] = empty($w3all_config_db["dbport"]) ? $w3all_config_db["dbhost"] : $w3all_config_db["dbhost"] . ':' . $w3all_config_db["dbport"];
       $w3all_phpbb_connection = new wpdb('yourUserName', 'yourdbpasswd', 'yourdbname', 'yourHost');
       // yourHost could be yourHost:3306 if port required
      }
The use of a CONSTANT in place of the global var $w3all_config_db should not fix the issue.
As you can see on the same function, the code on it already provide the switch to include a custom config.php, which was the way i solved the issue last time (same result of the above suggested, but in that case vars are coming so from an included custom phpBB config.php).
Think that the CONSTANT array will not fix because if not wrong, the call to get_option that should contain db connection values, return an empty val!
[EDITED]

Re: Allow some multisite illegal username characters

by pennymachines » Tue Apr 02, 2024 3:51 pm

Many thanks - working great now. Sorry about my late response!

On the subject of php warnings, there's still one small issue which I flagged before.

If I try to delete a user through network admin I get an error and delete fails. I have to deactivate your plugin to delete users.
I just noticed this also applies to deleting subsites.

Here's the error I got:

Code: Select all

Fatal error: Uncaught Error: Call to a member function get_results() on string in /home/www/mysite.com/wordpress/wp-content/plugins/wp-w3all-phpbb-integration/class.wp.w3all-phpbb.php:1992 Stack trace: #0 /home/www/mysite.com/wordpress/wp-content/plugins/wp-w3all-phpbb-integration/class.wp.w3all-phpbb.php(2039): WP_w3all_phpbb::wp_w3all_get_phpbb_user_info_by_email() #1 /home/www/mysite.com/wordpress/wp-content/plugins/wp-w3all-phpbb-integration/wp_w3all.php(1529): WP_w3all_phpbb::wp_w3all_phpbb_delete_user_signup() #2 /home/www/mysite.com/wordpress/wp-includes/class-wp-hook.php(326): w3all_remove_user_from_blog() #3 /home/www/mysite.com/wordpress/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters() #4 /home/www/mysite.com/wordpress/wp-includes/plugin.php(517): WP_Hook->do_action() #5 /home/www/mysite.com/wordpress/wp-includes/ms-functions.php(246): do_action() #6 /home/www/mysite.com/wordpress/wp-includes/ms-site.php(814): remove_user_from_blog() #7 /home/www/mysite.com/wordpress/wp-includes/class-wp-hook.php(324): wp_uninitialize_site() #8 /home/www/mysite.com/wordpress/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters() #9 /home/www/mysite.com/wordpress/wp-includes/plugin.php(517): WP_Hook->do_action() #10 /home/www/mysite.com/wordpress/wp-includes/ms-site.php(261): do_action() #11 /home/www/mysite.com/wordpress/wp-admin/includes/ms.php(98): wp_delete_site() #12 /home/www/mysite.com/wordpress/wp-admin/network/sites.php(146): wpmu_delete_blog() #13 {main} thrown in /home/www/mysite.com/wordpress/wp-content/plugins/wp-w3all-phpbb-integration/class.wp.w3all-phpbb.php on line 1992
Again, by deactivating wp.w3all, I was able to delete the subsite.

Re: Allow some multisite illegal username characters

by axew3 » Thu Mar 14, 2024 6:53 pm

Ok resolved, you was right! it was a problem on db vars when not still set, so throwing Php warnings, until the connection values where not set.
It has been now resolved, download 2.8.1 please!
As ever, thank you for the report David

ps old versions are here but i do not advice to use, just update to 2.8.1 instead to fix your reported issue
https://wordpress.org/plugins/wp-w3all- ... /advanced/

Top