Version Description
- Added a way to run shortcodes inside [raw] tags. To enable shortcodes, add the
shortcodes=1
attribute to the tag. Example:[raw shortcodes=1]some code ... [my-shortcode] ... other code[/raw]
. - Fixed a conflict with Events Calendar Pro (+ Community Events add-on). This should also fix conflicts with other plugins that remove default post filters like
wpautop
. - Tested with WP 4.6-beta2.
Download this release
Release Info
Developer | whiteshadow |
Plugin | Raw HTML |
Version | 1.5 |
Comparing to | |
See all releases |
Code changes from version 1.4.16 to 1.5
- include/formatting-override.php +30 -14
- include/tag-handler.php +50 -22
- raw_html.php +1 -1
- readme.txt +15 -2
include/formatting-override.php
CHANGED
@@ -40,30 +40,46 @@ function maybe_convert_smilies($content){
|
|
40 |
|
41 |
// Disable default filters and add our conditional filters
|
42 |
function rawhtml_add_conditional_filters(){
|
43 |
-
$
|
|
|
44 |
'the_content' => array(
|
45 |
-
'wpautop',
|
46 |
-
'wptexturize',
|
47 |
-
'convert_chars',
|
48 |
-
'convert_smilies',
|
49 |
),
|
50 |
'the_excerpt' => array(
|
51 |
-
'wpautop',
|
52 |
-
'wptexturize',
|
53 |
-
'convert_chars',
|
54 |
-
'convert_smilies',
|
55 |
),
|
56 |
);
|
57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
foreach ( $filters as $tag => $functions ){
|
59 |
-
foreach ( $functions as $func ){
|
60 |
-
if ( remove_filter($tag, $func) ){
|
61 |
-
add_filter( $tag, 'maybe_'.$func,
|
62 |
};
|
63 |
}
|
64 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
}
|
66 |
-
add_action('
|
67 |
|
68 |
// Add a custom meta box for per-post settings
|
69 |
add_action('admin_menu', 'rawhtml_add_custom_box');
|
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(
|
46 |
+
'wpautop' => 10,
|
47 |
+
'wptexturize' => 10,
|
48 |
+
'convert_chars' => 10,
|
49 |
+
'convert_smilies' => 20,
|
50 |
),
|
51 |
'the_excerpt' => array(
|
52 |
+
'wpautop' => 10,
|
53 |
+
'wptexturize' => 10,
|
54 |
+
'convert_chars' => 10,
|
55 |
+
'convert_smilies' => 20,
|
56 |
),
|
57 |
);
|
58 |
+
|
59 |
+
// Set up the callbacks when one of the target filters is called for the first time.
|
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 |
|
84 |
// Add a custom meta box for per-post settings
|
85 |
add_action('admin_menu', 'rawhtml_add_custom_box');
|
include/tag-handler.php
CHANGED
@@ -3,8 +3,9 @@
|
|
3 |
/**********************************************
|
4 |
Filter inline blocks of raw HTML
|
5 |
***********************************************/
|
6 |
-
global $wsh_raw_parts;
|
7 |
$wsh_raw_parts = array();
|
|
|
8 |
|
9 |
/**
|
10 |
* Extract content surrounded by [raw] or other supported tags
|
@@ -17,18 +18,24 @@ $wsh_raw_parts = array();
|
|
17 |
* @return string Filtered content.
|
18 |
*/
|
19 |
function wsh_extract_exclusions($text, $keep_tags = false){
|
20 |
-
global $wsh_raw_parts, $wp_current_filter;
|
21 |
-
|
22 |
-
|
23 |
-
$tags = array(
|
|
|
|
|
|
|
|
|
24 |
|
25 |
foreach ($tags as $tag_pair){
|
26 |
-
list($
|
27 |
|
28 |
//Find the start tag
|
29 |
-
$
|
30 |
-
|
31 |
-
|
|
|
|
|
32 |
|
33 |
//find the end tag
|
34 |
$fin = stripos($text, $end_tag, $content_start);
|
@@ -45,21 +52,24 @@ function wsh_extract_exclusions($text, $keep_tags = false){
|
|
45 |
} else {
|
46 |
//Store the content and replace it with a marker
|
47 |
if ( $keep_tags ){
|
48 |
-
$wsh_raw_parts[]=$
|
49 |
} else {
|
50 |
$wsh_raw_parts[]=$content;
|
51 |
-
}
|
52 |
-
$
|
|
|
|
|
|
|
53 |
}
|
54 |
$text = substr_replace($text, $replacement, $start,
|
55 |
$fin+strlen($end_tag)-$start
|
56 |
);
|
57 |
|
|
|
|
|
|
|
58 |
//Have we reached the end of the string yet?
|
59 |
-
if ($
|
60 |
-
|
61 |
-
//Find the next start tag
|
62 |
-
$start = stripos($text, $start_tag, $start + strlen($replacement));
|
63 |
}
|
64 |
}
|
65 |
return $text;
|
@@ -89,18 +99,28 @@ function wsh_insert_exclusions($text, $placeholder_callback = 'wsh_insertion_cal
|
|
89 |
function wsh_get_block_from_matches($matches) {
|
90 |
global $wsh_raw_parts;
|
91 |
|
92 |
-
|
93 |
-
|
94 |
-
} else if ( isset($matches[2]) ) {
|
95 |
-
$index = $matches[2];
|
96 |
-
} else {
|
97 |
return '{Invalid RAW block}';
|
98 |
}
|
99 |
|
100 |
-
$index = intval($index);
|
101 |
return $wsh_raw_parts[$index];
|
102 |
}
|
103 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
104 |
/**
|
105 |
* Regex callback for wsh_insert_exclusions. Returns the extracted content
|
106 |
* corresponding to a matched placeholder.
|
@@ -113,6 +133,14 @@ function wsh_insertion_callback($matches){
|
|
113 |
$closingParagraph = isset($matches[3]) ? $matches[3] : '';
|
114 |
$code = wsh_get_block_from_matches($matches);
|
115 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
//If the [raw] block is wrapped in its own paragraph, strip the <p>...</p> tags. If there's
|
117 |
//only one of <p>|</p> tag present, keep it - it's probably part of a larger paragraph.
|
118 |
if ( empty($openingParagraph) || empty($closingParagraph) ) {
|
3 |
/**********************************************
|
4 |
Filter inline blocks of raw HTML
|
5 |
***********************************************/
|
6 |
+
global $wsh_raw_parts, $wsh_raw_run_shortcodes;
|
7 |
$wsh_raw_parts = array();
|
8 |
+
$wsh_raw_run_shortcodes = array();
|
9 |
|
10 |
/**
|
11 |
* Extract content surrounded by [raw] or other supported tags
|
18 |
* @return string Filtered content.
|
19 |
*/
|
20 |
function wsh_extract_exclusions($text, $keep_tags = false){
|
21 |
+
global $wsh_raw_parts, $wsh_raw_run_shortcodes, $wp_current_filter;
|
22 |
+
|
23 |
+
$shortcode_flag = '(?:\s+shortcodes\s*=\s*[\'"]?(?P<shortcodes>1|0)[\'"]?\s*)?';
|
24 |
+
$tags = array(
|
25 |
+
array('@<!--start_raw-->@i', '<!--end_raw-->'),
|
26 |
+
array('@\[raw' . $shortcode_flag . '\]@i', '[/raw]'),
|
27 |
+
array('@<!--raw' . $shortcode_flag . '-->@i', '<!--/raw-->')
|
28 |
+
);
|
29 |
|
30 |
foreach ($tags as $tag_pair){
|
31 |
+
list($start_regex, $end_tag) = $tag_pair;
|
32 |
|
33 |
//Find the start tag
|
34 |
+
$offset = 0;
|
35 |
+
|
36 |
+
while( preg_match($start_regex, $text, $matches, PREG_OFFSET_CAPTURE, $offset) === 1 ) {
|
37 |
+
$start = $matches[0][1];
|
38 |
+
$content_start = $start + strlen($matches[0][0]);
|
39 |
|
40 |
//find the end tag
|
41 |
$fin = stripos($text, $end_tag, $content_start);
|
52 |
} else {
|
53 |
//Store the content and replace it with a marker
|
54 |
if ( $keep_tags ){
|
55 |
+
$wsh_raw_parts[]=$matches[0][0].$content.$end_tag;
|
56 |
} else {
|
57 |
$wsh_raw_parts[]=$content;
|
58 |
+
}
|
59 |
+
$index = count($wsh_raw_parts) - 1;
|
60 |
+
$replacement = "!RAWBLOCK" . $index . "!";
|
61 |
+
|
62 |
+
$wsh_raw_run_shortcodes[$index] = isset($matches['shortcodes']) && (intval($matches['shortcodes'][0]) == 1);
|
63 |
}
|
64 |
$text = substr_replace($text, $replacement, $start,
|
65 |
$fin+strlen($end_tag)-$start
|
66 |
);
|
67 |
|
68 |
+
//Continue searching after the marker.
|
69 |
+
$offset = $start + strlen($replacement);
|
70 |
+
|
71 |
//Have we reached the end of the string yet?
|
72 |
+
if ($offset >= strlen($text)) break;
|
|
|
|
|
|
|
73 |
}
|
74 |
}
|
75 |
return $text;
|
99 |
function wsh_get_block_from_matches($matches) {
|
100 |
global $wsh_raw_parts;
|
101 |
|
102 |
+
$index = wsh_get_index_from_matches($matches);
|
103 |
+
if ( $index === null ) {
|
|
|
|
|
|
|
104 |
return '{Invalid RAW block}';
|
105 |
}
|
106 |
|
|
|
107 |
return $wsh_raw_parts[$index];
|
108 |
}
|
109 |
|
110 |
+
/**
|
111 |
+
* @param array $matches
|
112 |
+
* @return int|null
|
113 |
+
*/
|
114 |
+
function wsh_get_index_from_matches($matches) {
|
115 |
+
$index = null;
|
116 |
+
if ( isset($matches['index']) ) {
|
117 |
+
$index = intval($matches['index']);
|
118 |
+
} else if ( isset($matches[2]) ) {
|
119 |
+
$index = intval($matches[2]);
|
120 |
+
}
|
121 |
+
return $index;
|
122 |
+
}
|
123 |
+
|
124 |
/**
|
125 |
* Regex callback for wsh_insert_exclusions. Returns the extracted content
|
126 |
* corresponding to a matched placeholder.
|
133 |
$closingParagraph = isset($matches[3]) ? $matches[3] : '';
|
134 |
$code = wsh_get_block_from_matches($matches);
|
135 |
|
136 |
+
//Optionally execute shortcodes inside [raw]...[/raw] tags.
|
137 |
+
global $wsh_raw_run_shortcodes;
|
138 |
+
$index = wsh_get_index_from_matches($matches);
|
139 |
+
$run_shortcodes = ($index !== null) && !empty($wsh_raw_run_shortcodes[$index]);
|
140 |
+
if ( $run_shortcodes ) {
|
141 |
+
$code = do_shortcode($code);
|
142 |
+
}
|
143 |
+
|
144 |
//If the [raw] block is wrapped in its own paragraph, strip the <p>...</p> tags. If there's
|
145 |
//only one of <p>|</p> tag present, keep it - it's probably part of a larger paragraph.
|
146 |
if ( empty($openingParagraph) || empty($closingParagraph) ) {
|
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.
|
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.5
|
7 |
Author: Janis Elsts
|
8 |
Author URI: http://w-shadow.com/
|
9 |
*/
|
readme.txt
CHANGED
@@ -2,8 +2,8 @@
|
|
2 |
Contributors: whiteshadow
|
3 |
Tags: posts, formatting, javascript, html, css, code, disable
|
4 |
Requires at least: 2.8
|
5 |
-
Tested up to: 4.
|
6 |
-
Stable tag: 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 |
|
@@ -42,6 +42,14 @@ In this case, the tags will prevent WordPress from inserting paragraph breaks be
|
|
42 |
|
43 |
To avoid problems, only edit posts that contain your custom code in Text/HTML mode. If you'd like to be able to also use the Visual editor, [get the Pro version](http://rawhtmlpro.com/?utm_source=wordpress.org&utm_medium=readme_link&utm_campaign=RawHTML%20free). It will make the code betwen [raw] tags appear as a read-only placeholder when viewed in Visual mode, ensuring WordPress doesn't change it.
|
44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
**Notes**
|
46 |
|
47 |
Some features of Raw HTML will only work for users who have the "unfiltered_html" capability. In a normal WordPress install that includes the Editor and Administrator roles. In a Multisite install, only the Super Admin has this capability by default.
|
@@ -72,6 +80,11 @@ Open to the post editor and click the "Screen Options" button in the top-right p
|
|
72 |
|
73 |
== Changelog ==
|
74 |
|
|
|
|
|
|
|
|
|
|
|
75 |
= 1.4.16 =
|
76 |
* Tested with WP 4.5.
|
77 |
|
2 |
Contributors: whiteshadow
|
3 |
Tags: posts, formatting, javascript, html, css, code, disable
|
4 |
Requires at least: 2.8
|
5 |
+
Tested up to: 4.8
|
6 |
+
Stable tag: 1.5
|
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 |
|
42 |
|
43 |
To avoid problems, only edit posts that contain your custom code in Text/HTML mode. If you'd like to be able to also use the Visual editor, [get the Pro version](http://rawhtmlpro.com/?utm_source=wordpress.org&utm_medium=readme_link&utm_campaign=RawHTML%20free). It will make the code betwen [raw] tags appear as a read-only placeholder when viewed in Visual mode, ensuring WordPress doesn't change it.
|
44 |
|
45 |
+
**Combining shortcodes**
|
46 |
+
|
47 |
+
By default, shortcodes that are inside [raw] tags will not work. They will just show up as plain text. To enable shortcodes, add the `shortcodes=1` attribute to the tag:
|
48 |
+
|
49 |
+
`[raw shortcodes=1]This [shortcode] will be run.[/raw]
|
50 |
+
|
51 |
+
[raw]This [shortcode] won't work.[/raw]`
|
52 |
+
|
53 |
**Notes**
|
54 |
|
55 |
Some features of Raw HTML will only work for users who have the "unfiltered_html" capability. In a normal WordPress install that includes the Editor and Administrator roles. In a Multisite install, only the Super Admin has this capability by default.
|
80 |
|
81 |
== Changelog ==
|
82 |
|
83 |
+
= 1.5 =
|
84 |
+
* Added a way to run shortcodes inside [raw] tags. To enable shortcodes, add the `shortcodes=1` attribute to the tag. Example: `[raw shortcodes=1]some code ... [my-shortcode] ... other code[/raw]`.
|
85 |
+
* Fixed a conflict with Events Calendar Pro (+ Community Events add-on). This should also fix conflicts with other plugins that remove default post filters like `wpautop`.
|
86 |
+
* Tested with WP 4.6-beta2.
|
87 |
+
|
88 |
= 1.4.16 =
|
89 |
* Tested with WP 4.5.
|
90 |
|