-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathorganic-shortcodes-functions.php
449 lines (366 loc) · 14.6 KB
/
organic-shortcodes-functions.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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
<?php
/*
-------------------------------------------------------------------------------------------------------
Toggle Box
-------------------------------------------------------------------------------------------------------
*/
function organic_toggle( $atts, $content = null ) {
$args = shortcode_atts(
array(
'title' => 'Toggle Item',
),
$atts
);
$title = esc_attr( $args['title'] );
$output = '
<div class="toggle-box">
<p class="toggle-trigger"><a href="javascript:void(0);">' . html_entity_decode( $title ) . '</a></p>
<div class="toggle-section">' . do_shortcode( $content ) . '</div>
</div>';
return force_balance_tags( $output );
}
add_shortcode( 'toggle', 'organic_toggle' );
/*
-------------------------------------------------------------------------------------------------------
Horizontal Bar Rating
-------------------------------------------------------------------------------------------------------
*/
function organic_rating( $atts ) {
$args = shortcode_atts(
array(
'title' => '',
'number' => '50',
),
$atts
);
$title = esc_attr( $args['title'] );
$number = (int) $args['number'];
return '<div class="rating-container">
<p class="rating-title">' . $title . '</p>
<div class="bar-rating"><span style="width:' . $number . '%;"></span></div>
</div>';
}
add_shortcode( 'rating', 'organic_rating' );
/*
-------------------------------------------------------------------------------------------------------
Modal Box
-------------------------------------------------------------------------------------------------------
*/
function organic_modal( $atts, $content = null ) {
$args = shortcode_atts(
array(
'title' => 'Open Modal',
'tag' => 'organic-modal',
'color' => '',
'size' => '',
'align' => '',
),
$atts
);
$title = esc_attr( $args['title'] );
$tag = esc_attr( $args['tag'] );
$color = esc_attr( $args['color'] );
$size = esc_attr( $args['size'] );
$align = esc_attr( $args['align'] );
$style = ( $color ) ? ' ' . $color . '-btn' : '';
$position = ( $align ) ? ' align-' . $align : '';
$output = '
<div class="modal modal-btn ' . $position . '"><a class="organic-btn ' . $style . ' ' . $size . '-btn ' . $position . '" href="#' . $tag . '" rel="modal:open"><span class="btn-holder">' . $title . '</span></a></div>
<div id="' . $tag . '" class="modal organic-modal" style="display: none;"><span class="modal-title">' . $title . '</span>' . do_shortcode( $content ) . '</div>';
return $output;
}
add_shortcode( 'modal', 'organic_modal' );
/*
-------------------------------------------------------------------------------------------------------
Accordion
-------------------------------------------------------------------------------------------------------
*/
function organic_accordion( $atts, $content = null ) {
$args = shortcode_atts(
array(
'collapsible' => 'false',
),
$atts
);
$collapse = esc_attr( $args['collapsible'] );
$GLOBALS['section_count'] = 0;
// Get the content.
do_shortcode( $content );
// Generate output.
if ( is_array( $GLOBALS['sections'] ) ) {
foreach ( $GLOBALS['sections'] as $section ) {
$panes[] = '<p><a href="javascript:void(0);">' . $section['name'] . '</a></p>
<div id="' . esc_attr( str_replace( ' ', '-', strtolower( $section['name'] ) ) ) . '">
' . do_shortcode( $section['content'] ) . '
</div>';
}
}
$output = "\n" . '<div class="organic-accordion">' . implode( "\n", $panes ) . '</div>' . "\n";
unset( $GLOBALS['sections'] ); // Clear array fix for multiple shorcodes.
return force_balance_tags( $output );
}
add_shortcode( 'accordion', 'organic_accordion' );
function organic_accordion_section( $atts, $content = null ) {
$args = shortcode_atts(
array(
'name' => 'Accordion Section Name',
),
$atts
);
$name = esc_attr( $args['name'] );
$x = $GLOBALS['section_count'];
$GLOBALS['sections'][ $x ] = array(
'name' => sprintf( html_entity_decode( $name ), $GLOBALS['section_count'] ),
'content' => do_shortcode( $content ),
);
$GLOBALS['section_count'] += 1;
}
add_shortcode( 'section', 'organic_accordion_section' );
/*
-------------------------------------------------------------------------------------------------------
Tabs
-------------------------------------------------------------------------------------------------------
*/
function organic_tab_group( $atts, $content ) {
$GLOBALS['tab_count'] = 0;
do_shortcode( $content );
if ( is_array( $GLOBALS['tabs'] ) ) {
$int = '1';
foreach ( $GLOBALS['tabs'] as $tab ) {
$tabs[] = '<li><a href="#panel-' . $int . '">' . $tab['title'] . '</a></li>';
$panes[] = '
<div class="ui-tabs-hide" id="panel-' . $int . '">
<h3>' . $tab['title'] . '</h3>
' . $tab['content'] . '
</div>';
$int++;
}
$output = "\n" . '
<div class="organic-tabs">
<ul id="tabs">' . implode( "\n", $tabs ) . '</ul>
' . "\n" . ' ' . implode( "\n", $panes ) . '
</div>' . "\n";
}
unset( $GLOBALS['tabs'] ); // Clear array fix for multiple shorcodes.
return force_balance_tags( $output );
}
add_shortcode( 'tabs', 'organic_tab_group' );
function organic_tab( $atts, $content ) {
$args = shortcode_atts(
array(
'title' => 'Tab %d',
),
$atts
);
$title = esc_attr( $args['title'] );
$x = $GLOBALS['tab_count'];
$GLOBALS['tabs'][ $x ] = array(
'title' => sprintf( html_entity_decode( $title ), $GLOBALS['tab_count'] ),
'content' => do_shortcode( $content ),
);
$GLOBALS['tab_count']++;
}
add_shortcode( 'tab', 'organic_tab' );
/*
-------------------------------------------------------------------------------------------------------
Icons
-------------------------------------------------------------------------------------------------------
*/
function organic_icons( $atts, $content = null ) {
$args = shortcode_atts(
array(
'style' => '',
'color' => '',
'size' => '',
'align' => '',
),
$atts
);
$style = esc_attr( $args['style'] );
$color = esc_attr( $args['color'] );
$size = esc_attr( $args['size'] );
$align = esc_attr( $args['align'] );
$output = '<span class="organic-icon" style="text-align: ' . $align . ';"><i class="fa fa-' . $style . '" style="color: #' . $color . '; font-size: ' . $size . 'px;"></i> ' . do_shortcode( $content ) . '</span>';
return $output;
}
add_shortcode( 'icon', 'organic_icons' );
/*
-------------------------------------------------------------------------------------------------------
Headlines
-------------------------------------------------------------------------------------------------------
*/
function organic_headline( $atts, $content = null ) {
$args = shortcode_atts(
array(
'align' => 'left',
'color' => '000000',
'size' => 'large',
),
$atts
);
$align = esc_attr( $args['align'] );
$color = esc_attr( $args['color'] );
$size = esc_attr( $args['size'] );
$output = '<h2 class="organic-headline ' . $size . '-headline" style="text-align: ' . $align . '; color: #' . $color . ';">' . do_shortcode( $content ) . '</h2>';
return $output;
}
add_shortcode( 'headline', 'organic_headline' );
/*
-------------------------------------------------------------------------------------------------------
Buttons
-------------------------------------------------------------------------------------------------------
*/
function organic_button( $atts, $content = null ) {
$args = shortcode_atts(
array(
'link' => '#',
'target' => '',
'color' => '',
'size' => '',
'align' => 'left',
),
$atts
);
$link = esc_url( $args['link'] );
$target = esc_attr( $args['target'] );
$color = esc_attr( $args['color'] );
$size = esc_attr( $args['size'] );
$align = esc_attr( $args['align'] );
$style = ( $color ) ? ' ' . $color . '-btn' : '';
$position = ( $align ) ? ' align-' . $align : '';
$location = ( 'blank' === $target ) ? ' target="_blank"' : '';
$output = '<div class="btn-container' . $position . '"><a ' . $location . ' class="organic-btn' . $style . ' ' . $size . '-btn' . $position . '" href="' . $link . '"><span class="btn-holder">' . do_shortcode( $content ) . '</span></a></div>';
return $output;
}
add_shortcode( 'button', 'organic_button' );
/*
-------------------------------------------------------------------------------------------------------
Alert Box
-------------------------------------------------------------------------------------------------------
*/
function organic_box( $atts, $content = null ) {
$args = shortcode_atts(
array(
'color' => '',
'align' => '',
),
$atts
);
$align = esc_attr( $args['align'] );
$color = esc_attr( $args['color'] );
$style = ( $color ) ? ' ' . $color . '-box' : '';
$position = ( $align ) ? ' text-' . $align : '';
$output = '<div class="organic-box ' . $style . $position . '"><a href="#blank" class="close"><i class="fa fa-times"></i></a><div class="box-content">' . do_shortcode( $content ) . '</div></div>';
return $output;
}
add_shortcode( 'box', 'organic_box' );
/*
-------------------------------------------------------------------------------------------------------
Columns
-------------------------------------------------------------------------------------------------------
*/
function organic_one_third( $atts, $content = null ) {
return '<div class="organic-column one-third">' . do_shortcode( $content ) . '</div>';
}
add_shortcode( 'one_third', 'organic_one_third' );
function organic_one_third_last( $atts, $content = null ) {
return '<div class="organic-column one-third last">' . do_shortcode( $content ) . '</div><div class="clearboth"></div>';
}
add_shortcode( 'one_third_last', 'organic_one_third_last' );
function organic_two_third( $atts, $content = null ) {
return '<div class="organic-column two-third">' . do_shortcode( $content ) . '</div>';
}
add_shortcode( 'two_third', 'organic_two_third' );
function organic_two_third_last( $atts, $content = null ) {
return '<div class="organic-column two-third last">' . do_shortcode( $content ) . '</div><div class="clearboth"></div>';
}
add_shortcode( 'two_third_last', 'organic_two_third_last' );
function organic_one_half( $atts, $content = null ) {
return '<div class="organic-column one-half">' . do_shortcode( $content ) . '</div>';
}
add_shortcode( 'one_half', 'organic_one_half' );
function organic_one_half_last( $atts, $content = null ) {
return '<div class="organic-column one-half last">' . do_shortcode( $content ) . '</div><div class="clearboth"></div>';
}
add_shortcode( 'one_half_last', 'organic_one_half_last' );
function organic_one_fourth( $atts, $content = null ) {
return '<div class="organic-column one-fourth">' . do_shortcode( $content ) . '</div>';
}
add_shortcode( 'one_fourth', 'organic_one_fourth' );
function organic_one_fourth_last( $atts, $content = null ) {
return '<div class="organic-column one-fourth last">' . do_shortcode( $content ) . '</div><div class="clearboth"></div>';
}
add_shortcode( 'one_fourth_last', 'organic_one_fourth_last' );
function organic_three_fourth( $atts, $content = null ) {
return '<div class="organic-column three-fourth">' . do_shortcode( $content ) . '</div>';
}
add_shortcode( 'three_fourth', 'organic_three_fourth' );
function organic_three_fourth_last( $atts, $content = null ) {
return '<div class="organic-column three-fourth last">' . do_shortcode( $content ) . '</div><div class="clearboth"></div>';
}
add_shortcode( 'three_fourth_last', 'organic_three_fourth_last' );
function organic_one_fifth( $atts, $content = null ) {
return '<div class="organic-column one-fifth">' . do_shortcode( $content ) . '</div>';
}
add_shortcode( 'one_fifth', 'organic_one_fifth' );
function organic_one_fifth_last( $atts, $content = null ) {
return '<div class="organic-column one-fifth last">' . do_shortcode( $content ) . '</div><div class="clearboth"></div>';
}
add_shortcode( 'one_fifth_last', 'organic_one_fifth_last' );
function organic_two_fifth( $atts, $content = null ) {
return '<div class="organic-column two-fifth">' . do_shortcode( $content ) . '</div>';
}
add_shortcode( 'two_fifth', 'organic_two_fifth' );
function organic_two_fifth_last( $atts, $content = null ) {
return '<div class="organic-column two-fifth last">' . do_shortcode( $content ) . '</div><div class="clearboth"></div>';
}
add_shortcode( 'two_fifth_last', 'organic_two_fifth_last' );
function organic_three_fifth( $atts, $content = null ) {
return '<div class="organic-column three-fifth">' . do_shortcode( $content ) . '</div>';
}
add_shortcode( 'three_fifth', 'organic_three_fifth' );
function organic_three_fifth_last( $atts, $content = null ) {
return '<div class="organic-column three-fifth last">' . do_shortcode( $content ) . '</div><div class="clearboth"></div>';
}
add_shortcode( 'three_fifth_last', 'organic_three_fifth_last' );
function organic_four_fifth( $atts, $content = null ) {
return '<div class="organic-column four-fifth">' . do_shortcode( $content ) . '</div>';
}
add_shortcode( 'four_fifth', 'organic_four_fifth' );
function organic_four_fifth_last( $atts, $content = null ) {
return '<div class="organic-column four-fifth last">' . do_shortcode( $content ) . '</div><div class="clearboth"></div>';
}
add_shortcode( 'four_fifth_last', 'organic_four_fifth_last' );
function organic_one_sixth( $atts, $content = null ) {
return '<div class="organic-column one-sixth">' . do_shortcode( $content ) . '</div>';
}
add_shortcode( 'one_sixth', 'organic_one_sixth' );
function organic_one_sixth_last( $atts, $content = null ) {
return '<div class="organic-column one-sixth last">' . do_shortcode( $content ) . '</div><div class="clearboth"></div>';
}
add_shortcode( 'one_sixth_last', 'organic_one_sixth_last' );
function organic_five_sixth( $atts, $content = null ) {
return '<div class="organic-column five-sixth">' . do_shortcode( $content ) . '</div>';
}
add_shortcode( 'five_sixth', 'organic_five_sixth' );
function organic_five_sixth_last( $atts, $content = null ) {
return '<div class="organic-column five-sixth last">' . do_shortcode( $content ) . '</div><div class="clearboth"></div>';
}
add_shortcode( 'five_sixth_last', 'organic_five_sixth_last' );
/*
-------------------------------------------------------------------------------------------------------
Empty paragraph, line break and content formatting fixes.
-------------------------------------------------------------------------------------------------------
*/
if ( ! function_exists( 'organic_fix_shortcodes' ) ) {
function organic_fix_shortcodes( $content ) {
$array = array(
'<p>[' => '[',
']</p>' => ']',
']<br />' => ']',
);
$content = strtr( $content, $array );
return $content;
}
add_filter( 'the_content', 'organic_fix_shortcodes' );
}