PluginProbe
Search Atlas SEO – OTTO AI SEO Automation for WordPress / 2.7.1
Search Atlas SEO – OTTO AI SEO Automation for WordPress v2.7.1
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 / includes / class-metasync-endpoint-manager.php

class-metasync-endpoint-manager.php in Search Atlas SEO – OTTO AI SEO Automation for WordPress 2.7.1, at includes/class-metasync-endpoint-manager.php

144 lines 4.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Endpoint Manager for MetaSync Plugin
4 *
5 * Manages switching between production and staging endpoints for development and testing.
6 *
7 * @package Metasync
8 * @subpackage Metasync/includes
9 */
10
11 /**
12 * The endpoint manager class.
13 *
14 * Provides centralized management of all SearchAtlas API endpoints with support
15 * for switching between production and staging environments.
16 *
17 * @package Metasync
18 * @subpackage Metasync/includes
19 */
20 class Metasync_Endpoint_Manager {
21
22 /**
23 * Option name for storing the current endpoint mode.
24 */
25 const MODE_OPTION = 'metasync_dev_endpoint_mode';
26
27 /**
28 * Valid endpoint modes.
29 */
30 const MODE_PRODUCTION = 'production';
31 const MODE_STAGING = 'staging';
32
33 /**
34 * Endpoint mapping for production and staging environments.
35 *
36 * @var array
37 */
38 private static $endpoints = array(
39 'production' => array(
40 'DASHBOARD_DOMAIN' => 'https://dashboard.searchatlas.com',
41 'API_DOMAIN' => 'https://api.searchatlas.com',
42 'CA_API_DOMAIN' => 'https://ca.searchatlas.com',
43 'OTTO_API_DOMAIN' => 'https://sa.searchatlas.com',
44 'OTTO_URL_DETAILS' => 'https://sa.searchatlas.com/api/v2/otto-url-details',
45 'OTTO_CRAWL_LOGS' => 'https://sa.searchatlas.com/api/v2/otto-page-crawl-logs',
46 'OTTO_PROJECTS' => 'https://sa.searchatlas.com/api/v2/otto-projects',
47 ),
48 'staging' => array(
49 'DASHBOARD_DOMAIN' => 'https://dashboard.staging.searchatlas.com',
50 'API_DOMAIN' => 'https://api.staging.searchatlas.com',
51 'CA_API_DOMAIN' => 'https://ca.staging.searchatlas.com',
52 'OTTO_API_DOMAIN' => 'https://sa.staging.searchatlas.com',
53 'OTTO_URL_DETAILS' => 'https://sa.staging.searchatlas.com/api/v2/otto-url-details',
54 'OTTO_CRAWL_LOGS' => 'https://sa.staging.searchatlas.com/api/v2/otto-page-crawl-logs',
55 'OTTO_PROJECTS' => 'https://sa.staging.searchatlas.com/api/v2/otto-projects',
56 ),
57 );
58
59 /**
60 * Get the current endpoint mode.
61 *
62 * @return string Either 'production' or 'staging'.
63 */
64 public static function get_mode() {
65 $mode = get_option( self::MODE_OPTION, self::MODE_PRODUCTION );
66
67 // Validate mode
68 if ( ! in_array( $mode, array( self::MODE_PRODUCTION, self::MODE_STAGING ), true ) ) {
69 $mode = self::MODE_PRODUCTION;
70 }
71
72 return $mode;
73 }
74
75 /**
76 * Set the endpoint mode.
77 *
78 * @param string $mode The mode to set ('production' or 'staging').
79 * @return bool True on success, false on failure.
80 */
81 public static function set_mode( $mode ) {
82 // Validate mode
83 if ( ! in_array( $mode, array( self::MODE_PRODUCTION, self::MODE_STAGING ), true ) ) {
84 error_log( "MetaSync Endpoint Manager: Invalid mode '{$mode}' provided" ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log -- genuine failure path, bounded, no secrets
85 return false;
86 }
87
88 $result = update_option( self::MODE_OPTION, $mode );
89
90 return $result;
91 }
92
93 /**
94 * Get a specific endpoint URL by key.
95 *
96 * @param string $endpoint_key The endpoint key (e.g., 'OTTO_URL_DETAILS').
97 * @return string The endpoint URL, or empty string if not found.
98 */
99 public static function get_endpoint( $endpoint_key ) {
100 $mode = self::get_mode();
101
102 if ( ! isset( self::$endpoints[ $mode ][ $endpoint_key ] ) ) {
103 error_log( "MetaSync Endpoint Manager: Unknown endpoint key '{$endpoint_key}'" ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log -- genuine failure path, bounded, no secrets
104
105 // Fallback to production if key exists there
106 if ( isset( self::$endpoints[ self::MODE_PRODUCTION ][ $endpoint_key ] ) ) {
107 return self::$endpoints[ self::MODE_PRODUCTION ][ $endpoint_key ];
108 }
109
110 return '';
111 }
112
113 return self::$endpoints[ $mode ][ $endpoint_key ];
114 }
115
116 /**
117 * Get all endpoints for the current mode.
118 *
119 * @return array Associative array of endpoint keys and URLs.
120 */
121 public static function get_all_endpoints() {
122 $mode = self::get_mode();
123 return self::$endpoints[ $mode ];
124 }
125
126 /**
127 * Check if staging mode is currently active.
128 *
129 * @return bool True if staging mode is active, false otherwise.
130 */
131 public static function is_staging_mode() {
132 return self::get_mode() === self::MODE_STAGING;
133 }
134
135 /**
136 * Get all available modes.
137 *
138 * @return array Array of available modes.
139 */
140 public static function get_available_modes() {
141 return array( self::MODE_PRODUCTION, self::MODE_STAGING );
142 }
143 }
144