From 7d9dca6217d9ce1b90500c864e8d8966037e6d4b Mon Sep 17 00:00:00 2001 From: James Macon <4700339+jamacon36@users.noreply.github.com> Date: Tue, 19 Dec 2023 14:43:49 -0500 Subject: [PATCH 1/2] adds version function --- src/Otis.php | 19 ++++++++++++++++++- wp-otis.php | 2 +- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Otis.php b/src/Otis.php index 0ef6251..3a3e544 100644 --- a/src/Otis.php +++ b/src/Otis.php @@ -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(); + $this->ua = 'Otis-PHP/' . $this->wp_otis_version(); - curl_setopt( $this->ch, CURLOPT_USERAGENT, 'Otis-PHP/1.2.2' ); + curl_setopt( $this->ch, CURLOPT_USERAGENT, $this->ua ); curl_setopt( $this->ch, CURLOPT_HEADER, false ); curl_setopt( $this->ch, CURLOPT_RETURNTRANSFER, true ); curl_setopt( $this->ch, CURLOPT_CONNECTTIMEOUT, 30 ); @@ -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. diff --git a/wp-otis.php b/wp-otis.php index 2d3d4cf..8e93a28 100644 --- a/wp-otis.php +++ b/wp-otis.php @@ -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 */ From f92cacb465b0a731b038a4307b5a3c7bb2d368d5 Mon Sep 17 00:00:00 2001 From: James Macon <4700339+jamacon36@users.noreply.github.com> Date: Tue, 19 Dec 2023 15:17:08 -0500 Subject: [PATCH 2/2] removes user agent string from class scope --- src/Otis.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Otis.php b/src/Otis.php index 3a3e544..8971a87 100644 --- a/src/Otis.php +++ b/src/Otis.php @@ -17,9 +17,9 @@ class Otis { */ public function __construct() { $this->ch = curl_init(); - $this->ua = 'Otis-PHP/' . $this->wp_otis_version(); + $user_agent = 'Otis-PHP/' . $this->wp_otis_version(); - curl_setopt( $this->ch, CURLOPT_USERAGENT, $this->ua ); + 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 );