How safe / sanitized is wp_insert_posts()?

You don’t have to do anything. On WP load: ‘init’ hook -> kses_init() -> kses_init_filters() Later: wp_insert_post() -> sanitize_post() -> sanitize_post_field() -> ‘content_save_pre’ -> wp_filter_post_kses() Similarly for post titles, comment text etc. Conclusion: wp_insert_post() is very sanitized. 🙂

Data sanitization: Best Practices with code examples

This codex page explains it pretty well I think. The most important and commonly used function is probably esc_attr. Take this example: <a href=”https://wordpress.stackexchange.com/questions/48660/<?php print $author_url; ?>” title=”<?php print $author_name; ?>”> <?php print $author_name; ?> </a> If $author_name contains a ” character you get your attribute closed, and if that character is followed by onclick=”do_something();” … Read more

wordpress sanitize array?

Here’s a way to do it with PHP’s array map function: // Good idea to make sure things are set before using them $tags = isset( $_POST[‘tags’] ) ? (array) $_POST[‘tags’] : array(); // Any of the WordPress data sanitization functions can be used here $tags = array_map( ‘esc_attr’, $tags );