Adds Hook for registering VueJs plugins instead of Components. #349.
This commit is contained in:
parent
ef0254957e
commit
cfb80d97e9
|
@ -159,6 +159,9 @@ $Tainacan_Admin_Hooks = \Tainacan\Admin_Hooks::get_instance();
|
|||
require_once(__DIR__ . '/../views/class-tainacan-component-hooks.php');
|
||||
$Tainacan_Component_Hooks = \Tainacan\Component_Hooks::get_instance();
|
||||
|
||||
require_once(__DIR__ . '/../views/class-tainacan-plugin-hooks.php');
|
||||
$Tainacan_Plugin_Hooks = \Tainacan\Plugin_Hooks::get_instance();
|
||||
|
||||
require_once(__DIR__ . '/theme-helper/class-tainacan-theme-helper.php');
|
||||
require_once(__DIR__ . '/theme-helper/template-tags.php');
|
||||
$Tainacan_Theme_Helper = \Tainacan\Theme_Helper::get_instance();
|
||||
|
|
|
@ -55,6 +55,12 @@ import eventBusSearch from './event-bus-search';
|
|||
import eventBusTermsList from './event-bus-terms-list.js';
|
||||
import { I18NPlugin, UserPrefsPlugin, RouterHelperPlugin, ConsolePlugin, UserCapabilitiesPlugin, StatusHelperPlugin, CommentsStatusHelperPlugin } from './utilities';
|
||||
|
||||
/* Registers Extra Vue Pluginss passed to the TainacanExtraVuePlugins */
|
||||
if (typeof TainacanExtraVuePlugins != "undefined") {
|
||||
for (let [extraVuePluginName, extraVuePluginObject] of Object.entries(TainacanExtraVuePlugin))
|
||||
Vue.use(extraVuePluginObject);
|
||||
}
|
||||
|
||||
// Configure and Register Plugins
|
||||
Vue.use(Buefy, {
|
||||
defaultTooltipAnimated: true
|
||||
|
|
|
@ -0,0 +1,84 @@
|
|||
<?php
|
||||
|
||||
namespace Tainacan;
|
||||
|
||||
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
|
||||
|
||||
/**
|
||||
* Class Plugins_Hooks
|
||||
*/
|
||||
class Plugin_Hooks {
|
||||
|
||||
private static $instance = null;
|
||||
/**
|
||||
* Stores external vue plugin available to be used in Tainacan
|
||||
*/
|
||||
private $registered_plugin;
|
||||
|
||||
public static function get_instance() {
|
||||
if ( ! isset( self::$instance ) ) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
private function __construct() {
|
||||
$this->registered_plugin = [];
|
||||
$this->init();
|
||||
}
|
||||
|
||||
private function init() {
|
||||
// the priority should see less than on function
|
||||
// `load_admin_page()` of class `Admin` in file /src/views/class-tainacan-admin.php
|
||||
add_action( 'admin_enqueue_scripts', array( &$this, 'register_plugin' ), 80 );
|
||||
do_action('tainacan-register-vuejs-plugin', $this);
|
||||
}
|
||||
|
||||
public function register_plugin() {
|
||||
foreach($this->registered_plugin as $handle => $plugin) {
|
||||
wp_enqueue_script($handle, $plugin['script_path']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a new vuejs plugin
|
||||
*
|
||||
* @param string $handle name of the plugin. Should be unique.
|
||||
* @param string $script_path path of file plugin
|
||||
* @param array|string $args
|
||||
*/
|
||||
public function register_vuejs_plugin($handle, $script_path, $args = []) {
|
||||
global $TAINACAN_EXTRA_SCRIPTS;
|
||||
|
||||
if ( ! in_array( $handle, $this->registered_plugin ) ) {
|
||||
$TAINACAN_EXTRA_SCRIPTS[] = $handle;
|
||||
$this->registered_plugin[$handle] = [
|
||||
'handle' => $handle,
|
||||
'script_path' => $script_path,
|
||||
'args' => $args
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all registered plugin
|
||||
*
|
||||
* @return array The list of registered plugin
|
||||
*/
|
||||
public function get_registered_plugin() {
|
||||
return $this->registered_plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get one specific plugin by its slug
|
||||
*
|
||||
* @param string $handle Name of the plugin
|
||||
*
|
||||
* @return array|false The plugin definition or false if it is not found
|
||||
*/
|
||||
public function get_plugin($handle) {
|
||||
return isset($this->registered_plugin[$handle]) ? $this->registered_plugin[$handle] : false;
|
||||
}
|
||||
|
||||
}
|
|
@ -35,6 +35,12 @@ import routerTheme from './theme-router.js';
|
|||
import eventBusSearch from '../../admin/js/event-bus-search';
|
||||
import { I18NPlugin, UserPrefsPlugin, ConsolePlugin } from '../../admin/js/utilities';
|
||||
|
||||
/* Registers Extra Vue Pluginss passed to the TainacanExtraVuePlugins */
|
||||
if (typeof TainacanExtraVuePlugins != "undefined") {
|
||||
for (let [extraVuePluginName, extraVuePluginObject] of Object.entries(TainacanExtraVuePlugin))
|
||||
Vue.use(extraVuePluginObject);
|
||||
}
|
||||
|
||||
// Configure and Register Plugins
|
||||
Vue.use(Buefy, {
|
||||
defaultTooltipAnimated: true
|
||||
|
|
Loading…
Reference in New Issue