Hide WordPress Posts and Media uploaded by other users

It is pretty cool how wordpress manages user and restrict access via defined roles but one of the critical part of the website are the images. Once you give access to your editors they will have capability to view and delete images even if they are not uploaded by them which will ruin the pages and posts that are using it. On some points you don’t want the site users, freelancers or even general public to access the images. Well then you came to the right page :)

This tutorial also covered the ability to hide the posts that are created by other users so that the current users cannot make any changes.

First you need to be able to access the editor by navigating to Appearance > Editor and find the theme’s functions.php

That’s great you have the required access ;)

Add the code below which will hide the posts and images uploaded by other users except for administrator on /wp-admin/edit.php and /wp-admin/upload.php

Easy isn’t it? Now we need to be able to hide the images when the user click the ‘Add Media’ button above the wordpress editor. Which is pretty much easy too by adding this code :

Works like charm! Special thanks to @timocouckuyt for providing that code on this forum post.

 

About Jeffrey

My name is Jeffrey Carandang a.k.a 'phpbits' and I'm a web developer. I love creating unique, clean, usable code for the web and other digital sources and my utmost priority is my customer’s satisfaction.

Increase reader engagement by using WP Author Box Lite for Free. Undecided? Read the plugin review first.

Comments

  1. Juan Pablo says

    This post is excellent. Thanks a lot! Really :-)

    I have a question. There is a situation in which the user can see the image, when he use directly URL like this:

    site.com/wp-content/uploads/2014/09/test.jpg

    Do you know if we can hook on that? Thanks for any tip.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">