Welcome to ShipWr3ck, where imagination comes to life!
Skip to content

WordPress Plugin Template

Here is a basic template for a WordPress plugin using Object-Oriented Programming:

<?php
/**
 * Plugin Name: Your Plugin Name
 * Plugin URI: Your Plugin URI
 * Description: A brief description of your plugin.
 * Version: 1.0.0
 * Author: Your Name
 * Author URI: Your Author URI
 * Text Domain: your-plugin-text-domain
 * Domain Path: /languages
 *
 * @package Your_Plugin_Name
 */

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

// Define plugin constants
define( 'YOUR_PLUGIN_NAME_VERSION', '1.0.0' );
define( 'YOUR_PLUGIN_NAME_TEXTDOMAIN', 'your-plugin-text-domain' );

// Plugin class
if ( ! class_exists( 'Your_Plugin_Name' ) ) :

    class Your_Plugin_Name {

        /**
         * Constructor.
         */
        public function __construct() {
            // Plugin initialization code here
        }

        /**
         * Plugin activation hook.
         */
        public static function activate() {
            // Activation code here
        }

        /**
         * Plugin deactivation hook.
         */
        public static function deactivate() {
            // Deactivation code here
        }

        /**
         * Plugin uninstall hook.
         */
        public static function uninstall() {
            // Uninstall code here
        }

    }

    // Instantiate the plugin class
    $your_plugin_name = new Your_Plugin_Name();

    // Activation hook
    register_activation_hook( __FILE__, array( 'Your_Plugin_Name', 'activate' ) );

    // Deactivation hook
    register_deactivation_hook( __FILE__, array( 'Your_Plugin_Name', 'deactivate' ) );

    // Uninstall hook
    register_uninstall_hook( __FILE__, array( 'Your_Plugin_Name', 'uninstall' ) );

endif;

This file defines the plugin constants and creates a class called Your_Plugin_Name that contains the plugin initialization code, as well as activation, deactivation, and uninstall hooks.

To create a new plugin, copy the code above and replace Your Plugin Name with your plugin’s name, and Your_Plugin_Name with your plugin’s unique class name. You can then add your plugin’s initialization code to the constructor function of the Your_Plugin_Name class. Remember to also update the plugin description, version, and other details in the plugin header.

Cookie Consent with Real Cookie BannerVisit Codelyfe

Subscribe to Ethical Hacking Tips