| @@ -1,11 +1,11 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | /** |
| 4 | - * Plugin Name: Timetics | |
| 4 | + * Plugin Name: Timetics - Appointment Booking Calendar & Scheduling System | |
| 5 | 5 | * Plugin URI: https://arraytics.com/timetics/ |
| 6 | 6 | * Description: Schedule, Appointment and Seat Booking plugin. |
| 7 | - * Version: 1.0.2 | |
| 7 | + * Version: 1.0.64 | |
| 8 | 8 | * Requires at least: 5.2 |
| 9 | 9 | * Requires PHP: 7.3 |
| 10 | 10 | * Author: Arraytics |
| 11 | 11 | * Author URI: https://arraytics.com/ |
| @@ -29,13 +29,13 @@ | ||
| 29 | 29 | * |
| 30 | 30 | * @package Timetics |
| 31 | 31 | * @category Core |
| 32 | 32 | * @author Arraytics |
| 33 | - * @version 1.0.0 | |
| 33 | + * @version 1.0.10 | |
| 34 | 34 | */ |
| 35 | 35 | |
| 36 | 36 | // Exit if accessed directly. |
| 37 | -defined('ABSPATH') || exit; | |
| 37 | +defined( 'ABSPATH' ) || exit; | |
| 38 | 38 | |
| 39 | 39 | /** |
| 40 | 40 | * The Main Plugin Requirements Checker |
| 41 | 41 | * |
| @@ -40,10 +40,9 @@ | ||
| 40 | 40 | * The Main Plugin Requirements Checker |
| 41 | 41 | * |
| 42 | 42 | * @since 1.0.0 |
| 43 | 43 | */ |
| 44 | -final class Timetics | |
| 45 | -{ | |
| 44 | +final class Timetics { | |
| 46 | 45 | |
| 47 | 46 | /** |
| 48 | 47 | * Static Property To Hold Singleton Instance |
| 49 | 48 | * |
| @@ -55,11 +54,10 @@ | ||
| 55 | 54 | * Plugin Current Production Version |
| 56 | 55 | * |
| 57 | 56 | * @return string |
| 58 | 57 | */ |
| 59 | - public static function get_version() | |
| 60 | - { | |
| 61 | - return '1.0.2'; | |
| 58 | + public static function get_version() { | |
| 59 | + return '1.0.64'; | |
| 62 | 60 | } |
| 63 | 61 | |
| 64 | 62 | /** |
| 65 | 63 | * Requirements Array |
| @@ -90,11 +88,10 @@ | ||
| 90 | 88 | * Singleton Instance |
| 91 | 89 | * |
| 92 | 90 | * @return Timetics |
| 93 | 91 | */ |
| 94 | - public static function get_instance() | |
| 95 | - { | |
| 96 | - if (null === self::$instance) { | |
| 92 | + public static function get_instance() { | |
| 93 | + if ( null === self::$instance ) { | |
| 97 | 94 | self::$instance = new self(); |
| 98 | 95 | } |
| 99 | 96 | |
| 100 | 97 | return self::$instance; |
| @@ -104,12 +101,11 @@ | ||
| 104 | 101 | * Setup Plugin Requirements |
| 105 | 102 | * |
| 106 | 103 | * @since 1.0.0 |
| 107 | 104 | */ |
| 108 | - private function __construct() | |
| 109 | - { | |
| 105 | + private function __construct() { | |
| 110 | 106 | // Always load translation. |
| 111 | - add_action('plugins_loaded', array($this, 'load_text_domain')); | |
| 107 | + add_action( 'init', array( $this, 'load_text_domain' ) ); | |
| 112 | 108 | |
| 113 | 109 | // Initialize plugin functionalities or quit. |
| 114 | 110 | $this->requirements_met() ? $this->initialize_modules() : $this->quit(); |
| 115 | 111 | } |
| @@ -119,15 +115,32 @@ | ||
| 119 | 115 | * |
| 120 | 116 | * @since 1.0 |
| 121 | 117 | * @return void |
| 122 | 118 | */ |
| 123 | - public function load_text_domain() | |
| 124 | - { | |
| 125 | - $locale = apply_filters('plugin_locale', get_user_locale(), 'timetics'); | |
| 119 | + public function load_text_domain() { | |
| 120 | + $locale = determine_locale(); | |
| 121 | + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- WordPress core localization hook. | |
| 122 | + $locale = apply_filters( 'plugin_locale', $locale, 'timetics' ); | |
| 123 | + $locale = apply_filters( 'timetics_plugin_locale', $locale, 'timetics' ); | |
| 126 | 124 | |
| 127 | - unload_textdomain('timetics'); | |
| 128 | - load_textdomain('timetics', WP_LANG_DIR . '/timetics/timetics-' . $locale . '.mo'); | |
| 129 | - load_plugin_textdomain('timetics', false, self::get_plugin_dir() . 'languages/'); | |
| 125 | + $mofile = 'timetics-' . $locale . '.mo'; | |
| 126 | + | |
| 127 | + // Loco "Custom" location. | |
| 128 | + if ( file_exists( WP_LANG_DIR . '/loco/plugins/' . $mofile ) ) { | |
| 129 | + load_textdomain( 'timetics', WP_LANG_DIR . '/loco/plugins/' . $mofile ); | |
| 130 | + } | |
| 131 | + | |
| 132 | + // Loco "System" location. | |
| 133 | + if ( file_exists( WP_LANG_DIR . '/plugins/' . $mofile ) ) { | |
| 134 | + load_textdomain( 'timetics', WP_LANG_DIR . '/plugins/' . $mofile ); | |
| 135 | + } | |
| 136 | + | |
| 137 | + // Bundled translations remain available while WordPress loads language | |
| 138 | + // packs for this text domain automatically. | |
| 139 | + $bundled_mofile = plugin_dir_path( __FILE__ ) . 'languages/' . $mofile; | |
| 140 | + if ( file_exists( $bundled_mofile ) ) { | |
| 141 | + load_textdomain( 'timetics', $bundled_mofile ); | |
| 142 | + } | |
| 130 | 143 | } |
| 131 | 144 | |
| 132 | 145 | /** |
| 133 | 146 | * Initialize Plugin Modules |
| @@ -134,28 +147,34 @@ | ||
| 134 | 147 | * |
| 135 | 148 | * @since 1.0.0 |
| 136 | 149 | * @return void |
| 137 | 150 | */ |
| 138 | - private function initialize_modules() | |
| 139 | - { | |
| 140 | - require_once dirname(__FILE__) . '/autoloader.php'; | |
| 141 | - require_once dirname(__FILE__) . '/core/settings/settings.php'; | |
| 151 | + private function initialize_modules() { | |
| 152 | + require_once dirname( __FILE__ ) . '/autoloader.php'; | |
| 153 | + require_once dirname( __FILE__ ) . '/core/settings/settings.php'; | |
| 142 | 154 | |
| 143 | - require_once dirname(__FILE__) . '/utils/global-helper.php'; | |
| 155 | + require_once dirname( __FILE__ ) . '/utils/global-helper.php'; | |
| 144 | 156 | |
| 157 | + // block for showing banner. | |
| 158 | + require_once plugin_dir_path( __FILE__ ) . '/utils/notice/notice.php'; | |
| 159 | + require_once plugin_dir_path( __FILE__ ) . '/utils/banner/banner.php'; | |
| 160 | + | |
| 145 | 161 | // Include the bootstrap file if not loaded. |
| 146 | - if (!class_exists('Timetics\Bootstrap')) { | |
| 162 | + if ( ! class_exists( 'Timetics\Bootstrap' ) ) { | |
| 147 | 163 | require_once self::get_plugin_dir() . 'bootstrap.php'; |
| 148 | 164 | } |
| 149 | 165 | |
| 166 | + // init notice class. | |
| 167 | + \Oxaim\Libs\Notice::init(); | |
| 168 | + | |
| 150 | 169 | // Initialize the bootstraper if exists. |
| 151 | - if (class_exists('Timetics\Bootstrap')) { | |
| 170 | + if ( class_exists( 'Timetics\Bootstrap' ) ) { | |
| 152 | 171 | |
| 153 | 172 | // Initialize all modules through plugins_loaded. |
| 154 | - add_action('plugins_loaded', array($this, 'init')); | |
| 173 | + add_action( 'plugins_loaded', array( $this, 'init' ) ); | |
| 155 | 174 | |
| 156 | - register_activation_hook(self::get_plugin_file(), array($this, 'activate')); | |
| 157 | - register_deactivation_hook(self::get_plugin_file(), array($this, 'deactivate')); | |
| 175 | + register_activation_hook( self::get_plugin_file(), array( $this, 'activate' ) ); | |
| 176 | + register_deactivation_hook( self::get_plugin_file(), array( $this, 'deactivate' ) ); | |
| 158 | 177 | } |
| 159 | 178 | } |
| 160 | 179 | |
| 161 | 180 | /** |
| @@ -162,17 +181,16 @@ | ||
| 162 | 181 | * Check If All Requirements Are Fulfilled |
| 163 | 182 | * |
| 164 | 183 | * @return boolean |
| 165 | 184 | */ |
| 166 | - private function requirements_met() | |
| 167 | - { | |
| 185 | + private function requirements_met() { | |
| 168 | 186 | $this->prepare_requirement_versions(); |
| 169 | 187 | |
| 170 | 188 | $passed = true; |
| 171 | - $to_meet = wp_list_pluck($this->requirements, 'met'); | |
| 189 | + $to_meet = wp_list_pluck( $this->requirements, 'met' ); | |
| 172 | 190 | |
| 173 | - foreach ($to_meet as $met) { | |
| 174 | - if (empty($met)) { | |
| 191 | + foreach ( $to_meet as $met ) { | |
| 192 | + if ( empty( $met ) ) { | |
| 175 | 193 | $passed = false; |
| 176 | 194 | continue; |
| 177 | 195 | } |
| 178 | 196 | } |
| @@ -186,26 +204,25 @@ | ||
| 186 | 204 | * @since 1.0.0 |
| 187 | 205 | * |
| 188 | 206 | * @return void |
| 189 | 207 | */ |
| 190 | - private function prepare_requirement_versions() | |
| 191 | - { | |
| 192 | - foreach ($this->requirements as $dependency => $config) { | |
| 193 | - switch ($dependency) { | |
| 194 | - case 'php': | |
| 195 | - $version = phpversion(); | |
| 196 | - break; | |
| 197 | - case 'wp': | |
| 198 | - $version = get_bloginfo('version'); | |
| 199 | - break; | |
| 200 | - default: | |
| 201 | - $version = false; | |
| 208 | + private function prepare_requirement_versions() { | |
| 209 | + foreach ( $this->requirements as $dependency => $config ) { | |
| 210 | + switch ( $dependency ) { | |
| 211 | + case 'php': | |
| 212 | + $version = phpversion(); | |
| 213 | + break; | |
| 214 | + case 'wp': | |
| 215 | + $version = get_bloginfo( 'version' ); | |
| 216 | + break; | |
| 217 | + default: | |
| 218 | + $version = false; | |
| 202 | 219 | } |
| 203 | 220 | |
| 204 | - if (!empty($version)) { | |
| 221 | + if ( ! empty( $version ) ) { | |
| 205 | 222 | $this->requirements[$dependency]['current'] = $version; |
| 206 | 223 | $this->requirements[$dependency]['checked'] = true; |
| 207 | - $this->requirements[$dependency]['met'] = version_compare($version, $config['minimum'], '>='); | |
| 224 | + $this->requirements[$dependency]['met'] = version_compare( $version, $config['minimum'], '>=' ); | |
| 208 | 225 | } |
| 209 | 226 | } |
| 210 | 227 | } |
| 211 | 228 | |
| @@ -215,11 +232,66 @@ | ||
| 215 | 232 | * @since 1.0.0 |
| 216 | 233 | * |
| 217 | 234 | * @return void |
| 218 | 235 | */ |
| 219 | - public function init() | |
| 220 | - { | |
| 221 | - Timetics\Bootstrap::instantiate(self::get_plugin_file()); | |
| 236 | + public function init() { | |
| 237 | + Timetics\Bootstrap::instantiate( self::get_plugin_file() ); | |
| 238 | + | |
| 239 | + // Add autoload from composer for integrating uninstallation form | |
| 240 | + if (file_exists(plugin_dir_path( __FILE__ ) . '/vendor/autoload.php')) { | |
| 241 | + require_once plugin_dir_path( __FILE__ ) . '/vendor/autoload.php'; | |
| 242 | + } | |
| 243 | + | |
| 244 | + if (class_exists('UninstallerForm\UninstallerForm') && is_callable(['\UninstallerForm\UninstallerForm', 'init'])) { | |
| 245 | + | |
| 246 | + $reflection = new ReflectionMethod('\UninstallerForm\UninstallerForm', 'init'); | |
| 247 | + | |
| 248 | + // Maximum number of parameters allowed | |
| 249 | + $totalParams = $reflection->getNumberOfParameters(); | |
| 250 | + | |
| 251 | + if($totalParams === 6) { | |
| 252 | + add_filter( 'rest_request_before_callbacks', function( $response, $handler, $request ) { | |
| 253 | + if ( $request->get_route() === '/timetics/v1/feedback' ) { | |
| 254 | + $params = $request->get_json_params(); | |
| 255 | + | |
| 256 | + if ( empty( $params['email'] ) ) { | |
| 257 | + $params['email'] = get_option( 'admin_email' ); | |
| 258 | + $request->set_body( wp_json_encode( $params ) ); | |
| 259 | + } | |
| 260 | + } | |
| 261 | + return $response; | |
| 262 | + }, 10, 3 ); | |
| 263 | + | |
| 264 | + \UninstallerForm\UninstallerForm::init( | |
| 265 | + 'Timetics', // Plugin name | |
| 266 | + 'timetics', // Plugin Slug | |
| 267 | + __FILE__, | |
| 268 | + 'timetics', // Text Domain Name | |
| 269 | + 'timetics-feedback-modal', // plugins-admin-script-handler | |
| 270 | + 'https://arraytics.com/?fluentcrm=1&route=contact&hash=13cce8a6-c038-4997-91e7-4a2326cc1124' | |
| 271 | + ); | |
| 272 | + } else { | |
| 273 | + add_filter( 'rest_request_before_callbacks', function( $response, $handler, $request ) { | |
| 274 | + if ( $request->get_route() === '/timetics/v1/feedback' ) { | |
| 275 | + $params = $request->get_json_params(); | |
| 276 | + | |
| 277 | + if ( empty( $params['email'] ) ) { | |
| 278 | + $params['email'] = get_option( 'admin_email' ); | |
| 279 | + $request->set_body( wp_json_encode( $params ) ); | |
| 280 | + } | |
| 281 | + } | |
| 282 | + return $response; | |
| 283 | + }, 10, 3 ); | |
| 284 | + | |
| 285 | + \UninstallerForm\UninstallerForm::init( | |
| 286 | + 'Timetics', // Plugin name | |
| 287 | + 'timetics', // Plugin Slug | |
| 288 | + __FILE__, | |
| 289 | + 'timetics', // Text Domain Name | |
| 290 | + 'timetics-feedback-modal' | |
| 291 | + ); | |
| 292 | + } | |
| 293 | + } | |
| 222 | 294 | } |
| 223 | 295 | |
| 224 | 296 | /** |
| 225 | 297 | * Called Only Once While Activation |
| @@ -225,10 +297,9 @@ | ||
| 225 | 297 | * Called Only Once While Activation |
| 226 | 298 | * |
| 227 | 299 | * @return void |
| 228 | 300 | */ |
| 229 | - public function activate() | |
| 230 | - { | |
| 301 | + public function activate() { | |
| 231 | 302 | // Insert new role. |
| 232 | 303 | Timetics\Base\Role::instance()->init(); |
| 233 | 304 | |
| 234 | 305 | // Update default settings. |
| @@ -235,8 +306,29 @@ | ||
| 235 | 306 | timetics_update_default_settings(); |
| 236 | 307 | |
| 237 | 308 | // Register cron |
| 238 | 309 | timetics_register_cron(); |
| 310 | + | |
| 311 | + // Create new woocommerce product category for timetics meeting | |
| 312 | + timetics_add_woocommerce_product_cat(); | |
| 313 | + | |
| 314 | + // Force rewrite-rule flush on activation; the maybe_flush_rules guard handles subsequent upgrades. | |
| 315 | + delete_option( 'timetics_rewrite_version' ); | |
| 316 | + | |
| 317 | + // Update option for onboard settings. | |
| 318 | + $timetics_onboard_setup = get_option( 'timetics_onboard_setup' ); | |
| 319 | + | |
| 320 | + $timetics_demo_data = get_option( 'timetics_demo_data' ); | |
| 321 | + | |
| 322 | + if ( ! $timetics_demo_data ) { | |
| 323 | + $dummy_data_generator = new Timetics\Core\DummyData\Dummy_Data_Generator(); | |
| 324 | + $dummy_data_generator->generate(); | |
| 325 | + update_option( 'timetics_demo_data', true ); | |
| 326 | + } | |
| 327 | + | |
| 328 | + if ( ! $timetics_onboard_setup ) { | |
| 329 | + update_option( 'timetics_onboard_settings', true ); | |
| 330 | + } | |
| 239 | 331 | } |
| 240 | 332 | |
| 241 | 333 | /** |
| 242 | 334 | * Called Only Once While Deactivation |
| @@ -242,10 +334,10 @@ | ||
| 242 | 334 | * Called Only Once While Deactivation |
| 243 | 335 | * |
| 244 | 336 | * @return void |
| 245 | 337 | */ |
| 246 | - public function deactivate() | |
| 247 | - { | |
| 338 | + public function deactivate() { | |
| 339 | + wp_clear_scheduled_hook( 'timetics_cleanup_unpaid_bookings' ); | |
| 248 | 340 | } |
| 249 | 341 | |
| 250 | 342 | /** |
| 251 | 343 | * Quit Plugin Execution |
| @@ -251,11 +343,10 @@ | ||
| 251 | 343 | * Quit Plugin Execution |
| 252 | 344 | * |
| 253 | 345 | * @return void |
| 254 | 346 | */ |
| 255 | - private function quit() | |
| 256 | - { | |
| 257 | - add_action('admin_head', array($this, 'show_plugin_requirements_not_met_notice')); | |
| 347 | + private function quit() { | |
| 348 | + add_action( 'admin_head', array( $this, 'show_plugin_requirements_not_met_notice' ) ); | |
| 258 | 349 | } |
| 259 | 350 | |
| 260 | 351 | /** |
| 261 | 352 | * Show Error Notice For Missing Requirements |
| @@ -261,11 +352,10 @@ | ||
| 261 | 352 | * Show Error Notice For Missing Requirements |
| 262 | 353 | * |
| 263 | 354 | * @return void |
| 264 | 355 | */ |
| 265 | - public function show_plugin_requirements_not_met_notice() | |
| 266 | - { | |
| 267 | - printf('<div>Minimum requirements for Timetics are not met. Please update requirements to continue.</div>'); | |
| 356 | + public function show_plugin_requirements_not_met_notice() { | |
| 357 | + printf( '<div>Minimum requirements for Timetics are not met. Please update requirements to continue.</div>' ); | |
| 268 | 358 | } |
| 269 | 359 | |
| 270 | 360 | /** |
| 271 | 361 | * Plugin Main File |
| @@ -271,10 +361,9 @@ | ||
| 271 | 361 | * Plugin Main File |
| 272 | 362 | * |
| 273 | 363 | * @return string |
| 274 | 364 | */ |
| 275 | - public static function get_plugin_file() | |
| 276 | - { | |
| 365 | + public static function get_plugin_file() { | |
| 277 | 366 | return __FILE__; |
| 278 | 367 | } |
| 279 | 368 | |
| 280 | 369 | /** |
| @@ -281,11 +370,38 @@ | ||
| 281 | 370 | * Plugin Base Directory Path |
| 282 | 371 | * |
| 283 | 372 | * @return string |
| 284 | 373 | */ |
| 285 | - public static function get_plugin_dir() | |
| 286 | - { | |
| 287 | - return trailingslashit(plugin_dir_path(self::get_plugin_file())); | |
| 374 | + public static function get_plugin_dir() { | |
| 375 | + return trailingslashit( plugin_dir_path( self::get_plugin_file() ) ); | |
| 288 | 376 | } |
| 289 | 377 | } |
| 378 | + | |
| 379 | +/** | |
| 380 | + * Add a "Go Pro" action link on the Plugins page. | |
| 381 | + * Hidden when the pro plugin already exists. | |
| 382 | + */ | |
| 383 | +if ( ! function_exists( 'timetics_add_go_pro_action_link' ) ) { | |
| 384 | + function timetics_add_go_pro_action_link( $links ) { | |
| 385 | + if ( ! function_exists( 'get_plugins' ) ) { | |
| 386 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; | |
| 387 | + } | |
| 388 | + | |
| 389 | + foreach ( get_plugins() as $plugin ) { | |
| 390 | + if ( isset( $plugin['TextDomain'] ) && 'timetics-pro' === $plugin['TextDomain'] ) { | |
| 391 | + return $links; | |
| 392 | + } | |
| 393 | + } | |
| 394 | + | |
| 395 | + $go_pro = sprintf( | |
| 396 | + '<a href="%1$s" target="_blank" rel="noopener noreferrer" style="color:#e8364c;font-weight:600;">%2$s</a>', | |
| 397 | + esc_url( 'https://arraytics.com/timetics/pricing/' ), | |
| 398 | + esc_html__( 'Go Pro', 'timetics' ) | |
| 399 | + ); | |
| 400 | + | |
| 401 | + $links[] = $go_pro; | |
| 402 | + return $links; | |
| 403 | + } | |
| 404 | +} | |
| 405 | +add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'timetics_add_go_pro_action_link' ); | |
| 290 | 406 | |
| 291 | 407 | Timetics::get_instance(); |