humanmade / S3-Uploads

The WordPress Plugin to Store Uploads on Amazon S3
1.95k stars 391 forks source link

Conflict between S3 upload and C3 cloudfront #667

Closed orso081980 closed 8 months ago

orso081980 commented 8 months ago

Let's start with the error:

[06-Mar-2024 09:53:32 UTC] PHP Fatal error: Uncaught Error: Class 'S3_Uploads\Plugin' not found in /Users/bammac2020/Sites/test/wp-content/plugins/S3-Uploads/inc/namespace.php:32 Stack trace:

0 /Users/bammac2020/Sites/test/wp-includes/class-wp-hook.php(324): S3_Uploads\init('')

1 /Users/bammac2020/Sites/test/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters(NULL, Array)

2 /Users/bammac2020/Sites/test/wp-includes/plugin.php(517): WP_Hook->do_action(Array)

3 /Users/bammac2020/Sites/test/wp-settings.php(506): do_action('plugins_loaded')

4 /Users/bammac2020/Sites/test/wp-config.php(100): require_once('/Users/bammac20...')

5 /Users/bammac2020/Sites/test/wp-load.php(50): require_once('/Users/bammac20...')

6 /Users/bammac2020/Sites/test/wp-blog-header.php(13): require_once('/Users/bammac20...')

7 /Users/bammac2020/Sites/test/index.php(17): require('/Users/bammac20...')

8 {main}

thrown in /Users/bammac2020/Sites/test/wp-content/plugins/S3-Uploads/inc/namespace.php on line 32

I guess that one explanation was made here:

https://github.com/humanmade/S3-Uploads/issues/377

and I guess that this:

<?php add_filter('s3_uploads_s3_client_params', 'my_custom_s3_client_params');

function my_custom_s3_client_params($params) { // Modify $params as needed to use your base AWS SDK instance // For example: // $params['version'] = 'latest'; // $params['region'] = 'us-west-2'; // $params['credentials'] = [ // 'key' => 'my-access-key-id', // 'secret' => 'my-secret-access-key', // ];

return $params;

} ?>

would be a possible solution.

I have a multiple concern about this approach. We're already using the config.php file to define our key and secrets:

define( 'S3_UPLOADS_BUCKET', 'mybucket' ); define( 'S3_UPLOADS_REGION', 'eu-central-1' ); define( 'S3_UPLOADS_KEY', '' ); define( 'S3_UPLOADS_SECRET', '' ); define( 'S3_UPLOADS_USE_INSTANCE_PROFILE', true );

and everything is working fine. On top of that, we're using a bitnami image on docker for our WordPress installation, so it is kind of complicated to use composer to install of of our plugins (we use wp-cli and some sh script).

Is there any scenario where we can modify the manual installation plugin or just the funciton.php to make them work together?

Thank you in advance!

rmccue commented 8 months ago

This indicates that the autoloader has not been registered, so either you need to install directly via Composer (composer require humanmade/s3-uploads), or via a built manual-install.php. If you're installing via Composer, you also need to ensure you've loaded the autoloader first.

orso081980 commented 8 months ago

Dear rmccue,

I indeed installed it with both.

Let me clarify my issue:

The installation with composer is up and running because, as you suggested, I required the autoload.php file from the wp-config.php file at the root of the website.

Unfortunately, we deploy on around 20 websites a bitnami image through docker, and the only folder I can access is the wp-content folder (without changing the current system/pipelines).

I tried to install it differently with the manual.zip file (there is no manual.php file inside that), but with no luck for getting rid of the error, so I was wondering if there is another method that you can suggest to install the plugin (composer/manual/wp-cli) that can involve any files from the wp-content folder (modifying the function.php, call the autoload.php from another file and so on).

rmccue commented 8 months ago

@orso081980 You could have a composer.json file in your wp-content/ directory rather than in the root, and then use custom install paths to ensure Composer places it in the right directory instead.