user3230561
user3230561

Reputation: 445

Wordpress Plugin Development - Settings page

I am developing plugin in Wordpress. For the plugin, I am suppose to create a settings page. When I was researching on Creation of Settings page for wordpress plugin. I found that, these values are normally stored under the wp_options table.

The only issue I am facing is that in my Settings page. I will be adding a lot of parameters. These parameters that I will be added is not a constant and will changes depending on the user's wish.

Therefore I thought of creating a separate table for the plugin settings page.

I would like to ask, Is there any disadvantage in doing so?

Thanks in Advance.

Upvotes: 2

Views: 331

Answers (3)

dhiraj kumar mishra
dhiraj kumar mishra

Reputation: 9

<?php
/**
Plugin Name: Curd Meta
*/
require_once "custom_post.php";
require_once "custom_category.php";
require_once "custom_texonomy.php";
require_once "metabox.php";
function  curd_enwueue_scripts(){
   wp_enqueue_style('plugin-css',plugins_url('assets\css\style.css',__FILE__));
    wp_enqueue_script('ajax-script',plugins_url('assets/js/custom.js',__FILE__),array('jquery','jquery-ui-datepicker'),'12345',true);
    wp_localize_script( 'ajax-script', 'ajaxobj', array('ajax_url' => admin_url( 'admin-ajax.php' )));
}
add_action('admin_enqueue_scripts','curd_enwueue_scripts');

add_action('admin_menu','my_curd_plugin_setting');
function my_curd_plugin_setting(){
    add_menu_page("Curd operation",'Curd','manage_options','curd-meta','my_curd_functions',
        "dashicons-facebook-alt",'9');    
}

function my_curd_functions(){

}

Upvotes: 0

Scuzzy
Scuzzy

Reputation: 12332

You could make use of the wordpress *_option() functions to store arbitrary data for your plugin, you can prefix it with your plugins name to ensure you don't collide with any existing data.

add_option('yourpluginnamehere_optionname','somedefaultdata'))

http://codex.wordpress.org/Options_API

From there you can use...

update_option('yourpluginnamehere_optionname',$somedatahere))
get_option('yourpluginnamehere_optionname');
delete_option('yourpluginnamehere_optionname');

You should also have a register_activation_hook() and register_deactivation_hook() process to create and clean up your plugins options when the plugin is installed/removed.


If you create and manage additional tables yourself, ensure you prefix them to ensure clear separation from the standard word press tables.

Create the appropriate activation/deactivation hooks to assist with plugin maintenance.

Upvotes: 1

Ilie Pandia
Ilie Pandia

Reputation: 1839

The only disadvantage would be that you'll have to manage storing the parameters yourself.

If you use the WP way of doing it, you already have functions do help you. If you want a custom storage, you will most likely have to write your own code to handle it.

Upvotes: 0

Related Questions