Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

cm21
cm21
150,854 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.

cm21
cm21
150,854 Points

Have you removed the curly brace too?

{ is this the curly brace?

cm21
cm21
150,854 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!

cm21
cm21
150,854 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.