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