Created
May 21, 2020 16:08
-
-
Save evanfraser/735a056ee9582089fdaea16da807656e to your computer and use it in GitHub Desktop.
Squadbox plugin blank template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: PLUGIN_NAME_HERE | |
* Plugin URI: PLUGIN_URI_HERE | |
* Description: PLUGIN_DESC_HERE | |
* Version: 0.0.1 | |
* Author: AUTHOR_HERE | |
* Author URI: AUTHOR_URI_HERE | |
* Text Domain: TEXT_DOMAIN_HERE | |
*/ | |
if (!defined('ABSPATH')) exit(); | |
define('SQUADBOX_PLUGIN_PATH', plugin_dir_path(__FILE__)); | |
define('SQUADBOX_PLUGIN_URL', plugin_dir_url(__FILE__)); | |
if (!class_exists('YourCoolClass')): | |
class YourCoolClass { | |
public static $plugin = array( | |
'name' => 'PLUGIN_NAME_HERE', | |
'version' => '0.0.1', | |
'file' => __FILE__, | |
'option_prefix' => 'acf_option_prefix_', | |
'block_prefix' => 'acf_block_prefix_', | |
); | |
/** | |
* Constructor. | |
*/ | |
public function setup() { | |
add_action('plugins_loaded', array($this, 'includes')); | |
} | |
/** | |
* Includes | |
*/ | |
public function includes() { | |
// Return null if Squadbox is not active. | |
if (!class_exists('Squadbox')) { | |
add_action('admin_notices', array($this, 'squadbox_notice')); | |
return null; | |
} | |
// Return if php version is below 5.5.0 or whatever version you require | |
if (version_compare('5.5.0', PHP_VERSION, '>') && current_user_can('activate_plugins')) { | |
add_action('admin_notices', array($this, 'php_version_notice')); | |
return; | |
} | |
// Include license if your plugin says so | |
if (Squadbox::$plugin['include_license'] !== false) { | |
require_once(SQUADBOX_LOCATION_PATH.'license/class-squadbox-location-plugin-license.php'); | |
} | |
// Includes | |
include_once(SQUADBOX_LOCATION_PATH.'inc/your-other-magic-files.php'); | |
} | |
/** | |
* Display an error notice if Squadbox is not active. | |
*/ | |
public function squadbox_notice() { | |
printf('<div class="error"><p>'.__('<strong>Squadbox</strong> is deactivated or does not exist. Please install and activate it to use <strong>'.self::$plugin['name'].'</strong>', 'squadbox').'</p></div>', PHP_VERSION); | |
} | |
/** | |
* Display an error notice if the PHP version is lower than your requirement | |
*/ | |
public function php_version_notice() { | |
printf('<div class="error"><p>'.__(self::$plugin['name'].' requires PHP version 5.5.0 or higher. Your server is running PHP version %s. Please contact your hosting company to upgrade your site to 5.5.0 or later.', 'squadbox').'</p></div>', PHP_VERSION); | |
} | |
} | |
/** | |
* Return YourCoolClass class instance. | |
*/ | |
function your_cool_class() { | |
global $your_cool_class; | |
// Instantiate only once. | |
if (!isset($your_cool_class)) { | |
$your_cool_class = new YourCoolClass(); | |
$your_cool_class->setup(); | |
} | |
return $your_cool_class; | |
} | |
// Instantiate. | |
your_cool_class(); | |
endif; // class_exists check |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment