How can i include Guzzle into a wordpress theme or plugin. Since the theme/plugins will be distributed to non tech users i cannot ask them to do that via Composer.
I have uploaded the guzzle pack in a theme folder in libs/resources/ and in functions.php and I have defined this autoloader for guzzle classes only
spl_autoload_register( 'guzzle_autoloader' );
function guzzle_autoloader( $class_name ) {
if ( false !== strpos( $class_name, 'GuzzleHttp' ) ) {
$classes_dir = realpath( plugin_dir_path( __FILE__ ) ) . DIRECTORY_SEPARATOR . 'libs' . DIRECTORY_SEPARATOR.'resources'. DIRECTORY_SEPARATOR .'guzzle-master'. DIRECTORY_SEPARATOR .'src'. DIRECTORY_SEPARATOR ;
$replace="GuzzleHttp\\";
$class_file = str_replace($replace,'', $class_name);
print 'request '.$classes_dir . $class_file.'</br>';
require_once $classes_dir . $class_file.'.php';
}
}
However i'm still getting this error "call to undefined function GuzzleHttp\choose_handler() "
What about composer autoload?
Simply Require Guzzle packagist repo with composer
composer require guzzlehttp/guzzle
Install
composer install
Simply autoload Guzzle Classes in your Wordpress plugin
require 'vendor/autoload.php';
//use GuzzleHttp\Client;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With