Raw HTML - Version 1.6.1

Version Description

  • Fixed a conflict with the "AMP Stories" plugin. This fix may also help with current or future conflicts with other plugins that remove the default post filters.
Download this release

Release Info

Developer whiteshadow
Plugin Icon wp plugin Raw HTML
Version 1.6.1
Comparing to
See all releases

Code changes from version 1.6 to 1.6.1

Files changed (3) hide show
  1. include/formatting-override.php +116 -7
  2. raw_html.php +1 -1
  3. readme.txt +4 -1
include/formatting-override.php CHANGED
@@ -39,7 +39,7 @@ function maybe_convert_smilies($content){
39
  }
40
 
41
  // Disable default filters and add our conditional filters
42
- function rawhtml_add_conditional_filters(){
43
  static $filters_added = false;
44
  static $filters = array(
45
  'the_content' => array(
@@ -60,24 +60,135 @@ function rawhtml_add_conditional_filters(){
60
  // This way there's less of a chance that Raw HTML will accidentally apply a filter
61
  // that another plugin has removed (e.g. via "remove_filter('the_content', 'wpautop')").
62
  if ( $filters_added || !isset($filters[current_filter()]) ) {
63
- return;
64
  }
65
 
66
  foreach ( $filters as $tag => $functions ){
67
  foreach ( $functions as $func => $priority ){
68
  if ( remove_filter($tag, $func, $priority) ){
69
- add_filter( $tag, 'maybe_'.$func, $priority - 1 );
70
  };
71
  }
72
  }
73
 
74
  $filters_added = true;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
  }
76
 
77
  // Performance optimization: Start watching for content filters only after everything has
78
  // been loaded and parsed. Running on every hook before that would be a waste.
79
  function rawhtml_add_filter_initializer() {
80
- add_action('all', 'rawhtml_add_conditional_filters');
 
 
 
 
 
 
 
81
  }
82
  add_action('parse_query', 'rawhtml_add_filter_initializer', 1000, 0);
83
 
@@ -328,6 +439,7 @@ function rawhtml_default_settings_panel(){
328
  $output = '<div class="metabox-prefs">';
329
  foreach($fields as $field => $legend){
330
  $esc_field = esc_attr($field);
 
331
  $output .= sprintf(
332
  '<label for="rawhtml_default-%s" style="line-height: 20px;">
333
  <input type="checkbox" name="rawhtml_default-%s" id="rawhtml_default-%s" %s>
@@ -367,6 +479,3 @@ function rawhtml_save_new_defaults($params){
367
  //Store the new defaults
368
  rawhtml_set_default_settings($defaults);
369
  }
370
-
371
-
372
- ?>
39
  }
40
 
41
  // Disable default filters and add our conditional filters
42
+ function rawhtml_add_conditional_filters($param = null){
43
  static $filters_added = false;
44
  static $filters = array(
45
  'the_content' => array(
60
  // This way there's less of a chance that Raw HTML will accidentally apply a filter
61
  // that another plugin has removed (e.g. via "remove_filter('the_content', 'wpautop')").
62
  if ( $filters_added || !isset($filters[current_filter()]) ) {
63
+ return $param;
64
  }
65
 
66
  foreach ( $filters as $tag => $functions ){
67
  foreach ( $functions as $func => $priority ){
68
  if ( remove_filter($tag, $func, $priority) ){
69
+ add_filter( $tag, 'maybe_'.$func, $priority );
70
  };
71
  }
72
  }
73
 
74
  $filters_added = true;
75
+ return $param;
76
+ }
77
+
78
+ class wsRawHtmlWrappedFilter {
79
+ /**
80
+ * @var string
81
+ */
82
+ private $callback;
83
+
84
+ public function __construct($callback) {
85
+ $this->callback = $callback;
86
+ }
87
+
88
+ /**
89
+ * Apply $callback to $content unless it's been disabled for the current post.
90
+ *
91
+ * @param string $content
92
+ * @return string
93
+ */
94
+ public function maybe_apply($content) {
95
+ $func = $this->callback;
96
+
97
+ global $post;
98
+ if ( !isset($post, $post->ID) ) {
99
+ return $func($content);
100
+ }
101
+
102
+ $settings = rawhtml_get_post_settings($post->ID);
103
+ if ( $settings['disable_' . $func] ) {
104
+ return $content;
105
+ } else {
106
+ return $func($content);
107
+ }
108
+ }
109
+ }
110
+
111
+ class wsRawHtmlFilterInterceptor {
112
+ private $filters = array(
113
+ 'the_content' => array(
114
+ 'wpautop' => 10,
115
+ 'wptexturize' => 10,
116
+ 'convert_chars' => 10,
117
+ 'convert_smilies' => 20,
118
+ ),
119
+ 'the_excerpt' => array(
120
+ 'wpautop' => 10,
121
+ 'wptexturize' => 10,
122
+ 'convert_chars' => 10,
123
+ 'convert_smilies' => 20,
124
+ ),
125
+ );
126
+
127
+ private $wrapped_handlers = array();
128
+
129
+ public function __construct() {
130
+ // Since WP 4.7.0 it's possible to add/remove callbacks to the current filter or action.
131
+ // This means we can add the conditional filters right before the default filters would run,
132
+ // which improves our ability to detect if any of the default filters have been removed
133
+ // by someone else. For example, do_blocks() removes wpautop() in the_content (priority: 9).
134
+ foreach($this->filters as $tag => $functions) {
135
+ add_filter($tag, array($this, 'wrap_filters'), 9, 1);
136
+ }
137
+ }
138
+
139
+ public function wrap_filters($content = '') {
140
+ $tag = current_filter();
141
+ if ( !isset($this->filters[$tag]) ) {
142
+ return $content;
143
+ }
144
+
145
+ //Find any filters that still need to be wrapped.
146
+ global $wp_filter;
147
+ foreach($this->filters[$tag] as $callback => $priority) {
148
+ if ( !isset($wp_filter[$tag][$priority][$callback]['function']) ) {
149
+ continue;
150
+ }
151
+
152
+ $current_callback = $wp_filter[$tag][$priority][$callback]['function'];
153
+ if ( is_string($current_callback) && ($current_callback === $callback) ) {
154
+ // Wrap the default callback in a conditional handler.
155
+ $handler = $this->get_handler($callback);
156
+
157
+ // We must update the whole list of callbacks instead of just the 'function'
158
+ // member of a specific callback because $wp_filter[tag] is not a real array
159
+ // but a class that implements ArrayAccess (update happens via offsetSet).
160
+ $callback_list = $wp_filter[$tag][$priority];
161
+ $callback_list[$callback]['function'] = array($handler, 'maybe_apply');
162
+ $wp_filter[$tag][$priority] = $callback_list;
163
+ }
164
+ }
165
+
166
+ return $content;
167
+ }
168
+
169
+ /**
170
+ * @param string $callback
171
+ * @return wsRawHtmlWrappedFilter
172
+ */
173
+ private function get_handler($callback) {
174
+ if ( !isset($this->wrapped_handlers[$callback]) ) {
175
+ $this->wrapped_handlers[$callback] = new wsRawHtmlWrappedFilter($callback);
176
+ }
177
+ return $this->wrapped_handlers[$callback];
178
+ }
179
  }
180
 
181
  // Performance optimization: Start watching for content filters only after everything has
182
  // been loaded and parsed. Running on every hook before that would be a waste.
183
  function rawhtml_add_filter_initializer() {
184
+ if ( class_exists('WP_Hook', false) ) {
185
+ global $wsh_raw_interceptor;
186
+ if ( !isset($wsh_raw_interceptor) ) {
187
+ $wsh_raw_interceptor = new wsRawHtmlFilterInterceptor();
188
+ }
189
+ } else {
190
+ add_action('all', 'rawhtml_add_conditional_filters');
191
+ }
192
  }
193
  add_action('parse_query', 'rawhtml_add_filter_initializer', 1000, 0);
194
 
439
  $output = '<div class="metabox-prefs">';
440
  foreach($fields as $field => $legend){
441
  $esc_field = esc_attr($field);
442
+ /** @noinspection HtmlUnknownAttribute */
443
  $output .= sprintf(
444
  '<label for="rawhtml_default-%s" style="line-height: 20px;">
445
  <input type="checkbox" name="rawhtml_default-%s" id="rawhtml_default-%s" %s>
479
  //Store the new defaults
480
  rawhtml_set_default_settings($defaults);
481
  }
 
 
 
raw_html.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Raw HTML
4
  Plugin URI: http://w-shadow.com/blog/2007/12/13/raw-html-in-wordpress/
5
  Description: Lets you enter any HTML/JS/CSS in your posts without WP changing it, as well as disable automatic formatting on a per-post basis. <strong>Usage:</strong> Wrap your code in [raw]...[/raw] tags. To avoid problems, only edit posts that contain raw code in HTML mode. <strong><a href="http://rawhtmlpro.com/?utm_source=RawHTML%20free&utm_medium=plugin_description&utm_campaign=Plugins">Upgrade to Pro</a></strong> to be able to use Visual editor on the same posts without it messing up the code.
6
- Version: 1.6
7
  Author: Janis Elsts
8
  Author URI: http://w-shadow.com/
9
  */
3
  Plugin Name: Raw HTML
4
  Plugin URI: http://w-shadow.com/blog/2007/12/13/raw-html-in-wordpress/
5
  Description: Lets you enter any HTML/JS/CSS in your posts without WP changing it, as well as disable automatic formatting on a per-post basis. <strong>Usage:</strong> Wrap your code in [raw]...[/raw] tags. To avoid problems, only edit posts that contain raw code in HTML mode. <strong><a href="http://rawhtmlpro.com/?utm_source=RawHTML%20free&utm_medium=plugin_description&utm_campaign=Plugins">Upgrade to Pro</a></strong> to be able to use Visual editor on the same posts without it messing up the code.
6
+ Version: 1.6.1
7
  Author: Janis Elsts
8
  Author URI: http://w-shadow.com/
9
  */
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: whiteshadow
3
  Tags: posts, formatting, javascript, html, css, code, disable
4
  Requires at least: 2.8
5
  Tested up to: 5.2
6
- Stable tag: 1.6
7
 
8
  Lets you use raw HTML or any other code in your posts. You can also disable smart quotes and other automatic formatting on a per-post basis.
9
 
@@ -90,6 +90,9 @@ Open to the post editor and click the "Screen Options" button in the top-right p
90
 
91
  == Changelog ==
92
 
 
 
 
93
  = 1.6 =
94
  * Added a way to preserve `[raw]` blocks in post excerpts.
95
  * Enabled the "Raw HTML" metabox for custom post types.
3
  Tags: posts, formatting, javascript, html, css, code, disable
4
  Requires at least: 2.8
5
  Tested up to: 5.2
6
+ Stable tag: 1.6.1
7
 
8
  Lets you use raw HTML or any other code in your posts. You can also disable smart quotes and other automatic formatting on a per-post basis.
9
 
90
 
91
  == Changelog ==
92
 
93
+ = 1.6.1 =
94
+ * Fixed a conflict with the "AMP Stories" plugin. This fix may also help with current or future conflicts with other plugins that remove the default post filters.
95
+
96
  = 1.6 =
97
  * Added a way to preserve `[raw]` blocks in post excerpts.
98
  * Enabled the "Raw HTML" metabox for custom post types.