I'm seeing a lot of cases where output is being collected in variables e.g. $html then printed out later down the code, and there is no escaping being added.
Instead, print immediatley and escape at the moment of output.
E.g.
?>
<a href="<?php echo esc_url( $url ); ?>"><?php echo esc_html( $link_text ); ?></a>
<?php
esc_url guarantees that you safely print out a URL, even if $url contains a malicious javascript snippet, it forces the result to be URL shaped. Using a temporary variable to batch up markup then printing it out later on allows you to miss escaping, or worse still double escape. It also means that the browser can't do anything with that markup until you send it, so no progressive rendering occurs.
I'm seeing a lot of cases where output is being collected in variables e.g.
$htmlthen printed out later down the code, and there is no escaping being added.Instead, print immediatley and escape at the moment of output.
E.g.
esc_urlguarantees that you safely print out a URL, even if$urlcontains a malicious javascript snippet, it forces the result to be URL shaped. Using a temporary variable to batch up markup then printing it out later on allows you to miss escaping, or worse still double escape. It also means that the browser can't do anything with that markup until you send it, so no progressive rendering occurs.