class.jetpack-sync-module-attachments.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. class Jetpack_Sync_Module_Attachments extends Jetpack_Sync_Module {
  3. function name() {
  4. return 'attachments';
  5. }
  6. public function init_listeners( $callable ) {
  7. add_action( 'edit_attachment', array( $this, 'send_attachment_info' ) );
  8. // Once we don't have to support 4.3 we can start using add_action( 'attachment_updated', $handler, 10, 3 ); instead
  9. add_action( 'add_attachment', array( $this, 'send_attachment_info' ) );
  10. add_action( 'jetpack_sync_save_update_attachment', $callable, 10, 2 );
  11. add_action( 'jetpack_sync_save_add_attachment', $callable, 10, 2 );
  12. }
  13. function send_attachment_info( $attachment_id ) {
  14. $attachment = get_post( $attachment_id );
  15. if ( 'add_attachment' === current_filter() ) {
  16. /**
  17. * Fires when the client needs to sync an new attachment
  18. *
  19. * @since 4.2.0
  20. *
  21. * @param int The attachment ID
  22. * @param object The attachment
  23. */
  24. do_action( 'jetpack_sync_save_add_attachment', $attachment_id, $attachment );
  25. } else {
  26. /**
  27. * Fires when the client needs to sync an updated attachment
  28. *
  29. * @since 4.9.0
  30. *
  31. * @param int The attachment ID
  32. * @param object The attachment
  33. *
  34. * Previously this action was synced using jetpack_sync_save_add_attachment action.
  35. */
  36. do_action( 'jetpack_sync_save_update_attachment', $attachment_id, $attachment );
  37. }
  38. }
  39. }