maybe_upgrade(); if ( false === get_option( Settings::OPTION, false ) ) { add_option( Settings::OPTION, Settings::defaults(), '', false ); } $role = get_role( 'administrator' ); if ( $role instanceof \WP_Role ) { $role->add_cap( Settings::capability() ); } self::install_loader(); if ( ! wp_next_scheduled( 'wpab_cron_tick' ) ) { wp_schedule_event( time() + 60, 'hourly', 'wpab_cron_tick' ); } } /** * Copy the must-use loader into mu-plugins. */ public static function install_loader(): void { $source = WPAB_PATH . 'mu-loader/wpab-runtime-loader.php'; if ( ! is_readable( $source ) ) { return; } if ( ! is_dir( WPMU_PLUGIN_DIR ) ) { wp_mkdir_p( WPMU_PLUGIN_DIR ); } if ( ! self::install_root_map() ) { return; } $target = trailingslashit( WPMU_PLUGIN_DIR ) . 'wpab-runtime-loader.php'; if ( is_readable( $target ) && hash_file( 'sha256', $source ) === hash_file( 'sha256', $target ) ) { return; } if ( ! copy( $source, $target ) ) { \WPAB\Support\Logger::write( 'Unable to install the must-use runtime loader.' ); } } /** * Remember this plugin's real path. The must-use loader lives outside the plugin directory. * * @return bool */ private static function install_root_map(): bool { $root = trailingslashit( wp_normalize_path( WPAB_PATH ) ); $file = wp_normalize_path( WPAB_FILE ); $quote = static function ( string $value ): string { return "'" . str_replace( array( '\\', "'" ), array( '\\\\', "\\'" ), $value ) . "'"; }; $body = "