Skip to content

Commit

Permalink
[pricing] [update] Use the bundled version of pricing SPA and remove …
Browse files Browse the repository at this point in the history
…the iFrame.
  • Loading branch information
swashata committed Oct 3, 2024
1 parent dcea1ac commit 9244b95
Show file tree
Hide file tree
Showing 18 changed files with 1,150 additions and 108 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
227 changes: 227 additions & 0 deletions assets/js/pricing/4529cac82a2d1f300d3c4702b7b5e8f3.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
402 changes: 402 additions & 0 deletions assets/js/pricing/b4f3b958f4a019862d81b15f3f8eee3a.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
227 changes: 227 additions & 0 deletions assets/js/pricing/f18006f6535a1a6e9c6bfbffafe6f18a.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
227 changes: 227 additions & 0 deletions assets/js/pricing/f928f1be99776af83e8e6be4baf8ffe7.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions assets/js/pricing/freemius-pricing.js

Large diffs are not rendered by default.

45 changes: 45 additions & 0 deletions assets/js/pricing/freemius-pricing.js.LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
object-assign
(c) Sindre Sorhus
@license MIT
*/

/*!
* Determine if an object is a Buffer
*
* @author Feross Aboukhadijeh <https://feross.org>
* @license MIT
*/

/*!
* Font Awesome Free 6.0.0 by @fontawesome - https://fontawesome.com
* License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License)
* Copyright 2022 Fonticons, Inc.
*/

/** @license React v0.20.2
* scheduler.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/** @license React v17.0.2
* react-dom.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/** @license React v17.0.2
* react.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
35 changes: 15 additions & 20 deletions includes/class-freemius.php
Original file line number Diff line number Diff line change
Expand Up @@ -379,13 +379,6 @@ class Freemius extends Freemius_Abstract {

#endregion

/**
* @author Leo Fajardo (@leorw)
* @since 2.3.1
*
* @var boolean|null
*/
private $_use_external_pricing = null;
/**
* @author Leo Fajardo (@leorw)
* @since 2.4.2
Expand Down Expand Up @@ -1501,7 +1494,7 @@ private function register_constructor_hooks() {
}

add_action( 'init', array( &$this, '_maybe_add_gdpr_optin_ajax_handler') );
add_action( 'init', array( &$this, '_maybe_add_pricing_ajax_handler' ) );
add_action( 'init', array( &$this, '_add_pricing_ajax_handler' ) );
}

if ( $this->is_plugin() ) {
Expand Down Expand Up @@ -13610,8 +13603,11 @@ function activate_migrated_license(
*/
function get_pricing_js_path() {
if ( ! isset( $this->_pricing_js_path ) ) {
$pricing_js_path = $this->apply_filters( 'freemius_pricing_js_path', '' );
$default_path = WP_FS__DIR_JS . '/pricing/freemius-pricing.js';

$pricing_js_path = $this->apply_filters( 'freemius_pricing_js_path', $default_path );

// Backward compatibility for people who placed the freemius-pricing inside `includes` directory. Let it take more preference than the default path.
if ( empty( $pricing_js_path ) ) {
global $fs_active_plugins;

Expand All @@ -13630,6 +13626,11 @@ function get_pricing_js_path() {
}
}

// If it is still empty, load the default pricing JS.
if ( ! file_exists( $pricing_js_path ) ) {
$pricing_js_path = $default_path;
}

$this->_pricing_js_path = $pricing_js_path;
}

Expand All @@ -13640,16 +13641,12 @@ function get_pricing_js_path() {
* @author Leo Fajardo (@leorw)
* @since 2.3.1
*
* @deprecated Since v2.9.0 we have removed the iFrame based pricing. This will always return `false`.
*
* @return bool
*/
function should_use_external_pricing() {
if ( is_null( $this->_use_external_pricing ) ) {
$pricing_js_path = $this->get_pricing_js_path();

$this->_use_external_pricing = ( empty( $pricing_js_path ) || ! file_exists( $pricing_js_path ) );
}

return $this->_use_external_pricing;
return false;
}

/**
Expand Down Expand Up @@ -23326,10 +23323,8 @@ function _pricing_page_render() {
* @author Leo Fajardo (@leorw)
* @since 2.3.1
*/
function _maybe_add_pricing_ajax_handler() {
if ( ! $this->should_use_external_pricing() ) {
$this->add_ajax_action( 'pricing_ajax_action', array( &$this, '_fs_pricing_ajax_action_handler' ) );
}
function _add_pricing_ajax_handler() {
$this->add_ajax_action( 'pricing_ajax_action', array( &$this, '_fs_pricing_ajax_action_handler' ) );
}

/**
Expand Down
93 changes: 5 additions & 88 deletions templates/pricing.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,9 @@

/**
* Note for WordPress.org Theme/Plugin reviewer:
* Freemius is an SDK for plugin and theme developers. Since the core
* of the SDK is relevant both for plugins and themes, for obvious reasons,
* we only develop and maintain one code base.
*
* This code (and page) will not run for wp.org themes (only plugins).
*
* In addition, this page loads an i-frame. We intentionally named it 'frame'
* so it will pass the "Theme Check" that is looking for the string "i" . "frame".
*
* UPDATE:
* After ongoing conversations with the WordPress.org TRT we received
* an official approval for including i-frames in the theme's WP Admin setting's
* page tab (the SDK will never add any i-frames on the sitefront). i-frames
* were never against the guidelines, but we wanted to get the team's blessings
* before we move forward. For the record, I got the final approval from
* Ulrich Pogson (@grapplerulrich), a team lead at the TRT during WordCamp
* Europe 2017 (June 16th, 2017).
* Freemius is an SDK for plugin and theme developers. This page will not
* load any external resources or make any remote requests. It's will use
* API (through WP-AJAX) and JavaScript (React) to render a pricing page.
*
* If you have any questions or need clarifications, please don't hesitate
* pinging me on slack, my username is @svovaf.
Expand Down Expand Up @@ -92,25 +78,9 @@
'discounts_model' => $fs->apply_filters( 'pricing/discounts_model', 'absolute' ),
) );

$use_external_pricing = $fs->should_use_external_pricing();
$pricing_js_url = fs_asset_url( $fs->get_pricing_js_path() );

if ( ! $use_external_pricing ) {
$pricing_js_url = fs_asset_url( $fs->get_pricing_js_path() );
wp_enqueue_script( 'freemius-pricing', $pricing_js_url );
} else {
if ( ! $fs->is_registered() ) {
$template_data = array(
'id' => $fs->get_id(),
);
fs_require_template( 'forms/trial-start.php', $template_data);
}

$view_params = array(
'id' => $VARS['id'],
'page' => strtolower( $fs->get_text_x_inline( 'Pricing', 'noun', 'pricing' ) ),
);
fs_require_once_template('secure-https-header.php', $view_params);
}
wp_enqueue_script( 'freemius-pricing', $pricing_js_url );

$has_tabs = $fs->_add_tabs_before_content();

Expand All @@ -119,7 +89,6 @@
}
?>
<div id="fs_pricing" class="wrap fs-section fs-full-size-wrapper">
<?php if ( ! $use_external_pricing ) : ?>
<div id="fs_pricing_wrapper" data-public-url="<?php echo trailingslashit( dirname( $pricing_js_url ) ) ?>"></div>
<?php
$pricing_config = array_merge( array(
Expand All @@ -142,58 +111,6 @@

wp_add_inline_script( 'freemius-pricing', 'Freemius.pricing.new( ' . json_encode( $pricing_config ) . ' )' );
?>
<?php else : ?>
<div id="fs_frame"></div>
<form action="" method="POST">
<input type="hidden" name="user_id"/>
<input type="hidden" name="user_email"/>
<input type="hidden" name="site_id"/>
<input type="hidden" name="public_key"/>
<input type="hidden" name="secret_key"/>
<input type="hidden" name="action" value="account"/>
</form>

<script type="text/javascript">
(function ($, undef) {
$(function () {
var
// Keep track of the i-frame height.
frame_height = 800,
base_url = '<?php echo WP_FS__ADDRESS ?>',
// Pass the parent page URL into the i-frame in a meaningful way (this URL could be
// passed via query string or hard coded into the child page, it depends on your needs).
src = base_url + '/pricing/?<?php echo http_build_query( $query_params ) ?>#' + encodeURIComponent(document.location.href),

// Append the I-frame into the DOM.
frame = $('<i' + 'frame " src="' + src + '" width="100%" height="' + frame_height + 'px" scrolling="no" frameborder="0" style="background: transparent; width: 1px; min-width: 100%;"><\/i' + 'frame>')
.appendTo('#fs_frame');

FS.PostMessage.init(base_url, [frame[0]]);

FS.PostMessage.receive('height', function (data) {
var h = data.height;
if (!isNaN(h) && h > 0 && h != frame_height) {
frame_height = h;
frame.height(frame_height + 'px');

FS.PostMessage.postScroll(frame[0]);
}
});

FS.PostMessage.receive('get_dimensions', function (data) {
FS.PostMessage.post('dimensions', {
height : $(document.body).height(),
scrollTop: $(document).scrollTop()
}, frame[0]);
});

FS.PostMessage.receive('start_trial', function (data) {
openTrialConfirmationModal(data);
});
});
})(jQuery);
</script>
<?php endif ?>
</div>
<?php
if ( $has_tabs ) {
Expand Down

0 comments on commit 9244b95

Please sign in to comment.