wpseek.com
Bazujące na WordPress narzędzie wyszukiwania dla deweloperów i twórców motywów.



wp_get_edit_root_attachment_id › WordPress Function

Od7.2.0
Przestarzałyn/a
› wp_get_edit_root_attachment_id ( $attachment_id )
Parametry:
  • (int) $attachment_id Attachment ID.
    Wymagane: Tak
Powrót:
  • (int) ID of the attachment the chain of edits started from, or 0 when none is recorded.
Zdefiniowane na:
Codex:

Retrieves the edit root of an attachment: the attachment its chain of edits started from.

Editing an image through the wp/v2/media/<id>/edit REST endpoint does not change the image that was edited. It saves the result as a brand new attachment, so a site can end up with a chain of attachments: an upload, a crop of it, a crop of that crop, and so on. Every attachment created that way stores the ID of the attachment at the top of its chain, so this function can find the edit root in one lookup no matter how long the chain is. Attachments that were uploaded rather than created by editing have no chain of their own, and this returns 0 for them.


Źródło

function wp_get_edit_root_attachment_id( $attachment_id ) {
	$edit_root_id = (int) get_post_meta( $attachment_id, '_wp_attachment_edit_root_id', true );

	// An attachment recorded as its own edit root is a broken record rather than a chain.
	if ( $edit_root_id <= 0 || $edit_root_id === (int) $attachment_id ) {
		return 0;
	}

	return $edit_root_id;
}