-
Notifications
You must be signed in to change notification settings - Fork 5
/
editor.php
84 lines (70 loc) · 2.09 KB
/
editor.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
<?php
class nhymxu_at_coupon_editor {
public function __construct() {
add_action( 'admin_print_footer_scripts', [$this, 'shortcode_button_script'] );
add_action( 'admin_print_scripts', [$this, 'data_for_tinymce_list'] );
add_action( 'init', [$this,'tinymce_new_button'] );
}
function shortcode_button_script() {
if(wp_script_is("quicktags")):
?>
<script type="text/javascript">
QTags.addButton(
"at_coupon",
"AT Coupon",
nhymxu_at_coupon_callback
);
function nhymxu_at_coupon_callback() {
QTags.insertContent('[atcoupon type="danh_sach_merchant" cat="danh_sach_category"]');
}
</script>
<?php
endif;
}
function data_for_tinymce_list() {
?>
<script type="text/javascript">
function nhymxu_at_coupon_get_tinymce_list( type ) {
if( type == 'merchant' ) {
return [<?=$this->get_coupon_merchant();?>];
}
if( type == 'cat' ) {
return [<?=$this->get_coupon_cat();?>];
}
}
</script>
<?php
}
function get_coupon_merchant() {
global $wpdb;
$coupon_type = $wpdb->get_results("SELECT type FROM {$wpdb->prefix}coupons GROUP BY type", ARRAY_A);
$output = '';
foreach( $coupon_type as $row ) {
$output .= '{text:\'' . $row['type'] . '\',value:\'' . $row['type'] . '\'},';
}
return $output;
}
function get_coupon_cat() {
global $wpdb;
$output = '{text:\'Tất cả\', value:\'\'},';
$coupon_cats = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}coupon_categories");
foreach( $coupon_cats as $row ) {
$output .= '{text:\'' . $row->name . '\',value:\'' . $row->slug . '\'},';
}
return $output;
}
function tinymce_new_button() {
add_filter("mce_external_plugins", [$this,'tinymce_add_button']);
add_filter("mce_buttons", [$this,'tinymce_register_button']);
}
function tinymce_add_button($plugin_array) {
//enqueue TinyMCE plugin script with its ID.
$plugin_array["at_coupon_button"] = plugin_dir_url(__FILE__) . "visual-editor-button.js";
return $plugin_array;
}
function tinymce_register_button($buttons) {
//register buttons with their id.
array_push($buttons, "at_coupon_button");
return $buttons;
}
}