wp_kses 缺少两个参数问题
wp_kses missing two arguments issue
迁移到新的 AWS 实例并从 apache 迁移到 nginx 后,我遇到了以前没有的 wp_kses 问题。
表单提交并且所有处理都顺利进行,但我没有重定向到成功页面,而是收到如下错误消息:
警告:wp_kses() 缺少参数 2,在第 20 行 path/to/a/file.php 中调用并在 root/folder/public_html/wp-includes/kses 中定义。 =40=] 第 521 行
这是我处理表单的代码
//Template Name: Jobs: Add mini ad form process
if (!wp_verify_nonce( $_POST['ad_mini_add_nonce'], 'submit_add_mini_ad_form' )) :
echo 'Sorry your nonce didn\'t verify';
exit;
endif;
// Checking for secret filed
if (isset($_POST["secret_field"]) && !empty($_POST["secret_field"])) :
echo 'Sorry, could not send.';
exit;
endif;
// process form data
$position_name = wp_kses($_POST['position_name']);
$company_name = wp_kses($_POST['company_name']);
$location = wp_kses($_POST['location']);
$link_for_apply = wp_kses($_POST['link_for_apply']);
$website = wp_kses($_POST['website']);
$name = wp_kses($_POST['name']);
$email = wp_kses($_POST['email']);
$phone = wp_kses($_POST['phone']);
// Create new add - privately published
$new_ad = array(
'post_title' => $position_name,
'post_type' => 'post',
'post_status' => 'private',
'post_author' => 1001189, //Tanja Mladenovic
);
$new_ad_id = wp_insert_post($new_ad);
$new_ad_url = get_post_permalink($new_ad_id);
$next_month = date( 'Ymd', strtotime('+30 days', time()) );
// Fill custom fileds
add_post_meta($new_ad_id, 'company_location', $location);
add_post_meta($new_ad_id, 'ad_type', 'mini');
add_post_meta($new_ad_id, 'company_name', $company_name);
add_post_meta($new_ad_id, 'webiste', $webiste);
add_post_meta($new_ad_id, 'expire', $next_month);
add_post_meta($new_ad_id, 'contact_person_name', $name);
add_post_meta($new_ad_id, 'contact_person_phone', $phone);
add_post_meta($new_ad_id, 'contact_person_email', $email);
add_post_meta($new_ad_id, 'type_of_apply', 'link');
add_post_meta($new_ad_id, 'link_for_apply', $link);
我知道 wp_kses 可以有两个参数,但之前一切正常。官方文档说 wp_kses 第二个参数 'allowed_html' 的默认值为 none (这正是我想要的),第三个参数 'allowed_protocols' 是可选的
好的,我意识到问题出在哪里了。这是 WordPress 更新。在这个较新的版本中 wp_kses
必须有第二个参数。我的情况是,我不想允许 html,所以我添加了空数组,它起作用了
所以我更改了这部分:
$position_name = wp_kses($_POST['position_name']);
$company_name = wp_kses($_POST['company_name']);
$location = wp_kses($_POST['location']);
$link_for_apply = wp_kses($_POST['link_for_apply']);
$website = wp_kses($_POST['website']);
$name = wp_kses($_POST['name']);
$email = wp_kses($_POST['email']);
$phone = wp_kses($_POST['phone']);
对此:
$position_name = wp_kses($_POST['position_name'], array());
$company_name = wp_kses($_POST['company_name'], array());
$location = wp_kses($_POST['location'], array());
$link_for_apply = wp_kses($_POST['link_for_apply'], array());
$website = wp_kses($_POST['website'], array());
$name = wp_kses($_POST['name'], array());
$email = wp_kses($_POST['email'], array());
$phone = wp_kses($_POST['phone'], array());
迁移到新的 AWS 实例并从 apache 迁移到 nginx 后,我遇到了以前没有的 wp_kses 问题。
表单提交并且所有处理都顺利进行,但我没有重定向到成功页面,而是收到如下错误消息:
警告:wp_kses() 缺少参数 2,在第 20 行 path/to/a/file.php 中调用并在 root/folder/public_html/wp-includes/kses 中定义。 =40=] 第 521 行
这是我处理表单的代码
//Template Name: Jobs: Add mini ad form process
if (!wp_verify_nonce( $_POST['ad_mini_add_nonce'], 'submit_add_mini_ad_form' )) :
echo 'Sorry your nonce didn\'t verify';
exit;
endif;
// Checking for secret filed
if (isset($_POST["secret_field"]) && !empty($_POST["secret_field"])) :
echo 'Sorry, could not send.';
exit;
endif;
// process form data
$position_name = wp_kses($_POST['position_name']);
$company_name = wp_kses($_POST['company_name']);
$location = wp_kses($_POST['location']);
$link_for_apply = wp_kses($_POST['link_for_apply']);
$website = wp_kses($_POST['website']);
$name = wp_kses($_POST['name']);
$email = wp_kses($_POST['email']);
$phone = wp_kses($_POST['phone']);
// Create new add - privately published
$new_ad = array(
'post_title' => $position_name,
'post_type' => 'post',
'post_status' => 'private',
'post_author' => 1001189, //Tanja Mladenovic
);
$new_ad_id = wp_insert_post($new_ad);
$new_ad_url = get_post_permalink($new_ad_id);
$next_month = date( 'Ymd', strtotime('+30 days', time()) );
// Fill custom fileds
add_post_meta($new_ad_id, 'company_location', $location);
add_post_meta($new_ad_id, 'ad_type', 'mini');
add_post_meta($new_ad_id, 'company_name', $company_name);
add_post_meta($new_ad_id, 'webiste', $webiste);
add_post_meta($new_ad_id, 'expire', $next_month);
add_post_meta($new_ad_id, 'contact_person_name', $name);
add_post_meta($new_ad_id, 'contact_person_phone', $phone);
add_post_meta($new_ad_id, 'contact_person_email', $email);
add_post_meta($new_ad_id, 'type_of_apply', 'link');
add_post_meta($new_ad_id, 'link_for_apply', $link);
我知道 wp_kses 可以有两个参数,但之前一切正常。官方文档说 wp_kses 第二个参数 'allowed_html' 的默认值为 none (这正是我想要的),第三个参数 'allowed_protocols' 是可选的
好的,我意识到问题出在哪里了。这是 WordPress 更新。在这个较新的版本中 wp_kses
必须有第二个参数。我的情况是,我不想允许 html,所以我添加了空数组,它起作用了
所以我更改了这部分:
$position_name = wp_kses($_POST['position_name']);
$company_name = wp_kses($_POST['company_name']);
$location = wp_kses($_POST['location']);
$link_for_apply = wp_kses($_POST['link_for_apply']);
$website = wp_kses($_POST['website']);
$name = wp_kses($_POST['name']);
$email = wp_kses($_POST['email']);
$phone = wp_kses($_POST['phone']);
对此:
$position_name = wp_kses($_POST['position_name'], array());
$company_name = wp_kses($_POST['company_name'], array());
$location = wp_kses($_POST['location'], array());
$link_for_apply = wp_kses($_POST['link_for_apply'], array());
$website = wp_kses($_POST['website'], array());
$name = wp_kses($_POST['name'], array());
$email = wp_kses($_POST['email'], array());
$phone = wp_kses($_POST['phone'], array());