-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathfreemius-dashboard.php
More file actions
143 lines (117 loc) · 4.67 KB
/
Copy pathfreemius-dashboard.php
File metadata and controls
143 lines (117 loc) · 4.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
/**
* Plugin Name: Freemius Customer Portal
* Plugin URI: https://freemius.com/
* Description: Embeddable the Customer Portal for Freemius powered shops and products.
* Version: 1.0.2
* Author: Freemius
* Author URI: https://freemius.com
* License: MIT
*/
/**
* @package Freemius Customer Portal
* @copyright Copyright (c) 2018, Freemius, Inc.
* @license https://opensource.org/licenses/mit MIT License
* @since 1.0.2
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! defined( 'WP_FS__MEMBERS_DASHBOARD_DEBUG' ) ) {
define( 'WP_FS__MEMBERS_DASHBOARD_DEBUG', false );
}
if ( ! defined( 'WP_FS__MEMBERS_DASHBOARD_SUBDOMAIN' ) ) {
define( 'WP_FS__MEMBERS_DASHBOARD_SUBDOMAIN', WP_FS__MEMBERS_DASHBOARD_DEBUG ?
'http://customers.freemius-local.com:4200/dashboard.js' :
'https://customers.freemius.com/js/v1/'
);
}
/**
* Example:
* [fs_members store_id="<storeID>" public_key="<storePublicKey>" position="fixed" left="0" right="0" top="195px" bottom="0"]
*
* @param $atts
* @param null $inner
*
* @return string
*/
function fs_members_dashboard_shortcode( $atts, $inner = null ) {
$store_id = isset( $atts['store_id'] ) && is_numeric( $atts['store_id'] ) ? $atts['store_id'] : null;
$public_key = isset( $atts['public_key'] ) && is_string( $atts['public_key'] ) ? $atts['public_key'] : null;
if ( ! is_numeric( $store_id ) || empty($public_key) ) {
return '<p style="font-weight: bold; color: red;">You have to specify the store_id and its public_key to embed the Freemius Customer Portal securely to your site.</p>';
}
$product_id = isset( $atts['product_id'] ) && is_numeric( $atts['product_id'] ) ? $atts['product_id'] : null;
$css = array(
'position' => 'relative',
'top' => 'auto',
'bottom' => 'auto',
'left' => 'auto',
'right' => 'auto',
'zIndex' => '2',
);
foreach ( $css as $k => $v ) {
if ( isset( $atts[ $k ] ) ) {
$css[ $k ] = $atts[ $k ];
}
}
// Fix props.
$numeric_props = array( 'top' => true, 'bottom' => true, 'left' => true, 'right' => true );
foreach ( $css as $k => $v ) {
if ( ! isset( $numeric_props[ $k ] ) ) {
continue;
}
if ( is_numeric( $v ) ) {
$css[ $k ] = "{$v}px";
}
}
$cache_killer = WP_FS__MEMBERS_DASHBOARD_DEBUG ?
// Clear cache every time on debug mode.
date('Y-m-d H:i:s') :
// Clear cache on an hourly basis.
date('Y-m-d H');
$user_id = null;
$access_token = null;
$is_sso_active = class_exists( 'FS_SSO' );
if ( is_user_logged_in() && $is_sso_active ) {
$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;
}
}
$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( $user_id ) && !empty($access_token)) {
$dashboard_params['user_id'] = $user_id;
$dashboard_params['token'] = $access_token;
}
$open_params = '';
if ( $is_sso_active ) {
$open_params = '{ afterLogout: function() { window.location.href = \'' . str_replace( '&', '&', wp_logout_url() ) . '\'; }}';
}
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(' . $open_params . ');
})();
</script>
');
}
function fs_add_members_dashboard_shortcode() {
wp_enqueue_script( 'jquery' );
add_shortcode( 'fs_members', 'fs_members_dashboard_shortcode' );
}
add_action( 'init', 'fs_add_members_dashboard_shortcode' );