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
FrontBuffering.php
70 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 FrontBuffering |
| 10 | { |
| 11 | use PluginHelper; |
| 12 | |
| 13 | |
| 14 | public function boot(): void |
| 15 | { |
| 16 | add_action( 'init', [ $this, 'buffer_final_output' ], 1000 ); |
| 17 | } |
| 18 | |
| 19 | |
| 20 | |
| 21 | public function buffer_final_output(): void |
| 22 | { |
| 23 | if ( defined( 'WP_CLI' ) || defined( 'DOING_CRON' ) ) { |
| 24 | return; |
| 25 | } |
| 26 | |
| 27 | if ( wp_doing_ajax() ) { |
| 28 | //Maybe allow filtering for ajax requests |
| 29 | $filter_ajax_requests = (int) $this->getSetting( 'ajax_requests', true, 'filter_body' ); |
| 30 | if ( $filter_ajax_requests !== 1 ) { |
| 31 | return; |
| 32 | } |
| 33 | |
| 34 | } |
| 35 | |
| 36 | if ( is_admin() ) { |
| 37 | |
| 38 | //Maybe allow filtering for admin requests |
| 39 | $filter_admin_requests = (int) $this->getSetting( 'admin_requests', true, 'filter_body' ); |
| 40 | if ( $filter_admin_requests !== 1 ) { |
| 41 | return; |
| 42 | } |
| 43 | |
| 44 | } |
| 45 | |
| 46 | ob_start( [ $this, 'apply_content_filter' ] ); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Apply the callabla function for ob_start() |
| 51 | * |
| 52 | * @param string $content |
| 53 | * @return string - the filtered content |
| 54 | */ |
| 55 | public function apply_content_filter( $content ) |
| 56 | { |
| 57 | $hook = $this->getFinalOutputBufferHook(); |
| 58 | if ( $hook === '' ) { |
| 59 | return $content; |
| 60 | } |
| 61 | |
| 62 | $filteredContent = apply_filters( $hook, $content ); |
| 63 | |
| 64 | // remove filters after applying to prevent multiple applies |
| 65 | remove_all_filters( $this->getFinalOutputBufferHook() ); |
| 66 | |
| 67 | return $filteredContent; |
| 68 | } |
| 69 | } |
| 70 |