Jump to content

undefined index problem


Go to solution Solved by CyberShot,

Recommended Posts

I am working in WordPress building a widget for siteorigin page builder. The widget is working just fine but I am getting an undefined index error and I don' t know why. I have a file that returns and array. That is all that it does. It looks like this but has a lot more indexes.

'facebook'    => array(
	'label'    => __( 'Facebook', 'mosty' ),
	'base_url' => 'https://www.facebook.com/',
	'class'	   => 'fa fa-facebook',
),
'twitter'     => array(
	'label'    => __( 'Twitter', 'mosty' ),
	'base_url' => 'https://twitter.com/',
	'class'	   => '',
),

I have added the class index to the array and I am using the facebook one as my test. I need to get the result of the "class" index and send it to the front end of the site. I have that working. It does display on the front end. In the front end file, I have a bit of code to error check to see if I can get the value

 

I brought the array file into the back end like this

if( empty( $this->networks ) ) {
	$this->networks = include plugin_dir_path( __FILE__ ) . 'data/networks.php';
}
?php foreach ($network_names as $key => $value){
echo '<ul><li>The key is '. $key . ' The value is ' . $value . '</li></ul>'; 
} ?>

Here is the output of my test loop and at this point, this is all I would expect and the first entry is correct

    The key is facebook The value is fa fa-facebook

    The key is twitter The value is 

    The key is google-plus The value is 

    The key is linkedin The value is 

    The key is tumblr The value is 

    The key is vk The value is 

    The key is flickr The value is 

    The key is delicious The value is 

    The key is dribbble The value is 

    The key is skype The value is 

    The key is youtube The value is 

    The key is github The value is 

    The key is forrst The value is 

    The key is digg The value is 

    The key is soundcloud The value is 

On the front end of the site, I am getting this error

 

Notice: Undefined index: class in /path to widget/team/team.php on line 111

 

Here is my line 111

109  $network_names = array();
110  foreach ( $this->networks as $key => $value ) {
111	$network_names[ $key ] = $value['class'];
112  }

I am sending the array to the front end of the site on line 121 of team.php

 

I have attached my team.php class to the post for you to view.  Again, the widget does work and does display the data but gives me that undefined index for "class" index of my array. How can I solve this problem?

team.php

Edited by CyberShot
Link to post
Share on other sites
This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.