his->password_manager, 'on_profile_update' ), 10, 2 ); add_action( 'after_password_reset', array( $this->password_manager, 'on_password_reset' ), 10, 1 ); } /** * Register hooks for password strength meter. * * @return void */ public function register_password_strength_meter_hooks(): void { add_action( 'admin_enqueue_scripts', array( $this->password_strength_meter, 'enqueue_jetpack_password_strength_meter_profile_script' ) ); add_action( 'login_enqueue_scripts', array( $this->password_strength_meter, 'enqueue_jetpack_password_strength_meter_reset_script' ) ); add_action( 'wp_ajax_validate_password_ajax', array( $this->password_strength_meter, 'validate_password_ajax' ) ); add_action( 'wp_ajax_nopriv_validate_password_ajax', array( $this->password_strength_meter, 'validate_password_ajax' ) ); } /** * Register hooks for strong passwords. * * @return void */ public function register_strong_passwords_hooks(): void { $this->register_password_manager_hooks(); $this->register_password_strength_meter_hooks(); } /** * Determines if the account protection module is enabled on the site. * * @return bool */ public function is_enabled(): bool { return $this->modules->is_active( self::ACCOUNT_PROTECTION_MODULE_NAME ); } /** * Enables the account protection module. * * @return bool */ public function enable(): bool { // Return true if already enabled. if ( $this->is_enabled() ) { return true; } return $this->modules->activate( self::ACCOUNT_PROTECTION_MODULE_NAME, false, false ); } /** * Disables the account protection module. * * @return bool */ public function disable(): bool { // Return true if already disabled. if ( ! $this->is_enabled() ) { return true; } return $this->modules->deactivate( self::ACCOUNT_PROTECTION_MODULE_NAME ); } /** * Determines if Account Protection is supported in the current environment. * * @return bool */ public function is_supported_environment(): bool { // Do not run when killswitch is enabled if ( defined( 'DISABLE_JETPACK_ACCOUNT_PROTECTION' ) && DISABLE_JETPACK_ACCOUNT_PROTECTION ) { return false; } // Do not run for WordPress.com Simple sites if ( ( new Host() )->is_wpcom_simple() ) { return false; } return true; } /** * Determines if the current Jetpack version is supported. * * @return bool */ public function has_unsupported_jetpack_version(): bool { // Do not run when Jetpack version is less than 14.5 $jetpack_version = Constants::get_constant( 'JETPACK__VERSION' ); if ( $jetpack_version && version_compare( $jetpack_version, '14.5', '<' ) ) { return true; } return false; } /** * Disables the Account Protection module when on an unsupported platform in Jetpack. * * @param array $modules Filterable value for `jetpack_get_available_modules`. * * @return array Array of module slugs. */ public function remove_module_on_unsupported_environments( array $modules ): array { if ( ! $this->is_supported_environment() ) { // Account protection should never be available on unsupported platforms. unset( $modules[ self::ACCOUNT_PROTECTION_MODULE_NAME ] ); } return $modules; } /** * Disables the Account Protection module when on an unsupported platform in a standalone plugin. * * @param array $modules Filterable value for `jetpack_get_available_standalone_modules`. * * @return array Array of module slugs. */ public function remove_standalone_module_on_unsupported_environments( array $modules ): array { if ( ! $this->is_supported_environment() ) { // Account Protection should never be available on unsupported platforms. $modules = array_filter( $modules, function ( $module ) { return $module !== self::ACCOUNT_PROTECTION_MODULE_NAME; } ); } return $modules; } }