-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclass-copy-to-clipboard.php
204 lines (174 loc) · 5.05 KB
/
class-copy-to-clipboard.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<?php
namespace COPYTOCLIPBOARD;
use COPYTOCLIPBOARD\Libs\Assets;
use COPYTOCLIPBOARD\Libs\Helper;
use COPYTOCLIPBOARD\Libs\Featured;
use COPYTOCLIPBOARD\Inc\Classes\Recommended_Plugins;
use COPYTOCLIPBOARD\Inc\Classes\Notifications\Notifications;
use COPYTOCLIPBOARD\Inc\Classes\Pro_Upgrade;
use COPYTOCLIPBOARD\Inc\Classes\Upgrade_Plugin;
use COPYTOCLIPBOARD\Inc\Classes\Feedback;
use COPYTOCLIPBOARD\Inc\Classes\Admin_Menu;
/**
* Main Class
*
* @copy-to-clipboard
* Jewel Theme <[email protected]>
* @version 1.0.2
*/
// No, Direct access Sir !!!
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Copy_To_Clipboard Class
*/
if ( ! class_exists( '\COPYTOCLIPBOARD\Copy_To_Clipboard' ) ) {
/**
* Class: Copy_To_Clipboard
*/
final class Copy_To_Clipboard {
const VERSION = COPYTOCLIPBOARD_VER;
private static $instance = null;
/**
* what we collect construct method
*
* @author Jewel Theme <[email protected]>
*/
public function __construct() {
$this->includes();
add_action( 'plugins_loaded', array( $this, 'copy_to_clipboard_plugins_loaded' ), 999 );
// Body Class.
add_filter( 'admin_body_class', array( $this, 'copy_to_clipboard_body_class' ) );
// This should run earlier .
// add_action( 'plugins_loaded', [ $this, 'copy_to_clipboard_maybe_run_upgrades' ], -100 ); .
}
/**
* plugins_loaded method
*
* @author Jewel Theme <[email protected]>
*/
public function copy_to_clipboard_plugins_loaded() {
$this->copy_to_clipboard_activate();
}
/**
* Version Key
*
* @author Jewel Theme <[email protected]>
*/
public static function plugin_version_key() {
return Helper::copy_to_clipboard_slug_cleanup() . '_version';
}
/**
* Activation Hook
*
* @author Jewel Theme <[email protected]>
*/
public static function copy_to_clipboard_activate() {
$current_copy_to_clipboard_version = get_option( self::plugin_version_key(), null );
if ( get_option( 'copy_to_clipboard_activation_time' ) === false ) {
update_option( 'copy_to_clipboard_activation_time', strtotime( 'now' ) );
}
if ( is_null( $current_copy_to_clipboard_version ) ) {
update_option( self::plugin_version_key(), self::VERSION );
}
$allowed = get_option( Helper::copy_to_clipboard_slug_cleanup() . '_allow_tracking', 'no' );
// if it wasn't allowed before, do nothing .
if ( 'yes' !== $allowed ) {
return;
}
// re-schedule and delete the last sent time so we could force send again .
$hook_name = Helper::copy_to_clipboard_slug_cleanup() . '_tracker_send_event';
if ( ! wp_next_scheduled( $hook_name ) ) {
wp_schedule_event( time(), 'weekly', $hook_name );
}
}
/**
* Add Body Class
*
* @param [type] $classes .
*
* @author Jewel Theme <[email protected]>
*/
public function copy_to_clipboard_body_class( $classes ) {
$classes .= ' copy-to-clipboard ';
return $classes;
}
/**
* Run Upgrader Class
*
* @return void
*/
public function copy_to_clipboard_maybe_run_upgrades() {
if ( ! is_admin() && ! current_user_can( 'manage_options' ) ) {
return;
}
// Run Upgrader .
$upgrade = new Upgrade_Plugin();
// Need to work on Upgrade Class .
if ( $upgrade->if_updates_available() ) {
$upgrade->run_updates();
}
}
/**
* Include methods
*
* @author Jewel Theme <[email protected]>
*/
public function includes() {
new Assets();
new Recommended_Plugins();
new Pro_Upgrade();
new Notifications();
new Featured();
new Feedback();
new Admin_Menu();
}
/**
* Initialization
*
* @author Jewel Theme <[email protected]>
*/
public function copy_to_clipboard_init() {
$this->copy_to_clipboard_load_textdomain();
}
/**
* Text Domain
*
* @author Jewel Theme <[email protected]>
*/
public function copy_to_clipboard_load_textdomain() {
$domain = 'copy-to-clipboard';
$locale = apply_filters( 'copy_to_clipboard_plugin_locale', get_locale(), $domain );
load_textdomain( $domain, WP_LANG_DIR . '/' . $domain . '/' . $domain . '-' . $locale . '.mo' );
load_plugin_textdomain( $domain, false, dirname( COPYTOCLIPBOARD_BASE ) . '/languages/' );
}
/**
* Deactivate Pro Plugin if it's not already active
*
* @author Jewel Theme <[email protected]>
*/
public static function copy_to_clipboard_activation_hook() {
if ( copy_to_clipboard_license_client()->is_free_plan() ) {
$plugin = 'copy-to-clipboard-pro/copy-to-clipboard.php';
} else {
$plugin = 'copy-to-clipboard/copy-to-clipboard.php';
}
if ( is_plugin_active( $plugin ) ) {
deactivate_plugins( $plugin );
}
}
/**
* Returns the singleton instance of the class.
*/
public static function get_instance() {
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof Copy_To_Clipboard ) ) {
self::$instance = new Copy_To_Clipboard();
self::$instance->copy_to_clipboard_init();
}
return self::$instance;
}
}
// Get Instant of Copy_To_Clipboard Class .
Copy_To_Clipboard::get_instance();
}