do_shortcode escaping
-
Please tell me how to escape the widget shortcode.
There is a function:
if (!function_exists(‘foo_do_shortcode’)) { function foo_do_shortcode($name, $attrs = array()) { $special_chars = array(‘[‘, ‘]’, ‘”‘, “‘”); $sc_params = ”; foreach ($attrs as $k => $v) { $v = str_replace($special_chars, ”, $v); if (!is_array($v) || !is_object($v)) { $sc_params .= sprintf( ‘ %s=”%s”‘, sanitize_key($k), esc_attr($v) ); } } $short_code = “[{$name}{$sc_params}]”; return do_shortcode($short_code); } }
We’re calling it in another file.
echo foo_do_shortcode( ‘foo_search’, array( ‘layout’ => $layout, ‘column’ => 1, ‘color_scheme’ => “color-dark”, ‘status_enable’ => $status_enable == 1 ? ‘true’ : ‘false’, ‘type_enable’ => $type_enable == 1 ? ‘true’ : ‘false’, ‘title_enable’ => $title_enable == 1 ? ‘true’ : ‘false’, ‘address_enable’ => $address_enable == 1 ? ‘true’ : ‘false’, ‘country_enable’ => $country_enable == 1 ? ‘true’ : ‘false’, ) ) ;
Error checking: All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found ‘foo_do_shortcode’ I tried wp_kses_post, esc_html …. and more. The widget breaks.
You must be logged in to reply to this topic.