PluginProbe
MOBILOOK — Mobile View & Mobile‑Friendly Test / trunk
MOBILOOK — Mobile View & Mobile‑Friendly Test vtrunk
2.1.3 2.1.2 trunk 1.2.8 2.0.1 2.0.3 2.1.0 2.1.1
mobilook / core / Option.php

Option.php in MOBILOOK — Mobile View & Mobile‑Friendly Test trunk, at core/Option.php

63 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Pagup\Mobilook\Core;
3
4 class Option
5 {
6 /**
7 * Retrieves all options.
8 *
9 * @return array The option value or false if not found.
10 */
11 public static function all(): array
12 {
13 $option = get_option('mobilook');
14 return is_array($option) ? $option : [];
15 }
16
17 /**
18 * Retrieves a specific option value by key.
19 *
20 * @param string $key The key for the option value.
21 */
22 public static function get(string $key)
23 {
24 $option = static::all();
25 return $option[$key];
26 }
27
28 /**
29 * Checks if a specific option key is set and not empty.
30 *
31 * @param string $key The key for the option.
32 * @return bool True if the option key is set and not empty, false otherwise.
33 */
34 public static function check(string $key): bool
35 {
36 $option = static::all();
37 return isset($option[$key]) && !empty($option[$key]);
38 }
39
40 /**
41 * Validates if a specific option key matches a given value.
42 *
43 * @param string $option The key for the option.
44 * @param mixed $val The value to compare.
45 * @return bool True if the option key matches the value, false otherwise.
46 */
47 public static function valid(string $option, $val): bool
48 {
49 return static::check($option) && static::get($option) == $val;
50 }
51
52 /**
53 * Retrieves post meta value by key for the current queried object.
54 *
55 * @param string $key The key for the post meta value.
56 */
57 public static function post_meta(string $key)
58 {
59 $post_id = get_queried_object_id();
60 return get_post_meta($post_id, $key, true);
61 }
62 }
63