WP Editor Widget - Version 0.1.0

Version Description

  • First stable proof of concept version.
Download this release

Release Info

Developer feedmeastraycat
Plugin Icon wp plugin WP Editor Widget
Version 0.1.0
Comparing to
See all releases

Version 0.1.0

Files changed (5) hide show
  1. assets/css/admin.css +58 -0
  2. assets/js/admin.js +47 -0
  3. license.txt +19 -0
  4. readme.txt +25 -0
  5. wp-editor-widget.php +177 -0
assets/css/admin.css ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #wp-editor-widget-container {
2
+ position: fixed;
3
+ top: 30px;
4
+ left: 30px;
5
+ right: 30px;
6
+ bottom: 30px;
7
+ z-index: 160000;
8
+ background: #fff;
9
+ }
10
+ #wp-editor-widget-backdrop {
11
+ position: fixed;
12
+ top: 0;
13
+ left: 0;
14
+ right: 0;
15
+ bottom: 0;
16
+ min-height: 360px;
17
+ background: #000;
18
+ opacity: .7;
19
+ z-index: 159900;
20
+ }
21
+ #wp-editor-widget-container .close {
22
+ position: absolute;
23
+ top: 7px;
24
+ right: 7px;
25
+ width: 30px;
26
+ height: 30px;
27
+ z-index: 1000;
28
+ }
29
+ #wp-editor-widget-container .close span {
30
+ display: block;
31
+ margin: 8px auto 0;
32
+ width: 15px;
33
+ height: 15px;
34
+ background-position: -100px 0;
35
+ }
36
+ #wp-editor-widget-container .icon {
37
+ background-image: url(../../../wp-includes/images/uploader-icons.png);
38
+ background-repeat: no-repeat;
39
+ }
40
+ #wp-editor-widget-container .close:active {
41
+ outline: 0;
42
+ }
43
+ #wp-editor-widget-container .editor {
44
+ margin: 50px;
45
+ }
46
+
47
+ /**
48
+ * HiDPI Displays
49
+ */
50
+ @media print,
51
+ (-o-min-device-pixel-ratio: 5/4),
52
+ (-webkit-min-device-pixel-ratio: 1.25),
53
+ (min-resolution: 120dpi) {
54
+ #wp-editor-widget-container .icon {
55
+ background-image: url(../images/uploader-icons-2x.png);
56
+ background-size: 134px 15px;
57
+ }
58
+ }
assets/js/admin.js ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * WP Editor Widget object
3
+ */
4
+ WPEditorWidget = {
5
+
6
+ /**
7
+ * @var string
8
+ */
9
+ currentContentId: '',
10
+
11
+ /**
12
+ * Show the editor
13
+ * @param string contentId
14
+ */
15
+ showEditor: function(contentId) {
16
+ jQuery('#wp-editor-widget-backdrop').show();
17
+ jQuery('#wp-editor-widget-container').show();
18
+
19
+ this.currentContentId = contentId;
20
+
21
+ this.setEditorContent(contentId);
22
+ },
23
+
24
+ /**
25
+ * Hide editor
26
+ */
27
+ hideEditor: function() {
28
+ jQuery('#wp-editor-widget-backdrop').hide();
29
+ jQuery('#wp-editor-widget-container').hide();
30
+ },
31
+
32
+ /**
33
+ * Set editor content
34
+ */
35
+ setEditorContent: function(contentId) {
36
+ tinyMCE.editors['wp-editor-widget'].setContent(jQuery('#'+ contentId).val());
37
+ },
38
+
39
+ /**
40
+ * Update widget and close the editor
41
+ */
42
+ updateWidgetAndCloseEditor: function() {
43
+ jQuery('#'+ this.currentContentId).val(tinyMCE.editors['wp-editor-widget'].getContent());
44
+ this.hideEditor();
45
+ }
46
+
47
+ };
license.txt ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Copyright (c) 2013 David Mårtensson <david.martensson@gmail.com>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
readme.txt ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === WP Editor Widget ===
2
+ Contributors: feedmeastraycat
3
+ Tags: widget, wysiwyg, editor
4
+ Requires at least: 3.5.1
5
+ Tested up to: 3.5.1
6
+ Stable tag: 0.1.0
7
+ License: MIT
8
+
9
+ WP Editor Widget adds a WYSIWYG widget using the wp_editor().
10
+
11
+ == Description ==
12
+
13
+ This plugin adds a WYSIWYG widget using the WP core function wp_editor() without
14
+ adding a custom post type for each widget.
15
+
16
+ == Installation ==
17
+
18
+ 1. Extract the ZIP file and move the folder "wp-editor-widget", with it contents,
19
+ to `/wp-content/plugins/` in your WordPress installation
20
+ 2. Activate the pluing under 'Plugins' in the WordPress admin area
21
+
22
+ == Changelog ==
23
+
24
+ = 0.1.0 =
25
+ * First stable proof of concept version.
wp-editor-widget.php ADDED
@@ -0,0 +1,177 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: WP Editor Widget
4
+ Plugin URI: http://oddalice.com/
5
+ Description: WP Editor Widget adds a WYSIWYG widget using the wp_editor().
6
+ Author: David M&aring;rtensson, Odd Alice
7
+ Version: 0.1.0
8
+ Author URI: http://www.feedmeastraycat.net/
9
+ */
10
+
11
+
12
+
13
+ // Setup actions
14
+ add_action('admin_init', array('WPEditorWidget', 'admin_init'));
15
+ add_action('widgets_admin_page', array('WPEditorWidget', 'widgets_admin_page'), 100);
16
+ add_action('widgets_init', array('WPEditorWidget', 'widgets_init'));
17
+
18
+
19
+
20
+ /**
21
+ * WP Editor Widget singelton
22
+ */
23
+ class WPEditorWidget
24
+ {
25
+
26
+ const TEXTDOMAIN = "wpeditorwidget";
27
+
28
+ /**
29
+ * Action: admin_init
30
+ */
31
+ public static function admin_init()
32
+ {
33
+ wp_register_script('wp-editor-widget-js', plugins_url('assets/js/admin.js', __FILE__));
34
+ wp_enqueue_script('wp-editor-widget-js');
35
+
36
+ wp_register_style('wp-editor-widget-css', plugins_url('assets/css/admin.css', __FILE__));
37
+ wp_enqueue_style('wp-editor-widget-css');
38
+ }
39
+
40
+ /**
41
+ * Action: widgets_admin_page
42
+ */
43
+ public static function widgets_admin_page() {
44
+ ?>
45
+ <div id="wp-editor-widget-container" style="display: none;">
46
+ <a class="close" href="javascript:WPEditorWidget.hideEditor();" title="<?php esc_attr_e('Close', self::TEXTDOMAIN) ?>"><span class="icon"></span></a>
47
+ <div class="editor">
48
+ <?php
49
+ $settings = array(
50
+ 'textarea_rows' => 15
51
+ );
52
+ wp_editor('', 'wp-editor-widget', $settings);
53
+ ?>
54
+ <p>
55
+ <a href="javascript:WPEditorWidget.updateWidgetAndCloseEditor();" class="button"><?php _e('Update and close', self::TEXTDOMAIN) ?></a>
56
+ </p>
57
+ </div>
58
+ </div>
59
+ <div id="wp-editor-widget-backdrop" style="display: none;"></div>
60
+ <?php
61
+ }
62
+
63
+ /**
64
+ * Action: widgets_init
65
+ */
66
+ public static function widgets_init()
67
+ {
68
+ register_widget('WP_Editor_Widget');
69
+ }
70
+
71
+ }
72
+
73
+
74
+
75
+ /**
76
+ * Adds WP_Editor_Widget widget.
77
+ */
78
+ class WP_Editor_Widget extends WP_Widget {
79
+
80
+ /**
81
+ * Register widget with WordPress.
82
+ */
83
+ public function __construct() {
84
+ parent::__construct(
85
+ 'wp_editor_widget',
86
+ __('WP Editor Widget', WPEditorWidget::TEXTDOMAIN),
87
+ array('description' => __('Adds an WP Editor Widget for WYSIWYG content.', WPEditorWidget::TEXTDOMAIN))
88
+ );
89
+ }
90
+
91
+ /**
92
+ * Front-end display of widget.
93
+ *
94
+ * @see WP_Widget::widget()
95
+ *
96
+ * @param array $args Widget arguments.
97
+ * @param array $instance Saved values from database.
98
+ */
99
+ public function widget($args, $instance) {
100
+ extract( $args );
101
+
102
+ $title = apply_filters('wp_editor_widget_title', $instance['title']);
103
+ $output_title = apply_filters('wp_editor_widget_output_title', $instance['output_title']);
104
+ $content = apply_filters('wp_editor_widget_content', $instance['content']);
105
+
106
+ echo $before_widget;
107
+
108
+ if ($output_title == "1" && !empty($title)) {
109
+ echo $before_title.$title.$after_title;
110
+ }
111
+
112
+ echo $content;
113
+
114
+ echo $after_widget;
115
+ }
116
+
117
+ /**
118
+ * Back-end widget form.
119
+ *
120
+ * @see WP_Widget::form()
121
+ *
122
+ * @param array $instance Previously saved values from database.
123
+ */
124
+ public function form( $instance ) {
125
+ if (isset( $instance[ 'title' ])) {
126
+ $title = $instance['title'];
127
+ }
128
+ else {
129
+ $title = __('New title', WPEditorWidget::TEXTDOMAIN);
130
+ }
131
+
132
+ if (isset( $instance['content'])) {
133
+ $content = $instance['content'];
134
+ }
135
+ else {
136
+ $content = "";
137
+ }
138
+
139
+ $output_title = (isset($instance['output_title']) && $instance['output_title'] == "1" ? true:false);
140
+ ?>
141
+ <input type="hidden" id="<?php echo $this->get_field_id('content'); ?>" name="<?php echo $this->get_field_name('content'); ?>" value="<?php echo esc_attr($content); ?>">
142
+ <p>
143
+ <label for="<?php echo $this->get_field_name('title'); ?>"><?php _e('Title', WPEditorWidget::TEXTDOMAIN); ?>:</label>
144
+ <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" />
145
+ </p>
146
+ <p>
147
+ <a href="javascript:WPEditorWidget.showEditor('<?php echo $this->get_field_id('content'); ?>');"><?php _e('Edit content', WPEditorWidget::TEXTDOMAIN) ?></a>
148
+ </p>
149
+ <p>
150
+ <label for="<?php echo $this->get_field_id('output_title'); ?>">
151
+ <input type="checkbox" id="<?php echo $this->get_field_id('output_title'); ?>" name="<?php echo $this->get_field_name('output_title'); ?>" value="1" <?php checked($output_title, true) ?>> <?php _e('Output title', WPEditorWidget::TEXTDOMAIN); ?>
152
+ </label>
153
+ </p>
154
+ <?php
155
+ }
156
+
157
+ /**
158
+ * Sanitize widget form values as they are saved.
159
+ *
160
+ * @see WP_Widget::update()
161
+ *
162
+ * @param array $new_instance Values just sent to be saved.
163
+ * @param array $old_instance Previously saved values from database.
164
+ *
165
+ * @return array Updated safe values to be saved.
166
+ */
167
+ public function update( $new_instance, $old_instance ) {
168
+ $instance = array();
169
+
170
+ $instance['title'] = (!empty($new_instance['title']) ? strip_tags( $new_instance['title']):'');
171
+ $instance['content'] = (!empty($new_instance['content']) ? $new_instance['content']:'');
172
+ $instance['output_title'] = (isset($new_instance['output_title']) && $new_instance['output_title'] == "1" ? 1:0);
173
+
174
+ return $instance;
175
+ }
176
+
177
+ }