Version Description
- To decrease UI clutter, post-level settings now use hidden custom fields.
Download this release
Release Info
| Developer | whiteshadow |
| Plugin | |
| Version | 1.4 |
| Comparing to | |
| See all releases | |
Code changes from version 1.3 to 1.4
- raw_html.php +30 -17
- readme.txt +12 -2
- screen-options/screen-options.php +35 -12
raw_html.php
CHANGED
|
@@ -3,7 +3,7 @@
|
|
| 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.
|
| 7 |
Author: Janis Elsts
|
| 8 |
Author URI: http://w-shadow.com/blog/
|
| 9 |
*/
|
|
@@ -28,7 +28,7 @@ function wsh_extraction_callback($matches){
|
|
| 28 |
}
|
| 29 |
|
| 30 |
function wsh_extract_exclusions($text){
|
| 31 |
-
global $wsh_raw_parts;
|
| 32 |
|
| 33 |
$tags = array(array('<!--start_raw-->', '<!--end_raw-->'), array('[RAW]', '[/RAW]'));
|
| 34 |
|
|
@@ -49,12 +49,17 @@ function wsh_extract_exclusions($text){
|
|
| 49 |
//extract the content between the tags
|
| 50 |
$content = substr($text, $content_start,$fin-$content_start);
|
| 51 |
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
$text = substr_replace($text, $replacement, $start,
|
| 56 |
$fin+strlen($end_tag)-$start
|
| 57 |
-
|
| 58 |
|
| 59 |
//Have we reached the end of the string yet?
|
| 60 |
if ($start + strlen($replacement) > strlen($text)) break;
|
|
@@ -92,7 +97,11 @@ add_filter('the_content', 'wsh_insert_exclusions', 1001);
|
|
| 92 |
//Apply function $func to $content unless it's been disabled for the current post
|
| 93 |
function maybe_use_filter($func, $content){
|
| 94 |
global $post;
|
| 95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
return $content;
|
| 97 |
} else {
|
| 98 |
return $func($content);
|
|
@@ -173,7 +182,10 @@ function rawhtml_meta_box(){
|
|
| 173 |
);
|
| 174 |
$defaults = rawhtml_get_default_settings();
|
| 175 |
foreach($fields as $field => $legend){
|
| 176 |
-
$current_setting = get_post_meta($post->ID,
|
|
|
|
|
|
|
|
|
|
| 177 |
if ( $current_setting == '' ){
|
| 178 |
$current_setting = $defaults[$field];
|
| 179 |
} else {
|
|
@@ -216,9 +228,9 @@ function rawhtml_save_postdata( $post_id ){
|
|
| 216 |
$fields = array('disable_wpautop', 'disable_wptexturize', 'disable_convert_chars', 'disable_convert_smilies');
|
| 217 |
foreach ( $fields as $field ){
|
| 218 |
if ( !empty($_POST['rawhtml_'.$field]) ){
|
| 219 |
-
update_post_meta($post_id,
|
| 220 |
} else {
|
| 221 |
-
update_post_meta($post_id,
|
| 222 |
};
|
| 223 |
}
|
| 224 |
|
|
@@ -227,12 +239,12 @@ function rawhtml_save_postdata( $post_id ){
|
|
| 227 |
|
| 228 |
//Add our panel to the "Screen Options" box
|
| 229 |
add_screen_options_panel(
|
| 230 |
-
'rawhtml-default-settings',
|
| 231 |
-
'Raw HTML defaults',
|
| 232 |
-
'rawhtml_default_settings_panel',
|
| 233 |
-
array('post', 'page'),
|
| 234 |
-
'rawhtml_save_new_defaults',
|
| 235 |
-
true
|
| 236 |
);
|
| 237 |
|
| 238 |
/**
|
|
@@ -300,7 +312,7 @@ function rawhtml_default_settings_panel(){
|
|
| 300 |
'disable_convert_smilies' => 'Disable smilies',
|
| 301 |
);
|
| 302 |
|
| 303 |
-
$output = '';
|
| 304 |
foreach($fields as $field => $legend){
|
| 305 |
$esc_field = esc_attr($field);
|
| 306 |
$output .= sprintf(
|
|
@@ -315,6 +327,7 @@ function rawhtml_default_settings_panel(){
|
|
| 315 |
$legend
|
| 316 |
);
|
| 317 |
}
|
|
|
|
| 318 |
|
| 319 |
return $output;
|
| 320 |
}
|
| 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.4
|
| 7 |
Author: Janis Elsts
|
| 8 |
Author URI: http://w-shadow.com/blog/
|
| 9 |
*/
|
| 28 |
}
|
| 29 |
|
| 30 |
function wsh_extract_exclusions($text){
|
| 31 |
+
global $wsh_raw_parts, $wp_current_filter;
|
| 32 |
|
| 33 |
$tags = array(array('<!--start_raw-->', '<!--end_raw-->'), array('[RAW]', '[/RAW]'));
|
| 34 |
|
| 49 |
//extract the content between the tags
|
| 50 |
$content = substr($text, $content_start,$fin-$content_start);
|
| 51 |
|
| 52 |
+
if ( (array_search('get_the_excerpt', $wp_current_filter) !== false) || (array_search('the_excerpt', $wp_current_filter) !== false) ){
|
| 53 |
+
//Strip out the raw blocks when displaying an excerpt
|
| 54 |
+
$replacement = '';
|
| 55 |
+
} else {
|
| 56 |
+
//Store the content and replace it with a marker
|
| 57 |
+
$wsh_raw_parts[]=$content;
|
| 58 |
+
$replacement = "!RAWBLOCK".(count($wsh_raw_parts)-1)."!";
|
| 59 |
+
}
|
| 60 |
$text = substr_replace($text, $replacement, $start,
|
| 61 |
$fin+strlen($end_tag)-$start
|
| 62 |
+
);
|
| 63 |
|
| 64 |
//Have we reached the end of the string yet?
|
| 65 |
if ($start + strlen($replacement) > strlen($text)) break;
|
| 97 |
//Apply function $func to $content unless it's been disabled for the current post
|
| 98 |
function maybe_use_filter($func, $content){
|
| 99 |
global $post;
|
| 100 |
+
$setting = get_post_meta($post->ID, '_disable_'.$func, true);
|
| 101 |
+
if ( $setting == '' ){
|
| 102 |
+
$setting = get_post_meta($post->ID, 'disable_'.$func, true);
|
| 103 |
+
}
|
| 104 |
+
if ($setting == '1') {
|
| 105 |
return $content;
|
| 106 |
} else {
|
| 107 |
return $func($content);
|
| 182 |
);
|
| 183 |
$defaults = rawhtml_get_default_settings();
|
| 184 |
foreach($fields as $field => $legend){
|
| 185 |
+
$current_setting = get_post_meta($post->ID, '_'.$field, true);
|
| 186 |
+
if ( $current_setting == '' ){
|
| 187 |
+
$current_setting = get_post_meta($post->ID, $field, true);
|
| 188 |
+
}
|
| 189 |
if ( $current_setting == '' ){
|
| 190 |
$current_setting = $defaults[$field];
|
| 191 |
} else {
|
| 228 |
$fields = array('disable_wpautop', 'disable_wptexturize', 'disable_convert_chars', 'disable_convert_smilies');
|
| 229 |
foreach ( $fields as $field ){
|
| 230 |
if ( !empty($_POST['rawhtml_'.$field]) ){
|
| 231 |
+
update_post_meta($post_id, '_'.$field, '1');
|
| 232 |
} else {
|
| 233 |
+
update_post_meta($post_id, '_'.$field, '0');
|
| 234 |
};
|
| 235 |
}
|
| 236 |
|
| 239 |
|
| 240 |
//Add our panel to the "Screen Options" box
|
| 241 |
add_screen_options_panel(
|
| 242 |
+
'rawhtml-default-settings', //Panel ID
|
| 243 |
+
'Raw HTML defaults', //Panel title.
|
| 244 |
+
'rawhtml_default_settings_panel', //The function that generates panel contents.
|
| 245 |
+
array('post', 'page'), //Pages/screens where the panel is displayed.
|
| 246 |
+
'rawhtml_save_new_defaults', //The function that gets triggered when settings are submitted/saved.
|
| 247 |
+
true //Auto-submit settings (via AJAX) when they change.
|
| 248 |
);
|
| 249 |
|
| 250 |
/**
|
| 312 |
'disable_convert_smilies' => 'Disable smilies',
|
| 313 |
);
|
| 314 |
|
| 315 |
+
$output = '<div class="metabox-prefs">';
|
| 316 |
foreach($fields as $field => $legend){
|
| 317 |
$esc_field = esc_attr($field);
|
| 318 |
$output .= sprintf(
|
| 327 |
$legend
|
| 328 |
);
|
| 329 |
}
|
| 330 |
+
$output .= "</div>";
|
| 331 |
|
| 332 |
return $output;
|
| 333 |
}
|
readme.txt
CHANGED
|
@@ -2,8 +2,8 @@
|
|
| 2 |
Contributors: whiteshadow
|
| 3 |
Tags: posts, formatting, javascript, html, css, code
|
| 4 |
Requires at least: 2.6
|
| 5 |
-
Tested up to: 3.
|
| 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 |
|
|
@@ -46,8 +46,18 @@ To install the plugin follow these steps :
|
|
| 46 |
1. Upload the "raw-html" folder to your "/wp-content/plugins/" directory.
|
| 47 |
1. Activate the plugin through the 'Plugins' menu in WordPress
|
| 48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
== Changelog ==
|
| 50 |
|
|
|
|
|
|
|
|
|
|
| 51 |
= 1.3 =
|
| 52 |
* Added a new panel to the "Screen Options" box that lest you auto-enable specific RawHTML settings (e.g. "Disable automatic paragraphs") for all new or updated posts.
|
| 53 |
|
| 2 |
Contributors: whiteshadow
|
| 3 |
Tags: posts, formatting, javascript, html, css, code
|
| 4 |
Requires at least: 2.6
|
| 5 |
+
Tested up to: 3.1
|
| 6 |
+
Stable tag: 1.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 |
|
| 46 |
1. Upload the "raw-html" folder to your "/wp-content/plugins/" directory.
|
| 47 |
1. Activate the plugin through the 'Plugins' menu in WordPress
|
| 48 |
|
| 49 |
+
== Frequently Asked Questions ==
|
| 50 |
+
|
| 51 |
+
= How can I set some of the "Disable xyz" tweaks to be "On" by default? =
|
| 52 |
+
|
| 53 |
+
Open to the post editor and click the "Screen Options" button in the top-right part of the page. A settings panel will appear. Locate the "Raw HTML defaults" section and tick the appropriate checkboxes. Any changes you make to these settings will only affect new and edited posts.
|
| 54 |
+
|
| 55 |
+
|
| 56 |
== Changelog ==
|
| 57 |
|
| 58 |
+
= 1.4 =
|
| 59 |
+
* To decrease UI clutter, post-level settings now use hidden custom fields.
|
| 60 |
+
|
| 61 |
= 1.3 =
|
| 62 |
* Added a new panel to the "Screen Options" box that lest you auto-enable specific RawHTML settings (e.g. "Disable automatic paragraphs") for all new or updated posts.
|
| 63 |
|
screen-options/screen-options.php
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
<?php
|
| 2 |
|
| 3 |
-
if ( !class_exists('
|
| 4 |
|
| 5 |
/**
|
| 6 |
* Class for adding new panels to the "Screen Options" box.
|
|
@@ -9,10 +9,10 @@ if ( !class_exists('wsScreenOptions10') ):
|
|
| 9 |
*
|
| 10 |
* @author Janis Elsts
|
| 11 |
* @copyright 2010
|
| 12 |
-
* @version 1.
|
| 13 |
* @access public
|
| 14 |
*/
|
| 15 |
-
class
|
| 16 |
var $registered_panels; //List of custom "Screen Options" panels
|
| 17 |
var $page_panels; //Index of panels registered for each page ($page => array of panel ids).
|
| 18 |
|
|
@@ -21,7 +21,7 @@ class wsScreenOptions10 {
|
|
| 21 |
*
|
| 22 |
* @return void
|
| 23 |
*/
|
| 24 |
-
function
|
| 25 |
$this->registered_panels = array();
|
| 26 |
$this->page_panels = array();
|
| 27 |
|
|
@@ -60,6 +60,7 @@ class wsScreenOptions10 {
|
|
| 60 |
add_action('wp_ajax_save_settings-' . $id, array(&$this, 'ajax_save_callback'));
|
| 61 |
}
|
| 62 |
|
|
|
|
| 63 |
foreach($page as $page_id){
|
| 64 |
if ( !isset($this->page_panels[$page_id]) ){
|
| 65 |
$this->page_panels[$page_id] = array();
|
|
@@ -111,10 +112,10 @@ class wsScreenOptions10 {
|
|
| 111 |
}
|
| 112 |
|
| 113 |
//Are there any panels that want to appear on this page?
|
| 114 |
-
|
|
|
|
| 115 |
return $current;
|
| 116 |
}
|
| 117 |
-
$panels = $this->page_panels[$screen->id];
|
| 118 |
|
| 119 |
//Append all panels registered for this screen
|
| 120 |
foreach($panels as $panel_id){
|
|
@@ -128,7 +129,6 @@ class wsScreenOptions10 {
|
|
| 128 |
if ( is_callable($panel['callback']) ){
|
| 129 |
$contents = call_user_func($panel['callback']);
|
| 130 |
$classes = array(
|
| 131 |
-
'metabox-prefs',
|
| 132 |
'custom-options-panel',
|
| 133 |
);
|
| 134 |
if ( $panel['autosave'] ){
|
|
@@ -192,13 +192,13 @@ class wsScreenOptions10 {
|
|
| 192 |
function add_autosave_script(){
|
| 193 |
//Get the page id/hook/slug/whatever.
|
| 194 |
global $hook_suffix;
|
| 195 |
-
$page = $this->page_to_screen_id($hook_suffix);
|
| 196 |
|
| 197 |
//Check if we have some panels with autosave registered for this page.
|
| 198 |
-
|
|
|
|
| 199 |
return;
|
| 200 |
}
|
| 201 |
-
|
| 202 |
$got_autosave = false;
|
| 203 |
foreach($panels as $panel_id){
|
| 204 |
if ( $this->registered_panels[$panel_id]['autosave'] ){
|
|
@@ -213,6 +213,28 @@ class wsScreenOptions10 {
|
|
| 213 |
wp_enqueue_script('screen-options-custom-autosave', $url, array('jquery'));
|
| 214 |
}
|
| 215 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 216 |
}
|
| 217 |
|
| 218 |
//All versions of the class are stored in a global array
|
|
@@ -221,7 +243,7 @@ global $ws_screen_options_versions;
|
|
| 221 |
if ( !isset($ws_screen_options_versions) ){
|
| 222 |
$ws_screen_options_versions = array();
|
| 223 |
}
|
| 224 |
-
$ws_screen_options_versions['1.
|
| 225 |
|
| 226 |
endif;
|
| 227 |
|
|
@@ -237,7 +259,7 @@ if ( !function_exists('add_screen_options_panel') ){
|
|
| 237 |
* @param callback $callback Function that fills the panel with the desired content. Should return its output.
|
| 238 |
* @param string|array $page The page(s) on which to show the panel (similar to add_meta_box()).
|
| 239 |
* @param callback $save_callback Optional. Function that saves the settings contained in the panel.
|
| 240 |
-
* @param bool $autosave Optional. If
|
| 241 |
* @return void
|
| 242 |
*/
|
| 243 |
function add_screen_options_panel($id, $title, $callback, $page, $save_callback = null, $autosave = false){
|
|
@@ -249,6 +271,7 @@ if ( !function_exists('add_screen_options_panel') ){
|
|
| 249 |
uksort($ws_screen_options_versions, 'version_compare');
|
| 250 |
$className = end($ws_screen_options_versions);
|
| 251 |
$instance = new $className;
|
|
|
|
| 252 |
}
|
| 253 |
|
| 254 |
return $instance->add_screen_options_panel($id, $title, $callback, $page, $save_callback, $autosave);
|
| 1 |
<?php
|
| 2 |
|
| 3 |
+
if ( !class_exists('wsScreenOptions12') ):
|
| 4 |
|
| 5 |
/**
|
| 6 |
* Class for adding new panels to the "Screen Options" box.
|
| 9 |
*
|
| 10 |
* @author Janis Elsts
|
| 11 |
* @copyright 2010
|
| 12 |
+
* @version 1.2
|
| 13 |
* @access public
|
| 14 |
*/
|
| 15 |
+
class wsScreenOptions12 {
|
| 16 |
var $registered_panels; //List of custom "Screen Options" panels
|
| 17 |
var $page_panels; //Index of panels registered for each page ($page => array of panel ids).
|
| 18 |
|
| 21 |
*
|
| 22 |
* @return void
|
| 23 |
*/
|
| 24 |
+
function init(){
|
| 25 |
$this->registered_panels = array();
|
| 26 |
$this->page_panels = array();
|
| 27 |
|
| 60 |
add_action('wp_ajax_save_settings-' . $id, array(&$this, 'ajax_save_callback'));
|
| 61 |
}
|
| 62 |
|
| 63 |
+
//Store the panel ID in each relevant page's list
|
| 64 |
foreach($page as $page_id){
|
| 65 |
if ( !isset($this->page_panels[$page_id]) ){
|
| 66 |
$this->page_panels[$page_id] = array();
|
| 112 |
}
|
| 113 |
|
| 114 |
//Are there any panels that want to appear on this page?
|
| 115 |
+
$panels = $this->get_panels_for_screen($screen->id, $hook_suffix);
|
| 116 |
+
if ( empty($panels) ){
|
| 117 |
return $current;
|
| 118 |
}
|
|
|
|
| 119 |
|
| 120 |
//Append all panels registered for this screen
|
| 121 |
foreach($panels as $panel_id){
|
| 129 |
if ( is_callable($panel['callback']) ){
|
| 130 |
$contents = call_user_func($panel['callback']);
|
| 131 |
$classes = array(
|
|
|
|
| 132 |
'custom-options-panel',
|
| 133 |
);
|
| 134 |
if ( $panel['autosave'] ){
|
| 192 |
function add_autosave_script(){
|
| 193 |
//Get the page id/hook/slug/whatever.
|
| 194 |
global $hook_suffix;
|
|
|
|
| 195 |
|
| 196 |
//Check if we have some panels with autosave registered for this page.
|
| 197 |
+
$panels = $this->get_panels_for_screen('', $hook_suffix);
|
| 198 |
+
if ( empty($panels) ){
|
| 199 |
return;
|
| 200 |
}
|
| 201 |
+
|
| 202 |
$got_autosave = false;
|
| 203 |
foreach($panels as $panel_id){
|
| 204 |
if ( $this->registered_panels[$panel_id]['autosave'] ){
|
| 213 |
wp_enqueue_script('screen-options-custom-autosave', $url, array('jquery'));
|
| 214 |
}
|
| 215 |
}
|
| 216 |
+
|
| 217 |
+
/**
|
| 218 |
+
* Get custom panels registered for a particular screen and/or page.
|
| 219 |
+
*
|
| 220 |
+
* @param string $screen_id Screen ID.
|
| 221 |
+
* @param string $page Optional. Page filename or hook name.
|
| 222 |
+
* @return array Array of custom panels.
|
| 223 |
+
*/
|
| 224 |
+
function get_panels_for_screen($screen_id, $page = ''){
|
| 225 |
+
if ( isset($this->page_panels[$screen_id]) && !empty($this->page_panels[$screen_id]) ){
|
| 226 |
+
$panels = $this->page_panels[$screen_id];
|
| 227 |
+
} else {
|
| 228 |
+
$panels = array();
|
| 229 |
+
}
|
| 230 |
+
if ( !empty($page) ){
|
| 231 |
+
$page_as_screen = $this->page_to_screen_id($page);
|
| 232 |
+
if ( isset($this->page_panels[$page_as_screen]) && !empty($this->page_panels[$page_as_screen]) ){
|
| 233 |
+
$panels = array_merge($panels, $this->page_panels[$page_as_screen]);
|
| 234 |
+
}
|
| 235 |
+
}
|
| 236 |
+
return array_unique($panels);
|
| 237 |
+
}
|
| 238 |
}
|
| 239 |
|
| 240 |
//All versions of the class are stored in a global array
|
| 243 |
if ( !isset($ws_screen_options_versions) ){
|
| 244 |
$ws_screen_options_versions = array();
|
| 245 |
}
|
| 246 |
+
$ws_screen_options_versions['1.2'] = 'wsScreenOptions12';
|
| 247 |
|
| 248 |
endif;
|
| 249 |
|
| 259 |
* @param callback $callback Function that fills the panel with the desired content. Should return its output.
|
| 260 |
* @param string|array $page The page(s) on which to show the panel (similar to add_meta_box()).
|
| 261 |
* @param callback $save_callback Optional. Function that saves the settings contained in the panel.
|
| 262 |
+
* @param bool $autosave Optional. If set, settings will be automatically saved (via AJAX) when the value of any input element in the panel changes. Defaults to false.
|
| 263 |
* @return void
|
| 264 |
*/
|
| 265 |
function add_screen_options_panel($id, $title, $callback, $page, $save_callback = null, $autosave = false){
|
| 271 |
uksort($ws_screen_options_versions, 'version_compare');
|
| 272 |
$className = end($ws_screen_options_versions);
|
| 273 |
$instance = new $className;
|
| 274 |
+
$instance->init();
|
| 275 |
}
|
| 276 |
|
| 277 |
return $instance->add_screen_options_panel($id, $title, $callback, $page, $save_callback, $autosave);
|
