Geen omschrijving

post-content.php 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * Server-side rendering of the `core/post-content` block.
  4. *
  5. * @package WordPress
  6. */
  7. /**
  8. * Renders the `core/post-content` block on the server.
  9. *
  10. * @param array $attributes Block attributes.
  11. * @param string $content Block default content.
  12. * @param WP_Block $block Block instance.
  13. * @return string Returns the filtered post content of the current post.
  14. */
  15. function render_block_core_post_content( $attributes, $content, $block ) {
  16. static $seen_ids = array();
  17. if ( ! isset( $block->context['postId'] ) ) {
  18. return '';
  19. }
  20. $post_id = $block->context['postId'];
  21. if ( isset( $seen_ids[ $post_id ] ) ) {
  22. // WP_DEBUG_DISPLAY must only be honored when WP_DEBUG. This precedent
  23. // is set in `wp_debug_mode()`.
  24. $is_debug = defined( 'WP_DEBUG' ) && WP_DEBUG &&
  25. defined( 'WP_DEBUG_DISPLAY' ) && WP_DEBUG_DISPLAY;
  26. return $is_debug ?
  27. // translators: Visible only in the front end, this warning takes the place of a faulty block.
  28. __( '[block rendering halted]' ) :
  29. '';
  30. }
  31. $seen_ids[ $post_id ] = true;
  32. if ( ! in_the_loop() && have_posts() ) {
  33. the_post();
  34. }
  35. $content = get_the_content( null, false, $post_id );
  36. /** This filter is documented in wp-includes/post-template.php */
  37. $content = apply_filters( 'the_content', str_replace( ']]>', ']]&gt;', $content ) );
  38. unset( $seen_ids[ $post_id ] );
  39. if ( empty( $content ) ) {
  40. return '';
  41. }
  42. $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => 'entry-content' ) );
  43. return (
  44. '<div ' . $wrapper_attributes . '>' .
  45. $content .
  46. '</div>'
  47. );
  48. }
  49. /**
  50. * Registers the `core/post-content` block on the server.
  51. */
  52. function register_block_core_post_content() {
  53. register_block_type_from_metadata(
  54. __DIR__ . '/post-content',
  55. array(
  56. 'render_callback' => 'render_block_core_post_content',
  57. )
  58. );
  59. }
  60. add_action( 'init', 'register_block_core_post_content' );