Plugin Writing Problems – Write / Read to textarea in Admin
-
Hey. I’ve been trying to write this plugin to return admin quotes into a theme. The plugin’s working nicely, but now I want to extend it so the user can add quotes from the admin area, instead of having to edit the PHP.
The trouble is that I can’t work out how to write current values to the textarea for the user to edit, or for them to be saved for future use. I’ve tried the codex and various plugin/admin-writing tutorials, but I can’t get it to work.
Here’s the code that I’ve written so far: (Yes, it’s probably a bit long, sorry!):
<?php /* Plugin Name: Admin_Quotes [UI] Plugin URI: Description: You put your quotes in, this shows one when you call it on your pages. Will soon include a UI to insert quotes. Author: Nathan Chapman Version: 0.7 Author URI: */ function list_of_quotes() { //These are the quotes that may be shown $quotes = "As a UNIT! Ni! Nobody Expects the Spanish Inquisition! Us nerds, we thrive on three things: <ol> <li>Doctor Who</li> <li>Battlestar Galactica, and a </li> <li>damn good complants forum</li> </ol> "; // Here we split it into lines $quotes = explode("\n", $quotes); // And then randomly choose a line return wptexturize( $quotes[ mt_rand(0, count($quotes) - 1) ] ); } // This just echoes the chosen line, this is what you call in the theme function get_admin_quotes() { $chosen = list_of_quotes(); echo "<p id='admin_quote'>$chosen "; } add_option($quotes); // From here down concerns the creation of the admin UI --------------------------------------------------------------------------------- add_action('admin_menu', 'quotes_menu'); function quotes_menu() { add_options_page('AdminQuotes Options', 'AdminQuotes', 8, __FILE__, 'admin_quotes_options'); } function admin_quotes_options() { echo ('<div class="wrap"> <h2>Admin Quotes Options</h2> Here you can define what quotes show up when the plugin is called. Add the quotes to the textbox below, one per line. <form method="post" action="options.php">'); wp_nonce_field('update-options'); // inserts some hidden fields into the form echo ('<table class="form-table"> <tr valign="top"> <th scope="row">List of quotes</th> <td><textarea name="new_option_name"></textarea></td> </tr> </table> <input type="hidden" name="action" value="update" /> <input type="hidden" name="page_options" value="quotes_list" /> <p class="submit"> <input type="submit" class="button-primary" value="Save" /> </form> </div> '); } ?>If anyone could help, or even just link to somewhere that I can use, it’d be great. Thanks, Nathan
The topic ‘Plugin Writing Problems – Write / Read to textarea in Admin’ is closed to new replies.