This repository has been archived by the owner on Jun 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
class-tp-term-description-editor.php
executable file
·70 lines (62 loc) · 1.98 KB
/
class-tp-term-description-editor.php
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
<?php
/**
* Plugin Name: Term description editor
* Description: Transforms the term description textarea to a WordPress WYSIWYG editor.
*
* Plugin URI: https://github.com/trendwerk/term-description-editor
*
* Author: Trendwerk
* Author URI: https://github.com/trendwerk
*
* Version: 1.0.0
*/
class TP_Term_Description_Editor {
function __construct() {
add_action('init',array($this,'init'),11);
add_action('admin_enqueue_scripts',array($this,'enqueue_scripts'));
//Allow HTML in Term descriptions
remove_filter('pre_term_description','wp_filter_kses');
remove_filter('term_description','wp_kses_data');
}
/**
* Initialize
*/
function init() {
$taxonomies = get_taxonomies();
if($taxonomies) :
foreach($taxonomies as $taxonomy) :
$taxonomy = get_taxonomy($taxonomy);
if(isset($taxonomy->supports) && is_array($taxonomy->supports)) :
if(in_array('editor',$taxonomy->supports)) :
add_action($taxonomy->name.'_edit_form_fields',array($this,'add'),10,2);
add_action('manage_edit-'.$taxonomy->name.'_columns',array($this,'hide_description_column'));
endif;
endif;
endforeach;
endif;
}
/**
* @add the editor
*/
function add($term, $taxonomy) {
?>
<tr class="form-field tp-term-description-editor">
<th scope="row" valign="top"><label for="description"><?php _ex('Description', 'Taxonomy Description'); ?></label></th>
<td><?php wp_editor(html_entity_decode($term->description,null,'UTF-8'),'tp-description',array('textarea_name' => 'description', 'quicktags' => false)); ?></td>
</tr>
<?php
}
/**
* @hide description as a column in the overview, because it's ugly with formatted text
*/
function hide_description_column($columns) {
unset($columns['description']);
return $columns;
}
/**
* @enqueue scripts (admin)
*/
function enqueue_scripts() {
wp_enqueue_script( 'tp-term-description-editor', plugins_url( 'assets/js/admin.js', __FILE__ ), array( 'jquery' ) );
}
} new TP_Term_Description_Editor;