1 <?php
2 3 4 5 6 7 8 9 10 11
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 18 19 20 21
22 class WC_Admin_Editor {
23
24 25 26
27 public function __construct() {
28 add_action( 'admin_head', array( $this, 'add_shortcode_button' ) );
29 add_filter( 'tiny_mce_version', array( $this, 'refresh_mce' ) );
30 add_filter( 'mce_external_languages', array( $this, 'add_tinymce_lang' ), 10, 1 );
31 }
32
33 34 35
36 public function add_shortcode_button() {
37 if ( ! current_user_can( 'edit_posts' ) && ! current_user_can( 'edit_pages' ) ) {
38 return;
39 }
40
41 if ( 'true' == get_user_option( 'rich_editing' ) ) {
42 add_filter( 'mce_external_plugins', array( $this, 'add_shortcode_tinymce_plugin' ) );
43 add_filter( 'mce_buttons', array( $this, 'register_shortcode_button' ) );
44 }
45 }
46
47 48 49 50 51 52
53 public function add_tinymce_lang( $arr ) {
54 $arr['wc_shortcodes_button'] = WC()->plugin_path() . '/assets/js/admin/editor_plugin_lang.php';
55 return $arr;
56 }
57
58 59 60 61 62 63
64 public function register_shortcode_button( $buttons ) {
65 array_push( $buttons, '|', 'wc_shortcodes_button' );
66 return $buttons;
67 }
68
69 70 71 72 73 74
75 public function add_shortcode_tinymce_plugin( $plugin_array ) {
76 $wp_version = get_bloginfo( 'version' );
77 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
78
79 if ( version_compare( $wp_version, '3.9', '>=' ) ) {
80 $plugin_array['wc_shortcodes_button'] = WC()->plugin_url() . '/assets/js/admin/editor_plugin' . $suffix . '.js';
81 } else {
82 $plugin_array['wc_shortcodes_button'] = WC()->plugin_url() . '/assets/js/admin/editor_plugin_legacy' . $suffix . '.js';
83 }
84
85 return $plugin_array;
86 }
87
88 89 90 91 92 93
94 public function refresh_mce( $ver ) {
95 $ver += 3;
96 return $ver;
97 }
98
99 }
100
101 new WC_Admin_Editor();
102