How to Hide the Download Button for the Public User Group in OSDownloads

If you want to control who sees the "Download" button for OSDownload files, Joomla offers a simple solution.

By using RegularLabs.com's "Conditional Content" extension and customizing a template override, you can restrict access to logged-in users only.

This post will show you how to set it up effectively.

Start by downloading, installing, and enabling the free version of the "Conditional Content" component from RegularLabs.com. This tool will allow you to display content conditionally based on user access levels.

Head to System > Site Templates in your Joomla admin area. This will take you to the "Templates: Templates (Site)" page, listing all your front-end templates.

Find and click on the title of your active front-end template. This will bring you to the "Templates: Customise (name-of-your-template)" admin page.

Navigate to the Create Overrides tab, as you can see in the next image.

the create overrides tab

Here, you’ll see a list of components in the Components column. Look for com_osdownloads and click on the item under it.

the item link

Joomla will confirm that an override has been created with a message like the one shown in the next image.

Next, click the Editor tab to edit your template override files.

the message and the editor tab

In the file structure on the left, go to html > com_osdownloads > item > default.php to open this file for editing.

the default PHP file

Within the default.php file, locate this line of code:

 <div class="btn_download">

Directly under this line, delete the following PHP code:

<?php echo LayoutHelper::render('osdownloads.buttons.download', $this); ?>

Replace it with the following code snippet:

{show accesslevels="Registered"}
            <?php echo LayoutHelper::render('osdownloads.buttons.download', $this); ?>
          {/show}

After making these changes, your outputting the "Download" button code snippet should now look like this:

 <div class="btn_download">
          {show accesslevels="Registered"}
            <?php echo LayoutHelper::render('osdownloads.buttons.download', $this); ?>
          {/show}
</div>

How to Hide the Download Button for the Public User Group in OSDownloads

Save your changes by clicking Save or Save & Close.

Finally, test it out! Visit the front end of your site as a guest (not logged in), and you’ll notice that the "Download" button is no longer displayed. Once you log in, the "Download" button will reappear, as expected.