Skip to content

Commit

Permalink
Adding getApiVersion function and ensuring getAPIBaseVersion doesn't …
Browse files Browse the repository at this point in the history
…need to be updated for new versions
  • Loading branch information
Connor Burton committed Dec 18, 2015
1 parent 52e1d02 commit 70db5fd
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions acf-to-wp-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function __construct() {
$this->plugin->url = WP_PLUGIN_URL . '/' . str_replace(basename( __FILE__), "", plugin_basename(__FILE__));
$this->plugin->version = '1.3.2';

$this->apiVersion = (REST_API_VERSION) ?: get_option( 'rest_api_plugin_version', get_option( 'json_api_plugin_version', null ) );
$this->apiVersion = $this->_getAPIVersion();

// Version One
if($this->_isAPIVersionOne()) {
Expand Down Expand Up @@ -106,6 +106,26 @@ private function _versionTwoSetup() {
add_action( 'rest_api_init', array( $this, 'addACFOptionRouteV2') );
}

/**
* Returns the WP REST API version, assumes version 2
* if can't find any other version
*
* @return string The version number, set by WP REST API
*
* @since 1.3.2
*/
private function _getAPIVersion() {
$version = 2;

if ( defined( REST_API_VERSION ) ) {
$version = REST_API_VERSION;
} else {
$version = get_option( 'rest_api_plugin_version', get_option( 'json_api_plugin_version', null ) );
}

return $version;
}

/**
* Gets the version number of the WP REST API
*
Expand All @@ -122,14 +142,10 @@ private function _getAPIBaseVersion() {
return false;
}

$baseNumber = substr( $version, 0, 1 );

if( $baseNumber === '1' ) {
return 1;
}
$baseNumber = (int) substr( $version, 0, 1 );

if( $baseNumber === '2' ) {
return 2;
if( $baseNumber > 0 ) {
return $baseNumber;
}

return false;
Expand Down

0 comments on commit 70db5fd

Please sign in to comment.