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

Getting and Storing JSON Code Challenge task 5

The question: Create a variable named my_plugin_profile. Assign it the JSON decoded value of the json_feed array's body index. Then return the my_plugin_profile variable.

My code: <?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 ); $wptreehouse_profile = json_decode( $json_feed['$my_plugin_profile'] ); return $json_feed['$my_plugin_profile']; }

?>

I don't understand what I'm doing wrong.

Hey there, I'm going to attempt to help you without giving you the answer. First "Create a variable named $my_plugin_profile." (not $wptreehouse_profile). Second "Assign it the JSON decoded value of the json_feed array's 'body' index" so your array[] needs a different value, extracted from the $json_feed. Lastly "Then return the my_plugin_profile variable." The $json_feed was already assigned to the $my_plugin_profile so you just need to return the my_plugin_profile variable. That may get you a little further, or you could be completely finished already. oh well.

M@

2 Answers

This is what I used and it worked. <?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 ); $my_plugin_profile = json_decode( $json_feed['body'] ); return $my_plugin_profile; }

?>

Kenan Memis
Kenan Memis
47,314 Points

Hi, The final part of your answer, the return statement, just replace it with the following:

return $my_plugin_profile;