PluginProbe
Search Atlas SEO – OTTO AI SEO Automation for WordPress / 2.7.2
Search Atlas SEO – OTTO AI SEO Automation for WordPress v2.7.2
2.7.1 2.7.2 2.7.0 2.6.26 2.6.25 2.6.24 2.6.23 2.6.22 2.6.21 2.6.20 2.6.19 2.6.18 2.6.17 2.6.16 2.6.15 2.6.14 2.6.13 2.6.12 2.6.11 2.6.10 2.6.9 2.6.8 2.6.7 2.6.6 2.6.5 All 141 releases
metasync / otto / class-metasync-otto-config.php

class-metasync-otto-config.php in Search Atlas SEO – OTTO AI SEO Automation for WordPress 2.7.2, at otto/class-metasync-otto-config.php

152 lines 4.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * MetaSync Otto Configuration Cache
4 *
5 * PERFORMANCE OPTIMIZATION: This class provides static caching of plugin options
6 * to avoid repeated get_option() calls within the same request.
7 *
8 * Expected improvement: 75% reduction in option loading queries
9 *
10 * @package Metasync
11 * @subpackage Otto
12 * @since 2.5.16
13 */
14
15 if (!defined('ABSPATH')) {
16 exit; # Exit if accessed directly
17 }
18
19 class Metasync_Otto_Config {
20 /**
21 * Cached options array
22 * @var array|null
23 */
24 private static $options = null;
25
26 /**
27 * Flag to track if options have been loaded
28 * @var bool
29 */
30 private static $loaded = false;
31
32 /**
33 * Get all MetaSync options (cached)
34 *
35 * @return array The cached options array
36 */
37 public static function get_options() {
38 if (!self::$loaded) {
39 self::$options = get_option('metasync_options');
40 self::$loaded = true;
41 }
42 return self::$options;
43 }
44
45 /**
46 * Get Otto Pixel UUID
47 *
48 * @return string The Otto UUID or empty string
49 */
50 public static function get_otto_uuid() {
51 $options = self::get_options();
52 return $options['general']['otto_pixel_uuid'] ?? '';
53 }
54
55 /**
56 * Check if Otto is enabled
57 *
58 * @return bool True if Otto UUID is configured
59 */
60 public static function is_otto_enabled() {
61 return !empty(self::get_otto_uuid());
62 }
63
64 /**
65 * Check if Otto is disabled for logged-in users
66 *
67 * @return bool True if Otto should be disabled for logged-in users
68 */
69 public static function is_disabled_for_loggedin() {
70 $options = self::get_options();
71 return !empty($options['general']['otto_disable_on_loggedin']) &&
72 filter_var($options['general']['otto_disable_on_loggedin'], FILTER_VALIDATE_BOOLEAN);
73 }
74
75 /**
76 * Get WP Rocket compatibility mode setting
77 *
78 * @return string Compatibility mode: 'auto', 'disabled', or 'forced'
79 */
80 public static function get_wp_rocket_compat_mode() {
81 $options = self::get_options();
82 return $options['general']['otto_wp_rocket_compat'] ?? 'auto';
83 }
84
85 /**
86 * Get the configured OTTO suggestions cache TTL, in seconds.
87 *
88 * Reads the admin-configurable value (in minutes) from execution settings,
89 * defaults to 30 minutes when unset, and clamps to [30, 1440] minutes so a
90 * bad stored value can never produce a runaway or zero TTL.
91 *
92 * @return int TTL in seconds
93 */
94 public static function get_otto_cache_ttl_seconds() {
95 $execution_settings = get_option('metasync_execution_settings', array());
96 $minutes = isset($execution_settings['otto_cache_ttl'])
97 ? (int) $execution_settings['otto_cache_ttl']
98 : 30;
99
100 if ($minutes < 30) {
101 $minutes = 30;
102 } elseif ($minutes > 1440) {
103 $minutes = 1440;
104 }
105
106 return $minutes * MINUTE_IN_SECONDS;
107 }
108
109 /**
110 * Check if meta descriptions are enabled
111 *
112 * @return bool True if meta descriptions are enabled
113 */
114 public static function is_meta_description_enabled() {
115 $options = self::get_options();
116 $enable_metadesc = $options['general']['enable_metadesc'] ?? '';
117 return $enable_metadesc === 'true' || $enable_metadesc === true;
118 }
119
120 /**
121 * Get a specific option value by path
122 *
123 * @param string $path Dot-notation path to option (e.g., 'general.otto_pixel_uuid')
124 * @param mixed $default Default value if not found
125 * @return mixed The option value or default
126 */
127 public static function get($path, $default = null) {
128 $options = self::get_options();
129 $keys = explode('.', $path);
130
131 $value = $options;
132 foreach ($keys as $key) {
133 if (!isset($value[$key])) {
134 return $default;
135 }
136 $value = $value[$key];
137 }
138
139 return $value;
140 }
141
142 /**
143 * Clear the cached options (useful for testing or when options change)
144 *
145 * @return void
146 */
147 public static function clear_cache() {
148 self::$options = null;
149 self::$loaded = false;
150 }
151 }
152