-
-
Save ppprakhar/c3bd3840d60c1a6624026fb6c5a7dcc5 to your computer and use it in GitHub Desktop.
Image-Shortcake: Fix 'media_send_to_editor' for WP Insert Media
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function myTest() { | |
| // Save default function | |
| var defaultSend = wp.media.editor.send.attachment; | |
| // new send function | |
| wp.media.editor.send.attachment = function( props, attachment) { | |
| // If not image, return default function | |
| if ( 'image' !== attachment.type ) | |
| return defaultSend( props, attachment) | |
| var caption = attachment.caption, | |
| options, html; | |
| // If captions are disabled, clear the caption. | |
| if ( ! wp.media.view.settings.captions ) { | |
| delete attachment.caption; | |
| } | |
| props = wp.media.string.props( props, attachment ); | |
| options = { | |
| id: attachment.id, | |
| post_content: attachment.description, | |
| post_excerpt: caption, | |
| linkto: props.link | |
| }; | |
| if ( props.linkUrl ) { | |
| options.url = props.linkUrl; | |
| } | |
| html = wp.media.string.image( props ); | |
| // Add linkTo | |
| options.linkto = props.link; | |
| // Remove URL if Link not Custom | |
| if ( 'custom' !== options.linkto && options.url ) { | |
| delete options.url; | |
| } | |
| _.each( | |
| { | |
| align: 'align', | |
| size: 'image-size', | |
| alt: 'image_alt' | |
| }, function( option, prop ) { | |
| if ( props[ prop ] ) | |
| options[ option ] = props[ prop ]; | |
| } | |
| ); | |
| return wp.media.post( 'send-attachment-to-editor', { | |
| nonce: wp.media.view.settings.nonce.sendToEditor, | |
| attachment: options, | |
| html: html, | |
| post_id: wp.media.view.settings.post.id | |
| }); | |
| }; | |
| }; | |
| jQuery(document).ready(function(){ | |
| myTest(); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment