*/ public static function defaults(): array { return [ self::DEFAULT_BOARD => 0, self::DEFAULT_STATUS => 0, self::DELETE_DATA_ON_UNINSTALL => false, self::NOTIFY_NEW_REQUESTS => true, self::NOTIFY_EMAILS => '', self::DATA_USE_NOTE => '', self::NOTIFY_FOLLOWERS => true, self::SUBSCRIBE_VOTERS => true, self::VOTES_PER_ADDRESS_USERS => 60, self::VOTES_PER_ADDRESS_GUESTS => 60, ]; } /** * Returns one setting, or its default when it was never saved. * * @param string $key Setting key, one of this class's constants. * @return mixed */ public static function get( string $key ) { $settings = array_merge( self::defaults(), self::stored() ); return $settings[ $key ] ?? null; } /** * Returns how many votes an hour can come from one IP address: from its logged-in * users, or from its visitors without an account. * * A stored number below 1 would refuse every vote, so the default takes its place. * * @param bool $logged_in Whether to return the limit for logged-in users. */ public static function votes_per_address( bool $logged_in ): int { $key = $logged_in ? self::VOTES_PER_ADDRESS_USERS : self::VOTES_PER_ADDRESS_GUESTS; $limit = (int) self::get( $key ); return $limit >= 1 ? $limit : (int) self::defaults()[ $key ]; } /** * Saves one setting. * * @param string $key Setting key, one of this class's constants. * @param mixed $value New value. */ public static function update( string $key, $value ): void { $settings = self::stored(); $settings[ $key ] = $value; update_option( self::OPTION, $settings ); } /** * Returns the saved settings. * * @return array */ private static function stored(): array { $stored = get_option( self::OPTION, [] ); return is_array( $stored ) ? $stored : []; } }