1

I have a code to link our students users with the wp-user. It was working without problems, and creating wp users without problems, but between July 29th and June 2nd, I think some plugin have been updated and now I can't edit passwords or create useres from my php code. It looks like Wordpress is working fine but my code not.

require_once $_SERVER["DOCUMENT_ROOT"] . '/wp-load.php';
require_once $_SERVER["DOCUMENT_ROOT"] . '/wp-config.php';
require_once $_SERVER['DOCUMENT_ROOT'] . "/wp-includes/formatting.php";
require_once $_SERVER['DOCUMENT_ROOT'] . "/wp-includes/user.php";
wp_set_password($password, $id);

this code returns an error.

Fatal error: Uncaught Error: Call to a member function add_query_var() on string in /var/app/current/wordpress-beanstalk/wp-includes/class-wp-taxonomy.php:460

Stack trace:
#0 /var/.../wp-includes/taxonomy.php(441): WP_Taxonomy->add_rewrite_rules()
#1 /var/.../wp-includes/taxonomy.php(79): register_taxonomy('category', 'post', Array)
#2 /var/.../wp-settings.php(375): create_initial_taxonomies()
#3 /var/.../wp-config.php(36): require_once('/var/app/curren...')
#4 /var/.../api/wp.php(6): require_once('/var/app/curren...')
#5 /var/.../api/customers/changepassword.php(22): updateWpPassword('********', '3')
#6 {main} thrown in /var/app/current/wordpress-beanstalk/wp-includes/class-wp-taxonomy.php on line 460

Notice: is_embed was called incorrectly. Conditional query tags do not work before the query is run. Before then, they always return false. Please see Debugging in WordPress for more information. (This message was added in version 3.1.0.) in /var/app/current/wordpress-beanstalk/wp-includes/functions.php on line 5313

Notice: is_search was called incorrectly. Conditional query tags do not work before the query is run. Before then, they always return false. Please see Debugging in WordPress for more information. (This message was added in version 3.1.0.) in /var/app/current/wordpress-beanstalk/wp-includes/functions.php on line 5313

I don't know what is happening, I have updated the plugins and the problem is there. I can't understand how Wordpress keep working but the code I have created calling to the wp function's is not.

hakre
  • 193,403
  • 52
  • 435
  • 836
  • Please study the error message(s) and follow the references given therein on how to debug Wordpress. – hakre Jul 14 '21 at 17:21
  • Also the PHP debugging reference about error message we have on site might help you to gain more understanding: https://stackoverflow.com/q/12769982/367456 – hakre Jul 14 '21 at 17:22
  • I have followed the files tree and I don't have the minimum idea about the problem, it is not in my code, is in wordpress code and I can't find the problem – Adrián Pastoriza Jul 14 '21 at 17:25
  • 1
    Looks like someone might be stomping the `$wp` global variable. You will need to edit the core file `wp-includes/class-wp-taxonomy.php` and put some debugging right before [line 460](https://github.com/WordPress/WordPress/blob/88309aa27e8eeb89a06142f8986a0ef7360bad2e/wp-includes/class-wp-taxonomy.php#L460). – Chris Haas Jul 14 '21 at 17:29
  • first of all the wordpress code is yours, too, it's free software. but more importantly, reading the code where the error happens can help to better understand the problem - regardless who owns that code, it can be a side-effect for example that only manifests as an error there. at the end of the day you want it to work, so it's your problem anyway, therefore, make it your code and own it. – hakre Jul 14 '21 at 17:34
  • @ChrisHaas you were right. I have solved the problem, the problem between 29th and 2nd was a coincidence, and I didn't focus in my code, the problem was that $wp, I was overwriting that variable. I don't know what happened that day with that student and that wp user id, was a coincidence and that made me focus in the wrong part of the code. – Adrián Pastoriza Jul 14 '21 at 18:06

1 Answers1

1

The problem was related to $wp. I was overwriting that variable in mi code. The previous problem those days was a coincidence, something different and I was focusing in the wrong part of my code. Until I read the Chris Haas comentary I didn't realized that.