
简单有效的WordPress调试及故障排查小技巧
wp_customize_support_script ( No parameters )
wp_customize_support_script: 这是一个动作钩子,当定制器的脚本被排队时被调用。如果你想在定制器中添加额外的脚本或修改默认的脚本,这个钩子会很有用。
打印一个脚本,以检查是否支持自定义器,并在正文中应用无自定义支持或自定义支持类。
这个函数必须在body标签内调用。
理想情况下,在body标签被打开后立即调用此函数。这可以防止未定型的内容的闪现。
我们还建议你在默认情况下为body标签添加”no-customize-support”类。
function wp_customize_support_script() { $admin_origin = parse_url( admin_url() ); $home_origin = parse_url( home_url() ); $cross_domain = ( strtolower( $admin_origin['host'] ) != strtolower( $home_origin['host'] ) ); $type_attr = current_theme_supports( 'html5', 'script' ) ? '' : ' type="text/javascript"'; ?> <script<?php echo $type_attr; ?>> (function() { var request, b = document.body, c = 'className', cs = 'customize-support', rcs = new RegExp('(^|\s+)(no-)?'+cs+'(\s+|$)'); <?php if ( $cross_domain ) : ?> request = (function(){ var xhr = new XMLHttpRequest(); return ('withCredentials' in xhr); })(); <?php else : ?> request = true; <?php endif; ?> b[c] = b[c].replace( rcs, ' ' ); // The customizer requires postMessage and CORS (if the site is cross domain). b[c] += ( window.postMessage && request ? ' ' : ' no-' ) + cs; }()); </script> <?php }