|
1
|
|
|
<?php |
|
2
|
|
|
//avoid direct calls to this file |
|
3
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
|
4
|
|
|
header( 'Status: 403 Forbidden' ); |
|
5
|
|
|
header( 'HTTP/1.1 403 Forbidden' ); |
|
6
|
|
|
exit(); |
|
7
|
|
|
} |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Adds WP_Editor_Widget widget. |
|
11
|
|
|
*/ |
|
12
|
|
|
class WP_Editor_Widget extends WP_Widget { |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Register widget with WordPress. |
|
16
|
|
|
*/ |
|
17
|
|
|
public function __construct() { |
|
18
|
|
|
|
|
19
|
|
|
// WPML support? |
|
20
|
|
|
if ( function_exists( 'icl_get_languages' ) ) { |
|
21
|
|
|
$widget_name = esc_html__( 'Multilingual', 'wp-editor-widget' ) . ' ' . esc_html__( 'Rich text', 'wp-editor-widget' ); |
|
22
|
|
|
} |
|
23
|
|
|
else { |
|
24
|
|
|
$widget_name = esc_html__( 'Rich text', 'wp-editor-widget' ); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
$widget_ops = apply_filters( |
|
28
|
|
|
'wp_editor_widget_ops', |
|
29
|
|
|
array( |
|
30
|
|
|
'classname' => 'WP_Editor_Widget', |
|
31
|
|
|
'description' => __( 'Arbitrary text, HTML or rich text through the standard WordPress visual editor.', 'wp-editor-widget' ), |
|
32
|
|
|
) |
|
33
|
|
|
); |
|
34
|
|
|
|
|
35
|
|
|
parent::__construct( |
|
36
|
|
|
'WP_Editor_Widget', |
|
37
|
|
|
$widget_name, |
|
38
|
|
|
$widget_ops |
|
39
|
|
|
); |
|
40
|
|
|
|
|
41
|
|
|
} // END __construct() |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Front-end display of widget. |
|
45
|
|
|
* |
|
46
|
|
|
* @see WP_Widget::widget() |
|
47
|
|
|
* |
|
48
|
|
|
* @param array $args Widget arguments. |
|
49
|
|
|
* @param array $instance Saved values from database. |
|
50
|
|
|
*/ |
|
51
|
|
|
public function widget( $args, $instance ) { |
|
52
|
|
|
|
|
53
|
|
|
$title = apply_filters( 'wp_editor_widget_title', $instance['title'] ); |
|
54
|
|
|
$output_title = apply_filters( 'wp_editor_widget_output_title', $instance['output_title'] ); |
|
55
|
|
|
$content = apply_filters( 'wp_editor_widget_content', $instance['content'] ); |
|
56
|
|
|
|
|
57
|
|
|
$show = true; |
|
58
|
|
|
|
|
59
|
|
|
// WPML support? |
|
60
|
|
|
if ( function_exists( 'icl_get_languages' ) ) { |
|
61
|
|
|
$language = apply_filters( 'wp_editor_widget_language', $instance['language'] ); |
|
62
|
|
|
$show = ($language == icl_get_current_language()); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
if ( $show ) { |
|
66
|
|
|
|
|
67
|
|
|
$default_html = $args['before_widget']; |
|
68
|
|
|
|
|
69
|
|
|
if ( '1' == $output_title && ! empty( $title ) ) { |
|
70
|
|
|
$default_html .= $args['before_title'] . $title . $args['after_title']; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
$default_html .= $content; |
|
74
|
|
|
|
|
75
|
|
|
$default_html .= $args['after_widget']; |
|
76
|
|
|
|
|
77
|
|
|
echo apply_filters( 'wp_editor_widget_html', $default_html, $args['id'], $instance, $args['before_widget'], $args['after_widget'], $output_title, $title, $args['before_title'], $args['after_title'], $content ); |
|
|
|
|
|
|
78
|
|
|
|
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
} // END widget() |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Back-end widget form. |
|
85
|
|
|
* |
|
86
|
|
|
* @see WP_Widget::form() |
|
87
|
|
|
* |
|
88
|
|
|
* @param array $instance Previously saved values from database. |
|
89
|
|
|
*/ |
|
90
|
|
|
public function form( $instance ) { |
|
91
|
|
|
|
|
92
|
|
|
if ( isset( $instance['title'] ) ) { |
|
93
|
|
|
$title = $instance['title']; |
|
94
|
|
|
} |
|
95
|
|
|
else { |
|
96
|
|
|
$title = __( 'New title', 'wp-editor-widget' ); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
if ( isset( $instance['content'] ) ) { |
|
100
|
|
|
$content = $instance['content']; |
|
101
|
|
|
} |
|
102
|
|
|
else { |
|
103
|
|
|
$content = ''; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
$output_title = ( isset( $instance['output_title'] ) && '1' == $instance['output_title'] ? true : false ); |
|
107
|
|
|
?> |
|
108
|
|
|
<input type="hidden" id="<?php echo esc_attr( $this->get_field_id( 'content' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'content' ) ); ?>" value="<?php echo esc_attr( $content ); ?>"> |
|
109
|
|
|
<p> |
|
110
|
|
|
<label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php _e( 'Title', 'wp-editor-widget' ); ?>:</label> |
|
111
|
|
|
<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" /> |
|
112
|
|
|
</p> |
|
113
|
|
|
<p> |
|
114
|
|
|
<a href="javascript:WPEditorWidget.showEditor('<?php echo esc_attr( $this->get_field_id( 'content' ) ); ?>');" class="button"><?php _e( 'Edit content', 'wp-editor-widget' ) ?></a> |
|
115
|
|
|
</p> |
|
116
|
|
|
<p> |
|
117
|
|
|
<label for="<?php echo esc_attr( $this->get_field_id( 'output_title' ) ); ?>"> |
|
118
|
|
|
<input type="checkbox" id="<?php echo esc_attr( $this->get_field_id( 'output_title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'output_title' ) ); ?>" value="1" <?php checked( $output_title, true ) ?>> <?php _e( 'Output title', 'wp-editor-widget' ); ?> |
|
119
|
|
|
</label> |
|
120
|
|
|
</p> |
|
121
|
|
|
<?php if ( function_exists( 'icl_get_languages' ) ) : $languages = icl_get_languages( 'skip_missing=0&orderby=code' ); ?> |
|
122
|
|
|
<label for="<?php echo esc_attr( $this->get_field_id( 'language' ) ); ?>"> |
|
123
|
|
|
<?php _e( 'Language', 'wp-editor-widget' ); ?>: |
|
124
|
|
|
<select id="<?php echo esc_attr( $this->get_field_id( 'language' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'language' ) ); ?>"> |
|
125
|
|
|
<?php foreach ( $languages as $id => $lang ) : ?> |
|
126
|
|
|
<option value="<?php echo esc_attr( $lang['language_code'] ) ?>" <?php selected( $instance['language'], $lang['language_code'] ) ?>><?php echo esc_attr( $lang['native_name'] ) ?></option> |
|
127
|
|
|
<?php endforeach; ?> |
|
128
|
|
|
</select> |
|
129
|
|
|
</label> |
|
130
|
|
|
<?php endif; ?> |
|
131
|
|
|
<?php |
|
132
|
|
|
|
|
133
|
|
|
do_action( 'wp_editor_widget_form', $this, $instance ); |
|
134
|
|
|
|
|
135
|
|
|
} // END form() |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* Sanitize widget form values as they are saved. |
|
139
|
|
|
* |
|
140
|
|
|
* @see WP_Widget::update() |
|
141
|
|
|
* |
|
142
|
|
|
* @param array $new_instance Values just sent to be saved. |
|
143
|
|
|
* @param array $old_instance Previously saved values from database. |
|
144
|
|
|
* |
|
145
|
|
|
* @return array Updated safe values to be saved. |
|
146
|
|
|
*/ |
|
147
|
|
|
public function update( $new_instance, $old_instance ) { |
|
148
|
|
|
|
|
149
|
|
|
$instance = array(); |
|
150
|
|
|
|
|
151
|
|
|
$instance['title'] = ( ! empty( $new_instance['title'] ) ? strip_tags( $new_instance['title'] ) : '' ); |
|
152
|
|
|
$instance['content'] = ( ! empty( $new_instance['content'] ) ? $new_instance['content'] : '' ); |
|
153
|
|
|
$instance['output_title'] = ( isset( $new_instance['output_title'] ) && '1' == $new_instance['output_title'] ? 1 : 0 ); |
|
154
|
|
|
|
|
155
|
|
|
// WPML support |
|
156
|
|
|
if ( function_exists( 'icl_get_languages' ) ) { |
|
157
|
|
|
$instance['language'] = ( isset( $new_instance['language'] ) ? $new_instance['language'] : ''); |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
do_action( 'wp_editor_widget_update', $new_instance, $instance ); |
|
161
|
|
|
|
|
162
|
|
|
return apply_filters( 'wp_editor_widget_update_instance', $instance, $new_instance ); |
|
163
|
|
|
|
|
164
|
|
|
} // END update() |
|
165
|
|
|
|
|
166
|
|
|
} // END class WP_Editor_Widget |
|
167
|
|
|
|