Black Studio TinyMCE Widget - Version 2.0.0

Version Description

(2014-10-06) = * Total refactoring of plugin's source code * Enhanced integration with TinyMCE editor for better compatibility with other plugins * Added support for QuickTags toolbar in HTML mode * Added support for mobile devices (responsive width in widgets administration page) * Added project to GitHub * Added project to Transifex translation platform * Added many new translations thanks to WP-Translation.org team * Added several filter and action hooks * Improved code quality and security thanks to Scrutinizer service * Improved development workflow thanks to Grunt * Improved performance and user experience * A huge Thanks to @cfoellmann for his precious support and contributions

Download this release

Release Info

Developer marcochiesi
Plugin Icon 128x128 Black Studio TinyMCE Widget
Version 2.0.0
Comparing to
See all releases

Code changes from version 1.4.8 to 2.0.0

Files changed (78) hide show
  1. black-studio-tinymce-widget-legacy.css +0 -70
  2. black-studio-tinymce-widget-legacy.js +0 -131
  3. black-studio-tinymce-widget-legacy.min.js +0 -1
  4. black-studio-tinymce-widget.css +0 -7
  5. black-studio-tinymce-widget.js +0 -160
  6. black-studio-tinymce-widget.min.js +0 -1
  7. black-studio-tinymce-widget.php +238 -302
  8. css/black-studio-tinymce-widget-pre33.css +99 -0
  9. css/black-studio-tinymce-widget-pre33.min.css +2 -0
  10. css/black-studio-tinymce-widget.css +55 -0
  11. css/black-studio-tinymce-widget.min.css +2 -0
  12. includes/class-admin.php +371 -0
  13. includes/class-compatibility-plugins.php +360 -0
  14. includes/class-compatibility-wordpress.php +349 -0
  15. includes/class-compatibility.php +150 -0
  16. includes/class-text-filters.php +161 -0
  17. includes/class-widget.php +123 -0
  18. includes/deprecated.php +152 -0
  19. js/black-studio-tinymce-widget-pre33.js +244 -0
  20. js/black-studio-tinymce-widget-pre33.min.js +2 -0
  21. js/black-studio-tinymce-widget-pre39.js +278 -0
  22. js/black-studio-tinymce-widget-pre39.min.js +2 -0
  23. js/black-studio-tinymce-widget.js +311 -0
  24. js/black-studio-tinymce-widget.min.js +2 -0
  25. js/wp-page-widget.js +27 -0
  26. js/wp-page-widget.min.js +2 -0
  27. languages/black-studio-tinymce-widget-ca.mo +0 -0
  28. languages/black-studio-tinymce-widget-ca.po +84 -0
  29. languages/black-studio-tinymce-widget-da_DK.mo +0 -0
  30. languages/black-studio-tinymce-widget-da_DK.po +67 -21
  31. languages/black-studio-tinymce-widget-de_DE.mo +0 -0
  32. languages/black-studio-tinymce-widget-de_DE.po +66 -21
  33. languages/black-studio-tinymce-widget-el.mo +0 -0
  34. languages/black-studio-tinymce-widget-el.po +84 -0
  35. languages/black-studio-tinymce-widget-en_GB.mo +0 -0
  36. languages/black-studio-tinymce-widget-en_GB.po +84 -0
  37. languages/black-studio-tinymce-widget-es_ES.mo +0 -0
  38. languages/black-studio-tinymce-widget-es_ES.po +66 -38
  39. languages/black-studio-tinymce-widget-fi.mo +0 -0
  40. languages/black-studio-tinymce-widget-fi.po +85 -0
  41. languages/black-studio-tinymce-widget-fi_FI.mo +0 -0
  42. languages/black-studio-tinymce-widget-fi_FI.po +0 -37
  43. languages/black-studio-tinymce-widget-fr_FR.mo +0 -0
  44. languages/black-studio-tinymce-widget-fr_FR.po +85 -0
  45. languages/black-studio-tinymce-widget-it_IT.mo +0 -0
  46. languages/black-studio-tinymce-widget-it_IT.po +63 -32
  47. languages/black-studio-tinymce-widget-ja.mo +0 -0
  48. languages/black-studio-tinymce-widget-ja.po +84 -0
  49. languages/black-studio-tinymce-widget-ko_KR.mo +0 -0
  50. languages/black-studio-tinymce-widget-ko_KR.po +84 -0
  51. languages/black-studio-tinymce-widget-nl_NL.mo +0 -0
  52. languages/black-studio-tinymce-widget-nl_NL.po +85 -0
  53. languages/black-studio-tinymce-widget-pl_PL.mo +0 -0
  54. languages/black-studio-tinymce-widget-pl_PL.po +84 -0
  55. languages/black-studio-tinymce-widget-pt_BR.mo +0 -0
  56. languages/black-studio-tinymce-widget-pt_BR.po +84 -0
  57. languages/black-studio-tinymce-widget-ro_RO.mo +0 -0
  58. languages/black-studio-tinymce-widget-ro_RO.po +84 -0
  59. languages/black-studio-tinymce-widget-ru_RU.mo +0 -0
  60. languages/black-studio-tinymce-widget-ru_RU.po +84 -0
  61. languages/black-studio-tinymce-widget-sk_SK.mo +0 -0
  62. languages/black-studio-tinymce-widget-sk_SK.po +85 -0
  63. languages/black-studio-tinymce-widget-sv_SE.mo +0 -0
  64. languages/black-studio-tinymce-widget-sv_SE.po +65 -39
  65. languages/black-studio-tinymce-widget-tr_TR.mo +0 -0
  66. languages/black-studio-tinymce-widget-tr_TR.po +84 -0
  67. languages/black-studio-tinymce-widget-uk.mo +0 -0
  68. languages/black-studio-tinymce-widget-uk.po +84 -0
  69. languages/black-studio-tinymce-widget-zh_CN.mo +0 -0
  70. languages/black-studio-tinymce-widget-zh_CN.po +85 -0
  71. languages/black-studio-tinymce-widget.pot +66 -19
  72. languages/black-studio-tinymce-widget_sk_SK.mo +0 -0
  73. languages/black-studio-tinymce-widget_sk_SK.po +0 -37
  74. languages/black-studio-tinymce-widget_uk_UA.mo +0 -0
  75. languages/black-studio-tinymce-widget_uk_UA.po +0 -37
  76. readme.txt +301 -261
  77. screenshot-1.png +0 -0
  78. screenshot-2.png +0 -0
black-studio-tinymce-widget-legacy.css DELETED
@@ -1,70 +0,0 @@
1
- /* CSS Document */
2
-
3
- #mce_fullscreen_container {
4
- background-color: white;
5
- }
6
-
7
- #wp-black-studio-tinymce-widget-wrap {
8
- display: none;
9
- }
10
-
11
- .editor_container {
12
- background-color: #FFF;
13
- border-color: #DEDEDE;
14
- border-style: solid;
15
- border-width: 1px;
16
- border-collapse: separate;
17
- border-top-right-radius: 3px;
18
- border-top-left-radius: 3px;
19
- padding: 0 1px 1px 1px;
20
- clear: both;
21
- }
22
- .editor_toggle_buttons {
23
- margin-right: 15px;
24
- margin-top: 8px;
25
- float: right;
26
- }
27
- .editor_toggle_buttons a {
28
- background: none repeat scroll 0 0 #EBEBEB;
29
- border: 1px solid #DEDEDE;
30
- color: #777777;
31
- cursor: pointer;
32
- float: right;
33
- font: 13px/19px "Open Sans",sans-serif;
34
- margin: 5px 0 0 5px;
35
- padding: 3px 8px 4px;
36
- position: relative;
37
- top: 1px;
38
- }
39
- .editor_toggle_buttons a.active {
40
- background: none repeat scroll 0 0 #F5F5F5;
41
- border-bottom: 0 none;
42
- color: #555555;
43
- height: 20px;
44
- }
45
- .editor_toggle_buttons_legacy a.active {
46
- border-color: #CCC #CCC #E9E9E9;
47
- background-color: #E9E9E9;
48
- }
49
- .editor_media_buttons {
50
- cursor: default;
51
- padding: 8px 8px;
52
- height: 22px;
53
- }
54
- .editor_media_buttons a {
55
- cursor: pointer;
56
- text-decoration: none;
57
- color: #333;
58
- font-size: 12px;
59
- margin-right: 8px;
60
- }
61
- .editor_media_buttons img {
62
- vertical-align: middle;
63
- padding: 0 4px;
64
- }
65
- .editor_links {
66
- font-size: 10px;
67
- text-align: right;
68
- padding-top: 3px;
69
- padding-bottom: 3px;
70
- }
black-studio-tinymce-widget-legacy.js DELETED
@@ -1,131 +0,0 @@
1
- // TinyMCE initialization parameters
2
- var tinyMCEPreInit;
3
- // Current editor (backward compatibility)
4
- var edCanvas;
5
- // Current editor
6
- var wpActiveEditor;
7
-
8
- (function($) {
9
- // Activate visual editor
10
- function black_studio_activate_visual_editor(id) {
11
- $('#'+id).addClass("mceEditor");
12
- if ( typeof( tinyMCE ) == "object" && typeof( tinyMCE.execCommand ) == "function" ) {
13
- black_studio_deactivate_visual_editor(id);
14
- if (typeof (tinyMCEPreInit.mceInit['black-studio-tinymce-widget']) == "object") { // WP 3.3+
15
- tinyMCEPreInit.mceInit[id] = tinyMCEPreInit.mceInit['black-studio-tinymce-widget'];
16
- tinyMCEPreInit.mceInit[id]["elements"] = id;
17
- try {
18
- // Instantiate new TinyMCE editor
19
- tinymce.init(tinymce.extend( {}, tinyMCEPreInit.mceInit['black-studio-tinymce-widget'], tinyMCEPreInit.mceInit[id] ));
20
- } catch(e){
21
- alert(e);
22
- }
23
- }
24
- else { // WP 3.2
25
- tinyMCE.execCommand("mceAddControl", false, id);
26
- }
27
- }
28
- }
29
- // Deactivate visual editor
30
- function black_studio_deactivate_visual_editor(id) {
31
- if ( typeof( tinyMCE ) == "object" && typeof( tinyMCE.execCommand ) == "function" ) {
32
- if (typeof(tinyMCE.get(id)) == "object") {
33
- var content = tinyMCE.get(id).getContent();
34
- tinyMCE.execCommand("mceRemoveControl", false, id);
35
- $('textarea#'+id).val(content);
36
- }
37
- }
38
- }
39
- // Activate editor deferred (used upon opening the widget)
40
- function black_studio_open_deferred_activate_visual_editor(id) {
41
- $('div.widget-inside:has(#' + id + ') input[id^=widget-black-studio-tinymce][id$=type][value=visual]').each(function() {
42
- // If textarea is visible and animation/ajax has completed (or in accessibility mode) then trigger a click to Visual button and enable the editor
43
- if ($('div.widget:has(#' + id + ') :animated').size() == 0 && typeof(tinyMCE.get(id)) != "object" && $('#' + id).is(':visible')) {
44
- $('a[id^=widget-black-studio-tinymce][id$=visual]', $(this).closest('div.widget-inside')).click();
45
- }
46
- // Otherwise wait and retry later (animation ongoing)
47
- else if (typeof(tinyMCE.get(id)) != "object") {
48
- setTimeout(function(){black_studio_open_deferred_activate_visual_editor(id);id=null;}, 100);
49
- }
50
- // If editor instance is already existing (i.e. dragged from another sidebar) just activate it
51
- else {
52
- $('a[id^=widget-black-studio-tinymce][id$=visual]', $(this).closest('div.widget-inside')).click();
53
- }
54
- });
55
- }
56
-
57
- // Activate editor deferred (used upon ajax requests)
58
- function black_studio_ajax_deferred_activate_visual_editor(id) {
59
- $('div.widget-inside:has(#' + id + ') input[id^=widget-black-studio-tinymce][id$=type][value=visual]').each(function() {
60
- // If textarea is visible and animation/ajax has completed then trigger a click to Visual button and enable the editor
61
- if ($.active == 0 && typeof(tinyMCE.get(id)) != "object" && $('#' + id).is(':visible')) {
62
- $('a[id^=widget-black-studio-tinymce][id$=visual]', $(this).closest('div.widget-inside')).click();
63
- }
64
- // Otherwise wait and retry later (animation ongoing)
65
- else if ($('div.widget:has(#' + id + ') div.widget-inside').is(':visible') && typeof(tinyMCE.get(id)) != "object") {
66
- setTimeout(function(){black_studio_ajax_deferred_activate_visual_editor(id);id=null;}, 100);
67
- }
68
- });
69
- }
70
-
71
-
72
- // Document ready stuff
73
- $(document).ready(function(){
74
- // Event handler for widget opening button
75
- $('div.widget:has(textarea[id^=widget-black-studio-tinymce]) a.widget-action').live('click', function(event){
76
- event.preventDefault();
77
- var $widget = $(this).closest('div.widget');
78
- var $text_area = $('textarea[id^=widget-black-studio-tinymce]', $widget);
79
- $('#wpbody-content').css('overflow', 'visible'); // needed for small screens
80
- $widget.css('position', 'relative').css('z-index', '100'); // needed for small screens
81
- black_studio_open_deferred_activate_visual_editor($text_area.attr('id'));
82
- });
83
- // Force BS handler of opening button to be executed before the one coming with Wordpress
84
- $(document).data("events").click.unshift($(document).data("events").click.pop());
85
- // Event handler for widget saving button
86
- $('div.widget[id*=black-studio-tinymce] input[name=savewidget]').live('click', function(event){
87
- event.preventDefault();
88
- var $widget = $(this).closest('div.widget')
89
- var $text_area = $('textarea[id^=widget-black-studio-tinymce]', $widget);
90
- if (typeof(tinyMCE.get($text_area.attr('id'))) == "object") {
91
- black_studio_deactivate_visual_editor($text_area.attr('id'));
92
- }
93
- // Event handler for ajax complete
94
- $(this).unbind('ajaxSuccess').ajaxSuccess(function(event, xhr, settings) {
95
- var $text_area = $('textarea[id^=widget-black-studio-tinymce]', $(this).closest('div.widget-inside'));
96
- black_studio_ajax_deferred_activate_visual_editor($text_area.attr('id'));
97
- });
98
- });
99
- // Force BS handler of save button to be executed before the one coming with Wordpress
100
- $(document).data("events").click.unshift($(document).data("events").click.pop());
101
- // Event handler for visual switch button
102
- $('a[id^=widget-black-studio-tinymce][id$=visual]').live('click', function(event){
103
- event.preventDefault();
104
- var $widget_inside = $(this).closest('div.widget-inside')
105
- $('input[id^=widget-black-studio-tinymce][id$=type]', $widget_inside).val('visual');
106
- $(this).addClass('active');
107
- $('a[id^=widget-black-studio-tinymce][id$=html]', $widget_inside).removeClass('active');
108
- black_studio_activate_visual_editor($('textarea[id^=widget-black-studio-tinymce]', $widget_inside).attr('id'));
109
- });
110
- // Event handler for html switch button
111
- $('a[id^=widget-black-studio-tinymce][id$=html]').live('click', function(event){
112
- event.preventDefault();
113
- var $widget_inside = $(this).closest('div.widget-inside')
114
- $('input[id^=widget-black-studio-tinymce][id$=type]', $widget_inside).val('html');
115
- $(this).addClass('active');
116
- $('a[id^=widget-black-studio-tinymce][id$=visual]', $widget_inside).removeClass('active');
117
- black_studio_deactivate_visual_editor($('textarea[id^=widget-black-studio-tinymce]', $widget_inside).attr('id'));
118
- });
119
- // Set edCanvas/wpActiveEditor variables used when adding media from media library dialog
120
- $('.editor_media_buttons a').live('click', function(){
121
- var $widget_inside = $(this).closest('div.widget-inside')
122
- edCanvas = $('textarea[id^=widget-black-studio-tinymce]', $widget_inside).get();
123
- wpActiveEditor = $('textarea[id^=widget-black-studio-tinymce]', $widget_inside).attr('id');
124
- });
125
- // Activate editor when in accessibility mode
126
- if($('body.widgets_access').size() > 0) {
127
- var $text_area = $('textarea[id^=widget-black-studio-tinymce]');
128
- black_studio_open_deferred_activate_visual_editor($text_area.attr('id'));
129
- }
130
- });
131
- })(jQuery); // end self-invoked wrapper function
black-studio-tinymce-widget-legacy.min.js DELETED
@@ -1 +0,0 @@
1
- var tinyMCEPreInit;var edCanvas;var wpActiveEditor;(function(c){function d(g){c("#"+g).addClass("mceEditor");if(typeof(tinyMCE)=="object"&&typeof(tinyMCE.execCommand)=="function"){b(g);if(typeof(tinyMCEPreInit.mceInit["black-studio-tinymce-widget"])=="object"){tinyMCEPreInit.mceInit[g]=tinyMCEPreInit.mceInit["black-studio-tinymce-widget"];tinyMCEPreInit.mceInit[g]["elements"]=g;try{tinymce.init(tinymce.extend({},tinyMCEPreInit.mceInit["black-studio-tinymce-widget"],tinyMCEPreInit.mceInit[g]))}catch(f){alert(f)}}else{tinyMCE.execCommand("mceAddControl",false,g)}}}function b(g){if(typeof(tinyMCE)=="object"&&typeof(tinyMCE.execCommand)=="function"){if(typeof(tinyMCE.get(g))=="object"){var f=tinyMCE.get(g).getContent();tinyMCE.execCommand("mceRemoveControl",false,g);c("textarea#"+g).val(f)}}}function a(f){c("div.widget-inside:has(#"+f+") input[id^=widget-black-studio-tinymce][id$=type][value=visual]").each(function(){if(c("div.widget:has(#"+f+") :animated").size()==0&&typeof(tinyMCE.get(f))!="object"&&c("#"+f).is(":visible")){c("a[id^=widget-black-studio-tinymce][id$=visual]",c(this).closest("div.widget-inside")).click()}else{if(typeof(tinyMCE.get(f))!="object"){setTimeout(function(){a(f);f=null},100)}else{c("a[id^=widget-black-studio-tinymce][id$=visual]",c(this).closest("div.widget-inside")).click()}}})}function e(f){c("div.widget-inside:has(#"+f+") input[id^=widget-black-studio-tinymce][id$=type][value=visual]").each(function(){if(c.active==0&&typeof(tinyMCE.get(f))!="object"&&c("#"+f).is(":visible")){c("a[id^=widget-black-studio-tinymce][id$=visual]",c(this).closest("div.widget-inside")).click()}else{if(c("div.widget:has(#"+f+") div.widget-inside").is(":visible")&&typeof(tinyMCE.get(f))!="object"){setTimeout(function(){e(f);f=null},100)}}})}c(document).ready(function(){c("div.widget:has(textarea[id^=widget-black-studio-tinymce]) a.widget-action").live("click",function(g){g.preventDefault();var i=c(this).closest("div.widget");var h=c("textarea[id^=widget-black-studio-tinymce]",i);c("#wpbody-content").css("overflow","visible");i.css("position","relative").css("z-index","100");a(h.attr("id"))});c(document).data("events").click.unshift(c(document).data("events").click.pop());c("div.widget[id*=black-studio-tinymce] input[name=savewidget]").live("click",function(g){g.preventDefault();var i=c(this).closest("div.widget");var h=c("textarea[id^=widget-black-studio-tinymce]",i);if(typeof(tinyMCE.get(h.attr("id")))=="object"){b(h.attr("id"))}c(this).unbind("ajaxSuccess").ajaxSuccess(function(k,l,j){var m=c("textarea[id^=widget-black-studio-tinymce]",c(this).closest("div.widget-inside"));e(m.attr("id"))})});c(document).data("events").click.unshift(c(document).data("events").click.pop());c("a[id^=widget-black-studio-tinymce][id$=visual]").live("click",function(g){g.preventDefault();var h=c(this).closest("div.widget-inside");c("input[id^=widget-black-studio-tinymce][id$=type]",h).val("visual");c(this).addClass("active");c("a[id^=widget-black-studio-tinymce][id$=html]",h).removeClass("active");d(c("textarea[id^=widget-black-studio-tinymce]",h).attr("id"))});c("a[id^=widget-black-studio-tinymce][id$=html]").live("click",function(g){g.preventDefault();var h=c(this).closest("div.widget-inside");c("input[id^=widget-black-studio-tinymce][id$=type]",h).val("html");c(this).addClass("active");c("a[id^=widget-black-studio-tinymce][id$=visual]",h).removeClass("active");b(c("textarea[id^=widget-black-studio-tinymce]",h).attr("id"))});c(".editor_media_buttons a").live("click",function(){var g=c(this).closest("div.widget-inside");edCanvas=c("textarea[id^=widget-black-studio-tinymce]",g).get();wpActiveEditor=c("textarea[id^=widget-black-studio-tinymce]",g).attr("id")});if(c("body.widgets_access").size()>0){var f=c("textarea[id^=widget-black-studio-tinymce]");a(f.attr("id"))}})})(jQuery);
black-studio-tinymce-widget.css DELETED
@@ -1,7 +0,0 @@
1
- /* CSS Document */
2
- #wp-black-studio-tinymce-widget-wrap {
3
- display: none;
4
- }
5
- #available-widgets [class*="black-studio-tinymce"] .widget-title:before {
6
- content: "\f116";
7
- }
black-studio-tinymce-widget.js DELETED
@@ -1,160 +0,0 @@
1
- // TinyMCE initialization parameters
2
- var tinyMCEPreInit;
3
- // Current editor
4
- var wpActiveEditor;
5
-
6
- (function( $ ) {
7
- // Activate visual editor
8
- function black_studio_activate_visual_editor(id) {
9
- $( '#' + id ).addClass( 'mceEditor' );
10
- if ( typeof tinyMCE == 'object' && typeof tinyMCE.execCommand == 'function' ) {
11
- black_studio_deactivate_visual_editor( id );
12
- tinyMCEPreInit.mceInit[id] = tinyMCEPreInit.mceInit['black-studio-tinymce-widget'];
13
- tinyMCEPreInit.mceInit[id]['selector'] = '#' + id;
14
- try {
15
- // Instantiate new TinyMCE editor
16
- tinymce.init( tinymce.extend( {}, tinyMCEPreInit.mceInit['black-studio-tinymce-widget'], tinyMCEPreInit.mceInit[id] ) );
17
- tinyMCE.execCommand( 'mceAddControl', false, id );
18
- } catch( e ) {
19
- alert( e );
20
- }
21
- if ( tinyMCE.get( id ) != null) {
22
- if ( typeof tinyMCE.get( id ).on == 'function' ) {
23
- tinyMCE.get( id ).on( 'keyup change', function() {
24
- var content = tinyMCE.get( id ).getContent();
25
- $( 'textarea#' + id ).val( content ).change();
26
- });
27
- }
28
- }
29
- }
30
- }
31
- // Deactivate visual editor
32
- function black_studio_deactivate_visual_editor( id ) {
33
- if ( typeof tinyMCE == 'object' && typeof tinyMCE.execCommand == 'function' ) {
34
- if ( tinyMCE.get( id ) != null && typeof tinyMCE.get( id ).getContent == 'function' ) {
35
- var content = tinyMCE.get( id ).getContent();
36
- // tinyMCE.execCommand('mceRemoveControl', false, id);
37
- tinyMCE.get( id ).remove();
38
- $( 'textarea#' + id ).val( content );
39
- }
40
- }
41
- }
42
- // Activate editor deferred (used upon opening the widget)
43
- function black_studio_open_deferred_activate_visual_editor( id ) {
44
- $( 'div.widget-inside:has(#' + id + ') input[id^=widget-black-studio-tinymce][id$=type][value=visual]' ).each(function() {
45
- // If textarea is visible and animation/ajax has completed (or in accessibility mode) then trigger a click to Visual button and enable the editor
46
- if ( $('div.widget:has(#' + id + ') :animated' ).size() == 0 && tinyMCE.get( id ) == null && $( '#' + id ).is( ':visible' ) ) {
47
- $( 'a[id^=widget-black-studio-tinymce][id$=tmce]', $( this ).closest( 'div.widget-inside' ) ).click();
48
- }
49
- // Otherwise wait and retry later (animation ongoing)
50
- else if ( tinyMCE.get( id ) == null ) {
51
- setTimeout(function() {
52
- black_studio_open_deferred_activate_visual_editor( id );
53
- id = null;
54
- }, 100 );
55
- }
56
- // If editor instance is already existing (i.e. dragged from another sidebar) just activate it
57
- else {
58
- $( 'a[id^=widget-black-studio-tinymce][id$=tmce]', $( this ).closest( 'div.widget-inside' ) ).click();
59
- }
60
- });
61
- }
62
-
63
- // Activate editor deferred (used upon ajax requests)
64
- function black_studio_ajax_deferred_activate_visual_editor( id ) {
65
- $( 'div.widget-inside:has(#' + id + ') input[id^=widget-black-studio-tinymce][id$=type][value=visual]' ).each(function() {
66
- // If textarea is visible and animation/ajax has completed then trigger a click to Visual button and enable the editor
67
- if ( $.active == 0 && tinyMCE.get( id ) == null && $( '#' + id ).is( ':visible' ) ) {
68
- $( 'a[id^=widget-black-studio-tinymce][id$=tmce]', $( this ).closest( 'div.widget-inside' ) ).click();
69
- }
70
- // Otherwise wait and retry later (animation ongoing)
71
- else if ( $( 'div.widget:has(#' + id + ') div.widget-inside' ).is( ':visible' ) && tinyMCE.get( id ) == null ) {
72
- setTimeout(function() {
73
- black_studio_ajax_deferred_activate_visual_editor( id );
74
- id=null;
75
- }, 100 );
76
- }
77
- });
78
- }
79
-
80
-
81
-
82
- // Document ready stuff
83
- $( document ).ready(function() {
84
- // Event handler for widget opening button
85
- $( document ).on( 'click', 'div.widget:has(textarea[id^=widget-black-studio-tinymce]) .widget-title, div.widget:has(textarea[id^=widget-black-studio-tinymce]) a.widget-action', function( event ) {
86
- //event.preventDefault();
87
- var $widget = $( this ).closest( 'div.widget' );
88
- var $text_area = $( 'textarea[id^=widget-black-studio-tinymce]', $widget );
89
- if ( $( '[name="' + $( '#' + $text_area.attr('id') ).attr('name') + '"]' ).size() > 1) {
90
- var $widget_inside = $( 'div.widget-inside', $widget );
91
- if ( $( 'div.error', $widget_inside).length == 0 ) {
92
- $widget_inside.prepend('<div class="error"><strong>' + black_studio_tinymce_local.error_duplicate_id + '</strong></div>');
93
- }
94
- }
95
- // Event handler for widget saving button (for new instances)
96
- $( 'input[name=savewidget]', $widget ).on( 'click', function( event ) {
97
- var $widget = $( this ).closest( 'div.widget' )
98
- var $text_area = $( 'textarea[id^=widget-black-studio-tinymce]', $widget );
99
- if ( tinyMCE.get( $text_area.attr( 'id' ) ) != null ) {
100
- black_studio_deactivate_visual_editor( $text_area.attr( 'id' ) );
101
- }
102
- // Event handler for ajax complete
103
- $( this ).unbind( 'ajaxSuccess' ).ajaxSuccess( function( event, xhr, settings ) {
104
- var $text_area = $( 'textarea[id^=widget-black-studio-tinymce]', $( this ).closest( 'div.widget-inside') );
105
- black_studio_ajax_deferred_activate_visual_editor( $text_area.attr( 'id' ) );
106
- });
107
- });
108
- $( '#wpbody-content' ).css( 'overflow', 'visible' ); // needed for small screens
109
- $widget.css( 'position', 'relative' ).css( 'z-index', '100000' ); // needed for small screens and for fullscreen mode
110
- black_studio_open_deferred_activate_visual_editor( $text_area.attr( 'id' ) );
111
- $( '.insert-media', $widget ).data( 'editor', $text_area.attr( 'id' ) );
112
- });
113
- // Event handler for widget saving button (for existing instances)
114
- $( 'div.widget[id*=black-studio-tinymce] input[name=savewidget]').on( 'click', function( event ) {
115
- var $widget = $( this ).closest( 'div.widget' )
116
- var $text_area = $( 'textarea[id^=widget-black-studio-tinymce]', $widget );
117
- if ( tinyMCE.get( $text_area.attr( 'id' ) ) != null ) {
118
- black_studio_deactivate_visual_editor( $text_area.attr( 'id' ) );
119
- }
120
- // Event handler for ajax complete
121
- $( this ).unbind( 'ajaxSuccess' ).ajaxSuccess( function( event, xhr, settings ) {
122
- var $text_area = $( 'textarea[id^=widget-black-studio-tinymce]', $( this ).closest( 'div.widget-inside' ) );
123
- black_studio_ajax_deferred_activate_visual_editor( $text_area.attr( 'id' ) );
124
- });
125
- });
126
- // Event handler for visual switch button
127
- $( document ).on( 'click', 'a[id^=widget-black-studio-tinymce][id$=tmce]', function( event ) {
128
- //event.preventDefault();
129
- var $widget_inside = $( this ).closest( 'div.widget-inside,div.panel-dialog' );
130
- var $wrap_id = $( 'div[id^=wp-widget-black-studio-tinymce][id$=-wrap]', $widget_inside );
131
- var $textarea_id = $( 'textarea[id^=widget-black-studio-tinymce]', $widget_inside ).attr( 'id' )
132
- tinymce.DOM.removeClass( $wrap_id, 'html-active' );
133
- tinymce.DOM.addClass( $wrap_id, 'tmce-active' );
134
- $( 'input[id^=widget-black-studio-tinymce][id$=type]', $widget_inside ).val( 'visual' );
135
- black_studio_activate_visual_editor( $textarea_id );
136
- });
137
- // Event handler for html switch button
138
- $( document ).on( 'click', 'a[id^=widget-black-studio-tinymce][id$=html]', function( event ) {
139
- //event.preventDefault();
140
- var $widget_inside = $( this ).closest( 'div.widget-inside,div.panel-dialog' );
141
- var $wrap_id = $( 'div[id^=wp-widget-black-studio-tinymce][id$=-wrap]', $widget_inside );
142
- var $textarea_id = $( 'textarea[id^=widget-black-studio-tinymce]', $widget_inside ).attr( 'id' )
143
- $( 'input[id^=widget-black-studio-tinymce][id$=type]', $widget_inside ).val( 'visual' );
144
- tinymce.DOM.removeClass( $wrap_id, 'tmce-active' );
145
- tinymce.DOM.addClass( $wrap_id, 'html-active' );
146
- $( 'input[id^=widget-black-studio-tinymce][id$=type]', $widget_inside ).val( 'html' );
147
- black_studio_deactivate_visual_editor( $textarea_id );
148
- });
149
- // Set wpActiveEditor variables used when adding media from media library dialog
150
- $( document ).on( 'click', '.wp-media-buttons a', function() {
151
- var $widget_inside = $( this ).closest( 'div.widget-inside' );
152
- wpActiveEditor = $( 'textarea[id^=widget-black-studio-tinymce]', $widget_inside ).attr( 'id' );
153
- });
154
- // Activate editor when in accessibility mode
155
- if ( $( 'body.widgets_access' ).size() > 0) {
156
- var $text_area = $( 'textarea[id^=widget-black-studio-tinymce]' );
157
- black_studio_open_deferred_activate_visual_editor( $text_area.attr( 'id' ) );
158
- }
159
- });
160
- })( jQuery ); // end self-invoked wrapper function
black-studio-tinymce-widget.min.js DELETED
@@ -1 +0,0 @@
1
- var tinyMCEPreInit;var wpActiveEditor;(function(c){function d(g){c("#"+g).addClass("mceEditor");if(typeof tinyMCE=="object"&&typeof tinyMCE.execCommand=="function"){b(g);tinyMCEPreInit.mceInit[g]=tinyMCEPreInit.mceInit["black-studio-tinymce-widget"];tinyMCEPreInit.mceInit[g]["selector"]="#"+g;try{tinymce.init(tinymce.extend({},tinyMCEPreInit.mceInit["black-studio-tinymce-widget"],tinyMCEPreInit.mceInit[g]));tinyMCE.execCommand("mceAddControl",false,g)}catch(f){alert(f)}if(tinyMCE.get(g)!=null){if(typeof tinyMCE.get(g).on=="function"){tinyMCE.get(g).on("keyup change",function(){var h=tinyMCE.get(g).getContent();c("textarea#"+g).val(h).change()})}}}}function b(g){if(typeof tinyMCE=="object"&&typeof tinyMCE.execCommand=="function"){if(tinyMCE.get(g)!=null&&typeof tinyMCE.get(g).getContent=="function"){var f=tinyMCE.get(g).getContent();tinyMCE.get(g).remove();c("textarea#"+g).val(f)}}}function a(f){c("div.widget-inside:has(#"+f+") input[id^=widget-black-studio-tinymce][id$=type][value=visual]").each(function(){if(c("div.widget:has(#"+f+") :animated").size()==0&&tinyMCE.get(f)==null&&c("#"+f).is(":visible")){c("a[id^=widget-black-studio-tinymce][id$=tmce]",c(this).closest("div.widget-inside")).click()}else{if(tinyMCE.get(f)==null){setTimeout(function(){a(f);f=null},100)}else{c("a[id^=widget-black-studio-tinymce][id$=tmce]",c(this).closest("div.widget-inside")).click()}}})}function e(f){c("div.widget-inside:has(#"+f+") input[id^=widget-black-studio-tinymce][id$=type][value=visual]").each(function(){if(c.active==0&&tinyMCE.get(f)==null&&c("#"+f).is(":visible")){c("a[id^=widget-black-studio-tinymce][id$=tmce]",c(this).closest("div.widget-inside")).click()}else{if(c("div.widget:has(#"+f+") div.widget-inside").is(":visible")&&tinyMCE.get(f)==null){setTimeout(function(){e(f);f=null},100)}}})}c(document).ready(function(){c(document).on("click","div.widget:has(textarea[id^=widget-black-studio-tinymce]) .widget-title, div.widget:has(textarea[id^=widget-black-studio-tinymce]) a.widget-action",function(g){var j=c(this).closest("div.widget");var i=c("textarea[id^=widget-black-studio-tinymce]",j);if(c('[name="'+c("#"+i.attr("id")).attr("name")+'"]').size()>1){var h=c("div.widget-inside",j);if(c("div.error",h).length==0){h.prepend('<div class="error"><strong>'+black_studio_tinymce_local.error_duplicate_id+"</strong></div>")}}c("input[name=savewidget]",j).on("click",function(k){var m=c(this).closest("div.widget");var l=c("textarea[id^=widget-black-studio-tinymce]",m);if(tinyMCE.get(l.attr("id"))!=null){b(l.attr("id"))}c(this).unbind("ajaxSuccess").ajaxSuccess(function(o,p,n){var q=c("textarea[id^=widget-black-studio-tinymce]",c(this).closest("div.widget-inside"));e(q.attr("id"))})});c("#wpbody-content").css("overflow","visible");j.css("position","relative").css("z-index","100000");a(i.attr("id"));c(".insert-media",j).data("editor",i.attr("id"))});c("div.widget[id*=black-studio-tinymce] input[name=savewidget]").on("click",function(g){var i=c(this).closest("div.widget");var h=c("textarea[id^=widget-black-studio-tinymce]",i);if(tinyMCE.get(h.attr("id"))!=null){b(h.attr("id"))}c(this).unbind("ajaxSuccess").ajaxSuccess(function(k,l,j){var m=c("textarea[id^=widget-black-studio-tinymce]",c(this).closest("div.widget-inside"));e(m.attr("id"))})});c(document).on("click","a[id^=widget-black-studio-tinymce][id$=tmce]",function(h){var i=c(this).closest("div.widget-inside,div.panel-dialog");var j=c("div[id^=wp-widget-black-studio-tinymce][id$=-wrap]",i);var g=c("textarea[id^=widget-black-studio-tinymce]",i).attr("id");tinymce.DOM.removeClass(j,"html-active");tinymce.DOM.addClass(j,"tmce-active");c("input[id^=widget-black-studio-tinymce][id$=type]",i).val("visual");d(g)});c(document).on("click","a[id^=widget-black-studio-tinymce][id$=html]",function(h){var i=c(this).closest("div.widget-inside,div.panel-dialog");var j=c("div[id^=wp-widget-black-studio-tinymce][id$=-wrap]",i);var g=c("textarea[id^=widget-black-studio-tinymce]",i).attr("id");c("input[id^=widget-black-studio-tinymce][id$=type]",i).val("visual");tinymce.DOM.removeClass(j,"tmce-active");tinymce.DOM.addClass(j,"html-active");c("input[id^=widget-black-studio-tinymce][id$=type]",i).val("html");b(g)});c(document).on("click",".wp-media-buttons a",function(){var g=c(this).closest("div.widget-inside");wpActiveEditor=c("textarea[id^=widget-black-studio-tinymce]",g).attr("id")});if(c("body.widgets_access").size()>0){var f=c("textarea[id^=widget-black-studio-tinymce]");a(f.attr("id"))}})})(jQuery);
black-studio-tinymce-widget.php CHANGED
@@ -1,302 +1,238 @@
1
- <?php
2
- /*
3
- Plugin Name: Black Studio TinyMCE Widget
4
- Plugin URI: http://wordpress.org/extend/plugins/black-studio-tinymce-widget/
5
- Description: Adds a WYSIWYG widget based on the standard TinyMCE WordPress visual editor.
6
- Version: 1.4.8
7
- Author: Black Studio
8
- Author URI: http://www.blackstudio.it
9
- License: GPLv3
10
- Text Domain: black-studio-tinymce-widget
11
- Domain Path: /languages
12
- */
13
-
14
- /* Widget class */
15
- class WP_Widget_Black_Studio_TinyMCE extends WP_Widget {
16
-
17
- function __construct() {
18
- $widget_ops = array( 'classname' => 'widget_black_studio_tinymce', 'description' => __( 'Arbitrary text or HTML with visual editor', 'black-studio-tinymce-widget' ) );
19
- $control_ops = array( 'width' => 800, 'height' => 800 );
20
- parent::__construct( 'black-studio-tinymce', __( 'Visual Editor', 'black-studio-tinymce-widget' ), $widget_ops, $control_ops );
21
- }
22
-
23
- function widget( $args, $instance ) {
24
- if ( get_option( 'embed_autourls' ) ) {
25
- $wp_embed = $GLOBALS['wp_embed'];
26
- add_filter( 'widget_text', array( $wp_embed, 'run_shortcode' ), 8 );
27
- add_filter( 'widget_text', array( $wp_embed, 'autoembed' ), 8 );
28
- }
29
- extract( $args );
30
- $before_text = apply_filters( 'black_studio_tinymce_before_text', '<div class="textwidget">', $instance );
31
- $after_text = apply_filters( 'black_studio_tinymce_after_text', '</div>', $instance );
32
- $title = apply_filters( 'widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base );
33
- $text = apply_filters( 'widget_text', $instance['text'], $instance );
34
- if ( function_exists( 'icl_t' ) && ! empty( $this->number ) ) {
35
- $title = icl_t( "Widgets", 'widget title - ' . md5 ( $title ), $title );
36
- $text = icl_t( "Widgets", 'widget body - ' . $this->id_base . '-' . $this->number, $text );
37
- }
38
- $text = do_shortcode( $text );
39
- echo $before_widget;
40
- if ( ! empty( $title ) ) {
41
- echo $before_title . $title . $after_title;
42
- }
43
- echo $before_text . $text . $after_text;
44
- echo $after_widget;
45
- }
46
-
47
- function update( $new_instance, $old_instance ) {
48
- $instance = $old_instance;
49
- $instance['title'] = strip_tags( $new_instance['title'] );
50
- if ( current_user_can( 'unfiltered_html' ) ) {
51
- $instance['text'] = $new_instance['text'];
52
- }
53
- else {
54
- $instance['text'] = stripslashes( wp_filter_post_kses( addslashes( $new_instance['text'] ) ) ); // wp_filter_post_kses() expects slashed
55
- }
56
- $instance['type'] = strip_tags( $new_instance['type'] );
57
- if ( function_exists( 'icl_register_string' ) && ! empty( $this->number ) ) {
58
- //icl_register_string( "Widgets", 'widget title - ' . $this->id_base . '-' . $this->number /* md5 ( apply_filters( 'widget_title', $instance['title'] ))*/, apply_filters( 'widget_title', $instance['title'] ) ); // This is handled automatically by WPML
59
- icl_register_string( "Widgets", 'widget body - ' . $this->id_base . '-' . $this->number, apply_filters( 'widget_text', $instance['text'] ) );
60
- }
61
- return $instance;
62
- }
63
-
64
- function form( $instance ) {
65
- $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'text' => '', 'type' => 'visual' ) );
66
- $title = strip_tags( $instance['title'] );
67
- if ( function_exists( 'esc_textarea' ) ) {
68
- $text = esc_textarea( $instance['text'] );
69
- }
70
- else {
71
- $text = stripslashes( wp_filter_post_kses( addslashes( $instance['text'] ) ) );
72
- }
73
- $type = esc_attr( $instance['type'] );
74
- $switch_class = $type == 'visual' ? 'html-active' : 'tmce-active';
75
- if ( version_compare( get_bloginfo( 'version' ), '3.5', '<' ) ) {
76
- $toggle_buttons_class = "editor_toggle_buttons_legacy";
77
- $media_buttons_class = "editor_media_buttons_legacy";
78
- }
79
- else if ( version_compare( get_bloginfo( 'version' ), '3.8', '<' ) ) {
80
- $toggle_buttons_class = "wp-toggle-buttons";
81
- $media_buttons_class = "wp-media-buttons";
82
- }
83
- else {
84
- $toggle_buttons_class = "wp-editor-tabs";
85
- $media_buttons_class = "wp-media-buttons";
86
- }
87
-
88
- ?>
89
- <input id="<?php echo $this->get_field_id( 'type' ); ?>" name="<?php echo $this->get_field_name( 'type' ); ?>" type="hidden" value="<?php echo esc_attr( $type ); ?>" />
90
- <p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
91
- <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></p>
92
- <div id="wp-<?php echo $this->get_field_id( 'text' ); ?>-wrap" class="wp-core-ui wp-editor-wrap <?php echo $switch_class; ?>">
93
- <div class="wp-editor-tools hide-if-no-js">
94
- <div class="<?php echo $toggle_buttons_class; ?>">
95
- <a id="<?php echo $this->get_field_id( 'text' ); ?>-html" class="wp-switch-editor switch-html"><?php _e( 'HTML' ); ?></a>
96
- <a id="<?php echo $this->get_field_id( 'text' ); ?>-tmce" class="wp-switch-editor switch-tmce"><?php _e(' Visual' ); ?></a>
97
- </div>
98
- <div class="<?php echo $media_buttons_class; ?>">
99
- <?php do_action( 'media_buttons', $this->get_field_id( 'text' ) ); ?>
100
- </div>
101
- </div>
102
- <div class="wp-editor-container">
103
- <textarea class="widefat" rows="20" cols="40" id="<?php echo $this->get_field_id( 'text' ); ?>" name="<?php echo $this->get_field_name('text'); ?>"><?php echo $text; ?></textarea>
104
- </div>
105
- </div>
106
- <div class="wp-editor-bstw-links" style="font-size: 10px; text-align: right; padding: 5px 0;"><a href="http://www.blackstudio.it/en/wordpress-plugins/black-studio-tinymce-widget/" target="_blank"><?php echo __( 'Donate', 'black-studio-tinymce-widget' ); ?></a> | <a href="http://wordpress.org/support/plugin/black-studio-tinymce-widget" target="_blank"><?php echo __( 'Support', 'black-studio-tinymce-widget' ); ?></a> | <a href="http://wordpress.org/support/view/plugin-reviews/black-studio-tinymce-widget" target="_blank"><?php echo __( 'Rate', 'black-studio-tinymce-widget' ); ?></a> | <a href="https://twitter.com/blackstudioita" target="_blank"><?php echo __( 'Follow', 'black-studio-tinymce-widget' ); ?></a></div>
107
- <?php
108
- }
109
- }
110
-
111
- /* Get plugin version */
112
- function black_studio_tinymce_get_version() {
113
- if ( ! function_exists( 'get_plugins' ) )
114
- require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
115
- $plugin_folder = get_plugins( '/' . plugin_basename( dirname( __FILE__ ) ) );
116
- $plugin_file = basename( ( __FILE__ ) );
117
- return $plugin_folder[$plugin_file]['Version'];
118
- }
119
-
120
- /* Load localization */
121
- load_plugin_textdomain( 'black-studio-tinymce-widget', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
122
-
123
- /* Widget initialization */
124
- add_action( 'widgets_init', 'black_studio_tinymce_widgets_init' );
125
- function black_studio_tinymce_widgets_init() {
126
- if ( ! is_blog_installed() )
127
- return;
128
- register_widget( 'WP_Widget_Black_Studio_TinyMCE' );
129
- }
130
-
131
- /* Add actions and filters (only in widgets admin page) */
132
- add_action( 'admin_init', 'black_studio_tinymce_admin_init' );
133
- function black_studio_tinymce_admin_init() {
134
- global $pagenow;
135
- $load_editor = false;
136
- if ( $pagenow == "widgets.php" || $pagenow == "customize.php" ) {
137
- $load_editor = true;
138
- }
139
- // Compatibility for WP Page Widget plugin
140
- if ( is_plugin_active('wp-page-widget/wp-page-widgets.php' ) && (
141
- ( in_array( $pagenow, array( 'post-new.php', 'post.php') ) ) ||
142
- ( in_array( $pagenow, array( 'edit-tags.php' ) ) && isset( $_GET['action'] ) && $_GET['action'] == 'edit' ) ||
143
- ( in_array( $pagenow, array( 'admin.php' ) ) && isset( $_GET['page'] ) && in_array( $_GET['page'], array( 'pw-front-page', 'pw-search-page' ) ) )
144
- ) ) {
145
- $load_editor = true;
146
- }
147
- if ( $load_editor ) {
148
- add_action( 'admin_head', 'black_studio_tinymce_load_tiny_mce' );
149
- add_filter( 'tiny_mce_before_init', 'black_studio_tinymce_init_editor', 20 );
150
- add_action( 'admin_print_scripts', 'black_studio_tinymce_scripts' );
151
- add_action( 'admin_print_styles', 'black_studio_tinymce_styles' );
152
- add_action( 'admin_print_footer_scripts', 'black_studio_tinymce_footer_scripts' );
153
- add_filter( 'atd_load_scripts', '__return_true'); // Compatibility with Jetpack After the deadline
154
- }
155
- }
156
-
157
- /* Instantiate tinyMCE editor */
158
- function black_studio_tinymce_load_tiny_mce() {
159
- // Add support for thickbox media dialog
160
- add_thickbox();
161
- // New media modal dialog (WP 3.5+)
162
- if ( function_exists( 'wp_enqueue_media' ) ) {
163
- wp_enqueue_media();
164
- }
165
- }
166
-
167
- /* TinyMCE setup customization */
168
- function black_studio_tinymce_init_editor( $initArray ) {
169
- global $pagenow;
170
- // Remove WP fullscreen mode and set the native tinyMCE fullscreen mode
171
- if ( version_compare( get_bloginfo( 'version' ), '3.3', '<' ) ) {
172
- $plugins = explode(',', $initArray['plugins']);
173
- if ( isset( $plugins['wpfullscreen'] ) ) {
174
- unset( $plugins['wpfullscreen'] );
175
- }
176
- if ( ! isset( $plugins['fullscreen'] ) ) {
177
- $plugins[] = 'fullscreen';
178
- }
179
- $initArray['plugins'] = implode( ',', $plugins );
180
- }
181
- // Remove the "More" toolbar button (only in widget screen)
182
- if ( $pagenow == "widgets.php" && version_compare( get_bloginfo( 'version' ), '3.8', '<' )) {
183
- $initArray['theme_advanced_buttons1'] = str_replace( ',wp_more', '', $initArray['theme_advanced_buttons1'] );
184
- }
185
- // Do not remove linebreaks
186
- $initArray['remove_linebreaks'] = false;
187
- // Convert newline characters to BR tags
188
- $initArray['convert_newlines_to_brs'] = false;
189
- // Force P newlines
190
- $initArray['force_p_newlines'] = true;
191
- // Force no newlines for BR
192
- $initArray['force_br_newlines'] = false;
193
- // Do not remove redundant BR tags
194
- $initArray['remove_redundant_brs'] = false;
195
- // Force p block
196
- $initArray['forced_root_block'] = 'p';
197
- // Apply source formatting
198
- $initArray['apply_source_formatting'] = true;
199
- // Return modified settings
200
- return $initArray;
201
- }
202
-
203
- /* Widget js loading */
204
- function black_studio_tinymce_scripts() {
205
- wp_enqueue_script('media-upload');
206
- $version = black_studio_tinymce_get_version();
207
- $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
208
- if ( version_compare( get_bloginfo( 'version' ), '3.3', '>=' ) ) {
209
- $local_data = array( 'error_duplicate_id' => __('ERROR: Duplicate widget ID detected. To avoid content loss, please create a new one with the same content and then delete this widget.', 'black-studio-tinymce-widget') );
210
- wp_enqueue_script( 'wplink' );
211
- wp_enqueue_script( 'wpdialogs-popup' );
212
- wp_enqueue_script( 'black-studio-tinymce-widget', plugins_url('black-studio-tinymce-widget' . $suffix . '.js', __FILE__ ), array( 'jquery', 'editor' ), $version, true );
213
- wp_localize_script( 'black-studio-tinymce-widget', 'black_studio_tinymce_local', $local_data );
214
- do_action( 'wp_enqueue_editor', array( 'tinymce' => true ) ); // Advanced Image Styles compatibility
215
- }
216
- else {
217
- wp_enqueue_script( 'black-studio-tinymce-widget-legacy', plugins_url('black-studio-tinymce-widget-legacy' . $suffix . '.js', __FILE__ ), array( 'jquery', 'editor' ), $version, true );
218
- }
219
- }
220
-
221
- /* Widget css loading */
222
- function black_studio_tinymce_styles() {
223
- if ( version_compare( get_bloginfo( 'version' ), '3.3', '<' ) ) {
224
- wp_enqueue_style( 'thickbox' );
225
- }
226
- else {
227
- wp_enqueue_style( 'wp-jquery-ui-dialog' );
228
- }
229
- $style = 'black-studio-tinymce-widget';
230
- $version = black_studio_tinymce_get_version();
231
- wp_enqueue_style( 'editor-buttons' );
232
- if ( version_compare( get_bloginfo( 'version' ), '3.8', '<' ) ) {
233
- $style .= '-legacy';
234
- }
235
- wp_enqueue_style( $style, plugins_url( $style. '.css', __FILE__ ), array(), $version );
236
- }
237
-
238
-
239
- /* Footer script */
240
- function black_studio_tinymce_footer_scripts() {
241
- // Setup for WP 3.1 and previous versions
242
- if ( version_compare( get_bloginfo( 'version' ), '3.2', '<' ) ) {
243
- if ( function_exists( 'wp_tiny_mce' ) ) {
244
- wp_tiny_mce( false, array() );
245
- }
246
- if ( function_exists( 'wp_tiny_mce_preload_dialogs' ) ) {
247
- wp_tiny_mce_preload_dialogs();
248
- }
249
- }
250
- // Setup for WP 3.2
251
- else if ( version_compare( get_bloginfo( 'version' ), '3.3', '<' ) ) {
252
- if ( function_exists( 'wp_tiny_mce' ) ) {
253
- wp_tiny_mce( false, array() );
254
- }
255
- if ( function_exists( 'wp_preload_dialogs') ) {
256
- wp_preload_dialogs( array( 'plugins' => 'wpdialogs,wplink,wpfullscreen' ) );
257
- }
258
- }
259
- // Setup for WP 3.3+ - New Editor API
260
- else {
261
- wp_editor( '', 'black-studio-tinymce-widget' );
262
- }
263
- }
264
-
265
- /* Support for Smilies */
266
- add_filter( 'widget_text', 'black_studio_tinymce_apply_smilies_to_widget_text' );
267
- function black_studio_tinymce_apply_smilies_to_widget_text( $text ) {
268
- if ( get_option( 'use_smilies' ) ) {
269
- $text = convert_smilies( $text );
270
- }
271
- return $text;
272
- }
273
-
274
- /* Hack needed to enable full media options when adding content from media library */
275
- /* (this is done excluding post_id parameter in Thickbox iframe url) */
276
- add_filter( '_upload_iframe_src', 'black_studio_tinymce_upload_iframe_src' );
277
- function black_studio_tinymce_upload_iframe_src ( $upload_iframe_src ) {
278
- global $pagenow;
279
- if ( $pagenow == "widgets.php" || ( $pagenow == "admin-ajax.php" && isset ( $_POST['id_base'] ) && $_POST['id_base'] == "black-studio-tinymce" ) ) {
280
- $upload_iframe_src = str_replace( 'post_id=0', '', $upload_iframe_src );
281
- }
282
- return $upload_iframe_src;
283
- }
284
-
285
- /* Hack for widgets accessibility mode */
286
- add_filter( 'wp_default_editor', 'black_studio_tinymce_editor_accessibility_mode' );
287
- function black_studio_tinymce_editor_accessibility_mode($editor) {
288
- global $pagenow;
289
- if ( $pagenow == "widgets.php" && isset( $_GET['editwidget'] ) && strpos( $_GET['editwidget'], 'black-studio-tinymce' ) === 0 ) {
290
- $editor = 'html';
291
- }
292
- return $editor;
293
- }
294
-
295
- /* Hack for compatibility with Page Builder + WPML String Translation */
296
- add_filter( 'siteorigin_panels_widget_object', 'black_studio_tinymce_siteorigin_panels_widget_object', 10, 2 );
297
- function black_studio_tinymce_siteorigin_panels_widget_object( $the_widget, $widget ) {
298
- if ( isset($the_widget->id_base) && $the_widget->id_base == 'black-studio-tinymce' ) {
299
- $the_widget->number = '';
300
- }
301
- return $the_widget;
302
- }
1
+ <?php
2
+ /*
3
+ Plugin Name: Black Studio TinyMCE Widget
4
+ Plugin URI: https://wordpress.org/plugins/black-studio-tinymce-widget/
5
+ Description: Adds a new "Visual Editor" widget type based on the native WordPress TinyMCE editor.
6
+ Version: 2.0.0
7
+ Author: Black Studio
8
+ Author URI: http://www.blackstudio.it
9
+ Requires at least: 3.1
10
+ Tested up to: 4.0
11
+ License: GPLv3
12
+ Text Domain: black-studio-tinymce-widget
13
+ Domain Path: /languages
14
+ */
15
+
16
+ // Exit if accessed directly
17
+ if ( ! defined( 'ABSPATH' ) ) {
18
+ exit;
19
+ }
20
+
21
+ /**
22
+ * Main plugin class
23
+ *
24
+ * @package Black_Studio_TinyMCE_Widget
25
+ * @since 2.0.0
26
+ */
27
+
28
+ if ( ! class_exists( 'Black_Studio_TinyMCE_Plugin' ) ) {
29
+
30
+ final class Black_Studio_TinyMCE_Plugin {
31
+
32
+ /**
33
+ * Plugin version
34
+ *
35
+ * @var string
36
+ * @since 2.0.0
37
+ */
38
+ public static $version = '2.0.0';
39
+
40
+ /**
41
+ * The single instance of the plugin class
42
+ *
43
+ * @var object
44
+ * @since 2.0.0
45
+ */
46
+ protected static $_instance = null;
47
+
48
+ /**
49
+ * Instance of admin class
50
+ *
51
+ * @var object
52
+ * @since 2.0.0
53
+ */
54
+ protected static $admin = null;
55
+
56
+ /**
57
+ * Instance of compatibility class
58
+ *
59
+ * @var object
60
+ * @since 2.0.0
61
+ */
62
+ protected static $compatibility = null;
63
+
64
+ /**
65
+ * Instance of the text filters class
66
+ *
67
+ * @var object
68
+ * @since 2.0.0
69
+ */
70
+ protected static $text_filters = null;
71
+
72
+ /**
73
+ * Return the main plugin instance
74
+ *
75
+ * @return object
76
+ * @since 2.0.0
77
+ */
78
+ public static function instance() {
79
+ if ( is_null( self::$_instance ) ) {
80
+ self::$_instance = new self();
81
+ }
82
+ return self::$_instance;
83
+ }
84
+
85
+ /**
86
+ * Return the instance of the admin class
87
+ *
88
+ * @return object
89
+ * @since 2.0.0
90
+ */
91
+ public static function admin() {
92
+ return self::$admin;
93
+ }
94
+
95
+ /**
96
+ * Return the instance of the compatibility class
97
+ *
98
+ * @return object
99
+ * @since 2.0.0
100
+ */
101
+ public static function compatibility() {
102
+ return self::$compatibility;
103
+ }
104
+
105
+ /**
106
+ * Return the instance of the text filters class
107
+ *
108
+ * @return object
109
+ * @since 2.0.0
110
+ */
111
+ public static function text_filters() {
112
+ return self::$text_filters;
113
+ }
114
+
115
+ /**
116
+ * Get plugin version
117
+ *
118
+ * @return string
119
+ * @since 2.0.0
120
+ */
121
+ public static function get_version() {
122
+ return self::$version;
123
+ }
124
+
125
+ /**
126
+ * Get plugin basename
127
+ *
128
+ * @uses plugin_basename()
129
+ *
130
+ * @return string
131
+ * @since 2.0.0
132
+ */
133
+ public static function get_basename() {
134
+ return plugin_basename( __FILE__ );
135
+ }
136
+
137
+ /**
138
+ * Class constructor
139
+ *
140
+ * @uses add_action()
141
+ * @uses add_filter()
142
+ * @uses get_option()
143
+ * @uses get_bloginfo()
144
+ *
145
+ * @global object $wp_embed
146
+ * @return void
147
+ * @since 2.0.0
148
+ */
149
+ protected function __construct() {
150
+ // Include required files
151
+ include_once( plugin_dir_path( __FILE__ ) . '/includes/class-widget.php' );
152
+ // Include and instantiate admin class on admin pages
153
+ if ( is_admin() ) {
154
+ include_once( plugin_dir_path( __FILE__ ) . '/includes/class-admin.php' );
155
+ self::$admin = Black_Studio_TinyMCE_Admin::instance();
156
+ }
157
+ // Include and instantiate text filter class on frontend pages
158
+ else {
159
+ include_once( plugin_dir_path( __FILE__ ) . '/includes/class-text-filters.php' );
160
+ self::$text_filters = Black_Studio_TinyMCE_Text_Filters::instance();
161
+ }
162
+ // Register action and filter hooks
163
+ add_action( 'plugins_loaded', array( $this, 'load_compatibility' ), 20 );
164
+ add_action( 'widgets_init', array( $this, 'widgets_init' ) );
165
+ }
166
+
167
+ /**
168
+ * Prevent the class from being cloned
169
+ *
170
+ * @return void
171
+ * @since 2.0.0
172
+ */
173
+ protected function __clone() {
174
+ _doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; uh?' ), '2.0' );
175
+ }
176
+
177
+ /**
178
+ * Load compatibility class
179
+ *
180
+ * @uses apply_filters()
181
+ * @uses get_bloginfo()
182
+ * @uses plugin_dir_path()
183
+ *
184
+ * @return void
185
+ * @since 2.0.0
186
+ */
187
+ public function load_compatibility() {
188
+ // Compatibility load flag (for both deprecated functions and code for compatibility with other plugins)
189
+ $load_compatibility = apply_filters( 'black_studio_tinymce_load_compatibility', true );
190
+ if ( $load_compatibility ) {
191
+ include_once( plugin_dir_path( __FILE__ ) . '/includes/class-compatibility.php' );
192
+ self::$compatibility = Black_Studio_TinyMCE_Compatibility::instance();
193
+ }
194
+ }
195
+
196
+ /**
197
+ * Widget initialization
198
+ *
199
+ * @uses is_blog_installed()
200
+ * @uses register_widget()
201
+ *
202
+ * @return null|void
203
+ * @since 2.0.0
204
+ */
205
+ public function widgets_init() {
206
+ if ( ! is_blog_installed() ) {
207
+ return;
208
+ }
209
+ register_widget( 'WP_Widget_Black_Studio_TinyMCE' );
210
+ }
211
+
212
+ /**
213
+ * Check if a widget is a Black Studio Tinyme Widget instance
214
+ *
215
+ * @param object $widget
216
+ * @return boolean
217
+ * @since 2.0.0
218
+ */
219
+ public function check_widget( $widget ) {
220
+ return gettype( $widget ) == 'object' && get_class( $widget ) == 'WP_Widget_Black_Studio_TinyMCE';
221
+ }
222
+
223
+ } // END class Black_Studio_TinyMCE_Plugin
224
+
225
+ } // class_exists check
226
+
227
+ /**
228
+ * Return the main instance to prevent the need to use globals
229
+ *
230
+ * @return object
231
+ * @since 2.0.0
232
+ */
233
+ function bstw() {
234
+ return Black_Studio_TinyMCE_Plugin::instance();
235
+ }
236
+
237
+ /* Create the main instance */
238
+ bstw();
css/black-studio-tinymce-widget-pre33.css ADDED
@@ -0,0 +1,99 @@
1
+ /* Black Studio TinyMCE Widget - CSS */
2
+
3
+ .bstw-links {
4
+ font-size: 11px;
5
+ margin-top: -3px;
6
+ text-align: right;
7
+ position: absolute;
8
+ right: 18px;
9
+ }
10
+
11
+ .bstw-links .icon-plugins {
12
+ float: right;
13
+ padding: 3px 6px;
14
+ margin: -8px -8px 0 -2px;
15
+ background: transparent url('../../../../wp-admin/images/menu.png') no-repeat scroll -180px -33px;
16
+ width: 16px;
17
+ height: 16px;
18
+ }
19
+
20
+ .bstw-links .bstw-links-list {
21
+ display: none;
22
+ }
23
+
24
+ .bstw-links a {
25
+ text-decoration: none;
26
+ }
27
+
28
+ #mce_fullscreen_container {
29
+ background-color: white;
30
+ }
31
+
32
+ #wp-black-studio-tinymce-widget-wrap {
33
+ display: none;
34
+ }
35
+
36
+ #TB_overlay, #TB_window {
37
+ z-index: 999999;
38
+ }
39
+
40
+ .wp-editor-container {
41
+ border-style: solid;
42
+ border-width: 1px;
43
+ border-collapse: separate;
44
+ -moz-border-radius: 3px 3px 0 0;
45
+ -webkit-border-top-right-radius: 3px;
46
+ -webkit-border-top-left-radius: 3px;
47
+ -khtml-border-top-right-radius: 3px;
48
+ -khtml-border-top-left-radius: 3px;
49
+ border-top-right-radius: 3px;
50
+ border-top-left-radius: 3px;
51
+ border-color: #ccc #ccc #dfdfdf;
52
+ clear: both;
53
+ }
54
+
55
+ .wp-switch-editor {
56
+ height: 18px;
57
+ margin: 5px 5px 0 0;
58
+ padding: 4px 5px 2px;
59
+ float: right;
60
+ cursor: pointer;
61
+ border-width: 1px;
62
+ border-style: solid;
63
+ -moz-border-radius: 3px 3px 0 0;
64
+ -webkit-border-top-right-radius: 3px;
65
+ -webkit-border-top-left-radius: 3px;
66
+ -khtml-border-top-right-radius: 3px;
67
+ -khtml-border-top-left-radius: 3px;
68
+ border-top-right-radius: 3px;
69
+ border-top-left-radius: 3px;
70
+ background-color: #f1f1f1;
71
+ border-color: #dfdfdf #dfdfdf #ccc;
72
+ color: #999;
73
+ position: relative;
74
+ top: 1px;
75
+ }
76
+
77
+ .tmce-active .switch-tmce, .html-active .switch-html {
78
+ border-color: #ccc #ccc #e9e9e9;
79
+ background-color: #e9e9e9;
80
+ color: #333;
81
+ }
82
+
83
+ .wp-media-buttons {
84
+ cursor: default;
85
+ padding: 8px 8px 0;
86
+ }
87
+
88
+ .wp-media-buttons a {
89
+ cursor: pointer;
90
+ padding: 0 0 5px 10px;
91
+ }
92
+
93
+ .wp-media-buttons img {
94
+ vertical-align: middle;
95
+ }
96
+
97
+ .wp_themeSkin .mceStatusbar {
98
+ border-color: #dfdfdf;
99
+ }
css/black-studio-tinymce-widget-pre33.min.css ADDED
@@ -0,0 +1,2 @@
1
+ /* Black Studio TinyMCE Widget - v2.0.0 */
2
+ .bstw-links{font-size:11px;margin-top:-3px;text-align:right;position:absolute;right:18px}.bstw-links .icon-plugins{float:right;padding:3px 6px;margin:-8px -8px 0 -2px;background:url(../../../../wp-admin/images/menu.png) -180px -33px no-repeat;width:16px;height:16px}.bstw-links .bstw-links-list{display:none}.bstw-links a{text-decoration:none}#mce_fullscreen_container{background-color:#fff}#wp-black-studio-tinymce-widget-wrap{display:none}#TB_overlay,#TB_window{z-index:999999}.wp-editor-container{border-style:solid;border-width:1px;border-collapse:separate;-moz-border-radius:3px 3px 0 0;-webkit-border-top-right-radius:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-right-radius:3px;-khtml-border-top-left-radius:3px;border-top-right-radius:3px;border-top-left-radius:3px;border-color:#ccc #ccc #dfdfdf;clear:both}.wp-switch-editor{height:18px;margin:5px 5px 0 0;padding:4px 5px 2px;float:right;cursor:pointer;border-width:1px;border-style:solid;-moz-border-radius:3px 3px 0 0;-webkit-border-top-right-radius:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-right-radius:3px;-khtml-border-top-left-radius:3px;border-top-right-radius:3px;border-top-left-radius:3px;background-color:#f1f1f1;border-color:#dfdfdf #dfdfdf #ccc;color:#999;position:relative;top:1px}.html-active .switch-html,.tmce-active .switch-tmce{border-color:#ccc #ccc #e9e9e9;background-color:#e9e9e9;color:#333}.wp-media-buttons{cursor:default;padding:8px 8px 0}.wp-media-buttons a{cursor:pointer;padding:0 0 5px 10px}.wp-media-buttons img{vertical-align:middle}.wp_themeSkin .mceStatusbar{border-color:#dfdfdf}
css/black-studio-tinymce-widget.css ADDED
@@ -0,0 +1,55 @@
1
+ /* Black Studio TinyMCE Widget - CSS */
2
+
3
+ .bstw-links {
4
+ font-size: 11px;
5
+ margin-top: -3px;
6
+ text-align: right;
7
+ position: absolute;
8
+ right: 18px;
9
+ }
10
+
11
+ .bstw-links .icon16:before {
12
+ padding: 0;
13
+ }
14
+
15
+ .bstw-links .icon16 {
16
+ float: right;
17
+ padding: 3px 6px;
18
+ margin: -6px -8px 0 -2px;
19
+ }
20
+
21
+ .bstw-links .bstw-links-list {
22
+ display: none;
23
+ }
24
+
25
+ .bstw-links a {
26
+ text-decoration: none;
27
+ }
28
+
29
+ #wp-black-studio-tinymce-widget-wrap {
30
+ display: none;
31
+ }
32
+
33
+ div[id*="black-studio-tinymce"] .wp-editor-wrap {
34
+ margin-bottom: 1em;
35
+ }
36
+
37
+ #available-widgets [class*="black-studio-tinymce"] .widget-title:before {
38
+ content: "\f116";
39
+ }
40
+
41
+ .wp-customizer .mce-floatpanel.mce-popover {
42
+ z-index: 500000 !important;
43
+ }
44
+
45
+ #TB_overlay, #TB_window {
46
+ z-index: 999999 !important;
47
+ }
48
+
49
+ body.wait, body.wait * {
50
+ cursor: wait !important;
51
+ }
52
+
53
+ #zedity_content_overlay {
54
+ z-index: 100000 !important;
55
+ }
css/black-studio-tinymce-widget.min.css ADDED
@@ -0,0 +1,2 @@
1
+ /* Black Studio TinyMCE Widget - v2.0.0 */
2
+ .bstw-links{font-size:11px;margin-top:-3px;text-align:right;position:absolute;right:18px}.bstw-links .icon16:before{padding:0}.bstw-links .icon16{float:right;padding:3px 6px;margin:-6px -8px 0 -2px}.bstw-links .bstw-links-list{display:none}.bstw-links a{text-decoration:none}#wp-black-studio-tinymce-widget-wrap{display:none}div[id*=black-studio-tinymce] .wp-editor-wrap{margin-bottom:1em}#available-widgets [class*=black-studio-tinymce] .widget-title:before{content:"\f116"}.wp-customizer .mce-floatpanel.mce-popover{z-index:500000!important}#TB_overlay,#TB_window{z-index:999999!important}body.wait,body.wait *{cursor:wait!important}#zedity_content_overlay{z-index:100000!important}
includes/class-admin.php ADDED
@@ -0,0 +1,371 @@
1
+ <?php
2
+
3
+ // Exit if accessed directly
4
+ if ( ! defined( 'ABSPATH' ) ) {
5
+ exit;
6
+ }
7
+
8
+ /**
9
+ * Class that provides admin functionalities
10
+ *
11
+ * @package Black_Studio_TinyMCE_Widget
12
+ * @since 2.0.0
13
+ */
14
+
15
+ if ( ! class_exists( 'Black_Studio_TinyMCE_Admin' ) ) {
16
+
17
+ final class Black_Studio_TinyMCE_Admin {
18
+
19
+ /**
20
+ * The single instance of the class
21
+ *
22
+ * @var object
23
+ * @since 2.0.0
24
+ */
25
+ protected static $_instance = null;
26
+
27
+ /**
28
+ * Array containing the plugin links
29
+ *
30
+ * @var array
31
+ * @since 2.0.0
32
+ */
33
+ protected $links;
34
+
35
+ /**
36
+ * Return the single class instance
37
+ *
38
+ * @return object
39
+ * @since 2.0.0
40
+ */
41
+ public static function instance() {
42
+ if ( is_null( self::$_instance ) ) {
43
+ self::$_instance = new self();
44
+ }
45
+ return self::$_instance;
46
+ }
47
+
48
+ /**
49
+ * Class constructor
50
+ *
51
+ * @uses add_action()
52
+ * @uses add_filter()
53
+ * @uses get_option()
54
+ * @uses get_bloginfo()
55
+ *
56
+ * @global object $wp_embed
57
+ * @return void
58
+ * @since 2.0.0
59
+ */
60
+ protected function __construct() {
61
+ // Register action and filter hooks
62
+ add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) );
63
+ add_action( 'admin_init', array( $this, 'admin_init' ), 20 );
64
+ add_filter( 'wp_default_editor', array( $this, 'editor_accessibility_mode' ) );
65
+ }
66
+
67
+ /**
68
+ * Prevent the class from being cloned
69
+ *
70
+ * @return void
71
+ * @since 2.0.0
72
+ */
73
+ protected function __clone() {
74
+ _doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; uh?' ), '2.0' );
75
+ }
76
+
77
+ /**
78
+ * Load language files
79
+ *
80
+ * @uses load_plugin_textdomain()
81
+ *
82
+ * @return void
83
+ * @since 2.0.0
84
+ */
85
+ public function load_textdomain() {
86
+ load_plugin_textdomain( 'black-studio-tinymce-widget', false, dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/' );
87
+ }
88
+
89
+ /**
90
+ * Checks if the plugin admin code should be loaded
91
+ *
92
+ * @uses apply_filters()
93
+ *
94
+ * @global string $pagenow
95
+ * @return void
96
+ * @since 2.0.0
97
+ */
98
+ public function enabled() {
99
+ global $pagenow;
100
+ $enabled_pages = apply_filters( 'black_studio_tinymce_enable_pages', array( 'widgets.php', 'customize.php', 'admin-ajax.php' ) );
101
+ return apply_filters( 'black_studio_tinymce_enable', in_array( $pagenow, $enabled_pages ) );
102
+ }
103
+
104
+ /**
105
+ * Add actions and filters (only in widgets admin page)
106
+ *
107
+ * @uses add_action()
108
+ * @uses add_filter()
109
+ * @uses do_action()
110
+ *
111
+ * @return void
112
+ * @since 2.0.0
113
+ */
114
+ public function admin_init() {
115
+ $this->init_links();
116
+ add_action( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 2 );
117
+ if ( $this->enabled() ) {
118
+ add_action( 'admin_head', array( $this, 'enqueue_media' ) );
119
+ add_action( 'admin_print_scripts', array( $this, 'admin_print_scripts' ) );
120
+ add_action( 'admin_print_styles', array( $this, 'admin_print_styles' ) );
121
+ add_action( 'admin_print_footer_scripts', array( $this, 'admin_print_footer_scripts' ) );
122
+ add_action( 'black_studio_tinymce_editor', array( $this, 'editor' ), 10, 3 );
123
+ add_action( 'black_studio_tinymce_before_editor', array( $this, 'display_links' ) ); // consider donating if you remove links
124
+ add_filter( 'wp_editor_settings', array( $this, 'editor_settings' ), 10, 2 );
125
+ do_action( 'black_studio_tinymce_load' );
126
+ }
127
+ }
128
+
129
+ /**
130
+ * Instantiate tinyMCE editor
131
+ *
132
+ * @uses add_thickbox()
133
+ * @uses wp_enqueue_media()
134
+ *
135
+ * @return void
136
+ * @since 2.0.0
137
+ */
138
+ public function enqueue_media() {
139
+ // Add support for thickbox media dialog
140
+ add_thickbox();
141
+ // New media modal dialog (WP 3.5+)
142
+ if ( function_exists( 'wp_enqueue_media' ) ) {
143
+ wp_enqueue_media();
144
+ }
145
+ }
146
+
147
+ /**
148
+ * Enqueue styles
149
+ *
150
+ * @uses wp_enqueue_style()
151
+ * @uses Black_Studio_TinyMCE_Plugin::enqueue_style()
152
+ *
153
+ * @return void
154
+ * @since 2.0.0
155
+ */
156
+ public function admin_print_styles() {
157
+ wp_enqueue_style( 'wp-jquery-ui-dialog' );
158
+ wp_enqueue_style( 'editor-buttons' );
159
+ $this->enqueue_style();
160
+ }
161
+
162
+ /**
163
+ * Helper function to enqueue style
164
+ *
165
+ * @uses apply_filters()
166
+ * @uses wp_enqueue_style()
167
+ * @uses plugins_url()
168
+ * @uses SCRIPT_DEBUG
169
+ *
170
+ * @return void
171
+ * @since 2.0.0
172
+ */
173
+ public function enqueue_style() {
174
+ $style = apply_filters( 'black-studio-tinymce-widget-style', 'black-studio-tinymce-widget' );
175
+ $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
176
+ wp_enqueue_style(
177
+ $style,
178
+ plugins_url( 'css/' . $style . $suffix. '.css', dirname( __FILE__ ) ),
179
+ array(),
180
+ bstw()->get_version()
181
+ );
182
+ }
183
+
184
+ /**
185
+ * Enqueue header scripts
186
+ *
187
+ * @uses wp_enqueue_script()
188
+ * @uses Black_Studio_TinyMCE_Plugin::enqueue_script()
189
+ * @uses Black_Studio_TinyMCE_Plugin::localize_script()
190
+ * @uses do_action()
191
+ *
192
+ * @return void
193
+ * @since 2.0.0
194
+ */
195
+ public function admin_print_scripts() {
196
+ wp_enqueue_script( 'media-upload' );
197
+ wp_enqueue_script( 'wplink' );
198
+ wp_enqueue_script( 'wpdialogs-popup' );
199
+ $this->enqueue_script();
200
+ $this->localize_script();
201
+ do_action( 'wp_enqueue_editor', array( 'tinymce' => true ) );
202
+ }
203
+
204
+ /**
205
+ * Helper function to enqueue script
206
+ *
207
+ * @uses apply_filters()
208
+ * @uses wp_enqueue_script()
209
+ * @uses plugins_url()
210
+ * @uses SCRIPT_DEBUG
211
+ *
212
+ * @return void
213
+ * @since 2.0.0
214
+ */
215
+ public function enqueue_script() {
216
+ $script = apply_filters( 'black-studio-tinymce-widget-script', 'black-studio-tinymce-widget' );
217
+ $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
218
+ wp_enqueue_script(
219
+ $script,
220
+ plugins_url( 'js/' . $script . $suffix . '.js', dirname( __FILE__ ) ),
221
+ array( 'jquery', 'editor', 'quicktags' ),
222
+ bstw()->get_version(),
223
+ true
224
+ );
225
+ }
226
+
227
+ /**
228
+ * Helper function to enqueue localized script
229
+ *
230
+ * @uses apply_filters()
231
+ * @uses wp_localize_script()
232
+ *
233
+ * @return void
234
+ * @since 2.0.0
235
+ */
236
+ public function localize_script() {
237
+ $container_selectors = apply_filters( 'black_studio_tinymce_container_selectors', array( 'div.widget', 'div.widget-inside' ) );
238
+ $activate_events = apply_filters( 'black_studio_tinymce_activate_events', array() );
239
+ $deactivate_events = apply_filters( 'black_studio_tinymce_deactivate_events', array() );
240
+ $data = array(
241
+ 'container_selectors' => implode( ', ', $container_selectors ),
242
+ 'activate_events' => $activate_events,
243
+ 'deactivate_events' => $deactivate_events,
244
+ /* translators: error message shown when a duplicated widget ID is detected */
245
+ 'error_duplicate_id' => __( 'ERROR: Duplicate widget ID detected. To avoid content loss, please create a new widget with the same content and then delete this one.', 'black-studio-tinymce-widget' )
246
+ );
247
+ wp_localize_script( apply_filters( 'black-studio-tinymce-widget-script', 'black-studio-tinymce-widget' ), 'bstw_data', $data );
248
+ }
249
+
250
+ /**
251
+ * Enqueue footer scripts
252
+ *
253
+ * @uses wp_editor()
254
+ *
255
+ * @return void
256
+ * @since 2.0.0
257
+ */
258
+ public function admin_print_footer_scripts() {
259
+ $this->editor( '', 'black-studio-tinymce-widget', 'black-studio-tinymce-widget' );
260
+ }
261
+
262
+ /**
263
+ * Output the visual editor
264
+ *
265
+ * @uses wp_editor()
266
+ *
267
+ * @param string $text
268
+ * @param string $editor_id
269
+ * @param string $name
270
+ * @return void
271
+ * @since 2.0.0
272
+ */
273
+ public function editor( $text, $editor_id, $name = '' ) {
274
+ wp_editor( $text, $editor_id, $this->editor_settings( array( 'textarea_name' => $name ), $editor_id ) );
275
+ }
276
+
277
+ /**
278
+ * Set editor settings
279
+ *
280
+ * @param mixed[] $settings
281
+ * @param string $editor_id
282
+ * @return mixed[]
283
+ * @since 2.0.0
284
+ */
285
+ public function editor_settings( $settings, $editor_id ) {
286
+ if ( strstr( $editor_id, 'black-studio-tinymce' ) ) {
287
+ $settings['default_editor'] = 'tmce';
288
+ $settings['tinymce'] = array( 'wp_skip_init' => true );
289
+ $settings['editor_height'] = 350;
290
+ }
291
+ return $settings;
292
+ }
293
+
294
+ /**
295
+ * Edit widgets in accessibility mode
296
+ *
297
+ * @global string $pagenow
298
+ * @param string $editor
299
+ * @return string
300
+ * @since 2.0.0
301
+ */
302
+ public function editor_accessibility_mode( $editor ) {
303
+ global $pagenow;
304
+ if ( $pagenow == 'widgets.php' && isset( $_GET['editwidget'] ) && strpos( $_GET['editwidget'], 'black-studio-tinymce' ) === 0 ) {
305
+ $editor = 'html';
306
+ }
307
+ return $editor;
308
+ }
309
+
310
+ /**
311
+ * Initialize plugin links
312
+ *
313
+ * @return void
314
+ * @since 2.0.0
315
+ */
316
+ public function init_links() {
317
+ $this->links = array(
318
+ /* translators: text used for plugin home link */
319
+ 'https://wordpress.org/plugins/black-studio-tinymce-widget/' => __( 'Home', 'black-studio-tinymce-widget' ),
320
+ /* translators: text used for support faq link */
321
+ 'https://wordpress.org/plugins/black-studio-tinymce-widget/faq/' => __( 'FAQ', 'black-studio-tinymce-widget' ),
322
+ /* translators: text used for support forum link */
323
+ 'https://wordpress.org/support/plugin/black-studio-tinymce-widget' => __( 'Support', 'black-studio-tinymce-widget' ),
324
+ /* translators: text used for reviews link */
325
+ 'https://wordpress.org/support/view/plugin-reviews/black-studio-tinymce-widget' => __( 'Rate', 'black-studio-tinymce-widget' ),
326
+ /* translators: text used for follow on twitter link */
327
+ 'https://twitter.com/blackstudioita' => __( 'Follow', 'black-studio-tinymce-widget' ),
328
+ /* translators: text used for donation link */
329
+ 'http://www.blackstudio.it/en/wordpress-plugins/black-studio-tinymce-widget/' => __( 'Donate', 'black-studio-tinymce-widget' ),
330
+ );
331
+ }
332
+
333
+ /**
334
+ * Display plugin links
335
+ *
336
+ * @return void
337
+ * @since 2.0.0
338
+ */
339
+ public function display_links() {
340
+ echo "\t<div class='bstw-links'>\n";
341
+ echo "\t\t<span class='bstw-links-list'>\n";
342
+ $counter = count( $this->links ) - 1;
343
+ foreach ( $this->links as $url => $label ) {
344
+ $separator = ( $counter-- > 0 ? ' | ' : '' );
345
+ echo "\t\t\t<a href='" . esc_url( $url ) . "' target='_blank'>" . esc_html( $label ) . "</a>$separator\n"; // xss ok
346
+ }
347
+ echo "\t\t</span>\n";
348
+ /* translators: text used for the icon that shows the plugin links */
349
+ echo "\t\t<a class='bstw-links-icon icon16 icon-plugins' href='#' title='" . esc_attr( __( 'About Black Studio TinyMCE Widget plugin', 'black-studio-tinymce-widget' ) ) . "'></a>\n";
350
+ echo "\t</div>\n";
351
+ }
352
+
353
+ /**
354
+ * Show row meta on the plugin screen
355
+ *
356
+ * @param string[] $links
357
+ * @param string $file
358
+ * @return string[]
359
+ */
360
+ public function plugin_row_meta( $links, $file ) {
361
+ if ( $file == bstw()->get_basename() ) {
362
+ foreach ( $this->links as $url => $label ) {
363
+ $links[ $label ] = '<a href="' . esc_url( $url ) . '" target="_blank">' . esc_html( $label ) . '</a>';
364
+ }
365
+ }
366
+ return $links;
367
+ }
368
+
369
+ } // END class Black_Studio_TinyMCE_Admin
370
+
371
+ } // class_exists check
includes/class-compatibility-plugins.php ADDED
@@ -0,0 +1,360 @@
1
+ <?php
2
+
3
+ // Exit if accessed directly
4
+ if ( ! defined( 'ABSPATH' ) ) {
5
+ exit;
6
+ }
7
+
8
+ /**
9
+ * Class that provides compatibility code with other plugins
10
+ *
11
+ * @package Black_Studio_TinyMCE_Widget
12
+ * @since 2.0.0
13
+ */
14
+
15
+ if ( ! class_exists( 'Black_Studio_TinyMCE_Compatibility_Plugins' ) ) {
16
+
17
+ final class Black_Studio_TinyMCE_Compatibility_Plugins {
18
+
19
+ /**
20
+ * The single instance of the class
21
+ *
22
+ * @var object
23
+ * @since 2.0.0
24
+ */
25
+ protected static $_instance = null;
26
+
27
+ /**
28
+ * Return the single class instance
29
+ *
30
+ * @param string[] $plugins
31
+ * @return object
32
+ * @since 2.0.0
33
+ */
34
+ public static function instance( $plugins = array() ) {
35
+ if ( is_null( self::$_instance ) ) {
36
+ self::$_instance = new self( $plugins );
37
+ }
38
+ return self::$_instance;
39
+ }
40
+
41
+ /**
42
+ * Class constructor
43
+ *
44
+ * @param string[] $plugins
45
+ * @return void
46
+ * @since 2.0.0
47
+ */
48
+ protected function __construct( $plugins ) {
49
+ foreach ( $plugins as $plugin ) {
50
+ if ( is_callable( array( $this, $plugin ), false ) ) {
51
+ $this->$plugin();
52
+ }
53
+ }
54
+ }
55
+
56
+ /**
57
+ * Prevent the class from being cloned
58
+ *
59
+ * @return void
60
+ * @since 2.0.0
61
+ */
62
+ protected function __clone() {
63
+ _doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; uh?' ), '2.0' );
64
+ }
65
+
66
+ /**
67
+ * Compatibility with WPML
68
+ *
69
+ * @uses add_filter()
70
+ *
71
+ * @return void
72
+ * @since 2.0.0
73
+ */
74
+ public function wpml() {
75
+ add_filter( 'black_studio_tinymce_widget_update', array( $this, 'wpml_widget_update' ), 10, 2 );
76
+ add_filter( 'widget_text', array( $this, 'wpml_widget_text' ), 5, 3 );
77
+ }
78
+
79
+ /**
80
+ * Add widget text to WPML String translation
81
+ *
82
+ * @uses icl_register_string() Part of WPML
83
+ *
84
+ * @param mixed[] $instance
85
+ * @param object $widget
86
+ * @return mixed[]
87
+ * @since 2.0.0
88
+ */
89
+ public function wpml_widget_update( $instance, $widget ) {
90
+ if ( function_exists( 'icl_register_string' ) && ! empty( $widget->number ) ) {
91
+ icl_register_string( 'Widgets', 'widget body - ' . $widget->id_base . '-' . $widget->number, $instance['text'] );
92
+ }
93
+ return $instance;
94
+ }
95
+
96
+ /**
97
+ * Translate widget text
98
+ *
99
+ * @uses icl_t() Part of WPML
100
+ *
101
+ * @param string $text
102
+ * @param mixed[] $instance
103
+ * @param object|null $widget
104
+ * @return string
105
+ * @since 2.0.0
106
+ */
107
+ public function wpml_widget_text( $text, $instance, $widget = null ) {
108
+ if ( bstw()->check_widget( $widget ) && ! empty( $instance ) ) {
109
+ if ( function_exists( 'icl_t' ) ) {
110
+ $text = icl_t( 'Widgets', 'widget body - ' . $widget->id_base . '-' . $widget->number, $text );
111
+ }
112
+ }
113
+ return $text;
114
+ }
115
+
116
+ /**
117
+ * Compatibility for WP Page Widget plugin
118
+ *
119
+ * @uses add_action()
120
+ *
121
+ * @return void
122
+ * @since 2.0.0
123
+ */
124
+ public function wp_page_widget() {
125
+ add_action( 'admin_init', array( $this, 'wp_page_widget_admin_init' ) );
126
+ }
127
+
128
+ /**
129
+ * Initialize compatibility for WP Page Widget plugin (only for WordPress 3.3+)
130
+ *
131
+ * @uses add_filter()
132
+ * @uses add_action()
133
+ * @uses is_plugin_active()
134
+ * @uses get_bloginfo()
135
+ *
136
+ * @return void
137
+ * @since 2.0.0
138
+ */
139
+ public function wp_page_widget_admin_init() {
140
+ if ( is_admin() && is_plugin_active( 'wp-page-widget/wp-page-widgets.php' ) && version_compare( get_bloginfo( 'version' ), '3.3', '>=' ) ) {
141
+ add_filter( 'black_studio_tinymce_enable_pages', array( $this, 'wp_page_widget_enable_pages' ) );
142
+ add_action( 'admin_print_scripts', array( $this, 'wp_page_widget_enqueue_script' ) );
143
+ }
144
+ }
145
+
146
+ /**
147
+ * Enable filter for WP Page Widget plugin
148
+ *
149
+ * @param string[] $pages
150
+ * @return string[]
151
+ * @since 2.0.0
152
+ */
153
+ public function wp_page_widget_enable_pages( $pages ) {
154
+ $pages[] = 'post-new.php';
155
+ $pages[] = 'post.php';
156
+ if ( isset( $_GET['action'] ) && $_GET['action'] == 'edit' ) {
157
+ $pages[] = 'edit-tags.php';
158
+ }
159
+ if ( isset( $_GET['page'] ) && in_array( $_GET['page'], array( 'pw-front-page', 'pw-search-page' ) ) ) {
160
+ $pages[] = 'admin.php';
161
+ }
162
+ return $pages;
163
+ }
164
+
165
+ /**
166
+ * Enqueue script for WP Page Widget plugin
167
+ *
168
+ * @uses apply_filters()
169
+ * @uses wp_enqueue_script()
170
+ * @uses plugins_url()
171
+ * @uses SCRIPT_DEBUG
172
+ *
173
+ * @return void
174
+ * @since 2.0.0
175
+ */
176
+ public function wp_page_widget_enqueue_script() {
177
+ $main_script = apply_filters( 'black-studio-tinymce-widget-script', 'black-studio-tinymce-widget' );
178
+ $compat_script = 'wp-page-widget';
179
+ $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
180
+ wp_enqueue_script(
181
+ $compat_script,
182
+ plugins_url( 'js/' . $compat_script . $suffix . '.js', dirname( __FILE__ ) ),
183
+ array( 'jquery', 'editor', 'quicktags', $main_script ),
184
+ bstw()->get_version(),
185
+ true
186
+ );
187
+ }
188
+
189
+ /**
190
+ * Compatibility with Page Builder (SiteOrigin Panels)
191
+ *
192
+ * @uses add_action()
193
+ *
194
+ * @return void
195
+ * @since 2.0.0
196
+ */
197
+ public function siteorigin_panels() {
198
+ add_action( 'admin_init', array( $this, 'siteorigin_panels_disable_compat' ), 7 );
199
+ add_action( 'admin_init', array( $this, 'siteorigin_panels_admin_init' ) );
200
+ }
201
+
202
+ /**
203
+ * Initialize compatibility for Page Builder (SiteOrigin Panels)
204
+ *
205
+ * @uses add_filter()
206
+ * @uses add_action()
207
+ * @uses remove_filter()
208
+ * @uses add_action()
209
+ * @uses is_plugin_active()
210
+ *
211
+ * @return void
212
+ * @since 2.0.0
213
+ */
214
+ public function siteorigin_panels_admin_init() {
215
+ if ( is_admin() && is_plugin_active( 'siteorigin-panels/siteorigin-panels.php' ) ) {
216
+ add_filter( 'siteorigin_panels_widget_object', array( $this, 'siteorigin_panels_widget_object' ), 10 );
217
+ add_filter( 'black_studio_tinymce_container_selectors', array( $this, 'siteorigin_panels_container_selectors' ) );
218
+ add_filter( 'black_studio_tinymce_activate_events', array( $this, 'siteorigin_panels_activate_events' ) );
219
+ add_filter( 'black_studio_tinymce_deactivate_events', array( $this, 'siteorigin_panels_deactivate_events' ) );
220
+ add_filter( 'black_studio_tinymce_enable_pages', array( $this, 'siteorigin_panels_enable_pages' ) );
221
+ add_filter( 'wp_editor_settings', array( $this, 'siteorigin_panels_editor_settings' ), 20, 2 );
222
+ remove_filter( 'widget_text', array( bstw()->text_filters(), 'wpautop' ), 40 );
223
+ add_action( 'black_studio_tinymce_after_editor', array( $this, 'siteorigin_panels_after_editor' ) );
224
+ }
225
+ }
226
+
227
+ /**
228
+ * Remove widget number to prevent translation when using Page Builder (SiteOrigin Panels) + WPML String Translation
229
+ *
230
+ * @param object $the_widget
231
+ * @return object
232
+ * @since 2.0.0
233
+ */
234
+ public function siteorigin_panels_widget_object( $the_widget ) {
235
+ if ( isset( $the_widget->id_base ) && $the_widget->id_base == 'black-studio-tinymce' ) {
236
+ $the_widget->number = '';
237
+ }
238
+ return $the_widget;
239
+ }
240
+
241
+ /**
242
+ * Add selector for widget detection for Page Builder (SiteOrigin Panels)
243
+ *
244
+ * @param string[] $selectors
245
+ * @return string[]
246
+ * @since 2.0.0
247
+ */
248
+ public function siteorigin_panels_container_selectors( $selectors ) {
249
+ $selectors[] = 'div.panel-dialog';
250
+ return $selectors;
251
+ }
252
+
253
+ /**
254
+ * Add activate events for Page Builder (SiteOrigin Panels)
255
+ *
256
+ * @param string[] $events
257
+ * @return string[]
258
+ * @since 2.0.0
259
+ */
260
+ public function siteorigin_panels_activate_events( $events ) {
261
+ $events[] = 'panelsopen';
262
+ return $events;
263
+ }
264
+
265
+ /**
266
+ * Add deactivate events for Page Builder (SiteOrigin Panels)
267
+ *
268
+ * @param string[] $events
269
+ * @return string[]
270
+ * @since 2.0.0
271
+ */
272
+ public function siteorigin_panels_deactivate_events( $events ) {
273
+ $events[] = 'panelsdone';
274
+ return $events;
275
+ }
276
+
277
+ /**
278
+ * Add pages filter to enable editor for Page Builder (SiteOrigin Panels)
279
+ *
280
+ * @param string[] $pages
281
+ * @return string[]
282
+ * @since 2.0.0
283
+ */
284
+ public function siteorigin_panels_enable_pages( $pages ) {
285
+ $pages[] = 'post-new.php';
286
+ $pages[] = 'post.php';
287
+ if ( isset( $_GET['page'] ) && $_GET['page'] == 'so_panels_home_page' ) {
288
+ $pages[] = 'themes.php';
289
+ }
290
+ return $pages;
291
+ }
292
+
293
+ /**
294
+ * Editor settings for use within Page Builder (SiteOrigin Panels)
295
+ *
296
+ * @return void
297
+ * @since 2.0.0
298
+ */
299
+ public function siteorigin_panels_editor_settings( $settings, $editor_id ) {
300
+ // Allow initialization of main page/post editor instances
301
+ if ( strstr( $editor_id, 'black-studio-tinymce' ) === false ) {
302
+ $settings['tinymce'] = array( 'wp_skip_init' => false );
303
+ }
304
+ // Prevent wpautop on editor instances inside Page Builder
305
+ if ( $editor_id == 'widget-black-studio-tinymce-{$id}-text' ) {
306
+ $settings['default_editor'] = 'html';
307
+ }
308
+ return $settings;
309
+ }
310
+
311
+ /**
312
+ * Remove editor content filters for use within Page Builder (SiteOrigin Panels)
313
+ * Workaround for WordPress Core bug #28403 https://core.trac.wordpress.org/ticket/28403
314
+ *
315
+ * @return void
316
+ * @since 2.0.0
317
+ */
318
+ public function siteorigin_panels_after_editor() {
319
+ remove_filter( 'the_editor_content', 'wp_htmledit_pre' );
320
+ remove_filter( 'the_editor_content', 'wp_richedit_pre' );
321
+ }
322
+
323
+ /**
324
+ * Disable old compatibility code provided by Page Builder (SiteOrigin Panels)
325
+ *
326
+ * @return void
327
+ * @since 2.0.0
328
+ */
329
+ public function siteorigin_panels_disable_compat( ) {
330
+ remove_action( 'admin_init', 'siteorigin_panels_black_studio_tinymce_admin_init' );
331
+ remove_action( 'admin_enqueue_scripts', 'siteorigin_panels_black_studio_tinymce_admin_enqueue', 15 );
332
+ }
333
+
334
+ /**
335
+ * Compatibility with Jetpack After the deadline
336
+ *
337
+ * @uses add_action()
338
+ *
339
+ * @return void
340
+ * @since 2.0.0
341
+ */
342
+ public function jetpack_after_the_deadline() {
343
+ add_action( 'black_studio_tinymce_load', array( $this, 'jetpack_after_the_deadline_load' ) );
344
+ }
345
+
346
+ /**
347
+ * Load Jetpack After the deadline scripts
348
+ *
349
+ * @uses add_filter()
350
+ *
351
+ * @return void
352
+ * @since 2.0.0
353
+ */
354
+ public function jetpack_after_the_deadline_load() {
355
+ add_filter( 'atd_load_scripts', '__return_true' );
356
+ }
357
+
358
+ } // END class Black_Studio_TinyMCE_Compatibility_Plugins
359
+
360
+ } // class_exists check
includes/class-compatibility-wordpress.php ADDED
@@ -0,0 +1,349 @@
1
+ <?php
2
+
3
+ // Exit if accessed directly
4
+ if ( ! defined( 'ABSPATH' ) ) {
5
+ exit;
6
+ }
7
+
8
+ /**
9
+ * Class that provides compatibility code with older WordPress versions
10
+ *
11
+ * @package Black_Studio_TinyMCE_Widget
12
+ * @since 2.0.0
13
+ */
14
+
15
+ if ( ! class_exists( 'Black_Studio_TinyMCE_Compatibility_Wordpress' ) ) {
16
+
17
+ final class Black_Studio_TinyMCE_Compatibility_Wordpress {
18
+
19
+ /**
20
+ * The single instance of the class
21
+ *
22
+ * @var object
23
+ * @since 2.0.0
24
+ */
25
+ protected static $_instance = null;
26
+
27
+ /**
28
+ * Return the single class instance
29
+ *
30
+ * @return object
31
+ * @since 2.0.0
32
+ */
33
+ public static function instance() {
34
+ if ( is_null( self::$_instance ) ) {
35
+ self::$_instance = new self();
36
+ }
37
+ return self::$_instance;
38
+ }
39
+
40
+ /**
41
+ * Class constructor
42
+ *
43
+ * @uses get_bloginfo()
44
+ * @uses add_action()
45
+ *
46
+ * @param object $plugin
47
+ * @since 2.0.0
48
+ */
49
+ protected function __construct() {
50
+ $current_version = get_bloginfo( 'version' );
51
+ $previous_versions = array( '3.2', '3.3', '3.5', '3.9' );
52
+ foreach ( $previous_versions as $previous_version ) {
53
+ if ( version_compare( $current_version, $previous_version, '<' ) ) {
54
+ add_action( 'admin_init', array( $this, 'wp_pre_' . str_replace( '.', '', $previous_version ) ), intval( 10 * $previous_version ) );
55
+ }
56
+ }
57
+ }
58
+
59
+ /**
60
+ * Prevent the class from being cloned
61
+ *
62
+ * @return void
63
+ * @since 2.0.0
64
+ */
65
+ protected function __clone() {
66
+ _doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; uh?' ), '2.0' );
67
+ }
68
+
69
+ /**
70
+ * Compatibility for WordPress prior to 3.2
71
+ *
72
+ * @uses remove_action()
73
+ * @uses add_action()
74
+ *
75
+ * @return void
76
+ * @since 2.0.0
77
+ */
78
+ public function wp_pre_32() {
79
+ if ( bstw()->admin()->enabled() ) {
80
+ remove_action( 'admin_print_footer_scripts', array( bstw()->admin(), 'admin_print_footer_scripts' ) );
81
+ add_action( 'admin_print_footer_scripts', array( $this, 'wp_pre_32_admin_print_footer_scripts' ) );
82
+ }
83
+ }
84
+
85
+ /**
86
+ * Enqueue footer scripts for WordPress prior to 3.2
87
+ *
88