diff --git a/lib/classes/AlterHtmlInit.php b/lib/classes/AlterHtmlInit.php index b32caf9d..24c2c5f5 100644 --- a/lib/classes/AlterHtmlInit.php +++ b/lib/classes/AlterHtmlInit.php @@ -107,6 +107,21 @@ public static function setHooks() { add_filter( 'the_excerpt', '\\WebPExpress\\AlterHtmlInit::alterHtml', 99999 ); add_filter( 'post_thumbnail_html', '\\WebPExpress\\AlterHtmlInit::alterHtml', 99999); + // Run custom Filtering Hooks for support 3rd plugins that do not hardcode above + $hooks_list = Option::getOption('webp-express-alter-html-content-hooks-list'); + if ( ! empty( $hooks_list ) ) { + $hooks_list = explode( "\n", $hooks_list ); + if ( ! empty( $hooks_list ) ) { + $hooks_list = array_map( 'trim', $hooks_list ); + + foreach ( $hooks_list as $hook_tag ) { + if ( ! empty( $hook_tag ) ) { + add_filter( $hook_tag, '\\WebPExpress\\AlterHtmlInit::alterHtml', 99999); + } + } + } + } + /* TODO: diff --git a/lib/classes/Config.php b/lib/classes/Config.php index 520b7e57..58626792 100644 --- a/lib/classes/Config.php +++ b/lib/classes/Config.php @@ -83,6 +83,7 @@ public static function getDefaultConfig($skipQualityAuto = false) { 'enabled' => false, 'replacement' => 'picture', // "picture" or "url" 'hooks' => 'ob', // "content-hooks" or "ob" + 'content-hooks-list' => '', // hooks list for hooks field is "content-hooks" 'only-for-webp-enabled-browsers' => true, // If true, there will be two HTML versions of each page 'only-for-webps-that-exists' => false, 'alter-html-add-picturefill-js' => true, @@ -394,6 +395,7 @@ public static function updateAutoloadedOptions($config) Option::updateOption('webp-express-alter-html', $config['alter-html']['enabled'], true); Option::updateOption('webp-express-alter-html-hooks', $config['alter-html']['hooks'], true); + Option::updateOption('webp-express-alter-html-content-hooks-list', $config['alter-html']['content-hooks-list'], ''); Option::updateOption('webp-express-alter-html-replacement', $config['alter-html']['replacement'], true); Option::updateOption('webp-express-alter-html-add-picturefill-js', (($config['alter-html']['replacement'] == 'picture') && (isset($config['alter-html']['alter-html-add-picturefill-js']) && $config['alter-html']['alter-html-add-picturefill-js'])), true); diff --git a/lib/options/js/0.16.0/page.js b/lib/options/js/0.16.0/page.js index bc1f31b2..12741647 100644 --- a/lib/options/js/0.16.0/page.js +++ b/lib/options/js/0.16.0/page.js @@ -264,6 +264,22 @@ document.addEventListener('DOMContentLoaded', function() { }); } + // Show/hide "Add custom filtering hooks from theme or plugins here, 1 per line" when "Where to replace" is changed + if (el('alter_html_hooks_content_hooks') && el('alter_html_content_hooks_options_div')) { + el('alter_html_content_hooks_options_div').classList.add('effect-opacity'); + function updateFilteringHooksVisibility() { + toggleVisibility('alter_html_content_hooks_options_div', el('alter_html_hooks_content_hooks').checked); + } + updateFilteringHooksVisibility(); + + el('alter_html_hooks_content_hooks').addEventListener('change', function() { + updateFilteringHooksVisibility(); + }); + el('alter_html_hooks_ob').addEventListener('change', function() { + updateFilteringHooksVisibility(); + }); + } + if (el('ui_show_alter_html_chart') && el('alter_html_comparison_chart')) { var elm = el('alter_html_comparison_chart'); elm.style['maxHeight'] = (elm.clientHeight + 80) + 'px'; diff --git a/lib/options/options/alter-html/alter-html-options.inc b/lib/options/options/alter-html/alter-html-options.inc index c7b7a6c2..27408e8e 100644 --- a/lib/options/options/alter-html/alter-html-options.inc +++ b/lib/options/options/alter-html/alter-html-options.inc @@ -183,14 +183,33 @@ namespace WebPExpress; '
', 'no-margin-left set-margin-right'); ?> +