Skip to content

Instantly share code, notes, and snippets.

@starise
Last active April 28, 2021 09:20
Show Gist options
  • Save starise/0c1432dfc41267b677c7 to your computer and use it in GitHub Desktop.
Save starise/0c1432dfc41267b677c7 to your computer and use it in GitHub Desktop.
WordPress Plugin Skeleton
<?php
/**
* Plugin Name: Plugin Skeleton
* Description: Static Base plugin for WordPress.
* Version: 1.0.0
* Author: starise
* Author URI: http://stari.se
* License: GPL
*/
/**
* Documentation:
* @link http://wpkrauts.com/2013/initialize-a-plugin-with-a-configuration-object/
* @link https://gist.github.com/toscho/3804204
*/
namespace Vendor\Plugins;
add_action( 'plugins_loaded', [ Skeleton::get_instance(), 'init' ] );
class Skeleton
{
/**
* Plugin instance.
*
* @see get_instance()
* @type object
*/
protected static $instance = NULL;
public $plugin_url = '';
public $plugin_path = '';
/**
* Access this plugin’s working instance.
*
* @wp-hook plugins_loaded
* @return object of this class
*/
public static function get_instance()
{
NULL === self::$instance and self::$instance = new self;
return self::$instance;
}
/**
* Used for regular plugin work.
*
* @wp-hook plugins_loaded
* @return void
*/
public function init()
{
$this->plugin_url = plugins_url( '/', __FILE__ );
$this->plugin_path = plugin_dir_path( __FILE__ );
$this->load_language( 'skeleton' );
// more stuff: register actions and filters
}
/**
* Constructor. Intentionally left empty and public.
*
* @see init()
*/
public function __construct() {}
/**
* Loads translation file.
*
* Accessible to other classes to load different language files
* (admin and front-end for example).
*
* @link https://codex.wordpress.org/Function_Reference/load_plugin_textdomain
*
* @wp-hook init
* @param string $domain
* @return void
*/
public function load_language( $domain )
{
load_plugin_textdomain( $domain, FALSE, $this->plugin_path . 'lang' );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment