Fileline documentation1.x
Developers

Hooks

The filters and actions for access, counting, sending files, links, the front end and add-ons.

Downloads are posts of the type fileline_download, with the taxonomies fileline_category and fileline_tag. Versions are rows of the {prefix}fileline_versions table. Read them with Extendiment\Fileline\Download::get( $id ), then ->versions(), ->latest(), ->version( '1.2' ), ->count() and ->url( $version ). Extendiment\Fileline\Versions::insert( $download_id, $data ) adds a version.

Access

Hook What it's for
fileline_can_download (filter) Whether the visitor may download ($result, $download_id, $version, $context). Return true or a WP_Error whose message is shown; its data may have status (HTTP status) and redirect (a URL to send the visitor to instead). $context has editor (may edit the download), method, partial (a resumed download), agent, ip, referer (host) and version_asked.
fileline_enforces_restrictions (filter) Whether an add-on enforces the rules stored in a download's _fileline_restrictions meta. While it's false, such downloads stay locked.
fileline_restriction_labels (filter) Names of those rules for screens.
// Only people who bought the "Oak table" product can download its assembly guide.
add_filter( 'fileline_can_download', function ( $result, $download_id ) {
	if ( true === $result && 42 === $download_id && ! my_customer_bought( 1234 ) ) {
		return new WP_Error( 'not_a_customer', 'This guide is for Oak table owners.', array( 'status' => 403 ) );
	}
	return $result;
}, 10, 2 );

Counting

Hook What it's for
fileline_should_count (filter) Whether a download is counted ($count, $download, $version, $context), after the bot and resume checks.
fileline_bot_agents (filter) Parts of user agents that mark bots (case-insensitive).
fileline_client_ip (filter) The visitor's IP address, e.g. from a trusted proxy header.
fileline_download_counted (action) After a download was counted ($download_id, $version_id, $context).
// Don't count downloads by the site's own staff.
add_filter( 'fileline_should_count', function ( $count ) {
	return $count && ! current_user_can( 'edit_others_posts' );
} );

Sending files

Hook What it's for
fileline_before_download (action) Right before a file is sent, after the access check ($download_id, $version, $context, $response). $response (an Extendiment\Fileline\Response) can still be changed, e.g. a header added.
fileline_file_path (filter) The file sent for a version ($path, $version).
fileline_allowed_paths (filter) Folders files may be sent from (the uploads folder by default). WordPress's own folder, wp-content and the folders above them are ignored. PHP files, wp-config.php, hidden files and folders, and .log, .sql, .bak, .ini, .env, .old, .swp and ~ files are never sent, and uploads/woocommerce_uploads only to users who can manage_woocommerce.
fileline_serve_method (filter) php, xsendfile or xaccel ($method, $version).
fileline_disposition (filter) attachment (save) or inline (open) ($disposition, $version). inline only applies to PDFs, PNG, JPEG, GIF and WebP images, plain text, video and audio; other types are always saved.
fileline_protect_upload (filter) Whether an upload goes into the protected folder.
Hook What it's for
fileline_download_url (filter) A download's link ($url, $download, $version).
fileline_endpoint (filter) The base of pretty links, download. Fileline updates the rewrite rules when it changes.
fileline_download_slug (filter) The base of download pages, downloads. Save Settings → Permalinks after changing it.

Front end

Hook What it's for
fileline_button_html (filter) A button's HTML ($html, $download, $version, $args).
fileline_button_meta (filter) The details under a button ($meta, $download).
fileline_list_query_args (filter) A download list's WP_Query arguments ($query, $args).
fileline_download_details (filter) The details on a download's page.
fileline_show_download_box (filter) Whether a download's page gets the box.
fileline_template (filter) The file used for a template ($file, $name).

Admin and add-ons

Hook What it's for
fileline_loaded (action) Fileline has loaded (on plugins_loaded). Add-ons start here; FILELINE_VERSION is defined.
fileline_access_fields (action) Print fields in a download's Access box ($download, $post).
fileline_save_download (action) Save them ($post_id, $post); Fileline has checked its nonce and edit_post.
fileline_versions_saved (action) After a download's versions were saved ($download_id, $version_ids).
fileline_settings (action) Add Settings API sections and fields to the fileline page (Downloads → Settings).
fileline_settings_after (action) Print after the settings form.