wpseek.com
A WordPress-centric search engine for devs and theme authors
wp_remove_surrounding_empty_script_tags is private and should not be used in themes or plugins directly.
wp_remove_surrounding_empty_script_tags › WordPress Function
Since6.4.0
Deprecatedn/a
› wp_remove_surrounding_empty_script_tags ( $contents )
Access: |
|
Parameters: |
|
See: | |
Returns: |
|
Defined at: |
|
Codex: |
Removes leading and trailing _empty_ script tags.
This is a helper meant to be used for literal script tag construction withinwp_get_inline_script_tag()
or wp_print_inline_script_tag()
.
It removes the literal values of "" from
around an inline script after trimming whitespace. Typically this
is used in conjunction with output buffering, where ob_get_clean()
is passed as the $contents
argument.
Example:
// Strips exact literal empty SCRIPT tags.
$js = ';
'sayHello();' === wp_remove_surrounding_empty_script_tags( $js );
// Otherwise if anything is different it warns in the JS console.
$js = '';
'console.error( ... )' === wp_remove_surrounding_empty_script_tags( $js );Related Functions: wp_print_script_tag, wp_get_script_tag, wp_get_inline_script_tag, __return_empty_string, remove_rewrite_tag
Source
function wp_remove_surrounding_empty_script_tags( $contents ) { $contents = trim( $contents ); $opener = '<SCRIPT>'; $closer = '</SCRIPT>'; if ( strlen( $contents ) > strlen( $opener ) + strlen( $closer ) && strtoupper( substr( $contents, 0, strlen( $opener ) ) ) === $opener && strtoupper( substr( $contents, -strlen( $closer ) ) ) === $closer ) { return substr( $contents, strlen( $opener ), -strlen( $closer ) ); } else { $error_message = __( 'Expected string to start with script tag (without attributes) and end with script tag, with optional whitespace.' ); _doing_it_wrong( __FUNCTION__, $error_message, '6.4' ); return sprintf( 'console.error(%s)', wp_json_encode( sprintf( /* translators: %s: wp_remove_surrounding_empty_script_tags() */ __( 'Function %s used incorrectly in PHP.' ), 'wp_remove_surrounding_empty_script_tags()' ) . ' ' . $error_message ) ); } }