refactor: refactor widget registration

This commit is contained in:
Ben Goldsworthy 2021-04-27 09:31:08 +01:00
parent 51f3f92c26
commit 850ab084ff
3 changed files with 25 additions and 19 deletions

View file

@ -77,19 +77,6 @@ class Footnotes_Loader {
$this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args ); $this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args );
} }
/**
* Initializes all Widgets of the Plugin.
*
* @since 1.5.0
* @since 2.8.0 Moved to `Footnotes_Loader` class.
*/
public function initialize_widgets() {
// TODO: This probably shouldn't be necessary here.
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/widget/class-footnotes-widget-reference-container.php';
register_widget( 'Footnotes_Widget_Reference_Container' );
}
/** /**
* A utility function that is used to register the actions and hooks into a single * A utility function that is used to register the actions and hooks into a single
* collection. * collection.
@ -133,8 +120,6 @@ class Footnotes_Loader {
add_action( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] ); add_action( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
} }
add_action( 'widgets_init', array( $this, 'initialize_widgets' ) );
} }
} }

View file

@ -194,6 +194,8 @@ class Footnotes {
$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' ); $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' );
$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' ); $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' );
$this->loader->add_action( 'widgets_init', $plugin_public, 'register_widgets' );
} }
/** /**

View file

@ -38,11 +38,19 @@ class Footnotes_Public {
private $version; private $version;
/** /**
* The Plugin task. * The reference container widget.
*
* @since 2.8.0
* @var Footnotes_Widget_Reference_Container $reference_container_widget The reference container widget
*/
private $reference_container_widget;
/**
* The footnote parser.
* *
* @since 1.5.0 * @since 1.5.0
* @since 2.8.0 Moved from `Footnotes` to `Footnotes_Public` class. * @since 2.8.0 Moved from `Footnotes` to `Footnotes_Public` class.
* @var Task $task The Plugin task. * @var Footnote_Parser $task The Plugin task.
*/ */
public $a_obj_task = null; public $a_obj_task = null;
@ -123,7 +131,9 @@ class Footnotes_Public {
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-footnotes-convert.php'; require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-footnotes-convert.php';
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-footnotes-parser.php'; require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-footnotes-parser.php';
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/widget/class-footnotes-widget-base.php'; require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/widget/class-footnotes-widget-reference-container.php';
$this->reference_container_widget = new Footnotes_Widget_Reference_Container($this->plugin_name);
$this->a_obj_task = new Footnotes_Parser(); $this->a_obj_task = new Footnotes_Parser();
} }
@ -252,5 +262,14 @@ class Footnotes_Public {
} }
/**
* Register the widget(s) for the public-facing side of the site.
*
* @since 1.5.0
* @since 2.8.0 Moved to `Footnotes_Public` class.
*/
public function register_widgets() {
register_widget( $this->reference_container_widget );
}
} }