forked from rafaelmardojai/simple-alert-boxes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin.php
executable file
·208 lines (177 loc) · 5.71 KB
/
plugin.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<?php
/**
* Callout Boxes Plugin
*
* @package callout-boxes
* @author David Skinner <[email protected]>
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*/
/**
* Plugin Name: Callout Boxes
* Description: Use responsives callout boxes with shortcodes.
* Version: 2.1.3
* Author: David Skinner
* License: GPLv2 or later
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/
/* Copyright 2022 David Skinner (email: [email protected])
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* Styles enqueue
*
* @since 1.0.0
*/
function callout_boxes_styles() {
//$options = get_option( 'cob_options' );
wp_enqueue_style( 'callout-boxes', plugins_url( 'css/callout-boxes.css', __FILE__ ), array(), '1.4', 'all' );
wp_enqueue_style( 'cob-fontawesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css', array(), '4.7.0', 'all' );
}
add_action( 'wp_enqueue_scripts', 'callout_boxes_styles' );
/**
* Admin styles enqueue
*
* @since 1.3.0
*/
function callout_boxes_admin_styles() {
wp_enqueue_style( 'callout-boxes-tinymce', plugins_url( 'css/callout-boxes-tinymce.css', __FILE__ ) );
}
add_action( 'admin_enqueue_scripts', 'callout_boxes_admin_styles' );
/*********************************************************************
* SHORTCODES
*********************************************************************/
/**
* Callout Shortcode
*
* [callout type=the-box-type size=the-icon-size]the content[/callout]
*
* @since 2.0.1
*
* @param array $atts Shortcode atts.
* @param string $content Shortcode content.
* @return string Shortcode HTML.
*/
function callout_boxes_output( array $atts, string $content = null) {
$atts = shortcode_atts( array(
'type' => 'info', // set type attr and defaults
'size' => 'normal', // set size attr and defaults
'icon-size' => '', // same as above - from simple alert boxes
'element' => '' // From Documentor
), $atts );
/* ALERT SHORTCODE */
if($atts['icon-size'] != '')
{
switch ($atts['type'])
{
case 'info':
$atts['type'] = 'tip';
break;
case 'success':
$atts['type'] = 'info';
break;
case 'warning':
$atts['type'] = 'note';
break;
case 'danger':
$atts['type'] = 'warn';
break;
}
$atts['size'] = $atts['icon-size'];
}
/* DOCUMETOR SHORTCODE */
if($atts['element'] == 'callout')
{
switch ($atts['type'])
{
case 'message':
$atts['type'] = 'tip';
break;
case 'note':
$atts['type'] = 'info';
break;
case 'warning':
$atts['type'] = 'note';
break;
case 'error':
$atts['type'] = 'warn';
break;
}
}
//$options = get_option( 'cob_options' );
$classes = array();
$classes[] = $atts['type'];
$classes[] = $atts['size'];
ob_start();
?>
<div class="callout-box <?php foreach( $classes as $class ) { echo 'cob_' . $class . ' '; }?>">
<?php echo $atts['text']; echo do_shortcode( $content ); ?>
</div>
<?php
return ob_get_clean();
}
add_shortcode( 'callout', 'callout_boxes_output' );
add_shortcode( 'alert', 'callout_boxes_output' );
add_shortcode( 'docembed', 'callout_boxes_output' );
/*********************************************************************
* FILTERS
*********************************************************************/
/**
* Filters the content to remove any extra paragraph or break tags
* caused by shortcodes.
*
* @since 1.3.0
*
* @param string $content String of HTML content.
* @return string $content Amended string of HTML content.
*/
function empty_paragraph_fix( $content ) {
$array = array(
'<p>[' => '[',
']</p>' => ']',
']<br />' => ']'
);
return strtr( $content, $array );
}
add_filter( 'the_content', 'empty_paragraph_fix' );
/*********************************************************************
* TINYMCE
*********************************************************************/
/**
* Register TinyMCE plugin
*
* @since 1.2.0
*/
function callout_boxes_tinymce() {
add_filter( 'mce_buttons', 'cob_add_tinymce_button' );
add_filter( 'mce_external_plugins', 'cob_add_tinymce_plugin' );
}
add_action( 'admin_init', 'callout_boxes_tinymce' );
/**
* Add TinyMCE button
*
* @since 1.2.0
*/
function cob_add_tinymce_button( $buttons ) {
array_push( $buttons, 'callout_box_button_key' );
return $buttons;
}
/**
* Add TinyMCE plugin
*
* @since 1.2.0
*
* @param array $plugin_array TinyMCE plugins list
*/
function cob_add_tinymce_plugin( $plugin_array ) {
$plugin_array['callout_boxes'] = plugins_url( 'js/tinymce-plugin.js', __FILE__ );
return $plugin_array;
}