boot(); } return self::$instance; } /** * Capability required to see and manage the log. * * @return string */ public static function capability() { /** * Filters the capability needed to use Maintained.log. * * @param string $capability Default 'manage_options'. */ return apply_filters( 'maintained_log_capability', 'manage_options' ); } /** * Whether a user can open and manage Maintained.log: they need the * capability and must be one of the people who maintain the site. * * @param int|null $user_id User ID; the current user by default. * @return bool */ public static function user_can_manage( $user_id = null ) { $user_id = null === $user_id ? get_current_user_id() : (int) $user_id; /** * Filters whether a user can use Maintained.log. * * @param bool $can Capability plus "Who maintains this site". * @param int $user_id User ID. */ return (bool) apply_filters( 'maintained_log_user_can_manage', Settings::is_maintainer( $user_id ), $user_id ); } /** * Registers hooks. */ private function boot() { Installer::maybe_upgrade(); Cron_Status::register(); Rollback::register(); Performance::register(); Public_Report::register(); Vulnerabilities::register(); Client_Widget::register(); Update_Listener::register(); add_action( self::CRON_HOOK, array( __CLASS__, 'run_cron' ) ); add_action( 'init', array( Installer::class, 'ensure_schedule' ) ); add_action( self::POST_UPDATE_HOOK, array( __CLASS__, 'run_post_update' ) ); if ( is_admin() ) { Admin\Admin::register(); } if ( defined( 'WP_CLI' ) && WP_CLI ) { \WP_CLI::add_command( 'maintained-log', __NAMESPACE__ . '\\CLI' ); } } /** * Twice-daily job: catches changes made outside WordPress, alerts and reports. */ public static function run_cron() { Inventory::detect_changes( 'external' ); Alerts::maybe_send_pending_updates_alert(); Backups::maybe_send_reminder(); Tech_Status::refresh(); Vulnerabilities::maybe_schedule(); Performance::maybe_schedule(); Reporter::maybe_send_scheduled(); } /** * Runs the configured checks after an update and alerts on failure. */ public static function run_post_update() { Health_Checks::run( 'post-update' ); } }