-
Notifications
You must be signed in to change notification settings - Fork 1
/
class-newcity-toolbars.php
125 lines (101 loc) · 3.59 KB
/
class-newcity-toolbars.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
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
<?php
/**
*
* Defines custom toolbars for TinyMCE
*
* @since 0.1.0
*
* @package NewCity_WYSIWYG
* @author Jesse Janowiak <[email protected]>
*/
class NewCityToolbars {
public function __construct() {
add_editor_style( plugins_url( 'wysiwyg-styles.css', __FILE__ ) );
add_filter( 'tiny_mce_before_init', array( $this, 'modify_tiny_mce' ) );
add_action( 'init', array( $this, 'register_mce_toolbar' ) );
add_filter( 'acf/fields/wysiwyg/toolbars', array( $this, 'my_toolbars' ) );
}
public function modify_tiny_mce( $settings ) {
$settings['block_formats'] = 'Paragraph=p;Heading 2=h2;Heading 3=h3;Heading 4=h4;';
if (get_option('newcity_wysiwyg_toolbar_format_dropdown')) {
$style_formats = array(
array(
'title' => 'Intro Paragraph',
'block' => 'p',
'classes' => 'intro',
'wrapper' => false
),
array(
'title' => 'Featured Link',
'inline' => 'a',
'classes' => 'large-arrow',
'wrapper' => true,
'attributes' => array( 'href' => '#' ),
),
);
$settings['style_formats'] = json_encode( $style_formats );
}
return $settings;
}
private function blockquote_name() {
if ( shortcode_exists( 'newcity_blockquote' ) ) {
return 'newcity_blockquote';
}
return 'blockquote';
}
private function custom_styles( $init_array ) {
if (get_option('newcity_wysiwyg_toolbar_format_dropdown')) {
$style_formats = array(
array(
'title' => 'Intro Paragraph',
'block' => 'p',
'classes' => 'intro',
'wrapper' => false,
),
array(
'title' => 'Featured Link',
'selector' => 'a',
'block' => 'a',
'classes' => 'large-arrow',
'wrapper' => false,
),
);
$init_array['style_formats'] = json_encode( $style_formats );
}
return $init_array;
}
function add_style_select_buttons( $buttons ) {
array_unshift( $buttons, 'styleselect' );
return $buttons;
}
function my_toolbars( $toolbars ) {
$toolbars['Minimum'] = array();
$toolbars['Minimum'][1] = array( 'bold', 'italic', '|', 'removeformat', '|', 'fullscreen' );
$toolbars['Minimum with Links'] = array();
$toolbars['Minimum with Links'][1] = array( 'bold', 'italic', 'link', 'unlink', '|', 'removeformat', '|', 'fullscreen' );
$toolbars['Minimum with Lists'] = array();
$toolbars['Minimum with Lists'][1] = array( 'bold', 'italic', 'link', 'unlink', '|', 'bullist', 'numlist', '|', 'removeformat', '|', 'fullscreen' );
$toolbars['Simple'] = array();
$toolbars['Simple'][1] = array( 'bold', 'italic', 'link', 'unlink', 'bullist', 'numlist', $this->blockquote_name(), '|', 'removeformat', '|', 'fullscreen' );
$toolbars['Simple with Headers'] = array();
$toolbars['Simple with Headers'][1] = array( 'bold', 'italic', 'link', 'unlink', 'bullist', 'numlist', 'formatselect', '|', 'removeformat', '|', 'fullscreen' );
if (get_option('newcity_wysiwyg_toolbar_format_dropdown')) {
array_splice($toolbars['Simple with Headers'][1], 6, 0, 'styleselect');
}
unset( $toolbars['Basic'] );
return $toolbars;
}
public function default_mce_toolbar( $buttons ) {
$buttons = array( 'bold', 'italic', 'link', 'unlink', 'bullist', 'numlist', 'formatselect', '|', 'removeformat', '|', 'fullscreen' );
return $buttons;
}
public function extra_mce_toolbar( $buttons ) {
$buttons = array( 'charmap', 'pastetext', 'undo', 'redo' );
return $buttons;
}
function register_mce_toolbar() {
add_filter( 'mce_buttons', array( $this, 'default_mce_toolbar' ) );
add_filter( 'mce_buttons', array( $this, 'add_style_select_buttons' ) );
add_filter( 'mce_buttons_2', array( $this, 'extra_mce_toolbar' ) );
}
}