Skip to content

Commit 4aa0783

Browse files
committedMar 6, 2025
Add Equalize Digital oEmbed Cleaner plugin with README and main functionality
0 parents  commit 4aa0783

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed
 

‎README.md

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Equalize Digital oEmbed Cleaner
2+
3+
**Contributors:** Equalize Digital
4+
**Tags:** oEmbed, cache, scheduled posts, WordPress
5+
**Requires at least:** 5.0
6+
**Tested up to:** 6.6
7+
**Stable tag:** 1.0.0
8+
**License:** GPLv2 or later
9+
**License URI:** [https://www.gnu.org/licenses/gpl-2.0.html](https://www.gnu.org/licenses/gpl-2.0.html)
10+
11+
## Description
12+
13+
Equalize Digital oEmbed Cleaner is a lightweight WordPress plugin that automatically removes invalid oEmbed cache entries when posts transition from **scheduled** to **published**. This ensures that broken or outdated embed previews do not persist on your site.
14+
15+
## Features
16+
17+
- Cleans up `_oembed_*` post meta with `{{unknown}}` values.
18+
- Runs automatically when a scheduled post gets published.
19+
- Helps prevent outdated or broken oEmbed caches.
20+
- Simple, efficient, and does not add overhead to your site.
21+
22+
## Installation
23+
24+
1. Download the plugin ZIP or clone the repository.
25+
2. Upload the extracted folder to `/wp-content/plugins/equalize-digital-oembed-cleaner/`.
26+
3. Activate the plugin via **Plugins > Installed Plugins** in your WordPress dashboard.
27+
28+
## How It Works
29+
30+
The plugin hooks into WordPress’s `transition_post_status` action and:
31+
32+
- Detects when a post status changes from **scheduled** (`future`) to **published**.
33+
- Removes `_oembed_*` cache entries with `{{unknown}}` values in the postmeta table.
34+
35+
## Changelog
36+
37+
### 1.0.0
38+
- Initial release.
39+
40+
## License
41+
42+
This plugin is licensed under the **GPL-2.0+**.

‎oembed-cleaner.php

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
/**
3+
* Plugin Name: Equalize Digital oEmbed Cleaner
4+
* Description: Cleans invalid oEmbed caches when posts transition from scheduled to published
5+
* Version: 1.0.0
6+
* Author: Equalize Digital
7+
*
8+
* @package EqualizedigitalOembedCleaner
9+
*/
10+
11+
// If this file is called directly, abort.
12+
if ( ! defined( 'WPINC' ) ) {
13+
die;
14+
}
15+
16+
/**
17+
* Cleans up invalid oEmbed cache entries when a post transitions from scheduled to published
18+
*
19+
* @param string $new_status New post status.
20+
* @param string $old_status Old post status.
21+
* @param WP_Post $post Post object.
22+
* @return void
23+
*/
24+
function eqd_clean_unknown_oembed_caches( $new_status, $old_status, $post ) {
25+
// Check if post is transitioning from future (scheduled) to publish.
26+
if ( 'publish' === $new_status && 'future' === $old_status ) {
27+
global $wpdb;
28+
29+
// Use WordPress's table references.
30+
$wpdb->query(
31+
$wpdb->prepare(
32+
"DELETE FROM {$wpdb->postmeta}
33+
WHERE post_id = %d
34+
AND meta_key LIKE '_oembed_%%'
35+
AND meta_value = '{{unknown}}';",
36+
absint( $post->ID )
37+
)
38+
);
39+
}
40+
}
41+
42+
// Hook into WordPress with a unique function name to avoid conflicts.
43+
add_action( 'transition_post_status', 'eqd_clean_unknown_oembed_caches', 10, 3 );

0 commit comments

Comments
 (0)
Please sign in to comment.