Make WordPress Core

Opened 10 years ago

Closed 9 months ago

#29505 closed defect (bug) (invalid)

Both update_user_option and update_user_meta returning false

Reported by: miqdadk's profile miqdadk Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.0
Component: Users Keywords: close
Focuses: Cc:

Description

if(update_user_meta( $user->ID, 'wp-lock-bg', serialize($bgs))){
    echo "true";
}
else{
    echo "False";
}
if(update_user_option( $user->ID, 'wp-lock-bg', serialize($bgs))){
    echo "true";
}
else{
    echo "False";
}

Both code snippet returning false. I am getting correct user id, and option value. I have tested wp4.0 rc1 . Tested and working fine with 3.9.2

Change History (10)

#1 @miqdadk
10 years ago

Detail explanation

register_activation_hook( __FILE__, 'plugin_activated');
function plugin_activated(){

   if(update_user_meta( $user->ID, 'wp-lock-bg', serialize($bgs))){
       echo "true";
   }
   else{
       echo "False";
   }
}

always returning false. Tried with update_user_option too. same

Version 0, edited 10 years ago by miqdadk (next)

#2 @SergeyBiryukov
10 years ago

What are $user->ID and $bgs values in plugin_activated()? Are they defined?

#3 @miqdadk
10 years ago

Yes, and code is working perfect with 3.9.2

$bgs = 'a:1:{i:0;s:93:"http://192.168.1.175/delta/wp4.0rc/wp-content/plugins/lock-it-up/templates/img/bg/default.jpg";}';

$user->ID = 1;

#4 @shooper
10 years ago

I just tried this on the trunk (post 4.0 release), and it worked OK in the init action. Will try and duplicate it on the plugin activation action next.

add_action('init', 'test_29505');
function test_29505() {
	global $current_user;
	if (is_user_logged_in()) {
		var_dump(update_user_option($current_user->ID, 'test', 1)); // returned int
		var_dump(update_user_meta($current_user->ID, 'test', 1)); // returned int 
	}
	die();
}

#5 @shooper
10 years ago

Getting same behaviour as OP, but also getting same behaviour in 3.9.2.
(Slightly modified code, my 3.9.2 test site doesn't have a user ID # 1)

/*
Plugin Name: Test Trac Bug # 29505
Plugin URI: https://core.trac.wordpress.org/ticket/29505
*/

function plugin_activated(){
	$bgs = 'a:1:{i:0;s:93:"http://192.168.1.175/delta/wp4.0rc/wp-content/plugins/lock-it-up/templates/img/bg/default.jpg";}';
	global $current_user;
	delete_user_option( $current_user->ID, 'wp-lock-bg-solid');  //deleting one user option
	var_dump(update_user_meta( $current_user->ID, 'wp-lock-bg-solid', 'test'));
	die();
}
register_activation_hook( __FILE__, 'plugin_activated');

#6 @miqdadk
10 years ago

Its working fine in 3.9.2. Here is actual code

class test_plugin{
    function __construct(){
        register_activation_hook( __FILE__, array( $this, 'plugin_activated'));
    }
    
    function plugin_activated(){
        $bgs = 'a:1:{i:0;s:93:"http://192.168.1.175/delta/wp4.0rc/wp-content/plugins/lock-it- up/templates/img/bg/default.jpg";}';
        $users = get_users( array( 'fields' => array( 'ID' ) ) );
        foreach($users as $user){
            delete_user_option($user->ID, 'wp-lock-bg-solid');
            update_user_option( $user->ID, 'wp-lock-bg', $bgs);
        }
    }
}

new test_plugin;
Last edited 10 years ago by miqdadk (previous) (diff)

#7 @miqdadk
10 years ago

Still no update :(

#8 @chriscct7
9 years ago

  • Keywords needs-patch added

#9 @donmhico
5 years ago

  • Keywords close added; needs-patch removed

Hello @miqdadk,

Sorry if this ticket wasn't able to get much attention. I no longer able to reproduce the error in the latest trunk 5.3-alpha-45282-src.

This is the code i'm using.

<?php
/**
 * Plugin Name: Test Trac Bug # 29505
 * Plugin URI: https://core.trac.wordpress.org/ticket/29505
 */
class test_plugin {
    function __construct(){
        register_activation_hook( __FILE__, array( $this, 'plugin_activated'));
    }
    
    function plugin_activated(){
        $bgs = 'a:1:{i:0;s:93:"http://192.168.1.175/delta/wp4.0rc/wp-content/plugins/lock-it- up/templates/img/bg/default.jpg";}';
        $users = get_users( array( 'fields' => array( 'ID' ) ) );
        foreach( $users as $user ){
            $a = delete_user_meta( $user->ID, 'wp-lock-bg');
            $b = update_user_meta( $user->ID, 'wp-lock-bg', $bgs);

            if ( $a ) {
                error_log( 'a TRUE' );
            }
            else {
                error_log( 'a FALSE' );
            }

            if ( $b ) {
                error_log( 'b TRUE' );
            }
            else {
                error_log( 'b FALSE' );
            }
        }
    }
}

new test_plugin;

I used both delete_user_option and delete_user_meta, as well as update_user_meta and update_user_option. The functions are behaving as intended.

Unfortunately, I can't find the ChangeSet that might have resolved this issue. Seeing that this ticket didn't have any interaction for the past 5 years, I'll be marking this as close.

Feel free to reopen if the issue still persist in your side.

#10 @hellofromTonya
9 months ago

  • Resolution set to invalid
  • Status changed from new to closed

Following up on older close candidate tickets.

I too was unable to reproduce the issue with 6.4.2. With 2 reports of it working, I'll close this ticket.

However, if the problem still persists today, @miqdadk please reopen this ticket and share updated information for how contributors can reproduce the issue.

I'll mark the resolution as invalid, not because the problem wasn't valid when reported, but rather to indicate it's no longer valid today.

Note: See TracTickets for help on using tickets.