Petar Popovic Petar Popovic - 3 months ago 14
Apache Configuration Question

wp_kses missing two arguments issue

After migrating to new AWS instance and moving from apache to nginx I have a problem with wp_kses that I didn't have before.

The form submits and all processing goes well, but instead of redirecting to the success page I get an error messages like this:

Warning: Missing argument 2 for wp_kses(), called in path/to/a/file.php on line 20 and defined in root/folder/public_html/wp-includes/kses.php on line 521

This is my code for processing form

//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);


I know wp_kses can have two more arguments, but everything worked before without trouble. Official documentations says that wp_kses second argument 'allowed_html' has default value of none (and that is exactly what I want), and third argument 'allowed_protocols' is optional

Answer

Ok, I realized what's the problem. It was WordPress update. In this newer version wp_kses must have second argument. Im my case, I don't want to allow html, so I added empty array, and it works

So I changed this part:

$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']);

to this:

$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());