Excellent Programming Tricks

WordPress Plugin Development Essentials


  1. Why plugin?
    1. Plugin is portable and independent for specific functionality.
    2. The plugin has no issue after theme update.
  2. Fundamentals
    1. Customize wp-config.php [Not mandatory if required]
      1. define('WP_DEBUG', false); -> define('WP_DEBUG', true);
    2. index.php file isn't mandatory.  
    3. Folder Structure
      1. Plugin folder name should be unique. Like iftekhar.
      2. Inside iftekhar (plugin folder) folder create folder_name.php(iftekhar.php).
      3. Create index.php empty with single comment.
    4. Class
      1. Unique name for class.
  3. Plugin has three basic behavioral options
    1. Activation
      1. generate a CPT
      2. Flush rewrite rules
      3. register_activation_hook( __FILE__, array( $excellentPT, 'activate' ) );
    2. Deactivation
      1. Flush rewrite rules
      2. register_deactivation_hook( __FILE__, array( $excellentPT, 'deactivate' ) );
    3. Uninstall
      1. Delete CPT
      2. Delete all the plugin data form the db
      3. Limitation of uninstall hook -> Only a static method or function can be used in an uninstall hook.
      4. uninstall.php [Predefined file inside plugin folder]
  4. Path
    1. __FILE__ Global predefined location that PHP uses. 
    2. plugins_url( '/assets/p_script.js', __FILE__ );
    3. require_once plugin_dir_path(__FILE__).'inc/abc.php';
    4. plugin_basename( __FILE__ );
  5. Shortcode
    1. Initialization isn't required inside functions.php
    2. Except functions.php initialization is required.  
  6. Check Everything ok or prevent direct page access (required).
    1. if ( ! defined( 'ABSPATH' ) ) { die;} or defined( 'ABSPATH' ) or die('text');
  7. Plugin enqueue
    1. function enqueue() {
        wp_enqueue_style( 'pluginstyle', plugins_url( '/assets/p_style.css', __FILE__ ) );
        wp_enqueue_script( 'pluginscript', plugins_url( '/assets/p_script.js', __FILE__ ) );
       }
  8. Add Menu //Inside the class
    1. function register(){add_action, array($this, 'add_admin_menus');}
    2. public function add_admin_menus(){ add_menu_page( 'Iftekhar Plugin', 'Menu Title', 'manage_options', 'my_plugin', array($this, 'admin_index'), 'dashicons-nametag', 110 );}
    3. public function admin_index(){require_once plugin_dir_path( __FILE__ ) . 'templates/admin.php';}
  9. Add Link on installed plugin
    1. public $plugin;
    2. function __construct(){
         $this->plugin = plugin_basename( __FILE__ );
        }
    3. function myFun(){add_filter( "plugin_action_links_$this->plugin", array( $this, 'settings_link' ) );}
    4. public function settings_link( $links ) {
         $settings_link = '<a href="admin.php?page=my_plugin">Settings</a>';
         array_push( $links, $settings_link );
         return $links;
        }













No comments:

Post a Comment


Authentic аnd Excellent

Website

HTML Template

Wordpress Theme

Database applications

OR

Application services?

Excellent Programming Tricks (EPT) || Iftekhar-IT || We develops the Web applications and the WordPress templates. || Excellent Programming Tricks (EPT)

© 2020 Blogger Theme by Iftekhar IT || Excellent Programming Tricks

Execllent Programming Tricks. Powered by Blogger.