Skip to content

Commit

Permalink
Merge pull request #49 from thinkshout/user-agent-as-plugin-version
Browse files Browse the repository at this point in the history
Plugin Version in User Agent
  • Loading branch information
jamacon36 authored Dec 19, 2023
2 parents 27b6499 + f92cacb commit 18bc88d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
19 changes: 18 additions & 1 deletion src/Otis.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ class Otis {
const AUTH_ROOT = 'https://otis.traveloregon.com/rest-auth';

private $ch;
private $ua;

/**
* Otis constructor.
*/
public function __construct() {
$this->ch = curl_init();
$user_agent = 'Otis-PHP/' . $this->wp_otis_version();

curl_setopt( $this->ch, CURLOPT_USERAGENT, 'Otis-PHP/1.2.2' );
curl_setopt( $this->ch, CURLOPT_USERAGENT, $user_agent );
curl_setopt( $this->ch, CURLOPT_HEADER, false );
curl_setopt( $this->ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $this->ch, CURLOPT_CONNECTTIMEOUT, 30 );
Expand All @@ -33,6 +35,21 @@ public function __destruct() {
}
}

protected function wp_otis_version() {
// Check if the function is available.
if( ! function_exists( 'get_plugin_data' ) ) {
require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
}
// Retrieve plugin data from the main plugin file.
$plugin_data = get_plugin_data( __FILE__ . '/../wp-otis.php' );
// Check if the plugin version was retrieved successfully.
if ( ! isset( $plugin_data['Version'] ) ) {
return '';
}
// Return the plugin version number.
return $plugin_data['Version'];
}

/**
* Get the API token.
* If the token does not exist, a new one is fetched from the API.
Expand Down
2 changes: 1 addition & 1 deletion wp-otis.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Author URI: thinkshout.com
* Text Domain: wp-otis
* Domain Path: /languages
* Version: 1.2.3.1
* Version: 1.2.4.1
*
* @package Otis
*/
Expand Down

0 comments on commit 18bc88d

Please sign in to comment.