PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.5.2
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.5.2
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 / Plugin.php

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

307 lines 7.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Templately plugin.
4 *
5 * The main plugin handler class is responsible for initializing Templately. The
6 * class registers and all the components required to run the plugin.
7 *
8 * @package Templately
9 */
10
11 namespace Templately;
12
13 use Templately\Admin\API\Settings as APISettings;
14 use Templately\Admin\Settings;
15 use Templately\API\AIContent;
16 use Templately\API\LogoGeneration;
17 use Templately\API\Conditions;
18 use Templately\API\ThemeBuilderApi;
19 use Templately\Builder\ThemeBuilder;
20 use Templately\Core\Importer\FullSiteImport;
21 use Templately\Utils\Base;
22 use Templately\Utils\Enqueue;
23
24 use Templately\Core\Admin;
25 use Templately\Core\Module;
26
27 use Templately\API\Tags;
28 use Templately\API\Items;
29 use Templately\API\Login;
30 use Templately\API\SignUp;
31 use Templately\API\Profile;
32 use Templately\API\Import;
33 use Templately\API\MyClouds;
34 use Templately\API\WorkSpaces;
35 use Templately\API\Categories;
36 use Templately\API\Dependencies;
37 use Templately\API\TemplateTypes;
38 use Templately\API\SavedTemplates;
39 use Templately\API\Sites;
40 use Templately\Core\Maintenance;
41 use Templately\Core\Migrator;
42 use Templately\Core\Platform\Gutenberg;
43 use Templately\Core\Platform\Elementor;
44
45 final class Plugin extends Base {
46 public $version = '3.5.2';
47
48 public $admin;
49 public $settings;
50 /**
51 * Enqueue class responsible for assets
52 * @var Enqueue
53 */
54 public $assets;
55
56 /**
57 * @var ThemeBuilder
58 */
59 public $theme_builder;
60
61 /**
62 * @var Developer
63 */
64 public $developer;
65
66 /**
67 * Plugin constructor.
68 * Initializing Templately plugin.
69 *
70 * @access private
71 */
72 public function __construct() {
73 $this->define_constants();
74 $this->set_locale();
75
76 Maintenance::init();
77
78 $this->assets = Enqueue::get_instance( TEMPLATELY_URL, TEMPLATELY_PATH, $this->version );
79 $this->admin = Admin::get_instance();
80 $this->settings = Settings::get_instance();
81 $this->theme_builder = ThemeBuilder::get_instance();
82
83 // Initialize developer functionality if available
84 $this->init_developer_functionality();
85
86 add_action( 'plugins_loaded', [ $this, 'plugins_loaded' ] );
87 add_action( 'rest_api_init', [ $this, 'register_routes' ] );
88
89 add_action( 'wp_ajax_templately_google_login', [ $this, 'google_login_handler' ] );
90 add_action( 'wp_ajax_nopriv_templately_google_login', [ $this, 'google_login_handler' ] );
91
92 /**
93 * Initialize.
94 */
95 do_action( 'templately_init' );
96
97 }
98
99 /**
100 * Cloning is forbidden.
101 *
102 * @since 2.0
103 */
104 public function __clone() {
105 _doing_it_wrong( __FUNCTION__, __( 'Cloning is forbidden.', 'templately' ), '2.0' );
106 }
107
108 /**
109 * Un-serializing instances of this class is forbidden.
110 *
111 * @since 2.0
112 */
113 public function __wakeup() {
114 _doing_it_wrong( __FUNCTION__, __( 'Un-serializing instances of this class is forbidden.', 'templately' ), '2.0' );
115 }
116
117 /**
118 * Initializing Things on Plugins Loaded
119 * @return void
120 */
121 public function plugins_loaded() {
122 $this->platforms(); // PLATFORMS LOADED
123 $this->apis(); // APIs LOADED
124
125 /**
126 * Migrator for Templately
127 */
128 Migrator::get_instance();
129
130 /**
131 * Full Site Import
132 */
133 FullSiteImport::get_instance();
134 }
135
136 /**
137 * Initialize developer functionality if available
138 *
139 * This method safely loads developer functionality only if the developer
140 * directory and class exist, preventing fatal errors in production builds.
141 *
142 * @return void
143 */
144 private function init_developer_functionality() {
145 $developer_file = TEMPLATELY_PATH . 'includes/Core/Developer/Developer.php';
146
147 // Check if developer file exists before attempting to load
148 if ( file_exists( $developer_file ) ) {
149 // Include the developer class file
150 require_once $developer_file;
151
152 // Check if the class exists after including the file
153 if ( class_exists( '\\Templately\\Core\\Developer\\Developer' ) ) {
154 $this->developer = \Templately\Core\Developer\Developer::get_instance();
155 }
156 }
157
158 // If developer functionality is not available, set to null
159 if ( ! isset( $this->developer ) ) {
160 $this->developer = null;
161 }
162 }
163
164
165
166 /**
167 * Initialize all platforms
168 * @return void
169 */
170 public function platforms() {
171 Gutenberg::get_instance();
172 Elementor::get_instance();
173 }
174
175 /**
176 * All the API instantiated
177 *
178 * @return void
179 */
180 private function apis() {
181 Conditions::get_instance();
182 Categories::get_instance();
183 TemplateTypes::get_instance();
184 Dependencies::get_instance();
185 Tags::get_instance();
186 ThemeBuilderApi::get_instance();
187
188 AIContent::get_instance();
189 LogoGeneration::get_instance();
190 Items::get_instance();
191 SavedTemplates::get_instance();
192
193 Login::get_instance();
194 SignUp::get_instance();
195 Import::get_instance();
196 Profile::get_instance();
197 MyClouds::get_instance();
198 WorkSpaces::get_instance();
199 Sites::get_instance();
200
201 APISettings::get_instance();
202 // Note: DeveloperSettings::get_instance() is called in Developer::init_modules() when developer functionality is available and enabled
203 }
204
205 /**
206 * Register all REST API endpoints
207 * @return void
208 */
209 public function register_routes() {
210 if ( ! empty( $modules = Module::get_instance()->get( 'API' ) ) ) {
211 foreach ( $modules as $module ) {
212 $module->object->register_routes();
213 }
214 }
215 }
216
217 /**
218 * Define CONSTANTS
219 *
220 * @return void
221 * @since 2.0.0
222 */
223 public function define_constants() {
224 $this->define( 'TEMPLATELY_URL', plugin_dir_url( TEMPLATELY_FILE ) );
225 $this->define( 'TEMPLATELY_ASSETS', TEMPLATELY_URL . 'assets/' );
226 $this->define( 'TEMPLATELY_PLUGIN_BASENAME', plugin_basename( TEMPLATELY_FILE ) );
227 $this->define( 'TEMPLATELY_VERSION', $this->version );
228 $this->define( 'TEMPLATELY_API_NAMESPACE', 'templately/v1' );
229 $this->define( 'TEMPLATELY_VIEWS_ABSPATH', TEMPLATELY_PATH . 'views/' );
230 }
231
232 /**
233 * Define constant if not already set.
234 *
235 * @param string $name Constant name.
236 * @param mixed $value Constant value.
237 *
238 * @return void
239 */
240 private function define( string $name, $value ) {
241 if ( ! defined( $name ) ) {
242 define( $name, $value );
243 }
244 }
245
246 /**
247 * Setting the locale for translation availability
248 * @return void
249 * @since 1.0.0
250 */
251 public function set_locale() {
252 add_action( 'init', [ $this, 'load_textdomain' ] );
253 }
254
255 /**
256 * Loading Text Domain on init HOOK
257 * @return void
258 * @since 1.0.0
259 *
260 */
261 public function load_textdomain() {
262 load_plugin_textdomain( 'templately', false, dirname( TEMPLATELY_PLUGIN_BASENAME ) . '/languages' );
263 }
264
265 public function google_login_handler() {
266 $redirect_url = admin_url( 'admin.php?page=templately' );
267
268 if ( ! empty( $_GET['error'] ) ) {
269 $error_message = sanitize_text_field( $_GET['error'] );
270 } elseif ( ! empty( $_GET['api_key'] ) ) {
271 $request = new \WP_REST_Request( 'POST', '/templately/v1/login' );
272 $request->set_param( 'viaAPI', true );
273 $request->set_param( 'api_key', sanitize_text_field( $_GET['api_key'] ) );
274
275 /**
276 * @var Login $login
277 */
278 $login = Login::get_instance();
279 $login->permission_check( $request );
280 $response = $login->login();
281
282 if ( ! is_wp_error( $response ) && ! empty( $response['user'] ) ) {
283 $redirect_path = ! empty( $_GET['redirect-to'] ) ? sanitize_text_field( $_GET['redirect-to'] ) : '';
284
285 if ( ! empty( $redirect_path ) ) {
286 $redirect_url = add_query_arg( 'path', $redirect_path, $redirect_url );
287 }
288
289 wp_safe_redirect( $redirect_url );
290 exit;
291 } else {
292 $error_message = ( is_wp_error( $response ) ) ? $response->get_error_message() : __( 'Login failed.', 'templately' );
293 }
294 } else {
295 $error_message = __( 'Missing API Key.', 'templately' );
296 }
297
298 $redirect_url = add_query_arg( [
299 'path' => 'sign-in',
300 'error_message' => $error_message,
301 ], $redirect_url );
302
303 wp_safe_redirect( $redirect_url );
304 exit;
305 }
306 }
307