ACF_Ajax_Check_Screen::get_assignable_post_terms │ protected │ ACF 6.8.11

Returns the submitted terms for the post's taxonomies the user can assign terms in, and the post's current terms for those they can't, whether or not they were submitted.

Once post_terms is set, location rules treat a taxonomy missing from it as having no terms, so leaving a taxonomy out must not be a way to change what the post appears to have.

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

Хуков нет.

Возвращает

array.

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->get_assignable_post_terms( $post, $terms );
$post(WP_Post) (обязательный)
The post being edited.
$terms(массив) (обязательный)
The submitted terms, keyed by taxonomy.

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

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

Код ACF_Ajax_Check_Screen::get_assignable_post_terms() ACF 6.8.11

protected function get_assignable_post_terms( $post, $terms ) {
	$post_terms = array();

	foreach ( get_object_taxonomies( $post->post_type, 'objects' ) as $taxonomy ) {
		if ( ! current_user_can( $taxonomy->cap->assign_terms ) ) {
			$current                       = wp_get_object_terms( $post->ID, $taxonomy->name, array( 'fields' => 'ids' ) );
			$post_terms[ $taxonomy->name ] = is_wp_error( $current ) ? array() : array_map( 'intval', $current );
		} elseif ( isset( $terms[ $taxonomy->name ] ) ) {
			$post_terms[ $taxonomy->name ] = array_values( array_map( 'sanitize_text_field', array_filter( (array) $terms[ $taxonomy->name ], 'is_scalar' ) ) );
		}
	}

	return $post_terms;
}