acf_field_gallery::apply_sidebar_changes │ private │ ACF 6.8.11

Applies the sidebar's title, caption and description changes to an attachment's post data, and saves its alt text.

Метод класса: acf_field_gallery{}

Хуков нет.

Возвращает

array. The post data to save.

Использование

// private - только в коде основоного (родительского) класса
$result = $this->apply_sidebar_changes( $post, $changes );
$post(массив) (обязательный)
The attachment's post data.
$changes(массив) (обязательный)
The changes submitted from the sidebar.

Список изменений

С версии 6.8.11 Введена.

Код acf_field_gallery::apply_sidebar_changes() ACF 6.8.11

private function apply_sidebar_changes( $post, $changes ) {
	$properties = array(
		'title'       => 'post_title',
		'caption'     => 'post_excerpt',
		'description' => 'post_content',
	);

	foreach ( $properties as $change => $property ) {
		if ( isset( $changes[ $change ] ) ) {
			$post[ $property ] = $changes[ $change ];
		}
	}

	if ( isset( $changes['alt'] ) ) {
		$alt = wp_unslash( $changes['alt'] );
		if ( $alt !== get_post_meta( $post['ID'], '_wp_attachment_image_alt', true ) ) {
			$alt = wp_strip_all_tags( $alt, true );
			update_post_meta( $post['ID'], '_wp_attachment_image_alt', wp_slash( $alt ) );
		}
	}

	return $post;
}