/** * @return bool * @throws \Exception */ private function sync_blog_uploads() { $option = Plugin::get_aws_option(); $client = Plugin::get_client($option); $upload_paths = wp_upload_dir(); $blog_local_dir = $upload_paths['basedir']; if (is_multisite()) { switch_to_blog(BLOG_ID_CURRENT_SITE); $upload_paths = wp_upload_dir(); $main_local_dir = $upload_paths['basedir']; restore_current_blog(); $key_prefix = trim(str_replace($main_local_dir, '', $blog_local_dir), '/'); if (empty($key_prefix)) { $key_prefix = null; } } else { $key_prefix = null; } try { $client->uploadDirectory($blog_local_dir, $option['bucket'], $key_prefix, array('params' => array('ACL' => 'public-read'), 'concurrency' => 20)); return true; } catch (\Exception $e) { throw $e; } }
public function panel() { $option = Plugin::get_aws_option(); $error = $this->error; $message = $this->message; Plugin::require_lib_path('includes/admin_panel_settings.php', compact('option', 'error', 'message')); }
/** * @param $post_id */ public function action_delete_attachment($post_id) { $option = Plugin::get_aws_option(); $client = Plugin::get_client($option); $attachment_meta = wp_get_attachment_metadata($post_id); $backup_sizes = get_post_meta($post_id, '_wp_attachment_backup_sizes', true); $attached = get_post_meta($post_id, '_wp_attached_file', true); if ($attachment_meta) { $full_local_path = $this->attached_file_meta_to_full_local_path($attached); $key_prefix = $this->full_local_path_to_key_prefix($full_local_path); $dir = explode('/', $attachment_meta['file']); $file = array_pop($dir); $this->delete_one($client, $option['bucket'], $key_prefix, $file); if (isset($attachment_meta['sizes']) && is_array($attachment_meta['sizes'])) { foreach ($attachment_meta['sizes'] as $size) { $this->delete_one($client, $option['bucket'], $key_prefix, $size['file']); } } if ($backup_sizes && is_array($backup_sizes)) { foreach ($backup_sizes as $size) { $this->delete_one($client, $option['bucket'], $key_prefix, $size['file']); } } } }