refactor: clear up Plugin init, add activator/deactivator hooks

This commit is contained in:
Ben Goldsworthy 2021-04-26 11:46:30 +01:00
parent 12b1eb556e
commit 0d1e0d75bb
4 changed files with 595 additions and 23 deletions

View file

@ -1,9 +1,15 @@
<?php
/**
* The footnotes WordPress Plugin.
* The plugin bootstrap file.
*
* This file is read by WordPress to generate the plugin information in the plugin
* admin area. This file also includes all of the dependencies used by the plugin,
* registers the activation and deactivation functions, and defines a function
* that starts the plugin.
*
* @package footnotes
* @author Mark Cheret
* @since 1.0.0
* @package footnotes
* @copyright 2021 Mark Cheret (email: mark@cheret.de)
* @license GPL-3.0-only
*
@ -11,7 +17,7 @@
* Plugin Name: footnotes
* Plugin URI: https://wordpress.org/plugins/footnotes/
* Description: footnotes lets you easily add highly-customisable footnotes on your WordPress Pages and Posts.
* Version: 2.7.3
* Version: 2.8.0d
* Requires at least: 3.9
* Requires PHP: 7.0
* Author: Mark Cheret
@ -24,13 +30,15 @@
declare(strict_types=1);
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
/**
* Defines the current Plugin version.
*
* @since 2.1.4
* @var string
* Current plugin version.
*/
const C_STR_FOOTNOTES_VERSION = '2.7.3';
define('C_STR_FOOTNOTES_VERSION', '2.8.0d');
/**
* Defines the current environment ('development' or 'production').
@ -38,25 +46,52 @@ const C_STR_FOOTNOTES_VERSION = '2.7.3';
* This primarily affects whether minified or unminified files are requested.
*
* @since 2.5.5
* @var bool
*/
const PRODUCTION_ENV = false;
define('PRODUCTION_ENV' , false);
/**
* Defines the Plugin entry point (relative to the `wp-content/` dir).
* The code that runs during plugin activation.
* This action is documented in includes/class-plugin-name-activator.php
*/
function activate_footnotes() {
require_once plugin_dir_path( __FILE__ ) . 'includes/class-footnotes-activator.php';
Footnotes_Activator::activate();
}
/**
* The code that runs during plugin deactivation.
* This action is documented in includes/class-plugin-name-deactivator.php
*/
function deactivate_plugin_name() {
require_once plugin_dir_path( __FILE__ ) . 'includes/class-footnotes-deactivator.php';
Footnotes_Deactivator::deactivate();
}
register_activation_hook( __FILE__, 'activate_footnotes' );
register_deactivation_hook( __FILE__, 'deactivate_footnotes' );
/**
* The core plugin class that is used to define internationalization,
* admin-specific hooks, and public-facing site hooks.
*/
require plugin_dir_path( __FILE__ ) . 'includes/class-footnotes.php';
/**
* Begins execution of the plugin.
*
* Since everything within the plugin is registered via hooks,
* then kicking off the plugin from this point in the file does
* not affect the page life cycle.
*
* @since 2.8.0
* @var string
*/
const PLUGIN_ENTRYPOINT = 'footnotes/footnotes.php';
function run_footnotes() {
global $footnotes;
$footnotes = new Footnotes();
$footnotes->run();
// Requires the core Plugin file.
require_once dirname( __FILE__ ) . '/class/init.php';
// Add links to the Installed Plugins page on the WordPress dashboard.
add_filter( 'plugin_action_links_' . PLUGIN_ENTRYPOINT, array( 'Footnotes_Hooks', 'get_plugin_links' ), 10, 2 );
// Initialize the Plugin.
$g_obj_mci_footnotes = new Footnotes();
// Run the Plugin.
$g_obj_mci_footnotes->run();
// Add the links to the dashboard plugins page.
// TODO: Move this somewhere more appropriate.
add_filter( "plugin_action_links_footnotes/footnotes.php", array( 'Footnotes_Hooks', 'get_plugin_links' ), 10, 2 );
}
run_footnotes();