Skip to content

Commit

Permalink
Merge pull request #2416 from Codeinwp/fix/use-sdk-functions
Browse files Browse the repository at this point in the history
Use SDK function for upgrade links and survey
  • Loading branch information
vytisbulkevicius authored Nov 21, 2024
2 parents be052ca + f0956ea commit 48d2f1d
Show file tree
Hide file tree
Showing 9 changed files with 204 additions and 89 deletions.
2 changes: 1 addition & 1 deletion inc/class-main.php
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ public function about_page() {
'location' => 'otter',
'logo' => esc_url_raw( OTTER_BLOCKS_URL . 'assets/images/logo-alt.png' ),
'has_upgrade_menu' => ! DEFINED( 'OTTER_PRO_VERSION' ),
'upgrade_link' => tsdk_utmify( Pro::get_url(), 'editor', Pro::get_reference() ),
'upgrade_link' => tsdk_translate_link( tsdk_utmify( Pro::get_url(), 'editor', Pro::get_reference() ) ),
'upgrade_text' => __( 'Get Otter Pro', 'otter-blocks' ),
);
}
Expand Down
2 changes: 1 addition & 1 deletion inc/class-pro.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public function render_metabox_upsell( $post_type ) {
<li><?php _e( 'Priority Support', 'otter-blocks' ); ?></li>
</ul>

<a href="<?php echo esc_url_raw( tsdk_utmify( self::get_url(), 'woobuilder', 'wooproducteditor' ) ); ?>" target="_blank" class="button button-primary">
<a href="<?php echo esc_url_raw( tsdk_translate_link( tsdk_utmify( self::get_url(), 'woobuilder', 'wooproducteditor' ) ) ); ?>" target="_blank" class="button button-primary">
<?php _e( 'Discover Otter Pro', 'otter-blocks' ); ?>
</a>
</div>
Expand Down
4 changes: 2 additions & 2 deletions inc/class-registration.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ public function enqueue_block_editor_assets() {
'hasNeve' => defined( 'NEVE_VERSION' ),
'hasPro' => Pro::is_pro_installed(),
'isProActive' => Pro::is_pro_active(),
'upgradeLink' => tsdk_utmify( Pro::get_url(), 'editor', Pro::get_reference() ),
'patternsLink' => tsdk_utmify( Pro::get_patterns_url(), 'editor', Pro::get_reference() ),
'upgradeLink' => tsdk_translate_link( tsdk_utmify( Pro::get_url(), 'editor', Pro::get_reference() ) ),
'patternsLink' => tsdk_translate_link( tsdk_utmify( Pro::get_patterns_url(), 'editor', Pro::get_reference() ) ),
'should_show_upsell' => Pro::should_show_upsell(),
'assetsPath' => OTTER_BLOCKS_URL . 'assets',
'updatePath' => admin_url( 'update-core.php' ),
Expand Down
112 changes: 67 additions & 45 deletions inc/plugins/class-dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public function form_submissions_callback() {
<img style="max-width: 100%" src="<?php echo esc_url( OTTER_BLOCKS_URL . 'assets/images/form-submissions-upsell.svg' ); ?>" alt="Otter Form Submissions Upsell" />
<h2 style="line-height: 1"><?php esc_html_e( 'Collect Your Form Submissions', 'otter-blocks' ); ?></h2>
<p><?php esc_html_e( 'Store, manage and analyze your form submissions with ease – all in one place. With Otter powerful features, managing submissions has never been simpler.', 'otter-blocks' ); ?></p>
<a href="<?php echo esc_url( tsdk_utmify( 'https://themeisle.com/plugins/otter-blocks/upgrade/', 'form-submissions', 'admin' ) ); ?>" class="button button-primary" target="_blank"><?php esc_html_e( 'Explore Otter PRO', 'otter-blocks' ); ?></a>
<a href="<?php echo esc_url( tsdk_translate_link( tsdk_utmify( 'https://themeisle.com/plugins/otter-blocks/upgrade/', 'form-submissions', 'admin' ) ) ); ?>" class="button button-primary" target="_blank"><?php esc_html_e( 'Explore Otter PRO', 'otter-blocks' ); ?></a>
</div>
</div>
<?php
Expand All @@ -192,9 +192,7 @@ public function form_submissions_callback() {
* @access public
*/
public function enqueue_options_assets() {
$wp_upload_dir = wp_upload_dir( null, false );
$basedir = $wp_upload_dir['basedir'] . '/themeisle-gutenberg/';
$asset_file = include OTTER_BLOCKS_PATH . '/build/dashboard/index.asset.php';
$asset_file = include OTTER_BLOCKS_PATH . '/build/dashboard/index.asset.php';

wp_enqueue_style(
'otter-blocks-styles',
Expand All @@ -213,55 +211,67 @@ public function enqueue_options_assets() {

wp_set_script_translations( 'otter-blocks-scripts', 'otter-blocks' );

$offer = new LimitedOffers();

wp_localize_script(
'otter-blocks-scripts',
'otterObj',
apply_filters(
'otter_dashboard_data',
array(
'version' => OTTER_BLOCKS_VERSION,
'assetsPath' => OTTER_BLOCKS_URL . 'assets/',
'stylesExist' => is_dir( $basedir ) || boolval( get_transient( 'otter_animations_parsed' ) ),
'hasPro' => Pro::is_pro_installed(),
'upgradeLink' => tsdk_utmify( Pro::get_url(), 'options', Pro::get_reference() ),
'docsLink' => Pro::get_docs_url(),
'showFeedbackNotice' => $this->should_show_feedback_notice(),
'deal' => ! Pro::is_pro_installed() ? $offer->get_localized_data() : array(),
'hasOnboarding' => false !== get_theme_support( FSE_Onboarding::SUPPORT_KEY ),
'days_since_install' => round( ( time() - get_option( 'otter_blocks_install', time() ) ) / DAY_IN_SECONDS ),
'rootUrl' => get_site_url(),
'neveThemePreviewUrl' => esc_url(
add_query_arg(
array(
'theme' => 'neve',
),
admin_url( 'theme-install.php' )
)
$this->get_dashboard_data()
);

$this->load_survey();
}

/**
* Get the dashboard data to store in global object.
*
* @return array
*/
public function get_dashboard_data() {
$wp_upload_dir = wp_upload_dir( null, false );
$basedir = $wp_upload_dir['basedir'] . '/themeisle-gutenberg/';
$offer = new LimitedOffers();

$global_data = array(
'version' => OTTER_BLOCKS_VERSION,
'assetsPath' => OTTER_BLOCKS_URL . 'assets/',
'stylesExist' => is_dir( $basedir ) || boolval( get_transient( 'otter_animations_parsed' ) ),
'hasPro' => Pro::is_pro_installed(),
'upgradeLink' => tsdk_translate_link( tsdk_utmify( Pro::get_url(), 'options', Pro::get_reference() ) ),
'docsLink' => Pro::get_docs_url(),
'showFeedbackNotice' => $this->should_show_feedback_notice(),
'deal' => ! Pro::is_pro_installed() ? $offer->get_localized_data() : array(),
'hasOnboarding' => false !== get_theme_support( FSE_Onboarding::SUPPORT_KEY ),
'days_since_install' => (int) round( ( time() - get_option( 'otter_blocks_install', time() ) ) / DAY_IN_SECONDS ),
'rootUrl' => get_site_url(),
'neveThemePreviewUrl' => esc_url(
add_query_arg(
array(
'theme' => 'neve',
),
'neveThemeActivationUrl' => esc_url(
add_query_arg(
array(
'action' => 'activate',
'stylesheet' => 'neve',
'_wpnonce' => wp_create_nonce( 'switch-theme_neve' ),
),
admin_url( 'themes.php' )
)
admin_url( 'theme-install.php' )
)
),
'neveThemeActivationUrl' => esc_url(
add_query_arg(
array(
'action' => 'activate',
'stylesheet' => 'neve',
'_wpnonce' => wp_create_nonce( 'switch-theme_neve' ),
),
'neveDashboardUrl' => esc_url(
add_query_arg(
array(
'page' => 'neve-welcome',
),
admin_url( 'admin.php' )
)
admin_url( 'themes.php' )
)
),
'neveDashboardUrl' => esc_url(
add_query_arg(
array(
'page' => 'neve-welcome',
),
'neveInstalled' => defined( 'NEVE_VERSION' ),
admin_url( 'admin.php' )
)
)
),
'neveInstalled' => defined( 'NEVE_VERSION' ),
);

return apply_filters( 'otter_dashboard_data', $global_data );
}

/**
Expand Down Expand Up @@ -720,6 +730,18 @@ public function form_submissions_widget_content() {
<?php
}

/**
* Load the Formbricks deps from SDK to initiate the survey.
*/
private function load_survey() {
$survey_handler = apply_filters( 'themeisle_sdk_dependency_script_handler', 'survey' );
if ( empty( $survey_handler ) ) {
return;
}

do_action( 'themeisle_sdk_dependency_enqueue_script', 'survey' );
}

/**
* The instance method for the static class.
* Defines and returns the instance of the static class.
Expand Down
2 changes: 1 addition & 1 deletion otter-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function() {
'is_enabled' => ! defined( 'OTTER_PRO_VERSION' ),
'pro_name' => __( 'Otter Blocks Pro', 'otter-blocks' ),
'logo' => OTTER_BLOCKS_URL . '/assets/images/logo-alt.png',
'cta_link' => tsdk_utmify( 'https://themeisle.com/plugins/otter-blocks/upgrade/?discount=LOYALUSER583&dvalue=60#pricing', 'otter-welcome', 'notice' ),
'cta_link' => tsdk_translate_link( tsdk_utmify( 'https://themeisle.com/plugins/otter-blocks/upgrade/?discount=LOYALUSER583&dvalue=60#pricing', 'otter-welcome', 'notice' ) ),
];
}
);
Expand Down
37 changes: 14 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
"lasttranslator": "Themeisle Translate Team <[email protected]>"
},
"dependencies": {
"@formbricks/js": "^2.2.0",
"@wordpress/icons": "^9.46.0",
"array-move": "^3.0.1",
"classnames": "^2.5.1",
Expand All @@ -80,7 +79,7 @@
},
"devDependencies": {
"@automattic/babel-plugin-replace-textdomain": "^1.0.35",
"@playwright/test": "^1.48.1",
"@playwright/test": "^1.48.2",
"@semantic-release/changelog": "^6.0.3",
"@semantic-release/exec": "^6.0.3",
"@semantic-release/git": "^10.0.1",
Expand Down
31 changes: 17 additions & 14 deletions src/dashboard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
/**
* External dependencies.
*/
/* eslint-disable import/no-unresolved */
import formbricks from '@formbricks/js/app';

/**
* WordPress dependencies.
Expand Down Expand Up @@ -52,18 +50,6 @@ const convertToCategory = ( number, scale = 1 ) => {
}
};

if ( 'undefined' !== typeof window ) {
formbricks.init({
environmentId: 'clp9hqm8c1osfdl2ixwd0k0iz',
apiHost: 'https://app.formbricks.com',
userId: 'otter_' + ( undefined !== window.otterObj?.license?.key ? window.otterObj.license.key : window.otterObj.rootUrl.replace( /[^\w\d]*/g, '' ) ),
attributes: {
plan: undefined !== window.otterObj?.license?.type ? window.otterObj.license.type : 'free',
days_since_install: convertToCategory( window.otterObj.days_since_install )
}
});
}

const App = () => {
const [ currentTab, setTab ] = useState( getInitialStateFromURLQuery() );

Expand All @@ -89,3 +75,20 @@ const App = () => {
const root = createRoot( document.getElementById( 'otter' ) );

root.render( <App /> );

/**
* Initialize the formbricks survey.
*
* @see https://github.com/formbricks/setup-examples/tree/main/html
*/
window.addEventListener('themeisle:survey:loaded', function () {
window?.tsdk_formbricks?.init?.({
environmentId: 'clp9hqm8c1osfdl2ixwd0k0iz',
apiHost: 'https://app.formbricks.com',
userId: 'otter_' + ( undefined !== window.otterObj?.license?.key ? window.otterObj.license.key : window.otterObj.rootUrl.replace( /[^\w\d]*/g, '' ) ),
attributes: {
plan: undefined !== window.otterObj?.license?.type ? window.otterObj.license.type : 'free',
days_since_install: convertToCategory( window.otterObj.days_since_install )
}
});
});
Loading

0 comments on commit 48d2f1d

Please sign in to comment.