Articles of validation

Validation Function for URL in plugin

if ( cpmb_is_valid_mp3( $_FILES[‘video-url’][‘name’] ) ) { $response = wp_upload_bits( $_FILES[‘video-url’][‘name’], null, file_get_contents( $_FILES[‘video-url’][‘tmp_name’] ) ); if ( 0 == strlen ( trim( $response[‘error’] ) ) ) { update_post_meta( $post_id, ‘mp3’, $response[‘url’] ); } // Otherwise, mark this as an invalid file } else { update_post_meta( $post_id, ‘mp3’, ‘invalid-file-type’ ); } The above is a […]

Calling JavaScript file with Custom Plugin

So, the goal is to use jQuery Validation for a custom form. Maybe I’m going about this the hard way. But, here’s what I’m doing: Uploaded the jQuery Validation file to my theme folder Created plug-in folder in plug-in’s file Added php file with this code: function custom_validation() { wp_enqueue_script(‘jquery’); wp_register_script( ‘jq-validation’, get_template_directory_uri() . ‘/jquery.validation/jquery.validation.js’, […]

Remove type attribute from script and style tags added by WordPress

Warning: The type attribute is unnecessary for JavaScript resources. From line 10, column 146; to line 10, column 176 feed/” /> <script type=”text/javascript”>window Warning: The type attribute for the style element is not needed and should be omitted. From line 11, column 1798; to line 11, column 1820 </script> <style type=”text/css”>img.wp Warning: The type attribute […]

Alternative to esc_textarea

I need an alternative function to use with textareas in meta boxes instead of esc_textarea. The problem is that when I use this function with textarea’s it removes line breaks and paragraphs. Is there an alternative function that will keep the line breaks and paragraphs. I have tried the validation reference page in the Codex […]

How do i validate data entered in a meta box so that only floats can be entered in a field?

We have a custom post type in our plugin and now i must provide the user a meta box where he enters latitude and longitude. I want them to be floats, i have no problems in doing the validation client side, but i don’t know how i should handle server side validation in wordpress. I […]

<?php echo $title ?> vs <?php echo esc_html( $title ); ?> WordPress Security

Reading this great article Data Validation and Sanitization in WordPress I’ve noticed that in my blog, in header.php, I used <?php echo $title ?> in a pair of codes. According to the above article, in order to secure data, it is important to validate the data itself for data’s without validation are vulnerable to hackers. […]

Who is responsible for data sanitization in WordPress development?

I am studying how to write more secure WordPress code by implementing validation, sanitization and data escaping wherever necessary. Validation and escaping makes perfect sense, but I am a little confused about sanitization. If I use a function like add_post_meta, does this function do sanitization for me? What about set_option or other ones that interact […]

How do I edit wp_head and/or functions.php to remove rss-feed which isnt used and dont validate?

When using’s validation tool Unicorn I get the following error/warning: URI: This feed does not validate. After looking into my source its there crystal clear in the <head>: <link rel=”alternate” type=”application/rss+xml” title=” &raquo; Hem kommentarsflöde” href=”” /> Now, how do I remove this feed since I dont use it? Thanks in advance!

Require a Custom Taxonomy to be checked

I have a custom taxonomy, “position”, with multiple terms for a custom post type, “employee” in the admin. I want to validate the form to require a position to be selected when you save/update a post. How do I validate and make the position custom taxonomy a required field in the wordpress admin? Also, I’d […]

Duplicate attribute class causing site validation error

The following bit of code results in a duplicate attribute site validation error. This template script: <div class=”clearfix” <?php post_class() ?>> produces this source output: <div class=”clearfix” class=”post-263 post type-post status-publish format-st… WordPress adds its own post-related classes to format the blog entry. Is there any way I can add my “clearfix” class to the […]