a_z_listing_register_rest_api()

Register the REST API extensions for the plugin


Description


Source

File: wp-api/api.php

function a_z_listing_register_rest_api() {
	$default_args = array(
		'alphabet'       => array(
			'description'       => __( 'Override default alphabet', 'a-z-listing' ),
			'type'              => 'string',
			'default'           => '',
			'sanitize_callback' => 'sanitize_text_field',
		),
		'grouping'       => array(
			'description' => __( 'Size of buckets to group the alphabet', 'a-z-listing' ),
			'type'        => 'integer',
			'default'     => 1,
			'minimum'     => 1,
		),
		'group-numbers'  => array(
			'description' => __( 'Include numbers as separate group. Implies {numbers:true}', 'a-z-listing' ),
			'type'        => 'boolean',
			'default'     => false,
		),
		'taxonomy'       => array(
			'description'       => __( 'Taxonomy', 'a-z-listing' ),
			'type'              => 'string',
			'default'           => '',
			'sanitize_callback' => 'sanitize_text_field',
		),
		'include-styles' => array(
			'description' => __( 'Include the stylesheet tags in the output', 'a-z-listing' ),
			'type'        => 'boolean',
			'default'     => false,
		),
	);

	register_rest_route(
		'a-z-listing/v1',
		'/posts/(?P<post_type>[a-z0-9-]+)',
		array(
			'methods'  => 'GET',
			'callback' => 'a_z_listing_posts_api_handler',
			'args'     => array(
				'post_type' => array(
					'description'       => __( 'Post type', 'a-z-listing' ),
					'type'              => 'string',
					'default'           => 'page',
					'sanitize_callback' => 'sanitize_text_field',
				),
				'terms'     => array(
					'description'       => __( 'Terms to filter by', 'a-z-listing' ),
					'type'              => 'string',
					'default'           => '',
					'sanitize_callback' => 'sanitize_text_field',
				),
				$default_args,
			),
		)
	);
	register_rest_route(
		'a-z-listing/v1',
		'/terms/(?P<taxonomy>[a-z0-9-]+)',
		array(
			'methods'  => 'GET',
			'callback' => 'a_z_listing_terms_api_handler',
			'args'     => array(
				$default_args,
			),
		)
	);
}

Changelog

Changelog
VersionDescription
2.0.0Introduced.