Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress How to Build a WordPress Plugin Connecting WordPress Plugins with 3rd Party APIs Getting and Storing JSON Code Challenge

Need Help with Task 5 on the challenge code course for Json task.

Have been stuck on this the past 2 hours! I don't know what i keep doing wrong.

plugin.php
<?php
function my_plugin_get_profile($my_plugin_username) {
$json_feed_url = 'http://myapi.net/' . $my_plugin_username . '.json';
$args = array( 'timeout' => 120);

 $json_feed = wp_remote_get( $json_feed_url, $args );
  return $json_feed;

  $my_plugin_profile = json_decode( $json_feed['body'] ); 
  return $my_plugin_profile; }
}
?>

4 Answers

Chase Marchione
Chase Marchione
155,055 Points

Hi Mark,

1) You have an extra closing curly brace, so you'll want to get rid of one of those.

2) You'll want to remove the following line:

  return $json_feed;

Your function currently has two return statements, and we want to keep those to one per function. Returning the $json_feed variable isn't needed in this case, so we don't need to add it to our needed return statement, either.

Hope this helps!

Still having a hard time with it. I did as you said. Removed the following line. Still getting it incorrect.

Chase Marchione
Chase Marchione
155,055 Points

Have you removed the curly brace too?

{ is this the curly brace?

Chase Marchione
Chase Marchione
155,055 Points

You have the right amount of those. What you have an extra of is a closing brace ('}').

yes i did. Still no progress.

Thanks for your advice! Its up and running now!

Chase Marchione
Chase Marchione
155,055 Points

Not a problem! The rule is that for every opening brace you want one closing brace: otherwise, the compiler gets confused because matching sets of opening and closing braces are used to contain things, such as function bodies.