You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.9 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. <?php
  2. /**
  3. * Plugin Name: Wpstudio Media Cloud Transform
  4. * Plugin URI: PLUGIN SITE HERE
  5. * Description: PLUGIN DESCRIPTION HERE
  6. * Author: YOUR NAME HERE
  7. * Author URI: YOUR SITE HERE
  8. * Text Domain: wpstudio-media-cloud-transform
  9. * Domain Path: /languages
  10. * Version: 0.1.0
  11. *
  12. * @package Wpstudio_Media_Cloud_Transform
  13. */
  14. use WpsMcloud\Actions;
  15. use WpsMcloud\Exceptions\VendorAutoloadException;
  16. use WpsMcloud\Pages;
  17. use WpsMcloud\Logger;
  18. define('WPSTUDIO_MEDIA_CLOUD_TRANFORM_BASE_PATH', dirname(__FILE__));
  19. add_action('admin_menu', fn () => add_submenu_page(
  20. 'media-cloud',
  21. 'Convert local to S3',
  22. 'Convert local to S3',
  23. 'manage_options',
  24. 'convert_local_to_s3',
  25. function () {
  26. // $ilabLoader = require dirname(__FILE__) . '/../ilab-media-tools/vendor/autoload.php';
  27. //
  28. // $ilabClassLoader = new Composer\Autoload\ClassLoader();
  29. // $ilabLoader->unregister();
  30. $localVendorAutoloadPath = 'vendor/autoload.php';
  31. $projectVendorAutoloadPath = ABSPATH . 'vendor/autoload.php';
  32. if (file_exists($localVendorAutoloadPath)) {
  33. include $localVendorAutoloadPath;
  34. } elseif (file_exists($projectVendorAutoloadPath)) {
  35. include $projectVendorAutoloadPath;
  36. } else {
  37. throw new VendorAutoloadException('Unable to find appropriate composer autoloader');
  38. }
  39. $dotEnvFile = __DIR__ . '/.env';
  40. if (file_exists($dotEnvFile)) {
  41. $dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
  42. $dotenv->load();
  43. }
  44. if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  45. $loggerConfig = include __DIR__ . '/config/logger.php';
  46. $logger = new Logger($loggerConfig['log_type']);
  47. echo '<pre>';
  48. (new Actions\Convert())->run();
  49. echo '</pre>';
  50. }
  51. (new Pages\Converter())->render();
  52. },
  53. 6
  54. ), 99);