Link to home
Start Free TrialLog in
Avatar of DrDamnit
DrDamnitFlag for United States of America

asked on

Wordpress Plugin Doesn't Save Options

I am working through the Wordpress Bible, and as usual, a programming book has errors in the code.

This code is ridiculously simple (supposedly); however, it doesn't save anything to the database.

here's the issue:

The plugin load fine.
It activates fine.
It displays the menu fine
But if you enter in the data to be saved to the DB, it doesn't save it.

I know the problem is that the add_action() is the failure point (specifically, because it specifies load-copyright-notices.php as the hook, which is not a hookable function / action).

The issue is... I don't know how to fix it.

How do I fix this?
<?php
/*
Plugin Name: Copyright Notices
Plugin URI: http://emmense.com/copyright-notices/
Description: A plugin that allows the user to set Copyright text in the
theme and control it from WordPress Admin.
Author: Aaron Brazell
Version: 1.0
Author URI: http://technosailor.com/
*/

function copyright_notices_admin()
{
?>
<div class="wrap">
<?php screen_icon(); ?>
<h2>Copyright Notices Configuration</h2>
<p>On this page, you will configure all the aspects of this plugins.</p>
<form action="" method="post" id="copyright-notices-conf-form">
<h3><label for="copyright_text">Copyright Text to be inserted in the footer of your theme:</label></h3>
<p><input type="text" name="copyright_text" id="copyright_text" value="<?php echo esc_attr( get_option('copyright_notices_text') ) ?> " /></p>
<p class="submit"><input type="submit" name="submit" value="Update options &raquo;" /></p>
<?php wp_nonce_field('copyright_notices_admin_options-update'); ?>
</form>
</div>
<?php
}
function copyright_notices_admin_page()
{
        add_submenu_page('options-general.php','Copyright Notices Configuration', 'Configure Copyright Notices ', 'manage_options', 'copyright-notices', 'cop
}

function save_copyright_notices()
{
        if( check_admin_referer('copyright_notices_admin_options-update'))
        {
                if( update_option( 'copyright_notices_test', stripslashes( $_POST['copyright_text']))) wp_redirect( __FILE__ . '?updated=1');
        } else {
                echo "<p>Update fail.</p>";
        }
}
add_action('admin_menu', 'copyright_notices_admin_page');
add_action('load-copyright-notices.php','save_copyright_notices');
?>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of jrm213jrm213
jrm213jrm213
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial