Header Ads Widget

Responsive Advertisement

Ticker

6/recent/ticker-posts

Create a Plugin Folder | WP Plugin Development: Class 1

How to Create a Plugin Folder?

Plugin ka folder aur is ki main file ka name same hoga. Like:

Folder: tw-like-dislike

File: tw-like-dislike.php

Index.php file empty hogi.

How to protect plugin?

Plugin file direct access na ho is ke leye ye code likhna pare ga.
Code: defined("ABSPATH") !! die("You can not access this file directly.");

Hooks !!

Wordpress me major 2 qisam ke hooks hote hen.
1.Action hooks
2.Filter hooks.

Hooks aik tarah ke functions hote hen.
Wordpress plugin development me 3 tarah ki hooks hoti hen.
1- register_activation_hook
2- register_deactivation_hook
3- register_uninstall_hook

1. register_activation_hook(__FILE__, "tw-register-activation-hook");
function tw-register-activation-hook(){
    add_option("postTitle", "This is post tiltle");
}

2. register_deactivation_hook(__FILE__, "tw-register-deactivation-hook");
function tw-register-deactivation-hook(){
    delete_option("postTitle");
}

3. register_uninstall_hook(__FILE__, "tw-register-uninstall-hook");
function tw-register-uninstall-hook(){
    delete_option("postTitle");
}

Note: 3rd hook ab use nhi hoti. ab uninstall.php file banai jati hai, us me jo code likha jae ga wo uninstall kartay hue execute hoga.

Action Hooks

Wordpress me 4 type ke Action Hooks hote hen.
1- do_action();
2- add_action();
3- remove_action();
4- has_action();

Filter Hooks

1- apply_filters();
2- add_filter();
3- remove_filter();
4- has_filter():

Note: Action hooks kuch return nhi karaty, filter hooks kuch na kuch return kartay hen true, false ya kuch aur.
Wordpress load hone ke bad pehli hook 'init' load hoti hai.
add_action('init');
















Post a Comment

0 Comments