-
Notifications
You must be signed in to change notification settings - Fork 7
Overload wp.media.editor.send
to send linkto and linkUrl fields
#70
base: master
Are you sure you want to change the base?
Conversation
Based off code by @vralle at https://gist.github.com/vralle/b0db1083f1c8e392527e I wanted a way to tap into the `wp.media.editor.send.attachment` functionality which didn't completely break the connection to core's functionality. This is the best I could come up with for now - temporarily redefining the ajax method so that the post data can be modified before posting to admin-ajax. The benefits of this approach over just copy-pasting the `wp.media.editor.send.attachment` functionality from core are that: * we're not preventing other plugins from also tapping into this method * we don't cut ourselves off from core's functionality, so that if this method is updated in core, we still get to use the core function; just temporarily interrupted at the stage of posting.
In the media editor, `linkto="post"` is the value for "Link to Attachment Page". In the shortcode UI, we call that value `linkto="attachment"`. This converts the values that might be returned by media-send-to-editor to the values we want to use in the shortcode. Props @vralle.
Each line in an array declaration must end in a comma.
@vralle I'd appreciate thoughts on this approach. It basically does the same thing as the gist you shared in #65, but without the copy-pasted code from core. I think something along these lines is necessary to allow developers to add their own customization into the method - in my theme, I have another method elsewhere already overwriting Overloading a basic method like |
The perfect solution ! |
And other way: if( !empty( $shortcode_attrs['url'] ) ) {
if ( $shortcode_attrs['url'] == get_attachment_link( $attachment_id ) ) {
$shortcode_attrs['linkto'] = 'post';
unset( $shortcode_attrs['url'] );
} elseif ( $shortcode_attrs['url'] == wp_get_attachment_url( $attachment_id ) ) {
$shortcode_attrs['linkto'] = 'file';
unset( $shortcode_attrs['url'] );
} else {
$shortcode_attrs['linkto'] = 'custom';
}
}
$shortcode_attrs = array_filter($shortcode_attrs); This fragment of 'filter_media_send_to_editor' |
When I check this out, spaces in caption and alt fields are encoded to On master:
On this branch:
|
Based off code by @vralle at https://gist.github.com/vralle/b0db1083f1c8e392527e
I wanted a way to tap into the
wp.media.editor.send.attachment
functionality which didn't completely break the connection to core's functionality. This is the best I could come up with for now - temporarily redefining the ajax method so that the post data can be modified before posting to admin-ajax.The benefits of this approach over just copy-pasting the
wp.media.editor.send.attachment
functionality from core are that:See #65