Skip to:
Content

BuddyPress.org

Opened 8 years ago

Closed 7 years ago

#7582 closed defect (bug) (no action required)

wp_update_user creates an error

Reported by: iamklaus's profile iamklaus Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Core Keywords: reporter-feedback
Cc:

Description

See my code below. Having buddypress activated, calling the function wp_update_user within the hook "after_setup_theme" throws an error:

[Thu Aug 10 16:31:55.944041 2017] [proxy_fcgi:error] [pid 10778] [client 10.130.37.117:64185] AH01071: Got error 'PHP message: WordPress database error You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'WHERE user_id = 1706 AND blog_id = 1' at line 1 for query SELECT COUNT(id) FROM WHERE user_id = 1706 AND blog_id = 1 made by require('wp-blog-header.php'), require_once('wp-load.php'), require_once('wp-config.php'), require_once('wp-settings.php'), do_action('after_setup_theme'), WP_Hook->do_action, WP_Hook->apply_filters, ad_sso_login, logmeintothesystem, ad_sso_register_user_wrapper, ad_sso_register_user, wp_update_user, wp_insert_user, do_action('profile_update'), WP_Hook->do_action, WP_Hook->apply_filters, bp_blogs_add_user_to_blog, bp_blogs_record_blog, BP_Blogs_Blog->save, BP_Blogs_Blog->exists\nPHP message: WordPress database error You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '( user_id, blog_id ) VALUES ( 1706, 1 )' at line 1 for query INSERT INTO ( user_id, blog_id ) VALUES ( 1706, 1 ) made by require('wp-blog-header.php'), require_once('wp-load.php'), require_once('wp-config.php'), require_once('wp-settings.php'), do_action('after_setup_theme'), WP_Hook->do_action, WP_Hook->apply_filters, ad_sso_login, logmeintothesystem, ad_sso_register_user_wrapper, ad_sso_register_user, wp_update_user, wp_insert_user, do_action('profile_update'), WP_Hook->do_action, WP_Hook->apply_filters, bp_blogs_add_user_to_blog, bp_blogs_record_blog, BP_Blogs_Blog->save\n'
[Thu Aug 10 16:32:03.102375 2017] [proxy_fcgi:error] [pid 10804] [client 10.70.36.82:57000] AH01071: Got error 'PHP message: WordPress database error You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'WHERE user_id = 385 AND blog_id = 1' at line 1 for query SELECT COUNT(id) FROM WHERE user_id = 385 AND blog_id = 1 made by require('wp-blog-header.php'), require_once('wp-load.php'), require_once('wp-config.php'), require_once('wp-settings.php'), do_action('after_setup_theme'), WP_Hook->do_action, WP_Hook->apply_filters, ad_sso_login, logmeintothesystem, ad_sso_register_user_wrapper, ad_sso_register_user, wp_update_user, wp_insert_user, do_action('profile_update'), WP_Hook->do_action, WP_Hook->apply_filters, bp_blogs_add_user_to_blog, bp_blogs_record_blog, BP_Blogs_Blog->save, BP_Blogs_Blog->exists\nPHP message: WordPress database error You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '( user_id, blog_id ) VALUES ( 385, 1 )' at line 1 for query INSERT INTO ( user_id, blog_id ) VALUES ( 385, 1 ) made by require('wp-blog-header.php'), require_once('wp-load.php'), require_once('wp-config.php'), require_once('wp-settings.php'), do_action('after_setup_theme'), WP_Hook->do_action, WP_Hook->apply_filters, ad_sso_login, logmeintothesystem, ad_sso_register_user_wrapper, ad_sso_register_user, wp_update_user, wp_insert_user, do_action('profile_update'), WP_Hook->do_action, WP_Hook->apply_filters, bp_blogs_add_user_to_blog, bp_blogs_record_blog, BP_Blogs_Blog->save\n'

The sql functions being executed by this functions are missing the database table name.
Here is the code I am using inside the functions.php from my plugin:

<?php
<?php
add_action('after_setup_theme', 'ad_sso_login');
function ad_sso_login () {

    $user_id = 6;
    $website = 'http://wordpress.org';

    $user_id = wp_update_user( array( 'ID' => $user_id, 'user_url' => $website ) );

    if ( is_wp_error( $user_id ) ) {
        echo "There was an error, probably that user doesn't exist.";
    } else {
        echo "Success!";
    }
}

Change History (4)

#1 @r-a-y
8 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

Your ad_sso_login() runs very early.

Why do you need to run your function on 'after_setup_theme'? All you are doing is updating the URL for a particular user. You should run your function later on 'wp_loaded' or later when you know that all of WordPress, the current theme and all plugins are loaded.

Closing as invalid.

#2 @iamklaus
8 years ago

  • Resolution invalid deleted
  • Status changed from closed to reopened

The function above is just a showcase for describing the problem. In my real application I do a automatic login (wp_login()) and update some user information which I gather from the Active Directoy.

Therefore my Apache uses mod_kerberos to the the clients credentials ( it's a intranet application) and does an automatic login.

Is there a way to fix this?

#3 @r-a-y
8 years ago

  • Keywords reporter-feedback added

When are you running your auto-login hook? Or what hook are you running your code at? That's important and is most likely causing your problem.

#4 @DJPaul
7 years ago

  • Resolution set to invalid
  • Status changed from reopened to closed
Note: See TracTickets for help on using tickets.