| @@ -9,8 +9,12 @@ | ||
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | 11 | namespace Templately; |
| 12 | 12 | |
| 13 | +use Templately\Admin\API\Settings as APISettings; | |
| 14 | +use Templately\Admin\Settings; | |
| 15 | +use Templately\API\AIContent; | |
| 16 | +use Templately\API\LogoGeneration; | |
| 13 | 17 | use Templately\API\Conditions; |
| 14 | 18 | use Templately\API\ThemeBuilderApi; |
| 15 | 19 | use Templately\Builder\ThemeBuilder; |
| 16 | 20 | use Templately\Core\Importer\FullSiteImport; |
| @@ -31,8 +35,9 @@ | ||
| 31 | 35 | use Templately\API\Categories; |
| 32 | 36 | use Templately\API\Dependencies; |
| 33 | 37 | use Templately\API\TemplateTypes; |
| 34 | 38 | use Templately\API\SavedTemplates; |
| 39 | +use Templately\API\Sites; | |
| 35 | 40 | use Templately\Core\Maintenance; |
| 36 | 41 | use Templately\Core\Migrator; |
| 37 | 42 | use Templately\Core\Platform\Gutenberg; |
| 38 | 43 | use Templately\Core\Platform\Elementor; |
| @@ -37,11 +42,12 @@ | ||
| 37 | 42 | use Templately\Core\Platform\Gutenberg; |
| 38 | 43 | use Templately\Core\Platform\Elementor; |
| 39 | 44 | |
| 40 | 45 | final class Plugin extends Base { |
| 41 | - public $version = '3.0.8'; | |
| 46 | + public $version = '3.5.2'; | |
| 42 | 47 | |
| 43 | 48 | public $admin; |
| 49 | + public $settings; | |
| 44 | 50 | /** |
| 45 | 51 | * Enqueue class responsible for assets |
| 46 | 52 | * @var Enqueue |
| 47 | 53 | */ |
| @@ -52,8 +58,13 @@ | ||
| 52 | 58 | */ |
| 53 | 59 | public $theme_builder; |
| 54 | 60 | |
| 55 | 61 | /** |
| 62 | + * @var Developer | |
| 63 | + */ | |
| 64 | + public $developer; | |
| 65 | + | |
| 66 | + /** | |
| 56 | 67 | * Plugin constructor. |
| 57 | 68 | * Initializing Templately plugin. |
| 58 | 69 | * |
| 59 | 70 | * @access private |
| @@ -65,16 +76,25 @@ | ||
| 65 | 76 | Maintenance::init(); |
| 66 | 77 | |
| 67 | 78 | $this->assets = Enqueue::get_instance( TEMPLATELY_URL, TEMPLATELY_PATH, $this->version ); |
| 68 | 79 | $this->admin = Admin::get_instance(); |
| 80 | + $this->settings = Settings::get_instance(); | |
| 69 | 81 | $this->theme_builder = ThemeBuilder::get_instance(); |
| 70 | 82 | |
| 83 | + // Initialize developer functionality if available | |
| 84 | + $this->init_developer_functionality(); | |
| 85 | + | |
| 71 | 86 | add_action( 'plugins_loaded', [ $this, 'plugins_loaded' ] ); |
| 72 | 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 | + | |
| 73 | 92 | /** |
| 74 | 93 | * Initialize. |
| 75 | 94 | */ |
| 76 | 95 | do_action( 'templately_init' ); |
| 96 | + | |
| 77 | 97 | } |
| 78 | 98 | |
| 79 | 99 | /** |
| 80 | 100 | * Cloning is forbidden. |
| @@ -113,8 +133,38 @@ | ||
| 113 | 133 | FullSiteImport::get_instance(); |
| 114 | 134 | } |
| 115 | 135 | |
| 116 | 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 | + /** | |
| 117 | 167 | * Initialize all platforms |
| 118 | 168 | * @return void |
| 119 | 169 | */ |
| 120 | 170 | public function platforms() { |
| @@ -134,8 +184,10 @@ | ||
| 134 | 184 | Dependencies::get_instance(); |
| 135 | 185 | Tags::get_instance(); |
| 136 | 186 | ThemeBuilderApi::get_instance(); |
| 137 | 187 | |
| 188 | + AIContent::get_instance(); | |
| 189 | + LogoGeneration::get_instance(); | |
| 138 | 190 | Items::get_instance(); |
| 139 | 191 | SavedTemplates::get_instance(); |
| 140 | 192 | |
| 141 | 193 | Login::get_instance(); |
| @@ -143,8 +195,12 @@ | ||
| 143 | 195 | Import::get_instance(); |
| 144 | 196 | Profile::get_instance(); |
| 145 | 197 | MyClouds::get_instance(); |
| 146 | 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 | |
| 147 | 203 | } |
| 148 | 204 | |
| 149 | 205 | /** |
| 150 | 206 | * Register all REST API endpoints |
| @@ -203,6 +259,48 @@ | ||
| 203 | 259 | * |
| 204 | 260 | */ |
| 205 | 261 | public function load_textdomain() { |
| 206 | 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; | |
| 207 | 305 | } |
| 208 | 306 | } |