-
Notifications
You must be signed in to change notification settings - Fork 10
/
cryptocurrency-price-ticker-widget.php
384 lines (327 loc) · 13.6 KB
/
cryptocurrency-price-ticker-widget.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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
<?php
/**
* Plugin Name: Cryptocurrency Widgets
* Description: Cryptocurrency price widgets for WordPress website. Display crypto ticker widget, coins live price list, table, labels & coin marketcap via shortcodes.
* Plugin URI: https://cryptocurrencyplugins.com/wordpress-plugin/cryptocurrency-widgets-pro/?utm_source=ccpw_plugin&utm_medium=plugin-uri
* Author: Cool Plugins
* Author URI: https://coolplugins.net/?utm_source=ccpw_plugin&utm_medium=author_uri
* Version: 2.6.4
* License: GPL3
* Text Domain: ccpw
* Domain Path: languages
*
* @package Cryptocurrency Price Ticker Widget
*
* */
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( defined( 'CCPWF_VERSION' ) ) {
return;
}
/*
Defined constent for later use
*/
define( 'CCPWF_VERSION', '2.6.4' );
define( 'CCPWF_FILE', __FILE__ );
define( 'CCPWF_DIR', plugin_dir_path( CCPWF_FILE ) );
define( 'CCPWF_URL', plugin_dir_url( CCPWF_FILE ) );
define( 'CCPWF_PRO_URL', 'https://cryptocurrencyplugins.com/wordpress-plugin/cryptocurrency-widgets-pro/?utm_source=ccpw_plugin&utm_medium=inside&utm_campaign=get-pro' );
define( 'CCPWF_DEMO_URL', 'https://cryptocurrencyplugins.com/demo/cryptocurrency-widgets-pro/' );
define( 'CCPWF_DEMO_UTM', '?utm_source=ccpw_plugin&utm_medium=inside&utm_campaign=demo' );
if ( ! class_exists( 'Crypto_Currency_Price_Widget' ) ) {
/**
* Class Crypto_Currency_Price_Widget
*/
final class Crypto_Currency_Price_Widget {
/**
* Plugin instance.
*
* @var Crypto_Currency_Price_Widget
* @access private
*/
private static $instance = null;
/**
* Get plugin instance.
*
* @return Crypto_Currency_Price_Widget
* @static
*/
public static function get_instance() {
if ( ! isset( self::$instance ) ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Constructor.
*
* @access private
*/
private function __construct() {
// register activation/ deactivation hooks
register_activation_hook( CCPWF_FILE, array( $this, 'ccpw_activate' ) );
register_deactivation_hook( CCPWF_FILE, array( $this, 'ccpw_deactivate' ) );
// include required files
$this->ccpw_includes();
add_action('admin_init', array($this, 'ccpw_do_activation_redirect'));
// verify plugin version
add_action( 'init', array( $this, 'ccpw_verify_plugin_version' ) );
// add_action('admin_init', array($this, 'ccpw_reg_settings'));
// load text domain for translation
add_action( 'plugins_loaded', array( $this, 'ccpw_plugins_loaded' ) );
// ajax call for datatable server processing
add_action( 'wp_ajax_ccpw_get_coins_list', array( $this, 'ccpw_get_coins_list' ) );
add_action( 'wp_ajax_nopriv_ccpw_get_coins_list', array( $this, 'ccpw_get_coins_list' ) );
// check coin market cap plugin is activated
add_action( 'admin_init', array( $this, 'ccpw_check_cmc_activated' ) );
add_action( 'wp_footer', array( $this, 'ticker_in_footer' ) );
add_action( 'wp_footer', array( $this, 'ccpw_enable_ticker' ) );
if ( is_admin() ) {
add_action( 'admin_menu', array( $this, 'init_crypto_admin_menu' ), 15 );
add_action( 'admin_enqueue_scripts', array( $this, 'ccpw_load_scripts' ) );
add_action( 'admin_head-edit.php', array( $this, 'ccpw_custom_btn' ) );
add_action( 'wp_ajax_ccpw_delete_transient', array( $this, 'ccpw_delete_transient' ) );
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'ccpw_add_widgets_action_links' ) );
}
}
/**
* initialize cron : MUST USE ON PLUGIN ACTIVATION
*/
public function ccpw_cron_job_init() {
if ( ! wp_next_scheduled( 'ccpw_coins_autosave' ) ) {
wp_schedule_event( time(), '5min', 'ccpw_coins_autosave' );
}
}
public function ccpw_data_insert() {
$api = get_option( 'ccpw_options' );
$api = ( ! isset( $api['select_api'] ) && empty( $api['select_api'] ) ) ? 'coin_gecko' : $api['select_api'];
$api_obj = new CCPW_api_data();
$data = ( $api == 'coin_gecko' ) ? $api_obj->ccpw_get_coin_gecko_data() : $api_obj->ccpw_get_coin_paprika_data();
}
/*
|--------------------------------------------------------------------------
| Load required files
|--------------------------------------------------------------------------
*/
public function ccpw_includes() {
require_once CCPWF_DIR . 'admin/addon-dashboard-page/addon-dashboard-page.php';
cool_plugins_crypto_addon_settings_page( 'crypto', 'cool-crypto-plugins', 'Cryptocurrency Plugins Dashboard', 'Crypto Plugins', 'dashicons-chart-area' );
require_once CCPWF_DIR . 'includes/api/ccpw-api-data.php';
// require CCPWF_DIR . 'includes/ccpw-db-helper.php';
// load post type geneartor
require_once CCPWF_DIR . 'admin/register-post-type/ccpw-post-type.php';
new CPTW_Posttype();
require_once CCPWF_DIR . 'includes/ccpw-functions.php';
$post_array = array( 'ccpw','cool-crypto-plugins', 'openexchange-api-settings', 'ccpw_options','ccpw_get_started' );
if ( isset( $_POST['submit-cmb'] ) || in_array( ccpw_get_post_type_page(), $post_array ) ) {
require_once CCPWF_DIR . 'admin/cmb2/init.php';
require_once CCPWF_DIR . 'admin/cmb2/cmb2-conditionals.php';
if ( ! class_exists( 'PW_CMB2_Field_Select2' ) ) {
require_once CCPWF_DIR . 'admin/cmb2/cmb-field-select2/cmb-field-select2.php';
}
}
// loading required functions
require_once CCPWF_DIR . 'admin/review-notices/class.review-notice.php';
if ( is_admin() ) {
require_once CCPWF_DIR . 'admin/feedback/admin-feedback-form.php';
require_once CCPWF_DIR . 'admin/openexchange-api/openexchange-api-settings.php';
}
require CCPWF_DIR . 'includes/ccpw-db-helper.php';
require_once CCPWF_DIR . 'includes/cron/ccpw-cron.php';
require_once CCPWF_DIR . 'includes/ccpw-shortcode.php';
new CPTW_Shortcode();
}
/**
* Move plugin's menu into cryptocurrency plugin menu
*/
public function init_crypto_admin_menu() {
add_submenu_page( 'cool-crypto-plugins', 'Cryptocurrency Widgets', '<strong>Crypto Widgets</strong>', 'manage_options', 'edit.php?post_type=ccpw', false, 15 );
add_submenu_page( 'cool-crypto-plugins', 'Cryptocurrency Widgets', '↳ All Widgets', 'manage_options', 'edit.php?post_type=ccpw', false, 16 );
add_submenu_page( 'cool-crypto-plugins', 'Add New Widget', '↳ Add New Widget', 'manage_options', 'post-new.php?post_type=ccpw', false, 17 );
add_submenu_page( 'cool-crypto-plugins', 'Settings', ' ↳ Settings', 'manage_options', 'admin.php?page=ccpw_options', false, 18 );
}
public function ccpw_delete_transient() {
// Check for nonce security
if ( ! wp_verify_nonce( $_POST['nonce'], 'ccpw-nonce' ) ) {
die( 'You don\'t have permission to delete the cache.' );
}
// Delete cache if user has permssion to delete it.
if ( current_user_can( 'manage_options' ) ) {
delete_transient( 'ccpw-saved-coindata' );
delete_option( 'ccpw_data_save' );
wp_send_json_success();
}
}
/**
* Code you want to run when all other plugins loaded.
*/
public function ccpw_plugins_loaded() {
// Require the main plugin file
if ( ! function_exists( 'is_plugin_active' ) ) {
// require only if needed
require ABSPATH . 'wp-admin/includes/plugin.php';
}
load_plugin_textdomain( 'ccpw', false, basename( dirname( __FILE__ ) ) . '/languages/' );
}
/**
* Run when activate plugin.
*/
public function ccpw_activate() {
$active_plugins = get_option('active_plugins', array());
if (!in_array("cryptocurrency-price-ticker-widget-pro/cryptocurrency-price-ticker-widget-pro.php", $active_plugins)) {
add_option('ccpw_do_activation_redirect', true);
}
$DB = new ccpw_database();
$DB->create_table();
$this->ccpw_cron_job_init();
update_option( 'ccpw-type', 'FREE' );
update_option( 'ccpw_activation_time', gmdate( 'Y-m-d h:i:s' ) );
update_option( 'ccpw_data_save', 'false' );
update_option( 'ccpw-alreadyRated', 'no' );
$this->ccpw_data_insert();
}
public function ccpw_do_activation_redirect()
{
if (get_option('ccpw_do_activation_redirect', false)) {
update_option('ccpw_do_activation_redirect',false);
if (!isset($_GET['activate-multi'])) {
wp_redirect(admin_url('admin.php?page=ccpw_get_started'));
exit;
}
}
}
/*
* Run when deactivate plugin.
*/
public function ccpw_deactivate() {
if ( wp_next_scheduled( 'ccpw_coins_autosave' ) ) {
wp_clear_scheduled_hook( 'ccpw_coins_autosave' );
}
$db = new ccpw_database();
$db->drop_table();
delete_transient( 'ccpw-saved-coindata' );
}
/**
* server side processing ajax callback
*/
public function ccpw_get_coins_list() {
require_once CCPWF_DIR . 'includes/ccpw-ad-tbl-handler.php';
ccpw_get_ajax_data();
wp_die();
}
/*
|--------------------------------------------------------------------------
| Added ticker shortcode in footer hook for footer ticker
|--------------------------------------------------------------------------
*/
public function ticker_in_footer() {
if ( ! wp_script_is( 'jquery', 'done' ) ) {
wp_enqueue_script( 'jquery' );
}
$id = get_option( 'ccpw-p-id' );
if ( $id ) {
$ticker_position = get_post_meta( $id, 'ticker_position', true );
$type = get_post_meta( $id, 'type', true );
if ( $type == 'ticker' ) {
if ( $ticker_position == 'header' || $ticker_position == 'footer' ) {
$shortcode = get_option( 'ccpw-shortcode' );
echo do_shortcode( $shortcode );
}
}
}
}
/*
|--------------------------------------------------------------------------
| Re-enable ticker after dom load
|--------------------------------------------------------------------------
*/
public function ccpw_enable_ticker() {
wp_add_inline_script(
'ccpw_bxslider_js',
'jQuery(document).ready(function($){
$(".ccpw-ticker-cont").fadeIn();
});',
'before'
);
}
/*
|--------------------------------------------------------------------------
| Check if plugin is just updated from older version to new!
|--------------------------------------------------------------------------
*/
public function ccpw_verify_plugin_version() {
// ccpw_widget_coin_peprika_insert_data();
// ccpw_widget_insert_data();
$CCPW_VERSION = get_option( 'CCPW_FREE_VERSION' );
if ( ! isset( $CCPW_VERSION ) || version_compare( $CCPW_VERSION, CCPWF_VERSION, '<' ) ) {
$this->ccpw_activate();
$conversions = get_transient( 'cmc_usd_conversions' );
if ( ! empty( $conversions ) ) {
update_option( 'cmc_usd_conversions', $conversions );
}
update_option( 'CCPW_FREE_VERSION', CCPWF_VERSION );
}
} // end of cmc_plugin_version_verify()
/*
|--------------------------------------------------------------------------
| check coin market cap plugin is activated. then enable links
|--------------------------------------------------------------------------
*/
public function ccpw_check_cmc_activated() {
if ( is_plugin_active( 'coin-market-cap/coin-market-cap.php' ) || class_exists( 'CoinMarketCap' ) ) {
update_option( 'cmc-dynamic-links', true );
} else {
update_option( 'cmc-dynamic-links', false );
}
}
/*
|--------------------------------------------------------------------------
| Integrated custom Button
|--------------------------------------------------------------------------
*/
public function ccpw_custom_btn() {
global $current_screen;
// Not our post type, exit earlier
if ( 'ccpw' != $current_screen->post_type ) {
return;
}?>
<script type="text/javascript">
jQuery(document).ready( function($)
{
$(".wrap").find('a.page-title-action').after("<a id='ccpw_add_premium' href='https://cryptocurrencyplugins.com/wordpress-plugin/cryptocurrency-widgets-pro/?utm_source=ccpw_plugin&utm_medium=inside&utm_campaign=get-pro&utm_content=add-pro-widgets' target='_blank' class='add-new-h2'>Add Premium Widgets</a>");
});
</script>
<?php
}
/*
|--------------------------------------------------------------------------
| custom links for add widgets in all plugins section
|--------------------------------------------------------------------------
*/
public function ccpw_add_widgets_action_links( $links ) {
$links[] = '<a style="font-weight:bold" href="' . esc_url( get_admin_url( null, 'post-new.php?post_type=ccpw' ) ) . '">Add Widgets</a>';
$links[] = '<a style="font-weight:bold" href="https://cryptocurrencyplugins.com/demo/cryptocurrency-widgets-pro/" target="_blank">Click Demos</a>';
return $links;
}
/*
|--------------------------------------------------------------------------
| Load admin side custom Styles
|--------------------------------------------------------------------------
*/
public function ccpw_load_scripts( $hook ) {
wp_enqueue_style( 'ccpw-custom-styles', CCPWF_URL . 'assets/css/ccpw-admin-styles.css',array(), CCPWF_VERSION );
wp_enqueue_script( 'ccpw-admin-script', CCPWF_URL . 'assets/js/admin-script.js', array( 'jquery' ), CCPWF_VERSION, true );
if ( get_post_type() === "ccpw" || $hook=="crypto-plugins_page_ccpw_get_started" || $hook=="crypto-plugins_page_ccpw_options"){
wp_enqueue_style('ccpw-custom-setting-styles', CCPWF_URL . 'assets/css/ccpw-custom-setting-styles.css',array(), CCPWF_VERSION );
}
if(get_post_type() === "ccpw" || $hook=="crypto-plugins_page_ccpw_get_started"){
wp_enqueue_script('ccpw-settings-custom-scripts', CCPWF_URL . 'assets/js/setting-custom-scripts.js',array('jquery'), CCPWF_VERSION, true);
}
}
}
function Crypto_Currency_Price_Widget() {
return Crypto_Currency_Price_Widget::get_instance();
}
Crypto_Currency_Price_Widget();
}