Latest Google Drive File
Latest Google Drive File is a back-end plugin that was developed for WordPress websites. It may work on other hosting site, but not guaranteed. This allows you to serve the most recent file from a Google Drive folder at a stable URL. Perfect for always showing the latest PDF, image, or other file in viewers like PDF Embedder, img, or video.
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/kt053374/latest-google-drive-file/archive/refs/heads/main.zipLatest Google Drive File is a back-end plugin that was developed for WordPress websites. It may work on other hosting site, but not guaranteed. This allows you to serve the most recent file from a Google Drive folder at a stable URL. Perfect for always showing the latest PDF, image, or other file in viewers like PDF Embedder, img, or video.
Latest Google Drive File
Contributors: Ken Thompson
Tags: google drive, pdf, media, embed, api, files, newsletter
Requires at least: 5.0
Tested up to: 6.7
Requires PHP: 7.4
Stable tag: 5.0.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Serve the most recent file from a Google Drive folder at a stable URL. Perfect for always showing the latest newsletter PDF, image, or other file in viewers like PDF Embedder, img, or video.
Description
Latest Google Drive File lets you define up to 10 Google Drive folders and exposes a simple endpoint that always returns the most recently modified file from each folder.
Common use cases:
- Always embed the latest PDF newsletter using PDF Embedder
- Always show the latest flyer or image from a Drive folder
- Serve the newest MP4 from a Drive folder into a video player
- Keep a "Latest XXX" download link in sync without editing pages
You configure:
- A Google Drive API key (restricted to your site and the Drive API)
- A root domain for example URL generation (optional)
- Up to 10 folder slots, each with:
- Folder key (short identifier)
- Drive Folder ID
- Optional MIME type filter
- Cache duration in minutes
- Custom public error message
The plugin then gives you for each folder:
- An example URL that always streams the latest file
- An example PDF Embedder shortcode that uses that URL
You can drop the URL into any embed system that accepts URLs:
- PDF Embedder
- Standard HTML tags like
img,video, ora - Your own shortcodes or custom templates
How it works
The plugin registers an endpoint on your site:
https://your-site.com/?latest_newsletter=1&folder_key=yourkey
When called, the plugin:
- Resolves the folder configuration based on
folder_key(orfolder_idif passed directly). - Calls the Google Drive API (v3) using your API key.
- Runs a query such as
With MIME filter:
'FOLDER_ID' in parents and mimeType = 'application/pdf' and trashed = false
Without MIME filter:
'FOLDER_ID' in parents and trashed = false - Orders results by
modifiedTime descand takes the first file. - Downloads the file bytes via
files.get?alt=media. - Streams it back to the browser with correct
Content-TypeandContent-Disposition: inline.
A per folder cache stores the selected file ID for a configurable number of minutes to reduce API calls.
Requirements
- WordPress 5.0 or higher
- PHP 7.4 or higher
- A Google Cloud project with the Google Drive API enabled
- A Google Drive API key restricted to:
- Your site domain (HTTP referrer restriction)
- Google Drive API only (API restriction)
- Drive folders shared as:
- General access:
Anyone with the link - Permission:
Viewer
- General access:
Installation
-
Download the plugin and place it in
wp-content/plugins/latest-google-drive-file -
Ensure the folder structure looks like:
latest-google-drive-file/
├── latest-google-drive-file.php
├── includes/
│ ├── helpers.php
│ ├── admin-settings.php
│ └── serve-file.php
└── assets/
├── css/admin.css
└── js/admin.js -
Activate the plugin from Plugins in the WordPress admin.
-
Go to Settings → Latest Google Drive File.
-
Under Global Settings:
- Enter your Google API Key (see next section).
- Optionally enter your Root domain (for example
https://alp166sc.com) so example URLs use that domain. - Choose how many Folder slots to show.
-
Under Google Drive Folders, configure one or more folders:
- Folder key
A short identifier likenewsletter,events,flyer. This is used infolder_keyin the URL. - Label
Human friendly description such as "Main Newsletter". - Folder ID
The string after/folders/in your Google Drive folder URL. - MIME type
Choose a specific MIME type (for exampleapplication/pdf) or "Any type". - Cache (minutes)
How long to cache the latest file ID for this folder. - Error message
Public message shown to visitors when no file is found or an error occurs.
- Folder key
-
Click Save Changes.
Each configured folder card will show an example URL and an example shortcode you can use.
Setting up the Google Drive API key
- Visit the Google Cloud Console and create or select a project.
- Go to APIs and Services → Library and search for Google Drive API.
- Enable the Google Drive API for your project.
- Go to APIs and Services → Credentials.
- Click Create credentials → API key.
- Edit the new API key:
- Under Application restrictions, choose HTTP referrers (web sites) and add your site for example:
https://example.com/* - Under API restrictions, select Restrict key and choose Google Drive API.
- Under Application restrictions, choose HTTP referrers (web sites) and add your site for example:
- Save, then copy the key and paste it into Google API Key on the plugin settings page.
Sharing your Google Drive folder
- Go to Google Drive and locate the folder you will use.
- Right click the folder and choose Share.
- Under General access, set it to Anyone with the link.
- Set the role to Viewer.
- Click Copy link.
- In the copied URL, find the part after
/folders/and before any?query. That is your Folder ID. - Paste that value into the Folder ID field on the plugin settings page.
Any file placed in that folder will inherit the sharing and can be accessed by the plugin.
Usage
Basic usage with folder key
-
Configure a folder with:
- Folder key:
newsletter - MIME type:
application/pdf - Folder ID: your Drive folder ID
- Folder key:
-
After saving, the folder card shows example values like:
Example URL
https://example.com/?latest_newsletter=1&folder_key=newsletterExample shortcode (for PDF Embedder)
[pdf-embedder url="https://example.com/?latest_newsletter=1&folder_key=newsletter"] -
Insert that shortcode into a page or post.
PDF Embedder will fetch from the plugin endpoint. The endpoint always serves the newest PDF in that folder.
Using different viewers
The endpoint streams the raw file bytes, so you can embed it anywhere a URL is accepted.
Image example:
<img src="https://example.com/?latest_newsletter=1&folder_key=flyer" alt="Latest flyer">