Video: Using existing options and option editing pages in WordPress

The WordPress options database has a number of options stored in it. Some of these are built into WordPress, and they might be handy to use in your own applications. In addition, you might want to be saving your own settings in here, and having them displayed in the built- in setting pages in the admin. So we're going to talk about how to integrate with these options. Let's go into the WordPress admin and take a look. There is a page you can link to-- you have to go there directly; there is not actually a link--in the admin menu called options.php, which contains all the settings in the database.

In WordPress: Creating Custom Widgets and Plugins with PHP, Drew Falkman teaches PHP developers how to create custom functionality for WordPress 2.0 through 3.0 using widgets and plugins. This course starts by installing and setting up WordPress 3.0 on both Mac and Windows, then provides an in-depth look at tasks related to these WordPress add-ons: installing and administering, building and customizing, creating editable options and database tables, working with posts and pages, and utilizing jQuery and AJAX. There are also tutorials dedicated to promoting a widget or plugin, adding security, and localizing the interface. Exercise files are included with the course.

Using existing options and option editing pages in WordPress

The WordPress options database has a number of options stored in it.Some of these are built into WordPress, and they might be handy to use inyour own applications.In addition, you might want to be saving your own settings in here, and havingthem displayed in the built- in setting pages in the admin.So we're going to talk about how to integrate with these options.Let's go into the WordPress admin and take a look. There is a page you can link to--you have to go there directly;there is not actually a link--in the admin menu called options.php, which containsall the settings in the database.

So you can see this is all here.Some of these are key, and you may want to access at different points in your application.You can always use get_option to refer to these just like we referred to our own options.So you can see the admin_e-mail is a good one.The blogdescription can be helpful. The blogname can be helpful.We also have information about the web site, what the URL is,stylesheet, all kinds of good information.In this page itself, you can actually edit this data directly.

So if you ever want to just quick change an option, you can do it right from here.If you want to integrate your own options into the built-in Settings pages, youcan do that, if you remember our cc_ comment plugin that we created allows us toedit a cccomm_cc_e-mail.Let's move this into the settings page.So first we can delete our existing form page.We won't need any longer.Then we can delete what's in the existing function to handle adding it to themenu, because it won't need to be in the menu any longer.

The first thing we're going to need to do is create a function that willgenerate an input field to handle this setting.So we'll create this, and we'll call it cccomm_setting_field.In here we're simply going to create input type = "text" name = "cccomm_cc_e-mail"id = "cccomm_cc_e-mail," and the value we're going to use get_option.

So echo get_option cccomm_cc_e-mail, and then close a tag, and then we'll want toof course go back into php.So we don't need to do anything else with this.You just need to make sure that the ID and the name field match the option.Then to add this into the Settings page, we're going to use thespecial add_settings_field.You can specify an id, cccomm_cc_e-mail.

You're going to specify what you want to read for the label of that field.Then you want to specify the function that's going to generate the field.So this is going to be cccomm_setting_ field, and finally the section it's going tobe, which will be the general section.Notice we're already adding this into the admin_menu hook, so that should put itinto our menu for us.

So if we go back to our General Settings and we refresh it andwe scroll down, we should see our CC Comments has now been added to this page.If you want to have multiple settings and create different sections, there isanother function that enables you to create an entirely new section heading.So you'll create a function that outputs the section, and here you can just dosomething simple Settings.

Then we'll use this add_settings _section to add it directly in.So we say cccomm, which is an ID of the section. We have a name.We have the function that's going to generate.It's going to run once, essentially, at the beginning of this heading.So this will be cccomm_setting_section, what we just wrote, and where you want it to appear,in this case in the general section.

The only other thing you need to do at this point is specify if your fields aregoing to fall under that section.So there is another option here where you can specify that, and we just use theID that we created for that section.Now if we go back to our Settings page, we can reload, and you'll see we have ourCC Comments section.Notice it outputs the name and then whatever you had in your code, and then wewould have whatever fields afterwards.So we can access any of these settings that are stored in the options database.

We also, since WordPress 2.7, have the ability to add our own items directlyinto the Settings pages.

Find answers to the most frequently asked questions about WordPress: Creating Custom Widgets and Plugins with PHP .

Here are the FAQs that matched your search "" :

Expand all | Collapse all

please wait ...

Q: Do I need a web hosting service for this course?

A: You don't need a hosting site to do any testing or development work that’s covered in this course. However, if you want to have your WordPress site available to the public, you will most definitely need a WordPress site. If you are hosting with an independent company, they will need to have PHP and MySQL installed, and there will be some configuration differences, but basically, you can upload anything on your local version to the web site. If you are hosting with Wordpress.com, you will need to add your plugins by uploading them manually through the WP Admin Plugin screen.

Sorry, there are no matches for your search "" —to search again, type in another word or phrase and click search.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.

Already a member ?

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships.
Learn more

Upgrade to our Annual Premium Membership today and get even more value from your lynda.com subscription:

“In a way, I feel like you are rooting for me. Like you are really invested in my experience, and want me to get as much out of these courses as possible this is the best place to start on your journey to learning new material.”— Nadine H.

Thanks for signing up.

We’ll send you a confirmation email shortly.

Sign up and receive emails about lynda.com and our online training library:

new course releases

newsletter

general communications

special notices

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

new course releases

newsletter

general communications

special notices

Here’s our privacy policy with more details about how we handle your information.