120 lines
3.2 KiB
PHP
120 lines
3.2 KiB
PHP
<?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();
|