. * @since 1.0.0 */ namespace APCuManager\Plugin; use APCuManager\System\Environment; use APCuManager\System\Loader; use APCuManager\System\I18n; use APCuManager\System\Assets; use APCuManager\Library\Libraries; use APCuManager\System\Nag; use APCuManager\System\Option; use APCuManager\Plugin\Feature\Capture; /** * 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 * @access protected * @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(); if ( \DecaLog\Engine::isDecalogActivated() && Option::network_get( 'metrics' ) && Environment::exec_mode_for_metrics() ) { Capture::metrics(); } } /** * Register all of the hooks related to the features of the plugin. * * @since 1.0.0 * @access private */ private function define_global_hooks() { add_action( 'cron_schedules', [ 'APCuManager\Plugin\Feature\Capture', 'add_cron_05_minutes_interval' ] ); add_action( 'cron_schedules', [ 'APCuManager\Plugin\Feature\GC', 'add_cron_15_minutes_interval' ] ); $bootstrap = new Initializer(); $assets = new Assets(); $updater = new Updater(); $libraries = new Libraries(); $this->loader->add_filter( 'perfopsone_plugin_info', self::class, 'perfopsone_plugin_info' ); $this->loader->add_action( 'init', $bootstrap, 'initialize' ); $this->loader->add_action( 'init', $bootstrap, 'late_initialize', PHP_INT_MAX ); $this->loader->add_action( 'wp_head', $assets, 'prefetch' ); add_shortcode( 'apcm-changelog', [ $updater, 'sc_get_changelog' ] ); add_shortcode( 'apcm-libraries', [ $libraries, 'sc_get_list' ] ); add_shortcode( 'apcm-statistics', [ 'APCuManager\System\Statistics', 'sc_get_raw' ] ); if ( Option::network_get( 'analytics' ) ) { $this->loader->add_action( APCM_CRON_STATS_NAME, 'APCuManager\Plugin\Feature\Capture', 'check' ); } if ( ! wp_next_scheduled( APCM_CRON_STATS_NAME ) ) { if ( Option::network_get( 'analytics' ) ) { wp_schedule_event( time(), 'five_minutes', APCM_CRON_STATS_NAME ); } } if ( Option::network_get( 'gc' ) ) { $this->loader->add_action( APCM_CRON_GC_NAME, 'APCuManager\Plugin\Feature\GC', 'do' ); } if ( ! wp_next_scheduled( APCM_CRON_GC_NAME ) ) { if ( Option::network_get( 'gc' ) ) { wp_schedule_event( time(), 'fifteen_minutes', APCM_CRON_GC_NAME ); } } } /** * Register all of the hooks related to the admin area functionality * of the plugin. * * @since 1.0.0 * @access private */ private function define_admin_hooks() { $plugin_admin = new Apcu_Manager_Admin(); $nag = new Nag(); $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' ); $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' ); $this->loader->add_action( 'admin_menu', $plugin_admin, 'init_admin_menus' ); $this->loader->add_action( 'admin_menu', $plugin_admin, 'finalize_admin_menus', 100 ); $this->loader->add_action( 'admin_menu', $plugin_admin, 'normalize_admin_menus', 110 ); $this->loader->add_action( 'admin_init', $plugin_admin, 'init_settings_sections' ); $this->loader->add_filter( 'plugin_action_links_' . plugin_basename( APCM_PLUGIN_DIR . APCM_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_apcm_nag', $nag, 'hide_callback' ); $this->loader->add_action( 'wp_ajax_apcm_get_stats', 'APCuManager\Plugin\Feature\AnalyticsFactory', 'get_stats_callback' ); } /** * Register all of the hooks related to the public-facing functionality * of the plugin. * * @since 1.0.0 * @access private */ private function define_public_hooks() { $plugin_public = new Apcu_Manager_Public(); $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' ); $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_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[ APCM_SLUG ] = [ 'name' => APCM_PRODUCT_NAME, 'code' => APCM_CODENAME, 'version' => APCM_VERSION, 'url' => APCM_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.0.0 */ public static function get_base64_logo() { $source = ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; // phpcs:ignore return 'data:image/svg+xml;base64,' . base64_encode( $source ); } }