Skip to content
Snippets Groups Projects
Commit 70076b7a authored by Dyszczo's avatar Dyszczo
Browse files

Merge branch 'feature/hookable-object' into 'master'

Feature/hookable object

See merge request !7
parents 1318edc3 4cec81f4
No related branches found
No related tags found
1 merge request!7Feature/hookable object
Pipeline #7023 failed
......@@ -8,7 +8,7 @@ namespace WPDesk\PluginBuilder\Plugin;
* @author Grzegorz
*
*/
abstract class AbstractPlugin implements \WPDesk_Translable {
abstract class AbstractPlugin implements \WPDesk_Translable, HookableCollection {
/** @var \WPDesk_Plugin_Info */
protected $plugin_info;
......@@ -25,6 +25,11 @@ abstract class AbstractPlugin implements \WPDesk_Translable {
/** @var string */
protected $settings_url;
/**
* @var array
*/
private $hookable_objects = array();
/**
* AbstractPlugin constructor.
*
......@@ -35,19 +40,33 @@ abstract class AbstractPlugin implements \WPDesk_Translable {
$this->plugin_namespace = strtolower( $plugin_info->get_plugin_dir() );
}
/**
* Init.
*/
public function init() {
$this->init_base_variables();
$this->hooks();
}
public function init_base_variables() {
$this->plugin_url = plugin_dir_url( $this->plugin_info->get_plugin_dir() );
}
/**
* Add hookable object.
*
* @param Hookable|HookablePluginDependant $hookable_object Hookable object.
*/
public function add_hookable( $hookable_object ) {
if ( $hookable_object instanceof HookablePluginDependant ) {
$hookable_object->set_plugin( $this );
}
$this->hookable_objects[] = $hookable_object;
}
/**
* @return void
*/
protected function hooks() {
public function hooks() {
add_action( 'admin_enqueue_scripts', [ $this, 'admin_enqueue_scripts' ] );
add_action( 'wp_enqueue_scripts', [ $this, 'wp_enqueue_scripts' ] );
......@@ -57,6 +76,10 @@ abstract class AbstractPlugin implements \WPDesk_Translable {
$this,
'links_filter'
] );
/** @var Hookable $hookable_object */
foreach ( $this->hookable_objects as $hookable_object ) {
$hookable_object->hooks();
}
}
......
<?php
namespace WPDesk\PluginBuilder\Plugin;
interface Hookable {
/**
* Init hooks (actions and filters).
*
* @return null
*/
public function hooks();
}
<?php
namespace WPDesk\PluginBuilder\Plugin;
interface HookableCollection extends Hookable {
/**
* Add hookable object.
*
* @param Hookable $hookable_object Hookable object to add.
*/
public function add_hookable( $hookable_object );
}
<?php
namespace WPDesk\PluginBuilder\Plugin;
interface HookablePluginDependant extends Hookable {
/**
* Set Plugin.
*
* @param AbstractPlugin $plugin Plugin.
*
* @return null
*/
public function set_plugin( $plugin );
/**
* Get plugin.
*
* @return AbstractPlugin.
*/
public function get_plugin();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment