[help] Trying to make a “hello world” like plugin
-
Hi guys!
As the title indicates, I’m trying to work my way arround into making a “hello dolly” like plugin, but, instead of echoing text to the admin footer, I want it to echo to the loop_end. I’m also trying to make this as simple as it comes (1 file), so i can understand it, and, eventually, do something better next time.
Here’s the entire code:
<?php // Hook for adding admin menus add_action('admin_menu', 'mt_add_pages'); // action function for above hook function mt_add_pages() { // Add a new top-level menu (ill-advised): add_menu_page('Hello World', 'Hello World', 'administrator', 'mt-top-level-handle', 'mt_toplevel_page'); } // mt_sublevel_page() displays the page content for the first submenu // of the custom Test Toplevel menu function mt_toplevel_page() { // variables for the field and option names $opt_name = 'mt_favorite_food'; $hidden_field_name = 'mt_submit_hidden'; $data_field_name = 'mt_favorite_food'; // Read in existing option value from database $opt_val = get_option( $opt_name ); // See if the user has posted us some information // If they did, this hidden field will be set to 'Y' if( $_POST[ $hidden_field_name ] == 'Y' ) { // Read their posted value $opt_val = $_POST[ $data_field_name ]; // Save the posted value in the database update_option( $opt_name, $opt_val ); // Put an options updated message on the screen ?> <div class="updated"> <p><strong> <?php _e('Options saved.', 'mt_trans_domain' ); ?> </strong></p> </div> <?php } // Now display the options editing screen echo '<div class="wrap">'; // header echo "<h2>" . __( 'Menu Test Plugin Options', 'mt_trans_domain' ) . "</h2>"; // options form ?> <form name="form1" method="post" action=""> <input type="hidden" name="<?php echo $hidden_field_name; ?>" value="Y"> <p> <?php _e("Favorite Color:", 'mt_trans_domain' ); ?> <input type="text" name="<?php echo $data_field_name; ?>" value="<?php echo $opt_val; ?>" size="20"> </p> <hr /> <p class="submit"> <input type="submit" name="Submit" value="<?php _e('Update Options', 'mt_trans_domain' ) ?>" /> </p> </form> </div> <?php show_my_data($opt_val); }; function show_my_data($val) { $myvar = "<h2>".$val."</h2>"; echo $myvar; } add_action('loop_end', 'show_my_data'); ?>
The problem is that it’s echoing the data to the plugin admin page, and throwing me a “Catchable fatal error” on the end of the loop.
Any ideas? Any tips would come in handy!
Thanks a bunch!
Regards
- The topic ‘[help] Trying to make a “hello world” like plugin’ is closed to new replies.