.
* @since 1.0.0
*/
namespace Decalog\Plugin;
use Decalog\System\Loader;
use Decalog\Plugin\Initializer;
use Decalog\System\I18n;
use Decalog\System\Assets;
use Decalog\Library\Libraries;
use Decalog\System\Nag;
use Decalog\Plugin\Feature\LoggerMaintainer;
use Decalog\Listener\ListenerFactory;
use Decalog\Integration\IntegrationsLoader;
use Decalog\LoggerRoute;
use Decalog\MonitorRoute;
/**
* The core plugin class.
*
* This is used to define internationalization, admin-specific hooks, and
* public-facing site hooks.
*
* @package Plugin
* @author Pierre Lannoy .
* @since 1.0.0
*/
class Core {
/**
* The loader that's responsible for maintaining and registering all hooks that power
* the plugin.
*
* @since 1.0.0
* @var Loader $loader Maintains and registers all hooks for the plugin.
*/
protected $loader;
/**
* Define the core functionality of the plugin.
*
* Load the dependencies, define the locale, and set the hooks for the admin area and
* the public-facing side of the site.
*
* @since 1.0.0
*/
public function __construct() {
$this->loader = new Loader();
$this->define_global_hooks();
$this->define_admin_hooks();
$this->define_public_hooks();
}
/**
* Register all of the hooks related to the features of the plugin.
*
* @since 1.0.0
*/
private function define_global_hooks() {
$bootstrap = new Initializer();
$assets = new Assets();
$updater = new Updater();
$libraries = new Libraries();
$listeners = new ListenerFactory();
$this->loader->add_filter( 'perfopsone_plugin_info', self::class, 'perfopsone_plugin_info' );
$this->loader->add_action( 'init', $bootstrap, 'initialize', 0 );
$this->loader->add_action( 'init', $bootstrap, 'late_initialize', PHP_INT_MAX );
$this->loader->add_action( 'plugins_loaded', $listeners, 'launch', PHP_INT_MIN );
$this->loader->add_action( 'plugins_loaded', $listeners, 'launch_late_init', PHP_INT_MAX );
$this->loader->add_action( 'wp_head', $assets, 'prefetch' );
add_shortcode( 'decalog-changelog', [ $updater, 'sc_get_changelog' ] );
add_shortcode( 'decalog-libraries', [ $libraries, 'sc_get_list' ] );
add_shortcode( 'decalog-statistics', [ 'Decalog\System\Statistics', 'sc_get_raw' ] );
add_shortcode( 'decalog-help-logging', [ 'Decalog\Plugin\Feature\InlineHelp', 'sc_get_logging' ] );
add_shortcode( 'decalog-help-monitoring', [ 'Decalog\Plugin\Feature\InlineHelp', 'sc_get_monitoring' ] );
add_shortcode( 'decalog-help-tracing', [ 'Decalog\Plugin\Feature\InlineHelp', 'sc_get_tracing' ] );
if ( ! wp_next_scheduled( DECALOG_CRON_NAME ) ) {
wp_schedule_event( time(), 'hourly', DECALOG_CRON_NAME );
}
$maintainer = new LoggerMaintainer();
$this->loader->add_action( DECALOG_CRON_NAME, $maintainer, 'cron_clean' );
$integrations_loader = new IntegrationsLoader();
$integrations_loader->load_psr3();
// REST API
$this->loader->add_action( 'rest_api_init', new LoggerRoute(), 'register_routes' );
$this->loader->add_action( 'rest_api_init', new MonitorRoute(), 'register_routes' );
}
/**
* Register all of the hooks related to the admin area functionality
* of the plugin.
*
* @since 1.0.0
*/
private function define_admin_hooks() {
$plugin_admin = new Decalog_Admin();
$nag = new Nag();
$this->loader->add_action( 'init', $plugin_admin, 'disable_wp_emojis', PHP_INT_MAX );
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'register_styles' );
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'register_scripts' );
$this->loader->add_action( 'admin_menu', $plugin_admin, 'init_admin_menus' );
$this->loader->add_action( 'admin_init', $plugin_admin, 'init_settings_sections' );
$this->loader->add_filter( 'plugin_action_links_' . plugin_basename( DECALOG_PLUGIN_DIR . DECALOG_SLUG . '.php' ), $plugin_admin, 'add_actions_links', 10, 4 );
$this->loader->add_filter( 'plugin_row_meta', $plugin_admin, 'add_row_meta', 10, 2 );
$this->loader->add_action( 'admin_notices', $nag, 'display' );
$this->loader->add_action( 'wp_ajax_hide_decalog_nag', $nag, 'hide_callback' );
$this->loader->add_filter( 'myblogs_blog_actions', $plugin_admin, 'blog_action', 10, 2 );
$this->loader->add_filter( 'manage_sites_action_links', $plugin_admin, 'site_action', 10, 3 );
add_shortcode( 'decalog-selfreg', [ 'Decalog\Plugin\Feature\SDK', 'sc_get_selfreg' ] );
}
/**
* Register all of the hooks related to the public-facing functionality
* of the plugin.
*
* @since 1.0.0
*/
private function define_public_hooks() {
$plugin_public = new Decalog_Public();
$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'register_styles' );
$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'register_scripts' );
}
/**
* Run the loader to execute all of the hooks with WordPress.
*
* @since 1.0.0
*/
public function run() {
$this->loader->run();
}
/**
* The reference to the class that orchestrates the hooks with the plugin.
*
* @since 1.0.0
* @return Loader Orchestrates the hooks of the plugin.
*/
public function get_loader() {
return $this->loader;
}
/**
* Adds full plugin identification.
*
* @param array $plugin The already set identification information.
* @return array The extended identification information.
* @since 1.0.0
*/
public static function perfopsone_plugin_info( $plugin ) {
$plugin[ DECALOG_SLUG ] = [
'name' => DECALOG_PRODUCT_NAME,
'code' => DECALOG_CODENAME,
'version' => DECALOG_VERSION,
'url' => DECALOG_PRODUCT_URL,
'icon' => self::get_base64_logo(),
];
return $plugin;
}
/**
* Returns a base64 svg resource for the plugin logo.
*
* @return string The svg resource as a base64.
* @since 1.5.0
*/
public static function get_base64_logo() {
$source = '';
// phpcs:ignore
return 'data:image/svg+xml;base64,' . base64_encode( $source );
}
}