Raw HTML - Version 1.4.5

Version Description

  • Tested on WP 3.4-alpha
  • Store per-post disable_* flags in a single post meta key instead of one key per flag.
Download this release

Release Info

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

Code changes from version 1.4.4 to 1.4.5

Files changed (3) hide show
  1. include/formatting-override.php +96 -19
  2. raw_html.php +2 -2
  3. readme.txt +7 -3
include/formatting-override.php CHANGED
@@ -9,11 +9,8 @@ require 'screen-options/screen-options.php';
9
  //Apply function $func to $content unless it's been disabled for the current post
10
  function maybe_use_filter($func, $content){
11
  global $post;
12
- $setting = get_post_meta($post->ID, '_disable_'.$func, true);
13
- if ( $setting == '' ){
14
- $setting = get_post_meta($post->ID, 'disable_'.$func, true);
15
- }
16
- if ($setting == '1') {
17
  return $content;
18
  } else {
19
  return $func($content);
@@ -92,20 +89,13 @@ function rawhtml_meta_box(){
92
  'disable_convert_chars' => array('Disable convert_chars', 'convert_chars converts ampersand to HTML entities and "fixes" some Unicode character'),
93
  'disable_convert_smilies' => array('Disable smilies', null),
94
  );
95
- $defaults = rawhtml_get_default_settings();
96
-
97
  echo '<ul>';
98
  foreach($fields as $field => $info){
99
  list($legend, $title) = $info;
100
- $current_setting = get_post_meta($post->ID, '_'.$field, true);
101
- if ( $current_setting == '' ){
102
- $current_setting = get_post_meta($post->ID, $field, true);
103
- }
104
- if ( $current_setting == '' ){
105
- $current_setting = $defaults[$field];
106
- } else {
107
- $current_setting = (bool)intval($current_setting);
108
- }
109
  ?>
110
  <li><label for="rawhtml_<?php echo $field; ?>" title="<?php if (!empty($title)) echo esc_attr($title); ?>">
111
  <input type="checkbox" name="rawhtml_<?php echo $field; ?>" id="rawhtml_<?php echo $field; ?>" <?php
@@ -141,14 +131,16 @@ function rawhtml_save_postdata( $post_id ){
141
  }
142
 
143
  // OK, we're authenticated: we need to find and save the data
144
- $fields = array('disable_wpautop', 'disable_wptexturize', 'disable_convert_chars', 'disable_convert_smilies');
 
145
  foreach ( $fields as $field ){
146
  if ( !empty($_POST['rawhtml_'.$field]) ){
147
- update_post_meta($post_id, '_'.$field, '1');
148
  } else {
149
- update_post_meta($post_id, '_'.$field, '0');
150
  };
151
  }
 
152
 
153
  return true;
154
  }
@@ -163,6 +155,91 @@ add_screen_options_panel(
163
  true //Auto-submit settings (via AJAX) when they change.
164
  );
165
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
166
  /**
167
  * Retrieve the default settings for our post/page meta box.
168
  * Settings are saved in user meta.
9
  //Apply function $func to $content unless it's been disabled for the current post
10
  function maybe_use_filter($func, $content){
11
  global $post;
12
+ $settings = rawhtml_get_post_settings($post->ID);
13
+ if ( $settings['disable_' . $func] ) {
 
 
 
14
  return $content;
15
  } else {
16
  return $func($content);
89
  'disable_convert_chars' => array('Disable convert_chars', 'convert_chars converts ampersand to HTML entities and "fixes" some Unicode character'),
90
  'disable_convert_smilies' => array('Disable smilies', null),
91
  );
92
+ $settings = rawhtml_get_post_settings($post->ID);
93
+
94
  echo '<ul>';
95
  foreach($fields as $field => $info){
96
  list($legend, $title) = $info;
97
+ $current_setting = $settings[$field];
98
+
 
 
 
 
 
 
 
99
  ?>
100
  <li><label for="rawhtml_<?php echo $field; ?>" title="<?php if (!empty($title)) echo esc_attr($title); ?>">
101
  <input type="checkbox" name="rawhtml_<?php echo $field; ?>" id="rawhtml_<?php echo $field; ?>" <?php
131
  }
132
 
133
  // OK, we're authenticated: we need to find and save the data
134
+ $fields = rawhtml_get_settings_fields();
135
+ $new_settings = array();
136
  foreach ( $fields as $field ){
137
  if ( !empty($_POST['rawhtml_'.$field]) ){
138
+ $new_settings[$field] = true;
139
  } else {
140
+ $new_settings[$field] = false;
141
  };
142
  }
143
+ rawhtml_save_post_settings($post_id, $new_settings);
144
 
145
  return true;
146
  }
155
  true //Auto-submit settings (via AJAX) when they change.
156
  );
157
 
158
+ /**
159
+ * Retrieve the "disable_*" flags associated with a post.
160
+ * If no flags have been set, this function will return the default settings.
161
+ *
162
+ * Note: Will transparently upgrade the old one-meta-key-per-flag storage system
163
+ * to the new one-key-per-post one.
164
+ *
165
+ * @param int $post_id
166
+ * @return array Flag values as an associative array.
167
+ */
168
+ function rawhtml_get_post_settings($post_id) {
169
+ $defaults = rawhtml_get_default_settings();
170
+ $fields = rawhtml_get_settings_fields();
171
+
172
+ //Per-post settings should be stored as a comma-separated list of 1/0 flags.
173
+ $settings = get_post_meta($post_id, '_rawhtml_settings', true);
174
+ if ( $settings != '' ) {
175
+ $settings = explode(',', $settings, count($fields));
176
+ $settings = array_combine($fields, $settings);
177
+ foreach($settings as $field => $value) {
178
+ $settings[$field] = (bool)intval($value);
179
+ }
180
+ } else {
181
+ //Older versions of the plugin stored each flag in a separate meta key.
182
+ $settings = array();
183
+ $should_upgrade_settings = false;
184
+ foreach($fields as $field) {
185
+ $value = get_post_meta($post_id, '_'.$field, true);
186
+ if ( $value == '' ){
187
+ $value = get_post_meta($post_id, $field, true);
188
+ }
189
+ if ( $value == '' ){
190
+ $value = $defaults[$field];
191
+ } else {
192
+ $value = (bool)intval($value);
193
+ $should_upgrade_settings = true;
194
+ }
195
+ $settings[$field] = $value;
196
+ }
197
+
198
+ if ( $should_upgrade_settings ) {
199
+ rawhtml_save_post_settings($post_id, $settings);
200
+ rawhtml_delete_old_post_settings($post_id);
201
+ }
202
+ }
203
+
204
+ return $settings;
205
+ }
206
+
207
+ /**
208
+ * Save the "disable_*" flag values set for a post.
209
+ *
210
+ * @param int $post_id Post ID.
211
+ * @param array $settings Flag values as an associative array.
212
+ * @return void
213
+ */
214
+ function rawhtml_save_post_settings($post_id, $settings) {
215
+ $fields = rawhtml_get_settings_fields();
216
+ $ordered_settings = array();
217
+ foreach($fields as $field) {
218
+ $ordered_settings[$field] = $settings[$field] ? '1' : '0';
219
+ }
220
+ update_post_meta($post_id, '_rawhtml_settings', implode(',', $ordered_settings));
221
+ }
222
+
223
+ /**
224
+ * Delete the old one-key-per-flag metadata that older versions of the plugin
225
+ * used to store per-post settings.
226
+ *
227
+ * @param int $post_id
228
+ */
229
+ function rawhtml_delete_old_post_settings($post_id) {
230
+ $fields = rawhtml_get_settings_fields();
231
+ foreach($fields as $field) {
232
+ delete_post_meta($post_id, $field);
233
+ }
234
+ foreach($fields as $field) {
235
+ delete_post_meta($post_id, '_' . $field);
236
+ }
237
+ }
238
+
239
+ function rawhtml_get_settings_fields() {
240
+ return array('disable_wpautop', 'disable_wptexturize', 'disable_convert_chars', 'disable_convert_smilies');
241
+ }
242
+
243
  /**
244
  * Retrieve the default settings for our post/page meta box.
245
  * Settings are saved in user meta.
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 raw HTML in your posts and disable automatic formatting on a per-post basis. <a href="http://wpplugins.com/plugin/850/raw-html-pro/">Upgrade to Pro Version</a>
6
- Version: 1.4.4
7
  Author: Janis Elsts
8
  Author URI: http://w-shadow.com/blog/
9
  */
@@ -16,7 +16,7 @@ Licensed under the LGPL.
16
  define('RAWHTML_PLUGIN_FILE', __FILE__);
17
 
18
  require 'include/tag-handler.php';
19
- require 'include/formatting-override.php';
20
 
21
  if ( is_admin() && file_exists(dirname(__FILE__).'/editor-plugin/init.php') ){
22
  require 'editor-plugin/init.php';
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 raw HTML in your posts and disable automatic formatting on a per-post basis. <a href="http://wpplugins.com/plugin/850/raw-html-pro/">Upgrade to Pro Version</a>
6
+ Version: 1.4.5
7
  Author: Janis Elsts
8
  Author URI: http://w-shadow.com/blog/
9
  */
16
  define('RAWHTML_PLUGIN_FILE', __FILE__);
17
 
18
  require 'include/tag-handler.php';
19
+ require 'include/formatting-override.php';
20
 
21
  if ( is_admin() && file_exists(dirname(__FILE__).'/editor-plugin/init.php') ){
22
  require 'editor-plugin/init.php';
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: 3.3-beta3
6
- Stable tag: 1.4.4
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
 
@@ -13,7 +13,7 @@ Lets you disable automatic formatting like smart quotes and automatic paragraphs
13
 
14
  The free version only works with the HTML editor. Get the Pro Version if you want to be able to switch between HTML and the Visual editor without WordPress messing up your content.
15
 
16
- [Upgrade to Pro version](http://wpplugins.com/plugin/850/raw-html-pro/)
17
 
18
  **Features**
19
 
@@ -64,6 +64,10 @@ Open to the post editor and click the "Screen Options" button in the top-right p
64
 
65
  == Changelog ==
66
 
 
 
 
 
67
  = 1.4.4 =
68
  * Fixed a minor conflict with the "Really simple Facebook Twitter share buttons" plugin.
69
 
2
  Contributors: whiteshadow
3
  Tags: posts, formatting, javascript, html, css, code, disable
4
  Requires at least: 2.8
5
+ Tested up to: 3.4-alpha
6
+ Stable tag: 1.4.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
 
13
 
14
  The free version only works with the HTML editor. Get the Pro Version if you want to be able to switch between HTML and the Visual editor without WordPress messing up your content.
15
 
16
+ [Upgrade to Pro version](http://w-shadow.com/RawHTML/)
17
 
18
  **Features**
19
 
64
 
65
  == Changelog ==
66
 
67
+ = 1.4.5 =
68
+ * Tested on WP 3.4-alpha
69
+ * Store per-post disable_* flags in a single post meta key instead of one key per flag.
70
+
71
  = 1.4.4 =
72
  * Fixed a minor conflict with the "Really simple Facebook Twitter share buttons" plugin.
73