]*)*>~Ui',
$footer_script . '\\0',
$buffer,
1
);
return $buffer;
}
/**
* Filters script tags that are flaged as deferred. This is used to prevent Minify from touching scripts deferred by this feature.
*
* @since 2.4.2
*
* @param array $script_tags array of script tags.
*
* @return array
*/
public function w3tc_minify_js_script_tags( $script_tags ) {
if ( ! is_null( $this->mutator ) ) {
$script_tags = $this->mutator->w3tc_minify_js_script_tags( $script_tags );
}
return $script_tags;
}
/**
* Renders the user experience defer JS settings page.
*
* @since 2.4.2
*
* @return void
*/
public function w3tc_userexperience_page() {
include __DIR__ . '/UserExperience_DeferScripts_Page_View.php';
}
/**
* Specify config key typing for fields that need it.
*
* @since 2.4.2
*
* @param mixed $descriptor Descriptor.
* @param mixed $key Compound key array.
*
* @return array
*/
public function w3tc_config_key_descriptor( $descriptor, $key ) {
if ( is_array( $key ) && 'user-experience-defer-scripts.includes' === implode( '.', $key ) ) {
$descriptor = array( 'type' => 'array' );
}
return $descriptor;
}
/**
* Performs actions on save.
*
* @since 2.4.2
*
* @param array $data Array of save data.
*
* @return array
*/
public function w3tc_save_options( $data ) {
$new_config = $data['new_config'];
$old_config = $data['old_config'];
if (
$new_config->get_array( array( 'user-experience-defer-scripts', 'timeout' ) ) !== $old_config->get_array( array( 'user-experience-defer-scripts', 'timeout' ) )
|| $new_config->get_array( array( 'user-experience-defer-scripts', 'includes' ) ) !== $old_config->get_array( array( 'user-experience-defer-scripts', 'includes' ) )
) {
$minify_enabled = $this->config->get_boolean( 'minify.enabled' );
$pgcache_enabled = $this->config->get_boolean( 'pgcache.enabled' );
if ( $minify_enabled || $pgcache_enabled ) {
$state = Dispatcher::config_state();
if ( $minify_enabled ) {
$state->set( 'minify.show_note.need_flush', true );
}
if ( $pgcache_enabled ) {
$state->set( 'common.show_note.flush_posts_needed', true );
}
$state->save();
}
}
return $data;
}
/**
* Gets the enabled status of the extension.
*
* @since 2.5.1
*
* @return bool
*/
public static function is_enabled() {
$config = Dispatcher::config();
$extensions_active = $config->get_array( 'extensions.active' );
return Util_Environment::is_w3tc_pro( $config ) && array_key_exists( 'user-experience-defer-scripts', $extensions_active );
}
}
$o = new UserExperience_DeferScripts_Extension();
$o->run();