|
14 | 14 | $headerImagePreview = $( '#activitypub-header-image-preview' ), |
15 | 15 | $hiddenDataField = $( '#activitypub_header_image' ), |
16 | 16 | $removeButton = $( '#activitypub-remove-header-image' ), |
17 | | - frame; |
| 17 | + frame, |
| 18 | + ImageCropperNoCustomizer; |
| 19 | + |
| 20 | + /** |
| 21 | + * We register our own handler because the Core one invokes the Customizer, which fails the request unnecessarily |
| 22 | + * for users who don't have the 'customize' capability. |
| 23 | + * See https://github.com/Automattic/wordpress-activitypub/issues/846 |
| 24 | + */ |
| 25 | + ImageCropperNoCustomizer = wp.media.controller.CustomizeImageCropper.extend( { |
| 26 | + doCrop: function( attachment ) { |
| 27 | + var cropDetails = attachment.get( 'cropDetails' ), |
| 28 | + control = this.get( 'control' ), |
| 29 | + ratio = cropDetails.width / cropDetails.height; |
| 30 | + |
| 31 | + // Use crop measurements when flexible in both directions. |
| 32 | + if ( control.params.flex_width && control.params.flex_height ) { |
| 33 | + cropDetails.dst_width = cropDetails.width; |
| 34 | + cropDetails.dst_height = cropDetails.height; |
| 35 | + |
| 36 | + // Constrain flexible side based on image ratio and size of the fixed side. |
| 37 | + } else { |
| 38 | + cropDetails.dst_width = control.params.flex_width ? control.params.height * ratio : control.params.width; |
| 39 | + cropDetails.dst_height = control.params.flex_height ? control.params.width / ratio : control.params.height; |
| 40 | + } |
| 41 | + |
| 42 | + return wp.ajax.post( 'crop-image', { |
| 43 | + // where wp_customize: 'on' would be in Core, for no good reason I understand. |
| 44 | + nonce: attachment.get( 'nonces' ).edit, |
| 45 | + id: attachment.get( 'id' ), |
| 46 | + context: control.id, |
| 47 | + cropDetails: cropDetails |
| 48 | + } ); |
| 49 | + } |
| 50 | + } ); |
| 51 | + |
| 52 | + |
18 | 53 |
|
19 | 54 | /** |
20 | 55 | * Calculate image selection options based on the attachment dimensions. |
|
73 | 108 | */ |
74 | 109 | $chooseButton.on( 'click', function () { |
75 | 110 | var $el = $( this ); |
| 111 | + var userId = $el.data( 'userId' ); |
| 112 | + var mediaQuery = { type: 'image' }; |
| 113 | + if ( userId ) { |
| 114 | + mediaQuery.author = userId; |
| 115 | + } |
76 | 116 |
|
77 | 117 | // Create the media frame. |
78 | 118 | frame = wp.media( { |
|
86 | 126 | states: [ |
87 | 127 | new wp.media.controller.Library( { |
88 | 128 | title: $el.data( 'choose-text' ), |
89 | | - library: wp.media.query( { type: 'image' } ), |
| 129 | + library: wp.media.query( mediaQuery ), |
90 | 130 | date: false, |
91 | 131 | suggestedWidth: $el.data( 'size' ), |
92 | 132 | suggestedHeight: $el.data( 'size' ), |
93 | 133 | } ), |
94 | | - new wp.media.controller.CustomizeImageCropper( { |
| 134 | + new ImageCropperNoCustomizer( { |
95 | 135 | control: { |
96 | 136 | params: { |
97 | 137 | width: $el.data( 'size' ), |
|
0 commit comments