Using a WP Network site to Manage Images and Finding a Blank theme

I'm testing using a site on a network to serve up images to the rest of the network sites.
I'm doing this because we use a lot of the same images across the network and rather than having 20 different variations of media galleries and duplicating image uploads into each one, it would be easier just to run images from one site and use the 'Insert from URL' command when adding media to specific posts and pages across the network.

This looks like it could work out ok. One issue I want to solve is how to prevent the public from viewing the images site directly whilst still allowing for the images to be served across the network. If I set the privacy on the images site to anything other than open for public, then the images won't serve to the network.

One idea is to have a 'blank' theme installed on the 'images' site. this would mean any attempt to view things on there would result in a blank page. I'm assuming this will mean that the images themselves can still be viewable across the network.

To test this idea, I'm looking for help with sourcing a 'blank' theme. Not a blank canvas to build a theme, just something i can load into wordpress that when activated will serve up blank pages, but still have the admin area accessable for image management.

This could just be editing the page and post templates of a wp theme to be empty and perhaps that will do the job.

Can anyone offer some advice on this that can steer me in the right direction? thanks in advance.

Paul

  • member1

    answering my own post. but with a follow up question....

    I install Twenty Twelve theme.
    Deleted the contents of index.php, single.php and page.php files and that seems to have done the trick.

    Next question...
    How can I protect the wp-content/uploads..... folders from view?
    e.g. if someone copies the image url then tracks back through the folder structure, they will see links to all of the files in the uplaods folders. Can these be protected? and how?

    thanks again.

  • Michael Bissett

    Hey @member1, hope you're doing well today! :slight_smile:

    Instead of doing all of that, would something like this suit your needs better?

    https://wordpress.org/plugins/network-shared-media/

    Feel free to correct me here, but it seems like that plugin would be a far easier solution for what you're wanting to accomplish (plus, you wouldn't need to maintain those index files). :slight_smile:

    Let me know if I can be of further assistance here please!

    Kind Regards,
    Michael

    P.S. You may wish to read more about this plugin over here:

    https://premium.wpmudev.org/blog/how-to-share-media-across-wordpress-multisite/

  • member1

    thanks Michael.
    I already checked out the Network Shared Media plugin. I gave it a test and really like what it can do but it creates duplicate of the same image to the new site you are posting to. Not ideal, as we want to limit the number of files we need on the server.

    It does solve the problem of only having to physically add an image once, but if a solution can be used where we don't have to duplicate then that is better.

    At the moment, the Insert from URL option looks like the go.

  • Ash

    Hello @member1

    I hope you are well today.

    You can try the following code:

    add_action( 'init', 'create_index' );
    function create_index() {
        switch_to_blog(1);
        $path = wp_upload_dir();
        readDirs($path['basedir']);
        restore_current_blog();
    }
    
    function readDirs($main){
      $dirHandle = opendir($main);
      while($file = readdir($dirHandle)){
        if(is_dir($main . '/' . $file) && $file != '.' && $file != '..'){
           readDirs($main . '/' . $file);
           $myfile = fopen($main . '/' . $file . "/index.html", "w");
          $txt = " ";
          fwrite($myfile, $txt);
          fclose($myfile);
        }
      }
    }

    You can add those codes in mu-plugins. To use mu-plugins, go to /wp-content/ and find the folder with name 'mu-plugins'. If there is no folder in that name, then create a folder, name it 'mu-plugins', create a file inside that, give any name you like and paste the code in there. You don't need to activate that plugin. Mu-plugins means must use plugins, so it will be activated automatically always. If you use mu-plugins then add a php start tag at the beginning of the code.

    This code will create index.html in every folder and subfolders inside the uploads folder.

    You can run this code once just after uploading a new media file, or you can run always. Running always won't help because, it will just overwrite existing index.html file.

    Hope it helps :slight_smile: Please feel free to ask more question if you have.

    Cheers
    Ash

  • member1

    Thanks Ash.
    I'll give that a test.

    Can you confirm more about this....

    "You can run this code once just after uploading a new media file, or you can run always. Running always won't help because, it will just overwrite existing index.html file."

    Does this mean that the best option is to upload this file everytime an image is added and that leaving it in the mu-plugins folder shouldn't be done?

    thanks

  • Ash

    Hello @member1

    If you leave this fine in mu-plugins folder, it will run on every page refresh. There is no need to create and overwrite an existing index.html file, it just increases a little page speed.

    Rather, when you upload a file, just run the code once, and then comment out the code. More specifically, you need to run once in a month. Because, every month WP creates a new folder inside the uploads folder :slight_smile:

    Cheers
    Ash

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.