PluginProbe
Snippet Shortcodes / 4.2.2
Snippet Shortcodes v4.2.2
5.2.1 5.2 5.1.8 5.1.6 5.1.7 5.1.5 trunk 1.0 1.1 1.2 1.3 1.3.1 1.4 1.5 1.5.1 1.6 1.6.1 1.7 1.7.1 1.7.2 1.7.3 1.7.4 1.8 2.0 2.0.1 All 74 releases
shortcode-variables / includes / shortcode.presets.premium.php

shortcode.presets.premium.php in Snippet Shortcodes 4.2.2, at includes/shortcode.presets.premium.php

525 lines 20.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 defined('ABSPATH') or die("Jog on!");
4
5 /**
6 * Return a list of slugs / titles for free presets
7 * @return array
8 */
9 function sh_cd_shortcode_presets_premium_list() {
10
11 return [
12 'sc-db-value-by-id' => [ 'class' => 'SC_DB_VALUE_BY_ID', 'description' => __( 'Return a column value from a MySQL database for the given ID of search criteria e.g. <a href="https://snippet-shortcodes.yeken.uk/shortcodes/sc-db-value-by-id.html" rel="noopener" target="_blank">[sv slug="sc-db-value-by-id" table="users" column="user_login" column-to-search="id" key="3" key-format="%d"]</a>', SH_CD_SLUG ), 'premium' => true, 'args' => [ '_sh_cd_func' => 'by-id' ] ],
13 'sc-date' => [ 'class' => 'SC_DATE', 'description' => __( 'A shortcode that displays today\'s date with the ability to add or subtract days, months and years. To specify an interval to add or subtract onto the date use the parameter "interval" e.g. [sv slug="sc-date" interval="-1 year"], [sv slug="sc-date" interval="+5 days"], [sv slug="sc-date" interval="+3 months"]. Intervals are based upon PHP intervals and are outlined here <a href="https://www.php.net/manual/en/dateinterval.createfromdatestring.php" target="_blank">https://www.php.net/manual/en/dateinterval.createfromdatestring.php</a>. Default is UK format (DD/MM/YYYY). Format can be changed by adding the parameter format="m/d/Y" onto the shortcode. Format syntax is based upon PHP date: <a href="http://php.net/manual/en/function.date.php" target="_blank">http://php.net/manual/en/function.date.php</a>', SH_CD_SLUG ), 'premium' => true ],
14 'sc-site-language' => [ 'class' => 'SC_BLOG_INFO', 'description' => __( 'Language code for the current site', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'language' ], 'premium' => true ],
15 'sc-site-description' => [ 'class' => 'SC_BLOG_INFO', 'description' => __( 'Site tagline (set in Settings > General)', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'description' ], 'premium' => true ],
16 'sc-site-wp-url' => [ 'class' => 'SC_BLOG_INFO', 'description' => __( 'The WordPress address (URL) (set in Settings > General)', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'wpurl' ], 'premium' => true ],
17 'sc-site-charset' => [ 'class' => 'SC_BLOG_INFO', 'description' => __( 'The "Encoding for pages and feeds" (set in Settings > Reading)', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'charset' ], 'premium' => true ],
18 'sc-site-wp-version' => [ 'class' => 'SC_BLOG_INFO', 'description' => __( 'The current WordPress version', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'version' ], 'premium' => true ],
19 'sc-site-html-type' => [ 'class' => 'SC_BLOG_INFO', 'description' => __( 'The content-type (default: "text/html"). Themes and plugins', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'html_type' ], 'premium' => true ],
20 'sc-site-stylesheet-url' => [ 'class' => 'SC_BLOG_INFO', 'description' => __( 'URL to the stylesheet for the active theme.', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'stylesheet_url' ], 'premium' => true ],
21 'sc-site-stylesheet_directory' => [ 'class' => 'SC_BLOG_INFO', 'description' => __( 'Directory path for the active theme.', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'stylesheet_directory' ], 'premium' => true ],
22 'sc-site-current-url' => [ 'class' => 'SC_CURRENT_URL', 'description' => __( 'Get the current URL.', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'current_url' ], 'premium' => true],
23 'sc-site-register-url' => [ 'class' => 'SC_REGISTER_URL', 'description' => __( 'Get the URL to the WordPress registration page.', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'registration_url' ], 'premium' => true],
24 'sc-site-template-url' => [ 'class' => 'SC_BLOG_INFO', 'description' => __( 'The URL of the active theme\'s directory.', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'template_url' ], 'premium' => true],
25 'sc-site-pingback-url' => [ 'class' => 'SC_BLOG_INFO', 'description' => __( 'The pingback XML-RPC file URL (xmlrpc.php)', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'pingback_url' ], 'premium' => true ],
26 'sc-site-atom-feed' => [ 'class' => 'SC_BLOG_INFO', 'description' => __( 'The Atom feed URL (/feed/atom)', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'atom_url' ], 'premium' => true ],
27 'sc-site-rdf-url' => [ 'class' => 'SC_BLOG_INFO', 'description' => __( 'The RDF/RSS 1.0 feed URL (/feed/rfd)', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'rdf_url' ], 'premium' => true ],
28 'sc-site-rss-url' => [ 'class' => 'SC_BLOG_INFO', 'description' => __( 'The RSS 0.92 feed URL (/feed/rss)', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'rss_url' ], 'premium' => true ],
29 'sc-site-rss2-url' => [ 'class' => 'SC_BLOG_INFO', 'description' => __( 'The RSS 2.0 feed URL (/feed)', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'rss2_url' ], 'premium' => true ],
30 'sc-site-comments-atom-url' => [ 'class' => 'SC_BLOG_INFO', 'description' => __( 'The comments Atom feed URL (/comments/feed)', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'comments_atom_url' ], 'premium' => true ],
31 'sc-site-comments-rss2-url' => [ 'class' => 'SC_BLOG_INFO', 'description' => __( 'The comments RSS 2.0 feed URL (/comments/feed)', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'comments_rss2_url' ], 'premium' => true ],
32 'sc-php-server-info' => [ 'class' => 'SC_SERVER_INFO', 'description' => __( 'Display data from the PHP $_SERVER global e.g. [sv slug="sc-server-info" field="SERVER_SOFTWARE"]. <a href="http://php.net/manual/en/reserved.variables.server.php" rel="noopener" target="_blank">Allowed values for field attribute</a>.', SH_CD_SLUG ), 'premium' => true ],
33 'sc-php-unique-id' => [ 'class' => 'SC_UNIQUE_ID', 'description' => __( 'Generate a unique ID. Based upon <a href="http://php.net/manual/en/function.uniqid.php" rel="noopener" target="_blank">uniqid()</a>. If you wish the unique ID to be prefixed, add a the prefix attribute e.g. [sv slug="sc-php-unique-id" prefix="yeken"]', SH_CD_SLUG ), 'premium' => true ],
34 'sc-php-timestamp' => [ 'class' => 'SC_TIMESTAMP', 'description' => __( 'Display the current unix timestamp. Based upon <a href="http://php.net/manual/en/function.time.php" rel="noopener" target="_blank">time()</a>.', SH_CD_SLUG ), 'premium' => true ],
35 'sc-php-random-number' => [ 'class' => 'SC_RAND_NUMBER', 'description' => __( 'Display a random number. Based upon <a href="http://php.net/manual/en/function.rand.php" rel="noopener" target="_blank">rand()</a>. It also supports the optional arguments of min and max e.g. [sv slug="sc-php-random-number" min="5" max="20" ]', SH_CD_SLUG ), 'premium' => true ],
36 'sc-php-random-string' => [ 'class' => 'SC_RAND_STRING', 'description' => __( 'Display a random string of characters. It also supports the optional argument of "length". This specifies the number of characters you wish to display (default is 10) [sv slug="sc-php-random-string" length="15"]', SH_CD_SLUG ), 'premium' => true ],
37 'sc-php-post-value' => [ 'class' => 'SC_POST_VALUE', 'description' => __( 'Display a value from the $_POST array. The "key" arguments specifies which array value to render. It also supports the optional arguments of "default". If there is no value in the array for the given "key" then the "default" will be displayed. [sv slug="sc-php-post-value" key="username" default="Not Found"]', SH_CD_SLUG ), 'premium' => true ],
38 'sc-php-get-value' => [ 'class' => 'SC_GET_VALUE', 'description' => __( 'Display a value from the $_GET array. The "key" arguments specifies which array value to render. It also supports the optional arguments of "default". If there is no value in the array for the given "key" then the "default" will be displayed. [sv slug="sc-php-get-value" key="username" default="Not Found"]', SH_CD_SLUG ), 'premium' => true ],
39 'sc-php-info' => [ 'class' => 'SC_PHP_INFO', 'description' => __( 'Display PHP Info', SH_CD_SLUG ), 'premium' => true ],
40 'sc-post-id' => [ 'class' => 'SC_POST_ID', 'description' => __( 'Display ID for the current post.', SH_CD_SLUG ), 'premium' => true ],
41 'sc-post-author' => [ 'class' => 'SC_POST_AUTHOR', 'description' => __( 'Display the author\'s display name or ID. The optional argument "field" allows you to specify whether you wish to display the author\'s "display-name" or "id". [sv slug="sc-post-author" field="id" ]', SH_CD_SLUG ), 'premium' => true ],
42 'sc-post-counts' => [ 'class' => 'SC_POST_COUNTS', 'description' => __( 'Display a count of posts for certain statuses. Using the argument status, specify whether to return a count for all posts that have a status of "publish" (default), "future", "draft", "pending" or "private". [sv slug="sc-post-counts" status="draft"]', SH_CD_SLUG ), 'premium' => true ],
43 'sc-user-counts' => [ 'class' => 'SC_USER_COUNTS', 'description' => __( 'Display a count of all WordPress users or the number of WordPress users for a given role e.g. [sv slug="sc-user-counts" role="subscriber"] or [sv slug="sc-user-counts"]', SH_CD_SLUG ), 'premium' => true ],
44 'sc-user-profile-photo' => [ 'class' => 'SC_AVATAR', 'description' => __( 'Display the WordPress profile photo for the logged in user e.g. [sv slug="sc-user-profile-photo" width="150"] or [sv slug="sc-user-profile-photo"]. Please note, width defaults to 96px.', SH_CD_SLUG ), 'premium' => true ],
45 'sc-user-meta' => [ 'class' => 'SC_USER_META', 'description' => __( 'Display a WordPress user meta field (wraps get_user_meta) field e.g. last_name. Read more: <a href="https://snippet-shortcodes.yeken.uk/shortcodes/sc-user-meta" rel="noopener" target="_blank">[sv slug="sc-user-meta" field="last_name"]</a>', SH_CD_SLUG ), 'premium' => true ],
46 'sc-woocommerce' => [ 'class' => 'SC_USER_META', 'description' => __( 'Display a Woocommerce user profile field e.g. billing_phone. Read more: <a href="https://snippet-shortcodes.yeken.uk/shortcodes/sc-woocommerce" rel="noopener" target="_blank">[sv slug="sc-woocommerce" field="billing_phone"]</a>', SH_CD_SLUG ), 'premium' => true ]
47
48 // '' => [ 'class' => '', 'description' => '', 'premium' => true ]
49 ];
50 }
51
52
53 /**
54 * Get data from get_bloginfo()
55 *
56 * Class SV_SC_SITE_TITLE
57 */
58 class SV_SC_BLOG_INFO extends SV_Preset {
59
60 protected function unsanitised() {
61
62 $args = $this->get_arguments();
63
64 $key = ( false === empty( $args['_sh_cd_func'] ) ) ? $args['_sh_cd_func'] : 'name';
65
66 return get_bloginfo( $key );
67 }
68 }
69
70 /**
71 * Get data from $_SERVER
72 *
73 * Class SV_SC_SERVER_INFO
74 */
75 class SV_SC_SERVER_INFO extends SV_Preset {
76
77 protected function unsanitised() {
78
79 $args = $this->get_arguments();
80
81 return ( false === empty( $_SERVER[ $args['field'] ] ) ) ? $_SERVER[ $args['field'] ] : '';
82 }
83 }
84
85 /**
86 * Get a unique ID
87 *
88 * Class SV_SC_UNIQUE_ID
89 */
90 class SV_SC_UNIQUE_ID extends SV_Preset {
91
92 protected function unsanitised() {
93
94 $args = $this->get_arguments();
95
96 $prefix = ( false === empty( $args['prefix'] ) ) ? $args['prefix'] : '';
97
98 return uniqid ( $prefix, true );
99 }
100 }
101
102 /**
103 * Get timestamp
104 *
105 * Class SV_SC_TIMESTAMP
106 */
107 class SV_SC_TIMESTAMP extends SV_Preset {
108
109 protected function unsanitised() {
110 return time();
111 }
112 }
113
114 /**
115 * Display PHP INFO
116 *
117 * Class SV_SC_PHP_INFO
118 */
119 class SV_SC_PHP_INFO extends SV_Preset {
120
121 protected function unsanitised() {
122 return phpinfo();
123 }
124 }
125
126 /**
127 * Current URL
128 *
129 * Class SV_SC_CURRENT_URL
130 */
131 class SV_SC_CURRENT_URL extends SV_Preset {
132
133 protected function unsanitised() {
134
135 $protocol = (
136 ( isset($_SERVER['HTTPS'] ) && 'on' == $_SERVER['HTTPS'] ) ||
137 ( isset($_SERVER['SERVER_PORT'] ) && 443 == $_SERVER['SERVER_PORT'] )
138 ) ? 'https://' : 'http://';
139
140 return $protocol . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
141 }
142 }
143
144 /**
145 * Register URL
146 *
147 * Class SV_SC_REGISTER_URL
148 */
149 class SV_SC_REGISTER_URL extends SV_Preset {
150
151 protected function unsanitised() {
152 return wp_registration_url();
153 }
154 }
155
156 /**
157 * Random number
158 *
159 * Class SV_SC_RAND_NUMBER
160 */
161 class SV_SC_RAND_NUMBER extends SV_Preset {
162
163 protected function unsanitised() {
164
165 $args = $this->get_arguments();
166
167 $min = ( false === empty( $args['min'] ) ) ? (int) $args['min'] : 0;
168
169 $max = ( false === empty( $args['max'] ) ) ? (int) $args['max'] : getrandmax();
170
171 return rand( $min, $max );
172 }
173 }
174
175 /**
176 * Avatar URL
177 *
178 * Class SV_SC_AVATAR
179 */
180 class SV_SC_AVATAR extends SV_Preset {
181
182 public function init() {
183
184 $this->escape_method = false;
185 }
186
187 protected function unsanitised() {
188
189 $args = $this->get_arguments();
190 $user_id = get_current_user_id();
191
192 // if ( true === empty( $user_id ) ) {
193 // return '';
194 // }
195
196 $width = ( false === empty( $args['width'] ) ) ? (int) $args['width'] : 96;
197 $profile_url = get_avatar_url( $user_id, [ 'size' => $width ] );
198
199 if ( true === empty( $profile_url ) ){
200 return '';
201 }
202
203 return sprintf( '<img src="%1$s" />', esc_url( $profile_url ) );
204 }
205 }
206
207 /**
208 * Random string
209 *
210 * Based upon: https://stackoverflow.com/questions/4356289/php-random-string-generator
211 *
212 * Class SV_SC_RAND_STRING
213 */
214 class SV_SC_RAND_STRING extends SV_Preset {
215
216 protected function unsanitised() {
217
218 $args = $this->get_arguments();
219
220 $length = ( false === empty( $args['length'] ) ) ? (int) $args['length'] : 10;
221
222 $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
223 $no_characters = strlen( $characters );
224 $random_string = '';
225
226 for ($i = 0; $i < $length; $i++) {
227 $random_string .= $characters[ rand( 0, $no_characters - 1 ) ];
228 }
229
230 return $random_string;
231 }
232 }
233
234 /**
235 * Fetch an item from the $_POST array
236 *
237 * Class SV_SC_POST_VALUE
238 */
239 class SV_SC_POST_VALUE extends SV_Preset {
240
241 protected function unsanitised() {
242
243 $args = $this->get_arguments();
244
245 $post_value = ( false === empty( $_POST[ $args['key'] ] ) ) ? $_POST[ $args['key'] ] : NULL;
246
247 if ( null !== $post_value ) {
248 return $post_value;
249 }
250
251 // Do we have a fall back default?
252 return ( false === empty( $args['default'] ) ) ? $args['default'] : '';
253
254 }
255 }
256
257 /**
258 * Fetch an item from the $_GET array
259 *
260 * Class SV_SC_GET_VALUE
261 */
262 class SV_SC_GET_VALUE extends SV_Preset {
263
264 protected function unsanitised() {
265
266 $args = $this->get_arguments();
267
268 $post_value = ( false === empty( $_GET[ $args['key'] ] ) ) ? $_GET[ $args['key'] ] : NULL;
269
270 if ( null !== $post_value ) {
271 return $post_value;
272 }
273
274 // Do we have a fall back default?
275 return ( false === empty( $args['default'] ) ) ? $args['default'] : '';
276
277 }
278 }
279
280 /**
281 * Display current Post ID
282 *
283 * Class SV_SC_POST_ID
284 */
285 class SV_SC_POST_ID extends SV_Preset {
286
287 protected function unsanitised() {
288 return get_the_ID();
289 }
290 }
291
292 /**
293 * Display author of current post
294 *
295 * Class SV_SC_POST_AUTHOR
296 */
297 class SV_SC_POST_AUTHOR extends SV_Preset {
298
299 protected function unsanitised() {
300
301 $args = $this->get_arguments();
302
303 switch ( $args['field'] ) {
304 case 'id':
305 return get_the_author_meta( 'ID' );
306 break;
307 default:
308 return get_the_author();
309 }
310 }
311 }
312
313 /**
314 * Display post counts
315 *
316 * Class SV_SC_POST_COUNTS
317 */
318 class SV_SC_POST_COUNTS extends SV_Preset {
319
320 protected function unsanitised() {
321
322 $args = $this->get_arguments();
323
324 $counts = wp_count_posts();
325
326 switch ( $args['status'] ) {
327 case 'future':
328 return $counts->future;
329 break;
330 case 'draft':
331 return $counts->draft;
332 break;
333 case 'pending':
334 return $counts->pending;
335 break;
336 case 'private':
337 return $counts->private;
338 break;
339 default:
340 return $counts->publish;
341 }
342 }
343 }
344
345 /**
346 * Get a User counts
347 *
348 * Class SV_SC_USER_COUNTS
349 */
350 class SV_SC_USER_COUNTS extends SV_Preset {
351
352 protected function unsanitised() {
353
354 $args = $this->get_arguments();
355
356 $role = ( false === empty( $args['role'] ) ) ? $args['role'] : NULL;
357
358 $users = count_users();
359
360 if ( false === empty( $role ) && true === isset( $users['avail_roles'][ $role ] ) ) {
361 return $users['avail_roles'][ $role ];
362 } if ( true === isset( $users['total_users'] ) ) {
363 return $users['total_users'];
364 }
365
366 return '';
367 }
368 }
369
370 /**
371 * Display a date and also support date arithmetic
372 *
373 * Class SV_SC_DATE
374 */
375 class SV_SC_DATE extends SV_Preset {
376
377 protected function unsanitised() {
378
379 $args = $this->get_arguments();
380
381 $todays_date = date_create();
382
383 // Do we have an interval?
384 if ( false === empty( $args['interval'] ) ) {
385
386 $interval = date_interval_create_from_date_string( $args['interval'] );
387
388 if ( $interval !== false ) {
389 $todays_date = date_add( $todays_date, $interval );
390 }
391
392 }
393
394 $date_format = ( false === empty( $args['format'] ) ) ? $args['format'] : 'd/m/Y';
395
396 return date_format( $todays_date, $date_format );
397 }
398 }
399
400 /**
401 * Fetch a column from a MySQL database by ID
402 *
403 * Min example:
404 *
405 * [sv slug="sc-db-value-by-id" table="users" column="user_login" column-to-search="id" key="3"]
406 *
407 * Full example:
408 *
409 * [sv slug="sc-db-value-by-id" table="wp_users" column="user_login" column-to-search="id" key="3" key-format="%d" message-not-found="User not found" cache=false cache-duration=3600 ]
410 *
411 * Another example is to fetch the key we're searching for from the query string:
412 *
413 * e.g. https://[url]/?user-id=3
414 *
415 * [sv slug="sc-db-value-by-id" table="wp_users" column="user_login" column-to-search="id" key-query-string="user-id" key-format="%d" message-not-found="User not found" cache=false cache-duration=3600 ]
416 *
417 * SC_DB_VALUE_BY_ID
418 */
419 class SV_SC_DB_VALUE_BY_ID extends SV_Preset {
420
421 protected function unsanitised() {
422
423 $args = wp_parse_args( $this->get_arguments(), [ 'key-format' => '%d', 'key-query-string' => NULL, 'message-not-found' => '', 'cache' => true, 'cache-duration' => 1 * HOUR_IN_SECONDS ] );
424
425 if ( $validation_error = $this->validate_arguments( $args ) ) {
426 return $validation_error;
427 }
428
429 $cache_key = md5( print_r( $args, true ) );
430
431 if( true === sh_cd_to_bool( $args[ 'cache'] )
432 && $cache = sh_cd_cache_get( $cache_key ) ) {
433 return $cache;
434 }
435
436 global $wpdb;
437
438 // Load key to look for from querystring?
439 $key = ( false === empty( $args['key-query-string'] ) ) ?
440 $_GET[ $args['key-query-string'] ] : $args['key'];
441
442 $sql = sprintf( 'Select %s from %s where %s = %s',
443 $args['column'],
444 $args['table'],
445 $args['column-to-search'],
446 $args['key-format']
447 );
448
449 $sql = $wpdb->prepare( $sql, $key );
450 $value = $wpdb->get_var( $sql );
451
452 if ( true === empty( $value )) {
453 $value = $args['message-not-found'] ;
454 }
455
456 sh_cd_cache_set( $cache_key, $value, (int) $args[ 'cache-duration'] );
457
458 return $value;
459 }
460
461 protected function validate_arguments( $args = [] ) {
462
463 if ( false === sh_cd_is_shortcode_db_value_by_id_enabled() ) {
464 return 'This shortcode has been disabled by admin. See "WP Admin" > "Snippet Shortcodes" > "Settings" to enable.';
465 }
466
467 if ( true === empty( $args['table'] ) ) {
468 return 'No MySQL table specified (i.e. "table" argument is missing).';
469 }
470
471 if ( true === empty( $args['column'] ) ) {
472 return 'No MySQL column specified (i.e. "column" argument is missing).';
473 }
474
475 if ( true === empty( $args['column-to-search'] ) ) {
476 return 'The MySQL column to search for given key has not been specified (i.e. "column-to-search" argument is missing).';
477 }
478
479 if ( false === empty( $args['key-query-string'] ) ) {
480 if( true === empty( $_GET[ $args['key-query-string'] ] ) ) {
481 return sprintf('A querystring key ( "%1$s" ) has been specified but no value was been passed within the URL? (e.g. https://[website-address]/?%1$s=some-value).', esc_html( $args['key-query-string'] ) );
482 }
483 } elseif ( true === empty( $args['key'] ) ) {
484 return 'No key has been specified (i.e. the "key" and "key-query-string" arguments are both missing).';
485 }
486
487 if ( true === empty( $args['key-format'] ) ) {
488 return 'No key format has been specified (i.e. "key-format" argument is missing). If the "key" field is numeric, then use %d otherwise use %s.';
489 }
490
491 if ( false === in_array( $args['key-format'], [ '%s', '%d' ] ) ) {
492 return 'The key format is invalid. If the "key" field is numeric, then use %d otherwise use %s.';
493 }
494
495 }
496 }
497
498 /**
499 * User Info
500 *
501 * Class SV_USER_INFO
502 */
503 class SV_SC_USER_META extends SV_Preset {
504
505 protected function unsanitised() {
506
507 $user_id = get_current_user_id();
508
509 // Not logged in?
510 if ( true === empty( $user_id ) ) {
511 return '';
512 }
513
514 $args = wp_parse_args( $this->get_arguments(), [ 'field' => NULL, 'message-not-found' => '' ] );
515
516 if ( true === empty( $args[ 'field' ] ) ) {
517 return 'Field not specified';
518 }
519
520 $value = get_user_meta( $user_id, $args[ 'field' ], true );
521
522 return !empty( $value ) ? $value : $args[ 'message-not-found' ];
523 }
524 }
525