PluginProbe
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts / 2.7.1
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts v2.7.1
2.7.7 2.7.6 2.7.5 2.7.4 trunk 1.3 2.0.4 2.0.6 2.1.91 2.2.4 2.2.7 2.2.9 2.3.1 2.3.10 2.4.10 2.4.2 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.6.0 2.6.1 2.7.0 All 28 releases
insert-php / admin / assets / gutenberg / build / render.php

render.php in Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts 2.7.1, at admin/assets/gutenberg/build/render.php

74 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Server-side rendering for the Woody Snippets block.
4 *
5 * @var array<string, mixed> $attributes Block attributes.
6 * @var string $content Block default content.
7 * @var WP_Block $block Block instance.
8 */
9
10 if ( ! defined( 'ABSPATH' ) ) {
11 exit;
12 }
13
14 // Get the snippet ID from attributes
15 $snippet_id = isset( $attributes['id'] ) ? $attributes['id'] : null;
16
17 if ( ! is_numeric( $snippet_id ) ) {
18 return '';
19 }
20
21 // Get snippets data
22 $snippets_data = WINP_Gutenberg_Snippet::get_prepared_snippets_data();
23 $current_snippet = isset( $snippets_data[ $snippet_id ] ) ? $snippets_data[ $snippet_id ] : null;
24
25 if ( empty( $current_snippet ) ) {
26 return '';
27 }
28
29 $snippet_attrs = $current_snippet['tags'];
30 $type = $current_snippet['type'];
31
32 // Build shortcode attributes
33 $shortcode_attributes = apply_filters( 'wbcr/inp/gutenberg/shortcode_attributes', ' id="' . $snippet_id . '" ', $snippet_id );
34
35 $attr_values = isset( $attributes['attrValues'] ) ? $attributes['attrValues'] : null;
36 if ( ! empty( $attr_values ) ) {
37 if ( empty( $snippet_attrs ) ) {
38 return '';
39 }
40
41 if ( count( $snippet_attrs ) !== count( $attr_values ) ) {
42 return '';
43 }
44
45 foreach ( $attr_values as $key => $value ) {
46 $snippet_attr = $snippet_attrs[ $key ];
47 $value = esc_attr( $value );
48
49 if ( empty( $value ) ) {
50 continue;
51 }
52 $shortcode_attributes .= " {$snippet_attr}=\"{$value}\"";
53 }
54
55 $shortcode_attributes = trim( $shortcode_attributes );
56 }
57
58 // Build shortcode name
59 $shortcode_name = apply_filters(
60 'wbcr/inp/gutenberg/shortcode_name',
61 sprintf( 'wbcr%s_snippet', ( $type === WINP_SNIPPET_TYPE_UNIVERSAL ? '' : '_' . $type ) ),
62 $snippet_id
63 );
64
65 // Build the shortcode
66 $shortcode = "[{$shortcode_name} {$shortcode_attributes}]";
67
68 if ( ! empty( $content ) ) {
69 $shortcode .= "{$content}[/{$shortcode_name}]";
70 }
71
72 // Render the shortcode
73 echo do_shortcode( $shortcode );
74