PluginProbe
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode / 2.5.0
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode v2.5.0
4.7.3 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 All 93 releases
cookiebot / addons / controller / addons / ninja-forms / ninja-forms.php

ninja-forms.php in Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode 2.5.0, at addons/controller/addons/ninja-forms/ninja-forms.php

320 lines 6.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace cookiebot_addons\controller\addons\ninja_forms;
4
5 use cookiebot_addons\controller\addons\Cookiebot_Addons_Interface;
6 use cookiebot_addons\lib\script_loader_tag\Script_Loader_Tag_Interface;
7 use cookiebot_addons\lib\Cookie_Consent_Interface;
8 use cookiebot_addons\lib\buffer\Buffer_Output_Interface;
9 use cookiebot_addons\lib\Settings_Service_Interface;
10
11 class Ninja_Forms implements Cookiebot_Addons_Interface {
12
13 /**
14 * @var Settings_Service_Interface
15 *
16 * @since 1.3.0
17 */
18 protected $settings;
19
20 /**
21 * @var Script_Loader_Tag_Interface
22 *
23 * @since 1.3.0
24 */
25 protected $script_loader_tag;
26
27 /**
28 * @var Cookie_Consent_Interface
29 *
30 * @since 1.3.0
31 */
32 public $cookie_consent;
33
34 /**
35 * @var Buffer_Output_Interface
36 *
37 * @since 1.3.0
38 */
39 protected $buffer_output;
40
41 /**
42 * Jetpack constructor.
43 *
44 * @param $settings Settings_Service_Interface
45 * @param $script_loader_tag Script_Loader_Tag_Interface
46 * @param $cookie_consent Cookie_Consent_Interface
47 * @param $buffer_output Buffer_Output_Interface
48 *
49 * @since 1.3.0
50 */
51 public function __construct( Settings_Service_Interface $settings, Script_Loader_Tag_Interface $script_loader_tag, Cookie_Consent_Interface $cookie_consent, Buffer_Output_Interface $buffer_output ) {
52 $this->settings = $settings;
53 $this->script_loader_tag = $script_loader_tag;
54 $this->cookie_consent = $cookie_consent;
55 $this->buffer_output = $buffer_output;
56 }
57
58 /**
59 * Loads addon configuration
60 *
61 * @since 1.3.0
62 */
63 public function load_configuration() {
64 /**
65 * We add the action after wp_loaded and replace the original
66 * HubSpot Tracking Code action with our own adjusted version.
67 */
68 add_action( 'wp_loaded', array( $this, 'cookiebot_addon_ninja_forms' ), 10 );
69 }
70
71 /**
72 * Manipulate the scripts if they are loaded.
73 *
74 * @since 1.3.0
75 */
76 public function cookiebot_addon_ninja_forms() {
77 /**
78 * block google captcha script
79 */
80 $this->script_loader_tag->add_tag( 'nf-google-recaptcha', $this->get_cookie_types() );
81
82 /**
83 * Display placeholder message
84 */
85 if ( $this->is_placeholder_enabled() ) {
86 add_filter( 'ninja_forms_display_fields', function ( $fields ) {
87 foreach ( $fields as $key => $field ) {
88 if ( $field['type'] == 'recaptcha' ) {
89 $fields[ $key ]['afterField'] = $this->get_placeholder();
90 }
91 }
92 return $fields;
93 }, 10, 1 );
94 }
95 }
96
97 /**
98 * Return addon/plugin name
99 *
100 * @return string
101 *
102 * @since 1.3.0
103 */
104 public function get_addon_name() {
105 return 'Ninja forms';
106 }
107
108 /**
109 * Option name in the database
110 *
111 * @return string
112 *
113 * @since 1.3.0
114 */
115 public function get_option_name() {
116 return 'ninja_forms';
117 }
118
119 /**
120 * Plugin file name
121 *
122 * @return string
123 *
124 * @since 1.3.0
125 */
126 public function get_plugin_file() {
127 return 'ninja-forms/ninja-forms.php';
128 }
129
130 /**
131 * Returns checked cookie types
132 * @return mixed
133 *
134 * @since 1.3.0
135 */
136 public function get_cookie_types() {
137 return $this->settings->get_cookie_types( $this->get_option_name() );
138 }
139
140 /**
141 * Returns default cookie types
142 * @return array
143 *
144 * @since 1.5.0
145 */
146 public function get_default_cookie_types() {
147 return array( 'marketing', 'statistics' );
148 }
149
150
151 /**
152 * Check if plugin is activated and checked in the backend
153 *
154 * @since 1.3.0
155 */
156 public function is_addon_enabled() {
157 return $this->settings->is_addon_enabled( $this->get_option_name() );
158 }
159
160 /**
161 * Checks if addon is installed
162 *
163 * @since 1.3.0
164 */
165 public function is_addon_installed() {
166 return $this->settings->is_addon_installed( $this->get_plugin_file() );
167 }
168
169 /**
170 * Checks if addon is activated
171 *
172 * @since 1.3.0
173 */
174 public function is_addon_activated() {
175 return $this->settings->is_addon_activated( $this->get_plugin_file() );
176 }
177
178 /**
179 * Retrieves current installed version of the addon
180 *
181 * @return bool
182 *
183 * @since 2.2.1
184 */
185 public function get_addon_version() {
186 return $this->settings->get_addon_version( $this->get_plugin_file() );
187 }
188
189 /**
190 * Default placeholder content
191 *
192 * @return string
193 *
194 * @since 1.8.0
195 */
196 public function get_default_placeholder() {
197 return 'Please accept [renew_consent]%cookie_types[/renew_consent] cookies to enable captcha.';
198 }
199
200 /**
201 * Get placeholder content
202 *
203 * This function will check following features:
204 * - Current language
205 *
206 * @param $src
207 *
208 * @return bool|mixed
209 *
210 * @since 1.8.0
211 */
212 public function get_placeholder( $src = '' ) {
213 return $this->settings->get_placeholder( $this->get_option_name(), $this->get_default_placeholder(), cookiebot_addons_output_cookie_types( $this->get_cookie_types() ), $src );
214 }
215
216 /**
217 * Checks if it does have custom placeholder content
218 *
219 * @return mixed
220 *
221 * @since 1.8.0
222 */
223 public function has_placeholder() {
224 return $this->settings->has_placeholder( $this->get_option_name() );
225 }
226
227 /**
228 * returns all placeholder contents
229 *
230 * @return mixed
231 *
232 * @since 1.8.0
233 */
234 public function get_placeholders() {
235 return $this->settings->get_placeholders( $this->get_option_name() );
236 }
237
238 /**
239 * Return true if the placeholder is enabled
240 *
241 * @return mixed
242 *
243 * @since 1.8.0
244 */
245 public function is_placeholder_enabled() {
246 return $this->settings->is_placeholder_enabled( $this->get_option_name() );
247 }
248
249 /**
250 * Adds extra information under the label
251 *
252 * @return string
253 *
254 * @since 1.8.0
255 */
256 public function get_extra_information() {
257 return false;
258 }
259
260 /**
261 * Returns the url of WordPress SVN repository or another link where we can verify the plugin file.
262 *
263 * @return boolean
264 *
265 * @since 1.8.0
266 */
267 public function get_svn_url() {
268 return 'http://plugins.svn.wordpress.org/ninja-forms/trunk/ninja-forms.php';
269 }
270
271 /**
272 * Placeholder helper overlay in the settings page.
273 *
274 * @return string
275 *
276 * @since 1.8.0
277 */
278 public function get_placeholder_helper() {
279 return '<p>Merge tags you can use in the placeholder text:</p><ul><li>%cookie_types - Lists required cookie types</li><li>[renew_consent]text[/renew_consent] - link to display cookie settings in frontend</li></ul>';
280 }
281
282 /**
283 * Returns parent class or false
284 *
285 * @return string|bool
286 *
287 * @since 2.1.3
288 */
289 public function get_parent_class() {
290 return get_parent_class( $this );
291 }
292
293 /**
294 * Action after enabling the addon on the settings page
295 *
296 * @since 2.2.0
297 */
298 public function post_hook_after_enabling() {
299 //do nothing
300 }
301
302 /**
303 * Cookiebot plugin is deactivated
304 *
305 * @since 2.2.0
306 */
307 public function plugin_deactivated() {
308 //do nothing
309 }
310
311 /**
312 * @return mixed
313 *
314 * @since 2.4.5
315 */
316 public function extra_available_addon_option() {
317 //do nothing
318 }
319 }
320