Skip to content

Actions and filters

Attachments: 25 hooks.

Every hook here has a description in the source.

11 actions14 filters

action

davo_attachment_removed

Fires after an attachment has been removed.

Parameters of davo_attachment_removed
ParameterTypeDescription
$rowarray<string, mixed>The removed row (pre-deletion snapshot).
$user_idintRequesting user ID.
add_action
add_action( 'davo_attachment_removed', 'my_action_callback', 10, 2 );

/**
 * @param array<string, mixed> $row
 * @param int $user_id
 */
function my_action_callback( $row, $user_id ) {
	// Your code here.
}

src/domains/attachments/repository.php:731

action

davo_attachment_scan_rejected

Fires when a hooked scanner rejects an upload.

Parameters of davo_attachment_scan_rejected
ParameterTypeDescription
$filenamestringSanitized filename.
$reasonstringScanner-supplied reason, if any.
add_action
add_action( 'davo_attachment_scan_rejected', 'my_action_callback', 10, 2 );

/**
 * @param string $filename
 * @param string $reason
 */
function my_action_callback( $filename, $reason ) {
	// Your code here.
}

src/domains/attachments/repository.php:1719

action

davo_attachment_sideloaded

Fires after a file has been sideloaded and committed directly to a target — the sideload equivalent of 'davo_attachment_uploaded' immediately followed by a successful commit_to_target(), collapsed into one event since sideload_from_path() has no separate temporary/commit steps of its own.

Parameters of davo_attachment_sideloaded
ParameterTypeDescription
$rowarray<string, mixed>The new attachment relationship row.
$user_idintAttributed uploader ID.
add_action
add_action( 'davo_attachment_sideloaded', 'my_action_callback', 10, 2 );

/**
 * @param array<string, mixed> $row
 * @param int $user_id
 */
function my_action_callback( $row, $user_id ) {
	// Your code here.
}

src/domains/attachments/repository.php:491

action

davo_attachment_uploaded

Fires after a file has been uploaded and stored as a temporary attachment.

Parameters of davo_attachment_uploaded
ParameterTypeDescription
$rowarray<string, mixed>The new attachment relationship row.
$user_idintUploading user ID.
add_action
add_action( 'davo_attachment_uploaded', 'my_action_callback', 10, 2 );

/**
 * @param array<string, mixed> $row
 * @param int $user_id
 */
function my_action_callback( $row, $user_id ) {
	// Your code here.
}

src/domains/attachments/repository.php:263

filter

davo_attachments_can_upload_{suffix}

Filter whether a user may upload attachments for this target type at all, independent of any specific target post.

The name is built at runtime: davo_attachments_can_upload_ followed by a suffix.

Parameters of davo_attachments_can_upload_…
ParameterTypeDescription
$can_uploadboolDefault true (no extra gate).
$user_idintUploading user ID.
$target_idintTarget post ID (0 pre-creation) — a trailing argument, added after $user_id, specifically so it's additive: a callback already registered with accepted_args = 2 is completely unaffected and never receives it.
add_filter
// $suffix is the part of the name that varies.
add_filter( 'davo_attachments_can_upload_' . $suffix, 'my_filter_callback', 10, 3 );

/**
 * @param bool $can_upload
 * @param int $user_id
 * @param int $target_id
 */
function my_filter_callback( $can_upload, $user_id, $target_id ) {
	// Change $can_upload as needed, then return it.
	return $can_upload;
}

src/domains/attachments/repository.php:1201

action

davo_attachments_committed

Fires after a batch of attachments has been committed to a target.

Parameters of davo_attachments_committed
ParameterTypeDescription
$target_typestringTarget type slug.
$target_idintTarget post ID.
$rowsarray<int, array<string, mixed>>Committed rows (pre-update snapshot).
$user_idintCommitting user ID.
add_action
add_action( 'davo_attachments_committed', 'my_action_callback', 10, 4 );

/**
 * @param string $target_type
 * @param int $target_id
 * @param array<int, array<string, mixed>> $rows
 * @param int $user_id
 */
function my_action_callback( $target_type, $target_id, $rows, $user_id ) {
	// Your code here.
}

src/domains/attachments/repository.php:648

filter

davo_attachments_failed_commit_grace_hours

Filters how many hours temporary attachments are kept after a failed commit. Defaults to 168 (seven days). A value of 0 or less leaves the expiry unchanged.

Parameters of davo_attachments_failed_commit_grace_hours
ParameterTypeDescription
$hoursintGrace period in hours.

Returns int

add_filter
add_filter( 'davo_attachments_failed_commit_grace_hours', 'my_filter_callback', 10, 1 );

/**
 * @param int $hours
 */
function my_filter_callback( $hours ) {
	// Change $hours as needed, then return it.
	return $hours;
}

src/domains/attachments/repository.php:674

filter

davo_attachments_hard_denylisted_extensions

Filters the file extensions that can never be uploaded. No admin setting can allow them.

Parameters of davo_attachments_hard_denylisted_extensions
ParameterTypeDescription
$extensionsstring[]Lowercase extensions without the leading dot.

Returns string[]

add_filter
add_filter( 'davo_attachments_hard_denylisted_extensions', 'my_filter_callback', 10, 1 );

/**
 * @param string[] $extensions
 */
function my_filter_callback( $extensions ) {
	// Change $extensions as needed, then return it.
	return $extensions;
}

src/domains/attachments/helpers.php:408

filter

davo_attachments_htaccess_rules

Filters the .htaccess rules written into the Attachments upload directory.

Parameters of davo_attachments_htaccess_rules
ParameterTypeDescription
$rulesstringFull file contents, including the version marker line.
add_filter
add_filter( 'davo_attachments_htaccess_rules', 'my_filter_callback', 10, 1 );

/**
 * @param string $rules
 */
function my_filter_callback( $rules ) {
	// Change $rules as needed, then return it.
	return $rules;
}

src/domains/attachments/initializer.php:436

filter

davo_attachments_max_file_size_{suffix}

Filters the largest single file allowed for a target type.

The name is built at runtime: davo_attachments_max_file_size_ followed by a suffix.

Parameters of davo_attachments_max_file_size_…
ParameterTypeDescription
$maxintBytes; defaults to the global limit.
add_filter
// $suffix is the part of the name that varies.
add_filter( 'davo_attachments_max_file_size_' . $suffix, 'my_filter_callback', 10, 1 );

/**
 * @param int $max
 */
function my_filter_callback( $max ) {
	// Change $max as needed, then return it.
	return $max;
}

src/domains/attachments/repository.php:62

filter

davo_attachments_migration_optional_providers

Filters the providers Attachments should run after WHEN PRESENT in the same job, without requiring their presence.

Parameters of davo_attachments_migration_optional_providers
ParameterTypeDescription
$provider_keysarray<int, string>Provider keys. Default none.
add_filter
add_filter( 'davo_attachments_migration_optional_providers', 'my_filter_callback', 10, 1 );

/**
 * @param array<int, string> $provider_keys
 */
function my_filter_callback( $provider_keys ) {
	// Change $provider_keys as needed, then return it.
	return $provider_keys;
}

src/domains/attachments/migration-provider.php:167

filter

davo_attachments_migration_required_providers

Filters the providers that must ALWAYS be imported before Attachments, widening any export that includes Attachments even when the added provider was never selected. Reserved for a genuinely hard requirement; a content domain that merely wants its posts imported first WHEN ALSO SELECTED should hook davo_attachments_migration_optional_providers instead (see optional_providers()) — that's what every current content domain uses.

Parameters of davo_attachments_migration_required_providers
ParameterTypeDescription
$provider_keysarray<int, string>Provider keys. Default users.
add_filter
add_filter( 'davo_attachments_migration_required_providers', 'my_filter_callback', 10, 1 );

/**
 * @param array<int, string> $provider_keys
 */
function my_filter_callback( $provider_keys ) {
	// Change $provider_keys as needed, then return it.
	return $provider_keys;
}

src/domains/attachments/migration-provider.php:142

filter

davo_attachments_migration_separate_targets

Filters target types whose files have a dedicated migration section. */

Passed to callbacks: array()

add_filter
add_filter( 'davo_attachments_migration_separate_targets', 'my_filter_callback', 10, 1 );

function my_filter_callback( $arg1 ) {
	// Change $arg1 as needed, then return it.
	return $arg1;
}

src/domains/attachments/migration-provider.php:514

action

davo_attachments_register_storage_drivers

Register Attachments storage drivers.

Parameters of davo_attachments_register_storage_drivers
ParameterTypeDescription
$registryAttachments_Storage_RegistryShared registry instance.
add_action
add_action( 'davo_attachments_register_storage_drivers', 'my_action_callback', 10, 1 );

/**
 * @param Attachments_Storage_Registry $registry
 */
function my_action_callback( $registry ) {
	// Your code here.
}

src/domains/attachments/storage/registry.php:112

action

davo_attachments_remote_stored

Fires after an attachment's file is confirmed stored remotely.

Parameters of davo_attachments_remote_stored
ParameterTypeDescription
$row_idintAttachments table row ID.
$driverstringDriver slug.
$keystringRemote object key.
add_action
add_action( 'davo_attachments_remote_stored', 'my_action_callback', 10, 3 );

/**
 * @param int $row_id
 * @param string $driver
 * @param string $key
 */
function my_action_callback( $row_id, $driver, $key ) {
	// Your code here.
}

src/domains/attachments/storage/service.php:171

filter

davo_attachments_resolve_target_{suffix}

Resolve permission/visibility for a single attachment target of this type. The owning domain must hook this and return the full {exists, can_edit, can_view, is_public} shape – returning the unmodified $default leaves the target treated as nonexistent.

The name is built at runtime: davo_attachments_resolve_target_ followed by a suffix.

Parameters of davo_attachments_resolve_target_…
ParameterTypeDescription
$defaultarray{exists: bool, can_edit: bool, can_view: bool, is_public: bool}Restrictive default.
$target_idintTarget post ID.
$user_idintUser ID being resolved for (0 = guest).
add_filter
// $suffix is the part of the name that varies.
add_filter( 'davo_attachments_resolve_target_' . $suffix, 'my_filter_callback', 10, 3 );

/**
 * @param array{exists: bool, can_edit: bool, can_view: bool, is_public: bool} $default
 * @param int $target_id
 * @param int $user_id
 */
function my_filter_callback( $default, $target_id, $user_id ) {
	// Change $default as needed, then return it.
	return $default;
}

src/domains/attachments/object-resolver.php:89, and 2 more places

filter

davo_attachments_s3_allow_insecure_endpoint

Filters whether a custom S3 endpoint may use plain http on a public host. Defaults to false; plain http is only accepted for internal hosts.

Parameters of davo_attachments_s3_allow_insecure_endpoint
ParameterTypeDescription
$allowboolWhether to allow it.
$hoststringThe endpoint's host name.

Returns bool

add_filter
add_filter( 'davo_attachments_s3_allow_insecure_endpoint', 'my_filter_callback', 10, 2 );

/**
 * @param bool $allow
 * @param string $host
 */
function my_filter_callback( $allow, $host ) {
	// Change $allow as needed, then return it.
	return $allow;
}

src/domains/attachments/storage/s3.php:417

filter

davo_attachments_skip_upload_limits

Filters whether to skip the per-user upload limits, for example during a bulk import. Defaults to false.

Parameters of davo_attachments_skip_upload_limits
ParameterTypeDescription
$skipboolWhether to skip the limits.
$uploader_idintUploading user ID.

Returns bool

add_filter
add_filter( 'davo_attachments_skip_upload_limits', 'my_filter_callback', 10, 2 );

/**
 * @param bool $skip
 * @param int $uploader_id
 */
function my_filter_callback( $skip, $uploader_id ) {
	// Change $skip as needed, then return it.
	return $skip;
}

src/domains/attachments/repository.php:1297, and 1 more place

filter

davo_attachments_storage_memory_ok

Filters whether a file may be uploaded to remote storage given current memory.

Parameters of davo_attachments_storage_memory_ok
ParameterTypeDescription
$okboolWhether enough memory is available.
$pathstringLocal file path.
$sizeintFile size in bytes.
add_filter
add_filter( 'davo_attachments_storage_memory_ok', 'my_filter_callback', 10, 3 );

/**
 * @param bool $ok
 * @param string $path
 * @param int $size
 */
function my_filter_callback( $ok, $path, $size ) {
	// Change $ok as needed, then return it.
	return $ok;
}

src/domains/attachments/storage/service.php:882

action

davo_attachments_storage_recovered

Fires when remote storage works again after a recorded failure.

Parameters of davo_attachments_storage_recovered
ParameterTypeDescription
$driver_idstringDriver slug.
add_action
add_action( 'davo_attachments_storage_recovered', 'my_action_callback', 10, 1 );

/**
 * @param string $driver_id
 */
function my_action_callback( $driver_id ) {
	// Your code here.
}

src/domains/attachments/storage/service.php:780

action

davo_attachments_storage_unhealthy

Fires when remote storage starts failing, or fails for a new reason. Hook the Notifications domain here to alert administrators.

Parameters of davo_attachments_storage_unhealthy
ParameterTypeDescription
$driver_idstringDriver slug.
$codestringError code.
$messagestringError message (plain text).
$operationstring'upload', 'download', 'delete' or 'test'.
add_action
add_action( 'davo_attachments_storage_unhealthy', 'my_action_callback', 10, 4 );

/**
 * @param string $driver_id
 * @param string $code
 * @param string $message
 * @param string $operation
 */
function my_action_callback( $driver_id, $code, $message, $operation ) {
	// Your code here.
}

src/domains/attachments/storage/service.php:816

action

davo_attachments_target_deleted

Fires after every attachment of a target has been deleted.

Parameters of davo_attachments_target_deleted
ParameterTypeDescription
$target_typestringThe kind of item the attachments belonged to.
$target_idintThe item's ID.
add_action
add_action( 'davo_attachments_target_deleted', 'my_action_callback', 10, 2 );

/**
 * @param string $target_type
 * @param int $target_id
 */
function my_action_callback( $target_type, $target_id ) {
	// Your code here.
}

src/domains/attachments/repository.php:763

filter

davo_attachments_target_type_for_post_type

Filter: resolve the Attachments target_type slug for a WP post type, or null if that post type has no attachments integration. Each domain that registers an attachment target type (Questions, future Articles/ Tickets, ...) hooks this once for its own post type(s).

Parameters of davo_attachments_target_type_for_post_type
ParameterTypeDescription
$target_typestring|nullDefault null (no mapping).
$post_typestringWP post type slug (e.g. 'question').
add_filter
add_filter( 'davo_attachments_target_type_for_post_type', 'my_filter_callback', 10, 2 );

/**
 * @param string|null $target_type
 * @param string $post_type
 */
function my_filter_callback( $target_type, $post_type ) {
	// Change $target_type as needed, then return it.
	return $target_type;
}

src/domains/attachments/initializer.php:612

filter

davo_attachments_user_may_upload

Filter whether a user may upload attachments at all, for any target type.

Lets other domains (for example Moderation, for suspended users) veto an upload without Attachments depending on them.

Parameters of davo_attachments_user_may_upload
ParameterTypeDescription
$can_uploadboolDefault true.
$user_idintUploading user ID.
$target_typestringTarget type slug.
$target_idintTarget post ID (0 pre-creation).
add_filter
add_filter( 'davo_attachments_user_may_upload', 'my_filter_callback', 10, 4 );

/**
 * @param bool $can_upload
 * @param int $user_id
 * @param string $target_type
 * @param int $target_id
 */
function my_filter_callback( $can_upload, $user_id, $target_type, $target_id ) {
	// Change $can_upload as needed, then return it.
	return $can_upload;
}

src/domains/attachments/repository.php:1186

action

davo_register_attachment_target_types

Register attachment target types.

Parameters of davo_register_attachment_target_types
ParameterTypeDescription
$registryAttachments_RegistryShared Attachments Registry instance.
add_action
add_action( 'davo_register_attachment_target_types', 'my_action_callback', 10, 1 );

/**
 * @param Attachments_Registry $registry
 */
function my_action_callback( $registry ) {
	// Your code here.
}

src/domains/attachments/initializer.php:195

Note. Generated from the plugin source. Descriptions and parameters are the ones written in the code. The starter code uses the parameter names from those comments, or generic names where there are none, so check them against your use.

See it on your own site.

Davo is a WordPress theme and plugin by Exorex.

  • Runs on your own WordPress
  • Guided setup wizard
  • AI is off until you switch it on
  • Read the licence on the marketplace first