Daman Daman - 1 year ago 51
PHP Question

Make uploaded file public in wordpress media library

I've kind of social networking wordpress site and users use wordpress's native upload script to upload images.

Is there anyway i can make some images accessible to all users. Right now they only see images uploaded by them.

Answer Source

Answering to my own question: This worked

add_filter( 'posts_where', 'devplus_wpquery_where' );
function devplus_wpquery_where( $where ){
global $current_user;

if( is_user_logged_in() ){
     // logged in user, but are we viewing the library?
     if( isset( $_POST['action'] ) && ( $_POST['action'] == 'query-attachments' ) ){
        // here you can add some extra logic if you'd want to.
        $where .= 'OR post_parent="6968"';
                  //OR ID='3783' // OR post_author= "34"
    }
}

return $where;
}

"Where" can be edited as per the need.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download