Unyson icon indicating copy to clipboard operation
Unyson copied to clipboard

Bunch of undefined indexes after update to 2.6.9 stable

Open danyj opened this issue 10 years ago • 25 comments

again db model is changing bunch of notices for Undefined index: from

https://github.com/ThemeFuse/Unyson/blob/master/framework/helpers/class-fw-db-options-model.php#L199

and

https://github.com/ThemeFuse/Unyson/blob/master/framework/helpers/class-fw-db-options-model.php#L147

what is changed this time?

default vale are set , what now?

danyj avatar Nov 28 '16 20:11 danyj

@moldcraft the reference removal messed up the indexes on my end https://github.com/ThemeFuse/Unyson/pull/2180

danyj avatar Nov 28 '16 20:11 danyj

This also happens for me 2016-11-29_10-20-23

dk-wordpress avatar Nov 29 '16 08:11 dk-wordpress

I'm also able to confirm that this is a thing.

andreiglingeanu avatar Nov 29 '16 08:11 andreiglingeanu

@WPJobs how are you calling that maintenance_mode variable , can yo show me please. Thnx , without reference the fw_akg seem like overriding second param unless we are doing something funky when calling the options.

danyj avatar Nov 29 '16 11:11 danyj

So I can delete this repository?

ghost avatar Nov 29 '16 11:11 ghost

How to test/reproduce? I don't have any notices

Maybe because I use PHP 7 ?

ghost avatar Nov 29 '16 11:11 ghost

So I can delete this repository?

dont get mad , looks like many of us did not see the approval for this version

look at my email http://prntscr.com/dd5n0c

and when you changed the ref I changed the same thing on the copy of your function thz_akg and had no issues with it , so I assumed that the core one would be ok.

as for php version I am on 7.0.4

danyj avatar Nov 29 '16 11:11 danyj

I dont know how to reproduce it thus I asked @WPJobs ,

I will try to find a way now . few min

danyj avatar Nov 29 '16 11:11 danyj

look at my email http://prntscr.com/dd5n0c

I have disabled email notifications, I use only notifications on github site, they are grouped by repository screenshot from 2016-11-29 13-30-03

ghost avatar Nov 29 '16 11:11 ghost

this might help to test , add to functions.php

function thz_test_option($id = null,$default= null){
	
	
	global $thz_posthook;
	
	if($thz_posthook){
		
		return fw_get_db_post_option(get_the_ID(),$id ,$default);
		
	}else{
		
		return fw_get_db_settings_option($id ,$default);
	}
	
	
}

and this in hooks

function _thz_action_load_options_hooks() {
	
	global $thz_posthook;
	
	$thz_posthook 		= false;
	 if ( !is_admin() ) {
		 
		$post_options 		= fw_get_db_post_option(get_the_ID(),'custom_post_options/0',array());

		
		if(!empty ($post_options)){
			$thz_posthook = true;
		}


	 }
	
}

add_action( 'wp', '_thz_action_load_options_hooks' );

than call some option via

$someoption = thz_test_option ('mustbe/an/array', array());


if(!empty($someoption )){
    return 'something';
}

undefined indexes come from fw_get_db_settings_option and not from fw_get_db_post_option so far I can tell , not sure why.

danyj avatar Nov 29 '16 11:11 danyj

and test that on blog category page

danyj avatar Nov 29 '16 12:11 danyj

function _test_action_debug() {
	fw_print(fw_get_db_post_option(get_the_ID(), 'hello'));
	fw_print(fw_get_db_settings_option('hello'));
}
add_action('wp_head', '_test_action_debug');
add_action('admin_notices', '_test_action_debug');

still no warning.

@danyj So when you add back the reference the warning is gone?

ghost avatar Nov 29 '16 12:11 ghost

easier test

add this in theme/static.php

// bugs
$someoption= fw_get_db_settings_option('someoption/something',array());
$someoption2= fw_get_db_post_option(get_the_ID(),'someoption/something',array());

// no bugs
$someoption3= fw_get_db_settings_option('someoption',array());
$someoption4= fw_get_db_post_option(get_the_ID(),'someoption',array());

danyj avatar Nov 29 '16 12:11 danyj

yes when I add ref back error is gone

danyj avatar Nov 29 '16 12:11 danyj

dont use actual existing options , use as something

danyj avatar Nov 29 '16 12:11 danyj

@danyj Thank you!

Notice: Undefined index: someoption in /.../wp-content/plugins/unyson/framework/helpers/class-fw-db-options-model.php on line 147

ghost avatar Nov 29 '16 12:11 ghost

function _test() {
	fw_get_db_settings_option('someoption/something', array());
	fw_get_db_post_option(get_the_ID(), 'someoption/something', array());
}
add_action('admin_notices', '_test');

ghost avatar Nov 29 '16 12:11 ghost

dont forget to test with number values like

function _test() {
	fw_get_db_settings_option('someoption/something/0', array());
	fw_get_db_post_option(get_the_ID(), 'someoption/something/1', array());
}
add_action('admin_notices', '_test');

danyj avatar Nov 29 '16 12:11 danyj

function _test() {
	function _test_value($value) {}
	function _test_reference(&$value) {}

	$arr = array('existing_key' => true);
	fw_print(1, $arr);

	_test_value($arr['existing_key']);
	_test_value($arr['not_existing_key']);
	fw_print(2, $arr);

	_test_reference($arr['existing_key']);
	_test_reference($arr['not_existing_key']); // This will create the key!
	fw_print(3, $arr);

	_test_value($arr['existing_key']);
	_test_value($arr['not_existing_key']);
	fw_print(4, $arr);
}
add_action('admin_notices', '_test');

staticshot_29-11-2016_14-31-27

giphy

ghost avatar Nov 29 '16 12:11 ghost

http://stackoverflow.com/a/2030924/594423

by ref is overriding the existing array within the function

danyj avatar Nov 29 '16 12:11 danyj