Skip to:
Content
Pages
Categories
Search
Top
Bottom

[SOLVED] Only keymasters (admin) can upload images


  • moonoi
    Participant

    @moonoi

    After having battled with this problem for a long time, I finally found out, why only keymaster users could upload images to their replies with the new media manager.

    The problem is not bbPress’ fault, but rather due to a shortcoming in the WP_Editor.

    When a front end editor is inserted on a page using the wp_editor() function, and media buttons are enabled, the media buttons will be automatically set up to attach the images being uploaded to the current global post object.

    This is a problem, because the current global post on a forum topic page is the topic. So if the user replying to the topic (and trying to upload images) is not the topic starter, a permissions problem will arise.

    The user will then in fact be attempting to attach media to the topic, which is owned by someone else. This will result in an error, unless the user has the “edit_others_topics” permission set to true.

    So, what to do? Here’s my temporary solution, until this hopefully gets addressed in the future:

    Because the core function that takes the post id from the current global post can’t be hooked directly into, I decided to hook in before and after it, to first change the global post id to null, and then change it back afterwards, so any logic that follows the WP_editor will not get disturbed.

    This will, however, cause the uploaded image to not be attached to any post. But it doesn’t have to be. The image will be inserted into the forum reply html, regardless of which post it is attached to in the DB.

    
    add_action('media_buttons', 'ml_pre_media_buttons', 1);
    add_action('media_buttons', 'ml_post_media_buttons', 20);
    function ml_pre_media_buttons($editor_id) {
        if (!$editor_id == 'bbp_reply_content')
            return;
    
        $GLOBALS['post_temp'] = $GLOBALS['post'];
        $GLOBALS['post'] = null;
    }
    function ml_post_media_buttons($editor_id) {
        if (!$editor_id == 'bbp_reply_content')
            return;
    
        $GLOBALS['post'] = $GLOBALS['post_temp'];
    }
    

    I created this issue on the WP support forums:
    http://wordpress.org/support/topic/front-end-editor-media-upload-would-like-ability-to-pass-post-id?replies=1#post-3895962

Viewing 3 replies - 1 through 3 (of 3 total)

  • rottnmutt
    Participant

    @rottnmutt

    What file do you put this in?

    Thanks for posting this. Whenever we tackle the job of adding “official” image uploading we’ll definitely encounter this issue, so this was helpful. I don’t think there is a ticket for at on trac at this point or I’d link to this 🙂


    rottnmutt
    Participant

    @rottnmutt

    I’d love to be able to use this fix. A little guidance on where to put this would be greatly appreciated.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.
Skip to toolbar