BASIC

Download Buttons

Hoster ships two blocks for download buttons, Download Static Button and Download Dynamic Button, in the Hoster block category. Oxygen Classic users get the Hoster Button element.

Hoster blocks in the inserter

Static Button

Pick the Download in the block settings: Settings → Choose download lists up to 100 of your Downloads, drafts included, so you can prepare the page before the product goes live. Use it anywhere on the site, for example on a pricing or landing page.

Static button settings

Choose download

Dynamic Button

The Dynamic Button downloads the current Download, so it has no download picker. Use it in the single Download template, or inside a Query Loop that lists Downloads: each item gets its own button. It only picks up the current post when that post is a Download, so place it only where a Download is being shown.

Both blocks have an Open in new tab setting, and you type the button text on the button itself.

A button for a Download that has no package yet, or isn't published, outputs nothing. This applies to both blocks and the Oxygen element. Tools → Site Health → Hoster downloads have a package lists published Downloads without a package.

The button link

Buttons link to a stable URL on your site:

https://your-site.com/?hoster_dl=<download ID>

The link holds no signature or expiry, so pages with buttons are safe to cache. Hoster checks who is clicking when the link is opened, and then sends a fresh, signed package link.

Free and licensed Downloads

What the button shows depends on the Download and on who is looking:

  • Visitor, not logged in — free: the download button. Licensed: a Log in to download link; after logging in, the download starts.
  • Logged-in user with an active licence for this Download — the download button.
  • Site owner or editor (anyone who can edit this Download) — the download button, for licensed Downloads too, without a licence.
  • Logged-in user without a licence — free: the download button. Licensed: a locked button with a lock icon and a licence notice below it.

The licence belongs to the user set in the licence's User field, see License on Hosted Plugin. A licence counts as active when its status is Active and its expiry date hasn't passed.

Locked button settings

For a licensed Download, the block's Settings panel has three more settings for logged-in users without a licence:

  • Show a locked button — on by default. Turn it off to show nothing to these users.
  • Show a licence notice below — on by default.
  • Licence notice — the notice text. Empty means "A licence is required to download this."

These settings only appear when the chosen Download is licensed. Inside a Query Loop they always appear, because the loop may list licensed Downloads.

The locked button is an <a> without a link, with the is-locked class, aria-disabled="true" and a lock icon (.hoster-lock-icon). The notice is a <p class="hoster-licence-notice"> right after the button.

Replace the locked button

Use the hoster_button_no_license_html filter to replace the whole locked output, for example with a link to your shop. It also runs when Show a locked button is off (the HTML is then empty).

add_filter('hoster_button_no_license_html', function ($html, $download_id) {
    return '<a class="wp-block-button__link" href="https://your-site.com/pricing/">Buy a licence</a>';
}, 10, 2);

Download counter

Every package Hoster serves adds one to the Download's counter: button clicks and updates installed by client sites. The count shows in the Downloads column of the Downloads list and at the top of the Download's sidebar.

For your own statistics, hook into hoster_package_served. It runs after all checks passed, right before the file is sent. The second argument is the licence the link was made for, or 0 for free Downloads and older clients.

add_action('hoster_package_served', function ($download_id, $license_id) {
    error_log("Download {$download_id} served (licence {$license_id})");
}, 10, 2);

Oxygen element

The Hoster Button element (Oxygen Classic) works like the Static Button:

  • Button Settings: Button Text (empty means "Download" plus the Download's title), Download and Target (tick New to open in a new tab).
  • Without a licence: the same settings as the blocks, described above. Oxygen checkboxes start unticked, so they are switches that hide things: tick Hide the locked button to show nothing to users without a licence, tick Hide the licence notice to keep only the locked button, and use Licence notice for your own text (empty means "A licence is required to download this."). The notice settings disappear while Hide the locked button is ticked.

The button is wrapped in a <div class="hoster-button">.

The element needs Oxygen Classic (tested with 4.9.1). Oxygen 6 registers elements differently, so the Hoster Button element isn't available there yet. Hoster itself works normally with Oxygen 6, and the Gutenberg blocks and shortcodes are not affected.

Styling the buttons

Style the blocks like any other block, in the Styles tab of the block settings:

  • Color
    • Text
    • Background (including gradients)
  • Typography
    • Size
    • Line height
    • Font family
    • Appearance (weight and style)
    • Letter spacing
    • Letter case
    • Decoration
  • Dimensions
    • Padding
    • Margin (top and bottom)
  • Border
    • Color
    • Width
    • Radius

Both blocks have the same styling options. The locked button uses the same styles, faded, with a "not allowed" cursor.

Button styles