wp_add_footnotes_revisions_to_post_meta()WP 6.3.0

This is a specific fix for the REST API. The REST API doesn't update the post and post meta in one go (through meta_input). While it does fix the wp_after_insert_post to be called correctly after updating meta, it does NOT fix hooks such as post_updated and save_post, which are normally also fired after post meta is updated in wp_insert_post(). Unfortunately, wp_save_post_revision is added to the post_updated which means the meta is not available at the time, so we have to add it afterwards through the "rest_after_insert_{$post_type}" action.

Хуков нет.

Возвращает

null. Ничего (null).

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

wp_add_footnotes_revisions_to_post_meta( $post );
$post(WP_Post) (обязательный)
The post object.

Заметки

  • Global. int. $wp_temporary_footnote_revision_id The footnote revision ID.

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

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

Код wp_add_footnotes_revisions_to_post_meta() WP 6.3.1

function wp_add_footnotes_revisions_to_post_meta( $post ) {
	global $wp_temporary_footnote_revision_id;

	if ( $wp_temporary_footnote_revision_id ) {
		$revision = get_post( $wp_temporary_footnote_revision_id );

		if ( ! $revision ) {
			return;
		}

		$post_id = $revision->post_parent;

		// Just making sure we're updating the right revision.
		if ( $post->ID === $post_id ) {
			$footnotes = get_post_meta( $post_id, 'footnotes', true );

			if ( $footnotes ) {
				// Can't use update_post_meta() because it doesn't allow revisions.
				update_metadata( 'post', $wp_temporary_footnote_revision_id, 'footnotes', wp_slash( $footnotes ) );
			}
		}
	}
}