Here is my example plugin for AWS S3 configuration
Here is my php my-s3-plugin.php
<?php
/*
Plugin Name: My S3 Plugin
Description: A plugin to integrate AWS S3 with WordPress.
Version: 1.0
Author: Your Name
*/
if (file_exists(__DIR__ . '/vendor/autoload.php')) {
require __DIR__ . '/vendor/autoload.php';
}
use AwsS3S3Client;
use AwsExceptionAwsException;
function pda_s3_integration_update_general_setting() {
error_reporting(E_ALL);
ini_set('display_errors', true);
// Security check
$nonce = $_REQUEST['security_check'];
if (!wp_verify_nonce($nonce, 'pdas3_ajax_nonce')) {
error_log('Nonce verification failed', 0);
wp_die('invalid_nonce');
}
// Get settings from request
$settings = $_REQUEST['settings'];
if (empty($settings)) {
error_log('Settings are empty', 0);
wp_die('Settings are empty');
}
// Assign settings to variables
$region = $settings["region"] ?? null;
$accessKeyId = $settings["aws_key"] ?? null;
$secretAccessKey = $settings["aws_secret"] ?? null;
$bucketName = $settings["bucket"] ?? null;
// Log and verify settings
if (!$region || !$accessKeyId || !$secretAccessKey || !$bucketName) {
error_log("Region: $region, Access Key ID: $accessKeyId, Secret Access Key: $secretAccessKey, Bucket Name: $bucketName", 0);
wp_die('Invalid AWS configuration settings');
}
// Initialize S3 client and check bucket
try {
$s3Client = new S3Client([
'version' => 'latest',
'region' => $region,
'credentials' => [
'key' => $accessKeyId,
'secret' => $secretAccessKey,
],
]);
$isOk = $s3Client->doesBucketExist($bucketName);
if (!$isOk) {
wp_send_json($isOk);
wp_die();
}
} catch (AwsException $e) {
error_log('AWS Error: ' . $e->getMessage(), 0);
wp_die('AWS SDK error');
}
}
// Hook into WordPress admin to add your function
add_action('wp_ajax_pda_s3_integration_update_general_setting', 'pda_s3_integration_update_general_setting');
// Enqueue the JavaScript file
function my_s3_plugin_enqueue_scripts() {
wp_enqueue_script('my-s3-plugin-js', plugins_url('js/my-s3-plugin.js', __FILE__), array('jquery'), '1.0', true);
// Localize the script with new data
wp_localize_script('my-s3-plugin-js', 'myS3Plugin', array(
'ajaxurl' => admin_url('admin-ajax.php'),
'nonce' => wp_create_nonce('pdas3_ajax_nonce')
));
}
add_action('admin_enqueue_scripts', 'my_s3_plugin_enqueue_scripts');
Here is my js file
jQuery(document).ready(function($) {
var data = {
action: 'pda_s3_integration_update_general_setting',
security_check: myS3Plugin.nonce,
settings: {
region: 'EXAMPLE',
aws_key: 'EXAMPLE',
aws_secret: 'EXAMPLE',
bucket: 'EXAMPLE'
}
};
$.post(myS3Plugin.ajaxurl, data, function(response) {
console.log(response);
});
});
Here is my composer.json file
{
"require": {
"aws/aws-sdk-php": "^3.318",
"coenjacobs/mozart": "^0.7.1"
}
}
I want to configure AWS s3 bucket with the latest version 3.318.0
Here is the errors I am getting
<br />
<b>Warning</b>: AwsClientResolver::_default_ignore_configured_endpoint_urls(): Argument #1 ($args) must be passed by reference, value given in <b>C:UsersMeetLocal Sitespda-liveapppublicwp-contentpluginsprevent-direct-access-gold-3.0vendorantecedentpatchworksrcCallRerouting.php</b> on line <b>419</b><br />
<br />
<b>Warning</b>: AwsClientResolver::_apply_ignore_configured_endpoint_urls(): Argument #2 ($args) must be passed by reference, value given in <b>C:UsersMeetLocal Sitespda-liveapppublicwp-contentpluginsprevent-direct-access-gold-3.0vendorantecedentpatchworksrcCallRerouting.php</b> on line <b>419</b><br />
<br />
<b>Warning</b>: AwsClientResolver::_default_endpoint(): Argument #1 ($args) must be passed by reference, value given in <b>C:UsersMeetLocal Sitespda-liveapppublicwp-contentpluginsprevent-direct-access-gold-3.0vendorantecedentpatchworksrcCallRerouting.php</b> on line <b>419</b><br />
<br />
<b>Warning</b>: Undefined array key "ignore_configured_endpoint_urls" in <b>C:UsersMeetLocal Sitespda-liveapppublicwp-contentpluginsmy-s3-pluginvendorawsaws-sdk-phpsrcClientResolver.php</b> on line <b>1245</b><br />
<br />
<b>Warning</b>: AwsClientResolver::_apply_endpoint(): Argument #2 ($args) must be passed by reference, value given in <b>C:UsersMeetLocal Sitespda-liveapppublicwp-contentpluginsprevent-direct-access-gold-3.0vendorantecedentpatchworksrcCallRerouting.php</b> on line <b>419</b><br />
<br />
<b>Warning</b>: AwsClientResolver::_apply_region(): Argument #2 ($args) must be passed by reference, value given in <b>C:UsersMeetLocal Sitespda-liveapppublicwp-contentpluginsprevent-direct-access-gold-3.0vendorantecedentpatchworksrcCallRerouting.php</b> on line <b>419</b><br />
<br />
<b>Warning</b>: AwsS3S3Client::_applyApiProvider(): Argument #2 ($args) must be passed by reference, value given in <b>C:UsersMeetLocal Sitespda-liveapppublicwp-contentpluginsprevent-direct-access-gold-3.0vendorantecedentpatchworksrcCallRerouting.php</b> on line <b>419</b><br />
<br />
<b>Warning</b>: AwsClientResolver::_apply_defaults(): Argument #2 ($args) must be passed by reference, value given in <b>C:UsersMeetLocal Sitespda-liveapppublicwp-contentpluginsprevent-direct-access-gold-3.0vendorantecedentpatchworksrcCallRerouting.php</b> on line <b>419</b><br />
<br />
<b>Warning</b>: AwsClientResolver::_default_use_fips_endpoint(): Argument #1 ($args) must be passed by reference, value given in <b>C:UsersMeetLocal Sitespda-liveapppublicwp-contentpluginsprevent-direct-access-gold-3.0vendorantecedentpatchworksrcCallRerouting.php</b> on line <b>419</b><br />
<br />
<b>Warning</b>: AwsClientResolver::_apply_use_fips_endpoint(): Argument #2 ($args) must be passed by reference, value given in <b>C:UsersMeetLocal Sitespda-liveapppublicwp-contentpluginsprevent-direct-access-gold-3.0vendorantecedentpatchworksrcCallRerouting.php</b> on line <b>419</b><br />
<br />
<b>Warning</b>: AwsClientResolver::_default_use_dual_stack_endpoint(): Argument #1 ($args) must be passed by reference, value given in <b>C:UsersMeetLocal Sitespda-liveapppublicwp-contentpluginsprevent-direct-access-gold-3.0vendorantecedentpatchworksrcCallRerouting.php</b> on line <b>419</b><br />
<br />
<b>Warning</b>: AwsClientResolver::_apply_use_dual_stack_endpoint(): Argument #2 ($args) must be passed by reference, value given in <b>C:UsersMeetLocal Sitespda-liveapppublicwp-contentpluginsprevent-direct-access-gold-3.0vendorantecedentpatchworksrcCallRerouting.php</b> on line <b>419</b><br />
<br />
<b>Warning</b>: AwsClientResolver::_apply_endpoint_provider(): Argument #2 ($args) must be passed by reference, value given in <b>C:UsersMeetLocal Sitespda-liveapppublicwp-contentpluginsprevent-direct-access-gold-3.0vendorantecedentpatchworksrcCallRerouting.php</b> on line <b>419</b><br />
<br />
<b>Warning</b>: Undefined array key "api" in <b>C:UsersMeetLocal Sitespda-liveapppublicwp-contentpluginsmy-s3-pluginvendorawsaws-sdk-phpsrcClientResolver.php</b> on line <b>1155</b><br />
<br />
<b>Fatal error</b>: Uncaught TypeError: AwsApiService::createSerializer(): Argument #1 ($api) must be of type AwsApiService, null given, called in C:UsersMeetLocal Sitespda-liveapppublicwp-contentpluginsmy-s3-pluginvendorawsaws-sdk-phpsrcClientResolver.php on line 1154 and defined in C:UsersMeetLocal Sitespda-liveapppublicwp-contentpluginsmy-s3-pluginvendorawsaws-sdk-phpsrcApiService.php:83
Stack trace:
#0 C:UsersMeetLocal Sitespda-liveapppublicwp-contentpluginsmy-s3-pluginvendorawsaws-sdk-phpsrcClientResolver.php(1154): AwsApiService::createSerializer(NULL, '')
#1 [internal function]: AwsClientResolver::_default_serializer(Array)
#2 C:UsersMeetLocal Sitespda-liveapppublicwp-contentpluginsprevent-direct-access-gold-3.0vendorantecedentpatchworksrcCallRerouting.php(419): call_user_func_array(Array, Array)
#3 C:UsersMeetLocal Sitespda-liveapppublicwp-contentpluginsmy-s3-pluginvendorawsaws-sdk-phpsrcClientResolver.php(393): PatchworkCallReroutingdispatchDynamic(Array, Array)
#4 C:UsersMeetLocal Sitespda-liveapppublicwp-contentpluginsmy-s3-pluginvendorawsaws-sdk-phpsrcAwsClient.php(248): AwsClientResolver->resolve(Array, Object(AwsHandlerList))
#5 C:UsersMeetLocal Sitespda-liveapppublicwp-contentpluginsmy-s3-pluginvendorawsaws-sdk-phpsrcS3S3Client.php(381): AwsAwsClient->__construct(Array)
#6 C:UsersMeetLocal Sitespda-liveapppublicwp-contentpluginsmy-s3-pluginmy-s3-plugin.php(47): AwsS3S3Client->__construct(Array)
#7 C:UsersMeetLocal Sitespda-liveapppublicwp-includesclass-wp-hook.php(324): pda_s3_integration_update_general_setting('')
#8 C:UsersMeetLocal Sitespda-liveapppublicwp-includesclass-wp-hook.php(348): WP_Hook->apply_filters('', Array)
#9 C:UsersMeetLocal Sitespda-liveapppublicwp-includesplugin.php(517): WP_Hook->do_action(Array)
#10 C:UsersMeetLocal Sitespda-liveapppublicwp-adminadmin-ajax.php(192): do_action('wp_ajax_pda_s3_...')
#11 {main}
thrown in <b>C:UsersMeetLocal Sitespda-liveapppublicwp-contentpluginsmy-s3-pluginvendorawsaws-sdk-phpsrcApiService.php</b> on line <b>83</b><br />
<p>There has been a critical error on this website.</p><p><a href="https://wordpress.org/documentation/article/faq-troubleshooting/">Learn more about troubleshooting WordPress.</a></p>
Here is the snapshot of errors and warning I am getting
enter image description here
New contributor
Riddhish is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.