refactor: rename Hooks, update docblocks

This commit is contained in:
Ben Goldsworthy 2021-04-16 23:17:07 +01:00
parent 571b6bf74f
commit 3af81c01b9
3 changed files with 30 additions and 72 deletions

View file

@ -1,9 +1,9 @@
<?php // phpcs:disable WordPress.Files.FileName.InvalidClassFileName, WordPress.Security.EscapeOutput.OutputNotEscaped
/**
* Handles all WordPress hooks of this Plugin.
* Hooks class
*
* @filesource
* @package footnotes
* @subpackage WPDashboard
* @since 1.5.0
*/
@ -12,7 +12,7 @@
*
* @since 1.5.0
*/
class MCI_Footnotes_Hooks {
class Hooks {
/**
* Registers all WordPress hooks.
@ -20,13 +20,15 @@ class MCI_Footnotes_Hooks {
* @since 1.5.0
*/
public static function register_hooks() {
register_activation_hook( dirname( __FILE__ ) . '/../footnotes.php', array( 'MCI_Footnotes_Hooks', 'activate_plugin' ) );
register_deactivation_hook( dirname( __FILE__ ) . '/../footnotes.php', array( 'MCI_Footnotes_Hooks', 'deactivate_plugin' ) );
register_uninstall_hook( dirname( __FILE__ ) . '/../footnotes.php', array( 'MCI_Footnotes_Hooks', 'uninstall_plugin' ) );
register_activation_hook( dirname( __FILE__ ) . '/../footnotes.php', array( 'Hooks', 'activate_plugin' ) );
register_deactivation_hook( dirname( __FILE__ ) . '/../footnotes.php', array( 'Hooks', 'deactivate_plugin' ) );
register_uninstall_hook( dirname( __FILE__ ) . '/../footnotes.php', array( 'Hooks', 'uninstall_plugin' ) );
}
/**
* Executed when the Plugin gets activated.
* Executes when the Plugin is activated.
*
* Currently a no-op placeholder.
*
* @since 1.5.0
*/
@ -35,7 +37,9 @@ class MCI_Footnotes_Hooks {
}
/**
* Executed when the Plugin gets deactivated.
* Executes when the Plugin is deactivated.
*
* Currently a no-op placeholder.
*
* @since 1.5.0
*/
@ -44,41 +48,20 @@ class MCI_Footnotes_Hooks {
}
/**
* Executed when the Plugin gets uninstalled.
* Appends the Plugin links for display in the dashboard “Plugins” page.
*
* @since 1.5.0
*
* @since 2.2.0 this function is not called any longer when deleting the plugin.
* Note: clear_all() didn't actually work.
* @see class/settings.php
* @param array $plugin_links The WP-default set of links to display.
* @return string[] The full set of links to display.
*/
public static function uninstall_plugin() {
// WordPress User has to be logged in.
if ( ! is_user_logged_in() ) {
wp_die( __( 'You must be logged in to run this script.', 'footnotes' ) );
}
// WordPress User needs the permission to (un)install plugins.
if ( ! current_user_can( 'install_plugins' ) ) {
wp_die( __( 'You do not have permission to run this script.', 'footnotes' ) );
}
}
/**
* Add Links to the Plugin in the "installed Plugins" page.
*
* @since 1.5.0
* @param array $p_arr_links Current Links.
* @param string $p_str_plugin_file_name Plugins init file name.
* @return array
*/
public static function plugin_links( $p_arr_links, $p_str_plugin_file_name ) {
public static function get_plugin_links( array $plugin_links ): array {
// Append link to the WordPress Plugin page.
$p_arr_links[] = sprintf( '<a href="https://wordpress.org/support/plugin/footnotes" target="_blank">%s</a>', __( 'Support', 'footnotes' ) );
$plugin_links[] = sprintf( '<a href="https://wordpress.org/support/plugin/footnotes" target="_blank">%s</a>', __( 'Support', 'footnotes' ) );
// Append link to the settings page.
$p_arr_links[] = sprintf( '<a href="%s">%s</a>', admin_url( 'options-general.php?page=footnotes' ), __( 'Settings', 'footnotes' ) );
$plugin_links[] = sprintf( '<a href="%s">%s</a>', admin_url( 'options-general.php?page=footnotes' ), __( 'Settings', 'footnotes' ) );
// Append link to the PayPal donate function.
$p_arr_links[] = sprintf( '<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=6Z6CZDW8PPBBJ" target="_blank">%s</a>', __( 'Donate', 'footnotes' ) );
$plugin_links[] = sprintf( '<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=6Z6CZDW8PPBBJ" target="_blank">%s</a>', __( 'Donate', 'footnotes' ) );
// Return new links.
return $p_arr_links;
return $plugin_links;
}
}

View file

@ -1,59 +1,34 @@
<?php // phpcs:disable WordPress.Files.FileName.InvalidClassFileName
/**
* Includes the main Class of the Plugin.
* Footnotes class
*
* @filesource
* @package footnotes
* @since 1.5.0
*
* @since 1.6.5 Bugfix: Improve widgets registration, thanks to @felipelavinz code contribution.
* @since 1.6.5 Update: Fix for deprecated PHP function create_function(), thanks to @psykonevro @daliasued bug reports, thanks to @felipelavinz code contribution.
* @since 2.0.0 Update: Tooltips: fix disabling bug by loading jQuery UI library, thanks to @rajinderverma @ericcorbett2 @honlapdavid @mmallett bug reports, thanks to @vonpiernik code contribution.
*
* @since 2.0.3 add versioning of public.css for cache busting
* @since 2.0.4 add jQuery UI from WordPress
* @since 2.1.4 automate passing version number for cache busting
* @since 2.1.4 optionally enqueue an extra stylesheet
*
* @since 2.5.5 Update: Stylesheets: increase speed and energy efficiency by tailoring stylesheets to the needs of the instance, thanks to @docteurfitness design contribution.
* @since 2.5.5 Bugfix: Stylesheets: minify to shrink the carbon footprint, increase speed and implement best practice, thanks to @docteurfitness issue report.
* @since 2.5.5 Bugfix: Libraries: optimize processes by loading external and internal scripts only if needed, thanks to @docteurfitness issue report.
* @since 2.5.6 Bugfix: Reference container: optional alternative expanding and collapsing without jQuery for use with hard links, thanks to @hopper87it @pkverma99 issue reports.
*/
/**
* Entry point of the Plugin. Loads the Dashboard and executes the Task.
* Provides an entry point to the Plugin.
*
* Loads the dashboard and executes the task.
*
* @since 1.5.0
*/
class MCI_Footnotes {
/**
* Reference to the Plugin Task object.
* The Plugin task.
*
* @since 1.5.0
* @var null|MCI_Footnotes_Task
* @var Task $task The Plugin task.
*/
public $a_obj_task = null;
/**
* Allows to determine whether tooltips are enabled.
* The actual value of these properties is configurable.
*
* - Bugfix: Templates: optimize template load and processing based on settings, thanks to @misfist code contribution.
* Flag for using tooltips.
*
* @since 2.4.0
*
* @contributor Patrizia Lutz @misfist
* @link https://wordpress.org/support/topic/template-override-filter/#post-13864301
* @link https://github.com/misfist/footnotes/releases/tag/2.4.0d3 repository
* @link https://github.com/misfist/footnotes/compare/2.4.0%E2%80%A62.4.0d3 diff
*
* @var bool
*
* Template process and script / stylesheet load optimization.
* Streamline process depending on tooltip enabled status.
* Load tooltip inline script only if jQuery tooltips are enabled.
* @var bool $tooltips_enabled Whether tooltips are enabled or not.
*/
public static $a_bool_tooltips_enabled = false;
@ -134,7 +109,7 @@ class MCI_Footnotes {
// Register Button hooks.
MCI_Footnotes_WYSIWYG::register_hooks();
// Register general hooks.
MCI_Footnotes_Hooks::register_hooks();
Hooks::register_hooks();
// Initialize the Plugin Dashboard.
$this->initialize_dashboard();

View file

@ -109,7 +109,7 @@ require_once dirname( __FILE__ ) . '/includes.php';
// Add Plugin Links to the "installed plugins" page.
$l_str_plugin_file = 'footnotes/footnotes.php';
add_filter( "plugin_action_links_{$l_str_plugin_file}", array( 'MCI_Footnotes_Hooks', 'plugin_links' ), 10, 2 );
add_filter( "plugin_action_links_{$l_str_plugin_file}", array( 'Hooks', 'get_plugin_links' ), 10, 2 );
// Initialize the Plugin.
$g_obj_mci_footnotes = new MCI_Footnotes();