PluginProbe
Age Gate / 3.7.3
Age Gate v3.7.3
3.7.3 trunk 1.0.0 1.0.1 1.1.0 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 1.4.13 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 All 113 releases
age-gate / src / Legacy / Deprecated.php

Deprecated.php in Age Gate 3.7.3, at src/Legacy/Deprecated.php

134 lines 4.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace AgeGate\Legacy;
4
5 use Exception;
6 use AgeGate\Common\Settings;
7
8 require_once dirname(__FILE__) . '/Validation.php';
9
10 class Deprecated
11 {
12 public function __construct()
13 {
14 add_action('age_gate/validation/validators', [$this, 'addLegacyValidators']);
15 add_filter('age_gate/validation/rules', [$this, 'addLegacyRules']);
16
17 if (has_filter('post_age_gate_custom_fields')) {
18 add_action('age_gate/custom/after', [$this, 'addLegacyAfter']);
19 }
20
21 if (has_filter('pre_age_gate_custom_fields')) {
22 add_action('age_gate/custom/before', [$this, 'addLegacyBefore']);
23 }
24 add_filter('age_gate/validation/messages', [$this, 'addLegacyMessages']);
25 add_filter('age_gate/validation/names', [$this, 'addLegacyNames']);
26 add_filter('age_gate/cookie/set', [$this, 'filterLegacyCookie'], 10, 2);
27
28 // restricted filters...
29 add_filter('age_gate/unrestricted/logged', [$this, 'addLegacyLogged'], 1, 3);
30 add_filter('age_gate/restricted', [$this, 'addLegacyRestricted'], 1, 3);
31 add_filter('age_gate/unrestricted', [$this, 'addLegacyUnrestricted'], 1, 3);
32
33 // logo
34 add_filter('age_gate/logo/src', [$this, 'addLegacyLogo'], 1, 2);
35
36 }
37
38 public function addLegacyLogo($logo)
39 {
40 $legacyLogo = apply_filters('age_gate_logo', $logo, $logo);
41
42 preg_match('/src=(?:"|\')(.*?)(?:"|\')/', $legacyLogo, $matches);
43
44 return $matches[1] ?? $logo;
45
46 }
47
48 public function addLegacyValidators($validation)
49 {
50 try {
51 do_action('age_gate_add_validators');
52 } catch(Exception $e) {
53 // dd($e->getMessage());
54 }
55 }
56
57 function addLegacyRules($rules)
58 {
59 return apply_filters('age_gate_validation', $rules);
60 }
61
62 public function addLegacyBefore()
63 {
64 echo wp_kses_post(apply_filters('pre_age_gate_custom_fields', ''));
65 }
66
67 public function addLegacyAfter()
68 {
69 echo wp_kses_post(apply_filters('post_age_gate_custom_fields', ''));
70 }
71
72 public function addLegacyMessages($messages)
73 {
74 return apply_filters('age_gate_validation_messages', $messages);
75 }
76
77 public function addLegacyNames($names)
78 {
79 return apply_filters('age_gate_field_names', $names);
80 }
81
82 public function filterLegacyCookie($set, $remember)
83 {
84 return apply_filters('age_gate_set_cookie', $set, $remember);
85 }
86
87 public function addLegacyLogged($status, $age, $content) {
88 $meta = $this->transformMeta($age, $content);
89 return apply_filters('age_gate_unrestricted_logged_in', $status, $meta);
90 }
91
92 public function addLegacyRestricted($status, $age, $content) {
93 $meta = $this->transformMeta($age, $content);
94 return apply_filters('age_gate_restricted', $status, $meta);
95 }
96
97 public function addLegacyUnrestricted($status, $age, $content) {
98 $meta = $this->transformMeta($age, $content);
99 return apply_filters('age_gate_unrestricted_unrestricted', $status, $meta);
100 }
101
102 private function transformMeta($age, $content)
103 {
104 $settings = Settings::getInstance();
105 $data = (object) [
106 'age' => $content->getAge(),
107 'type' => $content->getType(),
108 'bypass' => $content->getBypass(),
109 'restrict' => $content->getRestricted(),
110 'restrictions' => (object) [
111 'min_age' => $settings->defaultAge,
112 'restriction_type' => $settings->type,
113 'multi_age' => $settings->multiAge,
114 'restrict_register' => false,
115 'input_type' => $settings->inputType,
116 'stepped' => $settings->stepped,
117 'button_order' => $settings->buttonOrder,
118 'inherit_category' => $settings->inherit,
119 'remember' => $settings->remember,
120 'remember_days' => $settings->rememberLength,
121 'remember_timescale' => $settings->rememberTime,
122 'remember_auto_check' => $settings->rememberAutoCheck,
123 'date_format' => strtolower(str_replace(' ', '', $settings->dateFormat)), //'ddmmyyyy',
124 'ignore_logged' => $settings->ignoreLogged,
125 'rechallenge' => $settings->rechallenge,
126 'fail_link_title' => '',
127 'fail_link' => $settings->redirect,
128 ]
129 ];
130
131 return $data;
132 }
133 }
134