From a security standpoint, should bloginfo() or get_bloginfo() be escaped?

I’ve been reviewing a lot of information about WP theme and plugin security and understand the concept that you should escape attributes and HTML values in themes and plugins. I’ve seen bloginfo() and echo get_bloginfo() used both standard and inside an esc_html() or esc_attr() function. Genesis and _s, Automattic’s base theme both escape these values … Read more

Best Practice for PHP

When doing a template such as single.php and you have php wrapped in html, is it best to : Start + Stop PHP? for example <h1 class=”post-tilte”><?php the_title(); ?></h1> <p class=”post-content”><?php the_content();?></p> Or Echo HTML and Escape PHP? For example – <?php echo ‘<h1 class=”post-title”>’ . get_the_title() . ‘</h1> <p class=”post-content”‘ . get_the_content() . ‘</p> … Read more

Should HTML output be passed through esc_html() AND wp_kses()?

I’m confused about the different uses of esc_html() and wp_kses(). I understand that esc_html() converts special characters to their HTML entity, and that wp_kses() removes unwanted tags (e.g., &lt;script&gt;), but I’m not sure in what contexts they should be used together or separately. If I run some untrusted HTML through esc_html(), then any JavaScript will … Read more

Illegal Escape Character “\”

The character ‘\’ is a special character and needs to be escaped when used as part of a String, e.g., “\”. Here is an example of a string comparison using the ‘\’ character: if (invName.substring(j,k).equals(“\\”)) {…} You can also perform direct character comparisons using logic similar to the following: if (invName.charAt(j) == ‘\\’) {…}