boot.php 30 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865
<?php

namespace uncanny_pro_toolkit;

use uncanny_learndash_toolkit as toolkit;

class Boot extends toolkit\Config {

	/**
	 * class constructor
	 */
	public function __construct() {

		global $uncanny_pro_toolkit;

		if ( ! isset( $uncanny_pro_toolkit ) ) {
			$uncanny_pro_toolkit = new \stdClass();
		}

		// We need to check if spl auto loading is available when activating plugin
		// Plugin will not activate if SPL extension is not enabled by throwing error
		if ( ! extension_loaded( 'SPL' ) ) {
			$spl_error = esc_html__( 'Please contact your hosting company to update to php version 5.3+ and enable spl extensions.', 'uncanny-pro-toolkit' );
			trigger_error( $spl_error, E_USER_ERROR );
		}

		spl_autoload_register( array( __CLASS__, 'auto_loader' ) );


		// Class Details:  Add Class to Admin Menu page
		$classes = self::get_active_classes();

		// Import Gutenberg Blocks
		require_once( UNCANNY_TOOLKIT_PRO_PATH. 'src/blocks/blocks.php' );
		new Blocks( UNCANNY_TOOLKIT_PRO_PREFIX, UNCANNY_TOOLKIT_PRO_VERSION, $classes );

		if ( $classes ) {
			foreach ( self::get_active_classes() as $class ) {

				// Some wp installs remove slashes during db calls, being extra safe when comparing DB vs php values
				if ( strpos( $class, '\\' ) === false ) {
					$class = str_replace( 'pro_toolkit', 'pro_toolkit\\', $class );
				}

				$class_namespace = explode( '\\', $class );

				if ( class_exists( $class ) && __NAMESPACE__ === $class_namespace[0] ) {
					new $class;
				}

			}
		}

		/* Licensing */

		// URL of store powering the plugin
		define( 'UO_STORE_URL', 'https://www.uncannyowl.com/' ); // you should use your own CONSTANT name, and be sure to replace it throughout this file

		// Store download name/title
		define( 'UO_ITEM_NAME', 'Uncanny LearnDash Toolkit Pro' ); // you should use your own CONSTANT name, and be sure to replace it throughout this file

		// the name of the settings page for the license input to be displayed
		define( 'UO_LICENSE_PAGE', 'uncanny-toolkit-license' );

		// include updater
		$updater = self::get_include( 'EDD_SL_Plugin_Updater.php', __FILE__ );
		include_once( $updater );

		add_action( 'admin_init', array( __CLASS__, 'uo_plugin_updater' ), 0 );
		add_action( 'admin_menu', array( __CLASS__, 'uo_license_menu' ) );
		add_action( 'admin_init', array( __CLASS__, 'uo_activate_license' ) );
		add_action( 'admin_init', array( __CLASS__, 'uo_deactivate_license' ) );
		add_action( 'admin_notices', array( __CLASS__, 'uo_admin_notices' ) );
		add_action( 'admin_enqueue_scripts', array( __CLASS__, 'uo_license_css' ) );

		add_action( 'wp_enqueue_scripts', array( __CLASS__, 'uo_enqueue_frontend_assets' ) );
		add_action( 'admin_enqueue_scripts', array( __CLASS__, 'uo_enqueue_backend_assets' ) );

		// Register the endpoint to hide the "Try Automator"
		add_action( 'rest_api_init', array( __CLASS__, 'try_automator_rest_register' ) );
		// Evaluate the visibility of the "Try Automator" item
		add_filter( 'ult_admin_sidebar_try_automator_add', array(
			__CLASS__,
			'try_automator_evaluate_visibility'
		), 100 );
		// Modify the inner html of the "Try Automator! admin item"
		add_filter( 'ult_admin_sidebar_try_automator_inner_html', array( __CLASS__, 'try_automator_add_x_icon' ) );
	}

	public static function uo_license_css() {
		$style_url = plugins_url( basename( dirname( UO_FILE ) ) ) . '/src/assets/legacy/backend/css/license.css';
		wp_enqueue_style( 'uo-license-css', $style_url, false, UNCANNY_TOOLKIT_PRO_VERSION );
	}


	public static function uo_plugin_updater() {

		// retrieve our license key from the DB
		$license_key = trim( get_option( 'uo_license_key' ) );

		// setup the updater
		$uo_updater = new EDD_SL_Plugin_Updater( UO_STORE_URL, UO_FILE, array(

			'version'   => UNCANNY_TOOLKIT_PRO_VERSION,     // current version number
			'license'   => $license_key,                    // license key (used get_option above to retrieve from DB)
			'item_name' => UO_ITEM_NAME,                    // name of this plugin
			'author'    => 'Uncanny Owl',                   // author of this plugin
			'beta'      => false

		) );

	}

	// Licence options page
	public static function uo_license_menu() {
		add_submenu_page( 'uncanny-toolkit', 'Uncanny Pro License Activation', 'License Activation', 'manage_options', UO_LICENSE_PAGE, array(
			__CLASS__,
			'uo_license_page'
		) );
	}

	public static function uo_license_page() {

		// retrieve the license from the database
		$license = trim( get_option( 'uo_license_key' ) );


		// data to send in our API request
		$api_params = array(
			'edd_action' => 'check_license',
			'license'    => $license,
			'item_name'  => urlencode( UO_ITEM_NAME ), // the name of our product in uo
			'url'        => home_url()
		);

		// Call the custom API.
		$response = wp_remote_post( UO_STORE_URL, array(
			'timeout'   => 15,
			'sslverify' => false,
			'body'      => $api_params
		) );

		// make sure the response came back okay
		if ( is_wp_error( $response ) ) {
			return false;
		}

		// decode the license data
		$license_data = json_decode( wp_remote_retrieve_body( $response ) );

		if ( 'valid' !== $license_data->license ) {
			// $license_data->license will be either "valid", "invalid", "expired", "disabled", or "inactive"
			update_option( 'uo_license_status', $license_data->license );
		}

		// $license_data->license_check will be either "valid", "invalid", "expired", "disabled", or "inactive"
		update_option( 'uo_license_check', $license_data->license );

		// Get data
		$status        = get_option( 'uo_license_status' ); // $license_data->license will be either "valid", "invalid", "expired", "disabled"
		$license_check = get_option( 'uo_license_check' ); // $license_data->license_check will be either

		/**
		 * Possible values for $status
		 *
		 * {bool}    false     Empty, never saved
		 * {string}  valid       The License is valid
		 * {string}  expired   The License has expired
		 * {string}  invalid   The license is invalid
		 * {string}  inactive  The license has been disabled
		 */

		// Check license status
		$license_is_active = $status == 'valid' ? true : false;

		// CSS Classes
		$css_classes = array();

		if ( $license_is_active ) {
			$css_classes[] = 'uo-license--active';
		}

		// Set links. Add UTM parameters at the end of each URL
		$where_to_get_my_license = 'https://www.uncannyowl.com/plugin-frequently-asked-questions/#licensekey';
		$buy_new_license         = 'https://www.uncannyowl.com/downloads/uncanny-learndash-toolkit-pro/';
		$knowledge_base          = menu_page_url( 'uncanny-toolkit-kb', false );

		if ( class_exists( '\uncanny_learndash_toolkit\Config' ) && method_exists( '\uncanny_learndash_toolkit\Config', 'utm_parameters' ) ){
			$where_to_get_my_license = \uncanny_learndash_toolkit\Config::utm_parameters( $where_to_get_my_license, 'license-activation', 'where-to-get-license' );
			$buy_new_license         = \uncanny_learndash_toolkit\Config::utm_parameters( $buy_new_license, 'license-activation', 'buy-license-button' );
		}

		?>

        <div class="wrap"> <!-- WP container -->
            <div class="uo-plugins-header">
                <div class="uo-plugins-header__title">
                    Uncanny Toolkit for LearnDash
                </div>
                <div class="uo-plugins-header__author">
                    <span><?php esc_attr_e( 'by', 'uncanny-pro-toolkit' ); ?></span>
                    <a href="https://uncannyowl.com" target="_blank" class="uo-plugins-header__logo">
                        <img src="<?php echo esc_url( \uncanny_learndash_toolkit\Config::get_admin_media( 'uncanny-owl-logo.svg' ) ); ?>"
                             alt="Uncanny Owl">
                    </a>
                </div>
            </div>

            <div id="poststuff"> <!-- WP container -->

                <h1 class="nav-tab-wrapper">
                    <a href="?page=uncanny-toolkit"
                       class="nav-tab"><?php esc_attr_e( 'Modules', 'uncanny-pro-toolkit' ); ?></a>
                    <a href="?page=uncanny-toolkit-kb"
                       class="nav-tab"><?php esc_attr_e( 'Help', 'uncanny-pro-toolkit' ); ?></a>
                    <a href="?page=uncanny-toolkit-plugins"
                       class="nav-tab"><?php esc_attr_e( 'LearnDash Plugins', 'uncanny-pro-toolkit' ); ?></a>
                    <a href="?page=uncanny-toolkit-license"
                       class="nav-tab nav-tab-active"><?php esc_attr_e( 'License Activation', 'uncanny-pro-toolkit' ); ?></a>
                </h1>

                <div class="uo-license <?php echo implode( ' ', $css_classes ); ?>">
                    <div class="uo-license-status">
                        <div class="uo-license-status__icon">

							<?php if ( $license_is_active ) { ?>

                                <svg class="uo-license-status-icon__svg" xmlns="http://www.w3.org/2000/svg"
                                     xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 512 512">
                                    <path class="uo-license-status-icon__svg-path uo-license-status-icon__svg-check"
                                          d="M173.898 439.404l-166.4-166.4c-9.997-9.997-9.997-26.206 0-36.204l36.203-36.204c9.997-9.998 26.207-9.998 36.204 0L192 312.69 432.095 72.596c9.997-9.997 26.207-9.997 36.204 0l36.203 36.204c9.997 9.997 9.997 26.206 0 36.204l-294.4 294.401c-9.998 9.997-26.207 9.997-36.204-.001z"></path>
                                </svg>

							<?php } else { ?>

                                <svg class="uo-license-status-icon__svg" xmlns="http://www.w3.org/2000/svg"
                                     xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 352 512">
                                    <path class="uo-license-status-icon__svg-path uo-license-status-icon__svg-times"
                                          d="M242.72 256l100.07-100.07c12.28-12.28 12.28-32.19 0-44.48l-22.24-22.24c-12.28-12.28-32.19-12.28-44.48 0L176 189.28 75.93 89.21c-12.28-12.28-32.19-12.28-44.48 0L9.21 111.45c-12.28 12.28-12.28 32.19 0 44.48L109.28 256 9.21 356.07c-12.28 12.28-12.28 32.19 0 44.48l22.24 22.24c12.28 12.28 32.2 12.28 44.48 0L176 322.72l100.07 100.07c12.28 12.28 32.2 12.28 44.48 0l22.24-22.24c12.28-12.28 12.28-32.19 0-44.48L242.72 256z"></path>
                                </svg>

							<?php } ?>

                        </div>
                    </div>
                    <div class="uo-license-content">

                        <form class="uo-license-content-form" method="POST" action="options.php">

							<?php settings_fields( 'uo_license' ); ?>

							<?php wp_nonce_field( 'uo_nonce', 'uo_nonce' ); ?>

                            <div class="uo-license-content-top">
                                <div class="uo-license-content-info">

									<?php ?>

                                    <div class="uo-license-content-title">

										<?php

										if ( $license_is_active ) {
											_e( 'Your license is active!', 'uncanny-pro-toolkit' );
										} else {
											_e( 'Your license is not active!', 'uncanny-pro-toolkit' );
										}

										?>
                                    </div>

                                    <div class="uo-license-content-description">

										<?php

										switch ( $license_check ) {
											case 'valid':
												break;

											case 'empty':
												_e( 'Please enter a valid license code and click "Activate now".', 'uncanny-pro-toolkit' );
												break;

											case 'expired':
												printf(
													_x(
														'Your license has expired. Please %s to get instant access to updates and support.',
														'Your license has expired. Please renew your license to get instant access to updates and support.',
														'uncanny-pro-toolkit'
													),
													sprintf(
														'<a href="%s" target="_blank">%s</a>',
														'https://www.uncannyowl.com/checkout/?edd_license_key=' . $license . '&download_id=1377',
														_x(
															'renew your license',
															'Your license has expired. Please renew your license to get instant access to updates and support.',
															'uncanny-pro-toolkit' )
													)
												);
												break;

											case 'disabled':
												printf(
													_x( 'Your license is disabled. Please %s to get instant access to updates and support.',
														'Your license has disabled. Please renew your license to get instant access to updates and support.',
														'uncanny-pro-toolkit' ),
													sprintf(
														'<a href="%s" target="_blank">%s</a>',
														'https://www.uncannyowl.com/checkout/?edd_license_key=' . $license . '&download_id=1377',
														_x( 'renew your license',
															'Your license has expired. Please renew your license to get instant access to updates and support.',
															'uncanny-pro-toolkit' )
													)
												);
												break;

											case 'invalid':
											case 'inactive':
												_e( 'The license code you entered is invalid.', 'uncanny-pro-toolkit' );
												break;
										}

										?>

                                    </div>

                                    <div class="uo-license-content-form">

										<?php if ( $license_is_active ) { ?>

                                            <input id="uo-license-field" name="uo_license_key"
                                                   type="password" value="<?php echo esc_attr( $license ); ?>"
                                                   placeholder="<?php esc_attr_e( 'Enter your Uncanny Toolkit Pro for LearnDash license key', 'uncanny-pro-toolkit' ); ?>"
                                                   required>

										<?php } else { ?>

                                            <input id="uo-license-field" name="uo_license_key" type="text"
                                                   value="<?php echo esc_attr( $license ); ?>"
                                                   placeholder="<?php esc_attr_e( 'Enter your Uncanny Toolkit Pro for LearnDash license key', 'uncanny-pro-toolkit' ); ?>"
                                                   required>

										<?php } ?>

                                    </div>

                                    <div class="uo-license-content-mobile-buttons">

										<?php if ( $license_is_active ) { ?>

                                            <button type="submit" name="uo_license_deactivate"
                                                    class="uo-license-btn uo-license-btn--error">
												<?php esc_attr_e( 'Deactivate License', 'uncanny-pro-toolkit' ); ?>
                                            </button>

										<?php } else { ?>

                                            <button type="submit" name="uo_license_activate"
                                                    class="uo-license-btn uo-license-btn--primary">
												<?php esc_attr_e( 'Activate now', 'uncanny-pro-toolkit' ); ?>
                                            </button>

                                            <a href="<?php echo $buy_new_license; ?>" target="_blank"
                                               class="uo-license-btn uo-license-btn--secondary">
												<?php esc_attr_e( 'Buy license', 'uncanny-pro-toolkit' ); ?>
                                            </a>

										<?php } ?>

                                    </div>

                                </div>
                                <div class="uo-license-content-faq">
                                    <div class="uo-license-content-title">
										<?php esc_attr_e( 'Need help?', 'uncanny-pro-toolkit' ); ?>
                                    </div>

                                    <div class="uo-license-content-faq-list">
                                        <ul class="uo-license-content-faq-list-ul">
                                            <li class="uo-license-content-faq-item">
                                                <a href="<?php echo $where_to_get_my_license; ?>" target="_blank">
													<?php esc_attr_e( 'Where to get my license key', 'uncanny-pro-toolkit' ); ?>
                                                </a>
                                            </li>
                                            <li class="uo-license-content-faq-item">
                                                <a href="<?php echo $buy_new_license; ?>" target="_blank">
													<?php esc_attr_e( 'Buy a new license', 'uncanny-pro-toolkit' ); ?>
                                                </a>
                                            </li>
                                            <li class="uo-license-content-faq-item">
                                                <a href="<?php echo $knowledge_base; ?>" target="_blank">
													<?php esc_attr_e( 'Knowledge Base', 'uncanny-pro-toolkit' ); ?>
                                                </a>
                                            </li>
                                        </ul>
                                    </div>
                                </div>
                            </div>
                            <div class="uo-license-content-footer">

								<?php if ( $license_is_active ) { ?>

                                    <button type="submit" name="uo_license_deactivate"
                                            class="uo-license-btn uo-license-btn--error">
										<?php esc_attr_e( 'Deactivate License', 'uncanny-pro-toolkit' ); ?>
                                    </button>

								<?php } else { ?>

                                    <button type="submit" name="uo_license_activate"
                                            class="uo-license-btn uo-license-btn--primary">
										<?php esc_attr_e( 'Activate now', 'uncanny-pro-toolkit' ); ?>
                                    </button>

                                    <a href="<?php echo $buy_new_license; ?>" target="_blank"
                                       class="uo-license-btn uo-license-btn--secondary">
										<?php esc_attr_e( 'Buy license', 'uncanny-pro-toolkit' ); ?>
                                    </a>

								<?php } ?>

                            </div>

                        </form>

                    </div>
                </div>
            </div>
        </div>
		<?php
	}

	public static function uo_enqueue_frontend_assets() {
		$assets_url = plugins_url( basename( dirname( UO_FILE ) ) ) . '/src/assets/dist/';

		$uncanny_toolkit_pro = [
			'restURL' => esc_url_raw( rest_url() . 'uo_toolkit/v1/' ),
			'nonce'   => \wp_create_nonce( 'wp_rest' ),
		];

		wp_register_script( 'ultp-frontend', $assets_url . 'frontend/bundle.min.js', [ 'jquery' ], UNCANNY_TOOLKIT_PRO_VERSION );
		wp_localize_script( 'ultp-frontend', 'UncannyToolkitPro', $uncanny_toolkit_pro );
		wp_enqueue_script( 'ultp-frontend' );

		wp_enqueue_style( 'ultp-frontend', $assets_url . 'frontend/bundle.min.css', false, UNCANNY_TOOLKIT_PRO_VERSION );
	}

	public static function uo_enqueue_backend_assets() {
		$assets_url = plugins_url( basename( dirname( UO_FILE ) ) ) . '/src/assets/dist/';

		$uncanny_toolkit_pro = [
			'restURL' => esc_url_raw( rest_url() . 'uo_pro/v1/' ),
			'nonce'   => \wp_create_nonce( 'wp_rest' ),
			'i18n'    => [
				'all' => esc_attr__( 'All', 'uncanny-pro-toolkit' )
			]
		];

		wp_enqueue_style( 'ultp-backend', $assets_url . 'backend/bundle.min.css', false, UNCANNY_TOOLKIT_PRO_VERSION );

		wp_register_script( 'ultp-backend', $assets_url . 'backend/bundle.min.js', [ 'jquery' ], UNCANNY_TOOLKIT_PRO_VERSION );

		wp_localize_script( 'ultp-backend', 'UncannyToolkitPro', $uncanny_toolkit_pro );
		wp_enqueue_script( 'ultp-backend' );
	}

	/**
	 * Filters the variable that defines the visibility of the
	 * "Try Automator" item
	 *
	 * @since 3.5.4
	 */
	public static function try_automator_evaluate_visibility( $visible ) {
		// Check if the item is visible
		// If it's not, don't override the variable
		if ( true === $visible ) {
			// Check if the user clicked the "X" button before
			$visibility_option = get_option( '_uncanny_toolkit_try_automator_visibility' );

			// Check if the user chose to hide it
			if ( $visibility_option == 'hide-forever' ) {
				$visible = false;
			}
		}

		return $visible;
	}

	/**
	 * Filters the inner html of the "Try Automator" admin sidebar item
	 * to add the X icon to hide the item
	 *
	 * @param String $inner_html The inner HTML
	 *
	 * @return String             The inner HTML, modified.
	 * @since 3.5.4
	 */
	public static function try_automator_add_x_icon( $inner_html ) {
		// Add the "X" icon
		$inner_html .= '<span class="ultp-sidebar-featured-item__close" id="ultp-sidebar-try-automator-close" ult-tooltip-admin="' . esc_attr__( 'Hide forever', 'uncanny-pro-toolkit' ) . '"><span class="ultp-sidebar-featured-item__close-icon"></span></span>';

		return $inner_html;
	}

	/**
	 * Registers a REST API endpoint to change the visibility of the
	 * "Try Automator" item
	 *
	 * @since 3.5.4
	 */
	public static function try_automator_rest_register() {
		register_rest_route( 'uo_pro/v1', '/try-automator-visibility/', array(
			'methods'             => 'POST',
			'callback'            => array( __CLASS__, 'try_automator_rest_callback' ),
			'permission_callback' => function () {
				return true;
			}
		) );
	}

	/**
	 * Rest API callback for saving user selection for hiding the "Try Automator" item.
	 *
	 * @param object $request
	 *
	 * @return object
	 * @since 3.5.4
	 */
	public static function try_automator_rest_callback( $request ) {
		// check if its a valid request.
		$data = $request->get_params();
		if ( isset( $data['action'] ) && ( 'hide-forever' === $data['action'] || 'hide-forever' === $data['action'] ) ) {
			update_option( '_uncanny_toolkit_try_automator_visibility', $data['action'] );

			return new \WP_REST_Response( [ 'success' => true ], 200 );
		}

		return new \WP_REST_Response( [ 'success' => false ], 200 );
	}

	/************************************
	 * this illustrates how to activate
	 * a license key
	 *************************************/

	public static function uo_activate_license() {

		// listen for our activate button to be clicked
		if ( isset( $_POST['uo_license_activate'] ) ) {

			// run a quick security check
			if ( ! check_admin_referer( 'uo_nonce', 'uo_nonce' ) ) {
				return;
			} // get out if we didn't click the Activate button


			// Save license key
			$license = $_POST['uo_license_key'];
			update_option( 'uo_license_key', $license );

			// retrieve the license from the database
			$license = trim( get_option( 'uo_license_key' ) );


			// data to send in our API request
			$api_params = array(
				'edd_action' => 'activate_license',
				'license'    => $license,
				'item_name'  => urlencode( UO_ITEM_NAME ), // the name of our product in uo
				'url'        => home_url()
			);

			// Call the custom API.
			$response = wp_remote_post( UO_STORE_URL, array(
				'timeout'   => 15,
				'sslverify' => false,
				'body'      => $api_params
			) );

			// make sure the response came back okay
			if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) {

				if ( is_wp_error( $response ) ) {
					$message = $response->get_error_message();
				} else {
					$message = esc_attr__( 'An error occurred, please try again.' );
				}

			} else {

				$license_data = json_decode( wp_remote_retrieve_body( $response ) );

				if ( false === $license_data->success ) {

					switch ( $license_data->error ) {

						case 'expired' :

							$message = sprintf(
								__( 'Your license key expired on %s.' ),
								date_i18n( get_option( 'date_format' ), strtotime( $license_data->expires, current_time( 'timestamp' ) ) )
							);
							break;

						case 'revoked' :

							$message = esc_attr__( 'Your license key has been disabled.' );
							break;

						case 'missing' :

							$message = esc_attr__( 'Invalid license.' );
							break;

						case 'invalid' :
						case 'site_inactive' :

							$message = esc_attr__( 'Your license is not active for this URL.' );
							break;

						case 'item_name_mismatch' :

							$message = sprintf( esc_attr__( 'This appears to be an invalid license key for %s.' ), UO_ITEM_NAME );
							break;

						case 'no_activations_left':

							$message = esc_attr__( 'Your license key has reached its activation limit.' );
							break;

						default :

							$message = esc_attr__( 'An error occurred, please try again.' );
							break;
					}

				}

			}


			// Check if anything passed on a message constituting a failure
			if ( ! empty( $message ) ) {
				$base_url = admin_url( 'admin.php?page=' . UO_LICENSE_PAGE );
				$redirect = add_query_arg( array(
					'sl_activation' => 'false',
					'message'       => urlencode( $message )
				), $base_url );

				wp_redirect( $redirect );
				exit();
			}

			// $license_data->license will be either "valid" or "invalid"

			update_option( 'uo_license_status', $license_data->license );

			wp_redirect( admin_url( 'admin.php?page=' . UO_LICENSE_PAGE ) );
			exit();

		}
	}


	/***********************************************
	 * Illustrates how to deactivate a license key.
	 * This will descrease the site count
	 ***********************************************/

	public static function uo_deactivate_license() {

		// listen for our activate button to be clicked
		if ( isset( $_POST['uo_license_deactivate'] ) ) {

			// run a quick security check
			if ( ! check_admin_referer( 'uo_nonce', 'uo_nonce' ) ) {
				return;
			} // get out if we didn't click the Activate button

			// retrieve the license from the database
			$license = trim( get_option( 'uo_license_key' ) );


			// data to send in our API request
			$api_params = array(
				'edd_action' => 'deactivate_license',
				'license'    => $license,
				'item_name'  => urlencode( UO_ITEM_NAME ), // the name of our product in uo
				'url'        => home_url()
			);

			// Call the custom API.
			$response = wp_remote_post( UO_STORE_URL, array(
				'timeout'   => 15,
				'sslverify' => false,
				'body'      => $api_params
			) );

			// make sure the response came back okay
			if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) {

				if ( is_wp_error( $response ) ) {
					$message = $response->get_error_message();
				} else {
					$message = esc_attr__( 'An error occurred, please try again.' );
				}

				$base_url = admin_url( 'admin.php?page=' . UO_LICENSE_PAGE );
				$redirect = add_query_arg( array(
					'sl_activation' => 'false',
					'message'       => urlencode( $message )
				), $base_url );

				wp_redirect( $redirect );
				exit();
			}

			// decode the license data
			$license_data = json_decode( wp_remote_retrieve_body( $response ) );

			// $license_data->license will be either "deactivated" or "failed"
			if ( $license_data->license == 'deactivated' || $license_data->license == 'failed' ) {
				delete_option( 'uo_license_status' );
			}

			wp_redirect( admin_url( 'admin.php?page=' . UO_LICENSE_PAGE ) );
			exit();

		}
	}


	/************************************
	 * this illustrates how to check if
	 * a license key is still valid
	 * the updater does this for you,
	 * so this is only needed if you
	 * want to do something custom
	 *************************************/

	public static function uo_check_license() {

		global $wp_version;

		$license = trim( get_option( 'uo_license_key' ) );

		$api_params = array(
			'edd_action' => 'check_license',
			'license'    => $license,
			'item_name'  => urlencode( UO_ITEM_NAME ),
			'url'        => home_url()
		);

		// Call the custom API.
		$response = wp_remote_post( UO_STORE_URL, array(
			'timeout'   => 15,
			'sslverify' => false,
			'body'      => $api_params
		) );

		if ( is_wp_error( $response ) ) {
			return false;
		}

		$license_data = json_decode( wp_remote_retrieve_body( $response ) );

		if ( $license_data->license == 'valid' ) {
			echo 'valid';
			exit;
			// this license is still valid
		} else {
			echo 'invalid';
			exit;
			// this license is no longer valid
		}
	}

	/**
	 * This is a means of catching errors from the activation method above and displaying it to the customer
	 */
	public static function uo_admin_notices() {

		if ( ! isset( $_GET['page'] ) ) {
			return;
		}

		if ( 'uncanny-toolkit-license' !== sanitize_text_field( $_GET['page'] ) ) {
			return;
		}

		if ( ! isset( $_GET['sl_activation'] ) ) {
			return;
		}

		if ( ! empty( $_GET['message'] ) ) {

			switch ( $_GET['sl_activation'] ) {

				case 'false':
					$message = esc_html( wp_kses( $_GET['message'], [] ) );
					?>
                    <div class="error">
                        <p><?php echo $message; ?></p>
                    </div>
					<?php
					break;

				case 'true':
				default:
					// Developers can put a custom success message here for when activation is successful if they way.
					break;

			}
		}

	}

	/**
	 *
	 *
	 * @static
	 *
	 * @param $class
	 */
	private static function auto_loader( $class ) {

		// Remove Class's namespace eg: my_namespace/MyClassName to MyClassName
		$class = str_replace( 'uncanny_pro_toolkit', '', $class );
		$class = str_replace( '\\', '', $class );

		// First Character of class name to lowercase eg: MyClassName to myClassName
		$class_to_filename = lcfirst( $class );

		// Split class name on upper case letter eg: myClassName to array( 'my', 'Class', 'Name')
		$split_class_to_filename = preg_split( '#([A-Z][^A-Z]*)#', $class_to_filename, 0, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY );

		if ( 1 <= count( $split_class_to_filename ) ) {
			// Split class name to hyphenated name eg: array( 'my', 'Class', 'Name') to my-Class-Name
			$class_to_filename = implode( '-', $split_class_to_filename );
		}
		// Create file name that will be loaded from the classes directory eg: my-Class-Name to my-class-name.php
		$file_name = 'classes/' . strtolower( $class_to_filename ) . '.php';
		if ( file_exists( dirname( __FILE__ ) . '/' . $file_name ) ) {
			include_once $file_name;
		}

	}

	/**
	 * @param string $file_name File name must be prefixed with a \ (foreword slash)
	 * @param mixed $file (false || __FILE__ )
	 *
	 * @return string
	 */
	public static function get_pro_include( $file_name, $file = false ) {

		if ( false === $file ) {
			$file = __FILE__;
		}

		$asset_uri = dirname( $file ) . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . $file_name;

		return $asset_uri;
	}
}