Sin descripción

duplicate-post-gutenberg.php 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. /**
  3. * Gutenberg (Block editor)/Classic Editor compatibility functions
  4. *
  5. * @package Duplicate Post
  6. * @since 4.0
  7. */
  8. add_filter( 'duplicate_post_get_clone_post_link', 'duplicate_post_classic_editor_clone_link', 10, 4 );
  9. /**
  10. * Edits the clone link URL to enforce Classic Editor legacy support.
  11. *
  12. * @see duplicate_post_get_clone_post_link()
  13. *
  14. * @param string $url The duplicate post link URL.
  15. * @param int $post_id The original post ID.
  16. * @param string $context The context in which the URL is used.
  17. * @param bool $draft Whether the link is "New Draft" or "Clone".
  18. *
  19. * @return string
  20. */
  21. function duplicate_post_classic_editor_clone_link( $url, $post_id, $context, $draft ) {
  22. $post = get_post( $post_id );
  23. if ( ! $post ) {
  24. return $url;
  25. }
  26. if ( isset( $_GET['classic-editor'] ) // phpcs:ignore WordPress.Security.NonceVerification
  27. || ( $draft && function_exists( 'gutenberg_post_has_blocks' ) && ! gutenberg_post_has_blocks( $post ) )
  28. || ( $draft && function_exists( 'has_blocks' ) && ! has_blocks( $post ) ) ) {
  29. if ( 'display' === $context ) {
  30. $url .= '&amp;classic-editor';
  31. } else {
  32. $url .= '&classic-editor';
  33. }
  34. }
  35. return $url;
  36. }