示例#1
0
 public function setup_sync_assistant()
 {
     if (!Client::instance()->is_configured()) {
         return;
     }
     $sync_assistant = SyncAssistant::instance();
     if (Settings::instance()->get_setting('sync_addition')) {
         add_filter('wp_update_attachment_metadata', array($sync_assistant, 'sync_addition'), 10, 2);
     }
     if (Settings::instance()->get_setting('sync_deletion')) {
         add_action('delete_attachment', array($sync_assistant, 'sync_deletion'), 10, 1);
     }
     if (Settings::instance()->get_setting('remote_only')) {
         add_action('wpgcso_uploaded_to_cloud_storage', array($sync_assistant, 'delete_local_on_upload'), 10, 3);
     }
     // the following hooks prevent accidental removing of files
     add_action('wpgcso_delete_from_cloud_storage', array($sync_assistant, 'store_local_on_remote_only_delete'), 10, 3);
     add_action('wpgcso_delete_local_file', array($sync_assistant, 'store_remote_on_local_only_delete'), 10, 3);
 }
        public function attachment_submitbox_misc_actions($id = null)
        {
            $attachment = Attachment::get($id);
            if (!$attachment) {
                return;
            }
            ?>
			<div id="wp-gcs-offload-data">
				<div class="misc-pub-section misc-pub-gcs-data">
					<hr />
					<strong><?php 
            _e('Google Cloud Storage Data', 'wp-gcs-offload');
            ?>
</strong>
				</div>

				<?php 
            if (!$attachment->is_cloud_storage_file()) {
                ?>
					<div class="misc-pub-section misc-pub-gcs-sync-upstream">
						<?php 
                _e('This attachment is not synced with Google Cloud Storage.', 'wp-gcs-offload');
                ?>
						<?php 
                if (Client::instance()->is_configured()) {
                    ?>
							<a href="#" id="wp-gcs-offload-sync-attachment-upstream"><?php 
                    _e('Sync now', 'wp-gcs-offload');
                    ?>
</a>
						<?php 
                }
                ?>
					</div>
					<?php 
                return;
            }
            if (!$attachment->is_local_file()) {
                ?>
					<div class="misc-pub-section misc-pub-gcs-sync-downstream">
						<?php 
                _e('This attachment is on Google Cloud Storage, but not available locally.', 'wp-gcs-offload');
                ?>
						<?php 
                if (Client::instance()->is_configured()) {
                    ?>
							<a href="#" id="wp-gcs-offload-sync-attachment-downstream"><?php 
                    _e('Sync now', 'wp-gcs-offload');
                    ?>
</a>
						<?php 
                }
                ?>
					</div>
					<?php 
            } else {
                ?>
					<div class="misc-pub-section misc-pub-gcs-delete-downstream">
						<?php 
                _e('This attachment is available on Google Cloud Storage and locally.', 'wp-gcs-offload');
                ?>
						<?php 
                if (Client::instance()->is_configured()) {
                    ?>
							<a href="#" id="wp-gcs-offload-delete-attachment-downstream"><?php 
                    _e('Delete locally', 'wp-gcs-offload');
                    ?>
</a>
						<?php 
                }
                ?>
					</div>
					<?php 
            }
            ?>

				<div class="misc-pub-section misc-pub-gcs-bucket-name">
					<?php 
            _e('Bucket Name:', 'wp-gcs-offload');
            ?>
 <strong><?php 
            echo $attachment->get_cloud_storage_bucket_name();
            ?>
</strong>
				</div>
				<div class="misc-pub-section misc-pub-gcs-dir-name">
					<?php 
            _e('Directory Name:', 'wp-gcs-offload');
            ?>
 <strong><?php 
            echo $attachment->get_cloud_storage_dir_name();
            ?>
</strong>
				</div>
				<div class="misc-pub-section misc-pub-gcs-delete-upstream">
					<?php 
            _e('This attachment is on Google Cloud Storage.', 'wp-gcs-offload');
            ?>
					<?php 
            if (Client::instance()->is_configured()) {
                ?>
						<a href="#" id="wp-gcs-offload-delete-attachment-upstream"><?php 
                _e('Delete from Google Cloud Storage', 'wp-gcs-offload');
                ?>
</a>
					<?php 
            }
            ?>
				</div>
			</div>
			<?php 
        }
示例#3
0
 private function delete_sizes_from_google_cloud_storage($meta_sizes, $image_sizes, $main_file, $dir_name)
 {
     $errors = new WP_Error();
     foreach ($meta_sizes as $size => $data) {
         if (!in_array($size, $image_sizes, true)) {
             continue;
         }
         $file = str_replace(basename($main_file), $data['file'], $main_file);
         $status = Client::instance()->delete($file, $dir_name);
         if (is_wp_error($status)) {
             $errors->add($status->get_error_code(), $status->get_error_message(), $status->get_error_data());
             continue;
         }
     }
     if (empty($errors->errors)) {
         return true;
     }
     return $errors;
 }