Shortcodes
1 month ago
DisplayEmailImage.php
3 months ago
Front.php
2 months ago
FrontBuffering.php
3 months ago
FrontCore.php
3 months ago
FrontEnqueue.php
3 months ago
FrontTemplateTags.php
3 months ago
FrontCore.php
135 lines
| 1 | <?php |
| 2 | |
| 3 | namespace OnlineOptimisation\EmailEncoderBundle\Front; |
| 4 | |
| 5 | if ( ! defined( 'ABSPATH' ) ) exit; |
| 6 | |
| 7 | use OnlineOptimisation\EmailEncoderBundle\Traits\PluginHelper; |
| 8 | |
| 9 | class FrontCore |
| 10 | { |
| 11 | use PluginHelper; |
| 12 | |
| 13 | private int $protection_method; |
| 14 | private bool $protect_shortcode_tags; |
| 15 | // private bool $protect_using; |
| 16 | |
| 17 | |
| 18 | public function boot(): void |
| 19 | { |
| 20 | add_action( 'init', [ $this, 'register' ] ); |
| 21 | } |
| 22 | |
| 23 | |
| 24 | public function register(): void |
| 25 | { |
| 26 | $this->protection_method = (int) $this->getSetting( 'protect', true ); |
| 27 | $this->protect_shortcode_tags = $this->getSettingBool( 'protect_shortcode_tags', true, 'filter_body' ); |
| 28 | |
| 29 | $hook_name = (bool) $this->getSetting( 'filter_hook', true, 'filter_body' ) ? 'init' : 'wp'; |
| 30 | |
| 31 | add_action( $hook_name, [ $this, 'register_hooks' ], 100 ); |
| 32 | add_action( $hook_name, [ $this, 'register_rss_hooks' ], 100 ); |
| 33 | } |
| 34 | |
| 35 | |
| 36 | public function register_rss_hooks(): void |
| 37 | { |
| 38 | if ( !is_feed() ) { |
| 39 | return; |
| 40 | } |
| 41 | |
| 42 | $filter_rss = $this->getSettingBool( 'filter_rss', true, 'filter_body' ); |
| 43 | $remove_shortcodes_rss = $this->getSettingBool( 'remove_shortcodes_rss', true, 'filter_body' ); |
| 44 | |
| 45 | if ( $filter_rss ) { |
| 46 | add_filter( $this->getFinalOutputBufferHook(), [ $this, 'filter_rss' ], 100 ); |
| 47 | } |
| 48 | |
| 49 | if ( $remove_shortcodes_rss ) { |
| 50 | add_filter( $this->getFinalOutputBufferHook(), [ $this, 'remove_shortcodes' ], 100 ); |
| 51 | } |
| 52 | |
| 53 | } |
| 54 | |
| 55 | |
| 56 | public function register_hooks(): void |
| 57 | { |
| 58 | $exit_early = $this->protection_method === $this->settings()::PROTECT_DISABLED |
| 59 | || $this->isQueryParameterExcluded() |
| 60 | || $this->isPostExcluded() |
| 61 | ; |
| 62 | |
| 63 | if ( $exit_early ) { |
| 64 | return; |
| 65 | } |
| 66 | |
| 67 | |
| 68 | if ( $this->protection_method === $this->settings()::PROTECT_FILTERS_ONLY ) { |
| 69 | |
| 70 | $filter_hooks = [ |
| 71 | 'the_title', |
| 72 | 'the_content', |
| 73 | 'the_excerpt', |
| 74 | 'get_the_excerpt', |
| 75 | |
| 76 | //Comment related |
| 77 | 'comment_text', |
| 78 | 'comment_excerpt', |
| 79 | 'comment_url', |
| 80 | 'get_comment_author_url', |
| 81 | 'get_comment_author_url_link', |
| 82 | |
| 83 | //Widgets |
| 84 | 'widget_title', |
| 85 | 'widget_text', |
| 86 | 'widget_content', |
| 87 | 'widget_output', |
| 88 | ]; |
| 89 | |
| 90 | $filter_hooks = apply_filters( 'eeb/frontend/wordpress_filters', $filter_hooks ); |
| 91 | |
| 92 | foreach ( $filter_hooks as $hook ) { |
| 93 | add_filter( $hook, [ $this, 'filter_content' ], 100 ); |
| 94 | } |
| 95 | } elseif ( $this->protection_method === $this->settings()::PROTECT_FULL_PAGE ) { |
| 96 | |
| 97 | add_filter( $this->getFinalOutputBufferHook(), [ $this, 'filter_page' ], 100 ); |
| 98 | } |
| 99 | |
| 100 | if ( $this->protect_shortcode_tags ) { |
| 101 | add_filter( 'do_shortcode_tag', [ $this, 'filter_content' ], 10 ); |
| 102 | } |
| 103 | |
| 104 | } |
| 105 | |
| 106 | |
| 107 | public function filter_page( string $content ): string |
| 108 | { |
| 109 | $protect_using = (string) $this->getSetting( 'protect_using', true ); |
| 110 | return $this->filterPage( $content, $protect_using ); |
| 111 | } |
| 112 | |
| 113 | |
| 114 | public function filter_content( string $content ): string |
| 115 | { |
| 116 | $protect_using = (string) $this->getSetting( 'protect_using', true ); |
| 117 | return $this->filterContent( $content, $protect_using ); |
| 118 | } |
| 119 | |
| 120 | |
| 121 | public function filter_rss( string $content ): string |
| 122 | { |
| 123 | $protection_type = (string) $this->getSetting( 'protect_using', true ); |
| 124 | return $this->validate()->filters->filter_rss( $content, $protection_type ); |
| 125 | } |
| 126 | |
| 127 | |
| 128 | // strip shortcodes like [eeb_content], [eeb_form] |
| 129 | public function remove_shortcodes( string $content ): string |
| 130 | { |
| 131 | return strip_shortcodes( $content ); |
| 132 | } |
| 133 | |
| 134 | } |
| 135 |