Wordpress自定义字段可以';不能处理单引号
我正在创建一个自定义帖子,其中有几个自定义字段。当为自定义字段输入的值包含一个引号时,它后面的所有内容都将被截断。是否有一个筛选器可以用来转义引号,以便将它们作为字符串的一部分读入 我有很多自定义字段,但这里是我正在使用的代码示例Wordpress自定义字段可以';不能处理单引号,wordpress,custom-fields,Wordpress,Custom Fields,我正在创建一个自定义帖子,其中有几个自定义字段。当为自定义字段输入的值包含一个引号时,它后面的所有内容都将被截断。是否有一个筛选器可以用来转义引号,以便将它们作为字符串的一部分读入 我有很多自定义字段,但这里是我正在使用的代码示例 // prefix of meta keys, optional // use underscore (_) at the beginning to make keys hidden, for example $prefix = '_rw_'; // you
// prefix of meta keys, optional
// use underscore (_) at the beginning to make keys hidden, for example $prefix = '_rw_';
// you also can make prefix empty to disable it
$prefix = 'rw_';
$meta_boxes = array();
// first meta box
$meta_boxes[] = array(
'id' => 'entry_data', // meta box id, unique per meta box
'title' => 'Entry Data', // meta box title
'pages' => array('dictionary_entry'), // post types, accept custom post types as well, default is array('post'); optional
'context' => 'normal', // where the meta box appear: normal (default), advanced, side; optional
'priority' => 'high', // order of meta box: high (default), low; optional
'fields' => array( // list of meta fields
array(
'name' => 'Definition 1', // field name
'desc' => 'What does this mean?', // field description, optional
'id' => $prefix . 'definition1', // field id, i.e. the meta key
'type' => 'text', // text box
'std' => '', // default value, optional
'validate_func' => 'check_name' // validate function, created below, inside RW_Meta_Box_Validate class
),
array(
'name' => 'Example 1', // field name
'desc' => 'Use it in a sentence?', // field description, optional
'id' => $prefix . 'example1', // field id, i.e. the meta key
'type' => 'text', // text box
'std' => '', // default value, optional
'validate_func' => 'check_name' // validate function, created below, inside RW_Meta_Box_Validate class
),
)
);
您是否尝试过使用从文本框读取的on值?您是否尝试过使用从文本框读取的on值?这是我想做的事情,但我不确定在哪里做。我需要将该函数应用于输入的文本(保存时),因为单引号将从字符串的其余部分剪掉。因此,您可能希望在
'validate_func'
中使用htmlentities
或其他任何您读取文本框值并想对其执行操作的位置。这为我解决了这个问题。在save\u post
钩子期间保存字段数据之前,在字段数据上运行它,每次它都会恢复正常。这是我想做的事情,但我不确定在哪里做。我需要将该函数应用于输入的文本(保存时),因为单引号将从字符串的其余部分剪掉。因此,您可能希望在'validate_func'
中使用htmlentities
或其他任何您读取文本框值并想对其执行操作的位置。这为我解决了这个问题。在save\u post
钩子期间保存字段数据之前,在字段数据上运行它,每次都会恢复正常。