| Current File : /home/digitaw/www/wp-content/updraft/plugins-old/simple-history/dropins/class-react-dropin.php |
<?php
namespace Simple_History\Dropins;
use Simple_History\Helpers;
/**
* Loads the new GUI based on React.
*/
class React_Dropin extends Dropin {
/** @inheritdoc */
public function loaded() {
add_action( 'simple_history/history_page/gui_wrap_top', [ $this, 'output_element_page' ], 1 );
add_action( 'simple_history/dashboard/before_gui', [ $this, 'output_element_dashboard' ], 1 );
add_action( 'simple_history/enqueue_admin_scripts', [ $this, 'enqueue_admin_scripts' ] );
}
/**
* Enqueue scripts generated by wp-scripts.
*/
public function enqueue_admin_scripts() {
// Bail if not a Simple History page so no unneeded scripts are loaded.
if ( ! Helpers::is_on_our_own_pages() ) {
return;
}
$asset_file = include SIMPLE_HISTORY_PATH . 'build/index.asset.php';
// Load the WP components CSS or some components will be unstyled.
wp_enqueue_style( 'wp-components' );
wp_register_script(
'simple_history_wp_scripts',
SIMPLE_HISTORY_DIR_URL . 'build/index.js',
$asset_file['dependencies'],
$asset_file['version'],
true
);
wp_enqueue_script( 'simple_history_wp_scripts' );
wp_set_script_translations( 'simple_history_wp_scripts', 'simple-history' );
}
/**
* Output HTML element on the history page for React to mount on.
*/
public function output_element_page() {
?>
<div id="simple-history-react-root" class="SimpleHistoryReactRoot is-page">Loading</div>
<?php
}
/**
* Output HTML element on the dashboard for React to mount on.
*/
public function output_element_dashboard() {
?>
<div id="simple-history-react-root" class="SimpleHistoryReactRoot is-dashboard">Loading</div>
<?php
}
}