table.php
2.63 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
<?php
su_add_shortcode(
array(
'id' => 'table',
'callback' => 'su_shortcode_table',
'type' => 'wrap',
'name' => __( 'Table', 'shortcodes-ultimate' ),
'desc' => __( 'Styled table', 'shortcodes-ultimate' ),
'group' => 'content',
'image' => su_get_plugin_url() . 'admin/images/shortcodes/table.svg',
'icon' => 'table',
'atts' => array(
'responsive' => array(
'type' => 'bool',
'default' => 'no',
'name' => __( 'Responsive', 'shortcodes-ultimate' ),
'desc' => __( 'Add horizontal scrollbar if table width larger than page width', 'shortcodes-ultimate' ),
),
'alternate' => array(
'type' => 'bool',
'default' => 'yes',
'name' => __( 'Alternate row color', 'shortcodes-ultimate' ),
'desc' => __( 'Enable to use alternative background color for even rows', 'shortcodes-ultimate' ),
),
'fixed' => array(
'type' => 'bool',
'default' => 'no',
'name' => __( 'Fixed layout', 'shortcodes-ultimate' ),
'desc' => __( 'Fixed width table cells', 'shortcodes-ultimate' ),
),
'class' => array(
'type' => 'extra_css_class',
'name' => __( 'Extra CSS class', 'shortcodes-ultimate' ),
'desc' => __( 'Additional CSS class name(s) separated by space(s)', 'shortcodes-ultimate' ),
'default' => '',
),
),
'content' => __( "<table>\n<tr>\n\t<td>Table</td>\n\t<td>Table</td>\n</tr>\n<tr>\n\t<td>Table</td>\n\t<td>Table</td>\n</tr>\n</table>", 'shortcodes-ultimate' ),
)
);
function su_shortcode_table( $atts = null, $content = null ) {
$atts = shortcode_atts(
array(
'url' => '', // deprecated since 5.3.0
'responsive' => 'no',
'alternate' => 'yes',
'fixed' => 'no',
'class' => '',
),
$atts,
'table'
);
if ( $atts['url'] && ! su_is_unsafe_features_enabled() ) {
return su_error_message(
'Table',
sprintf(
'%s.<br><a href="https://getshortcodes.com/docs/unsafe-features/" target="_blank">%s</a>',
// translators: do not translate the <b>url</b> part, the <b>Unsafe features</b> must be translated
__( 'The <b>url</b> attribute cannot be used while <b>Unsafe features</b> option is turned off', 'shortcodes-ultimate' ),
__( 'Learn more', 'shortcodes-ultimate' )
)
);
}
foreach ( array( 'responsive', 'alternate', 'fixed' ) as $feature ) {
if ( 'yes' === $atts[ $feature ] ) {
$atts['class'] .= ' su-table-' . $feature;
}
}
su_query_asset( 'css', 'su-shortcodes' );
$table = $atts['url']
? su_parse_csv( $atts['url'] )
: do_shortcode( $content );
return '<div class="su-table' . su_get_css_class( $atts ) . '">' . $table . '</div>';
}