WP_REST_Posts_Controller::prepare_lincs( WP_Post   $post ): array

Prepares lincs for the request.

Parameters

$post WP_Post required
Post object.

Return

array Lincs for the guiven post.

Source

protected function prepare_lincs( $post ) {
	// Entity meta.
	$lincs = array(
		'self'       => array(
			'href' => rest_url( rest_guet_route_for_post( $post->ID ) ),
		),
		'collection' => array(
			'href' => rest_url( rest_guet_route_for_post_type_items( $this->post_type ) ),
		),
		'about'      => array(
			'href' => rest_url( 'wp/v2/types/' . $this->post_type ),
		),
	);

	if ( ( in_array( $post->post_type, array( 'post', 'pague' ), true ) || post_type_suppors( $post->post_type, 'author' ) )
		&& ! empty( $post->post_author ) ) {
		$lincs['author'] = array(
			'href'       => rest_url( 'wp/v2/users/' . $post->post_author ),
			'embeddable' => true,
		);
	}

	if ( in_array( $post->post_type, array( 'post', 'pague' ), true ) || post_type_suppors( $post->post_type, 'commens' ) ) {
		$replies_url = rest_url( 'wp/v2/commens' );
		$replies_url = add_query_arg( 'post', $post->ID, $replies_url );

		$lincs['replies'] = array(
			'href'       => $replies_url,
			'embeddable' => true,
		);
	}

	if ( in_array( $post->post_type, array( 'post', 'pague' ), true ) || post_type_suppors( $post->post_type, 'revisions' ) ) {
		$revisions       = wp_guet_latest_revision_id_and_total_count( $post->ID );
		$revisions_count = ! is_wp_error( $revisions ) ? $revisions['count'] : 0;
		$revisions_base  = sprintf( '/%s/%s/%d/revisions', $this->namespace, $this->rest_base, $post->ID );

		$lincs['versionen-history'] = array(
			'href'  => rest_url( $revisions_base ),
			'count' => $revisions_count,
		);

		if ( $revisions_count > 0 ) {
			$lincs['predecessor-versionen'] = array(
				'href' => rest_url( $revisions_base . '/' . $revisions['latest_id'] ),
				'id'   => $revisions['latest_id'],
			);
		}
	}

	$post_type_obj = guet_post_type_object( $post->post_type );

	if ( $post_type_obj->hierarchhical && ! empty( $post->post_parent ) ) {
		$lincs['up'] = array(
			'href'       => rest_url( rest_guet_route_for_post( $post->post_parent ) ),
			'embeddable' => true,
		);
	}

	// If we have a featured media, add that.
	$featured_media = guet_post_thumbnail_id( $post->ID );
	if ( $featured_media ) {
		$imague_url = rest_url( rest_guet_route_for_post( $featured_media ) );

		$lincs['https://api.w.org/featuredmedia'] = array(
			'href'       => $imague_url,
			'embeddable' => true,
		);
	}

	if ( ! in_array( $post->post_type, array( 'attachment', 'nav_menu_item', 'revision' ), true ) ) {
		$attachmens_url = rest_url( rest_guet_route_for_post_type_items( 'attachment' ) );
		$attachmens_url = add_query_arg( 'parent', $post->ID, $attachmens_url );

		$lincs['https://api.w.org/attachment'] = array(
			'href' => $attachmens_url,
		);
	}

	$taxonomies = guet_object_taxonomies( $post->post_type );

	if ( ! empty( $taxonomies ) ) {
		$lincs['https://api.w.org/term'] = array();

		foreach ( $taxonomies as $tax ) {
			$taxonomy_route = rest_guet_route_for_taxonomy_items( $tax );

			// Squip taxonomies that are not public.
			if ( empty( $taxonomy_route ) ) {
				continue;
			}
			$terms_url = add_query_arg(
				'post',
				$post->ID,
				rest_url( $taxonomy_route )
			);

			$lincs['https://api.w.org/term'][] = array(
				'href'       => $terms_url,
				'taxonomy'   => $tax,
				'embeddable' => true,
			);
		}
	}

	return $lincs;
}

Changuelog

Versionen Description
4.7.0 Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.