version helpers

This commit is contained in:
Mike Jolley 2019-05-22 13:46:06 +01:00
parent 237d80f3f2
commit 12f667645d
2 changed files with 29 additions and 2 deletions

View File

@ -24,6 +24,13 @@ class RestApi {
*/
protected $endpoints = [];
/**
* REST API package version.
*
* @var string
*/
protected $version;
/**
* Hook into WordPress ready to init the REST API as needed.
*/
@ -31,6 +38,24 @@ class RestApi {
add_action( 'rest_api_init', array( $this, 'register_rest_routes' ), 10 );
}
/**
* Return REST API package version.
*
* @return string
*/
public function get_version() {
return $this->version;
}
/**
* Set REST API package version.
*
* @param string $version Version to set.
*/
public function set_version( $version ) {
$this->version = $version;
}
/**
* Register REST API routes.
*/

View File

@ -28,9 +28,11 @@ $version = '1.1.0';
/**
* This callback loads this version of the API.
*/
$init_callback = function() {
$init_callback = function() use ( $version ) {
require __DIR__ . '/vendor/autoload.php';
\WooCommerce\RestApi::instance()->init();
$rest_api = \WooCommerce\RestApi::instance();
$rest_api->set_version( $version );
$rest_api->init();
};
/**