[Plugin: CongressLookup] Not Working
-
I can’t get your plugin to work. I’ve used it on your site and think it’s perfect for what I need.
I am using a fresh install of WordPress 3.4.1 and have all other plugins disabled. I only have 1 page and 1 post on the site and am have tried setting my theme to the twentyeleven theme to rule out anything else.
This is the error code I get:
Warning: Invalid argument supplied for foreach() in /home/losingou/public_html/wp-content/plugins/congresslookup/getData.php on line 35
I tried installing the plugin by zip file and by ftp. I can’t get either to work. I also noticed that when unpacking the getData.php file it did not format correctly. So I put the proper carriage returns back in to correct the formatting.
I think the problem may be that the getData.php file became corrupt when you packed it. Could you send me that file?
-
I am sorry that you are having problems with the plugin. I have tested the downloaded zip file on a fresh site and found no problems with that install.
Line 35 has to do with the legislator images. It is possible that the zip of their pictures did not download properly. Try going to Settings > CongressLookup and clicking the button to update/download the pictures again from Sunlight Labs site. This may take a while to complete… even though the images are small there are many of them.
But in case there is a problem with the file itself, here is the file you requested: http://congresslookup.com/files/getData.zip
Please let me know if you are still having problems.
Hi Again, Thanks for getting back to me. I am still unable to get it to function. The same thing happens when I download your zipped getData.php file. Every other php file uncompressed properly with the correct formatting. This one looks like this when uncompressed:
<?php if(isset($_GET['lat']) && isset($_GET['lon'])) { require_once('../../../wp-load.php'); $url = plugin_dir_url(__FILE__); $api_call = "http://services.sunlightlabs.com/api/legislators.allForLatLong.json?apikey=".get_option('congress_key')."&latitude=".$_GET['lat']."&longitude=".$_GET['lon']; if(get_option("congress_cache")) { require 'API_cache.php'; $cache_file = 'cache/'.md5($api_call).'.json'; $cache_for = get_option("congress_cache_time"); // cache time in minutes $api_cache = new API_cache ($api_call, $cache_for, $cache_file); $congress = $api_cache->get_api_cache(); } else $congress = @file_get_contents($api_call); if($congress ) { $congress = json_decode($congress); if(get_option("congress_options")) $a = get_option("congress_options"); else $a = array(); echo '<div class="legislators_list">'; foreach ($congress->response->legislators as $c) { $pic_name = "pics/".$c->legislator->bioguide_id.".jpg"; if(is_array($a) &&count($a) > 0) { echo "<h3 class='legislator'>".$c->legislator->firstname." ".$c->legislator->lastname." <small>(".$c->legislator->state." ".$c->legislator->district.")</small></h3>"; if(in_array("picture", $a)) { if(file_exists($pic_name)) echo "<img class='legislator-pic' src='".$url.$pic_name."' width='40' height='50' alt='' />"; else echo "<img class='legislator-pic' src='".$url."pics/unknown.jpg' width='40' height='50' alt='' />"; } echo "<ul class='legislator-contact'>"; foreach($c->legislator AS $key=>$value) { if(in_array($key, $a)) { if(empty($value)) $value = "Not Available"; if(strpos($value, "http:") !== false) $value = '<a href="'.$value.'" target="_blank" rel="nofollow">'.$value.'</a>'; echo "<li>$key: $value</li>"; } } echo "</ul>"; } else { echo "<h3 class='legislator'>".$c->legislator->firstname." ".$c->legislator->lastname." <small>(".$c->legislator->state." ".$c->legislator->district.")</small></h3>"; } } echo '<div style="clear:both"></div></div>'; } else echo "Error1"; } else echo "Error2"; ?>I’ve tried reformatting it to this:
<?php if(isset($_GET['lat']) && isset($_GET['lon'])) { require_once('../../../wp-load.php'); $url = plugin_dir_url(__FILE__); $api_call = "http://services.sunlightlabs.com/api/legislators.allForLatLong.json?apikey=".get_option('congress_key')."&latitude=".$_GET['lat']."&longitude=".$_GET['lon']; if(get_option("congress_cache")) { require 'API_cache.php'; $cache_file = 'cache/'.md5($api_call).'.json'; $cache_for = get_option("congress_cache_time"); // cache time in minutes $api_cache = new API_cache ($api_call, $cache_for, $cache_file); $congress = $api_cache->get_api_cache(); } else $congress = @file_get_contents($api_call); if($congress ) { $congress = json_decode($congress); if(get_option("congress_options")) $a = get_option("congress_options"); else $a = array(); echo '<div class="legislators_list">'; foreach ($congress->response->legislators as $c) { $pic_name = "pics/".$c->legislator->bioguide_id.".jpg"; if(is_array($a) &&count($a) > 0) { echo "<h3 class='legislator'>".$c->legislator->firstname." ".$c->legislator->lastname." <small>(".$c->legislator->state." ".$c->legislator->district.")</small></h3>"; if(in_array("picture", $a)) { if(file_exists($pic_name)) echo "<img class='legislator-pic' src='".$url.$pic_name."' width='40' height='50' alt='' />"; else echo "<img class='legislator-pic' src='".$url."pics/unknown.jpg' width='40' height='50' alt='' />"; } echo "<ul class='legislator-contact'>"; foreach($c->legislator AS $key=>$value) { if(in_array($key, $a)) { if(empty($value)) $value = "Not Available"; if(strpos($value, "http:") !== false) $value = '<a href="'.$value.'" target="_blank" rel="nofollow">'.$value.'</a>'; echo "<li>$key: $value</li>"; } } echo "</ul>"; } else { echo "<h3 class='legislator'>".$c->legislator->firstname." ".$c->legislator->lastname." <small>(".$c->legislator->state." ".$c->legislator->district.")</small></h3>"; } } echo '<div style="clear:both"></div></div>'; } else echo "Error1"; } else echo "Error2"; ?>But it still gives me this error:
Warning: Invalid argument supplied for foreach() in I_removed my_server_directory_structure_for_security/wp-content/plugins/congresslookup/getData.php on line 35
Let me correct that. When I copied the code it formatted it correctly. I then copied it and tried it in the plugin. and got back almost the same error but with line 34.
Warning: Invalid argument supplied for foreach() in I_removed my_server_directory_structure_for_security/wp-content/plugins/congresslookup/getData.php on line 34
I see no difference between the two sets of code you posted here. I have put them both into my comparison tool and, except for a couple extra blank lines, are identical to the original.
Have you tried re-downloading the image file from Sunlight Labs using the button in the Settings > CongressLookup page?
I have, I’ve looked through the code and can’t seem to find the error either . It’s very frustrating
We will get to the bottom of this, one way or the other.
I am the designer and not the coder so I’m going to get him involved now that it’s beyond my ability to help. He’s been on vacation in another part of the world. Hopefully I can get in touch with him soon. I’ll keep you informed.
While we are waiting on the coder… I have checked that the file in question was saved properly with a text editor and have re-committed it to the repository. Please uninstall and delete your current installed version and try downloading and installing the current one.
Also, can you tell us what domain you are trying it on? If you don’t want it made public here, you can email me at: [email protected]
Hi There,
Sorry for late,
It’s an odd bug you found there, unfortunately i can’t do much without taking a look at what exactly going on,
the problem comes after getting the data from sunlightlabs API
$congress = @file_get_contents($api_call);apparently the data returned is not an array or an object, so we will have so see what it actually returns,
Open getData.php file,
and right under
$congress = @file_get_contents($api_call);
put
print_r($congress);Thanks
Hello InsightDezign,
Just wanted to remind you that we are waiting on your reply so we can figure out the problem.
I just tried that and it just moved my error to line 37. I sent you login information so you can try if you like. I can resend it if you like.
Apparently, it seems to be working,
I guess the problem was with the key been invalidYes. Before when I checked it was showing an invalid key. InsightDezign entered it again and now it is working.
Please let us know if you face any other issues.
Thank you gentleman.
I feel pretty dumb. The email from sunlightlabs gave me API in it so I just copied it and used it. I didn’t bother to read the full email that said I needed to click on the link to activate the API.
Hopefully others who have the same problem will learn from my mistake.
I really appreciate you taking the time though. You are very professional.
I think it is good that you made this mistake early in the plugin’s life as now I can add a reminder to activate the API key to the installation instructions. So, thank you for that π
Please let us know if you need any further assistance.
Marking topic as resolved.
The topic ‘[Plugin: CongressLookup] Not Working’ is closed to new replies.