This commit is contained in:
Javier Casares 2026-02-19 11:15:55 +00:00
commit f7702f2872
25 changed files with 6453 additions and 0 deletions

120
uninstall.php Normal file
View file

@ -0,0 +1,120 @@
<?php
/**
* Uninstall handler for OpenGraph (by ROBOTSTXT)
*
* Fired when the plugin is uninstalled.
*
* @package ROBOTSTXT_OG
* @version 1.0.0
*/
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit; // Exit if accessed directly.
}
/**
* Delete plugin data if user opted in to data deletion.
*/
function robotstxt_og_uninstall_cleanup() {
// Check if user opted in to delete data on uninstall.
$delete_data = get_option( 'robotstxt_og_delete_data_on_uninstall', false );
if ( ! $delete_data ) {
// Preserve data by default.
return;
}
// Delete all plugin options.
delete_option( 'robotstxt_og_fallback_image' );
delete_option( 'robotstxt_og_homepage_image' );
delete_option( 'robotstxt_og_enable_facebook' );
delete_option( 'robotstxt_og_enable_twitter' );
delete_option( 'robotstxt_og_twitter_card_type' );
delete_option( 'robotstxt_og_twitter_site' );
delete_option( 'robotstxt_og_delete_data_on_uninstall' );
// Delete all cached postmeta (fallback URLs and per-post OG overrides).
global $wpdb;
// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
// Bulk delete during uninstall — no WP API exists to delete all postmeta rows by key at once.
$wpdb->query(
$wpdb->prepare(
"DELETE FROM {$wpdb->postmeta} WHERE meta_key = %s",
'_og_image_fallback_url'
)
);
$wpdb->query(
$wpdb->prepare(
"DELETE FROM {$wpdb->postmeta} WHERE meta_key = %s",
'_og_title'
)
);
$wpdb->query(
$wpdb->prepare(
"DELETE FROM {$wpdb->postmeta} WHERE meta_key = %s",
'_og_description'
)
);
// phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
// Clear related transients.
delete_transient( 'robotstxt_og_diagnostics_cache' );
// On Multisite, clean up site-by-site.
if ( is_multisite() ) {
$sites = get_sites(
array(
'number' => 0,
)
);
foreach ( $sites as $site ) {
switch_to_blog( $site->blog_id );
// Delete site-specific options.
delete_option( 'robotstxt_og_fallback_image' );
delete_option( 'robotstxt_og_homepage_image' );
delete_option( 'robotstxt_og_enable_facebook' );
delete_option( 'robotstxt_og_enable_twitter' );
delete_option( 'robotstxt_og_twitter_card_type' );
delete_option( 'robotstxt_og_twitter_site' );
delete_option( 'robotstxt_og_delete_data_on_uninstall' );
// Delete site-specific postmeta.
// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
// Bulk delete during uninstall — no WP API exists to delete all postmeta rows by key at once.
$wpdb->query(
$wpdb->prepare(
"DELETE FROM {$wpdb->postmeta} WHERE meta_key = %s",
'_og_image_fallback_url'
)
);
$wpdb->query(
$wpdb->prepare(
"DELETE FROM {$wpdb->postmeta} WHERE meta_key = %s",
'_og_title'
)
);
$wpdb->query(
$wpdb->prepare(
"DELETE FROM {$wpdb->postmeta} WHERE meta_key = %s",
'_og_description'
)
);
// phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
// Clear site-specific transients.
delete_transient( 'robotstxt_og_diagnostics_cache' );
restore_current_blog();
}
}
}
// Execute cleanup.
robotstxt_og_uninstall_cleanup();