When you create a WordPress plugin, and you're already saving WordPress plugin settings with a form. You want to register those settings and store them in the database with WordPress, so it can change your site.

Register plugin settings with WordPress

We want to take the info entered by a plugin user, and store it into the WordPress database. To do this we need to register our setting changes with WordPress so it can store this information in the wp_options table.

Add add_action hook to register settings

When you create a WordPress admin menu you can add an add_action function after the add_menu_page function. This call another function update_extra_post_info to save info to the database from our form.

  add_menu_page( $page_title,
                 $menu_title, 
                 $capability, 
                 $menu_slug, 
                 $function, 
                 $icon_url, 
                 $position );

  add_action( 'admin_init', 'update_extra_post_info' );
}

Register settings with register_setting function

Creating a function called update_extra_post_info you can use the WordPress register_setting function to store info from our form into the database. The value will be stored next to extra_post_info in the wp_options table.

if( !function_exists("update_extra_post_info") ) {
function update_extra_post_info() {
  register_setting( 'extra-post-info-settings', 'extra_post_info' );
}
}

Plugin settings now saved to WordPress database

When you view your plugin page, you can see that when EXTRA INFO is entered into our settings, it ends up in the WordPress database beside extra_post_info. When this info is updated, so is the database entry.

extra post info admin page register setting in database

Read WordPress plugin settings from database

With your plugin settings saved in the database, the next step is to read WordPress plugin settings from the database to complete your plugin.

Did you find this article helpful?

We value your feedback!

Why was this article not helpful? (Check all that apply)
The article is too difficult or too technical to follow.
There is a step or detail missing from the instructions.
The information is incorrect or out-of-date.
It does not resolve the question/problem I have.
How did you find this article?
Please tell us how we can improve this article:
Email Address
Name

new! - Enter your name and email address above and we will post your feedback in the comments on this page!

Like this Article?

Related Questions

Here are a few questions related to this article that our customers have asked:
Ooops! It looks like there are no questions about this page.
Would you like to ask a question about this page? If so, click the button below!
Ask a Question

Post a Comment

Name:
Email Address:
Phone Number:
Comment:
Submit

Please note: Your name and comment will be displayed, but we will not show your email address.

0 Questions & Comments

Post a comment

Back to first comment | top

Need more Help?

Search

Ask the Community!

Get help with your questions from our community of like-minded hosting users and InMotion Hosting Staff.

Current Customers

Chat: Click to Chat Now E-mail: support@InMotionHosting.com
Call: 888-321-HOST (4678) Ticket: Submit a Support Ticket

Not a Customer?

Get web hosting from a company that is here to help. Sign up today!