迁移到新的AWS实例并从apache迁移到nginx后,我遇到了wp_kses的问题,这是我之前没有的。
表单提交并且所有处理都顺利,但是我没有重定向到成功页面,而是收到如下错误消息:
警告:缺少wp_kses()的参数2,在第20行的path / to / a / file.php中调用,并在第521行的root / folder / public_html / wp-includes / kses.php中定义< /强>
这是我处理表格的代码
//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 ' 是可选的
答案 0 :(得分:2)
好的,我意识到了问题所在。这是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());