Site icon Hip-Hop Website Design and Development

update_option shouldn’t be working!

I’m writing a plugin and I would like to make use of the update_option perform to replace an array I’ve saved as an possibility in WP. For the admin panel I used the settings API however for this portion I would like to make use of the update_option straight.

I’ve simplified my code so all it’s presently doing is studying within the possibility, including a component to the returned array, and updating the choice with the modified array. However once I learn the choice again in it does no comprise the brand new factor.

Do I’ve to do one thing to tell the settings API that I might be utilizing this new factor (that I do not wish to be seen within the admin panel)? Have I missed one thing else?

I have no idea the place to troubleshoot past this level. The update_option perform doesn’t look like working and I don’t know why! Any options/pointers/troubleshooting concepts you may cross my approach might be drastically appreciated!

Beneath is code from my plugin:

$coupon_grab_options = get_option( 'coupon_grab_option' );

error_log( "Dump of coupon_grab_options earlier than replace", 0 );
error_log( print_r( $coupon_grab_options, true ), 0 );
error_log( "_______________________________", 0 );

$coupon_grab_options['testing'] = "Testing1234";

error_log( "Dump of array coupon_grab_options earlier than passing it as an argument to update_option");
error_log( print_r( $coupon_grab_options, true ), 0 );
error_log( "_______________________________", 0 );

wp_cache_delete ( 'alloptions', 'choices' );
$check = update_option( 'coupon_grab_option', $coupon_grab_options );

$booltest = ($check) ? 'true' : 'false';
error_log( "update_option returned a $booltest worth", 0 );

wp_cache_delete ( 'alloptions', 'choices' );
$coupon_grab_options = get_option( 'coupon_grab_option' );

error_log( "Dump of coupon_grab_options after replace", 0 );
error_log( print_r( $coupon_grab_options, true ), 0 );

Beneath is the output from my error logs from this code:

[Sat Jan 14 18:58:47.213079 2017] [:error] [pid 9414] [client 67.205.159.176:33378] Dump of coupon_grab_options earlier than replace
[Sat Jan 14 18:58:47.215500 2017] [:error] [pid 9414] [client 67.205.159.176:33378] Arrayn(n    [brandcaster_id] => 12222222222222n    [maxpost] => n    [status] => 1n    
		
=> 2n [parent_category] => 5n [tags] => BETTER WORK3, %majcat%, %mincat%, %brandpercentn [enable_featured] => enable_featuredn [html] => HTML goes heren [style] => n)n [Sat Jan 14 18:58:47.215675 2017] [:error] [pid 9414] [client 67.205.159.176:33378] _______________________________ [Sat Jan 14 18:58:47.215952 2017] [:error] [pid 9414] [client 67.205.159.176:33378] Dump of array coupon_grab_options earlier than passing it as an argument to update_option [Sat Jan 14 18:58:47.216101 2017] [:error] [pid 9414] [client 67.205.159.176:33378] Arrayn(n [brandcaster_id] => 12222222222222n [maxpost] => n [status] => 1n
=> 2n [parent_category] => 5n [tags] => BETTER WORK3, %majcat%, %mincat%, %brandpercentn [enable_featured] => enable_featuredn [html] => HTML goes heren [style] => n [testing] => Testing1234n)n [Sat Jan 14 18:58:47.216256 2017] [:error] [pid 9414] [client 67.205.159.176:33378] _______________________________ [Sat Jan 14 18:58:47.221790 2017] [:error] [pid 9414] [client 67.205.159.176:33378] Dump of coupon_grab_options after replace [Sat Jan 14 18:58:47.221961 2017] [:error] [pid 9414] [client 67.205.159.176:33378] Arrayn(n [brandcaster_id] => 12222222222222n [maxpost] => n [status] => 1n
=> 2n [parent_category] => 5n [tags] => BETTER WORK3, %majcat%, %mincat%, %brandpercentn [enable_featured] => enable_featuredn [html] => HTML goes heren [style] => n)n

You possibly can see from the error_log that the $coupon_grab_options array does have the factor testing current earlier than I cross it to update_option but when I learn within the possibility after the replace it isn’t current.