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.
As suggested by the author, I changed my initial <?php echo $title ?> into <?php echo esc_html( $title ); ?>.
This is the code before changes:
<span class="ads">
<?php
if ( is_user_logged_in() ) {
echo '<span><a href="/?page_id=175" title="inserisci un annuncio gratis">Pubblica il tuo annuncio gratis: è facile e veloce!</a></span>';
} else {
echo '<span><a class="simplemodal-login simplemodal-submit" href=""><?php echo $title ?>Pubblica il tuo annuncio gratis: è facile e veloce!</a> </span>';
}
?>
</span>
This is the code after changes:
<span class="ads">
<?php
if ( is_user_logged_in() ) {
echo '<span><a href="/?page_id=175" title="inserisci un annuncio gratis">Pubblica il tuo annuncio gratis: è facile e veloce!</a></span>';
} else {
echo '<span><a class="simplemodal-login simplemodal-submit" href=""><?php echo esc_html( $title ); ?>Pubblica il tuo annuncio gratis: è facile e veloce!</a> </span>';
}
?>
</span>
Now my question is (I guess it's a newbie one!): the change I made is good for my blog' security?