Edit File by line
/home/barbar84/www/wp-inclu...
File: formatting.php
[3500] Fix | Delete
// Test for invalid characters.
[3501] Fix | Delete
if ( ! preg_match( '/^[a-z0-9-]+$/i', $sub ) ) {
[3502] Fix | Delete
/** This filter is documented in wp-includes/formatting.php */
[3503] Fix | Delete
return apply_filters( 'is_email', false, $email, 'sub_invalid_chars' );
[3504] Fix | Delete
}
[3505] Fix | Delete
}
[3506] Fix | Delete
[3507] Fix | Delete
// Congratulations, your email made it!
[3508] Fix | Delete
/** This filter is documented in wp-includes/formatting.php */
[3509] Fix | Delete
return apply_filters( 'is_email', $email, $email, null );
[3510] Fix | Delete
}
[3511] Fix | Delete
[3512] Fix | Delete
/**
[3513] Fix | Delete
* Convert to ASCII from email subjects.
[3514] Fix | Delete
*
[3515] Fix | Delete
* @since 1.2.0
[3516] Fix | Delete
*
[3517] Fix | Delete
* @param string $string Subject line
[3518] Fix | Delete
* @return string Converted string to ASCII
[3519] Fix | Delete
*/
[3520] Fix | Delete
function wp_iso_descrambler( $string ) {
[3521] Fix | Delete
/* this may only work with iso-8859-1, I'm afraid */
[3522] Fix | Delete
if ( ! preg_match( '#\=\?(.+)\?Q\?(.+)\?\=#i', $string, $matches ) ) {
[3523] Fix | Delete
return $string;
[3524] Fix | Delete
} else {
[3525] Fix | Delete
$subject = str_replace( '_', ' ', $matches[2] );
[3526] Fix | Delete
return preg_replace_callback( '#\=([0-9a-f]{2})#i', '_wp_iso_convert', $subject );
[3527] Fix | Delete
}
[3528] Fix | Delete
}
[3529] Fix | Delete
[3530] Fix | Delete
/**
[3531] Fix | Delete
* Helper function to convert hex encoded chars to ASCII
[3532] Fix | Delete
*
[3533] Fix | Delete
* @since 3.1.0
[3534] Fix | Delete
* @access private
[3535] Fix | Delete
*
[3536] Fix | Delete
* @param array $match The preg_replace_callback matches array
[3537] Fix | Delete
* @return string Converted chars
[3538] Fix | Delete
*/
[3539] Fix | Delete
function _wp_iso_convert( $match ) {
[3540] Fix | Delete
return chr( hexdec( strtolower( $match[1] ) ) );
[3541] Fix | Delete
}
[3542] Fix | Delete
[3543] Fix | Delete
/**
[3544] Fix | Delete
* Given a date in the timezone of the site, returns that date in UTC.
[3545] Fix | Delete
*
[3546] Fix | Delete
* Requires and returns a date in the Y-m-d H:i:s format.
[3547] Fix | Delete
* Return format can be overridden using the $format parameter.
[3548] Fix | Delete
*
[3549] Fix | Delete
* @since 1.2.0
[3550] Fix | Delete
*
[3551] Fix | Delete
* @param string $string The date to be converted, in the timezone of the site.
[3552] Fix | Delete
* @param string $format The format string for the returned date. Default 'Y-m-d H:i:s'.
[3553] Fix | Delete
* @return string Formatted version of the date, in UTC.
[3554] Fix | Delete
*/
[3555] Fix | Delete
function get_gmt_from_date( $string, $format = 'Y-m-d H:i:s' ) {
[3556] Fix | Delete
$datetime = date_create( $string, wp_timezone() );
[3557] Fix | Delete
[3558] Fix | Delete
if ( false === $datetime ) {
[3559] Fix | Delete
return gmdate( $format, 0 );
[3560] Fix | Delete
}
[3561] Fix | Delete
[3562] Fix | Delete
return $datetime->setTimezone( new DateTimeZone( 'UTC' ) )->format( $format );
[3563] Fix | Delete
}
[3564] Fix | Delete
[3565] Fix | Delete
/**
[3566] Fix | Delete
* Given a date in UTC or GMT timezone, returns that date in the timezone of the site.
[3567] Fix | Delete
*
[3568] Fix | Delete
* Requires and returns a date in the Y-m-d H:i:s format.
[3569] Fix | Delete
* Return format can be overridden using the $format parameter.
[3570] Fix | Delete
*
[3571] Fix | Delete
* @since 1.2.0
[3572] Fix | Delete
*
[3573] Fix | Delete
* @param string $string The date to be converted, in UTC or GMT timezone.
[3574] Fix | Delete
* @param string $format The format string for the returned date. Default 'Y-m-d H:i:s'.
[3575] Fix | Delete
* @return string Formatted version of the date, in the site's timezone.
[3576] Fix | Delete
*/
[3577] Fix | Delete
function get_date_from_gmt( $string, $format = 'Y-m-d H:i:s' ) {
[3578] Fix | Delete
$datetime = date_create( $string, new DateTimeZone( 'UTC' ) );
[3579] Fix | Delete
[3580] Fix | Delete
if ( false === $datetime ) {
[3581] Fix | Delete
return gmdate( $format, 0 );
[3582] Fix | Delete
}
[3583] Fix | Delete
[3584] Fix | Delete
return $datetime->setTimezone( wp_timezone() )->format( $format );
[3585] Fix | Delete
}
[3586] Fix | Delete
[3587] Fix | Delete
/**
[3588] Fix | Delete
* Given an ISO 8601 timezone, returns its UTC offset in seconds.
[3589] Fix | Delete
*
[3590] Fix | Delete
* @since 1.5.0
[3591] Fix | Delete
*
[3592] Fix | Delete
* @param string $timezone Either 'Z' for 0 offset or '±hhmm'.
[3593] Fix | Delete
* @return int|float The offset in seconds.
[3594] Fix | Delete
*/
[3595] Fix | Delete
function iso8601_timezone_to_offset( $timezone ) {
[3596] Fix | Delete
// $timezone is either 'Z' or '[+|-]hhmm'.
[3597] Fix | Delete
if ( 'Z' === $timezone ) {
[3598] Fix | Delete
$offset = 0;
[3599] Fix | Delete
} else {
[3600] Fix | Delete
$sign = ( '+' === substr( $timezone, 0, 1 ) ) ? 1 : -1;
[3601] Fix | Delete
$hours = (int) substr( $timezone, 1, 2 );
[3602] Fix | Delete
$minutes = (int) substr( $timezone, 3, 4 ) / 60;
[3603] Fix | Delete
$offset = $sign * HOUR_IN_SECONDS * ( $hours + $minutes );
[3604] Fix | Delete
}
[3605] Fix | Delete
return $offset;
[3606] Fix | Delete
}
[3607] Fix | Delete
[3608] Fix | Delete
/**
[3609] Fix | Delete
* Given an ISO 8601 (Ymd\TH:i:sO) date, returns a MySQL DateTime (Y-m-d H:i:s) format used by post_date[_gmt].
[3610] Fix | Delete
*
[3611] Fix | Delete
* @since 1.5.0
[3612] Fix | Delete
*
[3613] Fix | Delete
* @param string $date_string Date and time in ISO 8601 format {@link https://en.wikipedia.org/wiki/ISO_8601}.
[3614] Fix | Delete
* @param string $timezone Optional. If set to 'gmt' returns the result in UTC. Default 'user'.
[3615] Fix | Delete
* @return string|false The date and time in MySQL DateTime format - Y-m-d H:i:s, or false on failure.
[3616] Fix | Delete
*/
[3617] Fix | Delete
function iso8601_to_datetime( $date_string, $timezone = 'user' ) {
[3618] Fix | Delete
$timezone = strtolower( $timezone );
[3619] Fix | Delete
$wp_timezone = wp_timezone();
[3620] Fix | Delete
$datetime = date_create( $date_string, $wp_timezone ); // Timezone is ignored if input has one.
[3621] Fix | Delete
[3622] Fix | Delete
if ( false === $datetime ) {
[3623] Fix | Delete
return false;
[3624] Fix | Delete
}
[3625] Fix | Delete
[3626] Fix | Delete
if ( 'gmt' === $timezone ) {
[3627] Fix | Delete
return $datetime->setTimezone( new DateTimeZone( 'UTC' ) )->format( 'Y-m-d H:i:s' );
[3628] Fix | Delete
}
[3629] Fix | Delete
[3630] Fix | Delete
if ( 'user' === $timezone ) {
[3631] Fix | Delete
return $datetime->setTimezone( $wp_timezone )->format( 'Y-m-d H:i:s' );
[3632] Fix | Delete
}
[3633] Fix | Delete
[3634] Fix | Delete
return false;
[3635] Fix | Delete
}
[3636] Fix | Delete
[3637] Fix | Delete
/**
[3638] Fix | Delete
* Strips out all characters that are not allowable in an email.
[3639] Fix | Delete
*
[3640] Fix | Delete
* @since 1.5.0
[3641] Fix | Delete
*
[3642] Fix | Delete
* @param string $email Email address to filter.
[3643] Fix | Delete
* @return string Filtered email address.
[3644] Fix | Delete
*/
[3645] Fix | Delete
function sanitize_email( $email ) {
[3646] Fix | Delete
// Test for the minimum length the email can be.
[3647] Fix | Delete
if ( strlen( $email ) < 6 ) {
[3648] Fix | Delete
/**
[3649] Fix | Delete
* Filters a sanitized email address.
[3650] Fix | Delete
*
[3651] Fix | Delete
* This filter is evaluated under several contexts, including 'email_too_short',
[3652] Fix | Delete
* 'email_no_at', 'local_invalid_chars', 'domain_period_sequence', 'domain_period_limits',
[3653] Fix | Delete
* 'domain_no_periods', 'domain_no_valid_subs', or no context.
[3654] Fix | Delete
*
[3655] Fix | Delete
* @since 2.8.0
[3656] Fix | Delete
*
[3657] Fix | Delete
* @param string $sanitized_email The sanitized email address.
[3658] Fix | Delete
* @param string $email The email address, as provided to sanitize_email().
[3659] Fix | Delete
* @param string|null $message A message to pass to the user. null if email is sanitized.
[3660] Fix | Delete
*/
[3661] Fix | Delete
return apply_filters( 'sanitize_email', '', $email, 'email_too_short' );
[3662] Fix | Delete
}
[3663] Fix | Delete
[3664] Fix | Delete
// Test for an @ character after the first position.
[3665] Fix | Delete
if ( strpos( $email, '@', 1 ) === false ) {
[3666] Fix | Delete
/** This filter is documented in wp-includes/formatting.php */
[3667] Fix | Delete
return apply_filters( 'sanitize_email', '', $email, 'email_no_at' );
[3668] Fix | Delete
}
[3669] Fix | Delete
[3670] Fix | Delete
// Split out the local and domain parts.
[3671] Fix | Delete
list( $local, $domain ) = explode( '@', $email, 2 );
[3672] Fix | Delete
[3673] Fix | Delete
// LOCAL PART
[3674] Fix | Delete
// Test for invalid characters.
[3675] Fix | Delete
$local = preg_replace( '/[^a-zA-Z0-9!#$%&\'*+\/=?^_`{|}~\.-]/', '', $local );
[3676] Fix | Delete
if ( '' === $local ) {
[3677] Fix | Delete
/** This filter is documented in wp-includes/formatting.php */
[3678] Fix | Delete
return apply_filters( 'sanitize_email', '', $email, 'local_invalid_chars' );
[3679] Fix | Delete
}
[3680] Fix | Delete
[3681] Fix | Delete
// DOMAIN PART
[3682] Fix | Delete
// Test for sequences of periods.
[3683] Fix | Delete
$domain = preg_replace( '/\.{2,}/', '', $domain );
[3684] Fix | Delete
if ( '' === $domain ) {
[3685] Fix | Delete
/** This filter is documented in wp-includes/formatting.php */
[3686] Fix | Delete
return apply_filters( 'sanitize_email', '', $email, 'domain_period_sequence' );
[3687] Fix | Delete
}
[3688] Fix | Delete
[3689] Fix | Delete
// Test for leading and trailing periods and whitespace.
[3690] Fix | Delete
$domain = trim( $domain, " \t\n\r\0\x0B." );
[3691] Fix | Delete
if ( '' === $domain ) {
[3692] Fix | Delete
/** This filter is documented in wp-includes/formatting.php */
[3693] Fix | Delete
return apply_filters( 'sanitize_email', '', $email, 'domain_period_limits' );
[3694] Fix | Delete
}
[3695] Fix | Delete
[3696] Fix | Delete
// Split the domain into subs.
[3697] Fix | Delete
$subs = explode( '.', $domain );
[3698] Fix | Delete
[3699] Fix | Delete
// Assume the domain will have at least two subs.
[3700] Fix | Delete
if ( 2 > count( $subs ) ) {
[3701] Fix | Delete
/** This filter is documented in wp-includes/formatting.php */
[3702] Fix | Delete
return apply_filters( 'sanitize_email', '', $email, 'domain_no_periods' );
[3703] Fix | Delete
}
[3704] Fix | Delete
[3705] Fix | Delete
// Create an array that will contain valid subs.
[3706] Fix | Delete
$new_subs = array();
[3707] Fix | Delete
[3708] Fix | Delete
// Loop through each sub.
[3709] Fix | Delete
foreach ( $subs as $sub ) {
[3710] Fix | Delete
// Test for leading and trailing hyphens.
[3711] Fix | Delete
$sub = trim( $sub, " \t\n\r\0\x0B-" );
[3712] Fix | Delete
[3713] Fix | Delete
// Test for invalid characters.
[3714] Fix | Delete
$sub = preg_replace( '/[^a-z0-9-]+/i', '', $sub );
[3715] Fix | Delete
[3716] Fix | Delete
// If there's anything left, add it to the valid subs.
[3717] Fix | Delete
if ( '' !== $sub ) {
[3718] Fix | Delete
$new_subs[] = $sub;
[3719] Fix | Delete
}
[3720] Fix | Delete
}
[3721] Fix | Delete
[3722] Fix | Delete
// If there aren't 2 or more valid subs.
[3723] Fix | Delete
if ( 2 > count( $new_subs ) ) {
[3724] Fix | Delete
/** This filter is documented in wp-includes/formatting.php */
[3725] Fix | Delete
return apply_filters( 'sanitize_email', '', $email, 'domain_no_valid_subs' );
[3726] Fix | Delete
}
[3727] Fix | Delete
[3728] Fix | Delete
// Join valid subs into the new domain.
[3729] Fix | Delete
$domain = implode( '.', $new_subs );
[3730] Fix | Delete
[3731] Fix | Delete
// Put the email back together.
[3732] Fix | Delete
$sanitized_email = $local . '@' . $domain;
[3733] Fix | Delete
[3734] Fix | Delete
// Congratulations, your email made it!
[3735] Fix | Delete
/** This filter is documented in wp-includes/formatting.php */
[3736] Fix | Delete
return apply_filters( 'sanitize_email', $sanitized_email, $email, null );
[3737] Fix | Delete
}
[3738] Fix | Delete
[3739] Fix | Delete
/**
[3740] Fix | Delete
* Determines the difference between two timestamps.
[3741] Fix | Delete
*
[3742] Fix | Delete
* The difference is returned in a human readable format such as "1 hour",
[3743] Fix | Delete
* "5 mins", "2 days".
[3744] Fix | Delete
*
[3745] Fix | Delete
* @since 1.5.0
[3746] Fix | Delete
* @since 5.3.0 Added support for showing a difference in seconds.
[3747] Fix | Delete
*
[3748] Fix | Delete
* @param int $from Unix timestamp from which the difference begins.
[3749] Fix | Delete
* @param int $to Optional. Unix timestamp to end the time difference. Default becomes time() if not set.
[3750] Fix | Delete
* @return string Human readable time difference.
[3751] Fix | Delete
*/
[3752] Fix | Delete
function human_time_diff( $from, $to = 0 ) {
[3753] Fix | Delete
if ( empty( $to ) ) {
[3754] Fix | Delete
$to = time();
[3755] Fix | Delete
}
[3756] Fix | Delete
[3757] Fix | Delete
$diff = (int) abs( $to - $from );
[3758] Fix | Delete
[3759] Fix | Delete
if ( $diff < MINUTE_IN_SECONDS ) {
[3760] Fix | Delete
$secs = $diff;
[3761] Fix | Delete
if ( $secs <= 1 ) {
[3762] Fix | Delete
$secs = 1;
[3763] Fix | Delete
}
[3764] Fix | Delete
/* translators: Time difference between two dates, in seconds. %s: Number of seconds. */
[3765] Fix | Delete
$since = sprintf( _n( '%s second', '%s seconds', $secs ), $secs );
[3766] Fix | Delete
} elseif ( $diff < HOUR_IN_SECONDS && $diff >= MINUTE_IN_SECONDS ) {
[3767] Fix | Delete
$mins = round( $diff / MINUTE_IN_SECONDS );
[3768] Fix | Delete
if ( $mins <= 1 ) {
[3769] Fix | Delete
$mins = 1;
[3770] Fix | Delete
}
[3771] Fix | Delete
/* translators: Time difference between two dates, in minutes (min=minute). %s: Number of minutes. */
[3772] Fix | Delete
$since = sprintf( _n( '%s min', '%s mins', $mins ), $mins );
[3773] Fix | Delete
} elseif ( $diff < DAY_IN_SECONDS && $diff >= HOUR_IN_SECONDS ) {
[3774] Fix | Delete
$hours = round( $diff / HOUR_IN_SECONDS );
[3775] Fix | Delete
if ( $hours <= 1 ) {
[3776] Fix | Delete
$hours = 1;
[3777] Fix | Delete
}
[3778] Fix | Delete
/* translators: Time difference between two dates, in hours. %s: Number of hours. */
[3779] Fix | Delete
$since = sprintf( _n( '%s hour', '%s hours', $hours ), $hours );
[3780] Fix | Delete
} elseif ( $diff < WEEK_IN_SECONDS && $diff >= DAY_IN_SECONDS ) {
[3781] Fix | Delete
$days = round( $diff / DAY_IN_SECONDS );
[3782] Fix | Delete
if ( $days <= 1 ) {
[3783] Fix | Delete
$days = 1;
[3784] Fix | Delete
}
[3785] Fix | Delete
/* translators: Time difference between two dates, in days. %s: Number of days. */
[3786] Fix | Delete
$since = sprintf( _n( '%s day', '%s days', $days ), $days );
[3787] Fix | Delete
} elseif ( $diff < MONTH_IN_SECONDS && $diff >= WEEK_IN_SECONDS ) {
[3788] Fix | Delete
$weeks = round( $diff / WEEK_IN_SECONDS );
[3789] Fix | Delete
if ( $weeks <= 1 ) {
[3790] Fix | Delete
$weeks = 1;
[3791] Fix | Delete
}
[3792] Fix | Delete
/* translators: Time difference between two dates, in weeks. %s: Number of weeks. */
[3793] Fix | Delete
$since = sprintf( _n( '%s week', '%s weeks', $weeks ), $weeks );
[3794] Fix | Delete
} elseif ( $diff < YEAR_IN_SECONDS && $diff >= MONTH_IN_SECONDS ) {
[3795] Fix | Delete
$months = round( $diff / MONTH_IN_SECONDS );
[3796] Fix | Delete
if ( $months <= 1 ) {
[3797] Fix | Delete
$months = 1;
[3798] Fix | Delete
}
[3799] Fix | Delete
/* translators: Time difference between two dates, in months. %s: Number of months. */
[3800] Fix | Delete
$since = sprintf( _n( '%s month', '%s months', $months ), $months );
[3801] Fix | Delete
} elseif ( $diff >= YEAR_IN_SECONDS ) {
[3802] Fix | Delete
$years = round( $diff / YEAR_IN_SECONDS );
[3803] Fix | Delete
if ( $years <= 1 ) {
[3804] Fix | Delete
$years = 1;
[3805] Fix | Delete
}
[3806] Fix | Delete
/* translators: Time difference between two dates, in years. %s: Number of years. */
[3807] Fix | Delete
$since = sprintf( _n( '%s year', '%s years', $years ), $years );
[3808] Fix | Delete
}
[3809] Fix | Delete
[3810] Fix | Delete
/**
[3811] Fix | Delete
* Filters the human readable difference between two timestamps.
[3812] Fix | Delete
*
[3813] Fix | Delete
* @since 4.0.0
[3814] Fix | Delete
*
[3815] Fix | Delete
* @param string $since The difference in human readable text.
[3816] Fix | Delete
* @param int $diff The difference in seconds.
[3817] Fix | Delete
* @param int $from Unix timestamp from which the difference begins.
[3818] Fix | Delete
* @param int $to Unix timestamp to end the time difference.
[3819] Fix | Delete
*/
[3820] Fix | Delete
return apply_filters( 'human_time_diff', $since, $diff, $from, $to );
[3821] Fix | Delete
}
[3822] Fix | Delete
[3823] Fix | Delete
/**
[3824] Fix | Delete
* Generates an excerpt from the content, if needed.
[3825] Fix | Delete
*
[3826] Fix | Delete
* Returns a maximum of 55 words with an ellipsis appended if necessary.
[3827] Fix | Delete
*
[3828] Fix | Delete
* The 55 word limit can be modified by plugins/themes using the {@see 'excerpt_length'} filter
[3829] Fix | Delete
* The ' [&hellip;]' string can be modified by plugins/themes using the {@see 'excerpt_more'} filter
[3830] Fix | Delete
*
[3831] Fix | Delete
* @since 1.5.0
[3832] Fix | Delete
* @since 5.2.0 Added the `$post` parameter.
[3833] Fix | Delete
*
[3834] Fix | Delete
* @param string $text Optional. The excerpt. If set to empty, an excerpt is generated.
[3835] Fix | Delete
* @param WP_Post|object|int $post Optional. WP_Post instance or Post ID/object. Default null.
[3836] Fix | Delete
* @return string The excerpt.
[3837] Fix | Delete
*/
[3838] Fix | Delete
function wp_trim_excerpt( $text = '', $post = null ) {
[3839] Fix | Delete
$raw_excerpt = $text;
[3840] Fix | Delete
[3841] Fix | Delete
if ( '' === trim( $text ) ) {
[3842] Fix | Delete
$post = get_post( $post );
[3843] Fix | Delete
$text = get_the_content( '', false, $post );
[3844] Fix | Delete
[3845] Fix | Delete
$text = strip_shortcodes( $text );
[3846] Fix | Delete
$text = excerpt_remove_blocks( $text );
[3847] Fix | Delete
[3848] Fix | Delete
/** This filter is documented in wp-includes/post-template.php */
[3849] Fix | Delete
$text = apply_filters( 'the_content', $text );
[3850] Fix | Delete
$text = str_replace( ']]>', ']]&gt;', $text );
[3851] Fix | Delete
[3852] Fix | Delete
/* translators: Maximum number of words used in a post excerpt. */
[3853] Fix | Delete
$excerpt_length = (int) _x( '55', 'excerpt_length' );
[3854] Fix | Delete
[3855] Fix | Delete
/**
[3856] Fix | Delete
* Filters the maximum number of words in a post excerpt.
[3857] Fix | Delete
*
[3858] Fix | Delete
* @since 2.7.0
[3859] Fix | Delete
*
[3860] Fix | Delete
* @param int $number The maximum number of words. Default 55.
[3861] Fix | Delete
*/
[3862] Fix | Delete
$excerpt_length = (int) apply_filters( 'excerpt_length', $excerpt_length );
[3863] Fix | Delete
[3864] Fix | Delete
/**
[3865] Fix | Delete
* Filters the string in the "more" link displayed after a trimmed excerpt.
[3866] Fix | Delete
*
[3867] Fix | Delete
* @since 2.9.0
[3868] Fix | Delete
*
[3869] Fix | Delete
* @param string $more_string The string shown within the more link.
[3870] Fix | Delete
*/
[3871] Fix | Delete
$excerpt_more = apply_filters( 'excerpt_more', ' ' . '[&hellip;]' );
[3872] Fix | Delete
$text = wp_trim_words( $text, $excerpt_length, $excerpt_more );
[3873] Fix | Delete
}
[3874] Fix | Delete
[3875] Fix | Delete
/**
[3876] Fix | Delete
* Filters the trimmed excerpt string.
[3877] Fix | Delete
*
[3878] Fix | Delete
* @since 2.8.0
[3879] Fix | Delete
*
[3880] Fix | Delete
* @param string $text The trimmed text.
[3881] Fix | Delete
* @param string $raw_excerpt The text prior to trimming.
[3882] Fix | Delete
*/
[3883] Fix | Delete
return apply_filters( 'wp_trim_excerpt', $text, $raw_excerpt );
[3884] Fix | Delete
}
[3885] Fix | Delete
[3886] Fix | Delete
/**
[3887] Fix | Delete
* Trims text to a certain number of words.
[3888] Fix | Delete
*
[3889] Fix | Delete
* This function is localized. For languages that count 'words' by the individual
[3890] Fix | Delete
* character (such as East Asian languages), the $num_words argument will apply
[3891] Fix | Delete
* to the number of individual characters.
[3892] Fix | Delete
*
[3893] Fix | Delete
* @since 3.3.0
[3894] Fix | Delete
*
[3895] Fix | Delete
* @param string $text Text to trim.
[3896] Fix | Delete
* @param int $num_words Number of words. Default 55.
[3897] Fix | Delete
* @param string $more Optional. What to append if $text needs to be trimmed. Default '&hellip;'.
[3898] Fix | Delete
* @return string Trimmed text.
[3899] Fix | Delete
*/
[3900] Fix | Delete
function wp_trim_words( $text, $num_words = 55, $more = null ) {
[3901] Fix | Delete
if ( null === $more ) {
[3902] Fix | Delete
$more = __( '&hellip;' );
[3903] Fix | Delete
}
[3904] Fix | Delete
[3905] Fix | Delete
$original_text = $text;
[3906] Fix | Delete
$text = wp_strip_all_tags( $text );
[3907] Fix | Delete
$num_words = (int) $num_words;
[3908] Fix | Delete
[3909] Fix | Delete
/*
[3910] Fix | Delete
* translators: If your word count is based on single characters (e.g. East Asian characters),
[3911] Fix | Delete
* enter 'characters_excluding_spaces' or 'characters_including_spaces'. Otherwise, enter 'words'.
[3912] Fix | Delete
* Do not translate into your own language.
[3913] Fix | Delete
*/
[3914] Fix | Delete
if ( strpos( _x( 'words', 'Word count type. Do not translate!' ), 'characters' ) === 0 && preg_match( '/^utf\-?8$/i', get_option( 'blog_charset' ) ) ) {
[3915] Fix | Delete
$text = trim( preg_replace( "/[\n\r\t ]+/", ' ', $text ), ' ' );
[3916] Fix | Delete
preg_match_all( '/./u', $text, $words_array );
[3917] Fix | Delete
$words_array = array_slice( $words_array[0], 0, $num_words + 1 );
[3918] Fix | Delete
$sep = '';
[3919] Fix | Delete
} else {
[3920] Fix | Delete
$words_array = preg_split( "/[\n\r\t ]+/", $text, $num_words + 1, PREG_SPLIT_NO_EMPTY );
[3921] Fix | Delete
$sep = ' ';
[3922] Fix | Delete
}
[3923] Fix | Delete
[3924] Fix | Delete
if ( count( $words_array ) > $num_words ) {
[3925] Fix | Delete
array_pop( $words_array );
[3926] Fix | Delete
$text = implode( $sep, $words_array );
[3927] Fix | Delete
$text = $text . $more;
[3928] Fix | Delete
} else {
[3929] Fix | Delete
$text = implode( $sep, $words_array );
[3930] Fix | Delete
}
[3931] Fix | Delete
[3932] Fix | Delete
/**
[3933] Fix | Delete
* Filters the text content after words have been trimmed.
[3934] Fix | Delete
*
[3935] Fix | Delete
* @since 3.3.0
[3936] Fix | Delete
*
[3937] Fix | Delete
* @param string $text The trimmed text.
[3938] Fix | Delete
* @param int $num_words The number of words to trim the text to. Default 55.
[3939] Fix | Delete
* @param string $more An optional string to append to the end of the trimmed text, e.g. &hellip;.
[3940] Fix | Delete
* @param string $original_text The text before it was trimmed.
[3941] Fix | Delete
*/
[3942] Fix | Delete
return apply_filters( 'wp_trim_words', $text, $num_words, $more, $original_text );
[3943] Fix | Delete
}
[3944] Fix | Delete
[3945] Fix | Delete
/**
[3946] Fix | Delete
* Converts named entities into numbered entities.
[3947] Fix | Delete
*
[3948] Fix | Delete
* @since 1.5.1
[3949] Fix | Delete
*
[3950] Fix | Delete
* @param string $text The text within which entities will be converted.
[3951] Fix | Delete
* @return string Text with converted entities.
[3952] Fix | Delete
*/
[3953] Fix | Delete
function ent2ncr( $text ) {
[3954] Fix | Delete
[3955] Fix | Delete
/**
[3956] Fix | Delete
* Filters text before named entities are converted into numbered entities.
[3957] Fix | Delete
*
[3958] Fix | Delete
* A non-null string must be returned for the filter to be evaluated.
[3959] Fix | Delete
*
[3960] Fix | Delete
* @since 3.3.0
[3961] Fix | Delete
*
[3962] Fix | Delete
* @param string|null $converted_text The text to be converted. Default null.
[3963] Fix | Delete
* @param string $text The text prior to entity conversion.
[3964] Fix | Delete
*/
[3965] Fix | Delete
$filtered = apply_filters( 'pre_ent2ncr', null, $text );
[3966] Fix | Delete
if ( null !== $filtered ) {
[3967] Fix | Delete
return $filtered;
[3968] Fix | Delete
}
[3969] Fix | Delete
[3970] Fix | Delete
$to_ncr = array(
[3971] Fix | Delete
'&quot;' => '&#34;',
[3972] Fix | Delete
'&amp;' => '&#38;',
[3973] Fix | Delete
'&lt;' => '&#60;',
[3974] Fix | Delete
'&gt;' => '&#62;',
[3975] Fix | Delete
'|' => '&#124;',
[3976] Fix | Delete
'&nbsp;' => '&#160;',
[3977] Fix | Delete
'&iexcl;' => '&#161;',
[3978] Fix | Delete
'&cent;' => '&#162;',
[3979] Fix | Delete
'&pound;' => '&#163;',
[3980] Fix | Delete
'&curren;' => '&#164;',
[3981] Fix | Delete
'&yen;' => '&#165;',
[3982] Fix | Delete
'&brvbar;' => '&#166;',
[3983] Fix | Delete
'&brkbar;' => '&#166;',
[3984] Fix | Delete
'&sect;' => '&#167;',
[3985] Fix | Delete
'&uml;' => '&#168;',
[3986] Fix | Delete
'&die;' => '&#168;',
[3987] Fix | Delete
'&copy;' => '&#169;',
[3988] Fix | Delete
'&ordf;' => '&#170;',
[3989] Fix | Delete
'&laquo;' => '&#171;',
[3990] Fix | Delete
'&not;' => '&#172;',
[3991] Fix | Delete
'&shy;' => '&#173;',
[3992] Fix | Delete
'&reg;' => '&#174;',
[3993] Fix | Delete
'&macr;' => '&#175;',
[3994] Fix | Delete
'&hibar;' => '&#175;',
[3995] Fix | Delete
'&deg;' => '&#176;',
[3996] Fix | Delete
'&plusmn;' => '&#177;',
[3997] Fix | Delete
'&sup2;' => '&#178;',
[3998] Fix | Delete
'&sup3;' => '&#179;',
[3999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function