Solved

Wordpress Plugin Doesn't Save Options

Posted on 2010-09-21
1
730 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 17

Accepted Solution

by:
jrm213jrm213 earned 500 total points
ID: 33728438
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

730 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