PluginProbe ʕ •ᴥ•ʔ
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode / 2.3.0
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode v2.3.0
4.7.2 4.7.1 trunk 2.3.0 2.4.0 2.4.1 2.4.2 2.5.0 3.0.0 3.0.1 3.1.0 3.10.0 3.10.1 3.11.1 3.11.2 3.11.3 3.2.0 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.6.1 3.6.2 3.6.5 3.6.6 3.7.0 3.7.1 3.8.0 3.9.0 4.0.0 4.0.1 4.0.2 4.0.3 4.1.0 4.1.1 4.2.0 4.2.1 4.2.10 4.2.11 4.2.12 4.2.13 4.2.14 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.2.7 4.2.8 4.2.9 4.3.0 4.3.1 4.3.10 4.3.11 4.3.12 4.3.2 4.3.3 4.3.4 4.3.5 4.3.6 4.3.7 4.3.7.1 4.3.8 4.3.9 4.3.9.1 4.4.0 4.4.1 4.4.2 4.5.0 4.5.1 4.5.10 4.5.11 4.5.2 4.5.3 4.5.4 4.5.5 4.5.6 4.5.7 4.5.8 4.5.9 4.6.0 4.6.1 4.6.2 4.6.3 4.6.4 4.6.5 4.6.6 4.6.7 4.7.0
cookiebot / addons / lib / buffer / buffer-output-tag.php
cookiebot / addons / lib / buffer Last commit date
buffer-output-interface.php 7 years ago buffer-output-tag-interface.php 7 years ago buffer-output-tag.php 7 years ago buffer-output.php 7 years ago
buffer-output-tag.php
136 lines
1 <?php
2
3 namespace cookiebot_addons\lib\buffer;
4
5 class Buffer_Output_Tag implements Buffer_Output_Tag_Interface {
6
7 /**
8 * Hook priority
9 *
10 * @var integer
11 *
12 * @since 1.1.0
13 */
14 public $priority;
15
16 /**
17 * Hook tag name
18 *
19 * @var string
20 *
21 * @since 1.2.0
22 */
23 public $tag;
24
25 /**
26 * Keywords to allow in the scripts
27 *
28 * @var array array
29 *
30 * @since 1.2.0
31 */
32 private $keywords;
33
34 /**
35 * Transient unique name
36 *
37 * @var string
38 *
39 * @since 1.1.0
40 */
41 private $transient_name;
42
43 /**
44 *
45 * Use transient cache
46 *
47 * @var boolean
48 *
49 * @since 1.2.0
50 */
51 private $use_cache;
52
53 /**
54 * Cookiebot_Buffer_Output_Tag constructor.
55 *
56 * @param $tag
57 * @param $priority
58 * @param array $keywords
59 * @param boolean $use_cache
60 *
61 * @since 1.2.0
62 */
63 public function __construct( $tag, $priority, $keywords = array(), $use_cache = true ) {
64 $this->tag = $tag;
65 $this->priority = $priority;
66 $this->keywords = $keywords;
67 $this->use_cache = $use_cache;
68 }
69
70 /**
71 * Merges new keywords in existence keywords variable
72 *
73 * @param $keywords
74 *
75 * @since 1.2.0
76 */
77 public function merge_keywords( $keywords ) {
78 $this->keywords = array_merge( $this->keywords, $keywords );
79 }
80
81 /**
82 * Start reading the buffer/output
83 *
84 * @since 1.1.0
85 */
86 public function cookiebot_start_buffer() {
87 ob_start( array( $this, 'manipulate_script' ) );
88 }
89
90 /**
91 * Stop reading the output and output buffered data through manipulate script filter.
92 *
93 * @since 1.1.0
94 */
95 public function cookiebot_stop_buffer() {
96 ob_end_flush();
97 }
98
99 /**
100 * Manipulate google analytic scripts to cookiebot and return it back
101 *
102 * @param $buffer
103 *
104 * @return null|string|string[]
105 *
106 * @since 1.1.0
107 */
108 public function manipulate_script( $buffer ) {
109 /**
110 * Get wp head scripts from the cache
111 */
112 if( $this->use_cache ) {
113 $updated_scripts = get_transient( $this->transient_name );
114 }
115
116 /**
117 * If cache is not set then build it
118 */
119 if ( !$this->use_cache || $updated_scripts === false ) {
120 /**
121 * Get all scripts and add cookieconsent if it does match with the criterion
122 */
123 $updated_scripts = cookiebot_addons_manipulate_script( $buffer, $this->keywords );
124
125 if( $this->use_cache ) {
126 /**
127 * Set cache for 15 minutes
128 */
129 set_transient( $this->transient_name, $updated_scripts, 60 * 15 );
130 }
131 }
132
133 return $updated_scripts;
134 }
135 }
136