| 1 |
<?php |
| 2 |
/** |
| 3 |
* PHP file to use when rendering the block type on the server to show on the front end. |
| 4 |
* |
| 5 |
* The following variables are exposed to the file: |
| 6 |
* $attributes (array): The block attributes. |
| 7 |
* $content (string): The block default content. |
| 8 |
* $block (WP_Block): The block instance. |
| 9 |
* |
| 10 |
* @see https://github.com/WordPress/gutenberg/blob/trunk/docs/reference-guides/block-api/block-metadata.md#render |
| 11 |
*/ |
| 12 |
|
| 13 |
// Generate unique id for aria-controls. |
| 14 |
$unique_id = wp_unique_id( 'pdf-' ); |
| 15 |
|
| 16 |
$p = new WP_HTML_Tag_Processor( $content ); |
| 17 |
|
| 18 |
$options = get_option( 'pdf_embed' ); |
| 19 |
|
| 20 |
if ( $p->next_tag( |
| 21 |
array( |
| 22 |
'tag_name' => 'DIV', |
| 23 |
'class_name' => 'wp-block-tropicalista-pdfembed', |
| 24 |
) |
| 25 |
) ) { |
| 26 |
$p->set_attribute( 'id', $unique_id ); |
| 27 |
$p->set_attribute( 'data-client-id', $options['apiKey'] ); |
| 28 |
if ( ! empty( $p->get_attribute( 'data-mediaurl' ) ) ) { |
| 29 |
$p->set_attribute( 'data-media-url', $p->get_attribute( 'data-mediaurl' ) ); |
| 30 |
} |
| 31 |
if ( ! empty( $p->get_attribute( 'data-filename' ) ) ) { |
| 32 |
$p->set_attribute( 'data-file-name', $p->get_attribute( 'data-filename' ) ); |
| 33 |
} |
| 34 |
if ( empty( $p->get_attribute( 'data-config' ) ) ) { |
| 35 |
$p->set_attribute( 'data-config', wp_json_encode( $options ) ); |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
echo $p->get_updated_html(); |
| 40 |
|