*/ class Admin { /** * The ID of this plugin. * * @since 3.0.0 * @access private * @var string $plugin_name The ID of this plugin. */ private $plugin_name; /** * The version of this plugin. * * @since 3.0.0 * @access private * @var string $version The current version of this plugin. */ private $version; /** * Admin modules of the plugin * * @var array */ private static $modules; /** * Currently active modules * * @var array */ private static $active_modules; /** * Existing modules * * @var array */ public static $existing_modules; /** * Initialize the class and set its properties. * * @since 3.0.0 * @param string $plugin_name The name of this plugin. * @param string $version The version of this plugin. */ public function __construct( $plugin_name, $version ) { $this->plugin_name = $plugin_name; $this->version = $version; self::$modules = $this->get_default_modules(); $this->load(); $this->load_modules(); add_action( 'admin_menu', array( $this, 'admin_menu' ) ); add_action( 'admin_print_scripts', array( $this, 'hide_admin_notices' ) ); // add_filter( 'admin_body_class', array( $this, 'admin_body_classes' ) ); } /** * Load activator on each load. * * @return void */ public function load() { Activator::init(); add_filter( 'plugin_action_links_' . WY_A11Y_PLUGIN_BASENAME, array( $this, 'plugin_action_links' ) ); } /** * Get the default modules array * * @return array */ public function get_default_modules() { $modules = array( 'settings', 'statement', 'auditable_urls', ); return $modules; } /** * Get the active admin modules * * @return void */ public function get_active_modules() { } /** * Load all the modules * * @return void */ public function load_modules() { foreach ( self::$modules as $module ) { $parts = explode( '_', $module ); $class = implode( '_', $parts ); $class_name = 'WebYes\AccessibilityPlus\Lite\\Admin\\Modules\\' . ucfirst( $module ) . '\\' . ucfirst( $class ); if ( class_exists( $class_name ) ) { $module_obj = new $class_name( $module ); if ( $module_obj instanceof $class_name ) { if ( $module_obj->is_active() ) { self::$active_modules[ $module ] = true; } } } } } /** * Register the stylesheets for the admin area. * * @since 3.0.0 */ public function enqueue_styles() { wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'app/dist/assets/react.css', array(), $this->version ); } /** * Register the JavaScript for the admin area. * * @since 3.0.0 */ public function enqueue_scripts() { wp_enqueue_script( $this->plugin_name . '-app', plugin_dir_url( __FILE__ ) . 'app/dist/assets/index.js', array(), $this->version, true ); // Add type="module" attribute to the script tag add_filter( 'script_loader_tag', array( $this, 'add_module_type_attribute' ), 10, 3 ); wp_localize_script( $this->plugin_name . '-app', 'wyA11yGlobals', array( 'api' => array( 'endpoint' => rest_url( 'wya11y/v1/' ), 'nonce' => wp_create_nonce( 'wp_rest' ), ), 'statement' => array( 'page' => get_option( 'wya11y_statement_page' ) ? get_option( 'wya11y_statement_page' ) : '', ), 'adminUrl' => admin_url(), 'version' => defined( 'WY_A11Y_VERSION' ) ? WY_A11Y_VERSION : '', ) ); } /** * Add type="module" attribute to script tag for ES module support * * @param string $tag The script tag. * @param string $handle The script handle. * @param string $src The script src. * @return string Modified script tag. */ public function add_module_type_attribute( $tag, $handle, $src ) { // Only add type="module" to our app script if ( $this->plugin_name . '-app' === $handle ) { $tag = str_replace( '