-
Notifications
You must be signed in to change notification settings - Fork 0
/
hive-engine-price.php
121 lines (93 loc) · 3.73 KB
/
hive-engine-price.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
<?php
/**
* @package HiveEnginePrice
*/
/*
Plugin Name: Hive Engine Price
Plugin URI: https://github.com/Hive-Pizza-Team/hive-engine-price-wp-widget
Description: Display price information for HiveEngine tokens
Version: 0.0.1
Author: Hive Pizza Team
Author URI: https://hive.pizza
License: GPLv2
Text Domain: hiveengine
*/
// Creating the widget
class hep_widget extends WP_Widget {
function __construct() {
parent::__construct(
// Base ID of your widget
'hep_widget',
// Widget name will appear in UI
__('Hive Engine Price', 'hep_widget_domain'),
// Widget description
array( 'description' => __( 'Show Hive-Engine token prices', 'hep_widget_domain' ), )
);
}
// Creating widget front-end
public function widget( $args, $instance ) {
$token = apply_filters( 'widget_title', $instance['token'] );
$content_div_id = 'hep_widget_content_' . $this->id;
// before and after widget arguments are defined by themes
echo $args['before_widget'];
if ( ! empty( $token ) )
//echo $args['before_title'] . $this->name . $args['after_title'];
// This is where you run the code and display the output
echo __( '<!-- Start : Hive Engine Price Widget -->', 'hep_widget_domain' );
echo __( '<div class="hep_widget_container">', 'hep_widget_domain' );
// Widget content header
echo __( '<div class="hep_widget_header" style="background-color: #'.get_background_color().'; color: #'.header_textcolor().';">', 'hep_widget_domain' );
echo __( '<h4>$' . $token . '</h4><h6> Current Price:</h6>', 'hep_widget_domain' );
echo __( '</div>', 'hep_widget_domain' );
echo __( get_header_textcolor(), 'hep_widget_domain');
// Width content body
echo __( '<h5><div id="' . $content_div_id . '" class="hep_widget_content" data-token-name="'.$token.'""></div></h5>', 'hep_widget_domain' );
echo __( '<div class="hep_widget_exchanges">
<a href="https://hive-engine.com/?p=market&t='.$token.'" target="_blank"><img src="'.plugins_url( '/img/hiveengine.png' , __FILE__ ).'"></a>
<a href="https://leodex.io/market/'.$token.'" target="_blank"><img src="'.plugins_url( '/img/leodex.png' , __FILE__ ).'"></a>
<a href="https://tribaldex.com/trade/'.$token.'" target="_blank"><img src="'.plugins_url( '/img/tribaldex.png' , __FILE__ ).'"></a>
</div>'
, 'hep_widget_domain' );
echo __( '</div>', 'hep_widget_domain' );
echo __( '<!-- End : Hive Engine Price Widget -->', 'hep_widget_domain' );
echo $args['after_widget'];
}
// Widget Backend
public function form( $instance ) {
if ( isset( $instance[ 'token' ] ) ) {
$token = $instance[ 'token' ];
}
else {
$token = __( 'PIZZA', 'hep_widget_domain' );
}
// Widget admin form
?>
<p>
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Token:' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( 'token' ); ?>" name="<?php echo $this->get_field_name( 'token' ); ?>" type="text" value="<?php echo esc_attr( $token ); ?>" />
</p>
<?php
}
// Updating widget replacing old instances with new
public function update( $new_instance, $old_instance ) {
$instance = array();
$instance['token'] = ( ! empty( $new_instance['token'] ) ) ? strip_tags( $new_instance['token'] ) : '';
return $instance;
}
// Class hep_widget ends here
}
// Register and load the widget
function hep_load_widget() {
register_widget( 'hep_widget' );
// Load scripts
add_action( 'wp_enqueue_scripts', 'hep_load_scripts' );
function hep_load_scripts() {
wp_enqueue_script( 'axios', plugins_url( '/axios.min.js' , __FILE__ ) );
wp_enqueue_script( 'hive-engine-price', plugins_url( '/hive-engine-price.js' , __FILE__ ), array( 'axios' ), '1.0', true);
}
add_action('wp_head', 'widget_styles');
function widget_styles(){
wp_enqueue_style( 'hep', plugins_url( '/css/hep.css' , __FILE__ ) );
}
}
add_action( 'widgets_init', 'hep_load_widget' );