remove_options(); $this->remove_transients(); $this->remove_tables(); $this->clean_users_meta(); // clear WP cache. wp_cache_flush(); } /** * Clean options */ private function remove_options() { global $wpdb; $items = [ 'ahrefs-seo' ]; foreach ( $items as $item ) { $options = $wpdb->get_col( $wpdb->prepare( "SELECT option_name AS name FROM {$wpdb->options}\n\t\t\t\t\tWHERE option_name LIKE %s", $wpdb->esc_like( "{$item}" ) . '%' ) ); foreach ( $options as $name ) { delete_option( $name ); } } } /** * Clean transients */ private function remove_transients() { global $wpdb; $items = [ 'ahrefs_seo', 'ahrefs-cron', 'ahrefs-content' ]; foreach ( $items as $item ) { $transients = $wpdb->get_col( $wpdb->prepare( "SELECT option_name AS name FROM {$wpdb->options}\n\t\t\t\t\tWHERE option_name LIKE %s", $wpdb->esc_like( "_transient_{$item}" ) . '%' ) ); foreach ( $transients as $transient ) { delete_transient( str_replace( '_transient_', '', $transient ) ); } } } /** * Remove tables */ private function remove_tables() { global $wpdb; $tables = [ 'ahrefs_seo_content', 'ahrefs_seo_snapshots', 'ahrefs_seo_keywords', 'ahrefs_seo_backlinks', 'ahrefs_seo_blacklist' ]; foreach ( $tables as $table ) { $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}{$table}" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.SchemaChange,WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- remove own predefined tables. } } /** * Remove admin message metadata */ private function clean_users_meta() { delete_metadata( 'user', 0, 'ahrefs_seo_admin_notice_dismissed', '', true ); } }