Solved

Wordpress Plugin Doesn't Save Options

Posted on 2010-09-21
1
720 Views
Last Modified: 2012-05-10
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

0
Comment
Question by:DrDamnit
1 Comment
 
LVL 17

Accepted Solution

by:
jrm213jrm213 earned 500 total points
Comment Utility
from: http://wordpress.org/support/topic/wordpress-bible-example

if(isset($_POST['copyright_text']))
add_action( 'load-plugins_page_copyright-notices', 'save_copyright_notices' );
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

So you have coded your own WordPress plugin and now you want to allow users to upload images to a folder in the plugin folder rather than the default media location? Follow along and this article will show you how to do just that!
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now