1
|
|
|
<?php |
|
|
|
|
2
|
|
|
/** |
3
|
|
|
* IMPORTANT: |
4
|
|
|
* This file will be loaded based on the order of the plugins/themes load. |
5
|
|
|
* If there's a theme and a plugin using Freemius, the plugin's essential |
6
|
|
|
* file will always load first. |
7
|
|
|
* |
8
|
|
|
* @package Freemius |
9
|
|
|
* @copyright Copyright (c) 2015, Freemius, Inc. |
10
|
|
|
* @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3 |
11
|
|
|
* @since 1.1.5 |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
if ( ! function_exists( 'fs_normalize_path' ) ) { |
15
|
|
|
if ( function_exists( 'wp_normalize_path' ) ) { |
16
|
|
|
/** |
17
|
|
|
* Normalize a filesystem path. |
18
|
|
|
* |
19
|
|
|
* Replaces backslashes with forward slashes for Windows systems, and ensures |
20
|
|
|
* no duplicate slashes exist. |
21
|
|
|
* |
22
|
|
|
* @param string $path Path to normalize. |
23
|
|
|
* |
24
|
|
|
* @return string Normalized path. |
25
|
|
|
*/ |
26
|
|
|
function fs_normalize_path( $path ) { |
27
|
|
|
return wp_normalize_path( $path ); |
28
|
|
|
} |
29
|
|
|
} else { |
30
|
|
|
function fs_normalize_path( $path ) { |
|
|
|
|
31
|
|
|
$path = str_replace( '\\', '/', $path ); |
32
|
|
|
$path = preg_replace( '|/+|', '/', $path ); |
33
|
|
|
|
34
|
|
|
return $path; |
35
|
|
|
} |
36
|
|
|
} |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
#region Core Redirect (copied from BuddyPress) ----------------------------------------- |
40
|
|
|
|
41
|
|
|
if ( ! function_exists( 'fs_redirect' ) ) { |
42
|
|
|
/** |
43
|
|
|
* Redirects to another page, with a workaround for the IIS Set-Cookie bug. |
44
|
|
|
* |
45
|
|
|
* @link http://support.microsoft.com/kb/q176113/ |
46
|
|
|
* @since 1.5.1 |
47
|
|
|
* @uses apply_filters() Calls 'wp_redirect' hook on $location and $status. |
48
|
|
|
* |
49
|
|
|
* @param string $location The path to redirect to. |
50
|
|
|
* @param bool $exit If true, exit after redirect (Since 1.2.1.5). |
51
|
|
|
* @param int $status Status code to use. |
52
|
|
|
* |
53
|
|
|
* @return bool False if $location is not set |
54
|
|
|
*/ |
55
|
|
|
function fs_redirect( $location, $exit = true, $status = 302 ) { |
56
|
|
|
global $is_IIS; |
|
|
|
|
57
|
|
|
|
58
|
|
|
$file = ''; |
59
|
|
|
$line = ''; |
60
|
|
|
if ( headers_sent($file, $line) ) { |
61
|
|
|
if ( WP_FS__DEBUG_SDK && class_exists( 'FS_Admin_Notice_Manager' ) ) { |
62
|
|
|
$notices = FS_Admin_Notice_Manager::instance( 'global' ); |
63
|
|
|
|
64
|
|
|
$notices->add( "Freemius failed to redirect the page because the headers have been already sent from line <b><code>{$line}</code></b> in file <b><code>{$file}</code></b>. If it's unexpected, it usually happens due to invalid space and/or EOL character(s).", 'Oops...', 'error' ); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
return false; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
if ( defined( 'DOING_AJAX' ) ) { |
71
|
|
|
// Don't redirect on AJAX calls. |
72
|
|
|
return false; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
if ( ! $location ) // allows the wp_redirect filter to cancel a redirect |
76
|
|
|
{ |
77
|
|
|
return false; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
$location = fs_sanitize_redirect( $location ); |
81
|
|
|
|
82
|
|
|
if ( $is_IIS ) { |
83
|
|
|
header( "Refresh: 0;url=$location" ); |
84
|
|
|
} else { |
85
|
|
|
if ( php_sapi_name() != 'cgi-fcgi' ) { |
86
|
|
|
status_header( $status ); |
87
|
|
|
} // This causes problems on IIS and some FastCGI setups |
88
|
|
|
header( "Location: $location" ); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
if ( $exit ) { |
92
|
|
|
exit(); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
return true; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
if ( ! function_exists( 'fs_sanitize_redirect' ) ) { |
99
|
|
|
/** |
100
|
|
|
* Sanitizes a URL for use in a redirect. |
101
|
|
|
* |
102
|
|
|
* @since 2.3 |
103
|
|
|
* |
104
|
|
|
* @param string $location |
105
|
|
|
* |
106
|
|
|
* @return string redirect-sanitized URL |
107
|
|
|
*/ |
108
|
|
|
function fs_sanitize_redirect( $location ) { |
109
|
|
|
$location = preg_replace( '|[^a-z0-9-~+_.?#=&;,/:%!]|i', '', $location ); |
110
|
|
|
$location = fs_kses_no_null( $location ); |
111
|
|
|
|
112
|
|
|
// remove %0d and %0a from location |
113
|
|
|
$strip = array( '%0d', '%0a' ); |
114
|
|
|
$found = true; |
115
|
|
|
while ( $found ) { |
116
|
|
|
$found = false; |
117
|
|
|
foreach ( (array) $strip as $val ) { |
118
|
|
|
while ( strpos( $location, $val ) !== false ) { |
119
|
|
|
$found = true; |
120
|
|
|
$location = str_replace( $val, '', $location ); |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
return $location; |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
if ( ! function_exists( 'fs_kses_no_null' ) ) { |
130
|
|
|
/** |
131
|
|
|
* Removes any NULL characters in $string. |
132
|
|
|
* |
133
|
|
|
* @since 1.0.0 |
134
|
|
|
* |
135
|
|
|
* @param string $string |
136
|
|
|
* |
137
|
|
|
* @return string |
138
|
|
|
*/ |
139
|
|
|
function fs_kses_no_null( $string ) { |
140
|
|
|
$string = preg_replace( '/\0+/', '', $string ); |
141
|
|
|
$string = preg_replace( '/(\\\\0)+/', '', $string ); |
142
|
|
|
|
143
|
|
|
return $string; |
144
|
|
|
} |
145
|
|
|
} |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
#endregion Core Redirect (copied from BuddyPress) ----------------------------------------- |
149
|
|
|
|
150
|
|
|
if ( ! function_exists( '__fs' ) ) { |
151
|
|
|
global $fs_text_overrides; |
|
|
|
|
152
|
|
|
|
153
|
|
|
if ( ! isset( $fs_text_overrides ) ) { |
154
|
|
|
$fs_text_overrides = array(); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Retrieve a translated text by key. |
159
|
|
|
* |
160
|
|
|
* @deprecated Use `fs_text()` instead since methods starting with `__` trigger warnings in Php 7. |
161
|
|
|
* |
162
|
|
|
* @author Vova Feldman (@svovaf) |
163
|
|
|
* @since 1.1.4 |
164
|
|
|
* |
165
|
|
|
* @param string $key |
166
|
|
|
* @param string $slug |
167
|
|
|
* |
168
|
|
|
* @return string |
169
|
|
|
* |
170
|
|
|
* @global $fs_text, $fs_text_overrides |
171
|
|
|
*/ |
172
|
|
|
function __fs( $key, $slug = 'freemius' ) { |
173
|
|
|
global $fs_text, |
|
|
|
|
174
|
|
|
$fs_module_info_text, |
175
|
|
|
$fs_text_overrides; |
176
|
|
|
|
177
|
|
|
if ( isset( $fs_text_overrides[ $slug ] ) ) { |
178
|
|
|
if ( isset( $fs_text_overrides[ $slug ][ $key ] ) ) { |
179
|
|
|
return $fs_text_overrides[ $slug ][ $key ]; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
$lower_key = strtolower( $key ); |
183
|
|
|
if ( isset( $fs_text_overrides[ $slug ][ $lower_key ] ) ) { |
184
|
|
|
return $fs_text_overrides[ $slug ][ $lower_key ]; |
185
|
|
|
} |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
if ( ! isset( $fs_text ) ) { |
189
|
|
|
$dir = defined( 'WP_FS__DIR_INCLUDES' ) ? |
190
|
|
|
WP_FS__DIR_INCLUDES : |
191
|
|
|
dirname( __FILE__ ); |
192
|
|
|
|
193
|
|
|
require_once $dir . '/i18n.php'; |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
if ( isset( $fs_text[ $key ] ) ) { |
197
|
|
|
return $fs_text[ $key ]; |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
if ( isset( $fs_module_info_text[ $key ] ) ) { |
201
|
|
|
return $fs_module_info_text[ $key ]; |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
return $key; |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* Output a translated text by key. |
209
|
|
|
* |
210
|
|
|
* @deprecated Use `fs_echo()` instead for consistency with `fs_text()`. |
211
|
|
|
* |
212
|
|
|
* @author Vova Feldman (@svovaf) |
213
|
|
|
* @since 1.1.4 |
214
|
|
|
* |
215
|
|
|
* @param string $key |
216
|
|
|
* @param string $slug |
217
|
|
|
*/ |
218
|
|
|
function _efs( $key, $slug = 'freemius' ) { |
219
|
|
|
fs_echo( $key, $slug ); |
220
|
|
|
} |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
if ( ! function_exists( 'fs_override_i18n' ) ) { |
224
|
|
|
/** |
225
|
|
|
* Override default i18n text phrases. |
226
|
|
|
* |
227
|
|
|
* @author Vova Feldman (@svovaf) |
228
|
|
|
* @since 1.1.6 |
229
|
|
|
* |
230
|
|
|
* @param string[] $key_value |
231
|
|
|
* @param string $slug |
232
|
|
|
* |
233
|
|
|
* @global $fs_text_overrides |
234
|
|
|
*/ |
235
|
|
|
function fs_override_i18n( array $key_value, $slug = 'freemius' ) { |
236
|
|
|
global $fs_text_overrides; |
|
|
|
|
237
|
|
|
|
238
|
|
|
if ( ! isset( $fs_text_overrides[ $slug ] ) ) { |
239
|
|
|
$fs_text_overrides[ $slug ] = array(); |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
foreach ( $key_value as $key => $value ) { |
243
|
|
|
$fs_text_overrides[ $slug ][ $key ] = $value; |
244
|
|
|
} |
245
|
|
|
} |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
if ( ! function_exists( 'fs_get_ip' ) ) { |
249
|
|
|
/** |
250
|
|
|
* Get client IP. |
251
|
|
|
* |
252
|
|
|
* @author Vova Feldman (@svovaf) |
253
|
|
|
* @since 1.1.2 |
254
|
|
|
* |
255
|
|
|
* @return string|null |
256
|
|
|
*/ |
257
|
|
|
function fs_get_ip() { |
|
|
|
|
258
|
|
|
$fields = array( |
259
|
|
|
'HTTP_CF_CONNECTING_IP', |
260
|
|
|
'HTTP_CLIENT_IP', |
261
|
|
|
'HTTP_X_FORWARDED_FOR', |
262
|
|
|
'HTTP_X_FORWARDED', |
263
|
|
|
'HTTP_FORWARDED_FOR', |
264
|
|
|
'HTTP_FORWARDED', |
265
|
|
|
'REMOTE_ADDR', |
266
|
|
|
); |
267
|
|
|
|
268
|
|
|
foreach ( $fields as $ip_field ) { |
269
|
|
|
if ( ! empty( $_SERVER[ $ip_field ] ) ) { |
270
|
|
|
return $_SERVER[ $ip_field ]; |
271
|
|
|
} |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
return null; |
275
|
|
|
} |
276
|
|
|
} |
277
|
|
|
|
278
|
|
|
/** |
279
|
|
|
* Leverage backtrace to find caller plugin main file path. |
280
|
|
|
* |
281
|
|
|
* @author Vova Feldman (@svovaf) |
282
|
|
|
* @since 1.0.6 |
283
|
|
|
* |
284
|
|
|
* @return string |
285
|
|
|
*/ |
286
|
|
|
function fs_find_caller_plugin_file() { |
287
|
|
|
/** |
288
|
|
|
* All the code below will be executed once on activation. |
289
|
|
|
* If the user changes the main plugin's file name, the file_exists() |
290
|
|
|
* will catch it. |
291
|
|
|
*/ |
292
|
|
|
if ( ! function_exists( 'get_plugins' ) ) { |
293
|
|
|
require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
294
|
|
|
} |
295
|
|
|
|
296
|
|
|
$all_plugins = get_plugins(); |
297
|
|
|
$all_plugins_paths = array(); |
298
|
|
|
|
299
|
|
|
// Get active plugin's main files real full names (might be symlinks). |
300
|
|
|
foreach ( $all_plugins as $relative_path => &$data ) { |
301
|
|
|
$all_plugins_paths[] = fs_normalize_path( realpath( WP_PLUGIN_DIR . '/' . $relative_path ) ); |
302
|
|
|
} |
303
|
|
|
|
304
|
|
|
$plugin_file = null; |
305
|
|
|
for ( $i = 1, $bt = debug_backtrace(), $len = count( $bt ); $i < $len; $i ++ ) { |
306
|
|
|
if ( empty( $bt[ $i ]['file'] ) ) { |
307
|
|
|
continue; |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
if ( in_array( fs_normalize_path( $bt[ $i ]['file'] ), $all_plugins_paths ) ) { |
311
|
|
|
$plugin_file = $bt[ $i ]['file']; |
312
|
|
|
break; |
313
|
|
|
} |
314
|
|
|
} |
315
|
|
|
|
316
|
|
|
if ( is_null( $plugin_file ) ) { |
317
|
|
|
// Throw an error to the developer in case of some edge case dev environment. |
318
|
|
|
wp_die( |
319
|
|
|
'Freemius SDK couldn\'t find the plugin\'s main file. Please contact [email protected] with the current error.', |
320
|
|
|
'Error', |
321
|
|
|
array( 'back_link' => true ) |
322
|
|
|
); |
323
|
|
|
} |
324
|
|
|
|
325
|
|
|
return $plugin_file; |
326
|
|
|
} |
327
|
|
|
|
328
|
|
|
require_once dirname( __FILE__ ) . '/supplements/fs-essential-functions-1.1.7.1.php'; |
329
|
|
|
|
330
|
|
|
/** |
331
|
|
|
* Update SDK newest version reference. |
332
|
|
|
* |
333
|
|
|
* @author Vova Feldman (@svovaf) |
334
|
|
|
* @since 1.1.6 |
335
|
|
|
* |
336
|
|
|
* @param string $sdk_relative_path |
337
|
|
|
* @param string|bool $plugin_file |
338
|
|
|
* |
339
|
|
|
* @global $fs_active_plugins |
340
|
|
|
*/ |
341
|
|
|
function fs_update_sdk_newest_version( $sdk_relative_path, $plugin_file = false ) { |
342
|
|
|
/** |
343
|
|
|
* If there is a plugin running an older version of FS (1.2.1 or below), the `fs_update_sdk_newest_version()` |
344
|
|
|
* function in the older version will be used instead of this one. But since the older version is using |
345
|
|
|
* the `is_plugin_active` function to check if a plugin is active, passing the theme's `plugin_path` to the |
346
|
|
|
* `is_plugin_active` function will return false since the path is not a plugin path, so `in_activation` will be |
347
|
|
|
* `true` for theme modules and the upgrading of the SDK version to 1.2.2 or newer version will work fine. |
348
|
|
|
* |
349
|
|
|
* Future versions that will call this function will use the proper logic here instead of just relying on the |
350
|
|
|
* `is_plugin_active` function to fail for themes. |
351
|
|
|
* |
352
|
|
|
* @author Leo Fajardo (@leorw) |
353
|
|
|
* @since 1.2.2 |
354
|
|
|
*/ |
355
|
|
|
|
356
|
|
|
global $fs_active_plugins; |
|
|
|
|
357
|
|
|
|
358
|
|
|
$newest_sdk = $fs_active_plugins->plugins[ $sdk_relative_path ]; |
359
|
|
|
|
360
|
|
|
if ( ! is_string( $plugin_file ) ) { |
361
|
|
|
$plugin_file = plugin_basename( fs_find_caller_plugin_file() ); |
362
|
|
|
} |
363
|
|
|
|
364
|
|
|
if ( ! isset( $newest_sdk->type ) || 'theme' !== $newest_sdk->type ) { |
365
|
|
|
$in_activation = ( ! is_plugin_active( $plugin_file ) ); |
366
|
|
|
} else { |
367
|
|
|
$theme = wp_get_theme(); |
368
|
|
|
$in_activation = ( $newest_sdk->plugin_path == $theme->stylesheet ); |
369
|
|
|
} |
370
|
|
|
|
371
|
|
|
$fs_active_plugins->newest = (object) array( |
372
|
|
|
'plugin_path' => $plugin_file, |
373
|
|
|
'sdk_path' => $sdk_relative_path, |
374
|
|
|
'version' => $newest_sdk->version, |
375
|
|
|
'in_activation' => $in_activation, |
376
|
|
|
'timestamp' => time(), |
377
|
|
|
); |
378
|
|
|
|
379
|
|
|
// Update DB with latest SDK version and path. |
380
|
|
|
update_option( 'fs_active_plugins', $fs_active_plugins ); |
381
|
|
|
} |
382
|
|
|
|
383
|
|
|
/** |
384
|
|
|
* Reorder the plugins load order so the plugin with the newest Freemius SDK is loaded first. |
385
|
|
|
* |
386
|
|
|
* @author Vova Feldman (@svovaf) |
387
|
|
|
* @since 1.1.6 |
388
|
|
|
* |
389
|
|
|
* @return bool Was plugin order changed. Return false if plugin was loaded first anyways. |
390
|
|
|
* |
391
|
|
|
* @global $fs_active_plugins |
392
|
|
|
*/ |
393
|
|
|
function fs_newest_sdk_plugin_first() { |
394
|
|
|
global $fs_active_plugins; |
|
|
|
|
395
|
|
|
|
396
|
|
|
/** |
397
|
|
|
* @todo Multi-site network activated plugin are always loaded prior to site plugins so if there's a a plugin activated in the network mode that has an older version of the SDK of another plugin which is site activated that has new SDK version, the fs-essential-functions.php will be loaded from the older SDK. Same thing about MU plugins (loaded even before network activated plugins). |
398
|
|
|
* |
399
|
|
|
* @link https://github.com/Freemius/wordpress-sdk/issues/26 |
400
|
|
|
*/ |
401
|
|
|
// $active_sitewide_plugins = get_site_option( 'active_sitewide_plugins' ); |
|
|
|
|
402
|
|
|
|
403
|
|
|
$active_plugins = get_option( 'active_plugins' ); |
404
|
|
|
$newest_sdk_plugin_key = array_search( $fs_active_plugins->newest->plugin_path, $active_plugins ); |
405
|
|
|
if ( 0 == $newest_sdk_plugin_key ) { |
406
|
|
|
// if it's 0 it's the first plugin already, no need to continue |
407
|
|
|
return false; |
408
|
|
|
} |
409
|
|
|
|
410
|
|
|
array_splice( $active_plugins, $newest_sdk_plugin_key, 1 ); |
411
|
|
|
array_unshift( $active_plugins, $fs_active_plugins->newest->plugin_path ); |
412
|
|
|
update_option( 'active_plugins', $active_plugins ); |
413
|
|
|
|
414
|
|
|
return true; |
415
|
|
|
} |
416
|
|
|
|
417
|
|
|
/** |
418
|
|
|
* Go over all Freemius SDKs in the system and find and "remember" |
419
|
|
|
* the newest SDK which is associated with an active plugin. |
420
|
|
|
* |
421
|
|
|
* @author Vova Feldman (@svovaf) |
422
|
|
|
* @since 1.1.6 |
423
|
|
|
* |
424
|
|
|
* @global $fs_active_plugins |
425
|
|
|
*/ |
426
|
|
|
function fs_fallback_to_newest_active_sdk() { |
427
|
|
|
global $fs_active_plugins; |
|
|
|
|
428
|
|
|
|
429
|
|
|
/** |
430
|
|
|
* @var object $newest_sdk_data |
431
|
|
|
*/ |
432
|
|
|
$newest_sdk_data = null; |
433
|
|
|
$newest_sdk_path = null; |
434
|
|
|
|
435
|
|
|
foreach ( $fs_active_plugins->plugins as $sdk_relative_path => $data ) { |
436
|
|
|
if ( is_null( $newest_sdk_data ) || version_compare( $data->version, $newest_sdk_data->version, '>' ) |
437
|
|
|
) { |
438
|
|
|
// If plugin inactive or SDK starter file doesn't exist, remove SDK reference. |
439
|
|
|
if ( 'plugin' === $data->type ) { |
440
|
|
|
$is_module_active = is_plugin_active( $data->plugin_path ); |
441
|
|
|
} else { |
442
|
|
|
$active_theme = wp_get_theme(); |
443
|
|
|
$is_module_active = ( $data->plugin_path === $active_theme->get_template() ); |
444
|
|
|
} |
445
|
|
|
|
446
|
|
|
$is_sdk_exists = file_exists( fs_normalize_path( WP_PLUGIN_DIR . '/' . $sdk_relative_path . '/start.php' ) ); |
447
|
|
|
|
448
|
|
|
if ( ! $is_module_active || ! $is_sdk_exists ) { |
449
|
|
|
unset( $fs_active_plugins->plugins[ $sdk_relative_path ] ); |
450
|
|
|
|
451
|
|
|
// No need to store the data since it will be stored in fs_update_sdk_newest_version() |
452
|
|
|
// or explicitly with update_option(). |
453
|
|
|
} else { |
454
|
|
|
$newest_sdk_data = $data; |
455
|
|
|
$newest_sdk_path = $sdk_relative_path; |
456
|
|
|
} |
457
|
|
|
} |
458
|
|
|
} |
459
|
|
|
|
460
|
|
|
if ( is_null( $newest_sdk_data ) ) { |
461
|
|
|
// Couldn't find any SDK reference. |
462
|
|
|
$fs_active_plugins = new stdClass(); |
463
|
|
|
update_option( 'fs_active_plugins', $fs_active_plugins ); |
464
|
|
|
} else { |
465
|
|
|
fs_update_sdk_newest_version( $newest_sdk_path, $newest_sdk_data->plugin_path ); |
466
|
|
|
} |
467
|
|
|
} |
468
|
|
|
|
469
|
|
|
#region Actions / Filters ----------------------------------------- |
470
|
|
|
|
471
|
|
|
/** |
472
|
|
|
* Apply filter for specific plugin. |
473
|
|
|
* |
474
|
|
|
* @author Vova Feldman (@svovaf) |
475
|
|
|
* @since 1.0.9 |
476
|
|
|
* |
477
|
|
|
* @param string $module_unique_affix Module's unique affix. |
478
|
|
|
* @param string $tag The name of the filter hook. |
479
|
|
|
* @param mixed $value The value on which the filters hooked to `$tag` are applied on. |
480
|
|
|
* |
481
|
|
|
* @return mixed The filtered value after all hooked functions are applied to it. |
482
|
|
|
* |
483
|
|
|
* @uses apply_filters() |
484
|
|
|
*/ |
485
|
|
|
function fs_apply_filter( $module_unique_affix, $tag, $value ) { |
|
|
|
|
486
|
|
|
$args = func_get_args(); |
487
|
|
|
|
488
|
|
|
return call_user_func_array( 'apply_filters', array_merge( |
489
|
|
|
array( "fs_{$tag}_{$module_unique_affix}" ), |
490
|
|
|
array_slice( $args, 2 ) ) |
491
|
|
|
); |
492
|
|
|
} |
493
|
|
|
|
494
|
|
|
#endregion Actions / Filters ----------------------------------------- |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.