Lesson 08: Creating pages in WordPress Management Options

View: 426    Dowload: 0   Comment: 0   Post by: admin  
Author: none   Category: WordPress template   Fields: Other

6 point/2 review File has been tested

Applying the knowledge of Options in WordPress API is in this article I will guide you to create a page in admin management options .

Introduction

Applying the knowledge of Lesson 07: Options in WordPress API is in this article I will guide you to create a page in admin management options
In previous articles I have outlined an example of management information email username and password , so in this article we will create a two- page information management , ie the user can edit and change their values ​​change .

To create this Options page management , you will have to make the turn in steps that I will present below

1. Create admin menu

When you log into the admin management system will see a menu based user interface as follows :

This is the default menu ( fixed ) of WordPress .

 Problems learn all this , I'll menu for a future article , so in this article I will guide you how to add a simple menu whiff , and his position will add a submenu inside Appearance items named Theme Options and click on the menu when the page will redirect to manage your Gmail account information . 

  click the file you Option-api.php erase all the old code and paste into the following code:

// Additional content on a menu submenu father
add_submenu_options function ( )
{
    add_submenu_page (
            ' Themes.php ' , // Menu father
            ' Theme Options' , // menu title
            ' Theme Options' , // The name of the menu
            ' Manage_options ' , // The access , meaningful values ​​only supper admin and user admin DC
            ' Theme - options' , // menu Slug
            ' Access_menu_options ' // callback displays the contents of the menu
    ) ;
}
 
// Add the action displayed on the Action submenu admin_menu Hooks
add_action ( ' admin_menu ' , ' add_submenu_options ' ) ;

 

This code displays a submenu within the Appearance menu father .

You try to click Theme Options menu you will get an error message like the following page :

This error may mean that you lack a callback function named access_menu_options . access_menu_options are values ​​that have been instilled into add_submenu_page code . To all my fault, you create a function in the file named access_menu_options option-api.php always offline.

// Additional content on a menu submenu father
add_submenu_options function ( )
{
    add_submenu_page (
            ' Themes.php ' , // Menu father
            ' Theme Options' , // menu title
            ' Theme Options' , // The name of the menu
            ' Manage_options ' , // The access , meaningful values ​​only supper admin and user admin DC
            ' Theme - options' , // menu Slug
            ' Access_menu_options ' // callback displays the contents of the menu
    ) ;
}
 
// Handler when clicking on menu
access_menu_options function ( )
{
    echo ' < h1 > Welcome to Theme Options Page < / h1 > ' ;
}
 
// Add the action displayed on the Action submenu admin_menu Hooks
add_action ( ' admin_menu ' , ' add_submenu_options ' ) ;

Rerun this page you will find there is no error message again .

2. Create a form management interface Theme Options

Access_menu_options function will have the task of handling display of the form interface . However for ease of file management , you create a folder named templates within public folder , then create a theme-option.php files inside the folder template used to display a form, ultimately require a file theme-option.php in access_menu_options function .

Folder structure :

Content in access_menu_options function :

// Handler when clicking on menu
access_menu_options function ( )
{
    require ( ' template / theme - option.php ' ) ;
}

theme-option.php file contents


 

Manage theme options

Email
Password
 

This menu strange running , you will see an interface as follows :

Thus we have completed step 2 , was wonderful .

3. Show information before updating

Now we will code the function to display information on the input box so that users can edit using the APIs get_option Options .

You fix access_menu_options function as follows:

// Handler when clicking on menu
access_menu_options function ( )
{
     
     
    // Get the information in the table Options
    $ Email = get_option ( ' mailer_gmail_username ' ) ;
    $ Pass = get_option ( ' mailer_gmail_password ' ) ;
     
    require ( ' template / theme - option.php ' ) ;
}

Then through theme-option.php file amended as follows :


 

Manage theme options

Email
Password
 

4. Handling save information Options

You want to look your form management option not transmit path into the action attribute , so when submitting the form it will handle in the pages up .

You fix access_menu_options function as follows:

// Handler when clicking on menu
access_menu_options function ( )
{
    if ( ! empty ( $ _ POST [ 'save - theme -option ' ] ) )
    {
        $ Email = $ _ POST [ ' email ' ] ;
        $ Pass = $ _ POST [ ' password' ] ;
         
        // Update ( if not, add a new automated system )
        update_option ( ' mailer_gmail_username ' , $ email ) ;
        update_option ( ' mailer_gmail_password ' , $ pass) ;
    }
     
    // Get the information in the table Options
    $ Email = get_option ( ' mailer_gmail_username ' ) ;
    $ Pass = get_option ( ' mailer_gmail_password ' ) ;
     
    require ( ' template / theme - option.php ' ) ;
}

And this is the final step of this management function options . You go to this page and make updates contents 2 information to see the results offline :)

5. Conclusion

In this article I only guide basic usage and no combination of security functions in WordPress so you take a whiff for reference , the latter when it comes to security issues , we 'll do it again a more professional way .  This article I have not learned to use the function for creating the menu , so my next post will talk about this issue .

Lesson 08: Creating pages in WordPress Management Options

Lesson 08: Creating pages in WordPress Management Options Posted on 06-05-2016  Applying the knowledge of Options in WordPress API is in this article I will guide you to create a page in admin management options . 3/10 426

Comment:

To comment you must be logged in members.

Files with category

 

File suggestion for you

File top downloads

logo codetitle
Codetitle.com - library source code to share, download the file to the community
Copyright © 2015. All rights reserved. codetitle.com Develope by Vinagon .Ltd