Rich Text Excerpts - Version 1.0

Version Description

  • Wordpress submission after initial development on bitbucket.

=

Download this release

Release Info

Developer bjorsq
Plugin Icon 128x128 Rich Text Excerpts
Version 1.0
Comparing to
See all releases

Version 1.0

Files changed (3) hide show
  1. readme.txt +76 -0
  2. rich-text-excerpts.php +122 -0
  3. screenshot-1.png +0 -0
readme.txt ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Rich Text Excerpts ===
2
+ Contributors: bjorsq
3
+ Donate Link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QAQ2WC8UHFMEQ
4
+ Tags: excerpt, editor, TinyMCE, formatting
5
+ Requires at least: 3.3
6
+ Tested up to: 3.4-beta
7
+ Stable tag: 1.0
8
+ License: GPLv3
9
+ License URI: http://www.gnu.org/licenses/gpl.html
10
+
11
+ A Wordpress plugin which swaps out the textarea used for excerpts with a TinyMCE editor instance.
12
+
13
+ == Description ==
14
+
15
+ The Plugin uses the [wp_editor](http://codex.wordpress.org/Function_Reference/wp_editor) function to generate a rich text editor for page/post excerpts, so **will only work in Wordpress 3.3 or greater**.
16
+
17
+ The plugin utilises three action hooks:
18
+
19
+ * [add_meta_boxes](http://adambrown.info/p/wp_hooks/hook/add_meta_boxes) is used to remove the excerpt meta box generated by Wordpress
20
+ * [edit_form_advanced](http://adambrown.info/p/wp_hooks/hook/edit_form_advanced) is used to add the excerpt editor to posts.
21
+ * [edit_page_form](http://adambrown.info/p/wp_hooks/hook/edit_page_form) is used to add the excerpt editor to pages.
22
+
23
+ **Note:** the new editing box cannot be placed in a sortable, movable meta box because of an issue with using TinyMCE in sortables documented here:
24
+
25
+ http://core.trac.wordpress.org/ticket/19173
26
+
27
+ The editing box for excerpts uses [wp_editor](http://codex.wordpress.org/Function_Reference/wp_editor) to create a rich text editor with the following options:
28
+
29
+ `
30
+ $options = array(
31
+ "wpautop" => true,
32
+ "media_buttons" => false,
33
+ "textarea_name" => 'excerpt',
34
+ "textarea_rows" => 3,
35
+ "teeny" => true
36
+ );
37
+ `
38
+
39
+ You could change these lines in the plugin to generate a fully featured editor with media upload fields if you wished - just look at the documentation in the Wordpress Codex for all the details:
40
+
41
+ http://codex.wordpress.org/Function_Reference/wp_editor
42
+
43
+ The plugin also contains two filters which act on the "teeny" MCE editor instance which is used by default. These currently add the "charmap" and "paste" plugins, remove some buttons (strikethrough, for example), and add a few buttons for the new plugins.
44
+
45
+ == Installation ==
46
+
47
+ 1. Upload the plugin to the `/wp-content/plugins/` directory
48
+ 2. Activate the plugin through the 'Plugins' menu in WordPress
49
+
50
+ If you want to use excerpts in pages, add this to your theme's `functions.php` file:
51
+
52
+ `add_post_type_support('pages', 'excerpt');`
53
+
54
+ See [add_post_type_support](add_post_type_support) in the Codex for details.
55
+
56
+ If you want to use excerpts in Custom Post Types, do it when you create them using the `supports` array in the arguments for [register_post_type](http://codex.wordpress.org/Function_Reference/register_post_type).
57
+
58
+
59
+ == Changelog ==
60
+
61
+ = 1.0 =
62
+ * Wordpress submission after [initial development on bitbucket](https://bitbucket.org/bjorsq/rich-text-excerpts).
63
+
64
+ == Screenshots ==
65
+
66
+ 1. A screenshot showing the rich text editor in a post excerpt
67
+
68
+ == Contribute ==
69
+
70
+ At the moment, the plugin uses [html_entity_decode](http://php.net/manual/en/function.html-entity-decode.php) to decode encoded entities in the excerpt content prior to displaying it in the editor. It would be nice to find a more robust way of accessing the excerpt field data using a Wordpress filter.
71
+
72
+ The plugin will change all excerpt fields into rich text editors - there isn't currently an option to only enable it for specified post types (although this would be easy to add).
73
+
74
+ The options for the editor should really be placed in an administration page so users can configure the plugin without editing the source. The only trouble is, which options do you put there? The TinyMCE Advanced Plugin does a good job of making the vast number of options for the editor configurable, but how much control do you really need over excerpts? It may be enough to have a simple choice of "tiny" or "teeny", but having any choice at all begs the question "if it can do that, why can't it do this?"
75
+
76
+ I use git for version control, so if you want to contribute, go over to [bitbucket](https://bitbucket.org/bjorsq/rich-text-excerpts). I'll push any stable changes to the Wordpress SVN repo when they're ready.
rich-text-excerpts.php ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: Rich Text Excerpts
4
+ Plugin URI: https://bitbucket.org/bjorsq/rich-text-excerpts
5
+ Description: Adds rich text editing capability for excerpts using wp_editor()
6
+ Author: Peter Edwards
7
+ Author URI: http://bjorsq.net
8
+ Version: 1.0
9
+ License: GPLv3
10
+
11
+ This program is free software; you can redistribute it and/or modify
12
+ it under the terms of the GNU General Public License as published by
13
+ the Free Software Foundation; either version 2 of the License, or
14
+ (at your option) any later version.
15
+
16
+ This program is distributed in the hope that it will be useful,
17
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
18
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
+ GNU General Public License for more details.
20
+
21
+ You should have received a copy of the GNU General Public License
22
+ along with this program; if not, write to the Free Software
23
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24
+ */
25
+
26
+ if ( ! class_exists('RichTextExcerpts') ) :
27
+ /**
28
+ * implemented as a class to help avoid naming collisions
29
+ */
30
+ class RichTextExcerpts {
31
+
32
+ public static function register()
33
+ {
34
+ /**
35
+ * adds an action to remove the default meta box
36
+ * just after it is added to the page
37
+ */
38
+ add_action('add_meta_boxes', array('RichTextExcerpts', 'remove_excerpt_meta_box'), 1, 1);
39
+ /**
40
+ * adds an action to add the new meta box using wp_editor()
41
+ */
42
+ add_action('edit_page_form', array('RichTextExcerpts', 'add_richtext_excerpt_editor'));
43
+ add_action('edit_form_advanced', array('RichTextExcerpts', 'add_richtext_excerpt_editor'));
44
+ /**
45
+ * filters to customise the teeny mce editor
46
+ */
47
+ add_filter('teeny_mce_plugins', array('RichTextExcerpts', 'teeny_mce_plugins'), 10, 2);
48
+ add_filter('teeny_mce_buttons', array('RichTextExcerpts', 'teeny_mce_buttons'), 10, 2);
49
+ }
50
+
51
+ /**
52
+ * removes the excerpt meta box normally used to edit excerpts
53
+ */
54
+ public static function remove_excerpt_meta_box($post_type)
55
+ {
56
+ if ( post_type_supports($post_type, 'excerpt') ) {
57
+ remove_meta_box( 'postexcerpt', $post_type, 'normal' );
58
+ }
59
+ }
60
+
61
+ /**
62
+ * adds a rich text editor to edit excerpts
63
+ * includes a sanity check to see if the post type supports them first
64
+ */
65
+ public static function add_richtext_excerpt_editor()
66
+ {
67
+ global $post;
68
+ if ( post_type_supports($post->post_type, 'excerpt') ) {
69
+ self::post_excerpt_editor();
70
+ }
71
+ }
72
+
73
+ /**
74
+ * Prints the post excerpt form field (using wp_editor()).
75
+ */
76
+ public static function post_excerpt_editor()
77
+ {
78
+ global $post;
79
+ print('<div class="postbox-container"><h3 style="float:left;"><label for="excerpt">Excerpt</label></h3>');
80
+ /* options for editor */
81
+ $options = array(
82
+ "wpautop" => true,
83
+ "media_buttons" => false,
84
+ "textarea_name" => 'excerpt',
85
+ "textarea_rows" => 3,
86
+ "teeny" => true //use minimal editor configuration
87
+ );
88
+ /* "echo" the editor */
89
+ wp_editor(html_entity_decode($post->post_excerpt), 'excerpt', $options );
90
+ print('</div>');
91
+ }
92
+
93
+ /**
94
+ * filter to add plugins for the "teeny" editor
95
+ */
96
+ public static function teeny_mce_plugins($plugins, $editor_id)
97
+ {
98
+ if (!isset($plugins["paste"])) {
99
+ array_push($plugins, "paste");
100
+ }
101
+ if (!isset($plugins["charmap"])) {
102
+ array_push($plugins, "charmap");
103
+ }
104
+ return $plugins;
105
+ }
106
+
107
+ /**
108
+ * filter to add buttons to the "teeny" editor
109
+ * this completely disregards the buttons array passed to it and returns a new array
110
+ */
111
+ public static function teeny_mce_buttons($buttons, $editor_id)
112
+ {
113
+ return array('bold', 'italic', 'underline', 'separator','pastetext', 'pasteword', 'removeformat', 'separator', 'charmap', 'blockquote', 'separator', 'bullist', 'numlist', 'separator', 'justifyleft', 'justifycenter', 'justifyright', 'separator', 'undo', 'redo', 'separator', 'link', 'unlink');
114
+ }
115
+
116
+ }
117
+ /* end class definition */
118
+
119
+ /* register the Plugin with the Wordpress API */
120
+ RichTextExcerpts::register();
121
+
122
+ endif;
screenshot-1.png ADDED
Binary file