From 5de6719b9a8c4b656657d79411ff370298abc74c Mon Sep 17 00:00:00 2001 From: Rumperuu Date: Tue, 27 Apr 2021 08:33:28 +0100 Subject: [PATCH] refactor: clean up internal dependency management --- src/admin/class-footnotes-wysiwyg.php | 4 --- .../layout/class-footnotes-layout-engine.php | 2 +- .../layout/class-footnotes-layout-init.php | 36 +++++++++++++++++-- .../class-footnotes-layout-settings.php | 2 +- src/includes/class-footnotes-i18n.php | 2 +- src/includes/class-footnotes-settings.php | 2 +- src/includes/class-footnotes.php | 1 + 7 files changed, 38 insertions(+), 11 deletions(-) diff --git a/src/admin/class-footnotes-wysiwyg.php b/src/admin/class-footnotes-wysiwyg.php index d45ae4d..50b9643 100644 --- a/src/admin/class-footnotes-wysiwyg.php +++ b/src/admin/class-footnotes-wysiwyg.php @@ -8,10 +8,6 @@ * @subpackage footnotes/admin */ -require_once dirname( __FILE__, 2 ) . '/includes/class-footnotes-config.php'; -require_once dirname( __FILE__, 2 ) . '/includes/class-footnotes-settings.php'; -require_once dirname( __FILE__, 2 ) . '/includes/class-footnotes-template.php'; - /** * Handles the WSYIWYG-Buttons. * diff --git a/src/admin/layout/class-footnotes-layout-engine.php b/src/admin/layout/class-footnotes-layout-engine.php index e836201..565bd7e 100644 --- a/src/admin/layout/class-footnotes-layout-engine.php +++ b/src/admin/layout/class-footnotes-layout-engine.php @@ -14,7 +14,7 @@ * @since 2.5.5 Bugfix: Stylesheets: minify to shrink the carbon footprint, increase speed and implement best practice, thanks to @docteurfitness issue report. */ -require_once dirname( __FILE__ ) . '/class-footnotes-layout-init.php'; +require_once plugin_dir_path( dirname( __FILE__ ) ). 'layout/class-footnotes-layout-init.php'; /** * Layout Engine for the administration dashboard. diff --git a/src/admin/layout/class-footnotes-layout-init.php b/src/admin/layout/class-footnotes-layout-init.php index 94150ed..e766075 100644 --- a/src/admin/layout/class-footnotes-layout-init.php +++ b/src/admin/layout/class-footnotes-layout-init.php @@ -8,9 +8,6 @@ * @subpackage footnotes/admin */ -require_once dirname( __FILE__, 3 ) . '/includes/class-footnotes-settings.php'; -require_once dirname( __FILE__ ) . '/class-footnotes-layout-settings.php'; - /** * Handles the Settings interface of the Plugin. * @@ -40,6 +37,8 @@ class Footnotes_Layout_Init { * @since 1.5.0 */ public function __construct() { + $this->load_dependencies(); + $this->settings_page = new Footnotes_Layout_Settings(); // Register hooks/actions. @@ -49,6 +48,37 @@ class Footnotes_Layout_Init { add_action( 'wp_ajax_nopriv_footnotes_get_plugin_info', array( $this, 'get_plugin_meta_information' ) ); add_action( 'wp_ajax_footnotes_get_plugin_info', array( $this, 'get_plugin_meta_information' ) ); } + /** + * Load the required dependencies for this plugin. + * + * Include the following files that make up the plugin: + * + * - `Footnotes_Config`. Defines constant plugin values. + * - `Footnotes_Settings`. Defines configurable plugin settings. + * - `Footnotes_Layout_Settings`. Defines the plugin settings page. + * + * Create an instance of the loader which will be used to register the hooks + * with WordPress. + * + * @since 2.8.0 + * @access private + */ + private function load_dependencies() { + /** + * The class responsible for defining plugin constants. + */ + require_once plugin_dir_path( dirname( __FILE__, 2 ) ) . 'includes/class-footnotes-config.php'; + + /** + * The class responsible for tracking configurable plugin settings. + */ + require_once plugin_dir_path( dirname( __FILE__, 2 ) ) . 'includes/class-footnotes-settings.php'; + + /** + * The class responsible for defining the plugin settings page. + */ + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'layout/class-footnotes-layout-settings.php'; + } /** * Registers the settings and initialises the settings page. diff --git a/src/admin/layout/class-footnotes-layout-settings.php b/src/admin/layout/class-footnotes-layout-settings.php index b606b71..6cc4ce3 100644 --- a/src/admin/layout/class-footnotes-layout-settings.php +++ b/src/admin/layout/class-footnotes-layout-settings.php @@ -41,7 +41,7 @@ * @subpackage footnotes/admin/layout */ -require_once dirname( __FILE__ ) . '/class-footnotes-layout-engine.php'; +require_once plugin_dir_path( dirname( __FILE__ ) ) . 'layout/class-footnotes-layout-engine.php'; /** * Displays and handles all Settings of the Plugin. diff --git a/src/includes/class-footnotes-i18n.php b/src/includes/class-footnotes-i18n.php index 4f15a08..3394ef1 100644 --- a/src/includes/class-footnotes-i18n.php +++ b/src/includes/class-footnotes-i18n.php @@ -12,7 +12,7 @@ * @subpackage footnotes/includes */ -require_once dirname( __FILE__ ) . '/class-footnotes-config.php'; +require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-footnotes-config.php'; /** * Define the internationalization functionality. diff --git a/src/includes/class-footnotes-settings.php b/src/includes/class-footnotes-settings.php index b93f4cb..8d937c2 100644 --- a/src/includes/class-footnotes-settings.php +++ b/src/includes/class-footnotes-settings.php @@ -14,7 +14,7 @@ * @subpackage footnotes/includes */ -require_once dirname( __FILE__ ) . '/class-footnotes-convert.php'; +require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-footnotes-convert.php'; /** * Loads the settings values, sets to default values if undefined. diff --git a/src/includes/class-footnotes.php b/src/includes/class-footnotes.php index e8350e3..4df02cc 100644 --- a/src/includes/class-footnotes.php +++ b/src/includes/class-footnotes.php @@ -117,6 +117,7 @@ class Footnotes { require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-footnotes-config.php'; require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-footnotes-convert.php'; require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-footnotes-settings.php'; + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-footnotes-template.php'; /** * The class responsible for defining all actions that occur in the admin area.