PluginProbe
Copy Anything to Clipboard for WordPress – Copy Button, Copy Text & Copy Code / 5.5.3
Copy Anything to Clipboard for WordPress – Copy Button, Copy Text & Copy Code v5.5.3
5.5.3 3.1.0 3.2.0 3.2.1 3.3.0 3.4.0 3.4.1 3.4.2 3.4.3 3.5.0 3.5.1 3.5.2 3.6.0 3.7.0 3.8.0 3.8.1 3.8.2 3.8.3 4.0.0 4.0.2 4.0.3 4.0.4 4.0.5 4.1.0 4.1.1 All 78 releases
copy-the-code / includes / freemius.php

freemius.php in Copy Anything to Clipboard for WordPress – Copy Button, Copy Text & Copy Code 5.5.3, at includes/freemius.php

117 lines 3.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Freemius helper.
5 *
6 * @package CTC
7 */
8 use CTC\Telemetry;
9 /**
10 * Create a helper function for easy SDK access.
11 *
12 * @return object|null Freemius SDK instance, or null if not yet initialized.
13 */
14 function ctc_fs() {
15 global $ctc_fs;
16 // Return existing instance if already initialized.
17 if ( isset( $ctc_fs ) ) {
18 return $ctc_fs;
19 }
20 // Don't initialize before plugins_loaded to avoid early translation loading (WP 6.7+).
21 if ( !did_action( 'plugins_loaded' ) ) {
22 return null;
23 }
24 // Include Freemius SDK from Composer vendor directory.
25 $freemius_sdk_path = dirname( __DIR__ ) . '/vendor/freemius/wordpress-sdk/start.php';
26 if ( !file_exists( $freemius_sdk_path ) ) {
27 wp_die( 'Freemius SDK not found. Please run: composer install' );
28 }
29 require_once $freemius_sdk_path;
30 $ctc_fs = fs_dynamic_init( [
31 'id' => '2780',
32 'slug' => 'ctc',
33 'type' => 'plugin',
34 'public_key' => 'pk_15a174f8c30f506a9a35ccbf0fa76',
35 'is_premium' => false,
36 'premium_suffix' => 'Premium',
37 'has_addons' => false,
38 'has_paid_plans' => true,
39 'has_affiliation' => 'selected',
40 'menu' => [
41 'slug' => 'ctc-global-injector',
42 'override_exact' => true,
43 'first-path' => 'options-general.php?page=ctc-global-injector',
44 'contact' => true,
45 'support' => true,
46 'affiliation' => false,
47 'parent' => [
48 'slug' => 'options-general.php',
49 ],
50 ],
51 'is_live' => true,
52 'is_org_compliant' => true,
53 ] );
54 // Signal that SDK was initiated.
55 do_action( 'ctc/freemius/loaded' );
56 return $ctc_fs;
57 }
58
59 /**
60 * Initialize Freemius SDK and add filters.
61 *
62 * Called on plugins_loaded to avoid early translation loading issues.
63 */
64 function ctc_fs_init() {
65 $fs = ctc_fs();
66 if ( !$fs ) {
67 return;
68 }
69 // @phpstan-ignore-next-line
70 $fs->add_filter( 'connect_url', 'ctc_fs_settings_url' );
71 // @phpstan-ignore-next-line
72 $fs->add_filter( 'after_skip_url', 'ctc_fs_settings_url' );
73 // @phpstan-ignore-next-line
74 $fs->add_filter( 'after_connect_url', 'ctc_fs_settings_url' );
75 // @phpstan-ignore-next-line
76 $fs->add_filter( 'after_pending_connect_url', 'ctc_fs_settings_url' );
77 // @phpstan-ignore-next-line
78 $fs->add_filter( 'after_pending_connect_url', 'ctc_enable_telemetry' );
79 // Clean up telemetry options when user uninstalls (Freemius runs this via after_uninstall).
80 // Do not add uninstall.php in plugin root — Freemius requires it absent to track uninstall feedback.
81 $fs->add_action( 'after_uninstall', 'ctc_cleanup_on_uninstall' );
82 }
83
84 /**
85 * Enable telemetry.
86 */
87 function ctc_enable_telemetry() {
88 Telemetry::set_opt_in( true );
89 Telemetry::maybe_send();
90 Telemetry::schedule_cron();
91 return ctc_fs_settings_url();
92 }
93
94 /**
95 * Clean up plugin options on uninstall (called by Freemius after_uninstall hook).
96 *
97 * Install identity is domain-based (no stored install id), so reinstall on same domain keeps the same id.
98 */
99 function ctc_cleanup_on_uninstall() {
100 delete_option( 'ctc_telemetry_opt_in' );
101 delete_option( 'ctc_telemetry_first_seen' );
102 delete_option( 'ctc_telemetry_last_sent' );
103 delete_option( 'ctc_install_id' );
104 wp_clear_scheduled_hook( 'ctc_telemetry_weekly_send' );
105 }
106
107 /**
108 * Get the settings URL.
109 *
110 * @return string
111 */
112 function ctc_fs_settings_url() {
113 return admin_url( 'options-general.php?page=ctc-global-injector' );
114 }
115
116 // Initialize Freemius on plugins_loaded (after textdomain is loaded).
117 add_action( 'plugins_loaded', 'ctc_fs_init', 10 );