-
-
Save ShinichiNishikawa/11371541 to your computer and use it in GitHub Desktop.
おかもとさんより
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'the_content', 'my_pre_shortcode', 7 ); | |
function my_pre_shortcode( $content ) { | |
global $shortcode_tags; | |
$shortcode_tags_org = $shortcode_tags; | |
remove_all_shortcodes(); | |
add_shortcode( 'code', 'code_shortcode_handler' ); | |
$content = do_shortcode( $content ); | |
$shortcode_tags = $shortcode_tags_org; | |
return $content; | |
} | |
function code_shortcode_handler( $atts, $content = null ) { | |
extract(shortcode_atts(array( | |
'class' => 'code', | |
'encode' => 'true', | |
), $atts)); | |
if ( strtolower($encode) === 'true' ) | |
$content = htmlentities( $content, ENT_QUOTES, get_option('blog_charset') ); | |
return sprintf( | |
'<pre class="%s"><code>%s</code></pre>'."\n\n", | |
esc_attr( $class ), | |
esc_html( $content ) | |
); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_shortcode('code', 'my_shortcode_handler'); | |
function my_shortcode_handler($atts, $content = null) { | |
extract(shortcode_atts(array( | |
'class' => 'code', | |
'encode' => 'true', | |
), $atts)); | |
if (strtolower($encode) === 'true' || $content != strip_tags($content)) | |
$content = htmlentities($content, ENT_QUOTES, get_option('blog_charset')); | |
return sprintf( | |
'<pre class="%s"><code>%s</code></pre>'."\n\n", | |
esc_attr($class), | |
esc_html($content), | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
wokamotoさんのをフォーク。
最終的に、文脈に合わせて関数名の変更と、半角スペースを入れる変更を入れました。