esc_like( $prefix ) . '%'; $names = $wpdb->get_col( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- no WordPress API lists options by name prefix; read live. $wpdb->prepare( "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE %s OR option_name LIKE %s OR option_name LIKE %s", $like, $wpdb->esc_like( '_transient_' . $prefix ) . '%', $wpdb->esc_like( '_transient_timeout_' . $prefix ) . '%' ) ); foreach ( (array) $names as $name ) { delete_option( $name ); } } if ( $erase ) { if ( ! class_exists( '\Careback\Data_Eraser' ) ) { require_once __DIR__ . '/includes/class-data-eraser.php'; } \Careback\Data_Eraser::erase(); } } /** * True when another installed plugin names this one under "Requires Plugins" * (read by WordPress 6.5 and later; earlier versions report no dependents, and * the option goes as it always did). * * @return bool */ function careback_uninstall_has_dependents() { if ( ! function_exists( 'get_plugins' ) ) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } $self = strtolower( dirname( (string) WP_UNINSTALL_PLUGIN ) ); if ( '' === $self || '.' === $self ) { return false; } foreach ( get_plugins() as $file => $data ) { if ( (string) WP_UNINSTALL_PLUGIN === $file || empty( $data['RequiresPlugins'] ) ) { continue; } $required = array_map( 'trim', explode( ',', strtolower( (string) $data['RequiresPlugins'] ) ) ); if ( in_array( $self, $required, true ) ) { return true; } } return false; } if ( is_multisite() ) { // A network install wrote its options per site, so they have to be removed // per site. Bounded, because get_sites() with no limit returns 100 by // default and a large network would otherwise be half cleaned. $careback_page = 1; do { $careback_sites = get_sites( array( 'number' => 100, 'offset' => ( $careback_page - 1 ) * 100, 'fields' => 'ids', ) ); foreach ( $careback_sites as $careback_site_id ) { switch_to_blog( $careback_site_id ); careback_uninstall_site(); restore_current_blog(); } $careback_page++; } while ( count( $careback_sites ) === 100 ); } else { careback_uninstall_site(); }