This post will guide you how to develop a new WordPress plugin, starting with the menu section.
Eventually the plugin will list Videos from Kaltura CE edition. Remember: Hook names and parameters must be exactly as written bellow.
WordPress Configuration Menu
Configuration menu allows you to control plugin specific settings,
functionality and options although it is not required by WordPress.
Here at Panda OS we always write configuration menus to support code reuse and enhance the functionality of our plugins.
Creating the menu:
Create a new directory under /wordpress/wp-content/plugins/ and give it a name. *Mine will be Panda Video.
Create a new php file in your plugin directory.
This file will serve as the “main” file for our plugin where we will
register our plugin and configure all the options that we’ll need for
it.
Register the plugin by inserting this code in the plugin main file, WordPress will automatically register it from the comments.
/** Plugin Name: Panda-OS New plugin
Plugin URI: A link to a text which contains information on the plugin.
Description: Listing Videos from Kaltura CE
Version: 1.0
Author: Panda OS
Author URI: http://www.panda-os.com
License: Your license agreement **/
Create a hook for our plugin global administration configuration. “admin_menu” – Display the configuration under the “Settings” in the admin panel. “admin_init” – Initialize page with all the new DB parameters.
public function __construct() {
if ( is_admin() ){ // admin actions
add_action( 'admin_menu', 'panda_video_menu' );
add_action( 'admin_init', 'page_init' );
} else {
// non-admin - enqueues, actions, and filters
}
}
public function panda_video_menu() {
add_options_page( 'PandaOS plugin Options', 'PandaOS Video', 'manage_options', 'pandaos_video', 'panda_video_options_page');
}
Initialize the new configuration page. *Use the name you have used in the action hook “admin_init”.
public function 'page_init'()
Register all the settings we need in our plugin using the “register_setting” function inside the “page_init” function.
Repeat this step for every settings parameter that you’ll need in your plugin.
Usage: register_setting( $option_group, $option_name, $sanitize_callback );
Create a settings section for the settings above.
Usage: add_settings_section( $id, $title, $callback, $page )
add_settings_section( 'global_section', 'Setting', "Enter your settings below", 'pandaos_video' );
Add a menu field for each setting we registered (step 7), so we can edit and view it.
Usage: add_settings_field( $id, $title, $callback, $page, $section, $args );
Comments
Post a Comment