函数文档

addslashes_strings_only()

💡 云策文档标注

概述

addslashes_strings_only() 是一个 WordPress 函数,用于仅在输入值为字符串时添加反斜杠转义,非字符串值则原样返回。该函数自 5.6.0 版本起已弃用。

关键要点

  • 函数功能:检查输入值是否为字符串,如果是则应用 addslashes() 进行转义,否则直接返回原值。
  • 参数:接受一个混合类型参数 $value,为必需项。
  • 返回值:返回转义后的字符串或原输入值。
  • 弃用状态:自 WordPress 5.6.0 起弃用,建议开发者注意替代方案。
  • 相关函数:参考 wp_slash() 以获取更全面的转义功能。

代码示例

/* Example usage of addslashes_strings_only() */
$string     = "This is a string with 'quotes'";
$non_string = 12345;

$escaped_string     = addslashes_strings_only( $string );
$escaped_non_string = addslashes_strings_only( $non_string );

echo "Original String: $string";
echo "Escaped String: $escaped_string";

echo "Original Non-string: $non_string";
echo "Escaped Non-string: $escaped_non_string";

📄 原文内容

Adds slashes only if the provided value is a string.

Description

See also

Parameters

$valuemixedrequired

Return

mixed

Source

function addslashes_strings_only( $value ) {
	return is_string( $value ) ? addslashes( $value ) : $value;
}

Changelog

Version Description
5.6.0 Deprecated.
5.3.0 Introduced.

User Contributed Notes

  1. Skip to note 2 content

    /* Example usage of addslashes_strings_only() */ 
    $string     = "This is a string with 'quotes'";
    $non_string = 12345;
    
    $escaped_string     = addslashes_strings_only( $string );
    $escaped_non_string = addslashes_strings_only( $non_string );
    
    echo "Original String: $string";
    echo "Escaped String: $escaped_string";
    
    echo "Original Non-string: $non_string";
    echo "Escaped Non-string: $escaped_non_string";