PluginProbe
WPIDE – File Manager & Code Editor / 3.5.8
WPIDE – File Manager & Code Editor v3.5.8
3.5.9 3.5.8 3.5.7 2.0.14 2.0.15 2.0.16 2.0.2 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1 2.2 2.3 2.3.1 2.3.2 2.4.0 2.5 2.6 3.0 3.1 3.2 3.3 All 55 releases
wpide / App / Classes / Freemius.php

Freemius.php in WPIDE – File Manager & Code Editor 3.5.8, at App/Classes/Freemius.php

264 lines 9.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WPIDE\App\Classes;
4
5 use Freemius_Api;
6 use WPIDE\App\App;
7 use const WPIDE\Constants\ASSETS_DIR;
8 use const WPIDE\Constants\ASSETS_URL;
9 use const WPIDE\Constants\AUTHOR;
10 use const WPIDE\Constants\DIR;
11 use const WPIDE\Constants\FS_ID;
12 use const WPIDE\Constants\FS_KEY;
13 use const WPIDE\Constants\GTM_ID;
14 use const WPIDE\Constants\NAME;
15 use const WPIDE\Constants\SLUG;
16 use const WPIDE\Constants\VERSION;
17 class Freemius {
18 private const RESERVED_PRICING_REQUEST_PARAMETERS = [
19 'action',
20 'bundle_id',
21 'contact_url',
22 'disable_single_package',
23 'fs_wp_endpoint_url',
24 'home_url',
25 'is_production',
26 'license',
27 'menu_slug',
28 'mode',
29 'module_id',
30 'plugin_icon',
31 'plugin_id',
32 'plugin_public_key',
33 'plugin_version',
34 'pricing_action',
35 'request_handler_url',
36 's_ctx_id',
37 's_ctx_secure',
38 's_ctx_ts',
39 's_ctx_type',
40 'sandbox',
41 'security',
42 'selector',
43 'show_annual_in_monthly',
44 'unique_affix'
45 ];
46
47 public static $fs;
48
49 public static $api;
50
51 public static $loaded = false;
52
53 /**
54 * @throws \Freemius_Exception
55 */
56 public static function init() {
57 if ( !isset( self::$fs ) ) {
58 self::sanitizePricingRequest();
59 if ( !defined( 'WP_FS__PRODUCT_' . FS_ID . '_MULTISITE' ) ) {
60 define( 'WP_FS__PRODUCT_' . FS_ID . '_MULTISITE', true );
61 }
62 // Init Freemius SDK.
63 require_once DIR . 'freemius/start.php';
64 self::$fs = fs_dynamic_init( array(
65 'id' => FS_ID,
66 'slug' => SLUG,
67 'premium_slug' => SLUG . '-pro',
68 'type' => 'plugin',
69 'public_key' => FS_KEY,
70 'is_premium' => false,
71 'premium_suffix' => 'Pro',
72 'has_addons' => false,
73 'has_paid_plans' => true,
74 'trial' => array(
75 'days' => 14,
76 'is_require_payment' => true,
77 ),
78 'menu' => array(
79 'slug' => SLUG,
80 'support' => false,
81 'affiliation' => false,
82 'network' => true,
83 ),
84 'is_live' => true,
85 'is_org_compliant' => true,
86 ) );
87 $GLOBALS['wpide_fs'] = self::$fs;
88 self::$fs->add_action( 'connect/before', [__CLASS__, 'beforeConnectBox'] );
89 self::$fs->add_action( 'connect/after', [__CLASS__, 'afterConnectBox'] );
90 self::$fs->add_filter( 'checkout/purchaseCompleted', [__CLASS__, 'afterPurchaseJs'] );
91 self::$fs->add_filter( 'templates/checkout.php', [__CLASS__, 'checkoutGtmScript'] );
92 self::$fs->add_filter( 'freemius_pricing_js_path', [__CLASS__, 'pricingJsPath'] );
93 self::$fs->add_filter( 'plugin_icon', [__CLASS__, 'pluginIcon'] );
94 self::$fs->add_filter( 'hide_account_tabs', '__return_true' );
95 self::$fs->add_filter( 'hide_freemius_powered_by', '__return_true' );
96 self::$fs->add_filter( 'hide_billing_and_payments_info', '__return_true' );
97 self::$fs->add_action( 'plugins_loaded', [__CLASS__, 'override_freemius_strings'] );
98 add_action( 'admin_enqueue_scripts', [__CLASS__, 'admin_enqueue_scripts'] );
99 self::$loaded = true;
100 // Signal that SDK was initiated.
101 do_action( 'wpide_fs_loaded' );
102 }
103 }
104
105 /**
106 * Prevent request parameters from overriding trusted pricing-page config.
107 */
108 public static function sanitizePricingRequest() : void {
109 $page = ( isset( $_GET['page'] ) && is_string( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : '' );
110 if ( SLUG . '-pricing' !== $page ) {
111 return;
112 }
113 foreach ( self::RESERVED_PRICING_REQUEST_PARAMETERS as $parameter ) {
114 unset($_GET[$parameter], $_REQUEST[$parameter]);
115 }
116 }
117
118 public static function admin_enqueue_scripts() {
119 if ( App::instance()->isFreemiusScreen() ) {
120 self::freemius_custom_styles();
121 }
122 }
123
124 public static function freemius_custom_styles() {
125 wp_enqueue_style(
126 SLUG . '-fs-connect',
127 ASSETS_URL . 'css/freemius/freemius.css',
128 [],
129 VERSION
130 );
131 }
132
133 public static function beforeConnectBox() {
134 wp_enqueue_style(
135 SLUG . '-fs-connect',
136 ASSETS_URL . 'css/freemius/freemius.css',
137 [],
138 VERSION
139 );
140 echo '<div id="fs-connect-wrap">';
141 }
142
143 public static function afterConnectBox() {
144 echo '</div>';
145 }
146
147 public static function afterPurchaseJs() : string {
148 return 'function ( data ) {
149
150 /**
151 * Since the user just entered their personal & billing information, agreed to the TOS & privacy,
152 * know they are running within a secure iframe from an external domain, they implicitly permit tracking
153 * this purchase. So initializing GTM here (after the purchase), is legitimate.
154 */
155
156 var is_subscription = typeof(data.purchase.initial_amount) !== "undefined";
157 var is_trial = typeof(data.purchase.trial_ends) !== "undefined" && data.purchase.trial_ends !== null;
158 var total = is_subscription ? data.purchase.initial_amount : data.purchase.gross;
159 total = is_trial ? 0 : total;
160
161 var coupon = data && data.coupon ? data.coupon.code : "";
162 var currency = data && data.currency ? data.currency.toUpperCase() : "USD";
163
164 var item = {
165 item_name: "' . NAME . '",
166 item_id: ' . FS_ID . ',
167 item_brand: "' . AUTHOR . '",
168 affiliation: "' . AUTHOR . '",
169 price: data.total,
170 discount: 0,
171 currency: currency,
172 coupon: coupon,
173 index: 1,
174 quantity: 1
175 };
176
177 // Purchase Event
178 dataLayer.push({ ecommerce: null }); // Clear the previous ecommerce object.
179 dataLayer.push({
180 event: "purchase",
181 ecommerce: {
182 transaction_id: data.purchase.id,
183 affiliation: item.affiliation,
184 tax: 0,
185 shipping: 0,
186 items: [item],
187 currency: item.currency,
188 coupon: item.coupon,
189 value: total
190 }
191 });
192 }';
193 }
194
195 public static function checkoutGtmScript( $html ) : string {
196 return "\n <script>window.dataLayer = window.dataLayer || [];</script>\n <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':\n new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],\n j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=\n 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);\n })(window,document,'script','dataLayer', '" . GTM_ID . "');</script>\n " . $html;
197 }
198
199 public static function pricingJsPath() : string {
200 return ASSETS_DIR . 'pricing/freemius-pricing.js';
201 }
202
203 public static function pluginIcon() : string {
204 return ASSETS_DIR . 'img/icon.png';
205 }
206
207 /**
208 * Add license dialog boxes
209 *
210 * @since 1.0.0
211 */
212 public static function addLicenseActivationDialogBox() {
213 if ( !did_action( SLUG . '_license_activation_dialog_added' ) && !App::instance()->isFreemiusScreen( 'account' ) ) {
214 self::sdk()->_add_license_activation_dialog_box();
215 fs_enqueue_local_style( 'fs_dialog_boxes', '/admin/dialog-boxes.css' );
216 do_action( SLUG . '_license_activation_dialog_added' );
217 }
218 }
219
220 public static function showSubmenus() : bool {
221 $is_activation_mode = self::sdk()->is_activation_mode();
222 if ( $is_activation_mode ) {
223 $show_submenus = false;
224 } else {
225 if ( fs_is_network_admin() ) {
226 /**
227 * Add submenu items or action links to network level when plugin was network activated and the super
228 * admin did NOT delegate the connection of all sites to site admins.
229 */
230 $show_submenus = App::instance()->isNetworkActive() && (WP_FS__SHOW_NETWORK_EVEN_WHEN_DELEGATED || !self::sdk()->is_network_delegated_connection());
231 } else {
232 $show_submenus = !App::instance()->isNetworkActive() || self::sdk()->is_delegated_connection();
233 }
234 }
235 return $show_submenus;
236 }
237
238 public static function showUpgradeLink() : bool {
239 $show_submenus = self::showSubmenus();
240 $is_activation_mode = self::sdk()->is_activation_mode();
241 $add_upgrade_link = ($show_submenus || $is_activation_mode && self::sdk()->is_only_premium()) && !self::sdk()->is_whitelabeled();
242 return $add_upgrade_link && self::sdk()->is_pricing_page_visible() && self::sdk()->is_submenu_item_visible( 'pricing' );
243 }
244
245 public static function showTrialLink() : bool {
246 return self::sdk()->apply_filters( 'show_trial', true ) && self::sdk()->has_trial_plan() && !self::sdk()->is_trial_utilized();
247 }
248
249 public static function sdk() : \Freemius {
250 return self::$fs;
251 }
252
253 public static function loaded() : bool {
254 return self::$loaded;
255 }
256
257 public static function override_freemius_strings() : void {
258 self::$fs->override_i18n( array(
259 'contact-us' => __( 'Support', 'wpide' ),
260 ) );
261 }
262
263 }
264