/** * creates the content for the howto-metabox * * @access public * * @return void * @since 1.0 */ public function connect() { $helper = new WPB_Google_Drive_Cdn_Service_Helper($this->_google_drive_cdn); $is_api_working = $helper->is_api_working(); $client = $this->_google_drive_cdn->get_google_client(); $client->setState('got_code'); // get offline access $client->setAccessType('offline'); // makes the UI window appear ALWAYS $client->setApprovalPrompt('force'); echo '<p>' . __('Please note: you will be redirected to a Google\'s authorization page. Please press the blue button to give this application the right to upload files.', $this->_google_drive_cdn->get_textdomain()) . '</p>'; echo '<a class="button-primary" href="' . $client->createAuthUrl() . '">' . __('Grant writing permissions to your Google Drive', $this->_google_drive_cdn->get_textdomain()) . '</a>'; if (!$is_api_working) { echo '<div class="error"><p>', __('The Google Drive API is currently not working.', $this->_google_drive_cdn->get_textdomain()), ' ' . __('Try to (re-)authenticate by using the button "Grant writing permissions to your Google Drive" button.', $this->_google_drive_cdn->get_textdomain()), '</p></div>'; } }
/** * @return bool * @since 1.0 */ public function delete_folder() { $service = new Google_Service_Drive($this->_google_drive_cdn->get_google_client()); // get the folder id $folder_id = WPB_Google_Drive_Cdn_Settings::get_setting('folder_id', 'wpbgdc_folders'); try { $service->files->trash($folder_id); // deleting the files directly will result in a bug @see http://stackoverflow.com/questions/16573970/google-drive-api-delete-method-bug // $service->files->delete( $folder_id ); } catch (Exception $e) { $this->_google_drive_cdn->set_error($e->getMessage() . '(wpbgdc: delete_folder 1)', false); return false; } return true; }