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!
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

Marwa zada
UX Design Techdegree Student 15,460 PointsCode Challenge: Create a global array named "options" and include it in the options page function.
I'm stuck on this challenge. I create a global option array using global $options; but am stuck on including it in the options page function.
4 Answers

Luke Wenke
32,294 Points<?php
$options = array();
function my_plugin_options_page() {
if( !current_user_can( 'manage_options' ) ) {
wp_die( 'You do not have sufficient permissions to access this page.' );
}
global $options;
if( isset( $_POST['my_plugin_hidden_field'] ) ) {
$my_plugin_username = esc_html( $_POST['my_plugin_username'] );
}
require('includes/page-wrapper.php');
}
?>

Luke Wenke
32,294 Points$options = array(); should be declared at the start

Bradley Maravalli
8,927 PointsThanks Luke! That did the trick.
<?php
$options = array();
function my_plugin_options_page() {
global $options;
if( !current_user_can( 'manage_options' ) ) {
wp_die( 'You do not have sufficient permissions to access this page.' );
}
if( isset( $_POST['my_plugin_hidden_field'] ) ) {
$my_plugin_username = esc_html( $_POST['my_plugin_username'] );
}
require('includes/page-wrapper.php');
}
?>

Luke Wenke
32,294 PointsI think initially I put "global $options" in the wrong spot but here you can see where the right spot is:
http://teamtreehouse.com/library/crud-with-the-wordpress-options-table-part-2

Marwa zada
UX Design Techdegree Student 15,460 PointsLuke would you mind sharing your code with me? I still haven't gotten this down.
lyonel scapino
14,191 Pointslyonel scapino
14,191 Pointswhy there? why not working at the beginning? (put the global variable at the beginning)