May it’s a silly question but i can not solve this, So i need some help.
I have made a fully custom profile page for my site, which works fine in backend,
Now when i just call the function from frontend page everything works fine but can not start mediauploader

Here is my js code

$('document') .ready( function(){
    /*snippet for media uploader */
    var mediaUploader;
    $('#upload-button').click(function(e) {
        e.preventDefault();
        if (mediaUploader) {
            mediaUploader.open();
            return;
        }
        mediaUploader = wp.media.frames.file_frame = wp.media({
            title: 'Choose Image',
            button: {
                text: 'Choose Image'
            }, multiple: false });
        mediaUploader.on('select', function() {
            var attachment = mediaUploader.state().get('selection').first().toJSON();
            console.log( attachment.url);
            $('#image_url').val(attachment.url);
            $("#propic").attr('src', $('#image_url').val());
        });
        mediaUploader.open();
    });
    /*snippet for media uploader */

and the php code is

<?php
      global $wpdb;
wp_enqueue_media();
?>
<span class="profile-picture text-center">
          <img class="img-responsive" id="propic" src="<?php echo (get_the_author_meta('image_url', $user->ID)) ? esc_attr(get_the_author_meta('image_url', $user->ID)) : get_template_directory_uri() . '/img/avatar.png' ?>"
               style="max-width: 200px; max-height: 200px; margin: auto;">
        </span>

and when i click to upload a photo the error comes

Uncaught TypeError: Cannot read property 'frames' of undefined

if it was post then maybe just

 wp_enqueue_media( array('post'=> $post->ID) ); 

will solved this problem , but what can i do for the profile picture ??

Please help, thanks.

Read more here: How to upload profile picture from frontend of wordpress site


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: