• Resolved Alak732

    (@alak732)


    Or using the WordPress 3.5 Media Uploader in wordpress 3.9.1.

    Hi everyone,

    I wrote my own plugin with a custom post type and at some point I was uploading picture with the wordpress media uploader.

    Everything was working fine, but since yesterday, I upgrade to the new ‘smith’ version (WordPress 3.9.1) and … now that didn’t work anymore.

    I’m calling the function wp.media via Jquery on a ‘click’ event, but now my browsers say that :
    -> for Firefox 30.0 : ‘wp.media is not a function’
    -> for Chrome 35.0.1916.153 m : ‘undefined is not a function ‘ – same line pointed in my js file so I guess that “undefined” means “wp.media”
    -> for IE : ‘SCRIPT438: The object didn’t handle the property or method ? media ?’

    Again, that script was working in WordPress 3.8.1 … so I guess something change.

    Here is how I call it :

    <div class="meta-box-item-content">
        <a href="#" class="button pelliculeUp">Add some pictures </a>
        <input class="containerOfUploadedUrls" name="picturesUrls" >
    </div>

    And here is the script :

    $('.pelliculeUp').click(function(event)
    {
    	event.preventDefault();
    
    	var uploader = wp.media(
    	{
    		title : 'Add images',
    		button : {
    			text : 'Pick files',
    		},
    		multiple : true
    	})
    
    	.on('select', function()
    	{
    		var selection = uploader.state().get('selection');
    
    		var attachements = [];
    		selection.map(function(attachement)
    		{
    			attachement = attachement.toJSON();
    
    			attachements.push([attachement.id, attachement.url, attachement.caption]);
    		})
    
    		$('.containerOfUploadedUrls').val(attachements);
    
    	})
    	.open();
    
    });

    So, did someone now what can I do for fixing my code ?
    His there a new way to use wordpress media uploader in 3.9.1 ?

Viewing 1 replies (of 1 total)
  • Thread Starter Alak732

    (@alak732)

    Ok, finally I made it working again …

    I create a new plugin with one admin page to understand what was going wrong. Firebug whas saying ‘wp.media is not a function’ again. And I just add an ‘wp_enqueue_media();’ in my admin page function (you know, the “$function” parameter of “add menu page”) and … Voila. wp.media was defined again, and my button work ??

    So, I just add ‘wp_enqueue_media();’ at the begining of my uploading pics metabox function – yes, I’ve created a custom post type, and I’m calling some metabox on my custom post type editing page –

    Now, my button is working again, and I can upload media via the WordPress Media Uploader.

    The strange things is that my code was working on previous version, so maybe there is some change with ‘smith’ on that ..

    Hope that will be usefull for someone

Viewing 1 replies (of 1 total)
  • The topic ‘wp.media in wordpress 3.9.1’ is closed to new replies.