Skip to content
Closed
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
69 changes: 24 additions & 45 deletions freemius-dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Freemius Customer Portal
* Plugin URI: https://freemius.com/
* Description: Embeddable the Customer Portal for Freemius powered shops and products.
* Version: 1.0.0
* Version: 1.0.1
* Author: Freemius
* Author URI: https://freemius.com
* License: MIT
Expand Down Expand Up @@ -84,57 +84,36 @@ function fs_members_dashboard_shortcode( $atts, $inner = null ) {
// Clear cache on an hourly basis.
date('Y-m-d H');

$user_id = null;
$access_token = null;

if ( is_user_logged_in() && class_exists( 'FS_SSO' ) ) {
$sso = FS_SSO::instance();

$user_id = $sso->get_freemius_user_id();

if ( is_numeric( $user_id ) ) {
$access_token = $sso->get_freemius_access_token();

$access_token = is_object( $access_token ) ?
$access_token->access :
null;
// Enqueue jQuery and the dashboard script via WP, and attach the inline initializer so it runs
// after the remote script is loaded. We do not output raw <script> tags anymore.
if ( ! is_admin() ) {
wp_enqueue_script( 'jquery' );

wp_enqueue_script(
'fs-members-dashboard',
WP_FS__MEMBERS_DASHBOARD_SUBDOMAIN . '?ck=' . $cache_killer,
array( 'jquery' ),
null,
true
);

$inline = '(function(){FS.Members.configure({css: ' . json_encode( $css ) . ', public_key: \'' . $public_key . '\'';
if ( is_numeric( $store_id ) ) {
$inline .= ', store_id: \'' . $store_id . '\'';
}
}

$dashboard_params = array(
'css' => $css,
'public_key' => $public_key,
);

if (is_numeric( $store_id )) {
$dashboard_params['store_id'] = $store_id;
}

if (is_numeric( $product_id )) {
$dashboard_params['product_id'] = $product_id;
}
if ( is_numeric( $product_id ) ) {
$inline .= ', product_id: \'' . $product_id . '\'';
}
$inline .= '}).open();})();';

if (is_numeric( $user_id ) && !empty($access_token)) {
$dashboard_params['user_id'] = $user_id;
$dashboard_params['token'] = $access_token;
wp_add_inline_script( 'fs-members-dashboard', $inline );
}

return apply_filters( 'fs_members_dashboard', '
<script type="text/javascript" src="' . WP_FS__MEMBERS_DASHBOARD_SUBDOMAIN . '?ck=' . $cache_killer . '"></script>
<script id="fs_dashboard_anchor" type="text/javascript">
(function(){
FS.Members.configure(' . json_encode( $dashboard_params ) . ').open({
afterLogout: function() {
window.location.href = \'' . str_replace( '&amp;', '&', wp_logout_url() ) . '\';
}
});
})();
</script>
');
return '';
}

function fs_add_members_dashboard_shortcode() {
wp_enqueue_script( 'jquery' );
wp_enqueue_style( 'jquery' );
add_shortcode( 'fs_members', 'fs_members_dashboard_shortcode' );
}

Expand Down