Completed
Branch fix-ticket-selector (6e20e7)
by
unknown
73:30 queued 64:12
created
core/domain/values/FilePath.php 2 patches
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -20,42 +20,42 @@
 block discarded – undo
20 20
 class FilePath
21 21
 {
22 22
 
23
-    /**
24
-     * @var string file_path
25
-     */
26
-    private $file_path;
27
-
28
-
29
-    /**
30
-     * FilePath constructor.
31
-     *
32
-     * @param string $file_path
33
-     * @throws InvalidDataTypeException
34
-     * @throws InvalidFilePathException
35
-     */
36
-    public function __construct($file_path)
37
-    {
38
-        if (! is_string($file_path)) {
39
-            throw new InvalidDataTypeException(
40
-                '$file_path',
41
-                $file_path,
42
-                'string'
43
-            );
44
-        }
45
-        if (! is_readable($file_path)) {
46
-            throw new InvalidFilePathException($file_path);
47
-        }
48
-        $this->file_path = $file_path;
49
-    }
50
-
51
-
52
-    /**
53
-     * @return string
54
-     */
55
-    public function __toString()
56
-    {
57
-        return $this->file_path;
58
-    }
23
+	/**
24
+	 * @var string file_path
25
+	 */
26
+	private $file_path;
27
+
28
+
29
+	/**
30
+	 * FilePath constructor.
31
+	 *
32
+	 * @param string $file_path
33
+	 * @throws InvalidDataTypeException
34
+	 * @throws InvalidFilePathException
35
+	 */
36
+	public function __construct($file_path)
37
+	{
38
+		if (! is_string($file_path)) {
39
+			throw new InvalidDataTypeException(
40
+				'$file_path',
41
+				$file_path,
42
+				'string'
43
+			);
44
+		}
45
+		if (! is_readable($file_path)) {
46
+			throw new InvalidFilePathException($file_path);
47
+		}
48
+		$this->file_path = $file_path;
49
+	}
50
+
51
+
52
+	/**
53
+	 * @return string
54
+	 */
55
+	public function __toString()
56
+	{
57
+		return $this->file_path;
58
+	}
59 59
 
60 60
 
61 61
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -35,14 +35,14 @@
 block discarded – undo
35 35
      */
36 36
     public function __construct($file_path)
37 37
     {
38
-        if (! is_string($file_path)) {
38
+        if ( ! is_string($file_path)) {
39 39
             throw new InvalidDataTypeException(
40 40
                 '$file_path',
41 41
                 $file_path,
42 42
                 'string'
43 43
             );
44 44
         }
45
-        if (! is_readable($file_path)) {
45
+        if ( ! is_readable($file_path)) {
46 46
             throw new InvalidFilePathException($file_path);
47 47
         }
48 48
         $this->file_path = $file_path;
Please login to merge, or discard this patch.
core/domain/values/FullyQualifiedName.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -37,14 +37,14 @@
 block discarded – undo
37 37
      */
38 38
     public function __construct($fully_qualified_name)
39 39
     {
40
-        if (! is_string($fully_qualified_name)) {
40
+        if ( ! is_string($fully_qualified_name)) {
41 41
             throw new InvalidDataTypeException(
42 42
                 '$fully_qualified_name',
43 43
                 $fully_qualified_name,
44 44
                 'string'
45 45
             );
46 46
         }
47
-        if (! class_exists($fully_qualified_name) && ! interface_exists($fully_qualified_name)) {
47
+        if ( ! class_exists($fully_qualified_name) && ! interface_exists($fully_qualified_name)) {
48 48
             if (strpos($fully_qualified_name, 'Interface') !== false) {
49 49
                 throw new InvalidInterfaceException($fully_qualified_name);
50 50
             }
Please login to merge, or discard this patch.
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -21,54 +21,54 @@
 block discarded – undo
21 21
 class FullyQualifiedName
22 22
 {
23 23
 
24
-    /**
25
-     * @var string $fully_qualified_name
26
-     */
27
-    private $fully_qualified_name;
24
+	/**
25
+	 * @var string $fully_qualified_name
26
+	 */
27
+	private $fully_qualified_name;
28 28
 
29 29
 
30
-    /**
31
-     * FullyQualifiedName constructor.
32
-     *
33
-     * @param string $fully_qualified_name
34
-     * @throws InvalidClassException
35
-     * @throws InvalidInterfaceException
36
-     * @throws InvalidDataTypeException
37
-     */
38
-    public function __construct($fully_qualified_name)
39
-    {
40
-        if (! is_string($fully_qualified_name)) {
41
-            throw new InvalidDataTypeException(
42
-                '$fully_qualified_name',
43
-                $fully_qualified_name,
44
-                'string'
45
-            );
46
-        }
47
-        if (! class_exists($fully_qualified_name) && ! interface_exists($fully_qualified_name)) {
48
-            if (strpos($fully_qualified_name, 'Interface') !== false) {
49
-                throw new InvalidInterfaceException($fully_qualified_name);
50
-            }
51
-            throw new InvalidClassException($fully_qualified_name);
52
-        }
53
-        $this->fully_qualified_name = $fully_qualified_name;
54
-    }
30
+	/**
31
+	 * FullyQualifiedName constructor.
32
+	 *
33
+	 * @param string $fully_qualified_name
34
+	 * @throws InvalidClassException
35
+	 * @throws InvalidInterfaceException
36
+	 * @throws InvalidDataTypeException
37
+	 */
38
+	public function __construct($fully_qualified_name)
39
+	{
40
+		if (! is_string($fully_qualified_name)) {
41
+			throw new InvalidDataTypeException(
42
+				'$fully_qualified_name',
43
+				$fully_qualified_name,
44
+				'string'
45
+			);
46
+		}
47
+		if (! class_exists($fully_qualified_name) && ! interface_exists($fully_qualified_name)) {
48
+			if (strpos($fully_qualified_name, 'Interface') !== false) {
49
+				throw new InvalidInterfaceException($fully_qualified_name);
50
+			}
51
+			throw new InvalidClassException($fully_qualified_name);
52
+		}
53
+		$this->fully_qualified_name = $fully_qualified_name;
54
+	}
55 55
 
56 56
 
57
-    /**
58
-     * @return string
59
-     */
60
-    public function string()
61
-    {
62
-        return $this->fully_qualified_name;
63
-    }
57
+	/**
58
+	 * @return string
59
+	 */
60
+	public function string()
61
+	{
62
+		return $this->fully_qualified_name;
63
+	}
64 64
 
65 65
 
66
-    /**
67
-     * @return string
68
-     */
69
-    public function __toString()
70
-    {
71
-        return $this->fully_qualified_name;
72
-    }
66
+	/**
67
+	 * @return string
68
+	 */
69
+	public function __toString()
70
+	{
71
+		return $this->fully_qualified_name;
72
+	}
73 73
 
74 74
 }
Please login to merge, or discard this patch.
core/domain/DomainBase.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -121,7 +121,7 @@
 block discarded – undo
121 121
 
122 122
 
123 123
     /**
124
-     * @return Version
124
+     * @return string
125 125
      */
126 126
     public function versionValueObject()
127 127
     {
Please login to merge, or discard this patch.
Indentation   +215 added lines, -215 removed lines patch added patch discarded remove patch
@@ -17,219 +17,219 @@
 block discarded – undo
17 17
 abstract class DomainBase implements DomainInterface
18 18
 {
19 19
 
20
-    const ASSETS_FOLDER = 'assets/';
21
-
22
-    /**
23
-     * Equivalent to `__FILE__` for main plugin file.
24
-     *
25
-     * @var FilePath
26
-     */
27
-    private $plugin_file;
28
-
29
-    /**
30
-     * String indicating version for plugin
31
-     *
32
-     * @var string
33
-     */
34
-    private $version;
35
-
36
-    /**
37
-     * @var string $plugin_basename
38
-     */
39
-    private $plugin_basename;
40
-
41
-    /**
42
-     * @var string $plugin_path
43
-     */
44
-    private $plugin_path;
45
-
46
-    /**
47
-     * @var string $plugin_url
48
-     */
49
-    private $plugin_url;
50
-
51
-    /**
52
-     * @var string $asset_namespace
53
-     */
54
-    private $asset_namespace;
55
-
56
-    /**
57
-     * @var string $assets_path
58
-     */
59
-    private $assets_path;
60
-
61
-    /**
62
-     * @var bool
63
-     */
64
-    protected $initialized = false;
65
-
66
-
67
-    /**
68
-     * Initializes internal properties.
69
-     *
70
-     * @param FilePath $plugin_file
71
-     * @param Version  $version
72
-     * @param string $asset_namespace
73
-     */
74
-    public function __construct(FilePath $plugin_file, Version $version, $asset_namespace = Domain::ASSET_NAMESPACE)
75
-    {
76
-        $this->plugin_file = $plugin_file;
77
-        $this->version     = $version;
78
-        $this->initialize($asset_namespace);
79
-    }
80
-
81
-
82
-    /**
83
-     * @param string $asset_namespace
84
-     * @return void
85
-     * @since $VID:$
86
-     */
87
-    public function initialize($asset_namespace = Domain::ASSET_NAMESPACE)
88
-    {
89
-        if (! $this->initialized) {
90
-            $this->plugin_basename = plugin_basename($this->pluginFile());
91
-            $this->plugin_path     = plugin_dir_path($this->pluginFile());
92
-            $this->plugin_url      = plugin_dir_url($this->pluginFile());
93
-            $this->setAssetNamespace($asset_namespace);
94
-            $this->setDistributionAssetsPath();
95
-            $this->initialized = true;
96
-        }
97
-    }
98
-
99
-
100
-    /**
101
-     * @param string $asset_namespace
102
-     * @return void
103
-     */
104
-    public function setAssetNamespace($asset_namespace = Domain::ASSET_NAMESPACE)
105
-    {
106
-        if (! $this->asset_namespace) {
107
-            $this->asset_namespace = sanitize_key(
108
-                // convert directory separators to dashes and remove file extension
109
-                str_replace(['/', '.php'], ['-', ''], $asset_namespace)
110
-            );
111
-        }
112
-    }
113
-
114
-
115
-    /**
116
-     * @throws DomainException
117
-     * @since $VID:$
118
-     */
119
-    private function setDistributionAssetsPath()
120
-    {
121
-        $assets_folder_paths = [
122
-            $this->plugin_path . DomainBase::ASSETS_FOLDER,
123
-            $this->plugin_path . 'src/' . DomainBase::ASSETS_FOLDER,
124
-        ];
125
-        foreach ($assets_folder_paths as $assets_folder_path) {
126
-            if (is_readable($assets_folder_path)) {
127
-                $this->assets_path = trailingslashit($assets_folder_path);
128
-                // once we find a valid path, just break out of loop
129
-                break;
130
-            }
131
-        }
132
-    }
133
-
134
-
135
-    /**
136
-     * @return string
137
-     */
138
-    public function pluginFile()
139
-    {
140
-        return (string) $this->plugin_file;
141
-    }
142
-
143
-
144
-    /**
145
-     * @return string
146
-     */
147
-    public function pluginBasename()
148
-    {
149
-        return $this->plugin_basename;
150
-    }
151
-
152
-
153
-    /**
154
-     * @param string $additional_path
155
-     * @return string
156
-     */
157
-    public function pluginPath($additional_path = '')
158
-    {
159
-        return is_string($additional_path) && $additional_path !== ''
160
-            ? $this->plugin_path . $additional_path
161
-            : $this->plugin_path;
162
-    }
163
-
164
-
165
-    /**
166
-     * @param string $additional_path
167
-     * @return string
168
-     */
169
-    public function pluginUrl($additional_path = '')
170
-    {
171
-        return is_string($additional_path) && $additional_path !== ''
172
-            ? $this->plugin_url . $additional_path
173
-            : $this->plugin_url;
174
-    }
175
-
176
-
177
-    /**
178
-     * @return string
179
-     */
180
-    public function version()
181
-    {
182
-        return (string) $this->version;
183
-    }
184
-
185
-
186
-    /**
187
-     * @return Version
188
-     */
189
-    public function versionValueObject()
190
-    {
191
-        return $this->version;
192
-    }
193
-
194
-
195
-    /**
196
-     * @return string
197
-     */
198
-    public function distributionAssetsFolder()
199
-    {
200
-        return DomainBase::ASSETS_FOLDER;
201
-    }
202
-
203
-
204
-    /**
205
-     * @param string $additional_path
206
-     * @return string
207
-     */
208
-    public function distributionAssetsPath($additional_path = '')
209
-    {
210
-        return is_string($additional_path) && $additional_path !== ''
211
-            ? $this->assets_path . $additional_path
212
-            : $this->assets_path;
213
-    }
214
-
215
-
216
-    /**
217
-     * @param string $additional_path
218
-     * @return string
219
-     */
220
-    public function distributionAssetsUrl($additional_path = '')
221
-    {
222
-        return is_string($additional_path) && $additional_path !== ''
223
-            ? $this->plugin_url . DomainBase::ASSETS_FOLDER . $additional_path
224
-            : $this->plugin_url . DomainBase::ASSETS_FOLDER;
225
-    }
226
-
227
-
228
-    /**
229
-     * @return string
230
-     */
231
-    public function assetNamespace()
232
-    {
233
-        return $this->asset_namespace;
234
-    }
20
+	const ASSETS_FOLDER = 'assets/';
21
+
22
+	/**
23
+	 * Equivalent to `__FILE__` for main plugin file.
24
+	 *
25
+	 * @var FilePath
26
+	 */
27
+	private $plugin_file;
28
+
29
+	/**
30
+	 * String indicating version for plugin
31
+	 *
32
+	 * @var string
33
+	 */
34
+	private $version;
35
+
36
+	/**
37
+	 * @var string $plugin_basename
38
+	 */
39
+	private $plugin_basename;
40
+
41
+	/**
42
+	 * @var string $plugin_path
43
+	 */
44
+	private $plugin_path;
45
+
46
+	/**
47
+	 * @var string $plugin_url
48
+	 */
49
+	private $plugin_url;
50
+
51
+	/**
52
+	 * @var string $asset_namespace
53
+	 */
54
+	private $asset_namespace;
55
+
56
+	/**
57
+	 * @var string $assets_path
58
+	 */
59
+	private $assets_path;
60
+
61
+	/**
62
+	 * @var bool
63
+	 */
64
+	protected $initialized = false;
65
+
66
+
67
+	/**
68
+	 * Initializes internal properties.
69
+	 *
70
+	 * @param FilePath $plugin_file
71
+	 * @param Version  $version
72
+	 * @param string $asset_namespace
73
+	 */
74
+	public function __construct(FilePath $plugin_file, Version $version, $asset_namespace = Domain::ASSET_NAMESPACE)
75
+	{
76
+		$this->plugin_file = $plugin_file;
77
+		$this->version     = $version;
78
+		$this->initialize($asset_namespace);
79
+	}
80
+
81
+
82
+	/**
83
+	 * @param string $asset_namespace
84
+	 * @return void
85
+	 * @since $VID:$
86
+	 */
87
+	public function initialize($asset_namespace = Domain::ASSET_NAMESPACE)
88
+	{
89
+		if (! $this->initialized) {
90
+			$this->plugin_basename = plugin_basename($this->pluginFile());
91
+			$this->plugin_path     = plugin_dir_path($this->pluginFile());
92
+			$this->plugin_url      = plugin_dir_url($this->pluginFile());
93
+			$this->setAssetNamespace($asset_namespace);
94
+			$this->setDistributionAssetsPath();
95
+			$this->initialized = true;
96
+		}
97
+	}
98
+
99
+
100
+	/**
101
+	 * @param string $asset_namespace
102
+	 * @return void
103
+	 */
104
+	public function setAssetNamespace($asset_namespace = Domain::ASSET_NAMESPACE)
105
+	{
106
+		if (! $this->asset_namespace) {
107
+			$this->asset_namespace = sanitize_key(
108
+				// convert directory separators to dashes and remove file extension
109
+				str_replace(['/', '.php'], ['-', ''], $asset_namespace)
110
+			);
111
+		}
112
+	}
113
+
114
+
115
+	/**
116
+	 * @throws DomainException
117
+	 * @since $VID:$
118
+	 */
119
+	private function setDistributionAssetsPath()
120
+	{
121
+		$assets_folder_paths = [
122
+			$this->plugin_path . DomainBase::ASSETS_FOLDER,
123
+			$this->plugin_path . 'src/' . DomainBase::ASSETS_FOLDER,
124
+		];
125
+		foreach ($assets_folder_paths as $assets_folder_path) {
126
+			if (is_readable($assets_folder_path)) {
127
+				$this->assets_path = trailingslashit($assets_folder_path);
128
+				// once we find a valid path, just break out of loop
129
+				break;
130
+			}
131
+		}
132
+	}
133
+
134
+
135
+	/**
136
+	 * @return string
137
+	 */
138
+	public function pluginFile()
139
+	{
140
+		return (string) $this->plugin_file;
141
+	}
142
+
143
+
144
+	/**
145
+	 * @return string
146
+	 */
147
+	public function pluginBasename()
148
+	{
149
+		return $this->plugin_basename;
150
+	}
151
+
152
+
153
+	/**
154
+	 * @param string $additional_path
155
+	 * @return string
156
+	 */
157
+	public function pluginPath($additional_path = '')
158
+	{
159
+		return is_string($additional_path) && $additional_path !== ''
160
+			? $this->plugin_path . $additional_path
161
+			: $this->plugin_path;
162
+	}
163
+
164
+
165
+	/**
166
+	 * @param string $additional_path
167
+	 * @return string
168
+	 */
169
+	public function pluginUrl($additional_path = '')
170
+	{
171
+		return is_string($additional_path) && $additional_path !== ''
172
+			? $this->plugin_url . $additional_path
173
+			: $this->plugin_url;
174
+	}
175
+
176
+
177
+	/**
178
+	 * @return string
179
+	 */
180
+	public function version()
181
+	{
182
+		return (string) $this->version;
183
+	}
184
+
185
+
186
+	/**
187
+	 * @return Version
188
+	 */
189
+	public function versionValueObject()
190
+	{
191
+		return $this->version;
192
+	}
193
+
194
+
195
+	/**
196
+	 * @return string
197
+	 */
198
+	public function distributionAssetsFolder()
199
+	{
200
+		return DomainBase::ASSETS_FOLDER;
201
+	}
202
+
203
+
204
+	/**
205
+	 * @param string $additional_path
206
+	 * @return string
207
+	 */
208
+	public function distributionAssetsPath($additional_path = '')
209
+	{
210
+		return is_string($additional_path) && $additional_path !== ''
211
+			? $this->assets_path . $additional_path
212
+			: $this->assets_path;
213
+	}
214
+
215
+
216
+	/**
217
+	 * @param string $additional_path
218
+	 * @return string
219
+	 */
220
+	public function distributionAssetsUrl($additional_path = '')
221
+	{
222
+		return is_string($additional_path) && $additional_path !== ''
223
+			? $this->plugin_url . DomainBase::ASSETS_FOLDER . $additional_path
224
+			: $this->plugin_url . DomainBase::ASSETS_FOLDER;
225
+	}
226
+
227
+
228
+	/**
229
+	 * @return string
230
+	 */
231
+	public function assetNamespace()
232
+	{
233
+		return $this->asset_namespace;
234
+	}
235 235
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
      */
87 87
     public function initialize($asset_namespace = Domain::ASSET_NAMESPACE)
88 88
     {
89
-        if (! $this->initialized) {
89
+        if ( ! $this->initialized) {
90 90
             $this->plugin_basename = plugin_basename($this->pluginFile());
91 91
             $this->plugin_path     = plugin_dir_path($this->pluginFile());
92 92
             $this->plugin_url      = plugin_dir_url($this->pluginFile());
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
      */
104 104
     public function setAssetNamespace($asset_namespace = Domain::ASSET_NAMESPACE)
105 105
     {
106
-        if (! $this->asset_namespace) {
106
+        if ( ! $this->asset_namespace) {
107 107
             $this->asset_namespace = sanitize_key(
108 108
                 // convert directory separators to dashes and remove file extension
109 109
                 str_replace(['/', '.php'], ['-', ''], $asset_namespace)
@@ -119,8 +119,8 @@  discard block
 block discarded – undo
119 119
     private function setDistributionAssetsPath()
120 120
     {
121 121
         $assets_folder_paths = [
122
-            $this->plugin_path . DomainBase::ASSETS_FOLDER,
123
-            $this->plugin_path . 'src/' . DomainBase::ASSETS_FOLDER,
122
+            $this->plugin_path.DomainBase::ASSETS_FOLDER,
123
+            $this->plugin_path.'src/'.DomainBase::ASSETS_FOLDER,
124 124
         ];
125 125
         foreach ($assets_folder_paths as $assets_folder_path) {
126 126
             if (is_readable($assets_folder_path)) {
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
     public function pluginPath($additional_path = '')
158 158
     {
159 159
         return is_string($additional_path) && $additional_path !== ''
160
-            ? $this->plugin_path . $additional_path
160
+            ? $this->plugin_path.$additional_path
161 161
             : $this->plugin_path;
162 162
     }
163 163
 
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
     public function pluginUrl($additional_path = '')
170 170
     {
171 171
         return is_string($additional_path) && $additional_path !== ''
172
-            ? $this->plugin_url . $additional_path
172
+            ? $this->plugin_url.$additional_path
173 173
             : $this->plugin_url;
174 174
     }
175 175
 
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
     public function distributionAssetsPath($additional_path = '')
209 209
     {
210 210
         return is_string($additional_path) && $additional_path !== ''
211
-            ? $this->assets_path . $additional_path
211
+            ? $this->assets_path.$additional_path
212 212
             : $this->assets_path;
213 213
     }
214 214
 
@@ -220,8 +220,8 @@  discard block
 block discarded – undo
220 220
     public function distributionAssetsUrl($additional_path = '')
221 221
     {
222 222
         return is_string($additional_path) && $additional_path !== ''
223
-            ? $this->plugin_url . DomainBase::ASSETS_FOLDER . $additional_path
224
-            : $this->plugin_url . DomainBase::ASSETS_FOLDER;
223
+            ? $this->plugin_url.DomainBase::ASSETS_FOLDER.$additional_path
224
+            : $this->plugin_url.DomainBase::ASSETS_FOLDER;
225 225
     }
226 226
 
227 227
 
Please login to merge, or discard this patch.
core/domain/entities/contexts/RequestTypeContext.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -91,7 +91,7 @@
 block discarded – undo
91 91
     public function __construct($slug, $description)
92 92
     {
93 93
         parent::__construct($slug, $description);
94
-        if (! in_array($this->slug(), $this->validRequestTypes(), true)) {
94
+        if ( ! in_array($this->slug(), $this->validRequestTypes(), true)) {
95 95
             throw new InvalidArgumentException(
96 96
                 sprintf(
97 97
                     esc_html__(
Please login to merge, or discard this patch.
Indentation   +181 added lines, -181 removed lines patch added patch discarded remove patch
@@ -16,185 +16,185 @@
 block discarded – undo
16 16
 class RequestTypeContext extends Context
17 17
 {
18 18
 
19
-    /**
20
-     * indicates that the current request involves some form of activation
21
-     */
22
-    const ACTIVATION = 'activation-request';
23
-
24
-    /**
25
-     * indicates that the current request is for the admin but is not being made via AJAX
26
-     */
27
-    const ADMIN = 'non-ajax-admin-request';
28
-
29
-    /**
30
-     * indicates that the current request is for the admin AND is being made via AJAX
31
-     */
32
-    const AJAX_ADMIN = 'admin-ajax-request';
33
-
34
-    /**
35
-     * indicates that the current request is for the frontend AND is being made via AJAX
36
-     */
37
-    const AJAX_FRONT = 'frontend-ajax-request';
38
-
39
-    /**
40
-     * indicates that the current request is for the WP Heartbeat
41
-     */
42
-    const AJAX_HEARTBEAT = 'admin-ajax-heartbeat';
43
-
44
-    /**
45
-     * indicates that the current request is being made via AJAX, but is NOT for EE
46
-     */
47
-    const AJAX_OTHER = 'other-ajax-request';
48
-
49
-    /**
50
-     * indicates that the current request is for the EE REST API
51
-     */
52
-    const API = 'rest-api';
53
-
54
-    /**
55
-     * indicates that the current request is from the command line
56
-     */
57
-    const CLI = 'command-line';
58
-
59
-    /**
60
-     * indicates that the current request is for a WP_Cron
61
-     */
62
-    const CRON = 'wp-cron';
63
-
64
-    /**
65
-     * indicates that the current request is for a feed (ie: RSS)
66
-     */
67
-    const FEED = 'feed-request';
68
-
69
-    /**
70
-     * indicates that the current request is for the frontend but is not being made via AJAX
71
-     */
72
-    const FRONTEND = 'non-ajax-frontend-request';
73
-
74
-    /**
75
-     * indicates that the current request is for content that is to be displayed within an iframe
76
-     */
77
-    const IFRAME = 'iframe-request';
78
-
79
-    /**
80
-     * indicates that the current request is for the EE GraphQL manager
81
-     */
82
-    const GQL = 'graphql';
83
-
84
-    /**
85
-     * indicates that the current request is for the WP REST API
86
-     */
87
-    const WP_API = 'wp-rest-api';
88
-
89
-    /**
90
-     * indicates that the current request is a loopback sent from WP core to test for errors
91
-     */
92
-    const WP_SCRAPE = 'wordpress-scrape';
93
-
94
-    /**
95
-     * @var boolean $is_activation
96
-     */
97
-    private $is_activation = false;
98
-
99
-    /**
100
-     * @var boolean $is_unit_testing
101
-     */
102
-    private $is_unit_testing = false;
103
-
104
-    /**
105
-     * @var array $valid_request_types
106
-     */
107
-    private $valid_request_types = array();
108
-
109
-
110
-    /**
111
-     * RequestTypeContext constructor.
112
-     *
113
-     * @param string $slug
114
-     * @param string $description
115
-     * @throws InvalidArgumentException
116
-     */
117
-    public function __construct($slug, $description)
118
-    {
119
-        parent::__construct($slug, $description);
120
-        if (! in_array($this->slug(), $this->validRequestTypes(), true)) {
121
-            throw new InvalidArgumentException(
122
-                sprintf(
123
-                    esc_html__(
124
-                        'The RequestTypeContext slug must be one of the following values: %1$s %2$s',
125
-                        'event_espresso'
126
-                    ),
127
-                    '<br />',
128
-                    var_export($this->validRequestTypes(), true)
129
-                )
130
-            );
131
-        }
132
-    }
133
-
134
-
135
-    /**
136
-     * @return array
137
-     */
138
-    public function validRequestTypes()
139
-    {
140
-        if (empty($this->valid_request_types)) {
141
-            $this->valid_request_types = apply_filters(
142
-                'FHEE__EventEspresso_core_domain_entities_contexts_RequestTypeContext__validRequestTypes',
143
-                array(
144
-                    RequestTypeContext::ACTIVATION,
145
-                    RequestTypeContext::ADMIN,
146
-                    RequestTypeContext::AJAX_ADMIN,
147
-                    RequestTypeContext::AJAX_FRONT,
148
-                    RequestTypeContext::AJAX_HEARTBEAT,
149
-                    RequestTypeContext::AJAX_OTHER,
150
-                    RequestTypeContext::API,
151
-                    RequestTypeContext::CLI,
152
-                    RequestTypeContext::CRON,
153
-                    RequestTypeContext::FEED,
154
-                    RequestTypeContext::FRONTEND,
155
-                    RequestTypeContext::GQL,
156
-                    RequestTypeContext::IFRAME,
157
-                    RequestTypeContext::WP_API,
158
-                    RequestTypeContext::WP_SCRAPE,
159
-                )
160
-            );
161
-        }
162
-        return $this->valid_request_types;
163
-    }
164
-
165
-
166
-    /**
167
-     * @return bool
168
-     */
169
-    public function isActivation()
170
-    {
171
-        return $this->is_activation;
172
-    }
173
-
174
-
175
-    /**
176
-     * @param bool $is_activation
177
-     */
178
-    public function setIsActivation($is_activation = false)
179
-    {
180
-        $this->is_activation = filter_var($is_activation, FILTER_VALIDATE_BOOLEAN);
181
-    }
182
-
183
-
184
-    /**
185
-     * @return bool
186
-     */
187
-    public function isUnitTesting()
188
-    {
189
-        return $this->is_unit_testing;
190
-    }
191
-
192
-
193
-    /**
194
-     * @param bool $is_unit_testing
195
-     */
196
-    public function setIsUnitTesting($is_unit_testing = false)
197
-    {
198
-        $this->is_unit_testing = filter_var($is_unit_testing, FILTER_VALIDATE_BOOLEAN);
199
-    }
19
+	/**
20
+	 * indicates that the current request involves some form of activation
21
+	 */
22
+	const ACTIVATION = 'activation-request';
23
+
24
+	/**
25
+	 * indicates that the current request is for the admin but is not being made via AJAX
26
+	 */
27
+	const ADMIN = 'non-ajax-admin-request';
28
+
29
+	/**
30
+	 * indicates that the current request is for the admin AND is being made via AJAX
31
+	 */
32
+	const AJAX_ADMIN = 'admin-ajax-request';
33
+
34
+	/**
35
+	 * indicates that the current request is for the frontend AND is being made via AJAX
36
+	 */
37
+	const AJAX_FRONT = 'frontend-ajax-request';
38
+
39
+	/**
40
+	 * indicates that the current request is for the WP Heartbeat
41
+	 */
42
+	const AJAX_HEARTBEAT = 'admin-ajax-heartbeat';
43
+
44
+	/**
45
+	 * indicates that the current request is being made via AJAX, but is NOT for EE
46
+	 */
47
+	const AJAX_OTHER = 'other-ajax-request';
48
+
49
+	/**
50
+	 * indicates that the current request is for the EE REST API
51
+	 */
52
+	const API = 'rest-api';
53
+
54
+	/**
55
+	 * indicates that the current request is from the command line
56
+	 */
57
+	const CLI = 'command-line';
58
+
59
+	/**
60
+	 * indicates that the current request is for a WP_Cron
61
+	 */
62
+	const CRON = 'wp-cron';
63
+
64
+	/**
65
+	 * indicates that the current request is for a feed (ie: RSS)
66
+	 */
67
+	const FEED = 'feed-request';
68
+
69
+	/**
70
+	 * indicates that the current request is for the frontend but is not being made via AJAX
71
+	 */
72
+	const FRONTEND = 'non-ajax-frontend-request';
73
+
74
+	/**
75
+	 * indicates that the current request is for content that is to be displayed within an iframe
76
+	 */
77
+	const IFRAME = 'iframe-request';
78
+
79
+	/**
80
+	 * indicates that the current request is for the EE GraphQL manager
81
+	 */
82
+	const GQL = 'graphql';
83
+
84
+	/**
85
+	 * indicates that the current request is for the WP REST API
86
+	 */
87
+	const WP_API = 'wp-rest-api';
88
+
89
+	/**
90
+	 * indicates that the current request is a loopback sent from WP core to test for errors
91
+	 */
92
+	const WP_SCRAPE = 'wordpress-scrape';
93
+
94
+	/**
95
+	 * @var boolean $is_activation
96
+	 */
97
+	private $is_activation = false;
98
+
99
+	/**
100
+	 * @var boolean $is_unit_testing
101
+	 */
102
+	private $is_unit_testing = false;
103
+
104
+	/**
105
+	 * @var array $valid_request_types
106
+	 */
107
+	private $valid_request_types = array();
108
+
109
+
110
+	/**
111
+	 * RequestTypeContext constructor.
112
+	 *
113
+	 * @param string $slug
114
+	 * @param string $description
115
+	 * @throws InvalidArgumentException
116
+	 */
117
+	public function __construct($slug, $description)
118
+	{
119
+		parent::__construct($slug, $description);
120
+		if (! in_array($this->slug(), $this->validRequestTypes(), true)) {
121
+			throw new InvalidArgumentException(
122
+				sprintf(
123
+					esc_html__(
124
+						'The RequestTypeContext slug must be one of the following values: %1$s %2$s',
125
+						'event_espresso'
126
+					),
127
+					'<br />',
128
+					var_export($this->validRequestTypes(), true)
129
+				)
130
+			);
131
+		}
132
+	}
133
+
134
+
135
+	/**
136
+	 * @return array
137
+	 */
138
+	public function validRequestTypes()
139
+	{
140
+		if (empty($this->valid_request_types)) {
141
+			$this->valid_request_types = apply_filters(
142
+				'FHEE__EventEspresso_core_domain_entities_contexts_RequestTypeContext__validRequestTypes',
143
+				array(
144
+					RequestTypeContext::ACTIVATION,
145
+					RequestTypeContext::ADMIN,
146
+					RequestTypeContext::AJAX_ADMIN,
147
+					RequestTypeContext::AJAX_FRONT,
148
+					RequestTypeContext::AJAX_HEARTBEAT,
149
+					RequestTypeContext::AJAX_OTHER,
150
+					RequestTypeContext::API,
151
+					RequestTypeContext::CLI,
152
+					RequestTypeContext::CRON,
153
+					RequestTypeContext::FEED,
154
+					RequestTypeContext::FRONTEND,
155
+					RequestTypeContext::GQL,
156
+					RequestTypeContext::IFRAME,
157
+					RequestTypeContext::WP_API,
158
+					RequestTypeContext::WP_SCRAPE,
159
+				)
160
+			);
161
+		}
162
+		return $this->valid_request_types;
163
+	}
164
+
165
+
166
+	/**
167
+	 * @return bool
168
+	 */
169
+	public function isActivation()
170
+	{
171
+		return $this->is_activation;
172
+	}
173
+
174
+
175
+	/**
176
+	 * @param bool $is_activation
177
+	 */
178
+	public function setIsActivation($is_activation = false)
179
+	{
180
+		$this->is_activation = filter_var($is_activation, FILTER_VALIDATE_BOOLEAN);
181
+	}
182
+
183
+
184
+	/**
185
+	 * @return bool
186
+	 */
187
+	public function isUnitTesting()
188
+	{
189
+		return $this->is_unit_testing;
190
+	}
191
+
192
+
193
+	/**
194
+	 * @param bool $is_unit_testing
195
+	 */
196
+	public function setIsUnitTesting($is_unit_testing = false)
197
+	{
198
+		$this->is_unit_testing = filter_var($is_unit_testing, FILTER_VALIDATE_BOOLEAN);
199
+	}
200 200
 }
Please login to merge, or discard this patch.
core/helpers/EEH_URL.helper.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -251,7 +251,7 @@
 block discarded – undo
251 251
     /**
252 252
      * Identical in functionality to EEH_current_url except it removes any provided query_parameters from it.
253 253
      *
254
-     * @param array $query_parameters An array of query_parameters to remove from the current url.
254
+     * @param string[] $query_parameters An array of query_parameters to remove from the current url.
255 255
      * @since 4.9.46.rc.029
256 256
      * @return string
257 257
      */
Please login to merge, or discard this patch.
Indentation   +245 added lines, -245 removed lines patch added patch discarded remove patch
@@ -12,270 +12,270 @@
 block discarded – undo
12 12
 class EEH_URL
13 13
 {
14 14
 
15
-    /**
16
-     * _add_query_arg
17
-     * adds nonce to array of arguments then calls WP add_query_arg function
18
-     *
19
-     * @access public
20
-     * @param array  $args
21
-     * @param string $url
22
-     * @param bool   $exclude_nonce If true then the nonce will be excluded from the generated url.
23
-     * @return string
24
-     */
25
-    public static function add_query_args_and_nonce($args = array(), $url = '', $exclude_nonce = false)
26
-    {
27
-        // check that an action exists and add nonce
28
-        if (! $exclude_nonce) {
29
-            if (isset($args['action']) && ! empty($args['action'])) {
30
-                $args = array_merge(
31
-                    $args,
32
-                    array(
33
-                        $args['action'] . '_nonce' => wp_create_nonce($args['action'] . '_nonce')
34
-                    )
35
-                );
36
-            } else {
37
-                $args = array_merge(
38
-                    $args,
39
-                    array(
40
-                        'action' => 'default', 'default_nonce' => wp_create_nonce('default_nonce')
41
-                    )
42
-                );
43
-            }
44
-        }
15
+	/**
16
+	 * _add_query_arg
17
+	 * adds nonce to array of arguments then calls WP add_query_arg function
18
+	 *
19
+	 * @access public
20
+	 * @param array  $args
21
+	 * @param string $url
22
+	 * @param bool   $exclude_nonce If true then the nonce will be excluded from the generated url.
23
+	 * @return string
24
+	 */
25
+	public static function add_query_args_and_nonce($args = array(), $url = '', $exclude_nonce = false)
26
+	{
27
+		// check that an action exists and add nonce
28
+		if (! $exclude_nonce) {
29
+			if (isset($args['action']) && ! empty($args['action'])) {
30
+				$args = array_merge(
31
+					$args,
32
+					array(
33
+						$args['action'] . '_nonce' => wp_create_nonce($args['action'] . '_nonce')
34
+					)
35
+				);
36
+			} else {
37
+				$args = array_merge(
38
+					$args,
39
+					array(
40
+						'action' => 'default', 'default_nonce' => wp_create_nonce('default_nonce')
41
+					)
42
+				);
43
+			}
44
+		}
45 45
 
46
-        // finally, let's always add a return address (if present) :)
47
-        $args = ! empty($_REQUEST['action']) && ! isset($_REQUEST['return'])
48
-            ? array_merge($args, array('return' => $_REQUEST['action']))
49
-            : $args;
46
+		// finally, let's always add a return address (if present) :)
47
+		$args = ! empty($_REQUEST['action']) && ! isset($_REQUEST['return'])
48
+			? array_merge($args, array('return' => $_REQUEST['action']))
49
+			: $args;
50 50
 
51
-        return add_query_arg($args, $url);
52
-    }
51
+		return add_query_arg($args, $url);
52
+	}
53 53
 
54 54
 
55
-    /**
56
-     * Returns whether not the remote file exists.
57
-     * Checking via GET because HEAD requests are blocked on some server configurations.
58
-     *
59
-     * @param string  $url
60
-     * @param array $args  the arguments that should be passed through to the wp_remote_request call.
61
-     * @return boolean
62
-     */
63
-    public static function remote_file_exists($url, $args = array())
64
-    {
65
-        $results = wp_remote_request(
66
-            $url,
67
-            array_merge(
68
-                array(
69
-                    'method'      => 'GET',
70
-                    'redirection' => 1,
71
-                ),
72
-                $args
73
-            )
74
-        );
75
-        if (! $results instanceof WP_Error &&
76
-            isset($results['response']) &&
77
-            isset($results['response']['code']) &&
78
-            $results['response']['code'] == '200') {
79
-            return true;
80
-        } else {
81
-            return false;
82
-        }
83
-    }
55
+	/**
56
+	 * Returns whether not the remote file exists.
57
+	 * Checking via GET because HEAD requests are blocked on some server configurations.
58
+	 *
59
+	 * @param string  $url
60
+	 * @param array $args  the arguments that should be passed through to the wp_remote_request call.
61
+	 * @return boolean
62
+	 */
63
+	public static function remote_file_exists($url, $args = array())
64
+	{
65
+		$results = wp_remote_request(
66
+			$url,
67
+			array_merge(
68
+				array(
69
+					'method'      => 'GET',
70
+					'redirection' => 1,
71
+				),
72
+				$args
73
+			)
74
+		);
75
+		if (! $results instanceof WP_Error &&
76
+			isset($results['response']) &&
77
+			isset($results['response']['code']) &&
78
+			$results['response']['code'] == '200') {
79
+			return true;
80
+		} else {
81
+			return false;
82
+		}
83
+	}
84 84
 
85 85
 
86
-    /**
87
-     * refactor_url
88
-     * primarily used for removing the query string from a URL
89
-     *
90
-     * @param string $url
91
-     * @param bool   $remove_query  - TRUE (default) will strip off any URL params, ie: ?this=1&that=2
92
-     * @param bool   $base_url_only - TRUE will only return the scheme and host with no other parameters
93
-     * @return string
94
-     */
95
-    public static function refactor_url($url = '', $remove_query = true, $base_url_only = false)
96
-    {
97
-        // break apart incoming URL
98
-        $url_bits = parse_url($url);
99
-        // HTTP or HTTPS ?
100
-        $scheme = isset($url_bits['scheme']) ? $url_bits['scheme'] . '://' : 'http://';
101
-        // domain
102
-        $host = isset($url_bits['host']) ? $url_bits['host'] : '';
103
-        // if only the base URL is requested, then return that now
104
-        if ($base_url_only) {
105
-            return $scheme . $host;
106
-        }
107
-        $port = isset($url_bits['port']) ? ':' . $url_bits['port'] : '';
108
-        $user = isset($url_bits['user']) ? $url_bits['user'] : '';
109
-        $pass = isset($url_bits['pass']) ? ':' . $url_bits['pass'] : '';
110
-        $pass = ($user || $pass) ? $pass . '@' : '';
111
-        $path = isset($url_bits['path']) ? $url_bits['path'] : '';
112
-        // if the query string is not required, then return what we have so far
113
-        if ($remove_query) {
114
-            return $scheme . $user . $pass . $host . $port . $path;
115
-        }
116
-        $query    = isset($url_bits['query']) ? '?' . $url_bits['query'] : '';
117
-        $fragment = isset($url_bits['fragment']) ? '#' . $url_bits['fragment'] : '';
118
-        return $scheme . $user . $pass . $host . $port . $path . $query . $fragment;
119
-    }
86
+	/**
87
+	 * refactor_url
88
+	 * primarily used for removing the query string from a URL
89
+	 *
90
+	 * @param string $url
91
+	 * @param bool   $remove_query  - TRUE (default) will strip off any URL params, ie: ?this=1&that=2
92
+	 * @param bool   $base_url_only - TRUE will only return the scheme and host with no other parameters
93
+	 * @return string
94
+	 */
95
+	public static function refactor_url($url = '', $remove_query = true, $base_url_only = false)
96
+	{
97
+		// break apart incoming URL
98
+		$url_bits = parse_url($url);
99
+		// HTTP or HTTPS ?
100
+		$scheme = isset($url_bits['scheme']) ? $url_bits['scheme'] . '://' : 'http://';
101
+		// domain
102
+		$host = isset($url_bits['host']) ? $url_bits['host'] : '';
103
+		// if only the base URL is requested, then return that now
104
+		if ($base_url_only) {
105
+			return $scheme . $host;
106
+		}
107
+		$port = isset($url_bits['port']) ? ':' . $url_bits['port'] : '';
108
+		$user = isset($url_bits['user']) ? $url_bits['user'] : '';
109
+		$pass = isset($url_bits['pass']) ? ':' . $url_bits['pass'] : '';
110
+		$pass = ($user || $pass) ? $pass . '@' : '';
111
+		$path = isset($url_bits['path']) ? $url_bits['path'] : '';
112
+		// if the query string is not required, then return what we have so far
113
+		if ($remove_query) {
114
+			return $scheme . $user . $pass . $host . $port . $path;
115
+		}
116
+		$query    = isset($url_bits['query']) ? '?' . $url_bits['query'] : '';
117
+		$fragment = isset($url_bits['fragment']) ? '#' . $url_bits['fragment'] : '';
118
+		return $scheme . $user . $pass . $host . $port . $path . $query . $fragment;
119
+	}
120 120
 
121 121
 
122
-    /**
123
-     * get_query_string
124
-     * returns just the query string from a URL, formatted by default into an array of key value pairs
125
-     *
126
-     * @param string $url
127
-     * @param bool   $as_array TRUE (default) will return query params as an array of key value pairs, FALSE will
128
-     *                         simply return the query string
129
-     * @return string|array
130
-     */
131
-    public static function get_query_string($url = '', $as_array = true)
132
-    {
133
-        // decode, then break apart incoming URL
134
-        $url_bits = parse_url(html_entity_decode($url));
135
-        // grab query string from URL
136
-        $query = isset($url_bits['query']) ? $url_bits['query'] : '';
137
-        // if we don't want the query string formatted into an array of key => value pairs, then just return it as is
138
-        if (! $as_array) {
139
-            return $query;
140
-        }
141
-        // if no query string exists then just return an empty array now
142
-        if (empty($query)) {
143
-            return array();
144
-        }
145
-        // empty array to hold results
146
-        $query_params = array();
147
-        // now break apart the query string into separate params
148
-        $query = explode('&', $query);
149
-        // loop thru our query params
150
-        foreach ($query as $query_args) {
151
-            // break apart the key value pairs
152
-            $query_args = explode('=', $query_args);
153
-            // and add to our results array
154
-            $query_params[ $query_args[0] ] = $query_args[1];
155
-        }
156
-        return $query_params;
157
-    }
122
+	/**
123
+	 * get_query_string
124
+	 * returns just the query string from a URL, formatted by default into an array of key value pairs
125
+	 *
126
+	 * @param string $url
127
+	 * @param bool   $as_array TRUE (default) will return query params as an array of key value pairs, FALSE will
128
+	 *                         simply return the query string
129
+	 * @return string|array
130
+	 */
131
+	public static function get_query_string($url = '', $as_array = true)
132
+	{
133
+		// decode, then break apart incoming URL
134
+		$url_bits = parse_url(html_entity_decode($url));
135
+		// grab query string from URL
136
+		$query = isset($url_bits['query']) ? $url_bits['query'] : '';
137
+		// if we don't want the query string formatted into an array of key => value pairs, then just return it as is
138
+		if (! $as_array) {
139
+			return $query;
140
+		}
141
+		// if no query string exists then just return an empty array now
142
+		if (empty($query)) {
143
+			return array();
144
+		}
145
+		// empty array to hold results
146
+		$query_params = array();
147
+		// now break apart the query string into separate params
148
+		$query = explode('&', $query);
149
+		// loop thru our query params
150
+		foreach ($query as $query_args) {
151
+			// break apart the key value pairs
152
+			$query_args = explode('=', $query_args);
153
+			// and add to our results array
154
+			$query_params[ $query_args[0] ] = $query_args[1];
155
+		}
156
+		return $query_params;
157
+	}
158 158
 
159 159
 
160
-    /**
161
-     * prevent_prefetching
162
-     *
163
-     * @return void
164
-     */
165
-    public static function prevent_prefetching()
166
-    {
167
-        // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes
168
-        // with the registration process
169
-        remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
170
-    }
160
+	/**
161
+	 * prevent_prefetching
162
+	 *
163
+	 * @return void
164
+	 */
165
+	public static function prevent_prefetching()
166
+	{
167
+		// prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes
168
+		// with the registration process
169
+		remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
170
+	}
171 171
 
172 172
 
173
-    /**
174
-     * This generates a unique site-specific string.
175
-     * An example usage for this string would be to save as a unique identifier for a record in the db for usage in
176
-     * urls.
177
-     *
178
-     * @param   string $prefix Use this to prefix the string with something.
179
-     * @return string
180
-     */
181
-    public static function generate_unique_token($prefix = '')
182
-    {
183
-        $token = md5(uniqid() . mt_rand());
184
-        return $prefix ? $prefix . '_' . $token : $token;
185
-    }
173
+	/**
174
+	 * This generates a unique site-specific string.
175
+	 * An example usage for this string would be to save as a unique identifier for a record in the db for usage in
176
+	 * urls.
177
+	 *
178
+	 * @param   string $prefix Use this to prefix the string with something.
179
+	 * @return string
180
+	 */
181
+	public static function generate_unique_token($prefix = '')
182
+	{
183
+		$token = md5(uniqid() . mt_rand());
184
+		return $prefix ? $prefix . '_' . $token : $token;
185
+	}
186 186
 
187 187
 
188
-    /**
189
-     * filter_input_server_url
190
-     * uses filter_input() to sanitize one of the INPUT_SERVER URL values
191
-     * but adds a backup in case filter_input() returns nothing, which can erringly happen on some servers
192
-     *
193
-     * @param string $server_variable
194
-     * @return string
195
-     */
196
-    public static function filter_input_server_url($server_variable = 'REQUEST_URI')
197
-    {
198
-        $URL              = '';
199
-        $server_variables = array(
200
-            'REQUEST_URI' => 1,
201
-            'HTTP_HOST'   => 1,
202
-            'PHP_SELF'    => 1,
203
-        );
204
-        $server_variable  = strtoupper($server_variable);
205
-        // whitelist INPUT_SERVER var
206
-        if (isset($server_variables[ $server_variable ])) {
207
-            $URL = filter_input(INPUT_SERVER, $server_variable, FILTER_SANITIZE_URL, FILTER_NULL_ON_FAILURE);
208
-            if (empty($URL)) {
209
-                // fallback sanitization if the above fails
210
-                $URL = wp_sanitize_redirect($_SERVER[ $server_variable ]);
211
-            }
212
-        }
213
-        return $URL;
214
-    }
188
+	/**
189
+	 * filter_input_server_url
190
+	 * uses filter_input() to sanitize one of the INPUT_SERVER URL values
191
+	 * but adds a backup in case filter_input() returns nothing, which can erringly happen on some servers
192
+	 *
193
+	 * @param string $server_variable
194
+	 * @return string
195
+	 */
196
+	public static function filter_input_server_url($server_variable = 'REQUEST_URI')
197
+	{
198
+		$URL              = '';
199
+		$server_variables = array(
200
+			'REQUEST_URI' => 1,
201
+			'HTTP_HOST'   => 1,
202
+			'PHP_SELF'    => 1,
203
+		);
204
+		$server_variable  = strtoupper($server_variable);
205
+		// whitelist INPUT_SERVER var
206
+		if (isset($server_variables[ $server_variable ])) {
207
+			$URL = filter_input(INPUT_SERVER, $server_variable, FILTER_SANITIZE_URL, FILTER_NULL_ON_FAILURE);
208
+			if (empty($URL)) {
209
+				// fallback sanitization if the above fails
210
+				$URL = wp_sanitize_redirect($_SERVER[ $server_variable ]);
211
+			}
212
+		}
213
+		return $URL;
214
+	}
215 215
 
216 216
 
217
-    /**
218
-     * Gets the current page's full URL.
219
-     *
220
-     * @return string
221
-     */
222
-    public static function current_url()
223
-    {
224
-        $url = '';
225
-        if (isset($_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'])) {
226
-            $url = is_ssl() ? 'https://' : 'http://';
227
-            $url .= \EEH_URL::filter_input_server_url('HTTP_HOST');
228
-            $url .= \EEH_URL::filter_input_server_url('REQUEST_URI');
229
-        }
230
-        return $url;
231
-    }
217
+	/**
218
+	 * Gets the current page's full URL.
219
+	 *
220
+	 * @return string
221
+	 */
222
+	public static function current_url()
223
+	{
224
+		$url = '';
225
+		if (isset($_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'])) {
226
+			$url = is_ssl() ? 'https://' : 'http://';
227
+			$url .= \EEH_URL::filter_input_server_url('HTTP_HOST');
228
+			$url .= \EEH_URL::filter_input_server_url('REQUEST_URI');
229
+		}
230
+		return $url;
231
+	}
232 232
 
233 233
 
234
-    /**
235
-     * Identical in functionality to EEH_current_url except it removes any provided query_parameters from it.
236
-     *
237
-     * @param array $query_parameters An array of query_parameters to remove from the current url.
238
-     * @since 4.9.46.rc.029
239
-     * @return string
240
-     */
241
-    public static function current_url_without_query_paramaters(array $query_parameters)
242
-    {
243
-        return remove_query_arg($query_parameters, EEH_URL::current_url());
244
-    }
234
+	/**
235
+	 * Identical in functionality to EEH_current_url except it removes any provided query_parameters from it.
236
+	 *
237
+	 * @param array $query_parameters An array of query_parameters to remove from the current url.
238
+	 * @since 4.9.46.rc.029
239
+	 * @return string
240
+	 */
241
+	public static function current_url_without_query_paramaters(array $query_parameters)
242
+	{
243
+		return remove_query_arg($query_parameters, EEH_URL::current_url());
244
+	}
245 245
 
246 246
 
247
-    /**
248
-     * @param string $location
249
-     * @param int    $status
250
-     * @param string $exit_notice
251
-     */
252
-    public static function safeRedirectAndExit($location, $status = 302, $exit_notice = '')
253
-    {
254
-        EE_Error::get_notices(false, true);
255
-        wp_safe_redirect($location, $status);
256
-        exit($exit_notice);
257
-    }
247
+	/**
248
+	 * @param string $location
249
+	 * @param int    $status
250
+	 * @param string $exit_notice
251
+	 */
252
+	public static function safeRedirectAndExit($location, $status = 302, $exit_notice = '')
253
+	{
254
+		EE_Error::get_notices(false, true);
255
+		wp_safe_redirect($location, $status);
256
+		exit($exit_notice);
257
+	}
258 258
 
259
-    /**
260
-     * Slugifies text for usage in a URL.
261
-     *
262
-     * Currently, this isn't just calling `sanitize_title()` on it, because that percent-encodes unicode characters,
263
-     * and WordPress chokes on them when used as CPT and custom taxonomy slugs.
264
-     *
265
-     * @since 4.9.66.p
266
-     * @param string $text
267
-     * @param string $fallback
268
-     * @return string which can be used in a URL
269
-     */
270
-    public static function slugify($text, $fallback)
271
-    {
272
-        // url decode after sanitizing title to restore unicode characters,
273
-        // see https://github.com/eventespresso/event-espresso-core/issues/575
274
-        return urldecode(
275
-            sanitize_title(
276
-                $text,
277
-                $fallback
278
-            )
279
-        );
280
-    }
259
+	/**
260
+	 * Slugifies text for usage in a URL.
261
+	 *
262
+	 * Currently, this isn't just calling `sanitize_title()` on it, because that percent-encodes unicode characters,
263
+	 * and WordPress chokes on them when used as CPT and custom taxonomy slugs.
264
+	 *
265
+	 * @since 4.9.66.p
266
+	 * @param string $text
267
+	 * @param string $fallback
268
+	 * @return string which can be used in a URL
269
+	 */
270
+	public static function slugify($text, $fallback)
271
+	{
272
+		// url decode after sanitizing title to restore unicode characters,
273
+		// see https://github.com/eventespresso/event-espresso-core/issues/575
274
+		return urldecode(
275
+			sanitize_title(
276
+				$text,
277
+				$fallback
278
+			)
279
+		);
280
+	}
281 281
 }
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -25,12 +25,12 @@  discard block
 block discarded – undo
25 25
     public static function add_query_args_and_nonce($args = array(), $url = '', $exclude_nonce = false)
26 26
     {
27 27
         // check that an action exists and add nonce
28
-        if (! $exclude_nonce) {
28
+        if ( ! $exclude_nonce) {
29 29
             if (isset($args['action']) && ! empty($args['action'])) {
30 30
                 $args = array_merge(
31 31
                     $args,
32 32
                     array(
33
-                        $args['action'] . '_nonce' => wp_create_nonce($args['action'] . '_nonce')
33
+                        $args['action'].'_nonce' => wp_create_nonce($args['action'].'_nonce')
34 34
                     )
35 35
                 );
36 36
             } else {
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
                 $args
73 73
             )
74 74
         );
75
-        if (! $results instanceof WP_Error &&
75
+        if ( ! $results instanceof WP_Error &&
76 76
             isset($results['response']) &&
77 77
             isset($results['response']['code']) &&
78 78
             $results['response']['code'] == '200') {
@@ -97,25 +97,25 @@  discard block
 block discarded – undo
97 97
         // break apart incoming URL
98 98
         $url_bits = parse_url($url);
99 99
         // HTTP or HTTPS ?
100
-        $scheme = isset($url_bits['scheme']) ? $url_bits['scheme'] . '://' : 'http://';
100
+        $scheme = isset($url_bits['scheme']) ? $url_bits['scheme'].'://' : 'http://';
101 101
         // domain
102 102
         $host = isset($url_bits['host']) ? $url_bits['host'] : '';
103 103
         // if only the base URL is requested, then return that now
104 104
         if ($base_url_only) {
105
-            return $scheme . $host;
105
+            return $scheme.$host;
106 106
         }
107
-        $port = isset($url_bits['port']) ? ':' . $url_bits['port'] : '';
107
+        $port = isset($url_bits['port']) ? ':'.$url_bits['port'] : '';
108 108
         $user = isset($url_bits['user']) ? $url_bits['user'] : '';
109
-        $pass = isset($url_bits['pass']) ? ':' . $url_bits['pass'] : '';
110
-        $pass = ($user || $pass) ? $pass . '@' : '';
109
+        $pass = isset($url_bits['pass']) ? ':'.$url_bits['pass'] : '';
110
+        $pass = ($user || $pass) ? $pass.'@' : '';
111 111
         $path = isset($url_bits['path']) ? $url_bits['path'] : '';
112 112
         // if the query string is not required, then return what we have so far
113 113
         if ($remove_query) {
114
-            return $scheme . $user . $pass . $host . $port . $path;
114
+            return $scheme.$user.$pass.$host.$port.$path;
115 115
         }
116
-        $query    = isset($url_bits['query']) ? '?' . $url_bits['query'] : '';
117
-        $fragment = isset($url_bits['fragment']) ? '#' . $url_bits['fragment'] : '';
118
-        return $scheme . $user . $pass . $host . $port . $path . $query . $fragment;
116
+        $query    = isset($url_bits['query']) ? '?'.$url_bits['query'] : '';
117
+        $fragment = isset($url_bits['fragment']) ? '#'.$url_bits['fragment'] : '';
118
+        return $scheme.$user.$pass.$host.$port.$path.$query.$fragment;
119 119
     }
120 120
 
121 121
 
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
         // grab query string from URL
136 136
         $query = isset($url_bits['query']) ? $url_bits['query'] : '';
137 137
         // if we don't want the query string formatted into an array of key => value pairs, then just return it as is
138
-        if (! $as_array) {
138
+        if ( ! $as_array) {
139 139
             return $query;
140 140
         }
141 141
         // if no query string exists then just return an empty array now
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
             // break apart the key value pairs
152 152
             $query_args = explode('=', $query_args);
153 153
             // and add to our results array
154
-            $query_params[ $query_args[0] ] = $query_args[1];
154
+            $query_params[$query_args[0]] = $query_args[1];
155 155
         }
156 156
         return $query_params;
157 157
     }
@@ -180,8 +180,8 @@  discard block
 block discarded – undo
180 180
      */
181 181
     public static function generate_unique_token($prefix = '')
182 182
     {
183
-        $token = md5(uniqid() . mt_rand());
184
-        return $prefix ? $prefix . '_' . $token : $token;
183
+        $token = md5(uniqid().mt_rand());
184
+        return $prefix ? $prefix.'_'.$token : $token;
185 185
     }
186 186
 
187 187
 
@@ -201,13 +201,13 @@  discard block
 block discarded – undo
201 201
             'HTTP_HOST'   => 1,
202 202
             'PHP_SELF'    => 1,
203 203
         );
204
-        $server_variable  = strtoupper($server_variable);
204
+        $server_variable = strtoupper($server_variable);
205 205
         // whitelist INPUT_SERVER var
206
-        if (isset($server_variables[ $server_variable ])) {
206
+        if (isset($server_variables[$server_variable])) {
207 207
             $URL = filter_input(INPUT_SERVER, $server_variable, FILTER_SANITIZE_URL, FILTER_NULL_ON_FAILURE);
208 208
             if (empty($URL)) {
209 209
                 // fallback sanitization if the above fails
210
-                $URL = wp_sanitize_redirect($_SERVER[ $server_variable ]);
210
+                $URL = wp_sanitize_redirect($_SERVER[$server_variable]);
211 211
             }
212 212
         }
213 213
         return $URL;
Please login to merge, or discard this patch.
core/libraries/messages/validators/EE_Messages_Validator.core.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -505,7 +505,7 @@
 block discarded – undo
505 505
      *
506 506
      * @param  string $value            string to evaluate
507 507
      * @param  array  $valid_shortcodes array of shortcodes that are acceptable.
508
-     * @return mixed (bool|string)  return either a list of invalid shortcodes OR false if the shortcodes validate.
508
+     * @return false|string (bool|string)  return either a list of invalid shortcodes OR false if the shortcodes validate.
509 509
      */
510 510
     protected function _invalid_shortcodes($value, $valid_shortcodes)
511 511
     {
Please login to merge, or discard this patch.
Indentation   +623 added lines, -623 removed lines patch added patch discarded remove patch
@@ -17,627 +17,627 @@
 block discarded – undo
17 17
 {
18 18
 
19 19
 
20
-    /**
21
-     * These properties just hold the name for the Messenger and Message Type (defined by child classes).
22
-     * These are used for retrieving objects etc.
23
-     *
24
-     * @var string
25
-     */
26
-    protected $_m_name;
27
-    protected $_mt_name;
28
-
29
-
30
-    /**
31
-     * This will hold any error messages from the validation process.
32
-     * The _errors property holds an associative array of error messages
33
-     * listing the field as the key and the message as the value.
34
-     *
35
-     * @var array()
36
-     */
37
-    private $_errors = array();
38
-
39
-
40
-    /**
41
-     * holds an array of fields being validated
42
-     *
43
-     * @var array
44
-     */
45
-    protected $_fields;
46
-
47
-
48
-    /**
49
-     * this will hold the incoming context
50
-     *
51
-     * @var string
52
-     */
53
-    protected $_context;
54
-
55
-
56
-    /**
57
-     * this holds an array of fields and the relevant validation information
58
-     * that the incoming fields data get validated against.
59
-     * This gets setup in the _set_props() method.
60
-     *
61
-     * @var array
62
-     */
63
-    protected $_validators;
64
-
65
-
66
-    /**
67
-     * holds the messenger object
68
-     *
69
-     * @var object
70
-     */
71
-    protected $_messenger;
72
-
73
-
74
-    /**
75
-     * holds the message type object
76
-     *
77
-     * @var object
78
-     */
79
-    protected $_message_type;
80
-
81
-
82
-    /**
83
-     * will hold any valid_shortcode modifications made by the _modify_validator() method.
84
-     *
85
-     * @var array
86
-     */
87
-    protected $_valid_shortcodes_modifier;
88
-
89
-
90
-    /**
91
-     * There may be times where a message type wants to include a shortcode group but exclude specific
92
-     * shortcodes.  If that's the case then it can set this property as an array of shortcodes to exclude and
93
-     * they will not be allowed.
94
-     * Array should be indexed by field and values are an array of specific shortcodes to exclude.
95
-     *
96
-     * @var array
97
-     */
98
-    protected $_specific_shortcode_excludes = array();
99
-
100
-
101
-    /**
102
-     * Runs the validator using the incoming fields array as the fields/values to check.
103
-     *
104
-     * @param array $fields The fields sent by the EEM object.
105
-     * @param       $context
106
-     * @throws EE_Error
107
-     * @throws ReflectionException
108
-     */
109
-    public function __construct($fields, $context)
110
-    {
111
-        // check that _m_name and _mt_name have been set by child class otherwise we get out.
112
-        if (empty($this->_m_name) || empty($this->_mt_name)) {
113
-            throw new EE_Error(
114
-                esc_html__(
115
-                    'EE_Messages_Validator child classes MUST set the $_m_name and $_mt_name property.  Check that the child class is doing this',
116
-                    'event_espresso'
117
-                )
118
-            );
119
-        }
120
-        $this->_fields  = $fields;
121
-        $this->_context = $context;
122
-
123
-        // load messenger and message_type objects and the related shortcode objects.
124
-        $this->_load_objects();
125
-
126
-
127
-        // modify any messenger/message_type specific validation instructions.  This is what child classes define.
128
-        $this->_modify_validator();
129
-
130
-
131
-        // let's set validators property
132
-        $this->_set_validators();
133
-    }
134
-
135
-
136
-    /**
137
-     * Child classes instantiate this and use it to modify the _validator_config array property
138
-     * for the messenger using messengers set_validate_config() method.
139
-     * This is so we can specify specific validation instructions for a messenger/message_type combo
140
-     * that aren't handled by the defaults setup in the messenger.
141
-     *
142
-     * @abstract
143
-     * @access protected
144
-     * @return void
145
-     */
146
-    abstract protected function _modify_validator();
147
-
148
-
149
-    /**
150
-     * loads all objects used by validator
151
-     *
152
-     * @access private
153
-     * @throws \EE_Error
154
-     */
155
-    private function _load_objects()
156
-    {
157
-        // load messenger
158
-        $messenger = ucwords(str_replace('_', ' ', $this->_m_name));
159
-        $messenger = str_replace(' ', '_', $messenger);
160
-        $messenger = 'EE_' . $messenger . '_messenger';
161
-
162
-        if (! class_exists($messenger)) {
163
-            throw new EE_Error(
164
-                sprintf(
165
-                    esc_html__('There is no messenger class for the given string (%s)', 'event_espresso'),
166
-                    $this->_m_name
167
-                )
168
-            );
169
-        }
170
-
171
-        $this->_messenger = new $messenger();
172
-
173
-        // load message type
174
-        $message_type = ucwords(str_replace('_', ' ', $this->_mt_name));
175
-        $message_type = str_replace(' ', '_', $message_type);
176
-        $message_type = 'EE_' . $message_type . '_message_type';
177
-
178
-        if (! class_exists($message_type)) {
179
-            throw new EE_Error(
180
-                sprintf(
181
-                    esc_html__('There is no message type class for the given string (%s)', 'event_espresso'),
182
-                    $this->_mt_name
183
-                )
184
-            );
185
-        }
186
-
187
-        $this->_message_type = new $message_type();
188
-    }
189
-
190
-
191
-    /**
192
-     * used to set the $_validators property
193
-     *
194
-     * @access private
195
-     * @return void
196
-     * @throws ReflectionException
197
-     */
198
-    private function _set_validators()
199
-    {
200
-        // let's get all valid shortcodes from mt and message type
201
-        // (messenger will have its set in the _validator_config property for the messenger)
202
-        $mt_codes = $this->_message_type->get_valid_shortcodes();
203
-
204
-
205
-        // get messenger validator_config
206
-        $msgr_validator = $this->_messenger->get_validator_config();
207
-
208
-
209
-        // we only want the valid shortcodes for the given context!
210
-        $context  = $this->_context;
211
-        $mt_codes = $mt_codes[ $context ];
212
-
213
-        // in this first loop we're just getting all shortcode group indexes from the msgr_validator
214
-        // into a single array (so we can get the appropriate shortcode objects for the groups)
215
-        $shortcode_groups = $mt_codes;
216
-        $groups_per_field = array();
217
-
218
-        foreach ($msgr_validator as $field => $config) {
219
-            if (empty($config) || ! isset($config['shortcodes'])) {
220
-                continue;
221
-            }  //Nothing to see here.
222
-            $groups_per_field[ $field ] = array_intersect($config['shortcodes'], $mt_codes);
223
-            $shortcode_groups         = array_merge($config['shortcodes'], $shortcode_groups);
224
-        }
225
-
226
-        $shortcode_groups = array_unique($shortcode_groups);
227
-
228
-        // okay now we've got our groups.
229
-        // Let's get the codes from the objects into an array indexed by group for easy retrieval later.
230
-        $codes_from_objs = array();
231
-
232
-        foreach ($shortcode_groups as $group) {
233
-            $ref       = ucwords(str_replace('_', ' ', $group));
234
-            $ref       = str_replace(' ', '_', $ref);
235
-            $classname = 'EE_' . $ref . '_Shortcodes';
236
-            if (class_exists($classname)) {
237
-                $a                       = new ReflectionClass($classname);
238
-                $obj                     = $a->newInstance();
239
-                $codes_from_objs[ $group ] = $obj->get_shortcodes();
240
-            }
241
-        }
242
-
243
-
244
-        // let's just replace the $mt shortcode group indexes with the actual shortcodes (unique)
245
-        $final_mt_codes = array();
246
-        foreach ($mt_codes as $group) {
247
-            $final_mt_codes = array_merge($final_mt_codes, $codes_from_objs[ $group ]);
248
-        }
249
-
250
-        $mt_codes = $final_mt_codes;
251
-
252
-
253
-        // k now in this next loop we're going to loop through $msgr_validator again
254
-        // and setup the _validators property from the data we've setup so far.
255
-        foreach ($msgr_validator as $field => $config) {
256
-            // if required shortcode is not in our list of codes for the given field, then we skip this field.
257
-            $required = isset($config['required'])
258
-                ? array_intersect($config['required'], array_keys($mt_codes))
259
-                : true;
260
-            if (empty($required)) {
261
-                continue;
262
-            }
263
-
264
-            if (isset($this->_valid_shortcodes_modifier[ $context ][ $field ])) {
265
-                // If we have an override then we use it to indicate the codes we want.
266
-                $this->_validators[ $field ]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group(
267
-                    $this->_valid_shortcodes_modifier[ $context ][ $field ],
268
-                    $codes_from_objs
269
-                );
270
-            } elseif (isset($groups_per_field[ $field ])) {
271
-                // if we have specific shortcodes for a field then we need to use them
272
-                $this->_validators[ $field ]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group(
273
-                    $groups_per_field[ $field ],
274
-                    $codes_from_objs
275
-                );
276
-            } elseif (empty($config)) {
277
-                // if empty config then we're assuming we're just going to use the shortcodes from the message type
278
-                // context
279
-                $this->_validators[ $field ]['shortcodes'] = $mt_codes;
280
-            } elseif (isset($config['specific_shortcodes'])) {
281
-                // if we have specific shortcodes then we need to use them
282
-                $this->_validators[ $field ]['shortcodes'] = $config['specific_shortcodes'];
283
-            } else {
284
-                // otherwise the shortcodes are what is set by the messenger for that field
285
-                foreach ($config['shortcodes'] as $group) {
286
-                    $this->_validators[ $field ]['shortcodes'] = isset($this->_validators[ $field ]['shortcodes'])
287
-                        ? array_merge($this->_validators[ $field ]['shortcodes'], $codes_from_objs[ $group ])
288
-                        : $codes_from_objs[ $group ];
289
-                }
290
-            }
291
-
292
-            // now let's just make sure that any excluded specific shortcodes are removed.
293
-            $specific_excludes = $this->get_specific_shortcode_excludes();
294
-            if (isset($specific_excludes[ $field ])) {
295
-                foreach ($specific_excludes[ $field ] as $sex) {
296
-                    if (isset($this->_validators[ $field ]['shortcodes'][ $sex ])) {
297
-                        unset($this->_validators[ $field ]['shortcodes'][ $sex ]);
298
-                    }
299
-                }
300
-            }
301
-
302
-            // hey! don't forget to include the type if present!
303
-            $this->_validators[ $field ]['type'] = isset($config['type']) ? $config['type'] : null;
304
-        }
305
-    }
306
-
307
-
308
-    /**
309
-     * This just returns the validators property that contains information
310
-     * about the various shortcodes and their availability with each field
311
-     *
312
-     * @return array
313
-     */
314
-    public function get_validators()
315
-    {
316
-        return $this->_validators;
317
-    }
318
-
319
-
320
-    /**
321
-     * This simply returns the specific shortcode_excludes property that is set.
322
-     *
323
-     * @since 4.5.0
324
-     * @return array
325
-     */
326
-    public function get_specific_shortcode_excludes()
327
-    {
328
-        // specific validator filter
329
-        $shortcode_excludes = apply_filters(
330
-            'FHEE__' . get_class($this) . '__get_specific_shortcode_excludes;',
331
-            $this->_specific_shortcode_excludes,
332
-            $this->_context
333
-        );
334
-        // global filter
335
-        return apply_filters(
336
-            'FHEE__EE_Messages_Validator__get_specific_shortcode_excludes',
337
-            $shortcode_excludes,
338
-            $this->_context,
339
-            $this
340
-        );
341
-    }
342
-
343
-
344
-    /**
345
-     * This is the main method that handles validation
346
-     * What it does is loop through the _fields (the ones that get validated)
347
-     * and checks them against the shortcodes array for the field and the 'type' indicated by the
348
-     *
349
-     * @access public
350
-     * @return mixed (bool|array)  if errors present we return the array otherwise true
351
-     */
352
-    public function validate()
353
-    {
354
-        // some defaults
355
-        $template_fields = $this->_messenger->get_template_fields();
356
-        // loop through the fields and check!
357
-        foreach ($this->_fields as $field => $value) {
358
-            $this->_errors[ $field ] = array();
359
-            $err_msg               = '';
360
-            $field_label           = '';
361
-            // if field is not present in the _validators array then we continue
362
-            if (! isset($this->_validators[ $field ])) {
363
-                unset($this->_errors[ $field ]);
364
-                continue;
365
-            }
366
-
367
-            // get the translated field label!
368
-            // first check if it's in the main fields list
369
-            if (isset($template_fields[ $field ])) {
370
-                if (empty($template_fields[ $field ])) {
371
-                    $field_label = $field;
372
-                } else {
373
-                    // most likely the field is found in the 'extra' array.
374
-                    $field_label = $template_fields[ $field ]['label'];
375
-                }
376
-            }
377
-
378
-            // if field label is empty OR is equal to the current field
379
-            // then we need to loop through the 'extra' fields in the template_fields config (if present)
380
-            if (isset($template_fields['extra']) && (empty($field_label) || $field_label === $field)) {
381
-                foreach ($template_fields['extra'] as $main_field => $secondary_field) {
382
-                    foreach ($secondary_field as $name => $values) {
383
-                        if ($name === $field) {
384
-                            $field_label = $values['label'];
385
-                        }
386
-
387
-                        // if we've got a 'main' secondary field, let's see if that matches what field we're on
388
-                        // which means it contains the label for this field.
389
-                        if ($name === 'main' && $main_field === $field_label) {
390
-                            $field_label = $values['label'];
391
-                        }
392
-                    }
393
-                }
394
-            }
395
-
396
-            // field is present. Let's validate shortcodes first (but only if shortcodes present).
397
-            if (isset($this->_validators[ $field ]['shortcodes'])
398
-                && ! empty($this->_validators[ $field ]['shortcodes'])
399
-            ) {
400
-                $invalid_shortcodes = $this->_invalid_shortcodes($value, $this->_validators[ $field ]['shortcodes']);
401
-                // if true then that means there is a returned error message
402
-                // that we'll need to add to the _errors array for this field.
403
-                if ($invalid_shortcodes) {
404
-                    $v_s     = array_keys($this->_validators[ $field ]['shortcodes']);
405
-                    $err_msg = sprintf(
406
-                        esc_html__(
407
-                            '%3$sThe following shortcodes were found in the "%1$s" field that ARE not valid: %2$s%4$s',
408
-                            'event_espresso'
409
-                        ),
410
-                        '<strong>' . $field_label . '</strong>',
411
-                        $invalid_shortcodes,
412
-                        '<p>',
413
-                        '</p >'
414
-                    );
415
-                    $err_msg .= sprintf(
416
-                        esc_html__('%2$sValid shortcodes for this field are: %1$s%3$s', 'event_espresso'),
417
-                        implode(', ', $v_s),
418
-                        '<strong>',
419
-                        '</strong>'
420
-                    );
421
-                }
422
-            }
423
-
424
-            // if there's a "type" to be validated then let's do that too.
425
-            if (isset($this->_validators[ $field ]['type']) && ! empty($this->_validators[ $field ]['type'])) {
426
-                switch ($this->_validators[ $field ]['type']) {
427
-                    case 'number':
428
-                        if (! is_numeric($value)) {
429
-                            $err_msg .= sprintf(
430
-                                esc_html__(
431
-                                    '%3$sThe %1$s field is supposed to be a number. The value given (%2$s)  is not.  Please double-check and make sure the field contains a number%4$s',
432
-                                    'event_espresso'
433
-                                ),
434
-                                $field_label,
435
-                                $value,
436
-                                '<p>',
437
-                                '</p >'
438
-                            );
439
-                        }
440
-                        break;
441
-                    case 'email':
442
-                        $valid_email = $this->_validate_email($value);
443
-                        if (! $valid_email) {
444
-                            $err_msg .= htmlentities(
445
-                                sprintf(
446
-                                    esc_html__(
447
-                                        'The %1$s field has at least one string that is not a valid email address record.  Valid emails are in the format: "Name <[email protected]>" or "[email protected]" and multiple emails can be separated by a comma.',
448
-                                        'event_espresso'
449
-                                    ),
450
-                                    $field_label
451
-                                )
452
-                            );
453
-                        }
454
-                        break;
455
-                    default:
456
-                        break;
457
-                }
458
-            }
459
-
460
-            // if $err_msg isn't empty let's setup the _errors array for this field.
461
-            if (! empty($err_msg)) {
462
-                $this->_errors[ $field ]['msg'] = $err_msg;
463
-            } else {
464
-                unset($this->_errors[ $field ]);
465
-            }
466
-        }
467
-
468
-        // if we have ANY errors, then we want to make sure we return the values
469
-        // for ALL the fields so the user doesn't have to retype them all.
470
-        if (! empty($this->_errors)) {
471
-            foreach ($this->_fields as $field => $value) {
472
-                $this->_errors[ $field ]['value'] = stripslashes($value);
473
-            }
474
-        }
475
-
476
-        // return any errors or just TRUE if everything validates
477
-        return empty($this->_errors) ? true : $this->_errors;
478
-    }
479
-
480
-
481
-    /**
482
-     * Reassembles and returns an array of valid shortcodes
483
-     * given the array of groups and array of shortcodes indexed by group.
484
-     *
485
-     * @param  array $groups          array of shortcode groups that we want shortcodes for
486
-     * @param  array $codes_from_objs All the codes available.
487
-     * @return array                   an array of actual shortcodes (that will be used for validation).
488
-     */
489
-    private function _reassemble_valid_shortcodes_from_group($groups, $codes_from_objs)
490
-    {
491
-        $shortcodes = array();
492
-        foreach ($groups as $group) {
493
-            $shortcodes = array_merge($shortcodes, $codes_from_objs[ $group ]);
494
-        }
495
-        return $shortcodes;
496
-    }
497
-
498
-
499
-    /**
500
-     * Validates a string against a list of accepted shortcodes
501
-     * This function takes in an array of shortcodes
502
-     * and makes sure that the given string ONLY contains shortcodes in that array.
503
-     *
504
-     * @param  string $value            string to evaluate
505
-     * @param  array  $valid_shortcodes array of shortcodes that are acceptable.
506
-     * @return mixed (bool|string)  return either a list of invalid shortcodes OR false if the shortcodes validate.
507
-     */
508
-    protected function _invalid_shortcodes($value, $valid_shortcodes)
509
-    {
510
-        // first we need to go through the string and get the shortcodes in the string
511
-        preg_match_all('/(\[.+?\])/', $value, $matches);
512
-        $incoming_shortcodes = (array) $matches[0];
513
-
514
-        // get a diff of the shortcodes in the string vs the valid shortcodes
515
-        $diff = array_diff($incoming_shortcodes, array_keys($valid_shortcodes));
516
-
517
-        // we need to account for custom codes so let's loop through the diff and remove any of those type of codes
518
-        foreach ($diff as $ind => $code) {
519
-            if (preg_match('/(\[[A-Za-z0-9\_]+_\*)/', $code)) {
520
-                // strip the shortcode so we just have the BASE string (i.e. [ANSWER_*] )
521
-                $dynamic_sc = preg_replace('/(_\*+.+)/', '_*]', $code);
522
-                // does this exist in the $valid_shortcodes?  If so then unset.
523
-                if (isset($valid_shortcodes[ $dynamic_sc ])) {
524
-                    unset($diff[ $ind ]);
525
-                }
526
-            }
527
-        }
528
-
529
-        if (empty($diff)) {
530
-            return false;
531
-        } //there is no diff, we have no invalid shortcodes, so return
532
-
533
-        // made it here? then let's assemble the error message
534
-        $invalid_shortcodes = implode('</strong>,<strong>', $diff);
535
-        $invalid_shortcodes = '<strong>' . $invalid_shortcodes . '</strong>';
536
-        return $invalid_shortcodes;
537
-    }
538
-
539
-
540
-    /**
541
-     * Validates an incoming string and makes sure we have valid emails in the string.
542
-     *
543
-     * @param  string $value incoming value to validate
544
-     * @return bool        true if the string validates, false if it doesn't
545
-     */
546
-    protected function _validate_email($value)
547
-    {
548
-        $validate = true;
549
-        $or_val   = $value;
550
-
551
-        // empty strings will validate because this is how a message template
552
-        // for a particular context can be "turned off" (if there is no email then no message)
553
-        if (empty($value)) {
554
-            return $validate;
555
-        }
556
-
557
-        // first determine if there ARE any shortcodes.
558
-        // If there are shortcodes and then later we find that there were no other valid emails
559
-        // but the field isn't empty...
560
-        // that means we've got extra commas that were left after stripping out shortcodes so probably still valid.
561
-        $has_shortcodes = preg_match('/(\[.+?\])/', $value);
562
-
563
-        // first we need to strip out all the shortcodes!
564
-        $value = preg_replace('/(\[.+?\])/', '', $value);
565
-
566
-        // if original value is not empty and new value is, then we've parsed out a shortcode
567
-        // and we now have an empty string which DOES validate.
568
-        // We also validate complete empty field for email because
569
-        // its possible that this message is being "turned off" for a particular context
570
-
571
-
572
-        if (! empty($or_val) && empty($value)) {
573
-            return $validate;
574
-        }
575
-
576
-        // trim any commas from beginning and end of string ( after whitespace trimmed );
577
-        $value = trim(trim($value), ',');
578
-
579
-
580
-        // next we need to split up the string if its comma delimited.
581
-        $emails = explode(',', $value);
582
-        $empty  = false; // used to indicate that there is an empty comma.
583
-        // now let's loop through the emails and do our checks
584
-        foreach ($emails as $email) {
585
-            if (empty($email)) {
586
-                $empty = true;
587
-                continue;
588
-            }
589
-
590
-            // trim whitespace
591
-            $email = trim($email);
592
-            // either its of type "[email protected]", or its of type "fname lname <[email protected]>"
593
-            if (is_email($email)) {
594
-                continue;
595
-            }
596
-            $matches  = array();
597
-            $validate = preg_match('/(.*)<(.+)>/', $email, $matches) ? true : false;
598
-            if ($validate && is_email($matches[2])) {
599
-                continue;
600
-            }
601
-            return false;
602
-        }
603
-
604
-        $validate = $empty && ! $has_shortcodes ? false : $validate;
605
-
606
-        return $validate;
607
-    }
608
-
609
-
610
-    /**
611
-     * Magic getter
612
-     * Using this to provide back compat with add-ons referencing deprecated properties.
613
-     *
614
-     * @param string $property Property being requested
615
-     * @throws Exception
616
-     * @return mixed
617
-     */
618
-    public function __get($property)
619
-    {
620
-        $expected_properties_map = array(
621
-            /**
622
-             * @deprecated 4.9.0
623
-             */
624
-            '_MSGR'   => '_messenger',
625
-            /**
626
-             * @deprecated 4.9.0
627
-             */
628
-            '_MSGTYP' => '_message_type',
629
-        );
630
-
631
-        if (isset($expected_properties_map[ $property ])) {
632
-            return $this->{$expected_properties_map[ $property ]};
633
-        }
634
-
635
-        throw new Exception(
636
-            sprintf(
637
-                esc_html__('The property %1$s being requested on %2$s does not exist', 'event_espresso'),
638
-                $property,
639
-                get_class($this)
640
-            )
641
-        );
642
-    }
20
+	/**
21
+	 * These properties just hold the name for the Messenger and Message Type (defined by child classes).
22
+	 * These are used for retrieving objects etc.
23
+	 *
24
+	 * @var string
25
+	 */
26
+	protected $_m_name;
27
+	protected $_mt_name;
28
+
29
+
30
+	/**
31
+	 * This will hold any error messages from the validation process.
32
+	 * The _errors property holds an associative array of error messages
33
+	 * listing the field as the key and the message as the value.
34
+	 *
35
+	 * @var array()
36
+	 */
37
+	private $_errors = array();
38
+
39
+
40
+	/**
41
+	 * holds an array of fields being validated
42
+	 *
43
+	 * @var array
44
+	 */
45
+	protected $_fields;
46
+
47
+
48
+	/**
49
+	 * this will hold the incoming context
50
+	 *
51
+	 * @var string
52
+	 */
53
+	protected $_context;
54
+
55
+
56
+	/**
57
+	 * this holds an array of fields and the relevant validation information
58
+	 * that the incoming fields data get validated against.
59
+	 * This gets setup in the _set_props() method.
60
+	 *
61
+	 * @var array
62
+	 */
63
+	protected $_validators;
64
+
65
+
66
+	/**
67
+	 * holds the messenger object
68
+	 *
69
+	 * @var object
70
+	 */
71
+	protected $_messenger;
72
+
73
+
74
+	/**
75
+	 * holds the message type object
76
+	 *
77
+	 * @var object
78
+	 */
79
+	protected $_message_type;
80
+
81
+
82
+	/**
83
+	 * will hold any valid_shortcode modifications made by the _modify_validator() method.
84
+	 *
85
+	 * @var array
86
+	 */
87
+	protected $_valid_shortcodes_modifier;
88
+
89
+
90
+	/**
91
+	 * There may be times where a message type wants to include a shortcode group but exclude specific
92
+	 * shortcodes.  If that's the case then it can set this property as an array of shortcodes to exclude and
93
+	 * they will not be allowed.
94
+	 * Array should be indexed by field and values are an array of specific shortcodes to exclude.
95
+	 *
96
+	 * @var array
97
+	 */
98
+	protected $_specific_shortcode_excludes = array();
99
+
100
+
101
+	/**
102
+	 * Runs the validator using the incoming fields array as the fields/values to check.
103
+	 *
104
+	 * @param array $fields The fields sent by the EEM object.
105
+	 * @param       $context
106
+	 * @throws EE_Error
107
+	 * @throws ReflectionException
108
+	 */
109
+	public function __construct($fields, $context)
110
+	{
111
+		// check that _m_name and _mt_name have been set by child class otherwise we get out.
112
+		if (empty($this->_m_name) || empty($this->_mt_name)) {
113
+			throw new EE_Error(
114
+				esc_html__(
115
+					'EE_Messages_Validator child classes MUST set the $_m_name and $_mt_name property.  Check that the child class is doing this',
116
+					'event_espresso'
117
+				)
118
+			);
119
+		}
120
+		$this->_fields  = $fields;
121
+		$this->_context = $context;
122
+
123
+		// load messenger and message_type objects and the related shortcode objects.
124
+		$this->_load_objects();
125
+
126
+
127
+		// modify any messenger/message_type specific validation instructions.  This is what child classes define.
128
+		$this->_modify_validator();
129
+
130
+
131
+		// let's set validators property
132
+		$this->_set_validators();
133
+	}
134
+
135
+
136
+	/**
137
+	 * Child classes instantiate this and use it to modify the _validator_config array property
138
+	 * for the messenger using messengers set_validate_config() method.
139
+	 * This is so we can specify specific validation instructions for a messenger/message_type combo
140
+	 * that aren't handled by the defaults setup in the messenger.
141
+	 *
142
+	 * @abstract
143
+	 * @access protected
144
+	 * @return void
145
+	 */
146
+	abstract protected function _modify_validator();
147
+
148
+
149
+	/**
150
+	 * loads all objects used by validator
151
+	 *
152
+	 * @access private
153
+	 * @throws \EE_Error
154
+	 */
155
+	private function _load_objects()
156
+	{
157
+		// load messenger
158
+		$messenger = ucwords(str_replace('_', ' ', $this->_m_name));
159
+		$messenger = str_replace(' ', '_', $messenger);
160
+		$messenger = 'EE_' . $messenger . '_messenger';
161
+
162
+		if (! class_exists($messenger)) {
163
+			throw new EE_Error(
164
+				sprintf(
165
+					esc_html__('There is no messenger class for the given string (%s)', 'event_espresso'),
166
+					$this->_m_name
167
+				)
168
+			);
169
+		}
170
+
171
+		$this->_messenger = new $messenger();
172
+
173
+		// load message type
174
+		$message_type = ucwords(str_replace('_', ' ', $this->_mt_name));
175
+		$message_type = str_replace(' ', '_', $message_type);
176
+		$message_type = 'EE_' . $message_type . '_message_type';
177
+
178
+		if (! class_exists($message_type)) {
179
+			throw new EE_Error(
180
+				sprintf(
181
+					esc_html__('There is no message type class for the given string (%s)', 'event_espresso'),
182
+					$this->_mt_name
183
+				)
184
+			);
185
+		}
186
+
187
+		$this->_message_type = new $message_type();
188
+	}
189
+
190
+
191
+	/**
192
+	 * used to set the $_validators property
193
+	 *
194
+	 * @access private
195
+	 * @return void
196
+	 * @throws ReflectionException
197
+	 */
198
+	private function _set_validators()
199
+	{
200
+		// let's get all valid shortcodes from mt and message type
201
+		// (messenger will have its set in the _validator_config property for the messenger)
202
+		$mt_codes = $this->_message_type->get_valid_shortcodes();
203
+
204
+
205
+		// get messenger validator_config
206
+		$msgr_validator = $this->_messenger->get_validator_config();
207
+
208
+
209
+		// we only want the valid shortcodes for the given context!
210
+		$context  = $this->_context;
211
+		$mt_codes = $mt_codes[ $context ];
212
+
213
+		// in this first loop we're just getting all shortcode group indexes from the msgr_validator
214
+		// into a single array (so we can get the appropriate shortcode objects for the groups)
215
+		$shortcode_groups = $mt_codes;
216
+		$groups_per_field = array();
217
+
218
+		foreach ($msgr_validator as $field => $config) {
219
+			if (empty($config) || ! isset($config['shortcodes'])) {
220
+				continue;
221
+			}  //Nothing to see here.
222
+			$groups_per_field[ $field ] = array_intersect($config['shortcodes'], $mt_codes);
223
+			$shortcode_groups         = array_merge($config['shortcodes'], $shortcode_groups);
224
+		}
225
+
226
+		$shortcode_groups = array_unique($shortcode_groups);
227
+
228
+		// okay now we've got our groups.
229
+		// Let's get the codes from the objects into an array indexed by group for easy retrieval later.
230
+		$codes_from_objs = array();
231
+
232
+		foreach ($shortcode_groups as $group) {
233
+			$ref       = ucwords(str_replace('_', ' ', $group));
234
+			$ref       = str_replace(' ', '_', $ref);
235
+			$classname = 'EE_' . $ref . '_Shortcodes';
236
+			if (class_exists($classname)) {
237
+				$a                       = new ReflectionClass($classname);
238
+				$obj                     = $a->newInstance();
239
+				$codes_from_objs[ $group ] = $obj->get_shortcodes();
240
+			}
241
+		}
242
+
243
+
244
+		// let's just replace the $mt shortcode group indexes with the actual shortcodes (unique)
245
+		$final_mt_codes = array();
246
+		foreach ($mt_codes as $group) {
247
+			$final_mt_codes = array_merge($final_mt_codes, $codes_from_objs[ $group ]);
248
+		}
249
+
250
+		$mt_codes = $final_mt_codes;
251
+
252
+
253
+		// k now in this next loop we're going to loop through $msgr_validator again
254
+		// and setup the _validators property from the data we've setup so far.
255
+		foreach ($msgr_validator as $field => $config) {
256
+			// if required shortcode is not in our list of codes for the given field, then we skip this field.
257
+			$required = isset($config['required'])
258
+				? array_intersect($config['required'], array_keys($mt_codes))
259
+				: true;
260
+			if (empty($required)) {
261
+				continue;
262
+			}
263
+
264
+			if (isset($this->_valid_shortcodes_modifier[ $context ][ $field ])) {
265
+				// If we have an override then we use it to indicate the codes we want.
266
+				$this->_validators[ $field ]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group(
267
+					$this->_valid_shortcodes_modifier[ $context ][ $field ],
268
+					$codes_from_objs
269
+				);
270
+			} elseif (isset($groups_per_field[ $field ])) {
271
+				// if we have specific shortcodes for a field then we need to use them
272
+				$this->_validators[ $field ]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group(
273
+					$groups_per_field[ $field ],
274
+					$codes_from_objs
275
+				);
276
+			} elseif (empty($config)) {
277
+				// if empty config then we're assuming we're just going to use the shortcodes from the message type
278
+				// context
279
+				$this->_validators[ $field ]['shortcodes'] = $mt_codes;
280
+			} elseif (isset($config['specific_shortcodes'])) {
281
+				// if we have specific shortcodes then we need to use them
282
+				$this->_validators[ $field ]['shortcodes'] = $config['specific_shortcodes'];
283
+			} else {
284
+				// otherwise the shortcodes are what is set by the messenger for that field
285
+				foreach ($config['shortcodes'] as $group) {
286
+					$this->_validators[ $field ]['shortcodes'] = isset($this->_validators[ $field ]['shortcodes'])
287
+						? array_merge($this->_validators[ $field ]['shortcodes'], $codes_from_objs[ $group ])
288
+						: $codes_from_objs[ $group ];
289
+				}
290
+			}
291
+
292
+			// now let's just make sure that any excluded specific shortcodes are removed.
293
+			$specific_excludes = $this->get_specific_shortcode_excludes();
294
+			if (isset($specific_excludes[ $field ])) {
295
+				foreach ($specific_excludes[ $field ] as $sex) {
296
+					if (isset($this->_validators[ $field ]['shortcodes'][ $sex ])) {
297
+						unset($this->_validators[ $field ]['shortcodes'][ $sex ]);
298
+					}
299
+				}
300
+			}
301
+
302
+			// hey! don't forget to include the type if present!
303
+			$this->_validators[ $field ]['type'] = isset($config['type']) ? $config['type'] : null;
304
+		}
305
+	}
306
+
307
+
308
+	/**
309
+	 * This just returns the validators property that contains information
310
+	 * about the various shortcodes and their availability with each field
311
+	 *
312
+	 * @return array
313
+	 */
314
+	public function get_validators()
315
+	{
316
+		return $this->_validators;
317
+	}
318
+
319
+
320
+	/**
321
+	 * This simply returns the specific shortcode_excludes property that is set.
322
+	 *
323
+	 * @since 4.5.0
324
+	 * @return array
325
+	 */
326
+	public function get_specific_shortcode_excludes()
327
+	{
328
+		// specific validator filter
329
+		$shortcode_excludes = apply_filters(
330
+			'FHEE__' . get_class($this) . '__get_specific_shortcode_excludes;',
331
+			$this->_specific_shortcode_excludes,
332
+			$this->_context
333
+		);
334
+		// global filter
335
+		return apply_filters(
336
+			'FHEE__EE_Messages_Validator__get_specific_shortcode_excludes',
337
+			$shortcode_excludes,
338
+			$this->_context,
339
+			$this
340
+		);
341
+	}
342
+
343
+
344
+	/**
345
+	 * This is the main method that handles validation
346
+	 * What it does is loop through the _fields (the ones that get validated)
347
+	 * and checks them against the shortcodes array for the field and the 'type' indicated by the
348
+	 *
349
+	 * @access public
350
+	 * @return mixed (bool|array)  if errors present we return the array otherwise true
351
+	 */
352
+	public function validate()
353
+	{
354
+		// some defaults
355
+		$template_fields = $this->_messenger->get_template_fields();
356
+		// loop through the fields and check!
357
+		foreach ($this->_fields as $field => $value) {
358
+			$this->_errors[ $field ] = array();
359
+			$err_msg               = '';
360
+			$field_label           = '';
361
+			// if field is not present in the _validators array then we continue
362
+			if (! isset($this->_validators[ $field ])) {
363
+				unset($this->_errors[ $field ]);
364
+				continue;
365
+			}
366
+
367
+			// get the translated field label!
368
+			// first check if it's in the main fields list
369
+			if (isset($template_fields[ $field ])) {
370
+				if (empty($template_fields[ $field ])) {
371
+					$field_label = $field;
372
+				} else {
373
+					// most likely the field is found in the 'extra' array.
374
+					$field_label = $template_fields[ $field ]['label'];
375
+				}
376
+			}
377
+
378
+			// if field label is empty OR is equal to the current field
379
+			// then we need to loop through the 'extra' fields in the template_fields config (if present)
380
+			if (isset($template_fields['extra']) && (empty($field_label) || $field_label === $field)) {
381
+				foreach ($template_fields['extra'] as $main_field => $secondary_field) {
382
+					foreach ($secondary_field as $name => $values) {
383
+						if ($name === $field) {
384
+							$field_label = $values['label'];
385
+						}
386
+
387
+						// if we've got a 'main' secondary field, let's see if that matches what field we're on
388
+						// which means it contains the label for this field.
389
+						if ($name === 'main' && $main_field === $field_label) {
390
+							$field_label = $values['label'];
391
+						}
392
+					}
393
+				}
394
+			}
395
+
396
+			// field is present. Let's validate shortcodes first (but only if shortcodes present).
397
+			if (isset($this->_validators[ $field ]['shortcodes'])
398
+				&& ! empty($this->_validators[ $field ]['shortcodes'])
399
+			) {
400
+				$invalid_shortcodes = $this->_invalid_shortcodes($value, $this->_validators[ $field ]['shortcodes']);
401
+				// if true then that means there is a returned error message
402
+				// that we'll need to add to the _errors array for this field.
403
+				if ($invalid_shortcodes) {
404
+					$v_s     = array_keys($this->_validators[ $field ]['shortcodes']);
405
+					$err_msg = sprintf(
406
+						esc_html__(
407
+							'%3$sThe following shortcodes were found in the "%1$s" field that ARE not valid: %2$s%4$s',
408
+							'event_espresso'
409
+						),
410
+						'<strong>' . $field_label . '</strong>',
411
+						$invalid_shortcodes,
412
+						'<p>',
413
+						'</p >'
414
+					);
415
+					$err_msg .= sprintf(
416
+						esc_html__('%2$sValid shortcodes for this field are: %1$s%3$s', 'event_espresso'),
417
+						implode(', ', $v_s),
418
+						'<strong>',
419
+						'</strong>'
420
+					);
421
+				}
422
+			}
423
+
424
+			// if there's a "type" to be validated then let's do that too.
425
+			if (isset($this->_validators[ $field ]['type']) && ! empty($this->_validators[ $field ]['type'])) {
426
+				switch ($this->_validators[ $field ]['type']) {
427
+					case 'number':
428
+						if (! is_numeric($value)) {
429
+							$err_msg .= sprintf(
430
+								esc_html__(
431
+									'%3$sThe %1$s field is supposed to be a number. The value given (%2$s)  is not.  Please double-check and make sure the field contains a number%4$s',
432
+									'event_espresso'
433
+								),
434
+								$field_label,
435
+								$value,
436
+								'<p>',
437
+								'</p >'
438
+							);
439
+						}
440
+						break;
441
+					case 'email':
442
+						$valid_email = $this->_validate_email($value);
443
+						if (! $valid_email) {
444
+							$err_msg .= htmlentities(
445
+								sprintf(
446
+									esc_html__(
447
+										'The %1$s field has at least one string that is not a valid email address record.  Valid emails are in the format: "Name <[email protected]>" or "[email protected]" and multiple emails can be separated by a comma.',
448
+										'event_espresso'
449
+									),
450
+									$field_label
451
+								)
452
+							);
453
+						}
454
+						break;
455
+					default:
456
+						break;
457
+				}
458
+			}
459
+
460
+			// if $err_msg isn't empty let's setup the _errors array for this field.
461
+			if (! empty($err_msg)) {
462
+				$this->_errors[ $field ]['msg'] = $err_msg;
463
+			} else {
464
+				unset($this->_errors[ $field ]);
465
+			}
466
+		}
467
+
468
+		// if we have ANY errors, then we want to make sure we return the values
469
+		// for ALL the fields so the user doesn't have to retype them all.
470
+		if (! empty($this->_errors)) {
471
+			foreach ($this->_fields as $field => $value) {
472
+				$this->_errors[ $field ]['value'] = stripslashes($value);
473
+			}
474
+		}
475
+
476
+		// return any errors or just TRUE if everything validates
477
+		return empty($this->_errors) ? true : $this->_errors;
478
+	}
479
+
480
+
481
+	/**
482
+	 * Reassembles and returns an array of valid shortcodes
483
+	 * given the array of groups and array of shortcodes indexed by group.
484
+	 *
485
+	 * @param  array $groups          array of shortcode groups that we want shortcodes for
486
+	 * @param  array $codes_from_objs All the codes available.
487
+	 * @return array                   an array of actual shortcodes (that will be used for validation).
488
+	 */
489
+	private function _reassemble_valid_shortcodes_from_group($groups, $codes_from_objs)
490
+	{
491
+		$shortcodes = array();
492
+		foreach ($groups as $group) {
493
+			$shortcodes = array_merge($shortcodes, $codes_from_objs[ $group ]);
494
+		}
495
+		return $shortcodes;
496
+	}
497
+
498
+
499
+	/**
500
+	 * Validates a string against a list of accepted shortcodes
501
+	 * This function takes in an array of shortcodes
502
+	 * and makes sure that the given string ONLY contains shortcodes in that array.
503
+	 *
504
+	 * @param  string $value            string to evaluate
505
+	 * @param  array  $valid_shortcodes array of shortcodes that are acceptable.
506
+	 * @return mixed (bool|string)  return either a list of invalid shortcodes OR false if the shortcodes validate.
507
+	 */
508
+	protected function _invalid_shortcodes($value, $valid_shortcodes)
509
+	{
510
+		// first we need to go through the string and get the shortcodes in the string
511
+		preg_match_all('/(\[.+?\])/', $value, $matches);
512
+		$incoming_shortcodes = (array) $matches[0];
513
+
514
+		// get a diff of the shortcodes in the string vs the valid shortcodes
515
+		$diff = array_diff($incoming_shortcodes, array_keys($valid_shortcodes));
516
+
517
+		// we need to account for custom codes so let's loop through the diff and remove any of those type of codes
518
+		foreach ($diff as $ind => $code) {
519
+			if (preg_match('/(\[[A-Za-z0-9\_]+_\*)/', $code)) {
520
+				// strip the shortcode so we just have the BASE string (i.e. [ANSWER_*] )
521
+				$dynamic_sc = preg_replace('/(_\*+.+)/', '_*]', $code);
522
+				// does this exist in the $valid_shortcodes?  If so then unset.
523
+				if (isset($valid_shortcodes[ $dynamic_sc ])) {
524
+					unset($diff[ $ind ]);
525
+				}
526
+			}
527
+		}
528
+
529
+		if (empty($diff)) {
530
+			return false;
531
+		} //there is no diff, we have no invalid shortcodes, so return
532
+
533
+		// made it here? then let's assemble the error message
534
+		$invalid_shortcodes = implode('</strong>,<strong>', $diff);
535
+		$invalid_shortcodes = '<strong>' . $invalid_shortcodes . '</strong>';
536
+		return $invalid_shortcodes;
537
+	}
538
+
539
+
540
+	/**
541
+	 * Validates an incoming string and makes sure we have valid emails in the string.
542
+	 *
543
+	 * @param  string $value incoming value to validate
544
+	 * @return bool        true if the string validates, false if it doesn't
545
+	 */
546
+	protected function _validate_email($value)
547
+	{
548
+		$validate = true;
549
+		$or_val   = $value;
550
+
551
+		// empty strings will validate because this is how a message template
552
+		// for a particular context can be "turned off" (if there is no email then no message)
553
+		if (empty($value)) {
554
+			return $validate;
555
+		}
556
+
557
+		// first determine if there ARE any shortcodes.
558
+		// If there are shortcodes and then later we find that there were no other valid emails
559
+		// but the field isn't empty...
560
+		// that means we've got extra commas that were left after stripping out shortcodes so probably still valid.
561
+		$has_shortcodes = preg_match('/(\[.+?\])/', $value);
562
+
563
+		// first we need to strip out all the shortcodes!
564
+		$value = preg_replace('/(\[.+?\])/', '', $value);
565
+
566
+		// if original value is not empty and new value is, then we've parsed out a shortcode
567
+		// and we now have an empty string which DOES validate.
568
+		// We also validate complete empty field for email because
569
+		// its possible that this message is being "turned off" for a particular context
570
+
571
+
572
+		if (! empty($or_val) && empty($value)) {
573
+			return $validate;
574
+		}
575
+
576
+		// trim any commas from beginning and end of string ( after whitespace trimmed );
577
+		$value = trim(trim($value), ',');
578
+
579
+
580
+		// next we need to split up the string if its comma delimited.
581
+		$emails = explode(',', $value);
582
+		$empty  = false; // used to indicate that there is an empty comma.
583
+		// now let's loop through the emails and do our checks
584
+		foreach ($emails as $email) {
585
+			if (empty($email)) {
586
+				$empty = true;
587
+				continue;
588
+			}
589
+
590
+			// trim whitespace
591
+			$email = trim($email);
592
+			// either its of type "[email protected]", or its of type "fname lname <[email protected]>"
593
+			if (is_email($email)) {
594
+				continue;
595
+			}
596
+			$matches  = array();
597
+			$validate = preg_match('/(.*)<(.+)>/', $email, $matches) ? true : false;
598
+			if ($validate && is_email($matches[2])) {
599
+				continue;
600
+			}
601
+			return false;
602
+		}
603
+
604
+		$validate = $empty && ! $has_shortcodes ? false : $validate;
605
+
606
+		return $validate;
607
+	}
608
+
609
+
610
+	/**
611
+	 * Magic getter
612
+	 * Using this to provide back compat with add-ons referencing deprecated properties.
613
+	 *
614
+	 * @param string $property Property being requested
615
+	 * @throws Exception
616
+	 * @return mixed
617
+	 */
618
+	public function __get($property)
619
+	{
620
+		$expected_properties_map = array(
621
+			/**
622
+			 * @deprecated 4.9.0
623
+			 */
624
+			'_MSGR'   => '_messenger',
625
+			/**
626
+			 * @deprecated 4.9.0
627
+			 */
628
+			'_MSGTYP' => '_message_type',
629
+		);
630
+
631
+		if (isset($expected_properties_map[ $property ])) {
632
+			return $this->{$expected_properties_map[ $property ]};
633
+		}
634
+
635
+		throw new Exception(
636
+			sprintf(
637
+				esc_html__('The property %1$s being requested on %2$s does not exist', 'event_espresso'),
638
+				$property,
639
+				get_class($this)
640
+			)
641
+		);
642
+	}
643 643
 }
Please login to merge, or discard this patch.
Spacing   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -157,9 +157,9 @@  discard block
 block discarded – undo
157 157
         // load messenger
158 158
         $messenger = ucwords(str_replace('_', ' ', $this->_m_name));
159 159
         $messenger = str_replace(' ', '_', $messenger);
160
-        $messenger = 'EE_' . $messenger . '_messenger';
160
+        $messenger = 'EE_'.$messenger.'_messenger';
161 161
 
162
-        if (! class_exists($messenger)) {
162
+        if ( ! class_exists($messenger)) {
163 163
             throw new EE_Error(
164 164
                 sprintf(
165 165
                     esc_html__('There is no messenger class for the given string (%s)', 'event_espresso'),
@@ -173,9 +173,9 @@  discard block
 block discarded – undo
173 173
         // load message type
174 174
         $message_type = ucwords(str_replace('_', ' ', $this->_mt_name));
175 175
         $message_type = str_replace(' ', '_', $message_type);
176
-        $message_type = 'EE_' . $message_type . '_message_type';
176
+        $message_type = 'EE_'.$message_type.'_message_type';
177 177
 
178
-        if (! class_exists($message_type)) {
178
+        if ( ! class_exists($message_type)) {
179 179
             throw new EE_Error(
180 180
                 sprintf(
181 181
                     esc_html__('There is no message type class for the given string (%s)', 'event_espresso'),
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
 
209 209
         // we only want the valid shortcodes for the given context!
210 210
         $context  = $this->_context;
211
-        $mt_codes = $mt_codes[ $context ];
211
+        $mt_codes = $mt_codes[$context];
212 212
 
213 213
         // in this first loop we're just getting all shortcode group indexes from the msgr_validator
214 214
         // into a single array (so we can get the appropriate shortcode objects for the groups)
@@ -219,8 +219,8 @@  discard block
 block discarded – undo
219 219
             if (empty($config) || ! isset($config['shortcodes'])) {
220 220
                 continue;
221 221
             }  //Nothing to see here.
222
-            $groups_per_field[ $field ] = array_intersect($config['shortcodes'], $mt_codes);
223
-            $shortcode_groups         = array_merge($config['shortcodes'], $shortcode_groups);
222
+            $groups_per_field[$field] = array_intersect($config['shortcodes'], $mt_codes);
223
+            $shortcode_groups = array_merge($config['shortcodes'], $shortcode_groups);
224 224
         }
225 225
 
226 226
         $shortcode_groups = array_unique($shortcode_groups);
@@ -232,11 +232,11 @@  discard block
 block discarded – undo
232 232
         foreach ($shortcode_groups as $group) {
233 233
             $ref       = ucwords(str_replace('_', ' ', $group));
234 234
             $ref       = str_replace(' ', '_', $ref);
235
-            $classname = 'EE_' . $ref . '_Shortcodes';
235
+            $classname = 'EE_'.$ref.'_Shortcodes';
236 236
             if (class_exists($classname)) {
237 237
                 $a                       = new ReflectionClass($classname);
238 238
                 $obj                     = $a->newInstance();
239
-                $codes_from_objs[ $group ] = $obj->get_shortcodes();
239
+                $codes_from_objs[$group] = $obj->get_shortcodes();
240 240
             }
241 241
         }
242 242
 
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
         // let's just replace the $mt shortcode group indexes with the actual shortcodes (unique)
245 245
         $final_mt_codes = array();
246 246
         foreach ($mt_codes as $group) {
247
-            $final_mt_codes = array_merge($final_mt_codes, $codes_from_objs[ $group ]);
247
+            $final_mt_codes = array_merge($final_mt_codes, $codes_from_objs[$group]);
248 248
         }
249 249
 
250 250
         $mt_codes = $final_mt_codes;
@@ -261,46 +261,46 @@  discard block
 block discarded – undo
261 261
                 continue;
262 262
             }
263 263
 
264
-            if (isset($this->_valid_shortcodes_modifier[ $context ][ $field ])) {
264
+            if (isset($this->_valid_shortcodes_modifier[$context][$field])) {
265 265
                 // If we have an override then we use it to indicate the codes we want.
266
-                $this->_validators[ $field ]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group(
267
-                    $this->_valid_shortcodes_modifier[ $context ][ $field ],
266
+                $this->_validators[$field]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group(
267
+                    $this->_valid_shortcodes_modifier[$context][$field],
268 268
                     $codes_from_objs
269 269
                 );
270
-            } elseif (isset($groups_per_field[ $field ])) {
270
+            } elseif (isset($groups_per_field[$field])) {
271 271
                 // if we have specific shortcodes for a field then we need to use them
272
-                $this->_validators[ $field ]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group(
273
-                    $groups_per_field[ $field ],
272
+                $this->_validators[$field]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group(
273
+                    $groups_per_field[$field],
274 274
                     $codes_from_objs
275 275
                 );
276 276
             } elseif (empty($config)) {
277 277
                 // if empty config then we're assuming we're just going to use the shortcodes from the message type
278 278
                 // context
279
-                $this->_validators[ $field ]['shortcodes'] = $mt_codes;
279
+                $this->_validators[$field]['shortcodes'] = $mt_codes;
280 280
             } elseif (isset($config['specific_shortcodes'])) {
281 281
                 // if we have specific shortcodes then we need to use them
282
-                $this->_validators[ $field ]['shortcodes'] = $config['specific_shortcodes'];
282
+                $this->_validators[$field]['shortcodes'] = $config['specific_shortcodes'];
283 283
             } else {
284 284
                 // otherwise the shortcodes are what is set by the messenger for that field
285 285
                 foreach ($config['shortcodes'] as $group) {
286
-                    $this->_validators[ $field ]['shortcodes'] = isset($this->_validators[ $field ]['shortcodes'])
287
-                        ? array_merge($this->_validators[ $field ]['shortcodes'], $codes_from_objs[ $group ])
288
-                        : $codes_from_objs[ $group ];
286
+                    $this->_validators[$field]['shortcodes'] = isset($this->_validators[$field]['shortcodes'])
287
+                        ? array_merge($this->_validators[$field]['shortcodes'], $codes_from_objs[$group])
288
+                        : $codes_from_objs[$group];
289 289
                 }
290 290
             }
291 291
 
292 292
             // now let's just make sure that any excluded specific shortcodes are removed.
293 293
             $specific_excludes = $this->get_specific_shortcode_excludes();
294
-            if (isset($specific_excludes[ $field ])) {
295
-                foreach ($specific_excludes[ $field ] as $sex) {
296
-                    if (isset($this->_validators[ $field ]['shortcodes'][ $sex ])) {
297
-                        unset($this->_validators[ $field ]['shortcodes'][ $sex ]);
294
+            if (isset($specific_excludes[$field])) {
295
+                foreach ($specific_excludes[$field] as $sex) {
296
+                    if (isset($this->_validators[$field]['shortcodes'][$sex])) {
297
+                        unset($this->_validators[$field]['shortcodes'][$sex]);
298 298
                     }
299 299
                 }
300 300
             }
301 301
 
302 302
             // hey! don't forget to include the type if present!
303
-            $this->_validators[ $field ]['type'] = isset($config['type']) ? $config['type'] : null;
303
+            $this->_validators[$field]['type'] = isset($config['type']) ? $config['type'] : null;
304 304
         }
305 305
     }
306 306
 
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
     {
328 328
         // specific validator filter
329 329
         $shortcode_excludes = apply_filters(
330
-            'FHEE__' . get_class($this) . '__get_specific_shortcode_excludes;',
330
+            'FHEE__'.get_class($this).'__get_specific_shortcode_excludes;',
331 331
             $this->_specific_shortcode_excludes,
332 332
             $this->_context
333 333
         );
@@ -355,23 +355,23 @@  discard block
 block discarded – undo
355 355
         $template_fields = $this->_messenger->get_template_fields();
356 356
         // loop through the fields and check!
357 357
         foreach ($this->_fields as $field => $value) {
358
-            $this->_errors[ $field ] = array();
358
+            $this->_errors[$field] = array();
359 359
             $err_msg               = '';
360 360
             $field_label           = '';
361 361
             // if field is not present in the _validators array then we continue
362
-            if (! isset($this->_validators[ $field ])) {
363
-                unset($this->_errors[ $field ]);
362
+            if ( ! isset($this->_validators[$field])) {
363
+                unset($this->_errors[$field]);
364 364
                 continue;
365 365
             }
366 366
 
367 367
             // get the translated field label!
368 368
             // first check if it's in the main fields list
369
-            if (isset($template_fields[ $field ])) {
370
-                if (empty($template_fields[ $field ])) {
369
+            if (isset($template_fields[$field])) {
370
+                if (empty($template_fields[$field])) {
371 371
                     $field_label = $field;
372 372
                 } else {
373 373
                     // most likely the field is found in the 'extra' array.
374
-                    $field_label = $template_fields[ $field ]['label'];
374
+                    $field_label = $template_fields[$field]['label'];
375 375
                 }
376 376
             }
377 377
 
@@ -394,20 +394,20 @@  discard block
 block discarded – undo
394 394
             }
395 395
 
396 396
             // field is present. Let's validate shortcodes first (but only if shortcodes present).
397
-            if (isset($this->_validators[ $field ]['shortcodes'])
398
-                && ! empty($this->_validators[ $field ]['shortcodes'])
397
+            if (isset($this->_validators[$field]['shortcodes'])
398
+                && ! empty($this->_validators[$field]['shortcodes'])
399 399
             ) {
400
-                $invalid_shortcodes = $this->_invalid_shortcodes($value, $this->_validators[ $field ]['shortcodes']);
400
+                $invalid_shortcodes = $this->_invalid_shortcodes($value, $this->_validators[$field]['shortcodes']);
401 401
                 // if true then that means there is a returned error message
402 402
                 // that we'll need to add to the _errors array for this field.
403 403
                 if ($invalid_shortcodes) {
404
-                    $v_s     = array_keys($this->_validators[ $field ]['shortcodes']);
404
+                    $v_s     = array_keys($this->_validators[$field]['shortcodes']);
405 405
                     $err_msg = sprintf(
406 406
                         esc_html__(
407 407
                             '%3$sThe following shortcodes were found in the "%1$s" field that ARE not valid: %2$s%4$s',
408 408
                             'event_espresso'
409 409
                         ),
410
-                        '<strong>' . $field_label . '</strong>',
410
+                        '<strong>'.$field_label.'</strong>',
411 411
                         $invalid_shortcodes,
412 412
                         '<p>',
413 413
                         '</p >'
@@ -422,10 +422,10 @@  discard block
 block discarded – undo
422 422
             }
423 423
 
424 424
             // if there's a "type" to be validated then let's do that too.
425
-            if (isset($this->_validators[ $field ]['type']) && ! empty($this->_validators[ $field ]['type'])) {
426
-                switch ($this->_validators[ $field ]['type']) {
425
+            if (isset($this->_validators[$field]['type']) && ! empty($this->_validators[$field]['type'])) {
426
+                switch ($this->_validators[$field]['type']) {
427 427
                     case 'number':
428
-                        if (! is_numeric($value)) {
428
+                        if ( ! is_numeric($value)) {
429 429
                             $err_msg .= sprintf(
430 430
                                 esc_html__(
431 431
                                     '%3$sThe %1$s field is supposed to be a number. The value given (%2$s)  is not.  Please double-check and make sure the field contains a number%4$s',
@@ -440,7 +440,7 @@  discard block
 block discarded – undo
440 440
                         break;
441 441
                     case 'email':
442 442
                         $valid_email = $this->_validate_email($value);
443
-                        if (! $valid_email) {
443
+                        if ( ! $valid_email) {
444 444
                             $err_msg .= htmlentities(
445 445
                                 sprintf(
446 446
                                     esc_html__(
@@ -458,18 +458,18 @@  discard block
 block discarded – undo
458 458
             }
459 459
 
460 460
             // if $err_msg isn't empty let's setup the _errors array for this field.
461
-            if (! empty($err_msg)) {
462
-                $this->_errors[ $field ]['msg'] = $err_msg;
461
+            if ( ! empty($err_msg)) {
462
+                $this->_errors[$field]['msg'] = $err_msg;
463 463
             } else {
464
-                unset($this->_errors[ $field ]);
464
+                unset($this->_errors[$field]);
465 465
             }
466 466
         }
467 467
 
468 468
         // if we have ANY errors, then we want to make sure we return the values
469 469
         // for ALL the fields so the user doesn't have to retype them all.
470
-        if (! empty($this->_errors)) {
470
+        if ( ! empty($this->_errors)) {
471 471
             foreach ($this->_fields as $field => $value) {
472
-                $this->_errors[ $field ]['value'] = stripslashes($value);
472
+                $this->_errors[$field]['value'] = stripslashes($value);
473 473
             }
474 474
         }
475 475
 
@@ -490,7 +490,7 @@  discard block
 block discarded – undo
490 490
     {
491 491
         $shortcodes = array();
492 492
         foreach ($groups as $group) {
493
-            $shortcodes = array_merge($shortcodes, $codes_from_objs[ $group ]);
493
+            $shortcodes = array_merge($shortcodes, $codes_from_objs[$group]);
494 494
         }
495 495
         return $shortcodes;
496 496
     }
@@ -520,8 +520,8 @@  discard block
 block discarded – undo
520 520
                 // strip the shortcode so we just have the BASE string (i.e. [ANSWER_*] )
521 521
                 $dynamic_sc = preg_replace('/(_\*+.+)/', '_*]', $code);
522 522
                 // does this exist in the $valid_shortcodes?  If so then unset.
523
-                if (isset($valid_shortcodes[ $dynamic_sc ])) {
524
-                    unset($diff[ $ind ]);
523
+                if (isset($valid_shortcodes[$dynamic_sc])) {
524
+                    unset($diff[$ind]);
525 525
                 }
526 526
             }
527 527
         }
@@ -532,7 +532,7 @@  discard block
 block discarded – undo
532 532
 
533 533
         // made it here? then let's assemble the error message
534 534
         $invalid_shortcodes = implode('</strong>,<strong>', $diff);
535
-        $invalid_shortcodes = '<strong>' . $invalid_shortcodes . '</strong>';
535
+        $invalid_shortcodes = '<strong>'.$invalid_shortcodes.'</strong>';
536 536
         return $invalid_shortcodes;
537 537
     }
538 538
 
@@ -569,7 +569,7 @@  discard block
 block discarded – undo
569 569
         // its possible that this message is being "turned off" for a particular context
570 570
 
571 571
 
572
-        if (! empty($or_val) && empty($value)) {
572
+        if ( ! empty($or_val) && empty($value)) {
573 573
             return $validate;
574 574
         }
575 575
 
@@ -628,8 +628,8 @@  discard block
 block discarded – undo
628 628
             '_MSGTYP' => '_message_type',
629 629
         );
630 630
 
631
-        if (isset($expected_properties_map[ $property ])) {
632
-            return $this->{$expected_properties_map[ $property ]};
631
+        if (isset($expected_properties_map[$property])) {
632
+            return $this->{$expected_properties_map[$property]};
633 633
         }
634 634
 
635 635
         throw new Exception(
Please login to merge, or discard this patch.
core/db_models/fields/EE_Simple_HTML_Field.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -11,14 +11,14 @@
 block discarded – undo
11 11
 
12 12
 
13 13
 
14
-    /**
15
-     * removes all tags which a WP Post wouldn't allow in its content normally
16
-     *
17
-     * @param string $value
18
-     * @return string
19
-     */
20
-    public function prepare_for_set($value)
21
-    {
22
-        return parent::prepare_for_set(wp_kses("$value", EEH_HTML::get_simple_tags()));
23
-    }
14
+	/**
15
+	 * removes all tags which a WP Post wouldn't allow in its content normally
16
+	 *
17
+	 * @param string $value
18
+	 * @return string
19
+	 */
20
+	public function prepare_for_set($value)
21
+	{
22
+		return parent::prepare_for_set(wp_kses("$value", EEH_HTML::get_simple_tags()));
23
+	}
24 24
 }
Please login to merge, or discard this patch.
core/db_classes/EE_Attendee.class.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -603,7 +603,7 @@  discard block
 block discarded – undo
603 603
     /**
604 604
      * returns any events attached to this attendee ($_Event property);
605 605
      *
606
-     * @return array
606
+     * @return EE_Base_Class[]
607 607
      * @throws EE_Error
608 608
      */
609 609
     public function events()
@@ -618,7 +618,7 @@  discard block
 block discarded – undo
618 618
      * used to save the billing info
619 619
      *
620 620
      * @param EE_Payment_Method $payment_method the _gateway_name property on the gateway class
621
-     * @return EE_Form_Section_Proper|null
621
+     * @return null|EE_Billing_Info_Form
622 622
      * @throws EE_Error
623 623
      */
624 624
     public function billing_info_for_payment_method($payment_method)
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -36,16 +36,16 @@  discard block
 block discarded – undo
36 36
      */
37 37
     protected function __construct($fieldValues = null, $bydb = false, $timezone = null, $date_formats = array())
38 38
     {
39
-        if (! isset($fieldValues['ATT_full_name'])) {
40
-            $fname = isset($fieldValues['ATT_fname']) ? $fieldValues['ATT_fname'] . ' ' : '';
39
+        if ( ! isset($fieldValues['ATT_full_name'])) {
40
+            $fname = isset($fieldValues['ATT_fname']) ? $fieldValues['ATT_fname'].' ' : '';
41 41
             $lname = isset($fieldValues['ATT_lname']) ? $fieldValues['ATT_lname'] : '';
42
-            $fieldValues['ATT_full_name'] = $fname . $lname;
42
+            $fieldValues['ATT_full_name'] = $fname.$lname;
43 43
         }
44
-        if (! isset($fieldValues['ATT_slug'])) {
44
+        if ( ! isset($fieldValues['ATT_slug'])) {
45 45
             // $fieldValues['ATT_slug'] = sanitize_key(wp_generate_password(20));
46 46
             $fieldValues['ATT_slug'] = sanitize_title($fieldValues['ATT_full_name']);
47 47
         }
48
-        if (! isset($fieldValues['ATT_short_bio']) && isset($fieldValues['ATT_bio'])) {
48
+        if ( ! isset($fieldValues['ATT_short_bio']) && isset($fieldValues['ATT_bio'])) {
49 49
             $fieldValues['ATT_short_bio'] = substr($fieldValues['ATT_bio'], 0, 50);
50 50
         }
51 51
         parent::__construct($fieldValues, $bydb, $timezone, $date_formats);
@@ -325,7 +325,7 @@  discard block
 block discarded – undo
325 325
         $initial_address_fields = array('ATT_address', 'ATT_address2', 'ATT_city',);
326 326
         foreach ($initial_address_fields as $address_field_name) {
327 327
             $address_fields_value = $this->get($address_field_name);
328
-            if (! empty($address_fields_value)) {
328
+            if ( ! empty($address_fields_value)) {
329 329
                 $full_address_array[] = $address_fields_value;
330 330
             }
331 331
         }
@@ -340,7 +340,7 @@  discard block
 block discarded – undo
340 340
         }
341 341
         // lastly get the xip
342 342
         $zip_value = $this->zip();
343
-        if (! empty($zip_value)) {
343
+        if ( ! empty($zip_value)) {
344 344
             $full_address_array[] = $zip_value;
345 345
         }
346 346
         return $full_address_array;
@@ -622,18 +622,18 @@  discard block
 block discarded – undo
622 622
     public function billing_info_for_payment_method($payment_method)
623 623
     {
624 624
         $pm_type = $payment_method->type_obj();
625
-        if (! $pm_type instanceof EE_PMT_Base) {
625
+        if ( ! $pm_type instanceof EE_PMT_Base) {
626 626
             return null;
627 627
         }
628 628
         $billing_info = $this->get_post_meta($this->get_billing_info_postmeta_name($payment_method), true);
629
-        if (! $billing_info) {
629
+        if ( ! $billing_info) {
630 630
             return null;
631 631
         }
632 632
         $billing_form = $pm_type->billing_form();
633 633
         // double-check the form isn't totally hidden, in which case pretend there is no form
634 634
         $form_totally_hidden = true;
635 635
         foreach ($billing_form->inputs_in_subsections() as $input) {
636
-            if (! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) {
636
+            if ( ! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) {
637 637
                 $form_totally_hidden = false;
638 638
                 break;
639 639
             }
@@ -660,7 +660,7 @@  discard block
 block discarded – undo
660 660
     public function get_billing_info_postmeta_name($payment_method)
661 661
     {
662 662
         if ($payment_method->type_obj() instanceof EE_PMT_Base) {
663
-            return 'billing_info_' . $payment_method->type_obj()->system_name();
663
+            return 'billing_info_'.$payment_method->type_obj()->system_name();
664 664
         }
665 665
         return null;
666 666
     }
@@ -677,7 +677,7 @@  discard block
 block discarded – undo
677 677
      */
678 678
     public function save_and_clean_billing_info_for_payment_method($billing_form, $payment_method)
679 679
     {
680
-        if (! $billing_form instanceof EE_Billing_Attendee_Info_Form) {
680
+        if ( ! $billing_form instanceof EE_Billing_Attendee_Info_Form) {
681 681
             EE_Error::add_error(__('Cannot save billing info because there is none.', 'event_espresso'));
682 682
             return false;
683 683
         }
Please login to merge, or discard this patch.
Indentation   +768 added lines, -768 removed lines patch added patch discarded remove patch
@@ -25,772 +25,772 @@
 block discarded – undo
25 25
 class EE_Attendee extends EE_CPT_Base implements EEI_Contact, EEI_Address, EEI_Admin_Links, EEI_Attendee
26 26
 {
27 27
 
28
-    /**
29
-     * Sets some dynamic defaults
30
-     *
31
-     * @param array  $fieldValues
32
-     * @param bool   $bydb
33
-     * @param string $timezone
34
-     * @param array  $date_formats
35
-     * @throws EE_Error
36
-     */
37
-    protected function __construct($fieldValues = null, $bydb = false, $timezone = null, $date_formats = array())
38
-    {
39
-        if (! isset($fieldValues['ATT_full_name'])) {
40
-            $fname = isset($fieldValues['ATT_fname']) ? $fieldValues['ATT_fname'] . ' ' : '';
41
-            $lname = isset($fieldValues['ATT_lname']) ? $fieldValues['ATT_lname'] : '';
42
-            $fieldValues['ATT_full_name'] = $fname . $lname;
43
-        }
44
-        if (! isset($fieldValues['ATT_slug'])) {
45
-            // $fieldValues['ATT_slug'] = sanitize_key(wp_generate_password(20));
46
-            $fieldValues['ATT_slug'] = sanitize_title($fieldValues['ATT_full_name']);
47
-        }
48
-        if (! isset($fieldValues['ATT_short_bio']) && isset($fieldValues['ATT_bio'])) {
49
-            $fieldValues['ATT_short_bio'] = substr($fieldValues['ATT_bio'], 0, 50);
50
-        }
51
-        parent::__construct($fieldValues, $bydb, $timezone, $date_formats);
52
-    }
53
-
54
-
55
-    /**
56
-     * @param array  $props_n_values          incoming values
57
-     * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
58
-     *                                        used.)
59
-     * @param array  $date_formats            incoming date_formats in an array where the first value is the
60
-     *                                        date_format and the second value is the time format
61
-     * @return EE_Attendee
62
-     * @throws EE_Error
63
-     */
64
-    public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
65
-    {
66
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
67
-        return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
68
-    }
69
-
70
-
71
-    /**
72
-     * @param array  $props_n_values  incoming values from the database
73
-     * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
74
-     *                                the website will be used.
75
-     * @return EE_Attendee
76
-     */
77
-    public static function new_instance_from_db($props_n_values = array(), $timezone = null)
78
-    {
79
-        return new self($props_n_values, true, $timezone);
80
-    }
81
-
82
-
83
-    /**
84
-     *        Set Attendee First Name
85
-     *
86
-     * @access        public
87
-     * @param string $fname
88
-     * @throws EE_Error
89
-     */
90
-    public function set_fname($fname = '')
91
-    {
92
-        $this->set('ATT_fname', $fname);
93
-    }
94
-
95
-
96
-    /**
97
-     *        Set Attendee Last Name
98
-     *
99
-     * @access        public
100
-     * @param string $lname
101
-     * @throws EE_Error
102
-     */
103
-    public function set_lname($lname = '')
104
-    {
105
-        $this->set('ATT_lname', $lname);
106
-    }
107
-
108
-
109
-    /**
110
-     *        Set Attendee Address
111
-     *
112
-     * @access        public
113
-     * @param string $address
114
-     * @throws EE_Error
115
-     */
116
-    public function set_address($address = '')
117
-    {
118
-        $this->set('ATT_address', $address);
119
-    }
120
-
121
-
122
-    /**
123
-     *        Set Attendee Address2
124
-     *
125
-     * @access        public
126
-     * @param        string $address2
127
-     * @throws EE_Error
128
-     */
129
-    public function set_address2($address2 = '')
130
-    {
131
-        $this->set('ATT_address2', $address2);
132
-    }
133
-
134
-
135
-    /**
136
-     *        Set Attendee City
137
-     *
138
-     * @access        public
139
-     * @param        string $city
140
-     * @throws EE_Error
141
-     */
142
-    public function set_city($city = '')
143
-    {
144
-        $this->set('ATT_city', $city);
145
-    }
146
-
147
-
148
-    /**
149
-     *        Set Attendee State ID
150
-     *
151
-     * @access        public
152
-     * @param        int $STA_ID
153
-     * @throws EE_Error
154
-     */
155
-    public function set_state($STA_ID = 0)
156
-    {
157
-        $this->set('STA_ID', $STA_ID);
158
-    }
159
-
160
-
161
-    /**
162
-     *        Set Attendee Country ISO Code
163
-     *
164
-     * @access        public
165
-     * @param        string $CNT_ISO
166
-     * @throws EE_Error
167
-     */
168
-    public function set_country($CNT_ISO = '')
169
-    {
170
-        $this->set('CNT_ISO', $CNT_ISO);
171
-    }
172
-
173
-
174
-    /**
175
-     *        Set Attendee Zip/Postal Code
176
-     *
177
-     * @access        public
178
-     * @param        string $zip
179
-     * @throws EE_Error
180
-     */
181
-    public function set_zip($zip = '')
182
-    {
183
-        $this->set('ATT_zip', $zip);
184
-    }
185
-
186
-
187
-    /**
188
-     *        Set Attendee Email Address
189
-     *
190
-     * @access        public
191
-     * @param        string $email
192
-     * @throws EE_Error
193
-     */
194
-    public function set_email($email = '')
195
-    {
196
-        $this->set('ATT_email', $email);
197
-    }
198
-
199
-
200
-    /**
201
-     *        Set Attendee Phone
202
-     *
203
-     * @access        public
204
-     * @param        string $phone
205
-     * @throws EE_Error
206
-     */
207
-    public function set_phone($phone = '')
208
-    {
209
-        $this->set('ATT_phone', $phone);
210
-    }
211
-
212
-
213
-    /**
214
-     *        set deleted
215
-     *
216
-     * @access        public
217
-     * @param        bool $ATT_deleted
218
-     * @throws EE_Error
219
-     */
220
-    public function set_deleted($ATT_deleted = false)
221
-    {
222
-        $this->set('ATT_deleted', $ATT_deleted);
223
-    }
224
-
225
-
226
-    /**
227
-     * Returns the value for the post_author id saved with the cpt
228
-     *
229
-     * @since 4.5.0
230
-     * @return int
231
-     * @throws EE_Error
232
-     */
233
-    public function wp_user()
234
-    {
235
-        return $this->get('ATT_author');
236
-    }
237
-
238
-
239
-    /**
240
-     *        get Attendee First Name
241
-     *
242
-     * @access        public
243
-     * @return string
244
-     * @throws EE_Error
245
-     */
246
-    public function fname()
247
-    {
248
-        return $this->get('ATT_fname');
249
-    }
250
-
251
-
252
-    /**
253
-     * echoes out the attendee's first name
254
-     *
255
-     * @return void
256
-     * @throws EE_Error
257
-     */
258
-    public function e_full_name()
259
-    {
260
-        echo $this->full_name();
261
-    }
262
-
263
-
264
-    /**
265
-     * Returns the first and last name concatenated together with a space.
266
-     *
267
-     * @param bool $apply_html_entities
268
-     * @return string
269
-     * @throws EE_Error
270
-     */
271
-    public function full_name($apply_html_entities = false)
272
-    {
273
-        $full_name = array(
274
-            $this->fname(),
275
-            $this->lname(),
276
-        );
277
-        $full_name = array_filter($full_name);
278
-        $full_name = implode(' ', $full_name);
279
-        return $apply_html_entities ? htmlentities($full_name, ENT_QUOTES, 'UTF-8') : $full_name;
280
-    }
281
-
282
-
283
-    /**
284
-     * This returns the value of the `ATT_full_name` field which is usually equivalent to calling `full_name()` unless
285
-     * the post_title field has been directly modified in the db for the post (espresso_attendees post type) for this
286
-     * attendee.
287
-     *
288
-     * @param bool $apply_html_entities
289
-     * @return string
290
-     * @throws EE_Error
291
-     */
292
-    public function ATT_full_name($apply_html_entities = false)
293
-    {
294
-        return $apply_html_entities
295
-            ? htmlentities($this->get('ATT_full_name'), ENT_QUOTES, 'UTF-8')
296
-            : $this->get('ATT_full_name');
297
-    }
298
-
299
-
300
-    /**
301
-     *        get Attendee Last Name
302
-     *
303
-     * @access        public
304
-     * @return string
305
-     * @throws EE_Error
306
-     */
307
-    public function lname()
308
-    {
309
-        return $this->get('ATT_lname');
310
-    }
311
-
312
-
313
-    /**
314
-     * get Attendee bio
315
-     *
316
-     * @access public
317
-     * @return string
318
-     * @throws EE_Error
319
-     */
320
-    public function bio()
321
-    {
322
-        return $this->get('ATT_bio');
323
-    }
324
-
325
-
326
-    /**
327
-     * get Attendee short bio
328
-     *
329
-     * @access public
330
-     * @return string
331
-     * @throws EE_Error
332
-     */
333
-    public function short_bio()
334
-    {
335
-        return $this->get('ATT_short_bio');
336
-    }
337
-
338
-
339
-    /**
340
-     * Gets the attendee's full address as an array so client code can decide hwo to display it
341
-     *
342
-     * @return array numerically indexed, with each part of the address that is known.
343
-     * Eg, if the user only responded to state and country,
344
-     * it would be array(0=>'Alabama',1=>'USA')
345
-     * @return array
346
-     * @throws EE_Error
347
-     */
348
-    public function full_address_as_array()
349
-    {
350
-        $full_address_array = array();
351
-        $initial_address_fields = array('ATT_address', 'ATT_address2', 'ATT_city',);
352
-        foreach ($initial_address_fields as $address_field_name) {
353
-            $address_fields_value = $this->get($address_field_name);
354
-            if (! empty($address_fields_value)) {
355
-                $full_address_array[] = $address_fields_value;
356
-            }
357
-        }
358
-        // now handle state and country
359
-        $state_obj = $this->state_obj();
360
-        if ($state_obj instanceof EE_State) {
361
-            $full_address_array[] = $state_obj->name();
362
-        }
363
-        $country_obj = $this->country_obj();
364
-        if ($country_obj instanceof EE_Country) {
365
-            $full_address_array[] = $country_obj->name();
366
-        }
367
-        // lastly get the xip
368
-        $zip_value = $this->zip();
369
-        if (! empty($zip_value)) {
370
-            $full_address_array[] = $zip_value;
371
-        }
372
-        return $full_address_array;
373
-    }
374
-
375
-
376
-    /**
377
-     *        get Attendee Address
378
-     *
379
-     * @return string
380
-     * @throws EE_Error
381
-     */
382
-    public function address()
383
-    {
384
-        return $this->get('ATT_address');
385
-    }
386
-
387
-
388
-    /**
389
-     *        get Attendee Address2
390
-     *
391
-     * @return string
392
-     * @throws EE_Error
393
-     */
394
-    public function address2()
395
-    {
396
-        return $this->get('ATT_address2');
397
-    }
398
-
399
-
400
-    /**
401
-     *        get Attendee City
402
-     *
403
-     * @return string
404
-     * @throws EE_Error
405
-     */
406
-    public function city()
407
-    {
408
-        return $this->get('ATT_city');
409
-    }
410
-
411
-
412
-    /**
413
-     *        get Attendee State ID
414
-     *
415
-     * @return string
416
-     * @throws EE_Error
417
-     */
418
-    public function state_ID()
419
-    {
420
-        return $this->get('STA_ID');
421
-    }
422
-
423
-
424
-    /**
425
-     * @return string
426
-     * @throws EE_Error
427
-     */
428
-    public function state_abbrev()
429
-    {
430
-        return $this->state_obj() instanceof EE_State ? $this->state_obj()->abbrev() : '';
431
-    }
432
-
433
-
434
-    /**
435
-     * Gets the state set to this attendee
436
-     *
437
-     * @return EE_State
438
-     * @throws EE_Error
439
-     */
440
-    public function state_obj()
441
-    {
442
-        return $this->get_first_related('State');
443
-    }
444
-
445
-
446
-    /**
447
-     * Returns the state's name, otherwise 'Unknown'
448
-     *
449
-     * @return string
450
-     * @throws EE_Error
451
-     */
452
-    public function state_name()
453
-    {
454
-        if ($this->state_obj()) {
455
-            return $this->state_obj()->name();
456
-        } else {
457
-            return '';
458
-        }
459
-    }
460
-
461
-
462
-    /**
463
-     * either displays the state abbreviation or the state name, as determined
464
-     * by the "FHEE__EEI_Address__state__use_abbreviation" filter.
465
-     * defaults to abbreviation
466
-     *
467
-     * @return string
468
-     * @throws EE_Error
469
-     */
470
-    public function state()
471
-    {
472
-        if (apply_filters('FHEE__EEI_Address__state__use_abbreviation', true, $this->state_obj())) {
473
-            return $this->state_abbrev();
474
-        }
475
-        return $this->state_name();
476
-    }
477
-
478
-
479
-    /**
480
-     *    get Attendee Country ISO Code
481
-     *
482
-     * @return string
483
-     * @throws EE_Error
484
-     */
485
-    public function country_ID()
486
-    {
487
-        return $this->get('CNT_ISO');
488
-    }
489
-
490
-
491
-    /**
492
-     * Gets country set for this attendee
493
-     *
494
-     * @return EE_Country
495
-     * @throws EE_Error
496
-     */
497
-    public function country_obj()
498
-    {
499
-        return $this->get_first_related('Country');
500
-    }
501
-
502
-
503
-    /**
504
-     * Returns the country's name if known, otherwise 'Unknown'
505
-     *
506
-     * @return string
507
-     * @throws EE_Error
508
-     */
509
-    public function country_name()
510
-    {
511
-        if ($this->country_obj()) {
512
-            return $this->country_obj()->name();
513
-        }
514
-        return '';
515
-    }
516
-
517
-
518
-    /**
519
-     * either displays the country ISO2 code or the country name, as determined
520
-     * by the "FHEE__EEI_Address__country__use_abbreviation" filter.
521
-     * defaults to abbreviation
522
-     *
523
-     * @return string
524
-     * @throws EE_Error
525
-     */
526
-    public function country()
527
-    {
528
-        if (apply_filters('FHEE__EEI_Address__country__use_abbreviation', true, $this->country_obj())) {
529
-            return $this->country_ID();
530
-        }
531
-        return $this->country_name();
532
-    }
533
-
534
-
535
-    /**
536
-     *        get Attendee Zip/Postal Code
537
-     *
538
-     * @return string
539
-     * @throws EE_Error
540
-     */
541
-    public function zip()
542
-    {
543
-        return $this->get('ATT_zip');
544
-    }
545
-
546
-
547
-    /**
548
-     *        get Attendee Email Address
549
-     *
550
-     * @return string
551
-     * @throws EE_Error
552
-     */
553
-    public function email()
554
-    {
555
-        return $this->get('ATT_email');
556
-    }
557
-
558
-
559
-    /**
560
-     *        get Attendee Phone #
561
-     *
562
-     * @return string
563
-     * @throws EE_Error
564
-     */
565
-    public function phone()
566
-    {
567
-        return $this->get('ATT_phone');
568
-    }
569
-
570
-
571
-    /**
572
-     *    get deleted
573
-     *
574
-     * @return        bool
575
-     * @throws EE_Error
576
-     */
577
-    public function deleted()
578
-    {
579
-        return $this->get('ATT_deleted');
580
-    }
581
-
582
-
583
-    /**
584
-     * Gets registrations of this attendee
585
-     *
586
-     * @param array $query_params
587
-     * @return EE_Registration[]
588
-     * @throws EE_Error
589
-     */
590
-    public function get_registrations($query_params = array())
591
-    {
592
-        return $this->get_many_related('Registration', $query_params);
593
-    }
594
-
595
-
596
-    /**
597
-     * Gets the most recent registration of this attendee
598
-     *
599
-     * @return EE_Registration
600
-     * @throws EE_Error
601
-     */
602
-    public function get_most_recent_registration()
603
-    {
604
-        return $this->get_first_related(
605
-            'Registration',
606
-            array('order_by' => array('REG_date' => 'DESC'))
607
-        ); // null, 'REG_date', 'DESC', '=', 'OBJECT_K');
608
-    }
609
-
610
-
611
-    /**
612
-     * Gets the most recent registration for this attend at this event
613
-     *
614
-     * @param int $event_id
615
-     * @return EE_Registration
616
-     * @throws EE_Error
617
-     */
618
-    public function get_most_recent_registration_for_event($event_id)
619
-    {
620
-        return $this->get_first_related(
621
-            'Registration',
622
-            array(array('EVT_ID' => $event_id), 'order_by' => array('REG_date' => 'DESC'))
623
-        );
624
-    }
625
-
626
-
627
-    /**
628
-     * returns any events attached to this attendee ($_Event property);
629
-     *
630
-     * @return array
631
-     * @throws EE_Error
632
-     */
633
-    public function events()
634
-    {
635
-        return $this->get_many_related('Event');
636
-    }
637
-
638
-
639
-    /**
640
-     * Gets the billing info array where keys match espresso_reg_page_billing_inputs(),
641
-     * and keys are their cleaned values. @see EE_Attendee::save_and_clean_billing_info_for_payment_method() which was
642
-     * used to save the billing info
643
-     *
644
-     * @param EE_Payment_Method $payment_method the _gateway_name property on the gateway class
645
-     * @return EE_Form_Section_Proper|null
646
-     * @throws EE_Error
647
-     */
648
-    public function billing_info_for_payment_method($payment_method)
649
-    {
650
-        $pm_type = $payment_method->type_obj();
651
-        if (! $pm_type instanceof EE_PMT_Base) {
652
-            return null;
653
-        }
654
-        $billing_info = $this->get_post_meta($this->get_billing_info_postmeta_name($payment_method), true);
655
-        if (! $billing_info) {
656
-            return null;
657
-        }
658
-        $billing_form = $pm_type->billing_form();
659
-        // double-check the form isn't totally hidden, in which case pretend there is no form
660
-        $form_totally_hidden = true;
661
-        foreach ($billing_form->inputs_in_subsections() as $input) {
662
-            if (! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) {
663
-                $form_totally_hidden = false;
664
-                break;
665
-            }
666
-        }
667
-        if ($form_totally_hidden) {
668
-            return null;
669
-        }
670
-        if ($billing_form instanceof EE_Form_Section_Proper) {
671
-            $billing_form->receive_form_submission(array($billing_form->name() => $billing_info), false);
672
-        }
673
-
674
-        return $billing_form;
675
-    }
676
-
677
-
678
-    /**
679
-     * Gets the postmeta key that holds this attendee's billing info for the
680
-     * specified payment method
681
-     *
682
-     * @param EE_Payment_Method $payment_method
683
-     * @return string
684
-     * @throws EE_Error
685
-     */
686
-    public function get_billing_info_postmeta_name($payment_method)
687
-    {
688
-        if ($payment_method->type_obj() instanceof EE_PMT_Base) {
689
-            return 'billing_info_' . $payment_method->type_obj()->system_name();
690
-        }
691
-        return null;
692
-    }
693
-
694
-
695
-    /**
696
-     * Saves the billing info to the attendee. @see EE_Attendee::billing_info_for_payment_method() which is used to
697
-     * retrieve it
698
-     *
699
-     * @param EE_Billing_Attendee_Info_Form $billing_form
700
-     * @param EE_Payment_Method             $payment_method
701
-     * @return boolean
702
-     * @throws EE_Error
703
-     */
704
-    public function save_and_clean_billing_info_for_payment_method($billing_form, $payment_method)
705
-    {
706
-        if (! $billing_form instanceof EE_Billing_Attendee_Info_Form) {
707
-            EE_Error::add_error(__('Cannot save billing info because there is none.', 'event_espresso'));
708
-            return false;
709
-        }
710
-        $billing_form->clean_sensitive_data();
711
-        return update_post_meta(
712
-            $this->ID(),
713
-            $this->get_billing_info_postmeta_name($payment_method),
714
-            $billing_form->input_values(true)
715
-        );
716
-    }
717
-
718
-
719
-    /**
720
-     * Return the link to the admin details for the object.
721
-     *
722
-     * @return string
723
-     * @throws EE_Error
724
-     * @throws InvalidArgumentException
725
-     * @throws InvalidDataTypeException
726
-     * @throws InvalidInterfaceException
727
-     * @throws ReflectionException
728
-     */
729
-    public function get_admin_details_link()
730
-    {
731
-        return $this->get_admin_edit_link();
732
-    }
733
-
734
-
735
-    /**
736
-     * Returns the link to the editor for the object.  Sometimes this is the same as the details.
737
-     *
738
-     * @return string
739
-     * @throws EE_Error
740
-     * @throws InvalidArgumentException
741
-     * @throws ReflectionException
742
-     * @throws InvalidDataTypeException
743
-     * @throws InvalidInterfaceException
744
-     */
745
-    public function get_admin_edit_link()
746
-    {
747
-        EE_Registry::instance()->load_helper('URL');
748
-        return EEH_URL::add_query_args_and_nonce(
749
-            array(
750
-                'page'   => 'espresso_registrations',
751
-                'action' => 'edit_attendee',
752
-                'post'   => $this->ID(),
753
-            ),
754
-            admin_url('admin.php')
755
-        );
756
-    }
757
-
758
-
759
-    /**
760
-     * Returns the link to a settings page for the object.
761
-     *
762
-     * @return string
763
-     * @throws EE_Error
764
-     * @throws InvalidArgumentException
765
-     * @throws InvalidDataTypeException
766
-     * @throws InvalidInterfaceException
767
-     * @throws ReflectionException
768
-     */
769
-    public function get_admin_settings_link()
770
-    {
771
-        return $this->get_admin_edit_link();
772
-    }
773
-
774
-
775
-    /**
776
-     * Returns the link to the "overview" for the object (typically the "list table" view).
777
-     *
778
-     * @return string
779
-     * @throws EE_Error
780
-     * @throws InvalidArgumentException
781
-     * @throws ReflectionException
782
-     * @throws InvalidDataTypeException
783
-     * @throws InvalidInterfaceException
784
-     */
785
-    public function get_admin_overview_link()
786
-    {
787
-        EE_Registry::instance()->load_helper('URL');
788
-        return EEH_URL::add_query_args_and_nonce(
789
-            array(
790
-                'page'   => 'espresso_registrations',
791
-                'action' => 'contact_list',
792
-            ),
793
-            admin_url('admin.php')
794
-        );
795
-    }
28
+	/**
29
+	 * Sets some dynamic defaults
30
+	 *
31
+	 * @param array  $fieldValues
32
+	 * @param bool   $bydb
33
+	 * @param string $timezone
34
+	 * @param array  $date_formats
35
+	 * @throws EE_Error
36
+	 */
37
+	protected function __construct($fieldValues = null, $bydb = false, $timezone = null, $date_formats = array())
38
+	{
39
+		if (! isset($fieldValues['ATT_full_name'])) {
40
+			$fname = isset($fieldValues['ATT_fname']) ? $fieldValues['ATT_fname'] . ' ' : '';
41
+			$lname = isset($fieldValues['ATT_lname']) ? $fieldValues['ATT_lname'] : '';
42
+			$fieldValues['ATT_full_name'] = $fname . $lname;
43
+		}
44
+		if (! isset($fieldValues['ATT_slug'])) {
45
+			// $fieldValues['ATT_slug'] = sanitize_key(wp_generate_password(20));
46
+			$fieldValues['ATT_slug'] = sanitize_title($fieldValues['ATT_full_name']);
47
+		}
48
+		if (! isset($fieldValues['ATT_short_bio']) && isset($fieldValues['ATT_bio'])) {
49
+			$fieldValues['ATT_short_bio'] = substr($fieldValues['ATT_bio'], 0, 50);
50
+		}
51
+		parent::__construct($fieldValues, $bydb, $timezone, $date_formats);
52
+	}
53
+
54
+
55
+	/**
56
+	 * @param array  $props_n_values          incoming values
57
+	 * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
58
+	 *                                        used.)
59
+	 * @param array  $date_formats            incoming date_formats in an array where the first value is the
60
+	 *                                        date_format and the second value is the time format
61
+	 * @return EE_Attendee
62
+	 * @throws EE_Error
63
+	 */
64
+	public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
65
+	{
66
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
67
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
68
+	}
69
+
70
+
71
+	/**
72
+	 * @param array  $props_n_values  incoming values from the database
73
+	 * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
74
+	 *                                the website will be used.
75
+	 * @return EE_Attendee
76
+	 */
77
+	public static function new_instance_from_db($props_n_values = array(), $timezone = null)
78
+	{
79
+		return new self($props_n_values, true, $timezone);
80
+	}
81
+
82
+
83
+	/**
84
+	 *        Set Attendee First Name
85
+	 *
86
+	 * @access        public
87
+	 * @param string $fname
88
+	 * @throws EE_Error
89
+	 */
90
+	public function set_fname($fname = '')
91
+	{
92
+		$this->set('ATT_fname', $fname);
93
+	}
94
+
95
+
96
+	/**
97
+	 *        Set Attendee Last Name
98
+	 *
99
+	 * @access        public
100
+	 * @param string $lname
101
+	 * @throws EE_Error
102
+	 */
103
+	public function set_lname($lname = '')
104
+	{
105
+		$this->set('ATT_lname', $lname);
106
+	}
107
+
108
+
109
+	/**
110
+	 *        Set Attendee Address
111
+	 *
112
+	 * @access        public
113
+	 * @param string $address
114
+	 * @throws EE_Error
115
+	 */
116
+	public function set_address($address = '')
117
+	{
118
+		$this->set('ATT_address', $address);
119
+	}
120
+
121
+
122
+	/**
123
+	 *        Set Attendee Address2
124
+	 *
125
+	 * @access        public
126
+	 * @param        string $address2
127
+	 * @throws EE_Error
128
+	 */
129
+	public function set_address2($address2 = '')
130
+	{
131
+		$this->set('ATT_address2', $address2);
132
+	}
133
+
134
+
135
+	/**
136
+	 *        Set Attendee City
137
+	 *
138
+	 * @access        public
139
+	 * @param        string $city
140
+	 * @throws EE_Error
141
+	 */
142
+	public function set_city($city = '')
143
+	{
144
+		$this->set('ATT_city', $city);
145
+	}
146
+
147
+
148
+	/**
149
+	 *        Set Attendee State ID
150
+	 *
151
+	 * @access        public
152
+	 * @param        int $STA_ID
153
+	 * @throws EE_Error
154
+	 */
155
+	public function set_state($STA_ID = 0)
156
+	{
157
+		$this->set('STA_ID', $STA_ID);
158
+	}
159
+
160
+
161
+	/**
162
+	 *        Set Attendee Country ISO Code
163
+	 *
164
+	 * @access        public
165
+	 * @param        string $CNT_ISO
166
+	 * @throws EE_Error
167
+	 */
168
+	public function set_country($CNT_ISO = '')
169
+	{
170
+		$this->set('CNT_ISO', $CNT_ISO);
171
+	}
172
+
173
+
174
+	/**
175
+	 *        Set Attendee Zip/Postal Code
176
+	 *
177
+	 * @access        public
178
+	 * @param        string $zip
179
+	 * @throws EE_Error
180
+	 */
181
+	public function set_zip($zip = '')
182
+	{
183
+		$this->set('ATT_zip', $zip);
184
+	}
185
+
186
+
187
+	/**
188
+	 *        Set Attendee Email Address
189
+	 *
190
+	 * @access        public
191
+	 * @param        string $email
192
+	 * @throws EE_Error
193
+	 */
194
+	public function set_email($email = '')
195
+	{
196
+		$this->set('ATT_email', $email);
197
+	}
198
+
199
+
200
+	/**
201
+	 *        Set Attendee Phone
202
+	 *
203
+	 * @access        public
204
+	 * @param        string $phone
205
+	 * @throws EE_Error
206
+	 */
207
+	public function set_phone($phone = '')
208
+	{
209
+		$this->set('ATT_phone', $phone);
210
+	}
211
+
212
+
213
+	/**
214
+	 *        set deleted
215
+	 *
216
+	 * @access        public
217
+	 * @param        bool $ATT_deleted
218
+	 * @throws EE_Error
219
+	 */
220
+	public function set_deleted($ATT_deleted = false)
221
+	{
222
+		$this->set('ATT_deleted', $ATT_deleted);
223
+	}
224
+
225
+
226
+	/**
227
+	 * Returns the value for the post_author id saved with the cpt
228
+	 *
229
+	 * @since 4.5.0
230
+	 * @return int
231
+	 * @throws EE_Error
232
+	 */
233
+	public function wp_user()
234
+	{
235
+		return $this->get('ATT_author');
236
+	}
237
+
238
+
239
+	/**
240
+	 *        get Attendee First Name
241
+	 *
242
+	 * @access        public
243
+	 * @return string
244
+	 * @throws EE_Error
245
+	 */
246
+	public function fname()
247
+	{
248
+		return $this->get('ATT_fname');
249
+	}
250
+
251
+
252
+	/**
253
+	 * echoes out the attendee's first name
254
+	 *
255
+	 * @return void
256
+	 * @throws EE_Error
257
+	 */
258
+	public function e_full_name()
259
+	{
260
+		echo $this->full_name();
261
+	}
262
+
263
+
264
+	/**
265
+	 * Returns the first and last name concatenated together with a space.
266
+	 *
267
+	 * @param bool $apply_html_entities
268
+	 * @return string
269
+	 * @throws EE_Error
270
+	 */
271
+	public function full_name($apply_html_entities = false)
272
+	{
273
+		$full_name = array(
274
+			$this->fname(),
275
+			$this->lname(),
276
+		);
277
+		$full_name = array_filter($full_name);
278
+		$full_name = implode(' ', $full_name);
279
+		return $apply_html_entities ? htmlentities($full_name, ENT_QUOTES, 'UTF-8') : $full_name;
280
+	}
281
+
282
+
283
+	/**
284
+	 * This returns the value of the `ATT_full_name` field which is usually equivalent to calling `full_name()` unless
285
+	 * the post_title field has been directly modified in the db for the post (espresso_attendees post type) for this
286
+	 * attendee.
287
+	 *
288
+	 * @param bool $apply_html_entities
289
+	 * @return string
290
+	 * @throws EE_Error
291
+	 */
292
+	public function ATT_full_name($apply_html_entities = false)
293
+	{
294
+		return $apply_html_entities
295
+			? htmlentities($this->get('ATT_full_name'), ENT_QUOTES, 'UTF-8')
296
+			: $this->get('ATT_full_name');
297
+	}
298
+
299
+
300
+	/**
301
+	 *        get Attendee Last Name
302
+	 *
303
+	 * @access        public
304
+	 * @return string
305
+	 * @throws EE_Error
306
+	 */
307
+	public function lname()
308
+	{
309
+		return $this->get('ATT_lname');
310
+	}
311
+
312
+
313
+	/**
314
+	 * get Attendee bio
315
+	 *
316
+	 * @access public
317
+	 * @return string
318
+	 * @throws EE_Error
319
+	 */
320
+	public function bio()
321
+	{
322
+		return $this->get('ATT_bio');
323
+	}
324
+
325
+
326
+	/**
327
+	 * get Attendee short bio
328
+	 *
329
+	 * @access public
330
+	 * @return string
331
+	 * @throws EE_Error
332
+	 */
333
+	public function short_bio()
334
+	{
335
+		return $this->get('ATT_short_bio');
336
+	}
337
+
338
+
339
+	/**
340
+	 * Gets the attendee's full address as an array so client code can decide hwo to display it
341
+	 *
342
+	 * @return array numerically indexed, with each part of the address that is known.
343
+	 * Eg, if the user only responded to state and country,
344
+	 * it would be array(0=>'Alabama',1=>'USA')
345
+	 * @return array
346
+	 * @throws EE_Error
347
+	 */
348
+	public function full_address_as_array()
349
+	{
350
+		$full_address_array = array();
351
+		$initial_address_fields = array('ATT_address', 'ATT_address2', 'ATT_city',);
352
+		foreach ($initial_address_fields as $address_field_name) {
353
+			$address_fields_value = $this->get($address_field_name);
354
+			if (! empty($address_fields_value)) {
355
+				$full_address_array[] = $address_fields_value;
356
+			}
357
+		}
358
+		// now handle state and country
359
+		$state_obj = $this->state_obj();
360
+		if ($state_obj instanceof EE_State) {
361
+			$full_address_array[] = $state_obj->name();
362
+		}
363
+		$country_obj = $this->country_obj();
364
+		if ($country_obj instanceof EE_Country) {
365
+			$full_address_array[] = $country_obj->name();
366
+		}
367
+		// lastly get the xip
368
+		$zip_value = $this->zip();
369
+		if (! empty($zip_value)) {
370
+			$full_address_array[] = $zip_value;
371
+		}
372
+		return $full_address_array;
373
+	}
374
+
375
+
376
+	/**
377
+	 *        get Attendee Address
378
+	 *
379
+	 * @return string
380
+	 * @throws EE_Error
381
+	 */
382
+	public function address()
383
+	{
384
+		return $this->get('ATT_address');
385
+	}
386
+
387
+
388
+	/**
389
+	 *        get Attendee Address2
390
+	 *
391
+	 * @return string
392
+	 * @throws EE_Error
393
+	 */
394
+	public function address2()
395
+	{
396
+		return $this->get('ATT_address2');
397
+	}
398
+
399
+
400
+	/**
401
+	 *        get Attendee City
402
+	 *
403
+	 * @return string
404
+	 * @throws EE_Error
405
+	 */
406
+	public function city()
407
+	{
408
+		return $this->get('ATT_city');
409
+	}
410
+
411
+
412
+	/**
413
+	 *        get Attendee State ID
414
+	 *
415
+	 * @return string
416
+	 * @throws EE_Error
417
+	 */
418
+	public function state_ID()
419
+	{
420
+		return $this->get('STA_ID');
421
+	}
422
+
423
+
424
+	/**
425
+	 * @return string
426
+	 * @throws EE_Error
427
+	 */
428
+	public function state_abbrev()
429
+	{
430
+		return $this->state_obj() instanceof EE_State ? $this->state_obj()->abbrev() : '';
431
+	}
432
+
433
+
434
+	/**
435
+	 * Gets the state set to this attendee
436
+	 *
437
+	 * @return EE_State
438
+	 * @throws EE_Error
439
+	 */
440
+	public function state_obj()
441
+	{
442
+		return $this->get_first_related('State');
443
+	}
444
+
445
+
446
+	/**
447
+	 * Returns the state's name, otherwise 'Unknown'
448
+	 *
449
+	 * @return string
450
+	 * @throws EE_Error
451
+	 */
452
+	public function state_name()
453
+	{
454
+		if ($this->state_obj()) {
455
+			return $this->state_obj()->name();
456
+		} else {
457
+			return '';
458
+		}
459
+	}
460
+
461
+
462
+	/**
463
+	 * either displays the state abbreviation or the state name, as determined
464
+	 * by the "FHEE__EEI_Address__state__use_abbreviation" filter.
465
+	 * defaults to abbreviation
466
+	 *
467
+	 * @return string
468
+	 * @throws EE_Error
469
+	 */
470
+	public function state()
471
+	{
472
+		if (apply_filters('FHEE__EEI_Address__state__use_abbreviation', true, $this->state_obj())) {
473
+			return $this->state_abbrev();
474
+		}
475
+		return $this->state_name();
476
+	}
477
+
478
+
479
+	/**
480
+	 *    get Attendee Country ISO Code
481
+	 *
482
+	 * @return string
483
+	 * @throws EE_Error
484
+	 */
485
+	public function country_ID()
486
+	{
487
+		return $this->get('CNT_ISO');
488
+	}
489
+
490
+
491
+	/**
492
+	 * Gets country set for this attendee
493
+	 *
494
+	 * @return EE_Country
495
+	 * @throws EE_Error
496
+	 */
497
+	public function country_obj()
498
+	{
499
+		return $this->get_first_related('Country');
500
+	}
501
+
502
+
503
+	/**
504
+	 * Returns the country's name if known, otherwise 'Unknown'
505
+	 *
506
+	 * @return string
507
+	 * @throws EE_Error
508
+	 */
509
+	public function country_name()
510
+	{
511
+		if ($this->country_obj()) {
512
+			return $this->country_obj()->name();
513
+		}
514
+		return '';
515
+	}
516
+
517
+
518
+	/**
519
+	 * either displays the country ISO2 code or the country name, as determined
520
+	 * by the "FHEE__EEI_Address__country__use_abbreviation" filter.
521
+	 * defaults to abbreviation
522
+	 *
523
+	 * @return string
524
+	 * @throws EE_Error
525
+	 */
526
+	public function country()
527
+	{
528
+		if (apply_filters('FHEE__EEI_Address__country__use_abbreviation', true, $this->country_obj())) {
529
+			return $this->country_ID();
530
+		}
531
+		return $this->country_name();
532
+	}
533
+
534
+
535
+	/**
536
+	 *        get Attendee Zip/Postal Code
537
+	 *
538
+	 * @return string
539
+	 * @throws EE_Error
540
+	 */
541
+	public function zip()
542
+	{
543
+		return $this->get('ATT_zip');
544
+	}
545
+
546
+
547
+	/**
548
+	 *        get Attendee Email Address
549
+	 *
550
+	 * @return string
551
+	 * @throws EE_Error
552
+	 */
553
+	public function email()
554
+	{
555
+		return $this->get('ATT_email');
556
+	}
557
+
558
+
559
+	/**
560
+	 *        get Attendee Phone #
561
+	 *
562
+	 * @return string
563
+	 * @throws EE_Error
564
+	 */
565
+	public function phone()
566
+	{
567
+		return $this->get('ATT_phone');
568
+	}
569
+
570
+
571
+	/**
572
+	 *    get deleted
573
+	 *
574
+	 * @return        bool
575
+	 * @throws EE_Error
576
+	 */
577
+	public function deleted()
578
+	{
579
+		return $this->get('ATT_deleted');
580
+	}
581
+
582
+
583
+	/**
584
+	 * Gets registrations of this attendee
585
+	 *
586
+	 * @param array $query_params
587
+	 * @return EE_Registration[]
588
+	 * @throws EE_Error
589
+	 */
590
+	public function get_registrations($query_params = array())
591
+	{
592
+		return $this->get_many_related('Registration', $query_params);
593
+	}
594
+
595
+
596
+	/**
597
+	 * Gets the most recent registration of this attendee
598
+	 *
599
+	 * @return EE_Registration
600
+	 * @throws EE_Error
601
+	 */
602
+	public function get_most_recent_registration()
603
+	{
604
+		return $this->get_first_related(
605
+			'Registration',
606
+			array('order_by' => array('REG_date' => 'DESC'))
607
+		); // null, 'REG_date', 'DESC', '=', 'OBJECT_K');
608
+	}
609
+
610
+
611
+	/**
612
+	 * Gets the most recent registration for this attend at this event
613
+	 *
614
+	 * @param int $event_id
615
+	 * @return EE_Registration
616
+	 * @throws EE_Error
617
+	 */
618
+	public function get_most_recent_registration_for_event($event_id)
619
+	{
620
+		return $this->get_first_related(
621
+			'Registration',
622
+			array(array('EVT_ID' => $event_id), 'order_by' => array('REG_date' => 'DESC'))
623
+		);
624
+	}
625
+
626
+
627
+	/**
628
+	 * returns any events attached to this attendee ($_Event property);
629
+	 *
630
+	 * @return array
631
+	 * @throws EE_Error
632
+	 */
633
+	public function events()
634
+	{
635
+		return $this->get_many_related('Event');
636
+	}
637
+
638
+
639
+	/**
640
+	 * Gets the billing info array where keys match espresso_reg_page_billing_inputs(),
641
+	 * and keys are their cleaned values. @see EE_Attendee::save_and_clean_billing_info_for_payment_method() which was
642
+	 * used to save the billing info
643
+	 *
644
+	 * @param EE_Payment_Method $payment_method the _gateway_name property on the gateway class
645
+	 * @return EE_Form_Section_Proper|null
646
+	 * @throws EE_Error
647
+	 */
648
+	public function billing_info_for_payment_method($payment_method)
649
+	{
650
+		$pm_type = $payment_method->type_obj();
651
+		if (! $pm_type instanceof EE_PMT_Base) {
652
+			return null;
653
+		}
654
+		$billing_info = $this->get_post_meta($this->get_billing_info_postmeta_name($payment_method), true);
655
+		if (! $billing_info) {
656
+			return null;
657
+		}
658
+		$billing_form = $pm_type->billing_form();
659
+		// double-check the form isn't totally hidden, in which case pretend there is no form
660
+		$form_totally_hidden = true;
661
+		foreach ($billing_form->inputs_in_subsections() as $input) {
662
+			if (! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) {
663
+				$form_totally_hidden = false;
664
+				break;
665
+			}
666
+		}
667
+		if ($form_totally_hidden) {
668
+			return null;
669
+		}
670
+		if ($billing_form instanceof EE_Form_Section_Proper) {
671
+			$billing_form->receive_form_submission(array($billing_form->name() => $billing_info), false);
672
+		}
673
+
674
+		return $billing_form;
675
+	}
676
+
677
+
678
+	/**
679
+	 * Gets the postmeta key that holds this attendee's billing info for the
680
+	 * specified payment method
681
+	 *
682
+	 * @param EE_Payment_Method $payment_method
683
+	 * @return string
684
+	 * @throws EE_Error
685
+	 */
686
+	public function get_billing_info_postmeta_name($payment_method)
687
+	{
688
+		if ($payment_method->type_obj() instanceof EE_PMT_Base) {
689
+			return 'billing_info_' . $payment_method->type_obj()->system_name();
690
+		}
691
+		return null;
692
+	}
693
+
694
+
695
+	/**
696
+	 * Saves the billing info to the attendee. @see EE_Attendee::billing_info_for_payment_method() which is used to
697
+	 * retrieve it
698
+	 *
699
+	 * @param EE_Billing_Attendee_Info_Form $billing_form
700
+	 * @param EE_Payment_Method             $payment_method
701
+	 * @return boolean
702
+	 * @throws EE_Error
703
+	 */
704
+	public function save_and_clean_billing_info_for_payment_method($billing_form, $payment_method)
705
+	{
706
+		if (! $billing_form instanceof EE_Billing_Attendee_Info_Form) {
707
+			EE_Error::add_error(__('Cannot save billing info because there is none.', 'event_espresso'));
708
+			return false;
709
+		}
710
+		$billing_form->clean_sensitive_data();
711
+		return update_post_meta(
712
+			$this->ID(),
713
+			$this->get_billing_info_postmeta_name($payment_method),
714
+			$billing_form->input_values(true)
715
+		);
716
+	}
717
+
718
+
719
+	/**
720
+	 * Return the link to the admin details for the object.
721
+	 *
722
+	 * @return string
723
+	 * @throws EE_Error
724
+	 * @throws InvalidArgumentException
725
+	 * @throws InvalidDataTypeException
726
+	 * @throws InvalidInterfaceException
727
+	 * @throws ReflectionException
728
+	 */
729
+	public function get_admin_details_link()
730
+	{
731
+		return $this->get_admin_edit_link();
732
+	}
733
+
734
+
735
+	/**
736
+	 * Returns the link to the editor for the object.  Sometimes this is the same as the details.
737
+	 *
738
+	 * @return string
739
+	 * @throws EE_Error
740
+	 * @throws InvalidArgumentException
741
+	 * @throws ReflectionException
742
+	 * @throws InvalidDataTypeException
743
+	 * @throws InvalidInterfaceException
744
+	 */
745
+	public function get_admin_edit_link()
746
+	{
747
+		EE_Registry::instance()->load_helper('URL');
748
+		return EEH_URL::add_query_args_and_nonce(
749
+			array(
750
+				'page'   => 'espresso_registrations',
751
+				'action' => 'edit_attendee',
752
+				'post'   => $this->ID(),
753
+			),
754
+			admin_url('admin.php')
755
+		);
756
+	}
757
+
758
+
759
+	/**
760
+	 * Returns the link to a settings page for the object.
761
+	 *
762
+	 * @return string
763
+	 * @throws EE_Error
764
+	 * @throws InvalidArgumentException
765
+	 * @throws InvalidDataTypeException
766
+	 * @throws InvalidInterfaceException
767
+	 * @throws ReflectionException
768
+	 */
769
+	public function get_admin_settings_link()
770
+	{
771
+		return $this->get_admin_edit_link();
772
+	}
773
+
774
+
775
+	/**
776
+	 * Returns the link to the "overview" for the object (typically the "list table" view).
777
+	 *
778
+	 * @return string
779
+	 * @throws EE_Error
780
+	 * @throws InvalidArgumentException
781
+	 * @throws ReflectionException
782
+	 * @throws InvalidDataTypeException
783
+	 * @throws InvalidInterfaceException
784
+	 */
785
+	public function get_admin_overview_link()
786
+	{
787
+		EE_Registry::instance()->load_helper('URL');
788
+		return EEH_URL::add_query_args_and_nonce(
789
+			array(
790
+				'page'   => 'espresso_registrations',
791
+				'action' => 'contact_list',
792
+			),
793
+			admin_url('admin.php')
794
+		);
795
+	}
796 796
 }
Please login to merge, or discard this patch.
core/db_classes/EE_WP_User.class.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@
 block discarded – undo
51 51
      */
52 52
     public function wp_user_obj()
53 53
     {
54
-        if (! $this->_wp_user_obj) {
54
+        if ( ! $this->_wp_user_obj) {
55 55
             $this->_wp_user_obj = get_user_by('ID', $this->ID());
56 56
         }
57 57
         return $this->_wp_user_obj;
Please login to merge, or discard this patch.
Indentation   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -11,91 +11,91 @@
 block discarded – undo
11 11
 class EE_WP_User extends EE_Base_Class implements EEI_Admin_Links
12 12
 {
13 13
 
14
-    /**
15
-     * @var WP_User
16
-     */
17
-    protected $_wp_user_obj;
14
+	/**
15
+	 * @var WP_User
16
+	 */
17
+	protected $_wp_user_obj;
18 18
 
19
-    /**
20
-     * @param array $props_n_values
21
-     * @return EE_WP_User|mixed
22
-     */
23
-    public static function new_instance($props_n_values = array())
24
-    {
25
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__);
26
-        return $has_object ? $has_object : new self($props_n_values);
27
-    }
19
+	/**
20
+	 * @param array $props_n_values
21
+	 * @return EE_WP_User|mixed
22
+	 */
23
+	public static function new_instance($props_n_values = array())
24
+	{
25
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__);
26
+		return $has_object ? $has_object : new self($props_n_values);
27
+	}
28 28
 
29 29
 
30
-    /**
31
-     * @param array $props_n_values
32
-     * @return EE_WP_User
33
-     */
34
-    public static function new_instance_from_db($props_n_values = array())
35
-    {
36
-        return new self($props_n_values, true);
37
-    }
30
+	/**
31
+	 * @param array $props_n_values
32
+	 * @return EE_WP_User
33
+	 */
34
+	public static function new_instance_from_db($props_n_values = array())
35
+	{
36
+		return new self($props_n_values, true);
37
+	}
38 38
 
39
-    /**
40
-     * Return a normal WP_User object (caches the object for future calls)
41
-     *
42
-     * @return WP_User
43
-     */
44
-    public function wp_user_obj()
45
-    {
46
-        if (! $this->_wp_user_obj) {
47
-            $this->_wp_user_obj = get_user_by('ID', $this->ID());
48
-        }
49
-        return $this->_wp_user_obj;
50
-    }
39
+	/**
40
+	 * Return a normal WP_User object (caches the object for future calls)
41
+	 *
42
+	 * @return WP_User
43
+	 */
44
+	public function wp_user_obj()
45
+	{
46
+		if (! $this->_wp_user_obj) {
47
+			$this->_wp_user_obj = get_user_by('ID', $this->ID());
48
+		}
49
+		return $this->_wp_user_obj;
50
+	}
51 51
 
52
-    /**
53
-     * Return the link to the admin details for the object.
54
-     *
55
-     * @return string
56
-     */
57
-    public function get_admin_details_link()
58
-    {
59
-        return $this->get_admin_edit_link();
60
-    }
52
+	/**
53
+	 * Return the link to the admin details for the object.
54
+	 *
55
+	 * @return string
56
+	 */
57
+	public function get_admin_details_link()
58
+	{
59
+		return $this->get_admin_edit_link();
60
+	}
61 61
 
62
-    /**
63
-     * Returns the link to the editor for the object.  Sometimes this is the same as the details.
64
-     *
65
-     * @return string
66
-     */
67
-    public function get_admin_edit_link()
68
-    {
69
-        return esc_url(
70
-            add_query_arg(
71
-                'wp_http_referer',
72
-                urlencode(
73
-                    wp_unslash(
74
-                        $_SERVER['REQUEST_URI']
75
-                    )
76
-                ),
77
-                get_edit_user_link($this->ID())
78
-            )
79
-        );
80
-    }
62
+	/**
63
+	 * Returns the link to the editor for the object.  Sometimes this is the same as the details.
64
+	 *
65
+	 * @return string
66
+	 */
67
+	public function get_admin_edit_link()
68
+	{
69
+		return esc_url(
70
+			add_query_arg(
71
+				'wp_http_referer',
72
+				urlencode(
73
+					wp_unslash(
74
+						$_SERVER['REQUEST_URI']
75
+					)
76
+				),
77
+				get_edit_user_link($this->ID())
78
+			)
79
+		);
80
+	}
81 81
 
82
-    /**
83
-     * Returns the link to a settings page for the object.
84
-     *
85
-     * @return string
86
-     */
87
-    public function get_admin_settings_link()
88
-    {
89
-        return $this->get_admin_edit_link();
90
-    }
82
+	/**
83
+	 * Returns the link to a settings page for the object.
84
+	 *
85
+	 * @return string
86
+	 */
87
+	public function get_admin_settings_link()
88
+	{
89
+		return $this->get_admin_edit_link();
90
+	}
91 91
 
92
-    /**
93
-     * Returns the link to the "overview" for the object (typically the "list table" view).
94
-     *
95
-     * @return string
96
-     */
97
-    public function get_admin_overview_link()
98
-    {
99
-        return admin_url('users.php');
100
-    }
92
+	/**
93
+	 * Returns the link to the "overview" for the object (typically the "list table" view).
94
+	 *
95
+	 * @return string
96
+	 */
97
+	public function get_admin_overview_link()
98
+	{
99
+		return admin_url('users.php');
100
+	}
101 101
 }
Please login to merge, or discard this patch.