diff --git a/.github/workflows/test-php.yml b/.github/workflows/test-php.yml index d4b6317..b8b0af0 100644 --- a/.github/workflows/test-php.yml +++ b/.github/workflows/test-php.yml @@ -47,7 +47,7 @@ jobs: - name: Setup PHP version uses: shivammathur/setup-php@v2 with: - php-version: '7.1' + php-version: '7.2' extensions: simplexml, mysql tools: phpunit-polyfills - name: Checkout source code @@ -69,4 +69,4 @@ jobs: - name: Install composer run: composer install --prefer-dist --no-progress --no-suggest - name: Run phpunit - run: phpunit + run: composer run-script phpunit diff --git a/.gitignore b/.gitignore index fab41ab..48ff83e 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ assets/js/build languages/neve-fse.pot .DS_Store +.phpunit.result.cache diff --git a/assets/js/src/welcome-notice.js b/assets/js/src/welcome-notice.js index 946088f..df170f8 100644 --- a/assets/js/src/welcome-notice.js +++ b/assets/js/src/welcome-notice.js @@ -10,6 +10,7 @@ function handleWelcomeNotice( $ ) { activationUrl, ajaxUrl, nonce, + otterRefNonce, otterStatus, } = neveFSEData; @@ -30,6 +31,12 @@ function handleWelcomeNotice( $ ) { const activateOtter = async () => { installText.text( activating ); await activatePlugin( activationUrl ); + + await $.post( ajaxUrl, { + nonce: otterRefNonce, + action: 'neve_fse_set_otter_ref', + } ); + installSpinner.removeClass( 'dashicons-update' ); installSpinner.addClass( 'dashicons-yes' ); installText.text( done ); diff --git a/composer.json b/composer.json index ae2652e..b303f96 100644 --- a/composer.json +++ b/composer.json @@ -51,6 +51,7 @@ "format": "phpcbf --standard=phpcs.xml --report-summary --report-source -s --runtime-set testVersion 7.0- ", "phpcs": "phpcs --standard=phpcs.xml -s --runtime-set testVersion 7.0-", "lint": "composer run-script phpcs", - "phpcs-i": "phpcs -i" + "phpcs-i": "phpcs -i", + "phpunit": "phpunit" } } diff --git a/composer.lock b/composer.lock index db4cdef..51f9498 100644 --- a/composer.lock +++ b/composer.lock @@ -8,16 +8,16 @@ "packages": [ { "name": "codeinwp/themeisle-sdk", - "version": "3.3.23", + "version": "3.3.28", "source": { "type": "git", "url": "https://github.com/Codeinwp/themeisle-sdk.git", - "reference": "24d9c93386b5b3f50673ab2433249cdede48cc6e" + "reference": "cd35fd5356ba169b9a0419ba879764ffeb811b63" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Codeinwp/themeisle-sdk/zipball/24d9c93386b5b3f50673ab2433249cdede48cc6e", - "reference": "24d9c93386b5b3f50673ab2433249cdede48cc6e", + "url": "https://api.github.com/repos/Codeinwp/themeisle-sdk/zipball/cd35fd5356ba169b9a0419ba879764ffeb811b63", + "reference": "cd35fd5356ba169b9a0419ba879764ffeb811b63", "shasum": "" }, "require-dev": { @@ -42,9 +42,9 @@ ], "support": { "issues": "https://github.com/Codeinwp/themeisle-sdk/issues", - "source": "https://github.com/Codeinwp/themeisle-sdk/tree/v3.3.23" + "source": "https://github.com/Codeinwp/themeisle-sdk/tree/v3.3.28" }, - "time": "2024-06-19T13:18:20+00:00" + "time": "2024-08-09T08:54:15+00:00" } ], "packages-dev": [ @@ -1962,16 +1962,16 @@ }, { "name": "squizlabs/php_codesniffer", - "version": "3.9.0", + "version": "3.10.2", "source": { "type": "git", "url": "https://github.com/PHPCSStandards/PHP_CodeSniffer.git", - "reference": "d63cee4890a8afaf86a22e51ad4d97c91dd4579b" + "reference": "86e5f5dd9a840c46810ebe5ff1885581c42a3017" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/d63cee4890a8afaf86a22e51ad4d97c91dd4579b", - "reference": "d63cee4890a8afaf86a22e51ad4d97c91dd4579b", + "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/86e5f5dd9a840c46810ebe5ff1885581c42a3017", + "reference": "86e5f5dd9a840c46810ebe5ff1885581c42a3017", "shasum": "" }, "require": { @@ -2038,7 +2038,7 @@ "type": "open_collective" } ], - "time": "2024-02-16T15:06:51+00:00" + "time": "2024-07-21T23:26:44+00:00" }, { "name": "symfony/polyfill-ctype", diff --git a/inc/Admin.php b/inc/Admin.php index 6e9a701..b56eb3a 100644 --- a/inc/Admin.php +++ b/inc/Admin.php @@ -22,6 +22,13 @@ class Admin { */ private $suspend_survey = true; + /** + * Otter reference key. + * + * @var string + */ + const OTTER_REF = 'otter_reference_key'; + /** * Admin constructor. */ @@ -60,6 +67,7 @@ public function setup_admin_hooks() { add_action( 'enqueue_block_editor_assets', array( $this, 'add_fse_design_pack_notice' ) ); add_action( 'wp_ajax_neve_fse_dismiss_design_pack_notice', array( $this, 'remove_design_pack_notice' ) ); add_action( 'activated_plugin', 'after_otter_activation' ); + add_action( 'wp_ajax_neve_fse_set_otter_ref', array( $this, 'set_otter_ref' ) ); } /** @@ -79,11 +87,12 @@ public function add_fse_design_pack_notice() { true, array(), array( - 'nonce' => wp_create_nonce( 'neve-fse-dismiss-design-pack-notice' ), - 'ajaxUrl' => esc_url( admin_url( 'admin-ajax.php' ) ), - 'ajaxAction' => 'neve_fse_dismiss_design_pack_notice', - 'buttonLink' => tsdk_utmify( 'https://themeisle.com/plugins/fse-design-pack', 'editor', 'neve-fse' ), - 'strings' => array( + 'nonce' => wp_create_nonce( 'neve-fse-dismiss-design-pack-notice' ), + 'otterRefNonce' => wp_create_nonce( 'neve-fse-set-otter-ref' ), + 'ajaxUrl' => esc_url( admin_url( 'admin-ajax.php' ) ), + 'ajaxAction' => 'neve_fse_dismiss_design_pack_notice', + 'buttonLink' => tsdk_utmify( 'https://themeisle.com/plugins/fse-design-pack', 'editor', 'neve-fse' ), + 'strings' => array( 'dismiss' => __( 'Dismiss', 'neve-fse' ), 'recommends' => __( 'Neve FSE recommends', 'neve-fse' ), 'learnMore' => __( 'Learn More', 'neve-fse' ), @@ -467,6 +476,21 @@ public function after_otter_activation( $plugin ) { wp_safe_redirect( $onboarding ); exit; + } + + /** + * Update Otter reference key. + * + * @return void + */ + public function set_otter_ref() { + if ( empty( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( $_POST['nonce'] ), 'neve-fse-set-otter-ref' ) ) { + return; + } + + update_option( self::OTTER_REF, 'neve-fse' ); + + wp_send_json_success(); } /** diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 6f688bf..cf809b1 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -8,6 +8,11 @@ define( 'NEVE_FSE_IGNORE_SOURCE_CHECK', true ); $_tests_dir = getenv( 'WP_TESTS_DIR' ); + +if ( class_exists( '\Yoast\PHPUnitPolyfills\Autoload' ) === false ) { + require_once dirname( dirname( __FILE__ ) ) . '/vendor/yoast/phpunit-polyfills/phpunitpolyfills-autoload.php'; +} + if ( ! $_tests_dir ) { $_tests_dir = '/tmp/wordpress-tests-lib'; }