query( $wpdb->prepare( 'DROP TABLE IF EXISTS %i', $wpdb->prefix . 'handymcp_' . $table ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.SchemaChange -- removing this plugin's tables on uninstall. } $wpdb->query( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- removing this plugin's options on uninstall. $wpdb->prepare( "DELETE FROM {$wpdb->options} WHERE option_name LIKE %s OR option_name LIKE %s OR option_name LIKE %s", $wpdb->esc_like( 'handymcp_' ) . '%', $wpdb->esc_like( '_transient_handymcp_' ) . '%', $wpdb->esc_like( '_transient_timeout_handymcp_' ) . '%' ) ); // Backups of replaced images: their files sit next to the image in the uploads folder. $handymcp_base = realpath( (string) wp_upload_dir( null, false )['basedir'] ); foreach ( get_posts( array( 'post_type' => 'attachment', 'post_status' => 'any', 'numberposts' => -1, 'fields' => 'ids', 'meta_key' => '_handymcp_replace_backup' ) ) as $handymcp_id ) { // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key -- one-time cleanup on uninstall. $handymcp_backup = get_post_meta( (int) $handymcp_id, '_handymcp_replace_backup', true ); $handymcp_dir = realpath( dirname( (string) get_attached_file( (int) $handymcp_id ) ) ); if ( ! $handymcp_base || ! $handymcp_dir || 0 !== strpos( wp_normalize_path( $handymcp_dir ) . '/', trailingslashit( wp_normalize_path( $handymcp_base ) ) ) || ! is_array( $handymcp_backup ) ) { continue; } foreach ( (array) ( $handymcp_backup['backups'] ?? array() ) as $handymcp_bak ) { $handymcp_path = trailingslashit( $handymcp_dir ) . wp_basename( (string) $handymcp_bak ); if ( false !== strpos( wp_basename( $handymcp_path ), '.bak-' ) && is_file( $handymcp_path ) ) { wp_delete_file( $handymcp_path ); } } } delete_post_meta_by_key( '_handymcp_replace_backup' ); delete_post_meta_by_key( '_handymcp_file_version' ); foreach ( array( 'handymcp_pro_free_notice', 'handymcp_hidden_pro', 'handymcp_hub_busy_until' ) as $handymcp_key ) { delete_metadata( 'user', 0, $handymcp_key, '', true ); } delete_option( 'handymcp_free_scopes' ); $sections = get_posts( array( 'post_type' => 'handymcp_section', 'post_status' => array_keys( get_post_stati() ), 'numberposts' => -1, 'fields' => 'ids', ) ); foreach ( $sections as $section_id ) { wp_delete_post( (int) $section_id, true ); } delete_metadata( 'user', 0, 'handymcp_hidden_pro', '', true ); } if ( is_multisite() ) { foreach ( get_sites( array( 'fields' => 'ids', 'number' => 0 ) ) as $handymcp_site_id ) { switch_to_blog( (int) $handymcp_site_id ); handymcp_uninstall_site(); restore_current_blog(); } } else { handymcp_uninstall_site(); }