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 / class-core.php

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

206 lines 5.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Core plugin class.
5 *
6 * @package CTC
7 * @since 5.1.0
8 */
9 if ( !defined( 'ABSPATH' ) ) {
10 exit;
11 }
12 use CTC\Global_Injector;
13 use CTC\Global_Injector\Main_Rule_List;
14 /**
15 * CTC class.
16 *
17 * @class Main class of the plugin.
18 */
19 final class CTC {
20 /**
21 * Plugin version.
22 *
23 * @var string
24 */
25 public $version = '5.5.3';
26
27 /**
28 * The single instance of the class.
29 *
30 * @var CTC
31 */
32 protected static $instance = null;
33
34 /**
35 * Retrieve main CTC instance.
36 *
37 * Ensure only one instance is loaded or can be loaded.
38 *
39 * @see ctc()
40 * @return CTC
41 */
42 public static function get() {
43 if ( null === self::$instance ) {
44 self::$instance = new CTC();
45 self::$instance->setup();
46 }
47 return self::$instance;
48 }
49
50 /**
51 * Instantiate the plugin.
52 */
53 private function setup() {
54 $this->includes();
55 register_activation_hook( CTC_FILE, [__CLASS__, 'activation'] );
56 register_deactivation_hook( CTC_FILE, [__CLASS__, 'deactivation'] );
57 add_action( 'init', [$this, 'init'], 0 );
58 add_action( 'plugins_loaded', [$this, 'load_textdomain'], 9 );
59 add_filter( 'plugin_action_links_' . plugin_basename( CTC_FILE ), [$this, 'action_links'] );
60 }
61
62 /**
63 * Initialize plugin components.
64 *
65 * Called at 'init' action to ensure translations are available.
66 *
67 * @since 5.1.0
68 */
69 public function init() {
70 $this->init_third_party();
71 $this->initialize();
72 do_action( 'ctc/loaded' );
73 }
74
75 /**
76 * Include the required files.
77 */
78 private function includes() {
79 include CTC_DIR . 'vendor/autoload.php';
80 }
81
82 /**
83 * Load third-party integrations when their plugins are active.
84 *
85 * Each integration registers container shortcodes so [copy] inside their output
86 * (e.g. table cells) triggers script enqueue and works with cached/dynamic content.
87 *
88 * @since 5.5.1
89 */
90 private function init_third_party() {
91 if ( !function_exists( 'is_plugin_active' ) ) {
92 require_once ABSPATH . 'wp-admin/includes/plugin.php';
93 }
94 if ( is_plugin_active( 'data-tables-generator-by-supsystic/index.php' ) ) {
95 new \CTC\ThirdParty\Supsystic_Tables();
96 }
97 if ( is_plugin_active( 'wpdatatables/wpdatatables.php' ) ) {
98 new \CTC\ThirdParty\WPDataTables();
99 }
100 }
101
102 /**
103 * Initialize the plugin.
104 */
105 private function initialize() {
106 \CTC\Base::get();
107 \CTC\Post_Types::get();
108 \CTC\Updater::get();
109 \CTC\Welcome::get();
110 \CTC\Telemetry::get();
111 \CTC\Analytics\Database::get();
112 \CTC\Global_Injector\Style_Presets::get();
113 \CTC\Global_Injector\Rest::get();
114 \CTC\Analytics::get();
115 \CTC\Analytics\Rest::get();
116 \CTC\Shortcode::get();
117 \CTC\Elementor\Blocks::get();
118 \CTC\Gutenberg\Blocks::get();
119 if ( is_admin() ) {
120 Global_Injector::get();
121 Main_Rule_List::get();
122 } else {
123 \CTC\Global_Injector\Frontend::get();
124 }
125 }
126
127 /**
128 * Load plugin textdomain.
129 */
130 public function load_textdomain() {
131 load_plugin_textdomain( 'ctc', false, dirname( CTC_BASE ) . '/languages/' );
132 }
133
134 /**
135 * Add plugin action links.
136 *
137 * @param array $links Plugin action links.
138 * @return array Modified plugin action links.
139 */
140 public function action_links( $links ) {
141 $action_links = [
142 'settings' => '<a href="' . admin_url( 'options-general.php?page=ctc' ) . '">' . esc_html__( 'Settings', 'ctc' ) . '</a>',
143 ];
144 return array_merge( $action_links, $links );
145 }
146
147 /**
148 * Plugin activation callback.
149 *
150 * Deactivates the free version if pro version is being activated.
151 * This prevents conflicts when both versions are installed.
152 *
153 * @since 5.1.0
154 */
155 public static function activation() {
156 // Ensure daily cleanup of old analytics events is scheduled for both free and Pro.
157 if ( !wp_next_scheduled( 'ctc_analytics_cleanup' ) ) {
158 wp_schedule_event( time() + DAY_IN_SECONDS, 'daily', 'ctc_analytics_cleanup' );
159 }
160 // Check if this is the premium version (has /premium/ folder).
161 $is_premium = file_exists( CTC_DIR . 'premium/' );
162 if ( !$is_premium ) {
163 return;
164 }
165 // Include plugin.php if not available (needed for is_plugin_active and deactivate_plugins).
166 if ( !function_exists( 'is_plugin_active' ) ) {
167 require_once ABSPATH . 'wp-admin/includes/plugin.php';
168 }
169 // Possible free version plugin paths.
170 // Freemius uses 'copy-the-code' for free and 'copy-the-code-premium' for pro.
171 $free_plugins = ['copy-the-code/copy-the-code.php'];
172 foreach ( $free_plugins as $free_plugin ) {
173 // Skip if this is the same plugin.
174 if ( CTC_BASE === $free_plugin ) {
175 continue;
176 }
177 // Deactivate free version if active.
178 if ( is_plugin_active( $free_plugin ) ) {
179 deactivate_plugins( $free_plugin );
180 }
181 }
182 }
183
184 /**
185 * Plugin deactivation callback.
186 *
187 * Clears scheduled analytics cleanup events.
188 *
189 * @since 5.4.0
190 */
191 public static function deactivation() {
192 wp_clear_scheduled_hook( 'ctc_analytics_cleanup' );
193 }
194
195 }
196
197 /**
198 * Returns the main instance of CTC to prevent the need to use globals.
199 *
200 * @return CTC
201 */
202 function ctc() {
203 // @codingStandardsIgnoreLine
204 return CTC::get();
205 }
206