Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: load survey vis internal pages hooks #152

Merged
merged 3 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions .github/workflows/create-build-zip.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Build and publish the ZIP build file

on:
pull_request:
types: [ opened, synchronize, ready_for_review ]
types: [opened, synchronize, ready_for_review]
branches-ignore:
- "update_dependencies"
jobs:
Expand All @@ -16,20 +16,10 @@ jobs:
steps:
- uses: actions/checkout@master
- name: Setup node 14
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: 14.x
- name: Get Composer Cache Directory
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Configure Composer cache
uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
cache: "yarn"
- name: Install composer deps
run: composer install --no-dev --prefer-dist --no-progress --no-suggest
- name: Install yarn deps
Expand Down Expand Up @@ -102,4 +92,4 @@ jobs:
comment-id: ${{ steps.find-comment.outputs.comment-id }}
token: ${{ secrets.BOT_TOKEN }}
edit-mode: replace
body: ${{ steps.get-comment-body.outputs.body }}
body: ${{ steps.get-comment-body.outputs.body }}
13 changes: 2 additions & 11 deletions .github/workflows/create-tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,7 @@ jobs:
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v2
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
cache: "yarn"
- name: Release new version
id: release
run: |
Expand All @@ -53,4 +44,4 @@ jobs:
steps:
- name: Meep
run: |
echo "Nothing to do"
echo "Nothing to do"
23 changes: 7 additions & 16 deletions .github/workflows/deploy-s3-store.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,10 @@ jobs:
steps:
- uses: actions/checkout@master
- name: Setup node 14
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: 14.x
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v2
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
cache: "yarn"
- name: Build & create dist/artifact
run: |
yarn install --frozen-lockfile
Expand All @@ -43,8 +34,8 @@ jobs:
AWS_S3_BUCKET: ${{ secrets.AWS_S3_BUCKET_DOWNLOADS }}
AWS_ACCESS_KEY_ID: ${{ secrets.S3_DOWNLOADS_AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.S3_DOWNLOADS_AWS_SECRET_ACCESS_KEY }}
AWS_REGION: 'us-west-1' # optional: defaults to us-east-1
SOURCE_DIR: 'artifact' # optional: defaults to entire repository
AWS_REGION: "us-west-1" # optional: defaults to us-east-1
SOURCE_DIR: "artifact" # optional: defaults to entire repository
DEST_DIR: ${{ secrets.S3_AWS_PRODUCTS_FOLDER }}/$BUILD_NAME/latest
- name: Upload Tagged Version to S3
uses: jakejarvis/s3-sync-action@master
Expand All @@ -54,8 +45,8 @@ jobs:
AWS_S3_BUCKET: ${{ secrets.AWS_S3_BUCKET_DOWNLOADS }}
AWS_ACCESS_KEY_ID: ${{ secrets.S3_DOWNLOADS_AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.S3_DOWNLOADS_AWS_SECRET_ACCESS_KEY }}
AWS_REGION: 'us-west-1' # optional: defaults to us-east-1
SOURCE_DIR: 'artifact' # optional: defaults to entire repository
AWS_REGION: "us-west-1" # optional: defaults to us-east-1
SOURCE_DIR: "artifact" # optional: defaults to entire repository
DEST_DIR: ${{ secrets.S3_AWS_PRODUCTS_FOLDER }}/$BUILD_NAME/$BUILD_VERSION
- name: Send update to the store
env:
Expand All @@ -64,4 +55,4 @@ jobs:
STORE_URL: ${{ secrets.THEMEISLE_STORE_URL }}
GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }}
BUILD_VERSION: ${{ env.BUILD_VERSION }}
uses: Codeinwp/action-store-release@main
uses: Codeinwp/action-store-release@main
12 changes: 6 additions & 6 deletions .github/workflows/diff-translations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ on:
pull_request:
types: [opened, edited, synchronize, ready_for_review]
branches:
- 'development'
- "development"

jobs:
translation:
runs-on: ubuntu-latest
steps:
- name: Checkout Ref Base
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
path: raft-head
- name: Setup node 14
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: 14.x
- name: FRESH Makepot BASE
Expand All @@ -28,7 +28,7 @@ jobs:
yarn run build
ls languages/
- name: Checkout Ref Head
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
ref: development
path: raft-base
Expand All @@ -45,7 +45,7 @@ jobs:
id: find_coomment
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'pirate-bot'
comment-author: "pirate-bot"
body-includes: PR has POT difference
- name: Install PODiff
run: |
Expand All @@ -71,4 +71,4 @@ jobs:
teams:
- "sbs"
status: Has translation changes, a review from SBS team is required
token: ${{ secrets.BOT_TOKEN }}
token: ${{ secrets.BOT_TOKEN }}
17 changes: 4 additions & 13 deletions .github/workflows/test-js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Test JS
on:
push:
branches-ignore:
- 'master'
- "master"

jobs:
jslint:
Expand All @@ -16,22 +16,13 @@ jobs:
- name: Checkout source code
uses: actions/checkout@master
- name: Setup node
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v2
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
cache: "yarn"
- name: Install Dependencies
run: yarn install --frozen-lockfile
- name: Build source
run: yarn run build
- name: Run lint checks
run: yarn run lint
run: yarn run lint
38 changes: 8 additions & 30 deletions .github/workflows/test-php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,27 @@ name: Test PHP
on:
push:
branches-ignore:
- 'master'
- "master"

jobs:
phplint:
name: Phplint
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- name: Setup PHP version
uses: shivammathur/setup-php@v2
with:
php-version: '7.2'
php-version: "7.2"
extensions: simplexml
- name: Checkout source code
uses: actions/checkout@v2
- name: Get Composer Cache Directory
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Setup Composer cache
uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
uses: actions/checkout@v4
- name: Install composer
run: composer install --prefer-dist --no-progress --no-suggest
- name: Run PHPCS
run: composer run lint
phpunit:
name: Phpunit
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
services:
mysql:
image: mysql:5.7
Expand All @@ -47,26 +36,15 @@ jobs:
- name: Setup PHP version
uses: shivammathur/setup-php@v2
with:
php-version: '7.2'
php-version: "7.2"
extensions: simplexml, mysql
tools: phpunit-polyfills
- name: Checkout source code
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Install WordPress Test Suite
run: |
bash bin/install-wp-tests.sh wordpress_test root root 127.0.0.1:${{ job.services.mysql.ports['3306'] }}
- name: Get Composer Cache Directory
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Setup Composer cache
uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Install composer
run: composer install --prefer-dist --no-progress --no-suggest
- name: Run phpunit
run: composer run-script phpunit
run: composer run-script phpunit
1 change: 1 addition & 0 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ function define_constants() {
define( 'RAFT_DEBUG', defined( 'WP_DEBUG' ) && WP_DEBUG === true );
define( 'RAFT_DIR', trailingslashit( get_template_directory() ) );
define( 'RAFT_URL', trailingslashit( get_template_directory_uri() ) );
define( 'RAFT_PRODUCT_SLUG', basename( RAFT_DIR ) );
}

/**
Expand Down
65 changes: 25 additions & 40 deletions inc/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function setup_admin_hooks() {
add_action( 'wp_ajax_raft_dismiss_welcome_notice', array( $this, 'remove_welcome_notice' ) );
add_action( 'wp_ajax_raft_set_otter_ref', array( $this, 'set_otter_ref' ) );
add_action( 'activated_plugin', array( $this, 'after_otter_activation' ) );
add_action( 'admin_print_scripts', array( $this, 'add_nps_form' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'register_internal_page' ) );

add_action( 'enqueue_block_editor_assets', array( $this, 'add_fse_design_pack_notice' ) );
add_action( 'wp_ajax_raft_dismiss_design_pack_notice', array( $this, 'remove_design_pack_notice' ) );
Expand Down Expand Up @@ -380,50 +380,35 @@ public function after_otter_activation( $plugin ) {
}

/**
* Add NPS form.
* Register internal pages.
*
* @return void
*/
public function add_nps_form() {
public function register_internal_page() {
$screen = get_current_screen();

if ( current_user_can( 'manage_options' ) && ( 'dashboard' === $screen->id || 'themes' === $screen->id ) ) {
$website_url = preg_replace( '/[^a-zA-Z0-9]+/', '', get_site_url() );

$config = array(
'environmentId' => 'clp9hp3j71oqndl2ietgq8nej',
'apiHost' => 'https://app.formbricks.com',
'userId' => 'raft_' . $website_url,
'attributes' => array(
'days_since_install' => self::convert_to_category( round( ( time() - get_option( 'raft_install', time() ) ) / DAY_IN_SECONDS ) ),
),
);

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>';

if ( ! current_user_can( 'manage_options' ) || ( 'dashboard' !== $screen->id && 'themes' !== $screen->id ) ) {
return;
}
}

add_filter(
'themeisle-sdk/survey/' . RAFT_PRODUCT_SLUG,
function( $data, $page_slug ) {
$install_days_number = intval( ( time() - get_option( 'raft_install', time() ) ) / DAY_IN_SECONDS );

$data = array(
'environmentId' => 'clp9hp3j71oqndl2ietgq8nej',
'attributes' => array(
'install_days_number' => $install_days_number,
'version' => RAFT_VERSION,
),
);

/**
* Convert a number to a category.
*
* @param int $number Number to convert.
* @param int $scale Scale.
*
* @return int
*/
public static function convert_to_category( $number, $scale = 1 ) {
$normalized_number = intval( round( $number / $scale ) );

if ( 0 === $normalized_number || 1 === $normalized_number ) {
return 0;
} elseif ( $normalized_number > 1 && $normalized_number < 8 ) {
return 7;
} elseif ( $normalized_number >= 8 && $normalized_number < 31 ) {
return 30;
} elseif ( $normalized_number > 30 && $normalized_number < 90 ) {
return 90;
} elseif ( $normalized_number > 90 ) {
return 91;
}
return $data;
},
10,
2
);
do_action( 'themeisle_internal_page', RAFT_PRODUCT_SLUG, $screen->id );
}
}
Loading