class-wp-customize-upload-control.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * Customize API: WP_Customize_Upload_Control class
  4. *
  5. * @package WordPress
  6. * @subpackage Customize
  7. * @since 4.4.0
  8. */
  9. /**
  10. * Customize Upload Control Class.
  11. *
  12. * @since 3.4.0
  13. *
  14. * @see WP_Customize_Media_Control
  15. */
  16. class WP_Customize_Upload_Control extends WP_Customize_Media_Control {
  17. /**
  18. * Control type.
  19. *
  20. * @since 3.4.0
  21. * @var string
  22. */
  23. public $type = 'upload';
  24. /**
  25. * Media control mime type.
  26. *
  27. * @since 4.1.0
  28. * @var string
  29. */
  30. public $mime_type = '';
  31. /**
  32. * Button labels.
  33. *
  34. * @since 4.1.0
  35. * @var array
  36. */
  37. public $button_labels = array();
  38. public $removed = ''; // Unused.
  39. public $context; // Unused.
  40. public $extensions = array(); // Unused.
  41. /**
  42. * Refresh the parameters passed to the JavaScript via JSON.
  43. *
  44. * @since 3.4.0
  45. *
  46. * @uses WP_Customize_Media_Control::to_json()
  47. */
  48. public function to_json() {
  49. parent::to_json();
  50. $value = $this->value();
  51. if ( $value ) {
  52. // Get the attachment model for the existing file.
  53. $attachment_id = attachment_url_to_postid( $value );
  54. if ( $attachment_id ) {
  55. $this->json['attachment'] = wp_prepare_attachment_for_js( $attachment_id );
  56. }
  57. }
  58. }
  59. }