Skip to content

Commit 19ae153

Browse files
authored
Use Plugins API rather than the global variable
WordPress 4.6 moves wp-includes/plugins.php inclusion before the loading of advanced-cache.php which means the Plugins API is available to use. To keep backwards compatibility we check for the existence of add_filter(). Props @aaronjorbin @danielbachhuber
1 parent 9bb9090 commit 19ae153

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

advanced-cache.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -537,8 +537,15 @@ function add_debug_html_to_output( $debug_html ) {
537537
if ( ! $batcache->do || ! $batcache->genlock )
538538
return;
539539

540-
$wp_filter['status_header'][10]['batcache'] = array( 'function' => array(&$batcache, 'status_header'), 'accepted_args' => 2 );
541-
$wp_filter['wp_redirect_status'][10]['batcache'] = array( 'function' => array(&$batcache, 'redirect_status'), 'accepted_args' => 2 );
540+
//WordPress 4.7 changes how filters are hooked. Since WordPress 4.6 add_filter can be used in advanced-cache.php. Previous behaviour is kept for backwards compatability with WP < 4.6
541+
if ( function_exists( 'add_filter' ) ) {
542+
add_filter( 'status_header', array( &$batcache, 'status_header' ), 10, 2 );
543+
add_filter( 'wp_redirect_status', array( &$batcache, 'redirect_status' ), 10, 2 );
544+
} else {
545+
$wp_filter['status_header'][10]['batcache'] = array( 'function' => array(&$batcache, 'status_header'), 'accepted_args' => 2 );
546+
$wp_filter['wp_redirect_status'][10]['batcache'] = array( 'function' => array(&$batcache, 'redirect_status'), 'accepted_args' => 2 );
547+
}
548+
542549

543550
ob_start(array(&$batcache, 'ob'));
544551

0 commit comments

Comments
 (0)