Wordpress custom plugin error - Warning: Undefined array key "home_team" - php

i created custom plugin few years ago and now i have in my admin plugin page error Warning: Undefined array key "home_team" ....
Here is my code:
function DBP_insert_data()
{
global $wpdb;
$table_name = $wpdb->prefix . 'funstar_league';
$DBP_home = $_POST['home_team'];
$DBP_guest = $_POST['guest_team'];
$DBP_home_team_url_logo = $_POST['home_team_url_logo'];
$DBP_guest_team_url_logo = $_POST['guest_team_url_logo'];
$DBP_home_team_url_logo = $_POST['home_team_url_logo'];
$DBP_url = $_POST['url'];
$DBP_place = $_POST['place'];
$DBP_time = $_POST['game_time'];
$DBP_date = $_POST['game_date'];
if (isset($_POST['save'])) {
$wpdb->insert(
$table_name,
array(
'home_team' => $DBP_home,
'guest_team' => $DBP_guest,
'home_team_url_logo' => $DBP_home_team_url_logo,
'guest_team_url_logo' => $DBP_guest_team_url_logo,
'url' => $DBP_url,
'place' => $DBP_place,
'game_time' => $DBP_time,
'game_date' => $DBP_date,
),
array(
'%s', // Use string format
'%s',
'%s',
'%s',
'%s',
)
);
}
}
Here is error post:
Warning: Undefined array key "home_team" in /Users/tomasvalach/www/fun_2/wp-content/plugins/extraliga/extraliga_insert_file.php on line 133
Warning: Undefined array key "guest_team" in /Users/tomasvalach/www/fun_2/wp-content/plugins/extraliga/extraliga_insert_file.php on line 134
Warning: Undefined array key "home_team_url_logo" in /Users/tomasvalach/www/fun_2/wp-content/plugins/extraliga/extraliga_insert_file.php on line 135
Warning: Undefined array key "guest_team_url_logo" in /Users/tomasvalach/www/fun_2/wp-content/plugins/extraliga/extraliga_insert_file.php on line 136
Warning: Undefined array key "home_team_url_logo" in /Users/tomasvalach/www/fun_2/wp-content/plugins/extraliga/extraliga_insert_file.php on line 137
Warning: Undefined array key "url" in /Users/tomasvalach/www/fun_2/wp-content/plugins/extraliga/extraliga_insert_file.php on line 138
Warning: Undefined array key "place" in /Users/tomasvalach/www/fun_2/wp-content/plugins/extraliga/extraliga_insert_file.php on line 139
Warning: Undefined array key "game_time" in /Users/tomasvalach/www/fun_2/wp-content/plugins/extraliga/extraliga_insert_file.php on line 140
Warning: Undefined array key "game_date" in /Users/tomasvalach/www/fun_2/wp-content/plugins/extraliga/extraliga_insert_file.php on line 141

Related

It is a bug of php about define?

Writing:
define ("MYARR", array(
'TITLE' => "MY TITLE",
) );
And giving:
print_r(MYARR);
No error is returned. It is all ok! I display:
Array
(
[TITLE] => MY TITLE
)
But if i write:
define ("MYARR['TITLE']", "MY TITLE");
I don't get a error, but giving:
print_r(MYARR);
I get:
Warning: Use of undefined constant MYARR - assumed 'MYARR'
And giving:
echo MYARR['TITLE'];
I get this two warning:
1) Warning: Use of undefined constant MYARR
2) Warning: Illegal string offset 'TITLE'
About first warning, it not is correct, becouse as is possible to see above it is declared!
I think which is a bug of PHP. From a side is allowed declare constant of array but of other side not allowed. What is your opinion?

Wordpress: "Warning: Illegal string offset" in multiple places

Hopefully, you guys can help me here. What's going on with these issues in my WordPress install, see the errors and referenced code block.
Errors:
Warning: Illegal string offset 'domain' in /home/customer/www/xxxxxxxx.xxx/public_html/wp-includes/l10n.php on line 583
Warning: Illegal string offset 'context' in /home/customer/www/xxxxxxxx.xxx/public_html/wp-includes/l10n.php on line 587
Warning: Illegal string offset 'singular' in /home/customer/www/xxxxxxxx.xxx/public_html/wp-includes/l10n.php on line 588
Warning: Illegal string offset 'plural' in /home/customer/www/xxxxxxxx.xxx/public_html/wp-includes/l10n.php on line 588
Warning: Illegal string offset 'context' in /home/customer/www/xxxxxxxx.xxx/public_html/wp-includes/l10n.php on line 588
Warning: Illegal string offset 'domain' in /home/customer/www/xxxxxxxx.xxx/public_html/wp-includes/l10n.php on line 583
Warning: Illegal string offset 'context' in /home/customer/www/xxxxxxxx.xxx/public_html/wp-includes/l10n.php on line 587
Warning: Illegal string offset 'singular' in /home/customer/www/xxxxxxxx.xxx/public_html/wp-includes/l10n.php on line 588
Warning: Illegal string offset 'plural' in /home/customer/www/xxxxxxxx.xxx/public_html/wp-includes/l10n.php on line 588
Warning: Illegal string offset 'context' in /home/customer/www/xxxxxxxx.xxx/public_html/wp-includes/l10n.php on line 588
Code:
function translate_nooped_plural( $nooped_plural, $count, $domain = 'default' ) {
if ( $nooped_plural['domain'] ) {
$domain = $nooped_plural['domain'];
}
if ( $nooped_plural['context'] ) {
return _nx( $nooped_plural['singular'], $nooped_plural['plural'], $count, $nooped_plural['context'], $domain );
} else {
return _n( $nooped_plural['singular'], $nooped_plural['plural'], $count, $domain );
}
}
Warning: Illegal string offset 'something' message means that you're trying to access the value of $someVar['something'] but it doesn't exist.
To avoid it, you should always use isset($someVar['something']) to check if the index exists (or not) in the given variable.

Illegal string offset After PHP Upgrade

Warning [2] Illegal string offset 'title' - Line: 66
if(!isset($params['title'])) {
$params['title'] = "Hidden Content";
}
and Warning [2] Illegal string offset 'title' - Line: 3
eval("\$return = \"".$templates->get("lock_wrapper")."\";");
Please help!

PHP Undefined offset Message when using "list" function

I got this error on my website this morning when I click on post-ad
I have tried looking at the code but don't seem to find anything wrong
if (!function_exists('adforest_extarct_link')) {
function adforest_extarct_link($string) {
$arr = explode('|', $string);
list($url, $title, $target, $rel) = $arr; /* This is line 148 */
$rel = urldecode(adforest_themeGetExplode($rel, ':', '1'));
$url = urldecode(adforest_themeGetExplode($url, ':', '1'));
$title = urldecode(adforest_themeGetExplode($title, ':', '1'));
$target = urldecode(adforest_themeGetExplode($target, ':', '1'));
return array("url" => $url, "title" => $title, "target" => $target, "rel" => $rel);
}
This is the error Message
Undefined offset: 3 in /customers/7/6/1/corpersmarket.com/httpd.www/wp-content/themes/adforest/inc/theme_shortcodes/short_codes_functions.php on line 148
It actually has 3 lines of error:
Notice: Undefined offset: 1 in /customers/7/6/1/corpersmarket.com/httpd.www/wp-content/themes/adforest/inc/theme_shortcodes/short_codes_functions.php on line 148
Notice: Undefined offset: 2 in /customers/7/6/1/corpersmarket.com/httpd.www/wp-content/themes/adforest/inc/theme_shortcodes/short_codes_functions.php on line 148
Notice: Undefined offset: 3 in /customers/7/6/1/corpersmarket.com/httpd.www/wp-content/themes/adforest/inc/theme_shortcodes/short_codes_functions.php on line 148
Question is broadly a duplicate of PHP undefined offset from list()
However,
Your list expects at least 4 prameters -- but your $arr array only has 1. So the following three are empty. (remember arrays start at 0). So your $string does not contain a | character for the explode function to work as intended.
Workaround:
Original:
$arr = explode('|', $string);
list($url, $title, $target, $rel) = $arr; /* This is line 148 */
Becomes:
$arr = array_pad(explode('|', $string), 4, null);
list($url, $title, $target, $rel) = $arr;
What this does:
Pads the array out to contain a minimum of 4 values; so that the list values will always be populated, even if they may still be empty.

Getting error Uninitialized string offset: 0 in php

$imageTypes = array("image/gif", "image/jpeg", "image/png","image/jpg");
$uploadData = array_shift($check);
print_r($uploadData)
Array
(
[name] => Chrysanthemum.jpg
[type] => image/jpeg
[tmp_name] => C:\xampp\tmp\phpAADE.tmp
[error] => 0
[size] => 879394
)
if(!in_array($uploadData['type'],$imageTypes)){
return false;
}
But i m getting error Uninitialized string offset: 0 in this below line
if(!in_array($uploadData['type'],$imageTypes)){
On your piece of code $check is undefined.
$imageTypes = array("image/gif", "image/jpeg", "image/png","image/jpg");
$uploadData = array_shift($check);
if(!in_array($uploadData['type'],$imageTypes)){
return false;
}
Maybe you have to fix by:
$imageTypes = array("image/gif", "image/jpeg", "image/png","image/jpg");
$uploadData = array_shift($imageTypes);
if(!in_array($uploadData['type'],$imageTypes)){
return false;
}
I think I understand what might be happening here. The value you array_shift() from the $check array might be an empty string. Consider the following example:
$imageTypes = array("image/gif", "image/jpeg", "image/png","image/jpg");
$check = array(
'' // empty string
);
$uploadData = array_shift($check);
var_dump(in_array($uploadData['type'], $imageTypes));
This raises the following warnings/notices:
PHP Warning: Illegal string offset 'type' in /Users/darragh/Sites/so.php on line 26
PHP Stack trace:
PHP 1. {main}() /Users/darragh/Sites/so.php:0
PHP Notice: Uninitialized string offset: 0 in /Users/darragh/Sites/so.php on line 26
PHP Stack trace:
PHP 1. {main}() /Users/darragh/Sites/so.php:0
Warning: Illegal string offset 'type' in /Users/darragh/Sites/so.php on line 26
Call Stack:
0.0002 227040 1. {main}() /Users/darragh/Sites/so.php:0
Notice: Uninitialized string offset: 0 in /Users/darragh/Sites/so.php on line 26
Call Stack:
0.0002 227040 1. {main}() /Users/darragh/Sites/so.php:0
bool(false)
Example: https://eval.in/134971
Note that your notice PHP Notice: Uninitialized string offset: 0 is in there, amongst other things.
Either way, you should make your code robust, perhaps raise an exception or deal with the error in your preferred manner. Something like:
$uploadData = array_shift($check);
// die if the data is not an array or if it does not have the expected key
if (!is_array($uploadData) || !array_key_exists('type', $uploadData)) {
exit('$uploadData is not a valid array!');
}
// etc.
return !in_array($uploadData['type'], $imageTypes);
Example: https://eval.in/134972
Hope this helps.

Categories