class-woodojo-html-term-description.php
3.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/**
* WooDojo HTML Term Description Class
*
* Allow HTML in term descriptions and show a WYSIWYG editor.
*
* @package WordPress
* @subpackage WooDojo
* @category Downloadable
* @author WooThemes
* @since 1.0.0
*
* TABLE OF CONTENTS
*
* var $service
* var $token
* var $settings_sreen
* var $settings
*
* - __construct()
* - queue_render_actions()
* - render_field_edit()
* - render_field_add()
*/
class WooDojo_HTML_Term_Description {
/* Variable Declarations */
public $token;
/**
* Constructor.
* @access public
* @since 1.0.0
* @return void
*/
public function __construct () {
if ( ! current_user_can( 'unfiltered_html' ) ) { return; } // Only users with the "unfiltered_html" capability can use this feature.
/* Class Settings */
$this->token = 'woodojo';
/* Allow HTML */
remove_filter( 'pre_term_description', 'wp_filter_kses' );
remove_filter( 'term_description', 'wp_kses_data' );
/* Queue the render actions in admin_init. */
add_action( 'admin_init', array( &$this, 'queue_render_actions' ) );
} // End __construct()
/**
* Queue the render actions.
* @access public
* @since 1.0.1
* @return void
*/
public function queue_render_actions () {
/* Add the tinymce powered field */
$taxonomies = get_taxonomies('','names');
foreach ( $taxonomies as $taxonomy ) {
add_action( $taxonomy . '_edit_form_fields', array( &$this, 'render_field_edit' ), 1, 2 );
add_action( $taxonomy . '_add_form_fields', array( &$this, 'render_field_add' ), 1, 1 );
}
} // End queue_render_actions()
/**
* Add the WYSIWYG editor to the "edit" field.
* @access public
* @since 1.0.0
* @return void
*/
public function render_field_edit ( $tag, $taxonomy ) {
$settings = array(
'quicktags' => array( 'buttons' => 'em,strong,link' ),
'textarea_name' => 'description',
'quicktags' => true,
'tinymce' => true,
'editor_css' => '<style>#wp-html-description-editor-container .wp-editor-area{ height:250px; }</style>'
);
?>
<tr>
<th scope="row" valign="top"><label for="description"><?php _ex( 'Description', 'Taxonomy Description' ); ?></label></th>
<td><?php wp_editor( htmlspecialchars_decode( $tag->description ), 'html-description', $settings ); ?>
<span class="description"><?php _e( 'The description is not prominent by default, however some themes may show it.', 'woodojo' ); ?></span></td>
<script type="text/javascript">
// Remove the non-html field
jQuery( 'textarea#description' ).closest( '.form-field' ).remove();
</script>
</tr>
<?php
} // End render_field_edit()
/**
* Add the WYSIWYG editor to the "add" field.
* @access public
* @since 1.0.0
* @return void
*/
public function render_field_add ( $taxonomy ) {
$settings = array(
'quicktags' => array( 'buttons' => 'em,strong,link' ),
'textarea_name' => 'description',
'quicktags' => true,
'tinymce' => true,
'editor_css' => '<style>#wp-html-tag-description-editor-container .wp-editor-area{ height:150px; }</style>'
);
?>
<div>
<label for="tag-description"><?php _ex( 'Description', 'Taxonomy Description', 'woodojo' ); ?></label>
<?php wp_editor( '', 'html-tag-description', $settings ); ?>
<p class="description"><?php _e( 'The description is not prominent by default, however some themes may show it.', 'woodojo' ); ?></p>
<script type="text/javascript">
// Remove the non-html field
jQuery( 'textarea#tag-description' ).closest( '.form-field' ).remove();
jQuery(function() {
// Trigger save
jQuery( '#addtag' ).on( 'mousedown', '#submit', function() {
tinyMCE.triggerSave();
});
});
</script>
</div>
<?php
} // End render_field_add()
} // End Class