PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.4.0
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.4.0
3.7.5 3.7.4 3.7.3 3.7.2 1-final 3.7.1 3.7.0 3.6.8 3.6.7 3.6.6 3.6.5 3.6.4 3.6.3 3.6.2 3.6.1 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.10 All 111 releases
templately / includes / Core / Developer / ApiManager.php

ApiManager.php in Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! 3.4.0, at includes/Core/Developer/ApiManager.php

74 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Templately\Core\Developer;
3
4 use Templately\Utils\Base;
5 use Templately\Utils\Helper;
6
7 /**
8 * Developer API Manager
9 *
10 * Handles API endpoint selection and legacy constant compatibility for developer features.
11 * Follows the proper module architecture pattern used by other developer modules.
12 *
13 * @since 3.3.4
14 */
15 class ApiManager extends Base {
16
17 /**
18 * Initialize ApiManager module
19 *
20 * Handles legacy TEMPLATELY_DEV constant compatibility and sets up hooks
21 */
22 public function __construct() {
23 // Handle legacy TEMPLATELY_DEV constant compatibility
24 $this->handle_legacy_constants();
25
26 // Initialize hooks
27 $this->init_hooks();
28 }
29
30 /**
31 * Handle legacy TEMPLATELY_DEV constant compatibility
32 *
33 * Automatically define TEMPLATELY_DEV_API as true if TEMPLATELY_DEV_API is not
34 * already defined AND TEMPLATELY_DEV constant is defined and true.
35 * This ensures existing setups using the old TEMPLATELY_DEV constant continue to work.
36 */
37 private function handle_legacy_constants() {
38 if ( ! defined( 'TEMPLATELY_DEV_API' ) && defined( 'TEMPLATELY_DEV' ) && constant( 'TEMPLATELY_DEV' ) ) {
39 define( 'TEMPLATELY_DEV_API', true );
40 }
41 }
42
43 /**
44 * Initialize hooks
45 */
46 private function init_hooks() {
47 add_filter( 'templately_admin_localized_data', [ $this, 'filter_localized_data' ] );
48 }
49
50 /**
51 * Check if development API should be used
52 *
53 * Simplified logic: if TEMPLATELY_DEV_API is defined and true, use dev server.
54 * Otherwise, use production server.
55 *
56 * @return bool True if development API should be used
57 */
58 public static function is_dev_api() {
59 return defined( 'TEMPLATELY_DEV_API' ) && constant( 'TEMPLATELY_DEV_API' );
60 }
61
62 /**
63 * Filter localized data to add API connection information
64 *
65 * @param array $data The localized data array
66 * @return array Modified localized data
67 */
68 public function filter_localized_data( $data ) {
69 $data['dev_api'] = Helper::is_dev_api();
70
71 return $data;
72 }
73 }
74