ACF_Media::get_source_fieldprivateACF 5.9.7

Returns the field responsible for the current Media query or upload context.

Method of the class: ACF_Media{}

No Hooks.

Returns

Array|. false.

Usage

// private - for code of main (parent) class only
$result = $this->get_source_field();

Changelog

Since 5.9.7 Introduced.

ACF_Media::get_source_field() code ACF 6.0.4

private function get_source_field() {
	$field = false;

	// phpcs:disable WordPress.Security.NonceVerification.Missing -- Verified elsewhere.
	// Search for field key within available data.
	// Case 1) Media modal query.
	if ( isset( $_POST['query']['_acfuploader'] ) ) {
		$field_key = sanitize_text_field( $_POST['query']['_acfuploader'] );

		// Case 2) Media modal upload.
	} elseif ( isset( $_POST['_acfuploader'] ) ) {
		$field_key = sanitize_text_field( $_POST['_acfuploader'] );
	}
	// phpcs:enable WordPress.Security.NonceVerification.Missing

	// Attempt to load field.
	// Note the `acf_get_field()` function will return false if not found.
	if ( isset( $field_key ) ) {
		$field = acf_get_field( $field_key );
	}
	return $field;
}