wp_sprintf

Definition:
function wp_sprintf( $pattern ) {}

WordPress implementation of PHP sprintf() with filters.

Parameters

  • string $pattern: The string which formatted args are inserted.
  • mixed $args,…: Arguments to be formatted into the $pattern string.

Return values

returns:The formatted string.

Defined filters

  • wp_sprintf
    apply_filters( 'wp_sprintf', $fragment, $arg )

Source code

function wp_sprintf( $pattern ) {

	$args = func_get_args( );

	$len = strlen($pattern);

	$start = 0;

	$result = '';

	$arg_index = 0;

	while ( $len > $start ) {

		// Last character: append and break

		if ( strlen($pattern) - 1 == $start ) {

			$result .= substr($pattern, -1);

			break;

		}



		// Literal %: append and continue

		if ( substr($pattern, $start, 2) == '%%' ) {

			$start += 2;

			$result .= '%';

			continue;

		}



		// Get fragment before next %

		$end = strpos($pattern, '%', $start + 1);

		if ( false === $end )

			$end = $len;

		$fragment = substr($pattern, $start, $end - $start);



		// Fragment has a specifier

		if ( $pattern[$start] == '%' ) {

			// Find numbered arguments or take the next one in order

			if ( preg_match('/^%(\d+)\$/', $fragment, $matches) ) {

				$arg = isset($args[$matches[1]]) ? $args[$matches[1]] : '';

				$fragment = str_replace("%{$matches[1]}$", '%', $fragment);

			} else {

				++$arg_index;

				$arg = isset($args[$arg_index]) ? $args[$arg_index] : '';

			}



			// Apply filters OR sprintf

			$_fragment = apply_filters( 'wp_sprintf', $fragment, $arg );

			if ( $_fragment != $fragment )

				$fragment = $_fragment;

			else

				$fragment = sprintf($fragment, strval($arg) );

		}



		// Append to result and move to next fragment

		$result .= $fragment;

		$start = $end;

	}

4139

wp_specialchars_decode

Definition:
function wp_specialchars_decode( $string, $quote_style = ENT_NOQUOTES ) {}

Converts a number of HTML entities into their special characters.
Specifically deals with: &, <, >, ", and ‘.

Parameters

  • string $string: The text which is to be decoded.
  • mixed $quote_style: Optional. Converts double quotes if set to ENT_COMPAT, both single and double if set to ENT_QUOTES or none if set to ENT_NOQUOTES. Also compatible with old _wp_specialchars() values; converting single quotes if set to ‘single’, double if set to ‘double’ or both if otherwise set. Default is ENT_NOQUOTES.

Return values

returns:The decoded text without HTML entities.

Source code

function wp_specialchars_decode( $string, $quote_style = ENT_NOQUOTES ) {

	$string = (string) $string;



	if ( 0 === strlen( $string ) ) {

		return '';

	}



	// Don't bother if there are no entities - saves a lot of processing

	if ( strpos( $string, '&' ) === false ) {

		return $string;

	}



	// Match the previous behaviour of _wp_specialchars() when the $quote_style is not an accepted value

	if ( empty( $quote_style ) ) {

		$quote_style = ENT_NOQUOTES;

	} elseif ( !in_array( $quote_style, array( 0, 2, 3, 'single', 'double' ), true ) ) {

		$quote_style = ENT_QUOTES;

	}



	// More complete than get_html_translation_table( HTML_SPECIALCHARS )

	$single = array( '''  => '\'', ''' => '\'' );

	$single_preg = array( '/&#0*39;/'  => ''', '/&#x0*27;/i' => ''' );

	$double = array( '&quot;' => '"', '"'  => '"', '"' => '"' );

	$double_preg = array( '/&#0*34;/'  => '"', '/&#x0*22;/i' => '"' );

	$others = array( '&lt;'   => '<', '<'  => '<', '&gt;'   => '>', '>'  => '>', '&amp;'  => '&', '&'  => '&', '&' => '&' );

	$others_preg = array( '/&#0*60;/'  => '<', '/&#0*62;/'  => '>', '/&#0*38;/'  => '&', '/&#x0*26;/i' => '&' );



	if ( $quote_style === ENT_QUOTES ) {

		$translation = array_merge( $single, $double, $others );

		$translation_preg = array_merge( $single_preg, $double_preg, $others_preg );

	} elseif ( $quote_style === ENT_COMPAT || $quote_style === 'double' ) {

		$translation = array_merge( $double, $others );

		$translation_preg = array_merge( $double_preg, $others_preg );

	} elseif ( $quote_style === 'single' ) {

		$translation = array_merge( $single, $others );

		$translation_preg = array_merge( $single_preg, $others_preg );

	} elseif ( $quote_style === ENT_NOQUOTES ) {

		$translation = $others;

		$translation_preg = $others_preg;

	}



	// Remove zero padding on numeric entities

	$string = preg_replace( array_keys( $translation_preg ), array_values( $translation_preg ), $string );



	// Replace characters according to translation table

	return strtr( $string, $translation );

}

4137

wp_specialchars

Definition:
function wp_specialchars( $string, $quote_style = ENT_NOQUOTES, $charset = false, $double_encode = false ) {}

Escaping for HTML blocks.

Parameters

  • $string
  • $quote_style
  • $charset
  • $double_encode

Source code

function wp_specialchars( $string, $quote_style = ENT_NOQUOTES, $charset = false, $double_encode = false ) {

	_deprecated_function( __FUNCTION__, '2.8', 'esc_html()' );

	if ( func_num_args() > 1 ) { // Maintain backwards compat for people passing additional args

		$args = func_get_args();

		return call_user_func_array( '_wp_specialchars', $args );

	} else {

		return esc_html( $string );

	}

}

4135

wp_spam_comment

Definition:
function wp_spam_comment($comment_id) {}

Marks a comment as Spam

Parameters

  • int $comment_id: Comment ID.

Return values

returns:False on failure

Defined actions

  • spam_comment
    do_action('spam_comment', $comment_id);
  • spammed_comment
    do_action('spammed_comment', $comment_id);

Source code

function wp_spam_comment($comment_id) {

	if ( !$comment = get_comment($comment_id) )

		return false;



	do_action('spam_comment', $comment_id);



	if ( wp_set_comment_status($comment_id, 'spam') ) {

		add_comment_meta($comment_id, '_wp_trash_meta_status', $comment->comment_approved);

		do_action('spammed_comment', $comment_id);

		return true;

	}



	return false;

}

4133