| @@ -6,19 +6,10 @@ | ||
| 6 | 6 | * class registers and all the components required to run the plugin. |
| 7 | 7 | * |
| 8 | 8 | * @package Templately |
| 9 | 9 | */ |
| 10 | - | |
| 11 | 10 | namespace Templately; |
| 12 | 11 | |
| 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 | 12 | use Templately\Utils\Base; |
| 22 | 13 | use Templately\Utils\Enqueue; |
| 23 | 14 | |
| 24 | 15 | use Templately\Core\Admin; |
| @@ -35,10 +26,8 @@ | ||
| 35 | 26 | use Templately\API\Categories; |
| 36 | 27 | use Templately\API\Dependencies; |
| 37 | 28 | use Templately\API\TemplateTypes; |
| 38 | 29 | use Templately\API\SavedTemplates; |
| 39 | -use Templately\API\Sites; | |
| 40 | -use Templately\API\Tour; | |
| 41 | 30 | use Templately\Core\Maintenance; |
| 42 | 31 | use Templately\Core\Migrator; |
| 43 | 32 | use Templately\Core\Platform\Gutenberg; |
| 44 | 33 | use Templately\Core\Platform\Elementor; |
| @@ -43,60 +32,39 @@ | ||
| 43 | 32 | use Templately\Core\Platform\Gutenberg; |
| 44 | 33 | use Templately\Core\Platform\Elementor; |
| 45 | 34 | |
| 46 | 35 | final class Plugin extends Base { |
| 47 | - public $version = '3.6.1'; | |
| 36 | + public $version = '2.2.5'; | |
| 48 | 37 | |
| 49 | 38 | public $admin; |
| 50 | - public $settings; | |
| 51 | - /** | |
| 52 | - * Enqueue class responsible for assets | |
| 53 | - * @var Enqueue | |
| 54 | - */ | |
| 55 | - public $assets; | |
| 39 | + /** | |
| 40 | + * Enqueue class responsible for assets | |
| 41 | + * @var Enqueue | |
| 42 | + */ | |
| 43 | + public $assets; | |
| 44 | + /** | |
| 45 | + * Plugin constructor. | |
| 46 | + * Initializing Templately plugin. | |
| 47 | + * | |
| 48 | + * @access private | |
| 49 | + */ | |
| 50 | + public function __construct() { | |
| 51 | + $this->define_constants(); | |
| 52 | + $this->set_locale(); | |
| 56 | 53 | |
| 57 | - /** | |
| 58 | - * @var ThemeBuilder | |
| 59 | - */ | |
| 60 | - public $theme_builder; | |
| 61 | - | |
| 62 | - /** | |
| 63 | - * @var Developer | |
| 64 | - */ | |
| 65 | - public $developer; | |
| 66 | - | |
| 67 | - /** | |
| 68 | - * Plugin constructor. | |
| 69 | - * Initializing Templately plugin. | |
| 70 | - * | |
| 71 | - * @access private | |
| 72 | - */ | |
| 73 | - public function __construct() { | |
| 74 | - $this->define_constants(); | |
| 75 | - $this->set_locale(); | |
| 76 | - | |
| 77 | 54 | Maintenance::init(); |
| 78 | 55 | |
| 79 | - $this->assets = Enqueue::get_instance( TEMPLATELY_URL, TEMPLATELY_PATH, $this->version ); | |
| 80 | - $this->admin = Admin::get_instance(); | |
| 81 | - $this->settings = Settings::get_instance(); | |
| 82 | - $this->theme_builder = ThemeBuilder::get_instance(); | |
| 56 | + $this->assets = Enqueue::get_instance( TEMPLATELY_URL, TEMPLATELY_PATH, $this->version ); | |
| 57 | + $this->admin = Admin::get_instance(); | |
| 83 | 58 | |
| 84 | - // Initialize developer functionality if available | |
| 85 | - $this->init_developer_functionality(); | |
| 86 | - | |
| 87 | - add_action( 'plugins_loaded', [ $this, 'plugins_loaded' ] ); | |
| 88 | - add_action( 'rest_api_init', [ $this, 'register_routes' ] ); | |
| 89 | - | |
| 90 | - add_action( 'init', [ $this, 'google_login_handler' ] ); | |
| 91 | - | |
| 59 | + add_action( 'plugins_loaded', [$this, 'plugins_loaded'] ); | |
| 60 | + add_action( 'rest_api_init', [$this, 'register_routes'] ); | |
| 92 | 61 | /** |
| 93 | 62 | * Initialize. |
| 94 | 63 | */ |
| 95 | - do_action( 'templately_init' ); | |
| 64 | + do_action( 'templately_init' ); | |
| 65 | + } | |
| 96 | 66 | |
| 97 | - } | |
| 98 | - | |
| 99 | 67 | /** |
| 100 | 68 | * Cloning is forbidden. |
| 101 | 69 | * |
| 102 | 70 | * @since 2.0 |
| @@ -105,14 +73,14 @@ | ||
| 105 | 73 | _doing_it_wrong( __FUNCTION__, __( 'Cloning is forbidden.', 'templately' ), '2.0' ); |
| 106 | 74 | } |
| 107 | 75 | |
| 108 | 76 | /** |
| 109 | - * Un-serializing instances of this class is forbidden. | |
| 77 | + * Unserializing instances of this class is forbidden. | |
| 110 | 78 | * |
| 111 | 79 | * @since 2.0 |
| 112 | 80 | */ |
| 113 | 81 | public function __wakeup() { |
| 114 | - _doing_it_wrong( __FUNCTION__, __( 'Un-serializing instances of this class is forbidden.', 'templately' ), '2.0' ); | |
| 82 | + _doing_it_wrong( __FUNCTION__, __( 'Unserializing instances of this class is forbidden.', 'templately' ), '2.0' ); | |
| 115 | 83 | } |
| 116 | 84 | |
| 117 | 85 | /** |
| 118 | 86 | * Initializing Things on Plugins Loaded |
| @@ -117,9 +85,9 @@ | ||
| 117 | 85 | /** |
| 118 | 86 | * Initializing Things on Plugins Loaded |
| 119 | 87 | * @return void |
| 120 | 88 | */ |
| 121 | - public function plugins_loaded() { | |
| 89 | + public function plugins_loaded(){ | |
| 122 | 90 | $this->platforms(); // PLATFORMS LOADED |
| 123 | 91 | $this->apis(); // APIs LOADED |
| 124 | 92 | |
| 125 | 93 | /** |
| @@ -125,53 +93,18 @@ | ||
| 125 | 93 | /** |
| 126 | 94 | * Migrator for Templately |
| 127 | 95 | */ |
| 128 | 96 | Migrator::get_instance(); |
| 129 | - | |
| 130 | - /** | |
| 131 | - * Full Site Import | |
| 132 | - */ | |
| 133 | - FullSiteImport::get_instance(); | |
| 134 | 97 | } |
| 135 | 98 | |
| 136 | 99 | /** |
| 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 | 100 | * Initialize all platforms |
| 168 | 101 | * @return void |
| 169 | 102 | */ |
| 170 | - public function platforms() { | |
| 171 | - Gutenberg::get_instance(); | |
| 172 | - Elementor::get_instance(); | |
| 173 | - } | |
| 103 | + public function platforms(){ | |
| 104 | + Gutenberg::get_instance(); | |
| 105 | + Elementor::get_instance(); | |
| 106 | + } | |
| 174 | 107 | |
| 175 | 108 | /** |
| 176 | 109 | * All the API instantiated |
| 177 | 110 | * |
| @@ -176,32 +109,23 @@ | ||
| 176 | 109 | * All the API instantiated |
| 177 | 110 | * |
| 178 | 111 | * @return void |
| 179 | 112 | */ |
| 180 | - private function apis() { | |
| 181 | - Conditions::get_instance(); | |
| 113 | + private function apis(){ | |
| 182 | 114 | Categories::get_instance(); |
| 183 | - TemplateTypes::get_instance(); | |
| 184 | - Dependencies::get_instance(); | |
| 185 | - Tags::get_instance(); | |
| 186 | - ThemeBuilderApi::get_instance(); | |
| 115 | + TemplateTypes::get_instance(); | |
| 116 | + Dependencies::get_instance(); | |
| 117 | + Tags::get_instance(); | |
| 187 | 118 | |
| 188 | - AIContent::get_instance(); | |
| 189 | - LogoGeneration::get_instance(); | |
| 190 | - Items::get_instance(); | |
| 191 | - SavedTemplates::get_instance(); | |
| 119 | + Items::get_instance(); | |
| 120 | + SavedTemplates::get_instance(); | |
| 192 | 121 | |
| 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 | - Tour::get_instance(); | |
| 201 | - | |
| 202 | - APISettings::get_instance(); | |
| 203 | - // Note: DeveloperSettings::get_instance() is called in Developer::init_modules() when developer functionality is available and enabled | |
| 122 | + Login::get_instance(); | |
| 123 | + SignUp::get_instance(); | |
| 124 | + Import::get_instance(); | |
| 125 | + Profile::get_instance(); | |
| 126 | + MyClouds::get_instance(); | |
| 127 | + WorkSpaces::get_instance(); | |
| 204 | 128 | } |
| 205 | 129 | |
| 206 | 130 | /** |
| 207 | 131 | * Register all REST API endpoints |
| @@ -206,40 +130,39 @@ | ||
| 206 | 130 | /** |
| 207 | 131 | * Register all REST API endpoints |
| 208 | 132 | * @return void |
| 209 | 133 | */ |
| 210 | - public function register_routes() { | |
| 211 | - if ( ! empty( $modules = Module::get_instance()->get( 'API' ) ) ) { | |
| 212 | - foreach ( $modules as $module ) { | |
| 134 | + public function register_routes(){ | |
| 135 | + if( ! empty( $modules = Module::get_instance()->get( 'API' ) ) ) { | |
| 136 | + foreach( $modules as $module ) { | |
| 213 | 137 | $module->object->register_routes(); |
| 214 | 138 | } |
| 215 | 139 | } |
| 216 | - } | |
| 140 | + } | |
| 217 | 141 | |
| 218 | 142 | /** |
| 219 | 143 | * Define CONSTANTS |
| 220 | 144 | * |
| 145 | + * @since 2.0.0 | |
| 221 | 146 | * @return void |
| 222 | - * @since 2.0.0 | |
| 223 | 147 | */ |
| 224 | - public function define_constants() { | |
| 225 | - $this->define( 'TEMPLATELY_URL', plugin_dir_url( TEMPLATELY_FILE ) ); | |
| 226 | - $this->define( 'TEMPLATELY_ASSETS', TEMPLATELY_URL . 'assets/' ); | |
| 148 | + public function define_constants() { | |
| 149 | + $this->define( 'TEMPLATELY_URL', plugin_dir_url( TEMPLATELY_FILE ) ); | |
| 150 | + $this->define( 'TEMPLATELY_ASSETS', TEMPLATELY_URL . 'assets/' ); | |
| 227 | 151 | $this->define( 'TEMPLATELY_PLUGIN_BASENAME', plugin_basename( TEMPLATELY_FILE ) ); |
| 228 | 152 | $this->define( 'TEMPLATELY_VERSION', $this->version ); |
| 229 | - $this->define( 'TEMPLATELY_API_NAMESPACE', 'templately/v1' ); | |
| 230 | - $this->define( 'TEMPLATELY_VIEWS_ABSPATH', TEMPLATELY_PATH . 'views/' ); | |
| 231 | - } | |
| 153 | + $this->define( 'TEMPLATELY_API_NAMESPACE', 'templately/v1' ); | |
| 154 | + } | |
| 232 | 155 | |
| 233 | 156 | /** |
| 234 | 157 | * Define constant if not already set. |
| 235 | 158 | * |
| 236 | - * @param string $name Constant name. | |
| 159 | + * @param string $name Constant name. | |
| 237 | 160 | * @param mixed $value Constant value. |
| 238 | 161 | * |
| 239 | 162 | * @return void |
| 240 | 163 | */ |
| 241 | - private function define( string $name, $value ) { | |
| 164 | + private function define( $name, $value ) { | |
| 242 | 165 | if ( ! defined( $name ) ) { |
| 243 | 166 | define( $name, $value ); |
| 244 | 167 | } |
| 245 | 168 | } |
| @@ -245,83 +168,21 @@ | ||
| 245 | 168 | } |
| 246 | 169 | |
| 247 | 170 | /** |
| 248 | 171 | * Setting the locale for translation availability |
| 172 | + * @since 1.0.0 | |
| 249 | 173 | * @return void |
| 250 | - * @since 1.0.0 | |
| 251 | 174 | */ |
| 252 | - public function set_locale() { | |
| 175 | + public function set_locale(){ | |
| 253 | 176 | add_action( 'init', [ $this, 'load_textdomain' ] ); |
| 254 | 177 | } |
| 255 | 178 | |
| 256 | 179 | /** |
| 257 | 180 | * Loading Text Domain on init HOOK |
| 258 | - * @return void | |
| 259 | 181 | * @since 1.0.0 |
| 260 | 182 | * |
| 183 | + * @return void | |
| 261 | 184 | */ |
| 262 | - public function load_textdomain() { | |
| 185 | + public function load_textdomain(){ | |
| 263 | 186 | load_plugin_textdomain( 'templately', false, dirname( TEMPLATELY_PLUGIN_BASENAME ) . '/languages' ); |
| 264 | - } | |
| 265 | - | |
| 266 | - public function google_login_handler() { | |
| 267 | - // Stop if not a templately google login request | |
| 268 | - if ( empty( $_GET['templately_google_login'] ) ) { | |
| 269 | - return; | |
| 270 | - } | |
| 271 | - | |
| 272 | - $redirect_url = remove_query_arg( [ 'templately_google_login', 'api_key', 'error', 'state', 'redirect-to' ] ); | |
| 273 | - | |
| 274 | - if ( ! empty( $_GET['error'] ) ) { | |
| 275 | - $error_message = sanitize_text_field( $_GET['error'] ); | |
| 276 | - } elseif ( ! empty( $_GET['api_key'] ) ) { | |
| 277 | - $request = new \WP_REST_Request( 'POST', '/templately/v1/login' ); | |
| 278 | - $request->set_param( 'viaAPI', true ); | |
| 279 | - $request->set_param( 'api_key', sanitize_text_field( $_GET['api_key'] ) ); | |
| 280 | - | |
| 281 | - /** | |
| 282 | - * @var Login $login | |
| 283 | - */ | |
| 284 | - $login = Login::get_instance(); | |
| 285 | - $login->permission_check( $request ); | |
| 286 | - $response = $login->login(); | |
| 287 | - | |
| 288 | - if ( ! is_wp_error( $response ) && ! empty( $response['user'] ) ) { | |
| 289 | - $redirect_path = ! empty( $_GET['redirect-to'] ) ? sanitize_text_field( wp_unslash( $_GET['redirect-to'] ) ) : ''; | |
| 290 | - if ( ! empty( $redirect_path ) ) { | |
| 291 | - if ( filter_var( $redirect_path, FILTER_VALIDATE_URL ) ) { | |
| 292 | - $redirect_url = $redirect_path; | |
| 293 | - } else { | |
| 294 | - $is_templately = strpos( $redirect_url, 'page=templately' ) !== false; | |
| 295 | - $is_elementor = strpos( $redirect_url, 'action=elementor' ) !== false; | |
| 296 | - // Gutenberg editor usually has action=edit or is a block editor page | |
| 297 | - $is_gutenberg = ( strpos( $redirect_url, 'action=edit' ) !== false || strpos( $redirect_url, 'post_type=' ) !== false ) && ! $is_elementor; | |
| 298 | - | |
| 299 | - if ( $is_templately || $is_elementor || $is_gutenberg ) { | |
| 300 | - $redirect_url = add_query_arg( 'path', ltrim( $redirect_path, '/' ), $redirect_url ); | |
| 301 | - | |
| 302 | - // Always open the modal in editors after google login | |
| 303 | - if ( $is_elementor || $is_gutenberg ) { | |
| 304 | - $redirect_url = add_query_arg( 'templately_open_modal', '1', $redirect_url ); | |
| 305 | - } | |
| 306 | - } | |
| 307 | - } | |
| 308 | - } | |
| 309 | - | |
| 310 | - wp_safe_redirect( $redirect_url ); | |
| 311 | - exit; | |
| 312 | - } else { | |
| 313 | - $error_message = ( is_wp_error( $response ) ) ? $response->get_error_message() : __( 'Login failed.', 'templately' ); | |
| 314 | - } | |
| 315 | - } else { | |
| 316 | - $error_message = __( 'Missing API Key.', 'templately' ); | |
| 317 | - } | |
| 318 | - | |
| 319 | - $redirect_url = add_query_arg( [ | |
| 320 | - 'templately_error' => 'login_failed', | |
| 321 | - 'error_message' => urlencode( $error_message ), | |
| 322 | - ], $redirect_url ); | |
| 323 | - | |
| 324 | - wp_safe_redirect( $redirect_url ); | |
| 325 | - exit; | |
| 326 | 187 | } |
| 327 | 188 | } |