Raw HTML - Version 1.1

Version Description

Download this release

Release Info

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

Code changes from version 1.0.5 to 1.1

Files changed (2) hide show
  1. raw_html.php +128 -2
  2. readme.txt +11 -4
raw_html.php CHANGED
@@ -2,8 +2,8 @@
2
  /*
3
  Plugin Name: Raw HTML capability
4
  Plugin URI: http://w-shadow.com/blog/2007/12/13/raw-html-in-wordpress/
5
- Description: Lets you enter raw HTML in your posts. See website for details.
6
- Version: 1.0.5
7
  Author: Janis Elsts
8
  Author URI: http://w-shadow.com/blog/
9
  */
@@ -13,6 +13,9 @@ Created by Janis Elsts (email : whiteshadow@w-shadow.com)
13
  It's GPL.
14
  */
15
 
 
 
 
16
  global $wsh_raw_parts;
17
  $wsh_raw_parts=array();
18
 
@@ -41,4 +44,127 @@ function wsh_insert_exclusions($text){
41
 
42
  add_filter('the_content', 'wsh_extract_exclusions', 0);
43
  add_filter('the_content', 'wsh_insert_exclusions', 1001);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  ?>
2
  /*
3
  Plugin Name: Raw HTML capability
4
  Plugin URI: http://w-shadow.com/blog/2007/12/13/raw-html-in-wordpress/
5
+ Description: Lets you enter raw HTML in your posts. You can also enable/disable smart quotes and other automatic formatting on a per-post basis.
6
+ Version: 1.1
7
  Author: Janis Elsts
8
  Author URI: http://w-shadow.com/blog/
9
  */
13
  It's GPL.
14
  */
15
 
16
+ /**********************************************
17
+ Filter inline blocks of raw HTML
18
+ ***********************************************/
19
  global $wsh_raw_parts;
20
  $wsh_raw_parts=array();
21
 
44
 
45
  add_filter('the_content', 'wsh_extract_exclusions', 0);
46
  add_filter('the_content', 'wsh_insert_exclusions', 1001);
47
+
48
+ /*****************************************************
49
+ Disable default formatting on a per-post level
50
+ ******************************************************/
51
+
52
+ //Apply function $func to $content unless it's been disabled for the current post
53
+ function maybe_use_filter($func, $content){
54
+ global $post;
55
+ if (get_post_meta($post->ID, 'disable_'.$func, true) == '1') {
56
+ return $content;
57
+ } else {
58
+ return $func($content);
59
+ }
60
+ }
61
+
62
+ //Stub filters that replace the WP defaults
63
+ function maybe_wptexturize($content){
64
+ return maybe_use_filter('wptexturize', $content);
65
+ }
66
+
67
+ function maybe_wpautop($content){
68
+ return maybe_use_filter('wpautop', $content);
69
+ }
70
+
71
+ function maybe_convert_chars($content){
72
+ return maybe_use_filter('convert_chars', $content);
73
+ }
74
+
75
+ function maybe_convert_smilies($content){
76
+ return maybe_use_filter('convert_smilies', $content);
77
+ }
78
+
79
+ // disable default filters
80
+ remove_filter('the_content', 'wpautop');
81
+ remove_filter('the_content', 'wptexturize');
82
+ remove_filter('the_content', 'convert_chars');
83
+ remove_filter('the_content', 'convert_smilies');
84
+ remove_filter('the_excerpt', 'wpautop');
85
+ remove_filter('the_excerpt', 'wptexturize');
86
+ remove_filter('the_excerpt', 'convert_chars');
87
+ remove_filter('the_excerpt', 'convert_smilies');
88
+
89
+ // add our conditional filters
90
+ add_filter('the_content', 'maybe_wptexturize');
91
+ add_filter('the_content', 'maybe_wpautop');
92
+ add_filter('the_content', 'maybe_convert_chars');
93
+ add_filter('the_content', 'maybe_convert_smilies');
94
+ add_filter('the_excerpt', 'maybe_wptexturize');
95
+ add_filter('the_excerpt', 'maybe_wpautop');
96
+ add_filter('the_excerpt', 'maybe_convert_chars');
97
+ add_filter('the_excerpt', 'maybe_convert_smilies');
98
+
99
+ // Add a custom meta box for per-post settings
100
+ add_action('admin_menu', 'rawhtml_add_custom_box');
101
+ add_action('save_post', 'rawhtml_save_postdata');
102
+
103
+ /* Adds a custom section to the "advanced" Post and Page edit screens */
104
+ function rawhtml_add_custom_box() {
105
+ //WP 2.5+
106
+ if( function_exists( 'add_meta_box' )) {
107
+ foreach( array('post', 'page') as $type ) {
108
+ add_meta_box( 'rawhtml_meta_box', 'Raw HTML', 'rawhtml_meta_box', $type, 'side' );
109
+ }
110
+ }
111
+ }
112
+
113
+ /* Displays the custom box */
114
+ function rawhtml_meta_box(){
115
+ global $post;
116
+ // Use nonce for verification
117
+ echo '<input type="hidden" name="rawhtml_nonce" id="rawhtml_nonce" value="' .
118
+ wp_create_nonce( plugin_basename(__FILE__) ) . '" />';
119
+
120
+ //Output checkboxes
121
+ $fields = array(
122
+ 'disable_wptexturize' => 'Disable wptexturize',
123
+ 'disable_wpautop' => 'Disable automatic paragraphs',
124
+ 'disable_convert_chars' => 'Disable convert_chars',
125
+ 'disable_convert_smilies' => 'Disable smilies',
126
+ );
127
+ foreach($fields as $field => $legend){
128
+ ?>
129
+ <label for="rawhtml_<?php echo $field; ?>">
130
+ <input type="checkbox" name="rawhtml_<?php echo $field; ?>" id="rawhtml_<?php echo $field; ?>" <?php
131
+ if (get_post_meta($post->ID, $field, true) == '1')
132
+ echo ' checked="checked"';
133
+ ?>/>
134
+ <?php echo $legend; ?>
135
+ </label>
136
+ <br />
137
+ <?php
138
+ }
139
+ }
140
+
141
+ /* Saves post metadata */
142
+ function rawhtml_save_postdata( $post_id ){
143
+ // verify this came from the our screen and with proper authorization,
144
+ // because save_post can be triggered at other times
145
+
146
+ if ( !wp_verify_nonce( $_POST['rawhtml_nonce'], plugin_basename(__FILE__) )) {
147
+ return $post_id;
148
+ }
149
+
150
+ if ( 'page' == $_POST['post_type'] ) {
151
+ if ( !current_user_can( 'edit_page', $post_id ))
152
+ return $post_id;
153
+ } else {
154
+ if ( !current_user_can( 'edit_post', $post_id ))
155
+ return $post_id;
156
+ }
157
+
158
+ // OK, we're authenticated: we need to find and save the data
159
+ $fields = array('disable_wpautop', 'disable_wptexturize', 'disable_convert_chars', 'disable_convert_smilies');
160
+ foreach ( $fields as $field ){
161
+ if ( !empty($_POST['rawhtml_'.$field]) ){
162
+ update_post_meta($post_id, $field, '1');
163
+ } else {
164
+ delete_post_meta($post_id, $field);
165
+ };
166
+ }
167
+
168
+ return true;
169
+ }
170
  ?>
readme.txt CHANGED
@@ -2,14 +2,21 @@
2
  Contributors: whiteshadow
3
  Tags: posts, formatting, javascript, html, css, code
4
  Requires at least: 2.2
5
- Tested up to: 2.6.2
6
- Stable tag: 1.0.5
7
 
8
- Lets you use raw HTML or any other code in your posts.
9
 
10
  == Description ==
11
 
12
- This plugin lets you use raw HTML or any other code in your posts. Wrap a part of your post in special tags (below) to prevent WordPress from converting newlines to HTML paragraphs, escaping apostrophes and so on. Very useful if you need to add a CSS block or JavaScript to your post.
 
 
 
 
 
 
 
13
 
14
  **Using the plugin**
15
 
2
  Contributors: whiteshadow
3
  Tags: posts, formatting, javascript, html, css, code
4
  Requires at least: 2.2
5
+ Tested up to: 2.7
6
+ Stable tag: 1.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
 
10
  == Description ==
11
 
12
+ This plugin lets you use raw HTML or any other code in your posts. One way to use it is to wrap a part of your post in special tags (below) to prevent WordPress from converting newlines to HTML paragraphs, escaping apostrophes and so on. This is very useful if you need to add a CSS block or JavaScript to your post.
13
+
14
+ RawHTML will also add some new checkboxes to the "Edit" screen that will let you disable certain WP filters on a per-post basis. This way you can :
15
+
16
+ * Disable wptexturize (this filter creates smart quotes and other typographic characters).
17
+ * Disable automatic paragraph creation.
18
+ * Disable image smilies.
19
+ * Disable convert_chars (this filter converts ampersands to HTML entities and "fixes" some Unicode characters).
20
 
21
  **Using the plugin**
22