WordPress Plugging

Page 1

Wordpress Plugging

Wodpress Plugging Creation Step 1: • • •

Create folder into wp-content/plugins folder Create php file into folder keep plugging folder name and main file name same. Add below code in to the php file : /* Plugin Name: pluging name Plugin URI: http://www.abc.net Description: Plugin description Author: vipul Version: 1.0 Author URI: http://www.abc.net */

• •

Now check in admin plugging, its showing plugging name in to plugging list. Now make it active

Step 2: 1. When Plugging active that time this function called register_activation_hook($file, function); example: register_activation_hook(__FILE__, ‘activation_action’); function activation_action () { /* write code here */ }

Prepared By: Vipul Patel

1


Wordpress Plugging

2. When plugging deactivate register_ deactivation_hook($file, function); example: register_deactivation_hook(__FILE__, ‘deactivation_action’); function deactivation_action () { /* write code here */ }

3. Pluggable hook action (replace keyword with html) add_filter('the_content', ‘function’); example: add_filter('the_content', ‘filter_content’); function filter_content() { $content = preg_replace_callback(‘/\[KEYWORD]/i, abc, $content); return $content; } Function abc() { /* write code here */ } 4. Add javascripts and stylesheets Note: common function to add javascript and css add_action('wp_enqueue_scripts', 'add_my_js_css’); function add_my_js_css() { Prepared By: Vipul Patel

2


Wordpress Plugging

//CSS $myStyleUrl = plugins_url('style.css', __FILE__); $myStyleFile =dirname(__FILE__). 'style.css'; if(file_exists($myStyleFile) ) { wp_register_style('myStyleSheets', $myStyleUrl); wp_enqueue_style( 'myStyleSheets'); } //JAVASCRIPT $myScriptUrl = plugins_url('script.js’, __FILE__); $myScriptFile =dirname(__FILE__). ‘script.js'; if(file_exists($myScriptFile) ) { wp_register_script('myScript', $myStyleUrl); wp_enqueue_script('myScript'); } } 5. Action to add menu into admin add_action('admin_menu', ‘admin_menu_plugin'); function admin_menu_plugin() { //add main menu add_menu_page('Main menu', 'Main menu', 'administrator','main-menu-page-name'); //add submenu add_submenu_page('main-menu-page-name', 'Sub Menu', 'Sub Menu', 'administrator','sub-menu-pagename',function); }

6. Admin initialize action add_action('admin_init', 'add_my_stylesheet');

Prepared By: Vipul Patel

3


Wordpress Plugging

7. File Upload wp_handle_upload($file, $overrides, $time); example : $overrides = array('test_form' => false); $filePath = wp_handle_upload($_FILES[$key],$overrides); 8. File Resize File: wp-includes/media.php image_resize( $file, $max_w, $max_h, $crop = false, $suffix = null, $dest_path = null, $jpeg_quality = 90 )

Prepared By: Vipul Patel

4


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.