get_instance() public static method

public static get_instance ( ) : S3_Uploads
return S3_Uploads
コード例 #1
0
function s3_uploads_init()
{
    if (!defined('S3_UPLOADS_BUCKET') || !defined('S3_UPLOADS_KEY') || !defined('S3_UPLOADS_SECRET')) {
        return;
    }
    $instance = S3_Uploads::get_instance();
    $instance->register_stream_wrapper();
    add_filter('upload_dir', array($instance, 'filter_upload_dir'));
    add_filter('wp_image_editors', array($instance, 'filter_editors'), 9);
    remove_filter('admin_notices', 'wpthumb_errors');
    add_action('wp_handle_sideload_prefilter', array($instance, 'filter_sideload_move_temp_file_to_s3'));
}
コード例 #2
0
ファイル: s3-uploads.php プロジェクト: nesth/S3-Uploads
function s3_uploads_init()
{
    if (!defined('S3_UPLOADS_BUCKET')) {
        return;
    }
    if ((!defined('S3_UPLOADS_KEY') || !defined('S3_UPLOADS_SECRET')) && !defined('S3_UPLOADS_USE_INSTANCE_PROFILE')) {
        return;
    }
    if (!s3_uploads_enabled()) {
        return;
    }
    $instance = S3_Uploads::get_instance();
    $instance->setup();
}
コード例 #3
0
ファイル: test-s3-uploads.php プロジェクト: iamlos/S3-Uploads
 public function test_image_sizes_are_deleted_on_attachment_delete()
 {
     S3_Uploads::get_instance()->setup();
     $upload_dir = wp_upload_dir();
     copy(dirname(__FILE__) . '/data/canola.jpg', $upload_dir['path'] . '/canola.jpg');
     $test_file = $upload_dir['path'] . '/canola.jpg';
     $attachment_id = $this->factory->attachment->create_object($test_file, 0, array('post_mime_type' => 'image/jpeg', 'post_excerpt' => 'A sample caption'));
     $meta_data = wp_generate_attachment_metadata($attachment_id, $test_file);
     wp_update_attachment_metadata($attachment_id, $meta_data);
     foreach ($meta_data['sizes'] as $size) {
         $this->assertTrue(file_exists($upload_dir['path'] . '/' . $size['file']));
     }
     wp_delete_attachment($attachment_id, true);
     foreach ($meta_data['sizes'] as $size) {
         $this->assertFalse(file_exists($upload_dir['path'] . '/' . $size['file']), sprintf('File %s was not deleted.', $upload_dir['path'] . '/' . $size['file']));
     }
 }
コード例 #4
0
ファイル: s3-uploads.php プロジェクト: iamlos/S3-Uploads
function s3_uploads_init()
{
    if (!s3_uploads_check_requirements()) {
        return;
    }
    if (!defined('S3_UPLOADS_BUCKET')) {
        return;
    }
    if ((!defined('S3_UPLOADS_KEY') || !defined('S3_UPLOADS_SECRET')) && !defined('S3_UPLOADS_USE_INSTANCE_PROFILE')) {
        return;
    }
    if (!s3_uploads_enabled()) {
        return;
    }
    if (!defined('S3_UPLOADS_REGION')) {
        wp_die('S3_UPLOADS_REGION constant is required. Please define it in your wp-config.php');
    }
    $instance = S3_Uploads::get_instance();
    $instance->setup();
}
コード例 #5
0
 /**
  * Delete files from S3
  *
  * @synopsis <path> [--regex=<regex>]
  */
 public function rm($args, $args_assoc)
 {
     $s3 = S3_Uploads::get_instance()->s3();
     $prefix = '';
     $regex = isset($args_assoc['regex']) ? $args_assoc['regex'] : '';
     if (strpos(S3_UPLOADS_BUCKET, '/')) {
         $prefix = trailingslashit(str_replace(strtok(S3_UPLOADS_BUCKET, '/') . '/', '', S3_UPLOADS_BUCKET));
     }
     if (isset($args[0])) {
         $prefix .= ltrim($args[0], '/');
         if (strpos($args[0], '.') === false) {
             $prefix = trailingslashit($prefix);
         }
     }
     try {
         $objects = $s3->deleteMatchingObjects(strtok(S3_UPLOADS_BUCKET, '/'), $prefix, $regex, array('before_delete', function () {
             WP_CLI::line(sprintf('Deleting file'));
         }));
     } catch (Exception $e) {
         WP_CLI::error($e->getMessage());
     }
     WP_CLI::success(sprintf('Successfully deleted %s', $prefix));
 }
コード例 #6
0
 public function tearDown()
 {
     stream_wrapper_unregister('s3');
     S3_Uploads::get_instance()->register_stream_wrapper();
 }
コード例 #7
0
 /**
  * Gets the path that the wrapper is responsible for.
  *
  * @return string
  *   String specifying the path.
  */
 static function getDirectoryPath()
 {
     $upload_dir = S3_Uploads::get_instance()->get_original_upload_dir();
     return $upload_dir['basedir'] . '/s3';
 }
コード例 #8
0
 public function test_get_s3_client()
 {
     $s3 = S3_Uploads::get_instance()->s3();
     $this->assertInstanceOf('Aws\\S3\\S3Client', $s3);
 }