PluginProbe
WPIDE – File Manager & Code Editor / 3.5.9
WPIDE – File Manager & Code Editor v3.5.9
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.9, at App/Classes/Freemius.php

269 lines 10.1 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 // Only sanitize when rendering the pricing page — never on admin-ajax,
110 // where the pricing JS legitimately passes these same params (incl. `action`).
111 if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
112 return;
113 }
114 $page = ( isset( $_GET['page'] ) && is_string( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : '' );
115 if ( SLUG . '-pricing' !== $page ) {
116 return;
117 }
118 foreach ( self::RESERVED_PRICING_REQUEST_PARAMETERS as $parameter ) {
119 unset($_GET[$parameter], $_REQUEST[$parameter]);
120 }
121 }
122
123 public static function admin_enqueue_scripts() {
124 if ( App::instance()->isFreemiusScreen() ) {
125 self::freemius_custom_styles();
126 }
127 }
128
129 public static function freemius_custom_styles() {
130 wp_enqueue_style(
131 SLUG . '-fs-connect',
132 ASSETS_URL . 'css/freemius/freemius.css',
133 [],
134 VERSION
135 );
136 }
137
138 public static function beforeConnectBox() {
139 wp_enqueue_style(
140 SLUG . '-fs-connect',
141 ASSETS_URL . 'css/freemius/freemius.css',
142 [],
143 VERSION
144 );
145 echo '<div id="fs-connect-wrap">';
146 }
147
148 public static function afterConnectBox() {
149 echo '</div>';
150 }
151
152 public static function afterPurchaseJs() : string {
153 return 'function ( data ) {
154
155 /**
156 * Since the user just entered their personal & billing information, agreed to the TOS & privacy,
157 * know they are running within a secure iframe from an external domain, they implicitly permit tracking
158 * this purchase. So initializing GTM here (after the purchase), is legitimate.
159 */
160
161 var is_subscription = typeof(data.purchase.initial_amount) !== "undefined";
162 var is_trial = typeof(data.purchase.trial_ends) !== "undefined" && data.purchase.trial_ends !== null;
163 var total = is_subscription ? data.purchase.initial_amount : data.purchase.gross;
164 total = is_trial ? 0 : total;
165
166 var coupon = data && data.coupon ? data.coupon.code : "";
167 var currency = data && data.currency ? data.currency.toUpperCase() : "USD";
168
169 var item = {
170 item_name: "' . NAME . '",
171 item_id: ' . FS_ID . ',
172 item_brand: "' . AUTHOR . '",
173 affiliation: "' . AUTHOR . '",
174 price: data.total,
175 discount: 0,
176 currency: currency,
177 coupon: coupon,
178 index: 1,
179 quantity: 1
180 };
181
182 // Purchase Event
183 dataLayer.push({ ecommerce: null }); // Clear the previous ecommerce object.
184 dataLayer.push({
185 event: "purchase",
186 ecommerce: {
187 transaction_id: data.purchase.id,
188 affiliation: item.affiliation,
189 tax: 0,
190 shipping: 0,
191 items: [item],
192 currency: item.currency,
193 coupon: item.coupon,
194 value: total
195 }
196 });
197 }';
198 }
199
200 public static function checkoutGtmScript( $html ) : string {
201 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;
202 }
203
204 public static function pricingJsPath() : string {
205 return ASSETS_DIR . 'pricing/freemius-pricing.js';
206 }
207
208 public static function pluginIcon() : string {
209 return ASSETS_DIR . 'img/icon.png';
210 }
211
212 /**
213 * Add license dialog boxes
214 *
215 * @since 1.0.0
216 */
217 public static function addLicenseActivationDialogBox() {
218 if ( !did_action( SLUG . '_license_activation_dialog_added' ) && !App::instance()->isFreemiusScreen( 'account' ) ) {
219 self::sdk()->_add_license_activation_dialog_box();
220 fs_enqueue_local_style( 'fs_dialog_boxes', '/admin/dialog-boxes.css' );
221 do_action( SLUG . '_license_activation_dialog_added' );
222 }
223 }
224
225 public static function showSubmenus() : bool {
226 $is_activation_mode = self::sdk()->is_activation_mode();
227 if ( $is_activation_mode ) {
228 $show_submenus = false;
229 } else {
230 if ( fs_is_network_admin() ) {
231 /**
232 * Add submenu items or action links to network level when plugin was network activated and the super
233 * admin did NOT delegate the connection of all sites to site admins.
234 */
235 $show_submenus = App::instance()->isNetworkActive() && (WP_FS__SHOW_NETWORK_EVEN_WHEN_DELEGATED || !self::sdk()->is_network_delegated_connection());
236 } else {
237 $show_submenus = !App::instance()->isNetworkActive() || self::sdk()->is_delegated_connection();
238 }
239 }
240 return $show_submenus;
241 }
242
243 public static function showUpgradeLink() : bool {
244 $show_submenus = self::showSubmenus();
245 $is_activation_mode = self::sdk()->is_activation_mode();
246 $add_upgrade_link = ($show_submenus || $is_activation_mode && self::sdk()->is_only_premium()) && !self::sdk()->is_whitelabeled();
247 return $add_upgrade_link && self::sdk()->is_pricing_page_visible() && self::sdk()->is_submenu_item_visible( 'pricing' );
248 }
249
250 public static function showTrialLink() : bool {
251 return self::sdk()->apply_filters( 'show_trial', true ) && self::sdk()->has_trial_plan() && !self::sdk()->is_trial_utilized();
252 }
253
254 public static function sdk() : \Freemius {
255 return self::$fs;
256 }
257
258 public static function loaded() : bool {
259 return self::$loaded;
260 }
261
262 public static function override_freemius_strings() : void {
263 self::$fs->override_i18n( array(
264 'contact-us' => __( 'Support', 'wpide' ),
265 ) );
266 }
267
268 }
269