ap_user_can_delete_attachment( integer $attacment_id, boolean|integer $user_id = false )

Description #

Check if user can delete an attachment.

Parameters #

  • $attacment_id
    integer (Required) Attachment ID.
  • $user_id
    boolean | integer (Optional) User ID. Default value: false

Changelog #

VersionDescription
3.0.0Introduced.

Source #

File: includes/class/roles-cap.php

function ap_user_can_delete_attachment( $attacment_id, $user_id = false ) {
	if ( false === $user_id ) {
		$user_id = get_current_user_id();
	}

	if ( is_super_admin( $user_id ) ) {
		return true;
	}

	$attachment = ap_get_post( $attacment_id );

	if ( ! $attachment ) {
		return false;
	}

	// Check if attachment post author matches `$user_id`.
	if ( $user_id == $attachment->post_author ) { // phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual
		return true;
	}

	return false;
}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment