• My site offers a front end form for creating draft content, it accepts a title, an uploaded image, and then a tiny-mce editor for the content (yes I know the issues of anyone can post, this is for a private site)

    I’m a bit baffled as if I am logged in, and I use the form, then all media URLs (YouTube, twitter, eyc) that normally autoembed in the editor do so on my forms. Perfectly.

    If I am not logged in, nothing gets embedded. My pages are properly enqueuing mce-view:

    if (! is_admin() ) wp_enqueue_media();
    				
    // Autoembed functionality in rich text editor
    // needs dependency on tiny_mce
    // h/t https://wordpress.stackexchange.com/a/287623
       		
    wp_enqueue_script( 'mce-view', '', array('tiny_mce') );	

    In viewing the load sequence in Chrome inspector, when logged in and the autoembed works, there is a call to admin_ajax.php — this of course will fail when not logged in, and this is my best guess as to why it’s not working.

    I know from research that to enable ajax calls that seem to be needed I need to have an action set up like wp_ajax_nopriv_{action} (I in fact do this successfully for the dropzone.js integration since I wrote the functions that are called back by ajax).

    But I have no idea what callbacks are needed to be granted wp_ajax_nopriv_{action} these are not my functions but from internal WordPress code for doing oembeds.

    So (a) is it even possible to enable auto embeds of media on a front end editor w/o a login and/or (b) how to I grant access to admin-ajax.php if there is no login?

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    I cannot claim to fully understand how embeds work, but AFAIK Ajax doesn’t play a part. Post content should be filtered through WP_Embed::autoembed(). It replaces the URL in content with the appropriate iframe code for the embed provider. Thus the remote request comes from the browser and Ajax does not play into it.

    Are you sure the embed URL remains intact when non-privledged posts are saved? Such users are typically restricted in what they can place in content. If not that, apparently the autoembed filter is not getting added for post content output with non-privledged users. You might try explicitly adding the method to “the_content” filter. For example:
    add_filter( 'the_content', array( $GLOBALS['wp_embed'], 'autoembed' ));
    No real harm done if it turns out to be redundant.

    Thread Starter cogdog

    (@cogdog)

    Thanks- but I am not writing about what happens when a post is saved (my theme is using wp_insert() to make a post), this works as expected. Naked URLs are in the saved post, but renders as embeds when published.

    This was authored not logged in via https://splot.ca/boom/dropper/

    I hoping to use the in-editor embeds that happen natively when logged in and using the visual editor– This must be done via ajax since it happens before any http transaction takes place. As far as I can decipher, it is done via mce-view.js. I’d like to know how to make the in-editor embed previews work for non logged in users (it works when logged in)

    • This reply was modified 5 years, 5 months ago by cogdog.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘No Media Embeds for non-loggedin users on front-end form’ is closed to new replies.