经过30分钟的研究,我得出了以下解决方案:
function wpse_175564() {
// The html goodies with shortcodes
$htmlcodes = \'<div class="akismet_activate">
<div class="aa_a">A</div>
<div onclick="document.akismet_activate.submit();" class="aa_button_container">
[the_shortcode id="4"]
<div class="aa_button_border">
<div class="aa_button">Activate your Akismet account</div>
</div>
</div>
<div class="aa_description"><strong>Almost done</strong>
- [the_shortcode id="4"] activate your account and say goodbye to comment spam</div>
</div>\';
// End of HTML Goodies
// Let\'s get the shortcode inside the string and execute it!
$pattern = get_shortcode_regex();
if (preg_match_all( \'/\'. $pattern .\'/s\', $htmlcodes, $matches ) && array_key_exists( 2, $matches )) {
foreach($matches[0] as $i => $v){
$htmlcodes = preg_replace($v , do_shortcode($v), $htmlcodes);
$htmlcodes = str_replace(array(\'[\',\']\'), \'\', $htmlcodes);
}
}
return $htmlcodes;
}
不确定这是否是最好的解决方案,但它有效。。。!