?
Solved

Wordpress Plugin Doesn't Save Options

Posted on 2010-09-21
1
Medium Priority
?
739 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 2000 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

WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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 purpose of this video is to demonstrate how to update a WordPress Site’s version. WordPress releases new versions of its software frequently and it is important to update frequently in order to keep your site secure, and to get new WordPress…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

764 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