暫無描述

duplicate-post-jetpack.php 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. * JetPack compatibility functions.
  4. *
  5. * @package Duplicate Post
  6. * @since 3.2
  7. */
  8. add_action( 'admin_init', 'duplicate_post_jetpack_init' );
  9. /**
  10. * Add handlers for JetPack compatibility.
  11. */
  12. function duplicate_post_jetpack_init() {
  13. add_filter( 'duplicate_post_excludelist_filter', 'duplicate_post_jetpack_add_to_excludelist', 10, 1 );
  14. if ( class_exists( 'WPCom_Markdown' ) ) {
  15. add_action( 'duplicate_post_pre_copy', 'duplicate_post_jetpack_disable_markdown', 10 );
  16. add_action( 'duplicate_post_post_copy', 'duplicate_post_jetpack_enable_markdown', 10 );
  17. }
  18. }
  19. /**
  20. * Add some JetPack custom field wildcards to be filtered out when cloning.
  21. *
  22. * @param array $meta_excludelist The array containing the blacklist of custom fields.
  23. * @return array
  24. */
  25. function duplicate_post_jetpack_add_to_excludelist( $meta_excludelist ) {
  26. $meta_excludelist[] = '_wpas*'; // Jetpack Publicize.
  27. $meta_excludelist[] = '_publicize*'; // Jetpack Publicize.
  28. $meta_excludelist[] = '_jetpack*'; // Jetpack Subscriptions etc.
  29. return $meta_excludelist;
  30. }
  31. /**
  32. * Disable Markdown.
  33. *
  34. * To be called before copy.
  35. */
  36. function duplicate_post_jetpack_disable_markdown() {
  37. WPCom_Markdown::get_instance()->unload_markdown_for_posts();
  38. }
  39. /**
  40. * Enaable Markdown.
  41. *
  42. * To be called after copy.
  43. */
  44. function duplicate_post_jetpack_enable_markdown() {
  45. WPCom_Markdown::get_instance()->load_markdown_for_posts();
  46. }