am = new AUC_Maintenance(); $this->an = new AUC_Notification(); $this->lm = new AUC_Login_Monitor(); $this->version = get_file_data( __FILE__, [ 'v' => 'Version' ] )['v']; } public function run() { register_activation_hook( __FILE__, [ $this, 'activate_plugin' ] ); register_deactivation_hook( __FILE__, [ $this, 'deactivate_plugin' ] ); add_action( 'admin_enqueue_scripts', [ $this, 'enqueue' ] ); add_action( 'plugins_loaded', [ $this, 'load_acf_lite' ] ); add_action( 'plugins_loaded', [ $this, 'load_text_domain' ] ); add_action( 'wp_ajax_admin-user-control', [ $this, 'create_response' ] ); $this->am->run(); $this->an->run(); $this->lm->run(); } public function activate_plugin() { update_option( 'admin-user-control_version', $this->version ); $this->am->add_maintenance_capabilities(); $this->an->add_notification_capabilities(); } public function deactivate_plugin() { delete_option( 'admin-user-control_version' ); } public function enqueue() { $ext = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; if ( is_admin_bar_showing() ) { wp_enqueue_style( 'login-monitor', plugin_dir_url( __FILE__ ) . "css/login-monitor{$ext}.css", [], $this->version ); } wp_enqueue_style( 'admin-notification', plugin_dir_url( __FILE__ ) . "css/admin-notification{$ext}.css", [], $this->version ); wp_enqueue_style( 'admin-maintenance', plugin_dir_url( __FILE__ ) . "css/admin-maintenance{$ext}.css", [], $this->version ); $capability = apply_filters( 'change_auc_capability', 'edit_posts' ); if ( is_user_logged_in() && current_user_can( $capability ) ) { wp_enqueue_script( 'admin-user-control', plugin_dir_url( __FILE__ ) . "js/admin-user-control{$ext}.js", [], null, true ); $lifetime = apply_filters( 'change_auc_lifetime', self::LIFETIME ); $script = 'var ADMIN_USER_CONTROL_CONST = ' . json_encode( [ 'url' => admin_url( 'admin-ajax.php' ), 'action' => 'admin-user-control', 'readNotificationAction' => 'admin-notification-read', 'lifetime' => $lifetime, ] ) . ';'; wp_add_inline_script( 'admin-user-control', $script, 'before' ); } } public function load_acf_lite() { if ( ! defined( 'ACF_LITE' ) ) { define( 'ACF_LITE', true ); } if ( ! class_exists( 'Acf' ) ) { include_once( plugin_dir_path( __FILE__ ) . 'includes/acf/acf.php' ); } } public function load_text_domain() { load_plugin_textdomain( 'admin-user-control', false, basename( __DIR__ ) . '/languages' ); } public function create_response() { $response = []; $response = array_merge( $response, $this->lm->create_response( apply_filters( 'change_auc_lifetime', self::LIFETIME ) ) ); $response = array_merge( $response, $this->an->create_response() ); $response = array_merge( $response, $this->am->create_response() ); wp_send_json( $response ); } } if ( ! function_exists( 'auc_is_login_page' ) ) { function auc_is_login_page() { if ( in_array( $GLOBALS['pagenow'], [ 'wp-login.php', 'wp-register.php' ] ) ) { return true; } else { return false; } } } if ( is_admin() || auc_is_login_page() ) { global $auc; $auc = new Admin_User_Control(); $auc->run(); }