-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
File Block: Add support for embedding PDFs #24233
Changes from all commits
d5b8aa7
81f7a1c
0d8b39d
31250fb
bb68306
68d53c2
7b9aa9d
9da53d0
1dec5e8
7734a3c
99fa001
7001171
2b239f3
5739c88
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,10 +33,17 @@ | |
"type": "string", | ||
"source": "html", | ||
"selector": "a[download]" | ||
}, | ||
"showInlineEmbed": { | ||
"type": "boolean" | ||
}, | ||
"embedHeight": { | ||
"type": "number" | ||
} | ||
}, | ||
"supports": { | ||
"anchor": true, | ||
"align": true | ||
} | ||
}, | ||
"script": "utils.js" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is doing? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems it's a way to tell pack to generate a separate script? Why not just a package because that's our way of doing this in Gutenberg? Alternatively, if we implement the |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
/** | ||
* Server-side rendering of the `core/file` block. | ||
* | ||
* @package WordPress | ||
*/ | ||
|
||
/** | ||
* When the `core/file` block is rendering, check if we need to enqueue the `'wp-block-library-file` script. | ||
* | ||
* @param array $attributes The block attributes. | ||
* @param array $content The block content. | ||
* | ||
* @return string Returns the block content. | ||
*/ | ||
function render_block_core_file( $attributes, $content ) { | ||
if ( ! empty( $attributes['showInlineEmbed'] ) ) { | ||
// Check if it's already enqueued, so we don't add the inline script multiple times. | ||
if ( ! in_array( 'wp-block-library-file', wp_scripts()->queue, true ) ) { | ||
wp_enqueue_script( 'wp-block-library-file', plugins_url( '/file.js', __FILE__ ) ); | ||
wp_add_inline_script( 'wp-block-library-file', 'hidePdfEmbedsOnUnsupportedBrowsers();' ); | ||
} | ||
} | ||
|
||
return $content; | ||
} | ||
|
||
/** | ||
* Registers the `core/file` block on server. | ||
*/ | ||
function register_block_core_file() { | ||
register_block_type_from_metadata( | ||
__DIR__ . '/file', | ||
array( | ||
'render_callback' => 'render_block_core_file', | ||
) | ||
); | ||
} | ||
add_action( 'init', 'register_block_core_file' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we call it "embed" or "preview"? I mean it's not that important but we could the same for like images, text .... any file that can be previewed. Something like "quick view" in MacOS
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
showPreview
ordisplayPreview
perhaps?