Form_Capabilities::map_item_action( string $action, int $user_id, int $args )

Maps a specific item capability.

Description

Parameters

$action

(string) (Required) Action name. Either 'read', 'edit' or 'delete'.

$user_id

(int) (Required) User ID.

$args

(int) (Required) Additional arguments.

Return

(string) Mapped capability name.

Source

File: src/db-objects/forms/form-capabilities.php

	protected function map_item_action( $action, $user_id, $args ) {
		/* Require an ID to be passed to this capability check. */
		if ( ! isset( $args[0] ) || ! is_numeric( $args[0] ) ) {
			return 'do_not_allow';
		}

		$item = $this->manager->get( $args[0] );
		if ( null === $item ) {
			return 'do_not_allow';
		}

		$primary_property = $this->manager->get_primary_property();

		$fallback_cap = $action . '_items';

		if ( method_exists( $this->manager, 'get_author_property' ) ) {
			$author_property = $this->manager->get_author_property();

			$author_id = $item->$author_property;
			if ( $author_id !== $user_id ) {
				$fallback_cap = 'read' === $action ? 'edit_others_items' : $action . '_others_items';
			}
		}

		$status = $item->status;
		if ( 'trash' === $status ) {
			$status = get_post_meta( $item->$primary_property, '_wp_trash_meta_status', true );
		}

		if ( $action . '_items' !== $fallback_cap && 'private' === $status ) {
			return $this->base_capabilities[ $action . '_private_items' ];
		}

		if ( 'read' !== $action && in_array( $status, array( 'publish', 'future' ), true ) ) {
			return $this->base_capabilities[ $action . '_published_items' ];
		}

		return $this->base_capabilities[ $fallback_cap ];
	}

Changelog

Changelog
Version Description
1.0.0 Introduced.