Skip to content

Commit 06874a6

Browse files
committed
Use shortcode_atts with [code_snippet] shortcode
1 parent e8b72d6 commit 06874a6

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

php/class-shortcode.php

+14-4
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,25 @@ function enqueue_prism( $posts ) {
4646

4747
function render_shortcode( $atts ) {
4848

49-
if ( ! isset( $atts['id'] ) || ! intval( $atts['id'] ) ) {
49+
$atts = shortcode_atts(
50+
array(
51+
'id' => 0,
52+
'network' => false,
53+
),
54+
$atts, 'code_snippet'
55+
);
56+
57+
if ( ! $id = intval( $atts['id'] ) ) {
5058
return '';
5159
}
5260

53-
$id = intval( $atts['id'] );
54-
$network = isset( $atts['network'] ) && $atts['network'] ? true : false;
55-
61+
$network = $atts['network'] ? true : false;
5662
$snippet = get_snippet( $id, $network );
5763

64+
if ( ! trim( $snippet->code ) ) {
65+
return '';
66+
}
67+
5868
return '<pre><code class="language-php">' . esc_html( $snippet->code ) . '</code></pre>';
5969
}
6070

0 commit comments

Comments
 (0)