What’s a safe / good way to output HTML safely within WordPress templates?

It depends on the context. In a template you’d just echo it: <div> <?php echo parse_html_for_images(); ?> </div> In a function you might want to concatenate it with something else: function wpse_303376_thumbnail() { return ‘<div>’ . parse_html_for_images() . ‘</div>’; } In a shortcode callback with lots other markup you might want to use output buffering, … Read more

How to escape $_GET and check if isset?

The proper way to do that is using filter_input(). Here is an example for using a custom sanitize function: $tab = filter_input( INPUT_GET, ‘tab’, FILTER_CALLBACK, [‘options’ => ‘esc_html’] ); $tab = $tab ?: ‘front_page_options’;

Echo JavaScript Safely

What you’re asking for is impossible, there is no such thing as a safe javascript entry box. Even if we strip out extra script and style tags, it’s pointless, as the javascript code itself is inherently dangerous, and can create any elements it wants using DOM construction, e.g.: var s = jQuery( ‘script’, { ‘src’: … Read more

Escape hexadecimals/rgba values

Just finished now the sanitize callback for RGBA colors.and tested in my theme and working perfect, and its taking RGBA values please find the code function awstheme_sanitize_rgba( $color ) { if ( empty( $color ) || is_array( $color ) ) return ‘rgba(0,0,0,0)’; // If string does not start with ‘rgba’, then treat as hex // … Read more

tech