• I use this little javascript snippets to add a button to the media manager in WP 3.6.1

    This button copies the link of the first selected media (the blue one) into Page Links To input text.

    jQuery(document).ready(function() {
        if(wp.media && wp.media.controller && wp.media.view)
        {
            var wpMediaFramePost = wp.media.view.MediaFrame.Post;
            wp.media.view.MediaFrame.Post = wpMediaFramePost.extend(
            {
                mainInsertToolbar: function(view)
                {
                    'use strict';
    
                    wpMediaFramePost.prototype.mainInsertToolbar.call(this, view);
    
                    var controller = this;
    
                    this.selectionStatusToolbar(view);
    
                    view.set('pageLinksTo', {
                        style: 'primary',
                        priority: 80,
                        text: 'Link page to the media',
                        requires: { selection: true },
    
                        click: function()
                        {
                            var state = controller.state();
                            var selection = state.get('selection')._byId;
                            var imagePath;
    
                            _.each(selection, function(item)
                            {
                                imagePath = item.attributes.sizes.full.url;
                                return;
                            });
    
                            if(imagePath && jQuery('#cws-links-to-choose-custom').exists())
                            {
                                controller.close();
    
                                jQuery('#cws-links-to-choose-custom').click();
                                jQuery('#cws-links-to').val(imagePath);
                                jQuery('#cws-links-to').focus();
                            }
                        }
                    });
                }
            });
        }
    }

    This snippet was inspired by the following post https://wordpress.stackexchange.com/questions/78881/wordpress-3-5-media-manager-add-a-button

    https://www.ads-software.com/plugins/page-links-to/

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Page links to media JS snippet’ is closed to new replies.