PluginProbe
Copy Anything to Clipboard for WordPress – Copy Button, Copy Text & Copy Code / 5.2.0
Copy Anything to Clipboard for WordPress – Copy Button, Copy Text & Copy Code v5.2.0
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.2.0, at includes/class-core.php

165 lines 4.2 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.2.0';
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 add_action( 'init', [$this, 'init'], 0 );
57 add_action( 'plugins_loaded', [$this, 'load_textdomain'], 9 );
58 add_filter( 'plugin_action_links_' . plugin_basename( CTC_FILE ), [$this, 'action_links'] );
59 }
60
61 /**
62 * Initialize plugin components.
63 *
64 * Called at 'init' action to ensure translations are available.
65 *
66 * @since 5.1.0
67 */
68 public function init() {
69 $this->initialize();
70 do_action( 'ctc/loaded' );
71 }
72
73 /**
74 * Include the required files.
75 */
76 private function includes() {
77 include CTC_DIR . 'vendor/autoload.php';
78 }
79
80 /**
81 * Initialize the plugin.
82 */
83 private function initialize() {
84 \CTC\Base::get();
85 \CTC\Post_Types::get();
86 \CTC\Updater::get();
87 \CTC\Welcome::get();
88 \CTC\Global_Injector\Style_Presets::get();
89 \CTC\Global_Injector\Rest::get();
90 \CTC\Shortcode::get();
91 \CTC\Elementor\Blocks::get();
92 \CTC\Gutenberg\Blocks::get();
93 if ( is_admin() ) {
94 Global_Injector::get();
95 Main_Rule_List::get();
96 } else {
97 \CTC\Global_Injector\Frontend::get();
98 }
99 }
100
101 /**
102 * Load plugin textdomain.
103 */
104 public function load_textdomain() {
105 load_plugin_textdomain( 'ctc', false, dirname( CTC_BASE ) . '/languages/' );
106 }
107
108 /**
109 * Add plugin action links.
110 *
111 * @param array $links Plugin action links.
112 * @return array Modified plugin action links.
113 */
114 public function action_links( $links ) {
115 $action_links = [
116 'settings' => '<a href="' . admin_url( 'options-general.php?page=ctc' ) . '">' . esc_html__( 'Settings', 'ctc' ) . '</a>',
117 ];
118 return array_merge( $action_links, $links );
119 }
120
121 /**
122 * Plugin activation callback.
123 *
124 * Deactivates the free version if pro version is being activated.
125 * This prevents conflicts when both versions are installed.
126 *
127 * @since 5.1.0
128 */
129 public static function activation() {
130 // Check if this is the premium version (has /premium/ folder).
131 $is_premium = file_exists( CTC_DIR . 'premium/' );
132 if ( !$is_premium ) {
133 return;
134 }
135 // Include plugin.php if not available (needed for is_plugin_active and deactivate_plugins).
136 if ( !function_exists( 'is_plugin_active' ) ) {
137 require_once ABSPATH . 'wp-admin/includes/plugin.php';
138 }
139 // Possible free version plugin paths.
140 // Freemius uses 'copy-the-code' for free and 'copy-the-code-premium' for pro.
141 $free_plugins = ['copy-the-code/copy-the-code.php'];
142 foreach ( $free_plugins as $free_plugin ) {
143 // Skip if this is the same plugin.
144 if ( CTC_BASE === $free_plugin ) {
145 continue;
146 }
147 // Deactivate free version if active.
148 if ( is_plugin_active( $free_plugin ) ) {
149 deactivate_plugins( $free_plugin );
150 }
151 }
152 }
153
154 }
155
156 /**
157 * Returns the main instance of CTC to prevent the need to use globals.
158 *
159 * @return CTC
160 */
161 function ctc() {
162 // @codingStandardsIgnoreLine
163 return CTC::get();
164 }
165