Skip to content

Commit 9c0cb95

Browse files
Merge pull request #152 from Codeinwp/refactor/internal-pages
feat: load survey vis internal pages hooks
2 parents fe819cc + c84f415 commit 9c0cb95

8 files changed

+57
-130
lines changed

.github/workflows/create-build-zip.yml

+4-14
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Build and publish the ZIP build file
22

33
on:
44
pull_request:
5-
types: [ opened, synchronize, ready_for_review ]
5+
types: [opened, synchronize, ready_for_review]
66
branches-ignore:
77
- "update_dependencies"
88
jobs:
@@ -16,20 +16,10 @@ jobs:
1616
steps:
1717
- uses: actions/checkout@master
1818
- name: Setup node 14
19-
uses: actions/setup-node@v1
19+
uses: actions/setup-node@v4
2020
with:
2121
node-version: 14.x
22-
- name: Get Composer Cache Directory
23-
id: composer-cache
24-
run: |
25-
echo "::set-output name=dir::$(composer config cache-files-dir)"
26-
- name: Configure Composer cache
27-
uses: actions/cache@v1
28-
with:
29-
path: ${{ steps.composer-cache.outputs.dir }}
30-
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
31-
restore-keys: |
32-
${{ runner.os }}-composer-
22+
cache: "yarn"
3323
- name: Install composer deps
3424
run: composer install --no-dev --prefer-dist --no-progress --no-suggest
3525
- name: Install yarn deps
@@ -102,4 +92,4 @@ jobs:
10292
comment-id: ${{ steps.find-comment.outputs.comment-id }}
10393
token: ${{ secrets.BOT_TOKEN }}
10494
edit-mode: replace
105-
body: ${{ steps.get-comment-body.outputs.body }}
95+
body: ${{ steps.get-comment-body.outputs.body }}

.github/workflows/create-tag.yml

+2-11
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,7 @@ jobs:
1919
uses: actions/setup-node@v1
2020
with:
2121
node-version: ${{ matrix.node-version }}
22-
- name: Get yarn cache directory path
23-
id: yarn-cache-dir-path
24-
run: echo "::set-output name=dir::$(yarn cache dir)"
25-
- uses: actions/cache@v2
26-
id: yarn-cache
27-
with:
28-
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
29-
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
30-
restore-keys: |
31-
${{ runner.os }}-yarn-
22+
cache: "yarn"
3223
- name: Release new version
3324
id: release
3425
run: |
@@ -53,4 +44,4 @@ jobs:
5344
steps:
5445
- name: Meep
5546
run: |
56-
echo "Nothing to do"
47+
echo "Nothing to do"

.github/workflows/deploy-s3-store.yml

+7-16
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,10 @@ jobs:
1111
steps:
1212
- uses: actions/checkout@master
1313
- name: Setup node 14
14-
uses: actions/setup-node@v1
14+
uses: actions/setup-node@v4
1515
with:
1616
node-version: 14.x
17-
- name: Get yarn cache directory path
18-
id: yarn-cache-dir-path
19-
run: echo "::set-output name=dir::$(yarn cache dir)"
20-
- uses: actions/cache@v2
21-
id: yarn-cache
22-
with:
23-
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
24-
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
25-
restore-keys: |
26-
${{ runner.os }}-yarn-
17+
cache: "yarn"
2718
- name: Build & create dist/artifact
2819
run: |
2920
yarn install --frozen-lockfile
@@ -43,8 +34,8 @@ jobs:
4334
AWS_S3_BUCKET: ${{ secrets.AWS_S3_BUCKET_DOWNLOADS }}
4435
AWS_ACCESS_KEY_ID: ${{ secrets.S3_DOWNLOADS_AWS_ACCESS_KEY_ID }}
4536
AWS_SECRET_ACCESS_KEY: ${{ secrets.S3_DOWNLOADS_AWS_SECRET_ACCESS_KEY }}
46-
AWS_REGION: 'us-west-1' # optional: defaults to us-east-1
47-
SOURCE_DIR: 'artifact' # optional: defaults to entire repository
37+
AWS_REGION: "us-west-1" # optional: defaults to us-east-1
38+
SOURCE_DIR: "artifact" # optional: defaults to entire repository
4839
DEST_DIR: ${{ secrets.S3_AWS_PRODUCTS_FOLDER }}/$BUILD_NAME/latest
4940
- name: Upload Tagged Version to S3
5041
uses: jakejarvis/s3-sync-action@master
@@ -54,8 +45,8 @@ jobs:
5445
AWS_S3_BUCKET: ${{ secrets.AWS_S3_BUCKET_DOWNLOADS }}
5546
AWS_ACCESS_KEY_ID: ${{ secrets.S3_DOWNLOADS_AWS_ACCESS_KEY_ID }}
5647
AWS_SECRET_ACCESS_KEY: ${{ secrets.S3_DOWNLOADS_AWS_SECRET_ACCESS_KEY }}
57-
AWS_REGION: 'us-west-1' # optional: defaults to us-east-1
58-
SOURCE_DIR: 'artifact' # optional: defaults to entire repository
48+
AWS_REGION: "us-west-1" # optional: defaults to us-east-1
49+
SOURCE_DIR: "artifact" # optional: defaults to entire repository
5950
DEST_DIR: ${{ secrets.S3_AWS_PRODUCTS_FOLDER }}/$BUILD_NAME/$BUILD_VERSION
6051
- name: Send update to the store
6152
env:
@@ -64,4 +55,4 @@ jobs:
6455
STORE_URL: ${{ secrets.THEMEISLE_STORE_URL }}
6556
GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }}
6657
BUILD_VERSION: ${{ env.BUILD_VERSION }}
67-
uses: Codeinwp/action-store-release@main
58+
uses: Codeinwp/action-store-release@main

.github/workflows/diff-translations.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ on:
55
pull_request:
66
types: [opened, edited, synchronize, ready_for_review]
77
branches:
8-
- 'development'
8+
- "development"
99

1010
jobs:
1111
translation:
1212
runs-on: ubuntu-latest
1313
steps:
1414
- name: Checkout Ref Base
15-
uses: actions/checkout@v2
15+
uses: actions/checkout@v4
1616
with:
1717
path: raft-head
1818
- name: Setup node 14
19-
uses: actions/setup-node@v1
19+
uses: actions/setup-node@v4
2020
with:
2121
node-version: 14.x
2222
- name: FRESH Makepot BASE
@@ -28,7 +28,7 @@ jobs:
2828
yarn run build
2929
ls languages/
3030
- name: Checkout Ref Head
31-
uses: actions/checkout@v2
31+
uses: actions/checkout@v4
3232
with:
3333
ref: development
3434
path: raft-base
@@ -45,7 +45,7 @@ jobs:
4545
id: find_coomment
4646
with:
4747
issue-number: ${{ github.event.pull_request.number }}
48-
comment-author: 'pirate-bot'
48+
comment-author: "pirate-bot"
4949
body-includes: PR has POT difference
5050
- name: Install PODiff
5151
run: |
@@ -71,4 +71,4 @@ jobs:
7171
teams:
7272
- "sbs"
7373
status: Has translation changes, a review from SBS team is required
74-
token: ${{ secrets.BOT_TOKEN }}
74+
token: ${{ secrets.BOT_TOKEN }}

.github/workflows/test-js.yml

+4-13
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Test JS
33
on:
44
push:
55
branches-ignore:
6-
- 'master'
6+
- "master"
77

88
jobs:
99
jslint:
@@ -16,22 +16,13 @@ jobs:
1616
- name: Checkout source code
1717
uses: actions/checkout@master
1818
- name: Setup node
19-
uses: actions/setup-node@v1
19+
uses: actions/setup-node@v4
2020
with:
2121
node-version: ${{ matrix.node-version }}
22-
- name: Get yarn cache directory path
23-
id: yarn-cache-dir-path
24-
run: echo "::set-output name=dir::$(yarn cache dir)"
25-
- uses: actions/cache@v2
26-
id: yarn-cache
27-
with:
28-
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
29-
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
30-
restore-keys: |
31-
${{ runner.os }}-yarn-
22+
cache: "yarn"
3223
- name: Install Dependencies
3324
run: yarn install --frozen-lockfile
3425
- name: Build source
3526
run: yarn run build
3627
- name: Run lint checks
37-
run: yarn run lint
28+
run: yarn run lint

.github/workflows/test-php.yml

+8-30
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,27 @@ name: Test PHP
33
on:
44
push:
55
branches-ignore:
6-
- 'master'
6+
- "master"
77

88
jobs:
99
phplint:
1010
name: Phplint
11-
runs-on: ubuntu-latest
11+
runs-on: ubuntu-22.04
1212
steps:
1313
- name: Setup PHP version
1414
uses: shivammathur/setup-php@v2
1515
with:
16-
php-version: '7.2'
16+
php-version: "7.2"
1717
extensions: simplexml
1818
- name: Checkout source code
19-
uses: actions/checkout@v2
20-
- name: Get Composer Cache Directory
21-
id: composer-cache
22-
run: |
23-
echo "::set-output name=dir::$(composer config cache-files-dir)"
24-
- name: Setup Composer cache
25-
uses: actions/cache@v1
26-
with:
27-
path: ${{ steps.composer-cache.outputs.dir }}
28-
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
29-
restore-keys: |
30-
${{ runner.os }}-composer-
19+
uses: actions/checkout@v4
3120
- name: Install composer
3221
run: composer install --prefer-dist --no-progress --no-suggest
3322
- name: Run PHPCS
3423
run: composer run lint
3524
phpunit:
3625
name: Phpunit
37-
runs-on: ubuntu-latest
26+
runs-on: ubuntu-22.04
3827
services:
3928
mysql:
4029
image: mysql:5.7
@@ -47,26 +36,15 @@ jobs:
4736
- name: Setup PHP version
4837
uses: shivammathur/setup-php@v2
4938
with:
50-
php-version: '7.2'
39+
php-version: "7.2"
5140
extensions: simplexml, mysql
5241
tools: phpunit-polyfills
5342
- name: Checkout source code
54-
uses: actions/checkout@v2
43+
uses: actions/checkout@v4
5544
- name: Install WordPress Test Suite
5645
run: |
5746
bash bin/install-wp-tests.sh wordpress_test root root 127.0.0.1:${{ job.services.mysql.ports['3306'] }}
58-
- name: Get Composer Cache Directory
59-
id: composer-cache
60-
run: |
61-
echo "::set-output name=dir::$(composer config cache-files-dir)"
62-
- name: Setup Composer cache
63-
uses: actions/cache@v1
64-
with:
65-
path: ${{ steps.composer-cache.outputs.dir }}
66-
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
67-
restore-keys: |
68-
${{ runner.os }}-composer-
6947
- name: Install composer
7048
run: composer install --prefer-dist --no-progress --no-suggest
7149
- name: Run phpunit
72-
run: composer run-script phpunit
50+
run: composer run-script phpunit

functions.php

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ function define_constants() {
7171
define( 'RAFT_DEBUG', defined( 'WP_DEBUG' ) && WP_DEBUG === true );
7272
define( 'RAFT_DIR', trailingslashit( get_template_directory() ) );
7373
define( 'RAFT_URL', trailingslashit( get_template_directory_uri() ) );
74+
define( 'RAFT_PRODUCT_SLUG', basename( RAFT_DIR ) );
7475
}
7576

7677
/**

inc/Admin.php

+25-40
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function setup_admin_hooks() {
3333
add_action( 'wp_ajax_raft_dismiss_welcome_notice', array( $this, 'remove_welcome_notice' ) );
3434
add_action( 'wp_ajax_raft_set_otter_ref', array( $this, 'set_otter_ref' ) );
3535
add_action( 'activated_plugin', array( $this, 'after_otter_activation' ) );
36-
add_action( 'admin_print_scripts', array( $this, 'add_nps_form' ) );
36+
add_action( 'admin_enqueue_scripts', array( $this, 'register_internal_page' ) );
3737

3838
add_action( 'enqueue_block_editor_assets', array( $this, 'add_fse_design_pack_notice' ) );
3939
add_action( 'wp_ajax_raft_dismiss_design_pack_notice', array( $this, 'remove_design_pack_notice' ) );
@@ -380,50 +380,35 @@ public function after_otter_activation( $plugin ) {
380380
}
381381

382382
/**
383-
* Add NPS form.
383+
* Register internal pages.
384384
*
385385
* @return void
386386
*/
387-
public function add_nps_form() {
387+
public function register_internal_page() {
388388
$screen = get_current_screen();
389-
390-
if ( current_user_can( 'manage_options' ) && ( 'dashboard' === $screen->id || 'themes' === $screen->id ) ) {
391-
$website_url = preg_replace( '/[^a-zA-Z0-9]+/', '', get_site_url() );
392-
393-
$config = array(
394-
'environmentId' => 'clp9hp3j71oqndl2ietgq8nej',
395-
'apiHost' => 'https://app.formbricks.com',
396-
'userId' => 'raft_' . $website_url,
397-
'attributes' => array(
398-
'days_since_install' => self::convert_to_category( round( ( time() - get_option( 'raft_install', time() ) ) / DAY_IN_SECONDS ) ),
399-
),
400-
);
401-
402-
echo '<script type="text/javascript">!function(){var t=document.createElement("script");t.type="text/javascript",t.async=!0,t.src="https://unpkg.com/@formbricks/js@^1.6.5/dist/index.umd.js";var e=document.getElementsByTagName("script")[0];e.parentNode.insertBefore(t,e),setTimeout(function(){window.formbricks.init(' . wp_json_encode( $config ) . ')},500)}();</script>';
389+
390+
if ( ! current_user_can( 'manage_options' ) || ( 'dashboard' !== $screen->id && 'themes' !== $screen->id ) ) {
391+
return;
403392
}
404-
}
393+
394+
add_filter(
395+
'themeisle-sdk/survey/' . RAFT_PRODUCT_SLUG,
396+
function( $data, $page_slug ) {
397+
$install_days_number = intval( ( time() - get_option( 'raft_install', time() ) ) / DAY_IN_SECONDS );
398+
399+
$data = array(
400+
'environmentId' => 'clp9hp3j71oqndl2ietgq8nej',
401+
'attributes' => array(
402+
'install_days_number' => $install_days_number,
403+
'version' => RAFT_VERSION,
404+
),
405+
);
405406

406-
/**
407-
* Convert a number to a category.
408-
*
409-
* @param int $number Number to convert.
410-
* @param int $scale Scale.
411-
*
412-
* @return int
413-
*/
414-
public static function convert_to_category( $number, $scale = 1 ) {
415-
$normalized_number = intval( round( $number / $scale ) );
416-
417-
if ( 0 === $normalized_number || 1 === $normalized_number ) {
418-
return 0;
419-
} elseif ( $normalized_number > 1 && $normalized_number < 8 ) {
420-
return 7;
421-
} elseif ( $normalized_number >= 8 && $normalized_number < 31 ) {
422-
return 30;
423-
} elseif ( $normalized_number > 30 && $normalized_number < 90 ) {
424-
return 90;
425-
} elseif ( $normalized_number > 90 ) {
426-
return 91;
427-
}
407+
return $data;
408+
},
409+
10,
410+
2
411+
);
412+
do_action( 'themeisle_internal_page', RAFT_PRODUCT_SLUG, $screen->id );
428413
}
429414
}

0 commit comments

Comments
 (0)